diff options
| author | historia <[not public]> | 2026-07-09 22:15:54 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-09 22:15:54 -0400 |
| commit | ecba7f726f70b37126d852c38c7e3eec7b04d730 (patch) | |
| tree | 9129215c6e5015336fde1116395336d82bb952d1 /internal/world/room_migrate_test.go | |
| parent | b3d4c616f59ad2519f3a0b77e3b47d6571cd2486 (diff) | |
| download | thehouseoficarus-ecba7f726f70b37126d852c38c7e3eec7b04d730.tar.gz | |
feat: old standalone trigger systems completely unified into trigger->condition->action system
Diffstat (limited to 'internal/world/room_migrate_test.go')
| -rw-r--r-- | internal/world/room_migrate_test.go | 104 |
1 files changed, 61 insertions, 43 deletions
diff --git a/internal/world/room_migrate_test.go b/internal/world/room_migrate_test.go index c54adf2..96f74ae 100644 --- a/internal/world/room_migrate_test.go +++ b/internal/world/room_migrate_test.go @@ -2,29 +2,42 @@ package world import ( "testing" - "thehouseoficarus/internal/behavior" ) func TestRoomRewriteRoomIDs(t *testing.T) { r := &Room{ Exits: map[ExitDir]ExitDef{ - North: {Room: 10, OnTraverse: []behavior.Interaction{{Action: &behavior.StepAction{ - NodeAction: behavior.NodeAction{SetGlobalFlags: map[string]any{"last": 10}, Teleport: 110}, - }}}}, - South: {Room: 99}, - }, - Triggers: []TriggerDef{ - { - Room: 30, - Steps: []behavior.StepAction{ - {NodeAction: behavior.NodeAction{Teleport: 40}, SpawnMob: &behavior.SpawnMobConfig{DespawnRooms: []int{50, 60}}}, - }, + North: { + Room: 10, + OnTraverse: []behavior.Trigger{{ + Condition: &behavior.Condition{Room: 60}, // projectile, ensures trigger-condition Room remaps too + Steps: []behavior.Step{{ + SetGlobalFlags: map[string]any{"last": 10}, + Teleport: 110, + }}, + }}, + Condition: &behavior.Condition{Room: 40}, }, + South: {Room: 99}, }, - OnEnter: []behavior.StepAction{ - {NodeAction: behavior.NodeAction{Teleport: 70}, SpawnMob: &behavior.SpawnMobConfig{DespawnRooms: []int{80}}}, - }, + OnEnter: []behavior.Trigger{{ + Condition: &behavior.Condition{Room: 20}, + Steps: []behavior.Step{{ + Teleport: 70, + SpawnMob: &behavior.SpawnMobConfig{DespawnRooms: []int{80}}, + }}, + }}, + OnExit: []behavior.Trigger{{ + Steps: []behavior.Step{{Teleport: 50}}, + }}, + OnFlagChange: []behavior.Trigger{{ + Condition: &behavior.Condition{Room: 30}, + Steps: []behavior.Step{{ + Teleport: 40, + SpawnMob: &behavior.SpawnMobConfig{DespawnRooms: []int{50, 60}}, + }}, + }}, Mobs: []RoomMob{ {ID: "guard", WanderRooms: []int{90, 100}}, }, @@ -38,40 +51,48 @@ func TestRoomRewriteRoomIDs(t *testing.T) { t.Fatal("expected changed=true") } - checkExit := func(dir ExitDir, want int) { - t.Helper() - if got := r.Exits[dir].Room; got != want { - t.Errorf("exit %s room = %d, want %d", dir, got, want) - } - } - checkExit(North, 11) - checkExit(South, 99) // unchanged (not in idMap) - - // Author set_flags values are NOT structural room references and must not - // be remapped (the old swapid regex wrongly rewrote these). - if v := r.Exits[North].OnTraverse[0].Action.SetGlobalFlags["last"]; v != 10 { + if got := r.Exits[North].Room; got != 11 { + t.Errorf("exit north room = %d, want 11", got) + } + if got := r.Exits[South].Room; got != 99 { + t.Errorf("exit south room = %d, want 99 (unchanged)", got) + } + // Author set_flags values are NOT structural room references and must not remap. + if v := r.Exits[North].OnTraverse[0].Steps[0].SetGlobalFlags["last"]; v != 10 { t.Errorf("set_global_flags value remapped: got %v, want 10", v) } - // Exit on_traverse teleport IS a structural room reference and must remap. - if r.Exits[North].OnTraverse[0].Action.Teleport != 111 { - t.Errorf("exit on_traverse teleport = %d, want 111", r.Exits[North].OnTraverse[0].Action.Teleport) + if got := r.Exits[North].OnTraverse[0].Steps[0].Teleport; got != 111 { + t.Errorf("on_traverse teleport = %d, want 111", got) } - - if r.Triggers[0].Room != 31 { - t.Errorf("trigger room = %d, want 31", r.Triggers[0].Room) + // Exit-level condition Room remaps. + if got := r.Exits[North].Condition.Room; got != 41 { + t.Errorf("exit condition room = %d, want 41", got) + } + // Trigger-level + per-step Condition.Room remaps. + if got := r.Exits[North].OnTraverse[0].Condition.Room; got != 61 { + t.Errorf("on_traverse trigger condition room = %d, want 61", got) } - if r.Triggers[0].Steps[0].Teleport != 41 { - t.Errorf("trigger teleport = %d, want 41", r.Triggers[0].Steps[0].Teleport) + if got := r.OnEnter[0].Condition.Room; got != 21 { + t.Errorf("on_enter trigger condition room = %d, want 21", got) } - if got := r.Triggers[0].Steps[0].SpawnMob.DespawnRooms; len(got) != 2 || got[0] != 51 || got[1] != 61 { - t.Errorf("trigger despawn_rooms = %v, want [51 61]", got) + if got := r.OnFlagChange[0].Condition.Room; got != 31 { + t.Errorf("on_flag_change condition room = %d, want 31", got) } - if r.OnEnter[0].Teleport != 71 { - t.Errorf("on_enter teleport = %d, want 71", r.OnEnter[0].Teleport) + if got := r.OnEnter[0].Steps[0].Teleport; got != 71 { + t.Errorf("on_enter teleport = %d, want 71", got) } - if got := r.OnEnter[0].SpawnMob.DespawnRooms; len(got) != 1 || got[0] != 81 { + if got := r.OnEnter[0].Steps[0].SpawnMob.DespawnRooms; len(got) != 1 || got[0] != 81 { t.Errorf("on_enter despawn_rooms = %v, want [81]", got) } + if got := r.OnExit[0].Steps[0].Teleport; got != 51 { + t.Errorf("on_exit teleport = %d, want 51", got) + } + if got := r.OnFlagChange[0].Steps[0].Teleport; got != 41 { + t.Errorf("on_flag_change teleport = %d, want 41", got) + } + if got := r.OnFlagChange[0].Steps[0].SpawnMob.DespawnRooms; len(got) != 2 || got[0] != 51 || got[1] != 61 { + t.Errorf("on_flag_change despawn_rooms = %v, want [51 61]", got) + } if got := r.Mobs[0].WanderRooms; len(got) != 2 || got[0] != 91 || got[1] != 101 { t.Errorf("mob wander_rooms = %v, want [91 101]", got) } @@ -81,7 +102,6 @@ func TestRoomRewriteRoomIDsNoChange(t *testing.T) { r := &Room{ Exits: map[ExitDir]ExitDef{North: {Room: 5}}, } - // idMap does not mention 5 -> nothing changes. if r.RewriteRoomIDs(map[int]int{99: 100}) { t.Error("expected changed=false when no references match") } @@ -100,7 +120,6 @@ func TestRoomRewriteRoomIDsSwapRoundTrips(t *testing.T) { if r.Exits[North].Room != 20 || r.Exits[South].Room != 10 { t.Errorf("after swap: north=%d south=%d, want north=20 south=10", r.Exits[North].Room, r.Exits[South].Room) } - // Applying the same swap again reverts (a swap is its own inverse). r.RewriteRoomIDs(swap) if r.Exits[North].Room != 10 || r.Exits[South].Room != 20 { t.Errorf("after double swap: north=%d south=%d, want north=10 south=20", r.Exits[North].Room, r.Exits[South].Room) @@ -114,7 +133,6 @@ func TestRoomRewriteRoomIDsIdempotentRename(t *testing.T) { if r.Exits[North].Room != 11 { t.Fatalf("after rename: room=%d, want 11", r.Exits[North].Room) } - // Second pass: 11 is not a key in idMap, so nothing changes. if r.RewriteRoomIDs(rename) { t.Error("expected changed=false on second pass of a rename idMap") } |
