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:
@@ -63,7 +63,7 @@ func get_chest_state(chest_id: String) -> Array:
|
||||
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
|
||||
state_changed.emit()
|
||||
|
||||
@@ -108,6 +108,8 @@ func apply_save_data(data: Dictionary) -> void:
|
||||
_character_held_items = {}
|
||||
if data.has("object_states"):
|
||||
_object_states = data["object_states"]
|
||||
else:
|
||||
_object_states = {}
|
||||
if data.has("current_room"):
|
||||
current_room = data["current_room"]
|
||||
if data.has("music_volume"):
|
||||
|
||||
@@ -43,7 +43,10 @@ func _try_return_to_chest() -> bool:
|
||||
return false
|
||||
if global_position.distance_to(home_chest.global_position) >= CHEST_RETURN_RADIUS:
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
func test_save_data_has_version_two() -> void:
|
||||
func test_save_data_has_version_three() -> void:
|
||||
var data: Dictionary = _state.get_save_data()
|
||||
assert_eq(data.get("version", 0), 3)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user