aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_swapid.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-18 20:03:13 -0400
committerhistoria <[not public]>2026-09-18 20:03:13 -0400
commit79764732406d6484f67d3dec045483dcb5d08c28 (patch)
tree7a64e8581a540b97ed554f5723e2d587424ab1c6 /internal/game/cmd_swapid.go
parentf1e461ab6aec6b9bf056bbe2daa88a251e0f21da (diff)
downloadthehouseoficarus-79764732406d6484f67d3dec045483dcb5d08c28.tar.gz
feat: better card ascii art
Diffstat (limited to 'internal/game/cmd_swapid.go')
-rw-r--r--internal/game/cmd_swapid.go19
1 files changed, 15 insertions, 4 deletions
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