07c3b996d7
- 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
148 lines
4.8 KiB
GDScript
148 lines
4.8 KiB
GDScript
## Tests for GameState — character positions, object states, save/load round-trip.
|
|
extends GutTest
|
|
|
|
const GameStateScript: GDScript = preload("res://scripts/autoload/GameState.gd")
|
|
|
|
var _state: Node
|
|
|
|
|
|
func before_each() -> void:
|
|
_state = GameStateScript.new()
|
|
add_child_autofree(_state)
|
|
|
|
|
|
func test_get_character_position_default_is_zero() -> void:
|
|
assert_eq(_state.get_character_position("bunny_01"), Vector2.ZERO)
|
|
|
|
|
|
func test_has_character_position_returns_false_for_unknown_id() -> void:
|
|
assert_false(_state.has_character_position("bunny_01"))
|
|
|
|
|
|
func test_set_character_position_stores_value() -> void:
|
|
_state.set_character_position("bunny_01", Vector2(100.0, 200.0))
|
|
assert_eq(_state.get_character_position("bunny_01"), Vector2(100.0, 200.0))
|
|
|
|
|
|
func test_has_character_position_returns_true_after_set() -> void:
|
|
_state.set_character_position("bunny_01", Vector2(50.0, 50.0))
|
|
assert_true(_state.has_character_position("bunny_01"))
|
|
|
|
|
|
func test_set_character_position_emits_character_moved() -> void:
|
|
watch_signals(_state)
|
|
_state.set_character_position("bunny_01", Vector2(100.0, 200.0))
|
|
assert_signal_emitted(_state, "character_moved")
|
|
|
|
|
|
func test_set_character_position_emits_state_changed() -> void:
|
|
watch_signals(_state)
|
|
_state.set_character_position("bunny_01", Vector2(100.0, 200.0))
|
|
assert_signal_emitted(_state, "state_changed")
|
|
|
|
|
|
func test_get_object_state_default_is_idle() -> void:
|
|
assert_eq(_state.get_object_state("gift_box_1"), "idle")
|
|
|
|
|
|
func test_set_object_state_stores_value() -> void:
|
|
_state.set_object_state("gift_box_1", "open")
|
|
assert_eq(_state.get_object_state("gift_box_1"), "open")
|
|
|
|
|
|
func test_set_object_state_emits_state_changed() -> void:
|
|
watch_signals(_state)
|
|
_state.set_object_state("gift_box_1", "open")
|
|
assert_signal_emitted(_state, "state_changed")
|
|
|
|
|
|
func test_save_data_round_trip_character_position() -> void:
|
|
_state.set_character_position("bunny_01", Vector2(100.0, 200.0))
|
|
var data: Dictionary = _state.get_save_data()
|
|
_state.set_character_position("bunny_01", Vector2.ZERO)
|
|
_state.apply_save_data(data)
|
|
assert_eq(_state.get_character_position("bunny_01"), Vector2(100.0, 200.0))
|
|
|
|
|
|
func test_save_data_round_trip_object_state() -> void:
|
|
_state.set_object_state("gift_box_1", "open")
|
|
var data: Dictionary = _state.get_save_data()
|
|
var state2: Node = GameStateScript.new()
|
|
add_child_autofree(state2)
|
|
state2.apply_save_data(data)
|
|
assert_eq(state2.get_object_state("gift_box_1"), "open")
|
|
|
|
|
|
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)
|