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:
@@ -1,10 +1,12 @@
|
||||
## GameState — global game state: character positions, object states, current room.
|
||||
## GameState — global game state: character positions, outfit, held items, object states, current room.
|
||||
extends Node
|
||||
|
||||
signal state_changed
|
||||
signal character_moved(character_id: String, position: Vector2)
|
||||
|
||||
var _character_positions: Dictionary = {}
|
||||
var _character_outfits: Dictionary = {}
|
||||
var _character_held_items: Dictionary = {}
|
||||
var _object_states: Dictionary = {}
|
||||
var current_room: String = "reception"
|
||||
var music_volume: float = 0.6
|
||||
@@ -25,6 +27,28 @@ func set_character_position(id: String, pos: Vector2) -> void:
|
||||
state_changed.emit()
|
||||
|
||||
|
||||
func get_character_outfit(id: String) -> Array:
|
||||
return _character_outfits.get(id, ["", "", ""])
|
||||
|
||||
|
||||
func set_character_outfit(id: String, outfit: Array) -> void:
|
||||
_character_outfits[id] = outfit
|
||||
state_changed.emit()
|
||||
|
||||
|
||||
func get_character_held_item(id: String, hand: String) -> String:
|
||||
if not _character_held_items.has(id):
|
||||
return ""
|
||||
return _character_held_items[id].get(hand, "")
|
||||
|
||||
|
||||
func set_character_held_item(id: String, hand: String, item_id: String) -> void:
|
||||
if not _character_held_items.has(id):
|
||||
_character_held_items[id] = {"left": "", "right": ""}
|
||||
_character_held_items[id][hand] = item_id
|
||||
state_changed.emit()
|
||||
|
||||
|
||||
func get_object_state(id: String) -> String:
|
||||
return _object_states.get(id, "idle")
|
||||
|
||||
@@ -40,7 +64,10 @@ func get_save_data() -> Dictionary:
|
||||
var pos: Vector2 = _character_positions[key]
|
||||
positions[key] = [pos.x, pos.y]
|
||||
return {
|
||||
"version": 2,
|
||||
"character_positions": positions,
|
||||
"character_outfits": _character_outfits.duplicate(true),
|
||||
"character_held_items": _character_held_items.duplicate(true),
|
||||
"object_states": _object_states,
|
||||
"current_room": current_room,
|
||||
"music_volume": music_volume,
|
||||
@@ -55,6 +82,14 @@ func apply_save_data(data: Dictionary) -> void:
|
||||
var val: Variant = data["character_positions"][key]
|
||||
if val is Array and val.size() >= 2:
|
||||
_character_positions[key] = Vector2(val[0], val[1])
|
||||
if data.has("character_outfits"):
|
||||
_character_outfits = data["character_outfits"].duplicate(true)
|
||||
else:
|
||||
_character_outfits = {}
|
||||
if data.has("character_held_items"):
|
||||
_character_held_items = data["character_held_items"].duplicate(true)
|
||||
else:
|
||||
_character_held_items = {}
|
||||
if data.has("object_states"):
|
||||
_object_states = data["object_states"]
|
||||
if data.has("current_room"):
|
||||
|
||||
Reference in New Issue
Block a user