feat(save): extend GameState to v2 — outfit and held items persisted per character
- Add held_left/held_right fields to CharacterData - Add get/set_character_outfit and get/set_character_held_item to GameState - get_save_data now returns version:2 with character_outfits and character_held_items - apply_save_data resets both dicts when keys absent (empty-dict reset safe) - 11 new tests in test_game_state.gd — 147/147 passing
This commit is contained in:
@@ -77,3 +77,71 @@ func test_apply_save_data_with_empty_dict_does_not_crash() -> void:
|
||||
_state.set_character_position("bunny_01", Vector2(10.0, 20.0))
|
||||
_state.apply_save_data({})
|
||||
assert_eq(_state.get_character_position("bunny_01"), Vector2(10.0, 20.0))
|
||||
|
||||
|
||||
func test_character_data_has_held_left_field() -> void:
|
||||
var cd: CharacterData = CharacterData.new()
|
||||
assert_eq(cd.held_left, "")
|
||||
|
||||
|
||||
func test_character_data_has_held_right_field() -> void:
|
||||
var cd: CharacterData = CharacterData.new()
|
||||
assert_eq(cd.held_right, "")
|
||||
|
||||
|
||||
func test_set_character_outfit_stores_value() -> void:
|
||||
_state.set_character_outfit("bunny_f", ["white_coat", "", "stethoscope"])
|
||||
assert_eq(_state.get_character_outfit("bunny_f"), ["white_coat", "", "stethoscope"])
|
||||
|
||||
|
||||
func test_get_character_outfit_returns_empty_array_for_unknown() -> void:
|
||||
var result: Array = _state.get_character_outfit("unknown_id")
|
||||
assert_eq(result, ["", "", ""])
|
||||
|
||||
|
||||
func test_set_character_held_item_left() -> void:
|
||||
_state.set_character_held_item("bunny_f", "left", "medicine_blue")
|
||||
assert_eq(_state.get_character_held_item("bunny_f", "left"), "medicine_blue")
|
||||
|
||||
|
||||
func test_get_character_held_item_returns_empty_for_unknown() -> void:
|
||||
assert_eq(_state.get_character_held_item("unknown", "left"), "")
|
||||
|
||||
|
||||
func test_save_data_includes_outfit() -> void:
|
||||
_state.set_character_outfit("bunny_f", ["white_coat", "", ""])
|
||||
var data: Dictionary = _state.get_save_data()
|
||||
assert_true(data.has("character_outfits"))
|
||||
assert_eq(data["character_outfits"]["bunny_f"], ["white_coat", "", ""])
|
||||
|
||||
|
||||
func test_save_data_includes_held_items() -> void:
|
||||
_state.set_character_held_item("bunny_f", "right", "medicine_blue")
|
||||
var data: Dictionary = _state.get_save_data()
|
||||
assert_true(data.has("character_held_items"))
|
||||
assert_eq(data["character_held_items"]["bunny_f"]["right"], "medicine_blue")
|
||||
|
||||
|
||||
func test_apply_save_data_restores_outfit() -> void:
|
||||
var save: Dictionary = {
|
||||
"character_outfits": {
|
||||
"bunny_f": ["doctor_coat", "", "stethoscope"]
|
||||
}
|
||||
}
|
||||
_state.apply_save_data(save)
|
||||
assert_eq(_state.get_character_outfit("bunny_f"), ["doctor_coat", "", "stethoscope"])
|
||||
|
||||
|
||||
func test_apply_save_data_restores_held_items() -> void:
|
||||
var save: Dictionary = {
|
||||
"character_held_items": {
|
||||
"kitten_f": {"left": "gel_tube", "right": ""}
|
||||
}
|
||||
}
|
||||
_state.apply_save_data(save)
|
||||
assert_eq(_state.get_character_held_item("kitten_f", "left"), "gel_tube")
|
||||
|
||||
|
||||
func test_save_data_has_version_two() -> void:
|
||||
var data: Dictionary = _state.get_save_data()
|
||||
assert_eq(data.get("version", 0), 2)
|
||||
|
||||
Reference in New Issue
Block a user