diff options
Diffstat (limited to 'util/generate_gamedata.rb')
-rw-r--r-- | util/generate_gamedata.rb | 96 |
1 files changed, 83 insertions, 13 deletions
diff --git a/util/generate_gamedata.rb b/util/generate_gamedata.rb index ce8df43..7db06ca 100644 --- a/util/generate_gamedata.rb +++ b/util/generate_gamedata.rb | |||
@@ -12,24 +12,43 @@ CLASSIFICATION_SMALL_SPHERE_ONE = 8 | |||
12 | 12 | ||
13 | panel_to_id = {} | 13 | panel_to_id = {} |
14 | door_groups = {} | 14 | door_groups = {} |
15 | panel_groups = {} | ||
15 | warp_groups = {} | 16 | warp_groups = {} |
16 | 17 | ||
17 | panel_output = [] | 18 | panel_output = [] |
18 | door_ids_by_item_id = {} | 19 | door_ids_by_item_id = {} |
19 | painting_ids_by_item_id = {} | 20 | painting_ids_by_item_id = {} |
21 | panel_ids_by_item_id = {} | ||
20 | warp_ids_by_item_id = {} | 22 | warp_ids_by_item_id = {} |
21 | panel_ids_by_location_id = {} | 23 | panel_ids_by_location_id = {} |
22 | classification_by_location_id = {} | 24 | classification_by_location_id = {} |
23 | sunwarps = Array.new(12) {Hash.new} | 25 | sunwarps = Array.new(12) {Hash.new} |
24 | mentioned_doors = Set[] | 26 | mentioned_doors = Set[] |
25 | mentioned_paintings = Set[] | 27 | mentioned_paintings = Set[] |
28 | mentioned_panels = Set[] | ||
26 | mentioned_warps = Set[] | 29 | mentioned_warps = Set[] |
27 | painting_output = {} | 30 | painting_output = {} |
28 | items_by_progressive_id = {} | 31 | door_items_by_progressive_id = {} |
32 | panel_items_by_progressive_id = {} | ||
33 | panel_location_ids = [] | ||
34 | solve_index_by_location = {} | ||
29 | 35 | ||
30 | ids_config = YAML.load_file(idspath) | 36 | ids_config = YAML.load_file(idspath) |
31 | |||
32 | config = YAML.load_file(configpath) | 37 | config = YAML.load_file(configpath) |
38 | |||
39 | config.each do |room_name, room_data| | ||
40 | if room_data.include? "panels" | ||
41 | room_data["panels"].each do |panel_name, panel| | ||
42 | location_id = ids_config["panels"][room_name][panel_name] | ||
43 | panel_location_ids << location_id | ||
44 | end | ||
45 | end | ||
46 | end | ||
47 | |||
48 | panel_location_ids.sort.each_with_index do |location_id, index| | ||
49 | solve_index_by_location[location_id] = index | ||
50 | end | ||
51 | |||
33 | config.each do |room_name, room_data| | 52 | config.each do |room_name, room_data| |
34 | if room_data.include? "panels" | 53 | if room_data.include? "panels" |
35 | room_data["panels"].each do |panel_name, panel| | 54 | room_data["panels"].each do |panel_name, panel| |
@@ -41,6 +60,7 @@ config.each do |room_name, room_data| | |||
41 | ret = {} | 60 | ret = {} |
42 | ret["id"] = "\"#{panel["id"]}\"" | 61 | ret["id"] = "\"#{panel["id"]}\"" |
43 | ret["loc"] = location_id | 62 | ret["loc"] = location_id |
63 | ret["solve_index"] = solve_index_by_location[location_id] | ||
44 | if panel.include? "colors" | 64 | if panel.include? "colors" |
45 | if panel["colors"].kind_of? String | 65 | if panel["colors"].kind_of? String |
46 | ret["color"] = "[\"#{panel["colors"]}\"]" | 66 | ret["color"] = "[\"#{panel["colors"]}\"]" |
@@ -69,9 +89,6 @@ config.each do |room_name, room_data| | |||
69 | if panel.include? "achievement" | 89 | if panel.include? "achievement" |
70 | ret["achievement"] = "\"#{panel["achievement"]}\"" | 90 | ret["achievement"] = "\"#{panel["achievement"]}\"" |
71 | end | 91 | end |
72 | if panel.include? "hunt" and panel["hunt"] | ||
73 | ret["hunt"] = "true" | ||
74 | end | ||
75 | panel_output << ret | 92 | panel_output << ret |
76 | 93 | ||
77 | panel_ids_by_location_id[location_id] = [panel["id"]] | 94 | panel_ids_by_location_id[location_id] = [panel["id"]] |
@@ -110,15 +127,29 @@ config.each do |room_name, room_data| | |||
110 | end | 127 | end |
111 | 128 | ||
112 | if room_data.include? "progression" | 129 | if room_data.include? "progression" |
113 | room_data["progression"].each do |progressive_item_name, progression| | 130 | room_data["progression"].each do |progressive_item_name, pdata| |
114 | progressive_id = ids_config["progression"][progressive_item_name] | 131 | progressive_id = ids_config["progression"][progressive_item_name] |
115 | items_by_progressive_id[progressive_id] = [] | ||
116 | 132 | ||
117 | progression.each do |item| | 133 | if pdata.include? "doors" |
118 | item_room_name = (item.kind_of? Hash) ? item["room"] : room_name | 134 | door_items_by_progressive_id[progressive_id] = [] |
119 | item_item_name = (item.kind_of? Hash) ? item["door"] : item | 135 | |
136 | pdata["doors"].each do |item| | ||
137 | item_room_name = (item.kind_of? Hash) ? item["room"] : room_name | ||
138 | item_item_name = (item.kind_of? Hash) ? item["door"] : item | ||
139 | |||
140 | door_items_by_progressive_id[progressive_id] << ids_config["doors"][item_room_name][item_item_name]["item"] | ||
141 | end | ||
142 | end | ||
143 | |||
144 | if pdata.include? "panel_doors" | ||
145 | panel_items_by_progressive_id[progressive_id] = [] | ||
120 | 146 | ||
121 | items_by_progressive_id[progressive_id] << ids_config["doors"][item_room_name][item_item_name]["item"] | 147 | pdata["panel_doors"].each do |item| |
148 | item_room_name = (item.kind_of? Hash) ? item["room"] : room_name | ||
149 | item_item_name = (item.kind_of? Hash) ? item["panel_door"] : item | ||
150 | |||
151 | panel_items_by_progressive_id[progressive_id] << ids_config["panel_doors"][item_room_name][item_item_name] | ||
152 | end | ||
122 | end | 153 | end |
123 | end | 154 | end |
124 | end | 155 | end |
@@ -206,6 +237,26 @@ config.each do |room_name, room_data| | |||
206 | end | 237 | end |
207 | end | 238 | end |
208 | end | 239 | end |
240 | |||
241 | if room_data.include? "panel_doors" | ||
242 | room_data["panel_doors"].each do |panel_door_name, panel_door| | ||
243 | item_id = ids_config["panel_doors"][room_name][panel_door_name] | ||
244 | |||
245 | panel_ids_by_item_id[item_id] = panel_door["panels"].map do |panel_identifier| | ||
246 | other_room_name = (panel_identifier.kind_of? String) ? room_name : panel_identifier["room"] | ||
247 | other_panel_name = (panel_identifier.kind_of? String) ? panel_identifier : panel_identifier["panel"] | ||
248 | |||
249 | config[other_room_name]["panels"][other_panel_name]["id"] | ||
250 | end | ||
251 | |||
252 | mentioned_panels.merge(panel_ids_by_item_id[item_id]) | ||
253 | |||
254 | if panel_door.include? "panel_group" | ||
255 | panel_groups[panel_door["panel_group"]] ||= Set[] | ||
256 | panel_groups[panel_door["panel_group"]].merge(panel_ids_by_item_id[item_id]) | ||
257 | end | ||
258 | end | ||
259 | end | ||
209 | end | 260 | end |
210 | 261 | ||
211 | door_groups.each do |group_name, door_ids| | 262 | door_groups.each do |group_name, door_ids| |
@@ -213,6 +264,11 @@ door_groups.each do |group_name, door_ids| | |||
213 | door_ids_by_item_id[item_id] = door_ids.to_a | 264 | door_ids_by_item_id[item_id] = door_ids.to_a |
214 | end | 265 | end |
215 | 266 | ||
267 | panel_groups.each do |group_name, panel_ids| | ||
268 | item_id = ids_config["panel_groups"][group_name] | ||
269 | panel_ids_by_item_id[item_id] = panel_ids.to_a | ||
270 | end | ||
271 | |||
216 | warp_groups.each do |group_name, warp_ids| | 272 | warp_groups.each do |group_name, warp_ids| |
217 | item_id = ids_config["door_groups"][group_name] | 273 | item_id = ids_config["door_groups"][group_name] |
218 | warp_ids_by_item_id[item_id] = warp_ids.to_a | 274 | warp_ids_by_item_id[item_id] = warp_ids.to_a |
@@ -231,6 +287,12 @@ File.open(outputpath, "w") do |f| | |||
231 | "\"#{door_id}\"" | 287 | "\"#{door_id}\"" |
232 | end.join(",") + "]" | 288 | end.join(",") + "]" |
233 | end.join(",")) | 289 | end.join(",")) |
290 | f.write "}\nvar panel_ids_by_item_id = {" | ||
291 | f.write(panel_ids_by_item_id.map do |item_id, panel_ids| | ||
292 | "#{item_id}:[" + panel_ids.map do |panel_id| | ||
293 | "\"#{panel_id}\"" | ||
294 | end.join(",") + "]" | ||
295 | end.join(",")) | ||
234 | f.write "}\nvar painting_ids_by_item_id = {" | 296 | f.write "}\nvar painting_ids_by_item_id = {" |
235 | f.write(painting_ids_by_item_id.map do |item_id, painting_ids| | 297 | f.write(painting_ids_by_item_id.map do |item_id, painting_ids| |
236 | "#{item_id}:[" + painting_ids.map do |painting_id| | 298 | "#{item_id}:[" + painting_ids.map do |painting_id| |
@@ -257,6 +319,10 @@ File.open(outputpath, "w") do |f| | |||
257 | f.write(mentioned_paintings.map do |painting_id| | 319 | f.write(mentioned_paintings.map do |painting_id| |
258 | "\"#{painting_id}\"" | 320 | "\"#{painting_id}\"" |
259 | end.join(",")) | 321 | end.join(",")) |
322 | f.write "]\nvar mentioned_panels = [" | ||
323 | f.write(mentioned_panels.map do |panel_id| | ||
324 | "\"#{panel_id}\"" | ||
325 | end.join(",")) | ||
260 | f.write "]\nvar mentioned_warps = [" | 326 | f.write "]\nvar mentioned_warps = [" |
261 | f.write(mentioned_warps.map do |warp_id| | 327 | f.write(mentioned_warps.map do |warp_id| |
262 | "\"#{warp_id}\"" | 328 | "\"#{warp_id}\"" |
@@ -273,8 +339,12 @@ File.open(outputpath, "w") do |f| | |||
273 | f.write(sunwarps.map do |sunwarp| | 339 | f.write(sunwarps.map do |sunwarp| |
274 | "{\"orientation\":\"#{sunwarp["orientation"]}\",\"entrance_indicator_pos\":#{sunwarp["entrance_indicator_pos"].to_s}}" | 340 | "{\"orientation\":\"#{sunwarp["orientation"]}\",\"entrance_indicator_pos\":#{sunwarp["entrance_indicator_pos"].to_s}}" |
275 | end.join(",")) | 341 | end.join(",")) |
276 | f.write "]\nvar items_by_progressive_id = {" | 342 | f.write "]\nvar door_items_by_progressive_id = {" |
277 | f.write(items_by_progressive_id.map do |item_id, progression_ids| | 343 | f.write(door_items_by_progressive_id.map do |item_id, progression_ids| |
344 | "#{item_id}:[" + progression_ids.map(&:to_s).join(",") + "]" | ||
345 | end.join(",")) | ||
346 | f.write "}\nvar panel_items_by_progressive_id = {" | ||
347 | f.write(panel_items_by_progressive_id.map do |item_id, progression_ids| | ||
278 | "#{item_id}:[" + progression_ids.map(&:to_s).join(",") + "]" | 348 | "#{item_id}:[" + progression_ids.map(&:to_s).join(",") + "]" |
279 | end.join(",")) | 349 | end.join(",")) |
280 | f.write "}" | 350 | f.write "}" |