diff options
Diffstat (limited to 'Archipelago')
-rw-r--r-- | Archipelago/client.gd | 61 | ||||
-rw-r--r-- | Archipelago/load.gd | 16 | ||||
-rw-r--r-- | Archipelago/messages.gd | 35 |
3 files changed, 103 insertions, 9 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index e8f9bba..be0ef2d 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd | |||
@@ -30,10 +30,12 @@ var _mentioned_doors = [] | |||
30 | var _painting_ids_by_item = {} | 30 | var _painting_ids_by_item = {} |
31 | var _mentioned_paintings = [] | 31 | var _mentioned_paintings = [] |
32 | var _panel_ids_by_location = {} | 32 | var _panel_ids_by_location = {} |
33 | var _localdata_file = "" | ||
33 | 34 | ||
34 | var _map_loaded = false | 35 | var _map_loaded = false |
35 | var _held_items = [] | 36 | var _held_items = [] |
36 | var _held_locations = [] | 37 | var _held_locations = [] |
38 | var _last_new_item = -1 | ||
37 | var _tower_floors = 0 | 39 | var _tower_floors = 0 |
38 | 40 | ||
39 | signal client_connected | 41 | signal client_connected |
@@ -135,6 +137,18 @@ func _on_data(): | |||
135 | if _slot_data.has("panel_ids_by_location_id"): | 137 | if _slot_data.has("panel_ids_by_location_id"): |
136 | _panel_ids_by_location = _slot_data["panel_ids_by_location_id"] | 138 | _panel_ids_by_location = _slot_data["panel_ids_by_location_id"] |
137 | 139 | ||
140 | _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot] | ||
141 | var ap_file = File.new() | ||
142 | if ap_file.file_exists(_localdata_file): | ||
143 | ap_file.open(_localdata_file, File.READ) | ||
144 | var localdata = ap_file.get_var(true) | ||
145 | ap_file.close() | ||
146 | |||
147 | if localdata.size() > 0: | ||
148 | _last_new_item = localdata[0] | ||
149 | else: | ||
150 | _last_new_item = -1 | ||
151 | |||
138 | requestSync() | 152 | requestSync() |
139 | 153 | ||
140 | emit_signal("client_connected") | 154 | emit_signal("client_connected") |
@@ -150,11 +164,19 @@ func _on_data(): | |||
150 | _tower_floors = 0 | 164 | _tower_floors = 0 |
151 | _held_items = [] | 165 | _held_items = [] |
152 | 166 | ||
167 | var i = 0 | ||
153 | for item in message["items"]: | 168 | for item in message["items"]: |
154 | if _map_loaded: | 169 | if _map_loaded: |
155 | processItem(item["item"]) | 170 | processItem(item["item"], message["index"] + i, item["player"]) |
156 | else: | 171 | else: |
157 | _held_items.append(item["item"]) | 172 | _held_items.append( |
173 | { | ||
174 | "item": item["item"], | ||
175 | "index": message["index"] + i, | ||
176 | "from": item["player"] | ||
177 | } | ||
178 | ) | ||
179 | i += 1 | ||
158 | 180 | ||
159 | 181 | ||
160 | func _process(_delta): | 182 | func _process(_delta): |
@@ -181,6 +203,23 @@ func saveSettings(): | |||
181 | file.close() | 203 | file.close() |
182 | 204 | ||
183 | 205 | ||
206 | func saveLocaldata(): | ||
207 | # Save the MW/slot specific settings to disk. | ||
208 | var dir = Directory.new() | ||
209 | var path = "user://archipelago" | ||
210 | if dir.dir_exists(path): | ||
211 | pass | ||
212 | else: | ||
213 | dir.make_dir(path) | ||
214 | |||
215 | var file = File.new() | ||
216 | file.open(_localdata_file, File.WRITE) | ||
217 | |||
218 | var data = [_last_new_item] | ||
219 | file.store_var(data, true) | ||
220 | file.close() | ||
221 | |||
222 | |||
184 | func getSaveFileName(): | 223 | func getSaveFileName(): |
185 | return "zzAP_%s_%d" % [_seed, _slot] | 224 | return "zzAP_%s_%d" % [_seed, _slot] |
186 | 225 | ||
@@ -229,6 +268,9 @@ func requestSync(): | |||
229 | func sendLocation(loc_id): | 268 | func sendLocation(loc_id): |
230 | if _map_loaded: | 269 | if _map_loaded: |
231 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) | 270 | sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) |
271 | |||
272 | var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") | ||
273 | messages_node.showMessage("Sent %d" % loc_id) | ||
232 | else: | 274 | else: |
233 | _held_locations.append(loc_id) | 275 | _held_locations.append(loc_id) |
234 | 276 | ||
@@ -240,7 +282,7 @@ func completedGoal(): | |||
240 | func mapFinishedLoading(): | 282 | func mapFinishedLoading(): |
241 | if !_map_loaded: | 283 | if !_map_loaded: |
242 | for item in _held_items: | 284 | for item in _held_items: |
243 | processItem(item) | 285 | processItem(item["item"], item["index"], item["from"]) |
244 | 286 | ||
245 | sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}]) | 287 | sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}]) |
246 | 288 | ||
@@ -249,7 +291,7 @@ func mapFinishedLoading(): | |||
249 | _held_locations = [] | 291 | _held_locations = [] |
250 | 292 | ||
251 | 293 | ||
252 | func processItem(item): | 294 | func processItem(item, index, from): |
253 | global._print(item) | 295 | global._print(item) |
254 | 296 | ||
255 | var stringified = String(item) | 297 | var stringified = String(item) |
@@ -270,6 +312,17 @@ func processItem(item): | |||
270 | processItem(_item_name_to_id[subitem_name]) | 312 | processItem(_item_name_to_id[subitem_name]) |
271 | _tower_floors += 1 | 313 | _tower_floors += 1 |
272 | 314 | ||
315 | # Show a message about the item if it's new. | ||
316 | if index > _last_new_item: | ||
317 | _last_new_item = index | ||
318 | saveLocaldata() | ||
319 | |||
320 | var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") | ||
321 | if from == _slot: | ||
322 | messages_node.showMessage("Found %d" % item) | ||
323 | else: | ||
324 | messages_node.showMessage("Received %d from %d" % [item, from]) | ||
325 | |||
273 | 326 | ||
274 | func doorIsVanilla(door): | 327 | func doorIsVanilla(door): |
275 | return !_mentioned_doors.has(door) | 328 | return !_mentioned_doors.has(door) |
diff --git a/Archipelago/load.gd b/Archipelago/load.gd index d17bfac..ca1269b 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd | |||
@@ -38,11 +38,17 @@ func _load(): | |||
38 | "answer_correct", location, "handle_correct" | 38 | "answer_correct", location, "handle_correct" |
39 | ) | 39 | ) |
40 | 40 | ||
41 | # Hardcode THE END as the goal for now. | 41 | # Hardcode THE END as the goal for now. |
42 | var the_end = self.get_node("Decorations/EndPanel/Panel_end_end") | 42 | var the_end = self.get_node("Decorations/EndPanel/Panel_end_end") |
43 | the_end.get_node("Viewport/GUI/Panel/TextEdit").connect( | 43 | the_end.get_node("Viewport/GUI/Panel/TextEdit").connect( |
44 | "answer_correct", apclient, "completedGoal" | 44 | "answer_correct", apclient, "completedGoal" |
45 | ) | 45 | ) |
46 | |||
47 | # Create the messages node. | ||
48 | var messages_script = ResourceLoader.load("user://maps/Archipelago/messages.gd") | ||
49 | var messages = messages_script.new() | ||
50 | messages.set_name("AP_Messages") | ||
51 | self.add_child(messages) | ||
46 | 52 | ||
47 | # Proceed with the rest of the load. | 53 | # Proceed with the rest of the load. |
48 | global._print("Hooked Load End") | 54 | global._print("Hooked Load End") |
diff --git a/Archipelago/messages.gd b/Archipelago/messages.gd new file mode 100644 index 0000000..63ce182 --- /dev/null +++ b/Archipelago/messages.gd | |||
@@ -0,0 +1,35 @@ | |||
1 | extends Node | ||
2 | |||
3 | |||
4 | func _ready(): | ||
5 | var label = Label.new() | ||
6 | label.set_name("label") | ||
7 | label.margin_right = 1920.0 | ||
8 | label.margin_bottom = 1080.0 - 20 | ||
9 | label.margin_left = 20.0 | ||
10 | label.align = Label.ALIGN_LEFT | ||
11 | label.valign = Label.VALIGN_BOTTOM | ||
12 | |||
13 | var dynamic_font = DynamicFont.new() | ||
14 | dynamic_font.font_data = load("res://fonts/Lingo.ttf") | ||
15 | dynamic_font.size = 36 | ||
16 | dynamic_font.outline_color = Color(0, 0, 0, 1) | ||
17 | dynamic_font.outline_size = 2 | ||
18 | label.add_font_override("font", dynamic_font) | ||
19 | |||
20 | add_child(label) | ||
21 | |||
22 | |||
23 | func showMessage(text): | ||
24 | var label = self.get_node("label") | ||
25 | if !label.text == "": | ||
26 | label.text += "\n" | ||
27 | label.text += text | ||
28 | |||
29 | yield(get_tree().create_timer(10.0), "timeout") | ||
30 | |||
31 | var newline = label.text.find("\n") | ||
32 | if newline == -1: | ||
33 | label.text = "" | ||
34 | else: | ||
35 | label.text = label.text.substr(newline + 1) | ||