From 3dc880b18277e4587aeb167f1f831bc8f1b9bf48 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 11 Sep 2023 16:52:39 -0400 Subject: Use static item/location IDs --- Archipelago/client.gd | 8 +++--- Archipelago/load.gd | 41 ++++++++++++++---------------- util/generate_gamedata.rb | 65 ++++++++++++++++++----------------------------- 3 files changed, 48 insertions(+), 66 deletions(-) diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 9f15506..068f300 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -588,16 +588,16 @@ func processItem(item, index, from, flags): if _item_id_to_name.has(item): item_name = _item_id_to_name[item] - if gamedata.door_ids_by_item_id.has(item_name): + if gamedata.door_ids_by_item_id.has(int(item)): var doorsNode = get_tree().get_root().get_node("Spatial/Doors") - for door_id in gamedata.door_ids_by_item_id[item_name]: + for door_id in gamedata.door_ids_by_item_id[int(item)]: doorsNode.get_node(door_id).openDoor() - if gamedata.painting_ids_by_item_id.has(item_name): + if gamedata.painting_ids_by_item_id.has(int(item)): var real_parent_node = get_tree().get_root().get_node("Spatial/Decorations/Paintings") var fake_parent_node = get_tree().get_root().get_node_or_null("Spatial/AP_Paintings") - for painting_id in gamedata.painting_ids_by_item_id[item_name]: + for painting_id in gamedata.painting_ids_by_item_id[int(item)]: var painting_node = real_parent_node.get_node_or_null(painting_id) if painting_node != null: painting_node.movePainting() diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 876910b..d2977dd 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -114,28 +114,25 @@ func _load(): var panels_parent = self.get_node("Panels") var location_script = ResourceLoader.load("user://maps/Archipelago/location.gd") for location_id in gamedata.panel_ids_by_location_id.keys(): - if apclient._location_name_to_id.has(location_id): - var location = location_script.new() - location.ap_id = int(apclient._location_name_to_id[location_id]) - location.name = "AP_location_%d" % location.ap_id - location.classification = gamedata.classification_by_location_id[location_id] - self.add_child(location) - - var panels = gamedata.panel_ids_by_location_id[location_id] - location.total = panels.size() - - for panel in panels: - var that_panel - if panel.begins_with("EndPanel"): - that_panel = self.get_node("Decorations").get_node(panel) - else: - that_panel = panels_parent.get_node(panel) - - that_panel.get_node("Viewport/GUI/Panel/TextEdit").connect( - "answer_correct", location, "handle_correct" - ) - else: - global._print("Could not find location ID for %s" % location_id) + var location = location_script.new() + location.ap_id = location_id + location.name = "AP_location_%d" % location.ap_id + location.classification = gamedata.classification_by_location_id[location_id] + self.add_child(location) + + var panels = gamedata.panel_ids_by_location_id[location_id] + location.total = panels.size() + + for panel in panels: + var that_panel + if panel.begins_with("EndPanel"): + that_panel = self.get_node("Decorations").get_node(panel) + else: + that_panel = panels_parent.get_node(panel) + + that_panel.get_node("Viewport/GUI/Panel/TextEdit").connect( + "answer_correct", location, "handle_correct" + ) # HOT CRUSTS should be at eye-level, have a yellow block behind it, and # not vanish when solved. diff --git a/util/generate_gamedata.rb b/util/generate_gamedata.rb index 72f0932..e130572 100644 --- a/util/generate_gamedata.rb +++ b/util/generate_gamedata.rb @@ -2,7 +2,8 @@ require 'set' require 'yaml' configpath = ARGV[0] -outputpath = ARGV[1] +idspath = ARGV[1] +outputpath = ARGV[2] CLASSIFICATION_NORMAL = 1 CLASSIFICATION_REDUCED = 2 @@ -20,10 +21,14 @@ mentioned_doors = Set[] mentioned_paintings = Set[] painting_output = {} +ids_config = YAML.load_file(idspath) + config = YAML.load_file(configpath) config.each do |room_name, room_data| if room_data.include? "panels" room_data["panels"].each do |panel_name, panel| + location_id = ids_config["panels"][room_name][panel_name] + full_name = "#{room_name} - #{panel_name}" panel_to_id[full_name] = panel["id"] @@ -59,16 +64,16 @@ config.each do |room_name, room_data| end panel_output << ret - panel_ids_by_location_id[full_name] = [panel["id"]] + panel_ids_by_location_id[location_id] = [panel["id"]] - classification_by_location_id[full_name] ||= 0 - classification_by_location_id[full_name] += CLASSIFICATION_INSANITY + classification_by_location_id[location_id] ||= 0 + classification_by_location_id[location_id] += CLASSIFICATION_INSANITY if panel.include? "check" and panel["check"] - classification_by_location_id[full_name] += CLASSIFICATION_NORMAL + classification_by_location_id[location_id] += CLASSIFICATION_NORMAL unless panel.include? "exclude_reduce" and panel["exclude_reduce"] - classification_by_location_id[full_name] += CLASSIFICATION_REDUCED + classification_by_location_id[location_id] += CLASSIFICATION_REDUCED end end end @@ -90,27 +95,9 @@ config.each do |room_name, room_data| not (door.include? "event" and door["event"]) and door.include? "panels" then - chosen_name = full_name - if door.include? "location_name" - chosen_name = door["location_name"] - else - panels_per_room = {} - door["panels"].each do |panel_identifier| - if panel_identifier.kind_of? String - panels_per_room[room_name] ||= [] - panels_per_room[room_name] << panel_identifier - else - panels_per_room[panel_identifier["room"]] ||= [] - panels_per_room[panel_identifier["room"]] << panel_identifier["panel"] - end - end + location_id = ids_config["doors"][room_name][door_name]["location"] - chosen_name = panels_per_room.map do |room_name, panels| - room_name + " - " + panels.join(", ") - end.join(" and ") - end - - panel_ids_by_location_id[chosen_name] = door["panels"].map do |panel_identifier| + panel_ids_by_location_id[location_id] = door["panels"].map do |panel_identifier| other_name = "" if panel_identifier.kind_of? String other_name = "#{room_name} - #{panel_identifier}" @@ -120,21 +107,18 @@ config.each do |room_name, room_data| panel_to_id[other_name] end - classification_by_location_id[chosen_name] ||= 0 - classification_by_location_id[chosen_name] += CLASSIFICATION_NORMAL + classification_by_location_id[location_id] ||= 0 + classification_by_location_id[location_id] += CLASSIFICATION_NORMAL if door.include? "include_reduce" and door["include_reduce"] - classification_by_location_id[chosen_name] += CLASSIFICATION_REDUCED + classification_by_location_id[location_id] += CLASSIFICATION_REDUCED end end if not (door.include? "skip_item" and door["skip_item"]) and not (door.include? "event" and door["event"]) then - chosen_name = full_name - if door.include? "item_name" - chosen_name = door["item_name"] - end + item_id = ids_config["doors"][room_name][door_name]["item"] if door.include? "id" internal_door_ids = [] @@ -149,7 +133,7 @@ config.each do |room_name, room_data| door_groups[door["group"]].merge(internal_door_ids) end - door_ids_by_item_id[chosen_name] = internal_door_ids + door_ids_by_item_id[item_id] = internal_door_ids mentioned_doors.merge(internal_door_ids) end @@ -161,7 +145,7 @@ config.each do |room_name, room_data| internal_painting_ids = door["painting_id"] end - painting_ids_by_item_id[chosen_name] = internal_painting_ids + painting_ids_by_item_id[item_id] = internal_painting_ids mentioned_paintings.merge(internal_painting_ids) end end @@ -170,7 +154,8 @@ config.each do |room_name, room_data| end door_groups.each do |group_name, door_ids| - door_ids_by_item_id[group_name] = door_ids.to_a + item_id = ids_config["door_groups"][group_name] + door_ids_by_item_id[item_id] = door_ids.to_a end File.open(outputpath, "w") do |f| @@ -182,19 +167,19 @@ File.open(outputpath, "w") do |f| end.join(",")) f.write "]\nvar door_ids_by_item_id = {" f.write(door_ids_by_item_id.map do |item_id, door_ids| - "\"#{item_id}\":[" + door_ids.map do |door_id| + "#{item_id}:[" + door_ids.map do |door_id| "\"#{door_id}\"" end.join(",") + "]" end.join(",")) f.write "}\nvar painting_ids_by_item_id = {" f.write(painting_ids_by_item_id.map do |item_id, painting_ids| - "\"#{item_id}\":[" + painting_ids.map do |painting_id| + "#{item_id}:[" + painting_ids.map do |painting_id| "\"#{painting_id}\"" end.join(",") + "]" end.join(",")) f.write "}\nvar panel_ids_by_location_id = {" f.write(panel_ids_by_location_id.map do |location_id, panel_ids| - "\"#{location_id}\":[" + panel_ids.map do |panel_id| + "#{location_id}:[" + panel_ids.map do |panel_id| "\"#{panel_id}\"" end.join(",") + "]" end.join(",")) @@ -212,7 +197,7 @@ File.open(outputpath, "w") do |f| end.join(",")) f.write "}\nvar classification_by_location_id = {" f.write(classification_by_location_id.map do |location_id, classification| - "\"#{location_id}\":#{classification}" + "#{location_id}:#{classification}" end.join(",")) f.write "}" end -- cgit 1.4.1