diff options
Diffstat (limited to 'internal/game/cmd_swapid.go')
| -rw-r--r-- | internal/game/cmd_swapid.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/internal/game/cmd_swapid.go b/internal/game/cmd_swapid.go index d1dbd68..b0863d4 100644 --- a/internal/game/cmd_swapid.go +++ b/internal/game/cmd_swapid.go @@ -3,10 +3,12 @@ package game import ( "fmt" "os" + "path/filepath" "strconv" "gopkg.in/yaml.v3" + "thehouseoficarus/internal/behavior" "thehouseoficarus/internal/net" ) @@ -149,6 +151,26 @@ func (g *Game) executeSwapID(sess *net.Session, args []string, rawInput string) } updated++ } + // Non-room content (courses, modules, triggers, items, objects, mobs) + // carries structural room references too. Stage it into the SAME journal + // transaction as the room files, so a swap never leaves a course obstacle, + // transport destination, or trigger teleport pointing at the wrong room + // even if one side's write fails. + contentUpdated := 0 + for _, sub := range behavior.RoomRefContentDirs { + changes, cerr := behavior.RewriteRoomRefsInDir(filepath.Join(g.DataDir, sub), idMap) + if cerr != nil { + sess.WriteLine(fmt.Sprintf("Error scanning %s for room references: %v", sub, cerr)) + return + } + for _, ch := range changes { + if werr := rewriteTxn.Replace(ch.Path, ch.Content, 0644); werr != nil { + sess.WriteLine(fmt.Sprintf("Error rewriting %s: %v", ch.Path, werr)) + return + } + contentUpdated++ + } + } if rerr := rewriteTxn.Commit(); rerr != nil { sess.WriteLine(fmt.Sprintf("Error rewriting room references: %v", rerr)) return @@ -162,5 +184,5 @@ func (g *Game) executeSwapID(sess *net.Session, args []string, rawInput string) // from the owner command loop) and must not dispatch again. g.MigrateRoomIDsOnOwner(idMap) - sess.WriteLine(fmt.Sprintf("Swapped room IDs %d and %d (%d files updated).", id1, id2, updated)) + sess.WriteLine(fmt.Sprintf("Swapped room IDs %d and %d (%d room files, %d content files updated).", id1, id2, updated, contentUpdated)) } |
