From 79764732406d6484f67d3dec045483dcb5d08c28 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 18 Sep 2026 20:03:13 -0400 Subject: feat: better card ascii art --- internal/game/cmd_swapid.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'internal/game/cmd_swapid.go') diff --git a/internal/game/cmd_swapid.go b/internal/game/cmd_swapid.go index 00b6568..8b637fb 100644 --- a/internal/game/cmd_swapid.go +++ b/internal/game/cmd_swapid.go @@ -117,7 +117,12 @@ func (g *Game) executeSwapID(sess *net.Session, args []string, rawInput string) // The two swapped rooms are always re-marshaled to correct their `id:` // field; other rooms are re-marshaled only if a reference actually moved. idMap := map[int]int{id1: id2, id2: id1} - var updated int + // Rewrite every room that references the swapped IDs in ONE journal + // transaction. The old per-file writeRoomFile loop swallowed errors, so + // a crash or a failed write mid-loop left a half-migrated world with no + // recovery record. + rewriteTxn := g.newTxn() + updated := 0 for id := range g.World.RoomIndex() { room, err := g.World.LoadRoom(id) if err != nil { @@ -133,13 +138,19 @@ func (g *Game) executeSwapID(sess *net.Session, args []string, rawInput string) } data, merr := yaml.Marshal(room) if merr != nil { - continue + sess.WriteLine(fmt.Sprintf("Error rewriting room %d: %v", id, merr)) + return } - if werr := writeRoomFile(path, data); werr != nil { - continue + if rerr := rewriteTxn.Replace(path, data, 0644); rerr != nil { + sess.WriteLine(fmt.Sprintf("Error rewriting room %d: %v", id, rerr)) + return } updated++ } + if rerr := rewriteTxn.Commit(); rerr != nil { + sess.WriteLine(fmt.Sprintf("Error rewriting room references: %v", rerr)) + return + } // Full runtime migration: Hub room buckets, casino room keys, world // room-keyed state (ground items, seeded markers, object states), live -- cgit v1.2.3