From deab7140f9415f0f5fea9240a291b976e507593f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 14 Apr 2023 11:32:40 -0400 Subject: Created rudimentary message display It shows when the player sends a location or receives an item. Currently it just shows IDs instead of names. We need to download all data packages so that we can read the names. We are also currently queueing a message when we send a location, which isn't the best because if that location turns out to contain an item for us, we'll get two messages. It would be better to hold off until we receive a PrintJSON message describing the location that was sent out. We also now cache the ID of the most recently processed item, so that on relaunch we know which items are new and should be announced. --- Archipelago/client.gd | 61 +++++++++++++++++++++++++++++++++++++++++++++---- Archipelago/load.gd | 16 +++++++++---- Archipelago/messages.gd | 35 ++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 Archipelago/messages.gd 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 = [] var _painting_ids_by_item = {} var _mentioned_paintings = [] var _panel_ids_by_location = {} +var _localdata_file = "" var _map_loaded = false var _held_items = [] var _held_locations = [] +var _last_new_item = -1 var _tower_floors = 0 signal client_connected @@ -135,6 +137,18 @@ func _on_data(): if _slot_data.has("panel_ids_by_location_id"): _panel_ids_by_location = _slot_data["panel_ids_by_location_id"] + _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot] + var ap_file = File.new() + if ap_file.file_exists(_localdata_file): + ap_file.open(_localdata_file, File.READ) + var localdata = ap_file.get_var(true) + ap_file.close() + + if localdata.size() > 0: + _last_new_item = localdata[0] + else: + _last_new_item = -1 + requestSync() emit_signal("client_connected") @@ -150,11 +164,19 @@ func _on_data(): _tower_floors = 0 _held_items = [] + var i = 0 for item in message["items"]: if _map_loaded: - processItem(item["item"]) + processItem(item["item"], message["index"] + i, item["player"]) else: - _held_items.append(item["item"]) + _held_items.append( + { + "item": item["item"], + "index": message["index"] + i, + "from": item["player"] + } + ) + i += 1 func _process(_delta): @@ -181,6 +203,23 @@ func saveSettings(): file.close() +func saveLocaldata(): + # Save the MW/slot specific settings to disk. + var dir = Directory.new() + var path = "user://archipelago" + if dir.dir_exists(path): + pass + else: + dir.make_dir(path) + + var file = File.new() + file.open(_localdata_file, File.WRITE) + + var data = [_last_new_item] + file.store_var(data, true) + file.close() + + func getSaveFileName(): return "zzAP_%s_%d" % [_seed, _slot] @@ -229,6 +268,9 @@ func requestSync(): func sendLocation(loc_id): if _map_loaded: sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) + + var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") + messages_node.showMessage("Sent %d" % loc_id) else: _held_locations.append(loc_id) @@ -240,7 +282,7 @@ func completedGoal(): func mapFinishedLoading(): if !_map_loaded: for item in _held_items: - processItem(item) + processItem(item["item"], item["index"], item["from"]) sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}]) @@ -249,7 +291,7 @@ func mapFinishedLoading(): _held_locations = [] -func processItem(item): +func processItem(item, index, from): global._print(item) var stringified = String(item) @@ -270,6 +312,17 @@ func processItem(item): processItem(_item_name_to_id[subitem_name]) _tower_floors += 1 + # Show a message about the item if it's new. + if index > _last_new_item: + _last_new_item = index + saveLocaldata() + + var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") + if from == _slot: + messages_node.showMessage("Found %d" % item) + else: + messages_node.showMessage("Received %d from %d" % [item, from]) + func doorIsVanilla(door): 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(): "answer_correct", location, "handle_correct" ) - # Hardcode THE END as the goal for now. - var the_end = self.get_node("Decorations/EndPanel/Panel_end_end") - the_end.get_node("Viewport/GUI/Panel/TextEdit").connect( - "answer_correct", apclient, "completedGoal" - ) + # Hardcode THE END as the goal for now. + var the_end = self.get_node("Decorations/EndPanel/Panel_end_end") + the_end.get_node("Viewport/GUI/Panel/TextEdit").connect( + "answer_correct", apclient, "completedGoal" + ) + + # Create the messages node. + var messages_script = ResourceLoader.load("user://maps/Archipelago/messages.gd") + var messages = messages_script.new() + messages.set_name("AP_Messages") + self.add_child(messages) # Proceed with the rest of the load. 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 @@ +extends Node + + +func _ready(): + var label = Label.new() + label.set_name("label") + label.margin_right = 1920.0 + label.margin_bottom = 1080.0 - 20 + label.margin_left = 20.0 + label.align = Label.ALIGN_LEFT + label.valign = Label.VALIGN_BOTTOM + + var dynamic_font = DynamicFont.new() + dynamic_font.font_data = load("res://fonts/Lingo.ttf") + dynamic_font.size = 36 + dynamic_font.outline_color = Color(0, 0, 0, 1) + dynamic_font.outline_size = 2 + label.add_font_override("font", dynamic_font) + + add_child(label) + + +func showMessage(text): + var label = self.get_node("label") + if !label.text == "": + label.text += "\n" + label.text += text + + yield(get_tree().create_timer(10.0), "timeout") + + var newline = label.text.find("\n") + if newline == -1: + label.text = "" + else: + label.text = label.text.substr(newline + 1) -- cgit 1.4.1