fix(items): safe cast in _try_return_to_chest, typed chest state param, object_states reset

- Replace unsafe direct cast in HoldableItem._try_return_to_chest() with guarded as-cast
- Type set_chest_state() parameter as Array[String] to match RoomChest._get_spawned_ids()
- Add else-branch in apply_save_data() to reset _object_states when key absent
- Rename test_save_data_has_version_two to test_save_data_has_version_three
This commit is contained in:
Steven Wroblewski
2026-05-09 01:12:29 +02:00
parent 96ec053331
commit 87db92955a
3 changed files with 8 additions and 3 deletions
+3 -1
View File
@@ -63,7 +63,7 @@ func get_chest_state(chest_id: String) -> Array:
return _chest_states.get(chest_id, []) return _chest_states.get(chest_id, [])
func set_chest_state(chest_id: String, spawned_item_ids: Array) -> void: func set_chest_state(chest_id: String, spawned_item_ids: Array[String]) -> void:
_chest_states[chest_id] = spawned_item_ids _chest_states[chest_id] = spawned_item_ids
state_changed.emit() state_changed.emit()
@@ -108,6 +108,8 @@ func apply_save_data(data: Dictionary) -> void:
_character_held_items = {} _character_held_items = {}
if data.has("object_states"): if data.has("object_states"):
_object_states = data["object_states"] _object_states = data["object_states"]
else:
_object_states = {}
if data.has("current_room"): if data.has("current_room"):
current_room = data["current_room"] current_room = data["current_room"]
if data.has("music_volume"): if data.has("music_volume"):
+4 -1
View File
@@ -43,7 +43,10 @@ func _try_return_to_chest() -> bool:
return false return false
if global_position.distance_to(home_chest.global_position) >= CHEST_RETURN_RADIUS: if global_position.distance_to(home_chest.global_position) >= CHEST_RETURN_RADIUS:
return false return false
(home_chest as RoomChest).receive_item(self) var chest: RoomChest = home_chest as RoomChest
if chest == null:
return false
chest.receive_item(self)
return true return true
+1 -1
View File
@@ -142,7 +142,7 @@ func test_apply_save_data_restores_held_items() -> void:
assert_eq(_state.get_character_held_item("kitten_f", "left"), "gel_tube") assert_eq(_state.get_character_held_item("kitten_f", "left"), "gel_tube")
func test_save_data_has_version_two() -> void: func test_save_data_has_version_three() -> void:
var data: Dictionary = _state.get_save_data() var data: Dictionary = _state.get_save_data()
assert_eq(data.get("version", 0), 3) assert_eq(data.get("version", 0), 3)