fix: preserve mutable floor entities compatibility
This commit is contained in:
@@ -26,3 +26,20 @@ SCRIPT ERROR: Parse Error: Cannot find member REFERENCE_VIEWPORT in base Game
|
|||||||
```
|
```
|
||||||
|
|
||||||
The runner exited with status `1`.
|
The runner exited with status `1`.
|
||||||
|
|
||||||
|
## B1 P1 — mutable `FloorState.entities` compatibility
|
||||||
|
|
||||||
|
### Root cause and resolution
|
||||||
|
|
||||||
|
`FloorState.entities` was aggregating `enemies` and `npcs` into a newly allocated dictionary on every read. Consequently, normal legacy operations such as `floor.entities[id] = actor` and `floor.entities.erase(id)` modified only that temporary dictionary.
|
||||||
|
|
||||||
|
The compatibility property now returns the real `enemies` dictionary. `enemies` and `npcs` remain explicit canonical collections; floor serialization continues to write separate `enemies` and `npcs` dictionaries, and the existing lossless `explored_cells` value serialization is unchanged. `GameState` continues to use the canonical `enemies` API.
|
||||||
|
|
||||||
|
### Compatibility coverage
|
||||||
|
|
||||||
|
`test_floor_state_entities_remains_a_mutable_legacy_enemy_alias` assigns the legacy dictionary, performs an indexed set through `entities`, verifies both actors exist in canonical `enemies`, then erases through `entities` and verifies the canonical store is updated.
|
||||||
|
|
||||||
|
### Verification
|
||||||
|
|
||||||
|
- `scripts/test-unit.sh`: passed — 62 tests, 546 assertions.
|
||||||
|
- `scripts/verify.sh`: passed — unit (62 tests, 546 assertions), integration (1 test, 13 assertions), E2E (18 tests, 199 assertions), and visual checks.
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ var entrance := Vector2i.ZERO
|
|||||||
var exit := Vector2i.ZERO
|
var exit := Vector2i.ZERO
|
||||||
var enemies: Dictionary[StringName, ActorState] = {}
|
var enemies: Dictionary[StringName, ActorState] = {}
|
||||||
var npcs: Dictionary[StringName, ActorState] = {}
|
var npcs: Dictionary[StringName, ActorState] = {}
|
||||||
# Legacy callers use the generic actor view. New floor code owns the explicit
|
# Legacy callers mutate the generic actor dictionary directly. It must remain
|
||||||
# collections above; this compatibility view is derived from both of them.
|
# the real enemy store rather than an aggregate snapshot; NPCs stay explicit.
|
||||||
var entities: Dictionary[StringName, ActorState]:
|
var entities: Dictionary[StringName, ActorState]:
|
||||||
get:
|
get:
|
||||||
var all_entities: Dictionary[StringName, ActorState] = {}
|
return enemies
|
||||||
for actor_id in enemies:
|
|
||||||
all_entities[actor_id] = enemies[actor_id]
|
|
||||||
for actor_id in npcs:
|
|
||||||
all_entities[actor_id] = npcs[actor_id]
|
|
||||||
return all_entities
|
|
||||||
set(value):
|
set(value):
|
||||||
enemies = value
|
enemies = value
|
||||||
npcs.clear()
|
npcs.clear()
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ func test_floor_state_round_trip_preserves_rooms_tiles_and_floor_collections() -
|
|||||||
var serialized := floor.to_dict()
|
var serialized := floor.to_dict()
|
||||||
var restored := FloorStateType.from_dict(serialized)
|
var restored := FloorStateType.from_dict(serialized)
|
||||||
|
|
||||||
|
assert_true(serialized.has("enemies"))
|
||||||
|
assert_true(serialized.has("npcs"))
|
||||||
|
assert_false(serialized.has("entities"))
|
||||||
assert_eq(restored.seed, 8675309)
|
assert_eq(restored.seed, 8675309)
|
||||||
assert_eq(restored.floor_number, 3)
|
assert_eq(restored.floor_number, 3)
|
||||||
assert_eq(restored.rooms.size(), 2)
|
assert_eq(restored.rooms.size(), 2)
|
||||||
@@ -44,7 +47,7 @@ func test_floor_state_round_trip_preserves_rooms_tiles_and_floor_collections() -
|
|||||||
assert_eq(restored.enemies[&"goblin"].cell, Vector2i(5, 4))
|
assert_eq(restored.enemies[&"goblin"].cell, Vector2i(5, 4))
|
||||||
assert_eq(restored.npcs[&"guide"].cell, Vector2i(3, 3))
|
assert_eq(restored.npcs[&"guide"].cell, Vector2i(3, 3))
|
||||||
assert_true(restored.entities.has(&"goblin"))
|
assert_true(restored.entities.has(&"goblin"))
|
||||||
assert_true(restored.entities.has(&"guide"))
|
assert_false(restored.entities.has(&"guide"))
|
||||||
assert_eq(restored.chests[Vector2i(3, 2)], {"opened": false, "loot": [{"id": "potion_minor", "quantity": 2}]})
|
assert_eq(restored.chests[Vector2i(3, 2)], {"opened": false, "loot": [{"id": "potion_minor", "quantity": 2}]})
|
||||||
assert_eq(restored.ground_items[Vector2i(4, 2)], [{"id": "gold", "quantity": 10}])
|
assert_eq(restored.ground_items[Vector2i(4, 2)], [{"id": "gold", "quantity": 10}])
|
||||||
assert_eq(restored.events, [{"id": "entry_event", "resolved": false}])
|
assert_eq(restored.events, [{"id": "entry_event", "resolved": false}])
|
||||||
@@ -52,14 +55,23 @@ func test_floor_state_round_trip_preserves_rooms_tiles_and_floor_collections() -
|
|||||||
assert_eq(restored.explored_cells[Vector2i(2, 3)], false)
|
assert_eq(restored.explored_cells[Vector2i(2, 3)], false)
|
||||||
assert_eq(restored.metadata, {"theme": "ruins", "difficulty": 2})
|
assert_eq(restored.metadata, {"theme": "ruins", "difficulty": 2})
|
||||||
|
|
||||||
func test_floor_state_entities_remains_a_legacy_enemy_alias() -> void:
|
func test_floor_state_entities_remains_a_mutable_legacy_enemy_alias() -> void:
|
||||||
var floor := FloorStateType.new(GridMapStateType.new(Vector2i(2, 2)))
|
var floor := FloorStateType.new(GridMapStateType.new(Vector2i(2, 2)))
|
||||||
var goblin := ActorStateType.new(&"goblin", Vector2i(1, 1), 6, 2)
|
var goblin := ActorStateType.new(&"goblin", Vector2i(1, 1), 6, 2)
|
||||||
|
var orc := ActorStateType.new(&"orc", Vector2i(0, 1), 8, 3)
|
||||||
|
|
||||||
floor.entities = {&"goblin": goblin}
|
floor.entities = {&"goblin": goblin}
|
||||||
|
floor.entities[&"orc"] = orc
|
||||||
|
|
||||||
assert_same(floor.entities[&"goblin"], floor.enemies[&"goblin"])
|
assert_same(floor.entities[&"goblin"], floor.enemies[&"goblin"])
|
||||||
|
assert_same(floor.entities[&"orc"], floor.enemies[&"orc"])
|
||||||
assert_same(floor.enemies[&"goblin"], goblin)
|
assert_same(floor.enemies[&"goblin"], goblin)
|
||||||
|
assert_same(floor.enemies[&"orc"], orc)
|
||||||
|
|
||||||
|
floor.entities.erase(&"goblin")
|
||||||
|
|
||||||
|
assert_false(floor.entities.has(&"goblin"))
|
||||||
|
assert_false(floor.enemies.has(&"goblin"))
|
||||||
assert_false(floor.npcs.has(&"goblin"))
|
assert_false(floor.npcs.has(&"goblin"))
|
||||||
|
|
||||||
func test_floor_state_deserializes_legacy_entities_and_explored_cell_arrays() -> void:
|
func test_floor_state_deserializes_legacy_entities_and_explored_cell_arrays() -> void:
|
||||||
|
|||||||
Reference in New Issue
Block a user