about summary refs log tree commit diff stats
path: root/util/generate_gamedata.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-08-01 17:11:10 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-08-01 17:11:10 -0400
commit6d8b971e7824dd6486bb4cb5a0f72eda7c5e47d3 (patch)
tree5e3ecfb848f4bb525a9c75a1627120bf9f2cad28 /util/generate_gamedata.rb
parent62f06090014aee90231eb90da36d5ae1b65171a3 (diff)
downloadlingo-archipelago-6d8b971e7824dd6486bb4cb5a0f72eda7c5e47d3.tar.gz
lingo-archipelago-6d8b971e7824dd6486bb4cb5a0f72eda7c5e47d3.tar.bz2
lingo-archipelago-6d8b971e7824dd6486bb4cb5a0f72eda7c5e47d3.zip
Gamedata is generated from main AP yaml
We now also include static data that was previously sent in slot data.
Diffstat (limited to 'util/generate_gamedata.rb')
-rw-r--r--util/generate_gamedata.rb215
1 files changed, 181 insertions, 34 deletions
diff --git a/util/generate_gamedata.rb b/util/generate_gamedata.rb index 3b57f76..bf8e3ae 100644 --- a/util/generate_gamedata.rb +++ b/util/generate_gamedata.rb
@@ -1,46 +1,193 @@
1require 'set'
1require 'yaml' 2require 'yaml'
2 3
3configpath = ARGV[0] 4configpath = ARGV[0]
4outputpath = ARGV[1] 5outputpath = ARGV[1]
5 6
7panel_to_id = {}
8door_groups = {}
9
10panel_output = []
11door_ids_by_item_id = {}
12painting_ids_by_item_id = {}
13panel_ids_by_location_id = {}
14mentioned_doors = Set[]
15mentioned_paintings = Set[]
16painting_output = {}
17
6config = YAML.load_file(configpath) 18config = YAML.load_file(configpath)
7output = config.map do |panel| 19config.each do |room_name, room_data|
8 ret = panel 20 if room_data.include? "panels"
9 if ret["color"].kind_of? String 21 room_data["panels"].each do |panel_name, panel|
10 ret["color"] = [ret["color"]] 22 full_name = "#{room_name} - #{panel_name}"
11 end 23 panel_to_id[full_name] = panel["id"]
12 ret 24
13end.map do |panel| 25 ret = {}
14 ret = {} 26 ret["id"] = "\"#{panel["id"]}\""
15 ret["id"] = "\"#{panel["id"]}\"" 27 if panel.include? "colors"
16 ret["color"] = "[\"" + panel["color"].join("\",\"") + "\"]" 28 if panel["colors"].kind_of? String
17 ret["tag"] = "\"#{panel["tag"]}\"" 29 ret["color"] = "[\"#{panel["colors"]}\"]"
18 if panel.include? "subtag" 30 else
19 ret["subtag"] = "\"#{panel["subtag"]}\"" 31 ret["color"] = "[\"" + panel["colors"].join("\",\"") + "\"]"
20 end 32 end
21 if panel.include? "link" 33 else
22 ret["link"] = "\"#{panel["link"]}\"" 34 ret["color"] = "[\"white\"]"
35 end
36 ret["tag"] = "\"#{panel["tag"]}\""
37 if panel.include? "subtag"
38 ret["subtag"] = "\"#{panel["subtag"]}\""
39 end
40 if panel.include? "link"
41 ret["link"] = "\"#{panel["link"]}\""
42 end
43 if panel.include? "copy_to_sign"
44 copytos = []
45 if panel["copy_to_sign"].kind_of? String
46 copytos = [panel["copy_to_sign"]]
47 else
48 copytos = panel["copy_to_sign"]
49 end
50 ret["copy_to_sign"] = "[\"" + copytos.join("\",\"") + "\"]"
51 end
52 if panel.include? "achievement"
53 ret["achievement"] = "\"#{panel["achievement"]}\""
54 end
55 panel_output << ret
56
57 if panel.include? "check" and panel["check"]
58 panel_ids_by_location_id[full_name] = [panel["id"]]
59 end
60 end
23 end 61 end
24 if panel.include? "copy_to_sign" 62
25 copytos = [] 63 if room_data.include? "paintings"
26 if panel["copy_to_sign"].kind_of? String 64 room_data["paintings"].each do |painting|
27 copytos = [panel["copy_to_sign"]] 65 painting_output[painting["id"]] = painting
28 else
29 copytos = panel["copy_to_sign"]
30 end 66 end
31 ret["copy_to_sign"] = "[\"" + copytos.join("\",\"") + "\"]"
32 end 67 end
33 if panel.include? "achievement" 68end
34 ret["achievement"] = "\"#{panel["achievement"]}\"" 69
70config.each do |room_name, room_data|
71 if room_data.include? "doors"
72 room_data["doors"].each do |door_name, door|
73 full_name = "#{room_name} - #{door_name}"
74
75 if not (door.include? "skip_location" and door["skip_location"]) and
76 not (door.include? "event" and door["event"]) and
77 door.include? "panels" then
78
79 chosen_name = full_name
80 if door.include? "location_name"
81 chosen_name = door["location_name"]
82 else
83 panels_per_room = {}
84 door["panels"].each do |panel_identifier|
85 if panel_identifier.kind_of? String
86 panels_per_room[room_name] ||= []
87 panels_per_room[room_name] << panel_identifier
88 else
89 panels_per_room[panel_identifier["room"]] ||= []
90 panels_per_room[panel_identifier["room"]] << panel_identifier["panel"]
91 end
92 end
93
94 chosen_name = panels_per_room.map do |room_name, panels|
95 room_name + " - " + panels.join(", ")
96 end.join(" and ")
97 end
98
99 panel_ids_by_location_id[chosen_name] = door["panels"].map do |panel_identifier|
100 other_name = ""
101 if panel_identifier.kind_of? String
102 other_name = "#{room_name} - #{panel_identifier}"
103 else
104 other_name = "#{panel_identifier["room"]} - #{panel_identifier["panel"]}"
105 end
106 panel_to_id[other_name]
107 end
108 end
109
110 if not (door.include? "skip_item" and door["skip_item"]) and
111 not (door.include? "event" and door["event"]) then
112
113 chosen_name = full_name
114 if door.include? "item_name"
115 chosen_name = door["item_name"]
116 end
117
118 if door.include? "id"
119 internal_door_ids = []
120 if door["id"].kind_of? String
121 internal_door_ids = [door["id"]]
122 else
123 internal_door_ids = door["id"]
124 end
125
126 if door.include? "group"
127 door_groups[door["group"]] ||= Set[]
128 door_groups[door["group"]].merge(internal_door_ids)
129 end
130
131 door_ids_by_item_id[chosen_name] = internal_door_ids
132 mentioned_doors.merge(internal_door_ids)
133 end
134
135 if door.include? "painting_id"
136 internal_painting_ids = []
137 if door["painting_id"].kind_of? String
138 internal_painting_ids = [door["painting_id"]]
139 else
140 internal_painting_ids = door["painting_id"]
141 end
142
143 painting_ids_by_item_id[chosen_name] = internal_painting_ids
144 mentioned_paintings.merge(internal_painting_ids)
145 end
146 end
147 end
35 end 148 end
36 ret 149end
37end.map do |panel|
38 "{" + panel.to_a.map do |element|
39 "\"#{element[0]}\":#{element[1]}"
40 end.join(",") + "}"
41end.join(",")
42 150
43header = "extends Node\n\nvar panels = [" 151door_groups.each do |group_name, door_ids|
44footer = "]" 152 door_ids_by_item_id[group_name] = door_ids.to_a
153end
45 154
46File.write(outputpath, header + output + footer) \ No newline at end of file 155File.open(outputpath, "w") do |f|
156 f.write "extends Node\n\nvar panels = ["
157 f.write(panel_output.map do |panel|
158 "{" + panel.to_a.map do |element|
159 "\"#{element[0]}\":#{element[1]}"
160 end.join(",") + "}"
161 end.join(","))
162 f.write "]\nvar door_ids_by_item_id = {"
163 f.write(door_ids_by_item_id.map do |item_id, door_ids|
164 "\"#{item_id}\":[" + door_ids.map do |door_id|
165 "\"#{door_id}\""
166 end.join(",") + "]"
167 end.join(","))
168 f.write "}\nvar painting_ids_by_item_id = {"
169 f.write(painting_ids_by_item_id.map do |item_id, painting_ids|
170 "\"#{item_id}\":[" + painting_ids.map do |painting_id|
171 "\"#{painting_id}\""
172 end.join(",") + "]"
173 end.join(","))
174 f.write "}\nvar panel_ids_by_location_id = {"
175 f.write(panel_ids_by_location_id.map do |location_id, panel_ids|
176 "\"#{location_id}\":[" + panel_ids.map do |panel_id|
177 "\"#{panel_id}\""
178 end.join(",") + "]"
179 end.join(","))
180 f.write "}\nvar mentioned_doors = ["
181 f.write(mentioned_doors.map do |door_id|
182 "\"#{door_id}\""
183 end.join(","))
184 f.write "]\nvar mentioned_paintings = ["
185 f.write(mentioned_paintings.map do |painting_id|
186 "\"#{painting_id}\""
187 end.join(","))
188 f.write "]\nvar paintings = {"
189 f.write(painting_output.map do |painting_id, painting|
190 "\"#{painting_id}\":{\"orientation\":\"#{painting["orientation"]}\",\"move\":#{painting.include? "move" and painting["move"]}}"
191 end.join(","))
192 f.write "}"
193end