save format changes
This commit is contained in:
parent
0626bf59ed
commit
f35508958f
|
@ -20,7 +20,9 @@ func save_world():
|
||||||
var save_game = FileAccess.open("user://%s.save" % world_info.name, FileAccess.WRITE)
|
var save_game = FileAccess.open("user://%s.save" % world_info.name, FileAccess.WRITE)
|
||||||
|
|
||||||
# Saving world info
|
# 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")
|
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 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")
|
var earth = get_tree().root.get_node("world/Earth")
|
||||||
|
|
||||||
while save_game.get_position() < save_game.get_length():
|
while save_game.get_position() < save_game.get_length():
|
||||||
|
@ -83,13 +75,16 @@ func load_world(save_name):
|
||||||
"tile":
|
"tile":
|
||||||
new_object = preload("res://scenes/models/tile.tscn").instantiate()
|
new_object = preload("res://scenes/models/tile.tscn").instantiate()
|
||||||
earth.add_child(new_object)
|
earth.add_child(new_object)
|
||||||
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
|
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
|
||||||
new_object.add_to_group("Persistent")
|
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():
|
for i in node_data.keys():
|
||||||
if i == "node" or "pos" in i:
|
if i == "node" or "pos" in i:
|
||||||
continue
|
continue
|
||||||
new_object.set(i, node_data[i])
|
new_object.set(i, node_data[i])
|
||||||
new_object.update_tile()
|
|
||||||
await get_tree().physics_frame
|
await get_tree().physics_frame
|
||||||
earth.mark_empty_tiles()
|
earth.mark_empty_tiles()
|
||||||
|
|
Loading…
Reference in New Issue