fix(core): serialize character positions as [x,y] arrays for JSON compatibility
Vector2 is not a JSON-native type — JSON.stringify converts it to a string, which cannot be assigned back to a Vector2 return type on load. Positions are now saved as [x, y] float arrays and reconstructed as Vector2 in apply_save_data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,8 +35,12 @@ func set_object_state(id: String, state: String) -> void:
|
||||
|
||||
|
||||
func get_save_data() -> Dictionary:
|
||||
var positions: Dictionary = {}
|
||||
for key: String in _character_positions:
|
||||
var pos: Vector2 = _character_positions[key]
|
||||
positions[key] = [pos.x, pos.y]
|
||||
return {
|
||||
"character_positions": _character_positions,
|
||||
"character_positions": positions,
|
||||
"object_states": _object_states,
|
||||
"current_room": current_room,
|
||||
"music_volume": music_volume,
|
||||
@@ -46,7 +50,11 @@ func get_save_data() -> Dictionary:
|
||||
|
||||
func apply_save_data(data: Dictionary) -> void:
|
||||
if data.has("character_positions"):
|
||||
_character_positions = data["character_positions"]
|
||||
_character_positions = {}
|
||||
for key: String in data["character_positions"]:
|
||||
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("object_states"):
|
||||
_object_states = data["object_states"]
|
||||
if data.has("current_room"):
|
||||
|
||||
Reference in New Issue
Block a user