save format changes

This commit is contained in:
leca 2024-06-03 03:02:20 +03:00
parent 0626bf59ed
commit f35508958f
1 changed files with 10 additions and 15 deletions

View File

@ -20,7 +20,9 @@ func save_world():
var save_game = FileAccess.open("user://%s.save" % world_info.name, FileAccess.WRITE)
# Saving world info
save_game.store_line(JSON.stringify(world_info))
var world_save = world_info.duplicate()
world_save["node"] = "worldinfo"
save_game.store_line(JSON.stringify(world_save))
var save_nodes = get_tree().get_nodes_in_group("Persistent")
@ -55,16 +57,6 @@ func load_world(save_name):
var save_game = FileAccess.open("user://%s.save" % save_name, FileAccess.READ)
var json_string_world = save_game.get_line()
var json_world = JSON.new()
var parse_result_world = json_world.parse(json_string_world)
if not parse_result_world == OK:
print("JSON Parse Error: ", json_world.get_error_message(), " in ", json_string_world, " at line ", json_world.get_error_line())
return
world_info = json_world.get_data()
var earth = get_tree().root.get_node("world/Earth")
while save_game.get_position() < save_game.get_length():
@ -83,13 +75,16 @@ func load_world(save_name):
"tile":
new_object = preload("res://scenes/models/tile.tscn").instantiate()
earth.add_child(new_object)
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
new_object.add_to_group("Persistent")
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
new_object.add_to_group("Persistent")
new_object.update_tile()
"worldinfo":
world_info = node_data
world_info["node"] = null
continue
for i in node_data.keys():
if i == "node" or "pos" in i:
continue
new_object.set(i, node_data[i])
new_object.update_tile()
await get_tree().physics_frame
earth.mark_empty_tiles()