about summary refs log tree commit diff stats
path: root/Archipelago/load.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Archipelago/load.gd')
-rw-r--r--Archipelago/load.gd76
1 files changed, 76 insertions, 0 deletions
diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 47f51a6..3c6b31c 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd
@@ -90,6 +90,52 @@ func _load():
90 target_panel_node.text = source["hint"] 90 target_panel_node.text = source["hint"]
91 target_panel_node.answer = source["answer"] 91 target_panel_node.answer = source["answer"]
92 92
93 # Randomize the paintings, if necessary.
94 if apclient._painting_shuffle:
95 var pd_script = ResourceLoader.load("user://maps/Archipelago/paintingdata.gd")
96 var pd = pd_script.new()
97 pd.set_name("AP_Paintings")
98 self.add_child(pd)
99
100 var all_paintings = pd.kALL_PAINTINGS
101
102 var classes = {}
103 for painting in apclient._paintings_mapping.values():
104 if not classes.has(painting):
105 var i = rng.randi_range(0, all_paintings.size() - 1)
106 var chosen = all_paintings[i]
107 classes[painting] = chosen
108 all_paintings.remove(i)
109
110 var randomized = []
111 for painting in apclient._paintings_mapping.values():
112 var painting_class = classes[painting]
113 instantiate_painting(painting, painting_class)
114 randomized.append(painting)
115
116 for source_painting in apclient._paintings_mapping.keys():
117 var target_painting = apclient._paintings_mapping[source_painting]
118 var painting_class = classes[target_painting]
119 var new_source = instantiate_painting(source_painting, painting_class)
120 new_source.target = pd.get_node(target_painting).get_node("Script")
121 randomized.append(source_painting)
122
123 var remaining_size = classes.size() / 2
124 if remaining_size >= all_paintings.size():
125 remaining_size = all_paintings.size()
126 var remaining = []
127 for i in range(0, remaining_size):
128 var j = rng.randi_range(0, all_paintings.size() - 1)
129 remaining.append(all_paintings[j])
130 all_paintings.remove(j)
131
132 for painting in apclient._paintings.keys():
133 if randomized.has(painting):
134 continue
135
136 var chosen_painting = remaining[rng.randi_range(0, remaining.size() - 1)]
137 instantiate_painting(painting, chosen_painting)
138
93 # Attach a script to every panel so that we can do things like conditionally 139 # Attach a script to every panel so that we can do things like conditionally
94 # disable them. 140 # disable them.
95 var panel_script = ResourceLoader.load("user://maps/Archipelago/panel.gd") 141 var panel_script = ResourceLoader.load("user://maps/Archipelago/panel.gd")
@@ -130,3 +176,33 @@ func _load():
130 176
131func sort_by_link(a, b): 177func sort_by_link(a, b):
132 return a["link"] < b["link"] 178 return a["link"] < b["link"]
179
180
181func instantiate_painting(name, scene):
182 var apclient = global.get_node("Archipelago")
183
184 var scene_path = "res://nodes/paintings/%s.tscn" % scene
185 var painting_scene = load(scene_path)
186 var new_painting = painting_scene.instance()
187 new_painting.set_name(name)
188
189 var old_painting = self.get_node("Decorations/Paintings").get_node(name)
190 new_painting.translation = old_painting.translation
191 new_painting.rotation = old_painting.rotation
192
193 var mypainting_script = ResourceLoader.load("user://maps/Archipelago/mypainting.gd")
194 var mps_inst = mypainting_script.new()
195 mps_inst.set_name("Script")
196
197 var pconfig = apclient._paintings[name]
198 mps_inst.orientation = pconfig["orientation"]
199 if pconfig["move"]:
200 mps_inst.move = true
201 mps_inst.move_to_x = old_painting.move_to_x
202 mps_inst.move_to_z = old_painting.move_to_z
203 mps_inst.key = old_painting.key
204
205 self.get_node("AP_Paintings").add_child(new_painting)
206 new_painting.add_child(mps_inst)
207 old_painting.queue_free()
208 return mps_inst