-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gameplay.gd
52 lines (45 loc) · 1.26 KB
/
Gameplay.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
extends Node2D
const SERIAL_CHILDREN = [
"Stations",
"Asteroids",
"Pickups",
"Npcs",
"Ships"
]
func _get_biome():
return Procgen.systems[Client.current_system].biome
func _ready():
if Client.current_system_data().state:
deserialize(Client.current_system_data().state)
else:
Procgen.do_spawns(Client.game_seed, Client.current_system, _get_biome(), self)
func serialize() -> Dictionary:
var children = {}
for child in SERIAL_CHILDREN:
children[child] = get_each_serialized(get_node(child))
return children
func get_each_serialized(node):
var list = []
for child in node.get_children():
if child.has_method("serialize"):
list.append({
"name": child.name,
"scene": child.filename,
"state": child.serialize(),
# "type": child.type
})
else:
breakpoint
print("No Serialization method, discarding: ", child.name)
return list
func deserialize(data: Dictionary):
for key in data.keys():
var node = get_node(key)
for serial_data in data[key]:
deserialize_entity(key, serial_data)
func deserialize_entity(destination, serial_data):
var node = get_node(destination)
var object = Client.cache_load(serial_data["scene"]).instance()
object.deserialize(serial_data["state"])
object.name = serial_data["name"]
node.add_child(object)