about summary refs log tree commit diff stats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/generate_gamedata.rb65
1 files changed, 25 insertions, 40 deletions
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'
2require 'yaml' 2require 'yaml'
3 3
4configpath = ARGV[0] 4configpath = ARGV[0]
5outputpath = ARGV[1] 5idspath = ARGV[1]
6outputpath = ARGV[2]
6 7
7CLASSIFICATION_NORMAL = 1 8CLASSIFICATION_NORMAL = 1
8CLASSIFICATION_REDUCED = 2 9CLASSIFICATION_REDUCED = 2
@@ -20,10 +21,14 @@ mentioned_doors = Set[]
20mentioned_paintings = Set[] 21mentioned_paintings = Set[]
21painting_output = {} 22painting_output = {}
22 23
24ids_config = YAML.load_file(idspath)
25
23config = YAML.load_file(configpath) 26config = YAML.load_file(configpath)
24config.each do |room_name, room_data| 27config.each do |room_name, room_data|
25 if room_data.include? "panels" 28 if room_data.include? "panels"
26 room_data["panels"].each do |panel_name, panel| 29 room_data["panels"].each do |panel_name, panel|
30 location_id = ids_config["panels"][room_name][panel_name]
31
27 full_name = "#{room_name} - #{panel_name}" 32 full_name = "#{room_name} - #{panel_name}"
28 panel_to_id[full_name] = panel["id"] 33 panel_to_id[full_name] = panel["id"]
29 34
@@ -59,16 +64,16 @@ config.each do |room_name, room_data|
59 end 64 end
60 panel_output << ret 65 panel_output << ret
61 66
62 panel_ids_by_location_id[full_name] = [panel["id"]] 67 panel_ids_by_location_id[location_id] = [panel["id"]]
63 68
64 classification_by_location_id[full_name] ||= 0 69 classification_by_location_id[location_id] ||= 0
65 classification_by_location_id[full_name] += CLASSIFICATION_INSANITY 70 classification_by_location_id[location_id] += CLASSIFICATION_INSANITY
66 71
67 if panel.include? "check" and panel["check"] 72 if panel.include? "check" and panel["check"]
68 classification_by_location_id[full_name] += CLASSIFICATION_NORMAL 73 classification_by_location_id[location_id] += CLASSIFICATION_NORMAL
69 74
70 unless panel.include? "exclude_reduce" and panel["exclude_reduce"] 75 unless panel.include? "exclude_reduce" and panel["exclude_reduce"]
71 classification_by_location_id[full_name] += CLASSIFICATION_REDUCED 76 classification_by_location_id[location_id] += CLASSIFICATION_REDUCED
72 end 77 end
73 end 78 end
74 end 79 end
@@ -90,27 +95,9 @@ config.each do |room_name, room_data|
90 not (door.include? "event" and door["event"]) and 95 not (door.include? "event" and door["event"]) and
91 door.include? "panels" then 96 door.include? "panels" then
92 97
93 chosen_name = full_name 98 location_id = ids_config["doors"][room_name][door_name]["location"]
94 if door.include? "location_name"
95 chosen_name = door["location_name"]
96 else
97 panels_per_room = {}
98 door["panels"].each do |panel_identifier|
99 if panel_identifier.kind_of? String
100 panels_per_room[room_name] ||= []
101 panels_per_room[room_name] << panel_identifier
102 else
103 panels_per_room[panel_identifier["room"]] ||= []
104 panels_per_room[panel_identifier["room"]] << panel_identifier["panel"]
105 end
106 end
107 99
108 chosen_name = panels_per_room.map do |room_name, panels| 100 panel_ids_by_location_id[location_id] = door["panels"].map do |panel_identifier|
109 room_name + " - " + panels.join(", ")
110 end.join(" and ")
111 end
112
113 panel_ids_by_location_id[chosen_name] = door["panels"].map do |panel_identifier|
114 other_name = "" 101 other_name = ""
115 if panel_identifier.kind_of? String 102 if panel_identifier.kind_of? String
116 other_name = "#{room_name} - #{panel_identifier}" 103 other_name = "#{room_name} - #{panel_identifier}"
@@ -120,21 +107,18 @@ config.each do |room_name, room_data|
120 panel_to_id[other_name] 107 panel_to_id[other_name]
121 end 108 end
122 109
123 classification_by_location_id[chosen_name] ||= 0 110 classification_by_location_id[location_id] ||= 0
124 classification_by_location_id[chosen_name] += CLASSIFICATION_NORMAL 111 classification_by_location_id[location_id] += CLASSIFICATION_NORMAL
125 112
126 if door.include? "include_reduce" and door["include_reduce"] 113 if door.include? "include_reduce" and door["include_reduce"]
127 classification_by_location_id[chosen_name] += CLASSIFICATION_REDUCED 114 classification_by_location_id[location_id] += CLASSIFICATION_REDUCED
128 end 115 end
129 end 116 end
130 117
131 if not (door.include? "skip_item" and door["skip_item"]) and 118 if not (door.include? "skip_item" and door["skip_item"]) and
132 not (door.include? "event" and door["event"]) then 119 not (door.include? "event" and door["event"]) then
133 120
134 chosen_name = full_name 121 item_id = ids_config["doors"][room_name][door_name]["item"]
135 if door.include? "item_name"
136 chosen_name = door["item_name"]
137 end
138 122
139 if door.include? "id" 123 if door.include? "id"
140 internal_door_ids = [] 124 internal_door_ids = []
@@ -149,7 +133,7 @@ config.each do |room_name, room_data|
149 door_groups[door["group"]].merge(internal_door_ids) 133 door_groups[door["group"]].merge(internal_door_ids)
150 end 134 end
151 135
152 door_ids_by_item_id[chosen_name] = internal_door_ids 136 door_ids_by_item_id[item_id] = internal_door_ids
153 mentioned_doors.merge(internal_door_ids) 137 mentioned_doors.merge(internal_door_ids)
154 end 138 end
155 139
@@ -161,7 +145,7 @@ config.each do |room_name, room_data|
161 internal_painting_ids = door["painting_id"] 145 internal_painting_ids = door["painting_id"]
162 end 146 end
163 147
164 painting_ids_by_item_id[chosen_name] = internal_painting_ids 148 painting_ids_by_item_id[item_id] = internal_painting_ids
165 mentioned_paintings.merge(internal_painting_ids) 149 mentioned_paintings.merge(internal_painting_ids)
166 end 150 end
167 end 151 end
@@ -170,7 +154,8 @@ config.each do |room_name, room_data|
170end 154end
171 155
172door_groups.each do |group_name, door_ids| 156door_groups.each do |group_name, door_ids|
173 door_ids_by_item_id[group_name] = door_ids.to_a 157 item_id = ids_config["door_groups"][group_name]
158 door_ids_by_item_id[item_id] = door_ids.to_a
174end 159end
175 160
176File.open(outputpath, "w") do |f| 161File.open(outputpath, "w") do |f|
@@ -182,19 +167,19 @@ File.open(outputpath, "w") do |f|
182 end.join(",")) 167 end.join(","))
183 f.write "]\nvar door_ids_by_item_id = {" 168 f.write "]\nvar door_ids_by_item_id = {"
184 f.write(door_ids_by_item_id.map do |item_id, door_ids| 169 f.write(door_ids_by_item_id.map do |item_id, door_ids|
185 "\"#{item_id}\":[" + door_ids.map do |door_id| 170 "#{item_id}:[" + door_ids.map do |door_id|
186 "\"#{door_id}\"" 171 "\"#{door_id}\""
187 end.join(",") + "]" 172 end.join(",") + "]"
188 end.join(",")) 173 end.join(","))
189 f.write "}\nvar painting_ids_by_item_id = {" 174 f.write "}\nvar painting_ids_by_item_id = {"
190 f.write(painting_ids_by_item_id.map do |item_id, painting_ids| 175 f.write(painting_ids_by_item_id.map do |item_id, painting_ids|
191 "\"#{item_id}\":[" + painting_ids.map do |painting_id| 176 "#{item_id}:[" + painting_ids.map do |painting_id|
192 "\"#{painting_id}\"" 177 "\"#{painting_id}\""
193 end.join(",") + "]" 178 end.join(",") + "]"
194 end.join(",")) 179 end.join(","))
195 f.write "}\nvar panel_ids_by_location_id = {" 180 f.write "}\nvar panel_ids_by_location_id = {"
196 f.write(panel_ids_by_location_id.map do |location_id, panel_ids| 181 f.write(panel_ids_by_location_id.map do |location_id, panel_ids|
197 "\"#{location_id}\":[" + panel_ids.map do |panel_id| 182 "#{location_id}:[" + panel_ids.map do |panel_id|
198 "\"#{panel_id}\"" 183 "\"#{panel_id}\""
199 end.join(",") + "]" 184 end.join(",") + "]"
200 end.join(",")) 185 end.join(","))
@@ -212,7 +197,7 @@ File.open(outputpath, "w") do |f|
212 end.join(",")) 197 end.join(","))
213 f.write "}\nvar classification_by_location_id = {" 198 f.write "}\nvar classification_by_location_id = {"
214 f.write(classification_by_location_id.map do |location_id, classification| 199 f.write(classification_by_location_id.map do |location_id, classification|
215 "\"#{location_id}\":#{classification}" 200 "#{location_id}:#{classification}"
216 end.join(",")) 201 end.join(","))
217 f.write "}" 202 f.write "}"
218end 203end