about summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/assign_ids/main.cpp253
-rw-r--r--tools/datapacker/container.cpp34
-rw-r--r--tools/datapacker/container.h6
-rw-r--r--tools/datapacker/main.cpp202
-rw-r--r--tools/util/godot_scene.cpp6
-rw-r--r--tools/util/ids_yaml_format.cpp60
-rw-r--r--tools/validator/CMakeLists.txt3
-rw-r--r--tools/validator/human_processor.cpp225
-rw-r--r--tools/validator/main.cpp4
-rw-r--r--tools/validator/structs.h41
-rw-r--r--tools/validator/validator.cpp715
-rw-r--r--tools/validator/validator.h2
12 files changed, 1275 insertions, 276 deletions
diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index e65e5e4..4a48b86 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp
@@ -2,6 +2,7 @@
2#include <google/protobuf/text_format.h> 2#include <google/protobuf/text_format.h>
3 3
4#include <cstdint> 4#include <cstdint>
5#include <filesystem>
5#include <fstream> 6#include <fstream>
6#include <iostream> 7#include <iostream>
7#include <map> 8#include <map>
@@ -40,6 +41,10 @@ class AssignIds {
40 ReadIds(ids_path); 41 ReadIds(ids_path);
41 42
42 ProcessMaps(datadir_path); 43 ProcessMaps(datadir_path);
44 ProcessSpecialIds();
45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb");
43 48
44 WriteIds(ids_path); 49 WriteIds(ids_path);
45 50
@@ -54,50 +59,31 @@ class AssignIds {
54 id_mappings_ = ReadIdsFromYaml(path.string()); 59 id_mappings_ = ReadIdsFromYaml(path.string());
55 60
56 for (const auto& [_, map] : id_mappings_.maps()) { 61 for (const auto& [_, map] : id_mappings_.maps()) {
57 for (const auto& [_, id] : map.doors()) { 62 UpdateNextId(map.doors());
58 if (id > next_id_) {
59 next_id_ = id;
60 }
61 }
62 63
63 for (const auto& [_, room] : map.rooms()) { 64 for (const auto& [_, room] : map.rooms()) {
64 for (const auto& [_, id] : room.panels()) { 65 UpdateNextId(room.panels());
65 if (id > next_id_) { 66 UpdateNextId(room.masteries());
66 next_id_ = id; 67 UpdateNextId(room.keyholders());
67 } 68 UpdateNextId(room.ports());
68 }
69
70 for (const auto& [_, id] : room.masteries()) {
71 if (id > next_id_) {
72 next_id_ = id;
73 }
74 }
75 } 69 }
76 }
77 70
78 for (const auto& [_, id] : id_mappings_.special()) { 71 if (map.has_rte()) {
79 if (id > next_id_) { 72 UpdateNextId(map.rte());
80 next_id_ = id;
81 } 73 }
82 } 74 }
83 75
84 for (const auto& [_, id] : id_mappings_.letters()) { 76 UpdateNextId(id_mappings_.special());
85 if (id > next_id_) { 77 UpdateNextId(id_mappings_.letters());
86 next_id_ = id; 78 UpdateNextId(id_mappings_.endings());
87 } 79 UpdateNextId(id_mappings_.progressives());
88 } 80 UpdateNextId(id_mappings_.door_groups());
89
90 for (const auto& [_, id] : id_mappings_.endings()) {
91 if (id > next_id_) {
92 next_id_ = id;
93 }
94 }
95 81
96 next_id_++; 82 next_id_++;
97 } 83 }
98 84
99 void WriteIds(std::filesystem::path path) { 85 void WriteIds(std::filesystem::path path) {
100 WriteIdsAsYaml(id_mappings_, path.string()); 86 WriteIdsAsYaml(output_, path.string());
101 } 87 }
102 88
103 void ProcessMaps(std::filesystem::path path) { 89 void ProcessMaps(std::filesystem::path path) {
@@ -111,10 +97,31 @@ class AssignIds {
111 void ProcessMap(std::filesystem::path path) { 97 void ProcessMap(std::filesystem::path path) {
112 std::string map_name = path.filename().string(); 98 std::string map_name = path.filename().string();
113 99
100 ProcessMapMetadata(path / "metadata.txtpb", map_name);
114 ProcessDoorsFile(path / "doors.txtpb", map_name); 101 ProcessDoorsFile(path / "doors.txtpb", map_name);
115 ProcessRooms(path / "rooms", map_name); 102 ProcessRooms(path / "rooms", map_name);
116 } 103 }
117 104
105 void ProcessMapMetadata(std::filesystem::path path,
106 const std::string& current_map_name) {
107 if (!std::filesystem::exists(path)) {
108 return;
109 }
110
111 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
112 auto& maps = *output_.mutable_maps();
113
114 if (metadata.has_rte_room()) {
115 if (!id_mappings_.maps().contains(current_map_name) ||
116 !id_mappings_.maps().at(current_map_name).has_rte()) {
117 maps[current_map_name].set_rte(next_id_++);
118 } else {
119 maps[current_map_name].set_rte(
120 id_mappings_.maps().at(current_map_name).rte());
121 }
122 }
123 }
124
118 void ProcessDoorsFile(std::filesystem::path path, 125 void ProcessDoorsFile(std::filesystem::path path,
119 const std::string& current_map_name) { 126 const std::string& current_map_name) {
120 if (!std::filesystem::exists(path)) { 127 if (!std::filesystem::exists(path)) {
@@ -130,18 +137,23 @@ class AssignIds {
130 137
131 void ProcessDoor(const HumanDoor& h_door, 138 void ProcessDoor(const HumanDoor& h_door,
132 const std::string& current_map_name) { 139 const std::string& current_map_name) {
133 if (h_door.type() == DoorType::EVENT) { 140 if (h_door.type() == DoorType::EVENT && !h_door.latch() &&
141 !h_door.legacy_location()) {
134 return; 142 return;
135 } 143 }
136 144
145 auto& maps = *output_.mutable_maps();
146 auto& doors = *maps[current_map_name].mutable_doors();
147
137 if (!id_mappings_.maps().contains(current_map_name) || 148 if (!id_mappings_.maps().contains(current_map_name) ||
138 !id_mappings_.maps() 149 !id_mappings_.maps()
139 .at(current_map_name) 150 .at(current_map_name)
140 .doors() 151 .doors()
141 .contains(h_door.name())) { 152 .contains(h_door.name())) {
142 auto& maps = *id_mappings_.mutable_maps();
143 auto& doors = *maps[current_map_name].mutable_doors();
144 doors[h_door.name()] = next_id_++; 153 doors[h_door.name()] = next_id_++;
154 } else {
155 doors[h_door.name()] =
156 id_mappings_.maps().at(current_map_name).doors().at(h_door.name());
145 } 157 }
146 } 158 }
147 159
@@ -156,6 +168,10 @@ class AssignIds {
156 void ProcessRoom(const HumanRoom& h_room, 168 void ProcessRoom(const HumanRoom& h_room,
157 const std::string& current_map_name) { 169 const std::string& current_map_name) {
158 for (const HumanPanel& h_panel : h_room.panels()) { 170 for (const HumanPanel& h_panel : h_room.panels()) {
171 auto& maps = *output_.mutable_maps();
172 auto& rooms = *maps[current_map_name].mutable_rooms();
173 auto& panels = *rooms[h_room.name()].mutable_panels();
174
159 if (!id_mappings_.maps().contains(current_map_name) || 175 if (!id_mappings_.maps().contains(current_map_name) ||
160 !id_mappings_.maps() 176 !id_mappings_.maps()
161 .at(current_map_name) 177 .at(current_map_name)
@@ -167,23 +183,33 @@ class AssignIds {
167 .at(h_room.name()) 183 .at(h_room.name())
168 .panels() 184 .panels()
169 .contains(h_panel.name())) { 185 .contains(h_panel.name())) {
170 auto& maps = *id_mappings_.mutable_maps();
171 auto& rooms = *maps[current_map_name].mutable_rooms();
172 auto& panels = *rooms[h_room.name()].mutable_panels();
173 panels[h_panel.name()] = next_id_++; 186 panels[h_panel.name()] = next_id_++;
187 } else {
188 panels[h_panel.name()] = id_mappings_.maps()
189 .at(current_map_name)
190 .rooms()
191 .at(h_room.name())
192 .panels()
193 .at(h_panel.name());
174 } 194 }
175 } 195 }
176 196
177 for (const HumanLetter& h_letter : h_room.letters()) { 197 for (const HumanLetter& h_letter : h_room.letters()) {
178 std::string lettername = GetLetterName(h_letter.key(), h_letter.level2()); 198 std::string lettername = GetLetterName(h_letter.key(), h_letter.level2());
179 199
200 auto& letters = *output_.mutable_letters();
180 if (!id_mappings_.letters().contains(lettername)) { 201 if (!id_mappings_.letters().contains(lettername)) {
181 auto& letters = *id_mappings_.mutable_letters();
182 letters[lettername] = next_id_++; 202 letters[lettername] = next_id_++;
203 } else {
204 letters[lettername] = id_mappings_.letters().at(lettername);
183 } 205 }
184 } 206 }
185 207
186 for (const HumanMastery& h_mastery : h_room.masteries()) { 208 for (const HumanMastery& h_mastery : h_room.masteries()) {
209 auto& maps = *output_.mutable_maps();
210 auto& rooms = *maps[current_map_name].mutable_rooms();
211 auto& masteries = *rooms[h_room.name()].mutable_masteries();
212
187 if (!id_mappings_.maps().contains(current_map_name) || 213 if (!id_mappings_.maps().contains(current_map_name) ||
188 !id_mappings_.maps() 214 !id_mappings_.maps()
189 .at(current_map_name) 215 .at(current_map_name)
@@ -195,27 +221,168 @@ class AssignIds {
195 .at(h_room.name()) 221 .at(h_room.name())
196 .masteries() 222 .masteries()
197 .contains(h_mastery.name())) { 223 .contains(h_mastery.name())) {
198 auto& maps = *id_mappings_.mutable_maps();
199 auto& rooms = *maps[current_map_name].mutable_rooms();
200 auto& masteries = *rooms[h_room.name()].mutable_masteries();
201 masteries[h_mastery.name()] = next_id_++; 224 masteries[h_mastery.name()] = next_id_++;
225 } else {
226 masteries[h_mastery.name()] = id_mappings_.maps()
227 .at(current_map_name)
228 .rooms()
229 .at(h_room.name())
230 .masteries()
231 .at(h_mastery.name());
202 } 232 }
203 } 233 }
204 234
205 for (const HumanEnding& h_ending : h_room.endings()) { 235 for (const HumanEnding& h_ending : h_room.endings()) {
236 auto& endings = *output_.mutable_endings();
237
206 if (!id_mappings_.endings().contains(h_ending.name())) { 238 if (!id_mappings_.endings().contains(h_ending.name())) {
207 auto& endings = *id_mappings_.mutable_endings();
208 endings[h_ending.name()] = next_id_++; 239 endings[h_ending.name()] = next_id_++;
240 } else {
241 endings[h_ending.name()] = id_mappings_.endings().at(h_ending.name());
242 }
243 }
244
245 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
246 if (!h_keyholder.has_key()) {
247 continue;
248 }
249
250 auto& maps = *output_.mutable_maps();
251 auto& rooms = *maps[current_map_name].mutable_rooms();
252 auto& keyholders = *rooms[h_room.name()].mutable_keyholders();
253
254 if (!id_mappings_.maps().contains(current_map_name) ||
255 !id_mappings_.maps()
256 .at(current_map_name)
257 .rooms()
258 .contains(h_room.name()) ||
259 !id_mappings_.maps()
260 .at(current_map_name)
261 .rooms()
262 .at(h_room.name())
263 .keyholders()
264 .contains(h_keyholder.name())) {
265 keyholders[h_keyholder.name()] = next_id_++;
266 } else {
267 keyholders[h_keyholder.name()] = id_mappings_.maps()
268 .at(current_map_name)
269 .rooms()
270 .at(h_room.name())
271 .keyholders()
272 .at(h_keyholder.name());
273 }
274 }
275
276 for (const HumanPort& h_port : h_room.ports()) {
277 if (h_port.no_shuffle()) {
278 continue;
279 }
280
281 auto& maps = *output_.mutable_maps();
282 auto& rooms = *maps[current_map_name].mutable_rooms();
283 auto& ports = *rooms[h_room.name()].mutable_ports();
284
285 if (!id_mappings_.maps().contains(current_map_name) ||
286 !id_mappings_.maps()
287 .at(current_map_name)
288 .rooms()
289 .contains(h_room.name()) ||
290 !id_mappings_.maps()
291 .at(current_map_name)
292 .rooms()
293 .at(h_room.name())
294 .ports()
295 .contains(h_port.name())) {
296 ports[h_port.name()] = next_id_++;
297 } else {
298 ports[h_port.name()] = id_mappings_.maps()
299 .at(current_map_name)
300 .rooms()
301 .at(h_room.name())
302 .ports()
303 .at(h_port.name());
304 }
305 }
306 }
307
308 void ProcessSpecialIds() {
309 auto& specials = *output_.mutable_special();
310
311 for (const auto& [special_name, ap_id] : id_mappings_.special()) {
312 specials[special_name] = ap_id;
313 }
314 }
315
316 void ProcessProgressivesFile(std::filesystem::path path) {
317 if (!std::filesystem::exists(path)) {
318 return;
319 }
320
321 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
322 auto& progs = *output_.mutable_progressives();
323
324 for (const HumanProgressive& h_prog : h_progs.progressives()) {
325 if (!id_mappings_.progressives().contains(h_prog.name())) {
326 progs[h_prog.name()] = next_id_++;
327 } else {
328 progs[h_prog.name()] = id_mappings_.progressives().at(h_prog.name());
329 }
330 }
331 }
332
333 void ProcessDoorGroupsFile(std::filesystem::path path) {
334 if (!std::filesystem::exists(path)) {
335 return;
336 }
337
338 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
339 auto& groups = *output_.mutable_door_groups();
340
341 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
342 if (!id_mappings_.door_groups().contains(h_group.name())) {
343 groups[h_group.name()] = next_id_++;
344 } else {
345 groups[h_group.name()] = id_mappings_.door_groups().at(h_group.name());
346 }
347 }
348 }
349
350 void ProcessGlobalMetadataFile(std::filesystem::path path) {
351 if (!std::filesystem::exists(path)) {
352 return;
353 }
354
355 auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string());
356 auto& specials = *output_.mutable_special();
357
358 for (const std::string& h_special : h_metadata.special_names()) {
359 if (!id_mappings_.special().contains(h_special)) {
360 specials[h_special] = next_id_++;
361 } else {
362 specials[h_special] = id_mappings_.special().at(h_special);
209 } 363 }
210 } 364 }
211 } 365 }
212 366
213 private: 367 private:
368 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) {
369 for (const auto& [_, id] : ids) {
370 UpdateNextId(id);
371 }
372 }
373
374 void UpdateNextId(uint64_t id) {
375 if (id > next_id_) {
376 next_id_ = id;
377 }
378 }
379
214 std::string mapdir_; 380 std::string mapdir_;
215 381
216 uint64_t next_id_ = 1; 382 uint64_t next_id_ = 1;
217 383
218 IdMappings id_mappings_; 384 IdMappings id_mappings_;
385 IdMappings output_;
219}; 386};
220 387
221} // namespace 388} // namespace
diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp index 2c68552..4a656b3 100644 --- a/tools/datapacker/container.cpp +++ b/tools/datapacker/container.cpp
@@ -331,6 +331,40 @@ uint64_t Container::FindOrAddDoor(std::optional<std::string> map_name,
331 } 331 }
332} 332}
333 333
334uint64_t Container::FindOrAddProgressive(std::string prog_name) {
335 auto it = progressive_id_by_name_.find(prog_name);
336
337 if (it == progressive_id_by_name_.end()) {
338 uint64_t new_id = all_objects_.progressives_size();
339 Progressive* progressive = all_objects_.add_progressives();
340 progressive->set_id(new_id);
341 progressive->set_name(prog_name);
342
343 progressive_id_by_name_[prog_name] = new_id;
344
345 return new_id;
346 } else {
347 return it->second;
348 }
349}
350
351uint64_t Container::FindOrAddDoorGroup(std::string group_name) {
352 auto it = door_group_id_by_name_.find(group_name);
353
354 if (it == door_group_id_by_name_.end()) {
355 uint64_t new_id = all_objects_.door_groups_size();
356 DoorGroup* door_group = all_objects_.add_door_groups();
357 door_group->set_id(new_id);
358 door_group->set_name(group_name);
359
360 door_group_id_by_name_[group_name] = new_id;
361
362 return new_id;
363 } else {
364 return it->second;
365 }
366}
367
334void Container::AddConnection(const Connection& connection) { 368void Container::AddConnection(const Connection& connection) {
335 *all_objects_.add_connections() = connection; 369 *all_objects_.add_connections() = connection;
336} 370}
diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h index 68f5875..bc02ba4 100644 --- a/tools/datapacker/container.h +++ b/tools/datapacker/container.h
@@ -60,6 +60,10 @@ class Container {
60 60
61 void AddConnection(const Connection& connection); 61 void AddConnection(const Connection& connection);
62 62
63 uint64_t FindOrAddProgressive(std::string prog_name);
64
65 uint64_t FindOrAddDoorGroup(std::string group_name);
66
63 AllObjects& all_objects() { return all_objects_; } 67 AllObjects& all_objects() { return all_objects_; }
64 68
65 private: 69 private:
@@ -82,6 +86,8 @@ class Container {
82 std::map<std::string, std::map<std::string, uint64_t>> 86 std::map<std::string, std::map<std::string, uint64_t>>
83 door_id_by_map_door_names_; 87 door_id_by_map_door_names_;
84 std::map<std::string, uint64_t> ending_id_by_name_; 88 std::map<std::string, uint64_t> ending_id_by_name_;
89 std::map<std::string, uint64_t> progressive_id_by_name_;
90 std::map<std::string, uint64_t> door_group_id_by_name_;
85}; 91};
86 92
87} // namespace com::fourisland::lingo2_archipelago 93} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index d820360..4ecde74 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp
@@ -43,6 +43,9 @@ class DataPacker {
43 43
44 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 44 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
45 ProcessMaps(datadir_path); 45 ProcessMaps(datadir_path);
46 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
47 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
48 ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb");
46 ProcessIdsFile(datadir_path / "ids.yaml"); 49 ProcessIdsFile(datadir_path / "ids.yaml");
47 50
48 { 51 {
@@ -85,9 +88,28 @@ class DataPacker {
85 uint64_t map_id = container_.FindOrAddMap(map_name); 88 uint64_t map_id = container_.FindOrAddMap(map_name);
86 Map& map = *container_.all_objects().mutable_maps(map_id); 89 Map& map = *container_.all_objects().mutable_maps(map_id);
87 90
91 map.set_type(metadata.type());
92 map.set_daedalus_only_mode(metadata.daedalus_only_mode());
93
88 if (metadata.has_display_name()) { 94 if (metadata.has_display_name()) {
89 map.set_display_name(metadata.display_name()); 95 map.set_display_name(metadata.display_name());
90 } 96 }
97
98 if (metadata.has_worldport_entrance()) {
99 map.set_worldport_entrance(container_.FindOrAddPort(
100 map_name, metadata.worldport_entrance().room(),
101 metadata.worldport_entrance().name(), std::nullopt, std::nullopt));
102 }
103
104 if (metadata.has_rte_room()) {
105 map.set_rte_room(container_.FindOrAddRoom(map_name, metadata.rte_room(),
106 std::nullopt));
107 }
108
109 if (metadata.has_rte_trigger_pos()) {
110 *map.mutable_rte_trigger_pos() = metadata.rte_trigger_pos();
111 *map.mutable_rte_trigger_scale() = metadata.rte_trigger_scale();
112 }
91 } 113 }
92 114
93 void ProcessRooms(std::filesystem::path path, 115 void ProcessRooms(std::filesystem::path path,
@@ -104,7 +126,15 @@ class DataPacker {
104 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); 126 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt);
105 Room& room = *container_.all_objects().mutable_rooms(room_id); 127 Room& room = *container_.all_objects().mutable_rooms(room_id);
106 128
107 room.set_display_name(h_room.display_name()); 129 // room.set_display_name(h_room.display_name());
130
131 if (h_room.has_panel_display_name()) {
132 room.set_panel_display_name(h_room.panel_display_name());
133 }
134
135 if (h_room.has_daedalus_only_allow()) {
136 room.set_daedalus_only_allow(h_room.daedalus_only_allow());
137 }
108 138
109 for (const HumanPanel& h_panel : h_room.panels()) { 139 for (const HumanPanel& h_panel : h_room.panels()) {
110 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name())); 140 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name()));
@@ -175,6 +205,14 @@ class DataPacker {
175 map_name, h_panel.required_room().name(), current_map_name)); 205 map_name, h_panel.required_room().name(), current_map_name));
176 } 206 }
177 207
208 if (h_panel.has_display_name()) {
209 panel.set_display_name(h_panel.display_name());
210 }
211
212 if (h_panel.has_exclude_from_panelsanity()) {
213 panel.set_exclude_from_panelsanity(h_panel.exclude_from_panelsanity());
214 }
215
178 return panel_id; 216 return panel_id;
179 } 217 }
180 218
@@ -228,7 +266,14 @@ class DataPacker {
228 Port& port = *container_.all_objects().mutable_ports(port_id); 266 Port& port = *container_.all_objects().mutable_ports(port_id);
229 267
230 port.set_path(h_port.path()); 268 port.set_path(h_port.path());
231 port.set_orientation(h_port.orientation()); 269 port.set_display_name(h_port.display_name());
270
271 if (h_port.no_shuffle()) {
272 port.set_no_shuffle(h_port.no_shuffle());
273 } else {
274 *port.mutable_destination() = h_port.destination();
275 port.set_rotation(h_port.rotation());
276 }
232 277
233 // Setting this explicitly because the Godot protobuf doesn't support 278 // Setting this explicitly because the Godot protobuf doesn't support
234 // custom defaults. 279 // custom defaults.
@@ -284,6 +329,10 @@ class DataPacker {
284 329
285 keyholder.set_path(h_keyholder.path()); 330 keyholder.set_path(h_keyholder.path());
286 331
332 if (h_keyholder.has_key()) {
333 keyholder.set_key(h_keyholder.key());
334 }
335
287 return keyholder_id; 336 return keyholder_id;
288 } 337 }
289 338
@@ -331,8 +380,8 @@ class DataPacker {
331 h_door.receivers().begin(), h_door.receivers().end(), 380 h_door.receivers().begin(), h_door.receivers().end(),
332 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers())); 381 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers()));
333 std::copy( 382 std::copy(
334 h_door.switches().begin(), h_door.switches().end(), 383 h_door.senders().begin(), h_door.senders().end(),
335 google::protobuf::RepeatedFieldBackInserter(door.mutable_switches())); 384 google::protobuf::RepeatedFieldBackInserter(door.mutable_senders()));
336 385
337 for (const PaintingIdentifier& pi : h_door.move_paintings()) { 386 for (const PaintingIdentifier& pi : h_door.move_paintings()) {
338 std::optional<std::string> map_name = 387 std::optional<std::string> map_name =
@@ -380,9 +429,9 @@ class DataPacker {
380 door.add_doors( 429 door.add_doors(
381 container_.FindOrAddDoor(map_name, di.name(), current_map_name)); 430 container_.FindOrAddDoor(map_name, di.name(), current_map_name));
382 } 431 }
383 432
384 for (const std::string& ending_name : h_door.endings()) { 433 if (h_door.has_white_ending()) {
385 door.add_endings(container_.FindOrAddEnding(ending_name)); 434 door.set_white_ending(h_door.white_ending());
386 } 435 }
387 436
388 if (h_door.has_control_center_color()) { 437 if (h_door.has_control_center_color()) {
@@ -394,6 +443,30 @@ class DataPacker {
394 } 443 }
395 444
396 door.set_type(h_door.type()); 445 door.set_type(h_door.type());
446
447 if (h_door.has_location_name()) {
448 door.set_location_name(h_door.location_name());
449 }
450
451 if (h_door.has_double_letters()) {
452 door.set_double_letters(h_door.double_letters());
453 }
454
455 if (h_door.has_latch()) {
456 door.set_latch(h_door.latch());
457 }
458
459 if (h_door.has_legacy_location()) {
460 door.set_legacy_location(h_door.legacy_location());
461 }
462
463 if (h_door.has_daedalus_only_allow()) {
464 door.set_daedalus_only_allow(h_door.daedalus_only_allow());
465 }
466
467 if (h_door.has_daedalus_only_always_item()) {
468 door.set_daedalus_only_always_item(h_door.daedalus_only_always_item());
469 }
397 } 470 }
398 471
399 void ProcessConnectionsFile(std::filesystem::path path, 472 void ProcessConnectionsFile(std::filesystem::path path,
@@ -445,6 +518,31 @@ class DataPacker {
445 r_connection.set_required_door(door_id); 518 r_connection.set_required_door(door_id);
446 } 519 }
447 520
521 if (human_connection.has_roof_access()) {
522 f_connection.set_roof_access(human_connection.roof_access());
523 r_connection.set_roof_access(human_connection.roof_access());
524 }
525
526 if (human_connection.has_purple_ending()) {
527 f_connection.set_purple_ending(human_connection.purple_ending());
528 r_connection.set_purple_ending(human_connection.purple_ending());
529 }
530
531 if (human_connection.has_cyan_ending()) {
532 f_connection.set_cyan_ending(human_connection.cyan_ending());
533 r_connection.set_cyan_ending(human_connection.cyan_ending());
534 }
535
536 if (human_connection.has_mint_ending()) {
537 f_connection.set_mint_ending(human_connection.mint_ending());
538 r_connection.set_mint_ending(human_connection.mint_ending());
539 }
540
541 if (human_connection.has_vanilla_only()) {
542 f_connection.set_vanilla_only(human_connection.vanilla_only());
543 r_connection.set_vanilla_only(human_connection.vanilla_only());
544 }
545
448 container_.AddConnection(f_connection); 546 container_.AddConnection(f_connection);
449 if (!human_connection.oneway()) { 547 if (!human_connection.oneway()) {
450 container_.AddConnection(r_connection); 548 container_.AddConnection(r_connection);
@@ -528,6 +626,67 @@ class DataPacker {
528 } 626 }
529 } 627 }
530 628
629 void ProcessProgressivesFile(std::filesystem::path path) {
630 if (!std::filesystem::exists(path)) {
631 return;
632 }
633
634 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
635
636 for (const HumanProgressive& h_prog : h_progs.progressives()) {
637 ProcessProgressive(h_prog);
638 }
639 }
640
641 void ProcessProgressive(const HumanProgressive& h_prog) {
642 uint64_t prog_id = container_.FindOrAddProgressive(h_prog.name());
643 Progressive& prog = *container_.all_objects().mutable_progressives(prog_id);
644
645 for (const DoorIdentifier& di : h_prog.doors()) {
646 uint64_t door_id =
647 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
648 prog.add_doors(door_id);
649 }
650 }
651
652 void ProcessDoorGroupsFile(std::filesystem::path path) {
653 if (!std::filesystem::exists(path)) {
654 return;
655 }
656
657 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
658
659 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
660 ProcessDoorGroup(h_group);
661 }
662 }
663
664 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
665 uint64_t group_id = container_.FindOrAddDoorGroup(h_group.name());
666 DoorGroup& group = *container_.all_objects().mutable_door_groups(group_id);
667
668 group.set_type(h_group.type());
669
670 for (const DoorIdentifier& di : h_group.doors()) {
671 uint64_t door_id =
672 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
673 group.add_doors(door_id);
674 }
675
676 if (h_group.has_daedalus_only_always_item()) {
677 group.set_daedalus_only_always_item(h_group.daedalus_only_always_item());
678 }
679 }
680
681 void ProcessGlobalMetadataFile(std::filesystem::path path) {
682 if (!std::filesystem::exists(path)) {
683 return;
684 }
685
686 auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string());
687 *container_.all_objects().mutable_version() = h_metadata.version();
688 }
689
531 void ProcessIdsFile(std::filesystem::path path) { 690 void ProcessIdsFile(std::filesystem::path path) {
532 auto ids = ReadIdsFromYaml(path.string()); 691 auto ids = ReadIdsFromYaml(path.string());
533 692
@@ -552,6 +711,25 @@ class DataPacker {
552 .mutable_masteries(mastery_id) 711 .mutable_masteries(mastery_id)
553 ->set_ap_id(ap_id); 712 ->set_ap_id(ap_id);
554 } 713 }
714
715 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
716 uint64_t keyholder_id = container_.FindOrAddKeyholder(
717 map_name, room_name, keyholder_name, std::nullopt, std::nullopt);
718 container_.all_objects()
719 .mutable_keyholders(keyholder_id)
720 ->set_ap_id(ap_id);
721 }
722
723 for (const auto& [port_name, ap_id] : room.ports()) {
724 uint64_t port_id = container_.FindOrAddPort(
725 map_name, room_name, port_name, std::nullopt, std::nullopt);
726 container_.all_objects().mutable_ports(port_id)->set_ap_id(ap_id);
727 }
728 }
729
730 if (map.has_rte()) {
731 uint64_t map_id = container_.FindOrAddMap(map_name);
732 container_.all_objects().mutable_maps(map_id)->set_rte_ap_id(map.rte());
555 } 733 }
556 } 734 }
557 735
@@ -569,6 +747,16 @@ class DataPacker {
569 uint64_t ending_id = container_.FindOrAddEnding(ending_name); 747 uint64_t ending_id = container_.FindOrAddEnding(ending_name);
570 container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id); 748 container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id);
571 } 749 }
750
751 for (const auto& [prog_name, ap_id] : ids.progressives()) {
752 uint64_t prog_id = container_.FindOrAddProgressive(prog_name);
753 container_.all_objects().mutable_progressives(prog_id)->set_ap_id(ap_id);
754 }
755
756 for (const auto& [group_name, ap_id] : ids.door_groups()) {
757 uint64_t group_id = container_.FindOrAddDoorGroup(group_name);
758 container_.all_objects().mutable_door_groups(group_id)->set_ap_id(ap_id);
759 }
572 } 760 }
573 761
574 std::string mapdir_; 762 std::string mapdir_;
diff --git a/tools/util/godot_scene.cpp b/tools/util/godot_scene.cpp index 1e77c9e..f788d21 100644 --- a/tools/util/godot_scene.cpp +++ b/tools/util/godot_scene.cpp
@@ -1,10 +1,8 @@
1#include "godot_scene.h" 1#include "godot_scene.h"
2 2
3#include <absl/strings/str_split.h>
4#include <absl/strings/string_view.h>
5
6#include <fstream> 3#include <fstream>
7#include <sstream> 4#include <sstream>
5#include <string_view>
8#include <variant> 6#include <variant>
9 7
10namespace com::fourisland::lingo2_archipelago { 8namespace com::fourisland::lingo2_archipelago {
@@ -23,7 +21,7 @@ struct Heading {
23 GodotInstanceType instance_type; 21 GodotInstanceType instance_type;
24}; 22};
25 23
26Heading ParseTscnHeading(absl::string_view line) { 24Heading ParseTscnHeading(std::string_view line) {
27 std::string original_line(line); 25 std::string original_line(line);
28 Heading heading; 26 Heading heading;
29 27
diff --git a/tools/util/ids_yaml_format.cpp b/tools/util/ids_yaml_format.cpp index f72f60e..c23c66b 100644 --- a/tools/util/ids_yaml_format.cpp +++ b/tools/util/ids_yaml_format.cpp
@@ -56,6 +56,21 @@ IdMappings ReadIdsFromYaml(const std::string& filename) {
56 mastery_it.second.as<uint64_t>(); 56 mastery_it.second.as<uint64_t>();
57 } 57 }
58 } 58 }
59
60 if (room_it.second["keyholders"]) {
61 for (const auto& keyholder_it : room_it.second["keyholders"]) {
62 (*room_ids.mutable_keyholders())[keyholder_it.first
63 .as<std::string>()] =
64 keyholder_it.second.as<uint64_t>();
65 }
66 }
67
68 if (room_it.second["ports"]) {
69 for (const auto& port_it : room_it.second["ports"]) {
70 (*room_ids.mutable_ports())[port_it.first.as<std::string>()] =
71 port_it.second.as<uint64_t>();
72 }
73 }
59 } 74 }
60 } 75 }
61 76
@@ -65,6 +80,10 @@ IdMappings ReadIdsFromYaml(const std::string& filename) {
65 door_it.second.as<uint64_t>(); 80 door_it.second.as<uint64_t>();
66 } 81 }
67 } 82 }
83
84 if (map_it.second["rte"]) {
85 map_ids.set_rte(map_it.second["rte"].as<uint64_t>());
86 }
68 } 87 }
69 } 88 }
70 89
@@ -89,6 +108,20 @@ IdMappings ReadIdsFromYaml(const std::string& filename) {
89 } 108 }
90 } 109 }
91 110
111 if (document["progressives"]) {
112 for (const auto& prog_it : document["progressives"]) {
113 (*result.mutable_progressives())[prog_it.first.as<std::string>()] =
114 prog_it.second.as<uint64_t>();
115 }
116 }
117
118 if (document["door_groups"]) {
119 for (const auto& group_it : document["door_groups"]) {
120 (*result.mutable_door_groups())[group_it.first.as<std::string>()] =
121 group_it.second.as<uint64_t>();
122 }
123 }
124
92 return result; 125 return result;
93} 126}
94 127
@@ -117,6 +150,19 @@ void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) {
117 mastery_id; 150 mastery_id;
118 }); 151 });
119 152
153 OperateOnSortedMap(room_ids.keyholders(),
154 [&room_node](const std::string& keyholder_name,
155 uint64_t keyholder_id) {
156 room_node["keyholders"][keyholder_name] =
157 keyholder_id;
158 });
159
160 OperateOnSortedMap(
161 room_ids.ports(),
162 [&room_node](const std::string& port_name, uint64_t port_id) {
163 room_node["ports"][port_name] = port_id;
164 });
165
120 map_node["rooms"][room_name] = std::move(room_node); 166 map_node["rooms"][room_name] = std::move(room_node);
121 }); 167 });
122 168
@@ -126,6 +172,10 @@ void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) {
126 map_node["doors"][door_name] = door_id; 172 map_node["doors"][door_name] = door_id;
127 }); 173 });
128 174
175 if (map_ids.has_rte()) {
176 map_node["rte"] = map_ids.rte();
177 }
178
129 result["maps"][map_name] = std::move(map_node); 179 result["maps"][map_name] = std::move(map_node);
130 }); 180 });
131 181
@@ -144,6 +194,16 @@ void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) {
144 result["special"][special_name] = special_id; 194 result["special"][special_name] = special_id;
145 }); 195 });
146 196
197 OperateOnSortedMap(ids.progressives(),
198 [&result](const std::string& prog_name, uint64_t prog_id) {
199 result["progressives"][prog_name] = prog_id;
200 });
201
202 OperateOnSortedMap(ids.door_groups(), [&result](const std::string& group_name,
203 uint64_t group_id) {
204 result["door_groups"][group_name] = group_id;
205 });
206
147 std::ofstream output_stream(filename); 207 std::ofstream output_stream(filename);
148 output_stream << result << std::endl; 208 output_stream << result << std::endl;
149} 209}
diff --git a/tools/validator/CMakeLists.txt b/tools/validator/CMakeLists.txt index 967b890..1a8fd9c 100644 --- a/tools/validator/CMakeLists.txt +++ b/tools/validator/CMakeLists.txt
@@ -1,3 +1,4 @@
1find_package(fmt REQUIRED)
1find_package(Protobuf REQUIRED) 2find_package(Protobuf REQUIRED)
2 3
3add_executable(validator 4add_executable(validator
@@ -9,4 +10,4 @@ add_executable(validator
9set_property(TARGET validator PROPERTY CXX_STANDARD 20) 10set_property(TARGET validator PROPERTY CXX_STANDARD 20)
10set_property(TARGET validator PROPERTY CXX_STANDARD_REQUIRED ON) 11set_property(TARGET validator PROPERTY CXX_STANDARD_REQUIRED ON)
11target_include_directories(validator PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools) 12target_include_directories(validator PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools)
12target_link_libraries(validator PUBLIC protos util protobuf::libprotobuf) 13target_link_libraries(validator PUBLIC protos util fmt::fmt protobuf::libprotobuf)
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index f53dc79..d6fcfa6 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp
@@ -1,5 +1,6 @@
1#include "human_processor.h" 1#include "human_processor.h"
2 2
3#include <fmt/core.h>
3#include <google/protobuf/message.h> 4#include <google/protobuf/message.h>
4#include <google/protobuf/text_format.h> 5#include <google/protobuf/text_format.h>
5 6
@@ -12,6 +13,7 @@
12#include <string> 13#include <string>
13 14
14#include "structs.h" 15#include "structs.h"
16#include "util/ids_yaml_format.h"
15 17
16namespace com::fourisland::lingo2_archipelago { 18namespace com::fourisland::lingo2_archipelago {
17namespace { 19namespace {
@@ -40,7 +42,9 @@ class HumanProcessor {
40 42
41 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
42 ProcessMaps(datadir_path); 44 ProcessMaps(datadir_path);
43 ProcessIdsFile(datadir_path / "ids.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
44 } 48 }
45 49
46 private: 50 private:
@@ -70,9 +74,35 @@ class HumanProcessor {
70 MapInfo& map_info = info_.maps[current_map_name]; 74 MapInfo& map_info = info_.maps[current_map_name];
71 75
72 auto metadata = ReadMessageFromFile<HumanMap>(path.string()); 76 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
77 map_info.definitions.push_back(metadata);
78
73 for (const std::string& path : metadata.excluded_nodes()) { 79 for (const std::string& path : metadata.excluded_nodes()) {
74 map_info.game_nodes[path].uses++; 80 map_info.game_nodes[path].uses++;
75 } 81 }
82
83 for (const std::string& path : metadata.custom_nodes()) {
84 map_info.game_nodes[path].defined = true;
85 }
86
87 if (metadata.has_worldport_entrance()) {
88 auto port_identifier = GetCompletePortIdentifier(
89 metadata.worldport_entrance(), current_map_name, std::nullopt);
90 if (port_identifier) {
91 PortInfo& port_info = info_.ports[*port_identifier];
92 port_info.map_worldport_entrances.push_back(current_map_name);
93 } else {
94 map_info.malformed_worldport_entrance = metadata.worldport_entrance();
95 }
96 }
97
98 if (metadata.has_rte_room()) {
99 RoomIdentifier room_identifier;
100 room_identifier.set_map(current_map_name);
101 room_identifier.set_name(metadata.rte_room());
102
103 RoomInfo& room_info = info_.rooms[room_identifier];
104 room_info.map_rtes_referenced_by.push_back(current_map_name);
105 }
76 } 106 }
77 107
78 void ProcessRooms(std::filesystem::path path, 108 void ProcessRooms(std::filesystem::path path,
@@ -93,7 +123,7 @@ class HumanProcessor {
93 room_info.definitions.push_back(h_room); 123 room_info.definitions.push_back(h_room);
94 124
95 for (const HumanPanel& h_panel : h_room.panels()) { 125 for (const HumanPanel& h_panel : h_room.panels()) {
96 ProcessPanel(h_panel, current_map_name, h_room.name()); 126 ProcessPanel(h_panel, current_map_name, h_room);
97 } 127 }
98 128
99 for (const HumanPainting& h_painting : h_room.paintings()) { 129 for (const HumanPainting& h_painting : h_room.paintings()) {
@@ -123,15 +153,14 @@ class HumanProcessor {
123 153
124 void ProcessPanel(const HumanPanel& h_panel, 154 void ProcessPanel(const HumanPanel& h_panel,
125 const std::string& current_map_name, 155 const std::string& current_map_name,
126 const std::string& current_room_name) { 156 const HumanRoom& h_room) {
127 PanelIdentifier panel_identifier; 157 PanelIdentifier panel_identifier;
128 panel_identifier.set_map(current_map_name); 158 panel_identifier.set_map(current_map_name);
129 panel_identifier.set_room(current_room_name); 159 panel_identifier.set_room(h_room.name());
130 panel_identifier.set_name(h_panel.name()); 160 panel_identifier.set_name(h_panel.name());
131 161
132 PanelInfo& panel_info = info_.panels[panel_identifier]; 162 PanelInfo& panel_info = info_.panels[panel_identifier];
133 panel_info.definitions.push_back(h_panel); 163 panel_info.definitions.push_back(h_panel);
134 panel_info.proxies[h_panel.answer()].definitions.push_back(Proxy());
135 164
136 MapInfo& map_info = info_.maps[current_map_name]; 165 MapInfo& map_info = info_.maps[current_map_name];
137 map_info.game_nodes[h_panel.path()].uses++; 166 map_info.game_nodes[h_panel.path()].uses++;
@@ -156,6 +185,24 @@ class HumanProcessor {
156 RoomInfo& required_room_info = info_.rooms[required_room_identifier]; 185 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
157 required_room_info.panels_referenced_by.push_back(panel_identifier); 186 required_room_info.panels_referenced_by.push_back(panel_identifier);
158 } 187 }
188
189 std::string map_area_name = current_map_name;
190 if (h_room.has_panel_display_name()) {
191 map_area_name =
192 fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
193 }
194
195 panel_info.map_area_name = map_area_name;
196
197 std::string panelsanity_name;
198 if (h_panel.has_display_name()) {
199 panelsanity_name =
200 fmt::format("{} - {}", map_area_name, h_panel.display_name());
201 } else {
202 panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
203 }
204 info_.panel_names[panelsanity_name].panels_used_by.push_back(
205 panel_identifier);
159 } 206 }
160 207
161 void ProcessPainting(const HumanPainting& h_painting, 208 void ProcessPainting(const HumanPainting& h_painting,
@@ -337,11 +384,6 @@ class HumanProcessor {
337 DoorInfo& other_door_info = info_.doors[complete_door_identifier]; 384 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
338 other_door_info.doors_referenced_by.push_back(door_identifier); 385 other_door_info.doors_referenced_by.push_back(door_identifier);
339 } 386 }
340
341 for (const std::string& ei : h_door.endings()) {
342 EndingInfo& ending_info = info_.endings[ei];
343 ending_info.doors_referenced_by.push_back(door_identifier);
344 }
345 } 387 }
346 388
347 void ProcessConnectionsFile(std::filesystem::path path, 389 void ProcessConnectionsFile(std::filesystem::path path,
@@ -373,7 +415,9 @@ class HumanProcessor {
373 } 415 }
374 } else if (human_connection.has_from()) { 416 } else if (human_connection.has_from()) {
375 ProcessSingleConnection(human_connection, human_connection.from(), 417 ProcessSingleConnection(human_connection, human_connection.from(),
376 current_map_name); 418 current_map_name,
419 /*is_target=*/!human_connection.oneway() &&
420 !human_connection.bypass_target_door());
377 } 421 }
378 422
379 if (human_connection.has_to_room()) { 423 if (human_connection.has_to_room()) {
@@ -389,8 +433,9 @@ class HumanProcessor {
389 std::cout << "A global connection used to_room." << std::endl; 433 std::cout << "A global connection used to_room." << std::endl;
390 } 434 }
391 } else if (human_connection.has_to()) { 435 } else if (human_connection.has_to()) {
392 ProcessSingleConnection(human_connection, human_connection.to(), 436 ProcessSingleConnection(
393 current_map_name); 437 human_connection, human_connection.to(), current_map_name,
438 /*is_target=*/!human_connection.bypass_target_door());
394 } 439 }
395 440
396 if (human_connection.has_door()) { 441 if (human_connection.has_door()) {
@@ -411,7 +456,7 @@ class HumanProcessor {
411 void ProcessSingleConnection( 456 void ProcessSingleConnection(
412 const HumanConnection& human_connection, 457 const HumanConnection& human_connection,
413 const HumanConnection::Endpoint& endpoint, 458 const HumanConnection::Endpoint& endpoint,
414 const std::optional<std::string>& current_map_name) { 459 const std::optional<std::string>& current_map_name, bool is_target) {
415 if (endpoint.has_room()) { 460 if (endpoint.has_room()) {
416 auto room_identifier = 461 auto room_identifier =
417 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 462 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -430,6 +475,11 @@ class HumanProcessor {
430 if (painting_identifier) { 475 if (painting_identifier) {
431 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 476 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
432 painting_info.connections_referenced_by.push_back(human_connection); 477 painting_info.connections_referenced_by.push_back(human_connection);
478
479 if (is_target) {
480 painting_info.target_connections_referenced_by.push_back(
481 human_connection);
482 }
433 } else { 483 } else {
434 // Not sure where else to store this right now. 484 // Not sure where else to store this right now.
435 std::cout 485 std::cout
@@ -442,6 +492,11 @@ class HumanProcessor {
442 if (port_identifier) { 492 if (port_identifier) {
443 PortInfo& port_info = info_.ports[*port_identifier]; 493 PortInfo& port_info = info_.ports[*port_identifier];
444 port_info.connections_referenced_by.push_back(human_connection); 494 port_info.connections_referenced_by.push_back(human_connection);
495
496 if (is_target) {
497 port_info.target_connections_referenced_by.push_back(
498 human_connection);
499 }
445 } else { 500 } else {
446 // Not sure where else to store this right now. 501 // Not sure where else to store this right now.
447 std::cout 502 std::cout
@@ -459,12 +514,152 @@ class HumanProcessor {
459 panel_info.proxies[endpoint.panel().answer()] 514 panel_info.proxies[endpoint.panel().answer()]
460 .connections_referenced_by.push_back(human_connection); 515 .connections_referenced_by.push_back(human_connection);
461 } 516 }
517
518 if (is_target) {
519 panel_info.target_connections_referenced_by.push_back(
520 human_connection);
521 }
462 } 522 }
463 } 523 }
464 } 524 }
465 525
526 void ProcessProgressivesFile(std::filesystem::path path) {
527 if (!std::filesystem::exists(path)) {
528 return;
529 }
530
531 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
532
533 for (const HumanProgressive& h_prog : h_progs.progressives()) {
534 ProcessProgressive(h_prog);
535 }
536 }
537
538 void ProcessProgressive(const HumanProgressive& h_prog) {
539 ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
540 prog_info.definitions.push_back(h_prog);
541
542 for (const DoorIdentifier& di : h_prog.doors()) {
543 if (!di.has_map()) {
544 prog_info.malformed_doors.push_back(di);
545 continue;
546 }
547
548 DoorInfo& door_info = info_.doors[di];
549 door_info.progressives_referenced_by.push_back(h_prog.name());
550 }
551 }
552
553 void ProcessDoorGroupsFile(std::filesystem::path path) {
554 if (!std::filesystem::exists(path)) {
555 return;
556 }
557
558 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
559
560 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
561 ProcessDoorGroup(h_group);
562 }
563 }
564
565 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
566 DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
567 group_info.definitions.push_back(h_group);
568
569 for (const DoorIdentifier& di : h_group.doors()) {
570 if (!di.has_map()) {
571 group_info.malformed_doors.push_back(di);
572 continue;
573 }
574
575 DoorInfo& door_info = info_.doors[di];
576 door_info.door_groups_referenced_by.push_back(h_group.name());
577 }
578 }
579
466 void ProcessIdsFile(std::filesystem::path path) { 580 void ProcessIdsFile(std::filesystem::path path) {
467 // Ignore this for now. 581 auto ids = ReadIdsFromYaml(path.string());
582
583 DoorIdentifier di;
584 PanelIdentifier pai;
585 PortIdentifier poi;
586 KeyholderIdentifier ki;
587
588 for (const auto& [map_name, map] : ids.maps()) {
589 di.set_map(map_name);
590 pai.set_map(map_name);
591 poi.set_map(map_name);
592 ki.set_map(map_name);
593
594 for (const auto& [door_name, ap_id] : map.doors()) {
595 di.set_name(door_name);
596
597 DoorInfo& door_info = info_.doors[di];
598 door_info.has_id = true;
599 }
600
601 for (const auto& [room_name, room] : map.rooms()) {
602 pai.set_room(room_name);
603 poi.set_room(room_name);
604 ki.set_room(room_name);
605
606 for (const auto& [panel_name, ap_id] : room.panels()) {
607 pai.set_name(panel_name);
608
609 PanelInfo& panel_info = info_.panels[pai];
610 panel_info.has_id = true;
611 }
612
613 for (const auto& [mastery_name, ap_id] : room.masteries()) {
614 // TODO: Mastery
615 }
616
617 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
618 ki.set_name(keyholder_name);
619
620 KeyholderInfo& keyholder_info = info_.keyholders[ki];
621 keyholder_info.has_id = true;
622 }
623
624 for (const auto& [port_name, ap_id] : room.ports()) {
625 poi.set_name(port_name);
626
627 PortInfo& port_info = info_.ports[poi];
628 port_info.has_id = true;
629 }
630 }
631
632 if (map.has_rte()) {
633 MapInfo& map_info = info_.maps[map_name];
634 map_info.has_rte_id = true;
635 }
636 }
637
638 for (const auto& [tag, id] : ids.special()) {
639 // TODO: Specials
640 }
641
642 for (const auto& [letter_name, ap_id] : ids.letters()) {
643 LetterIdentifier li =
644 std::make_tuple(letter_name[0], letter_name[1] == '2');
645 LetterInfo& letter_info = info_.letters[li];
646 letter_info.has_id = true;
647 }
648
649 for (const auto& [ending_name, ap_id] : ids.endings()) {
650 EndingInfo& ending_info = info_.endings[ending_name];
651 ending_info.has_id = true;
652 }
653
654 for (const auto& [prog_name, ap_id] : ids.progressives()) {
655 ProgressiveInfo& prog_info = info_.progressives[prog_name];
656 prog_info.has_id = true;
657 }
658
659 for (const auto& [group_name, ap_id] : ids.door_groups()) {
660 DoorGroupInfo& group_info = info_.door_groups[group_name];
661 group_info.has_id = true;
662 }
468 } 663 }
469 664
470 std::string mapdir_; 665 std::string mapdir_;
diff --git a/tools/validator/main.cpp b/tools/validator/main.cpp index 1a72e9a..6139e95 100644 --- a/tools/validator/main.cpp +++ b/tools/validator/main.cpp
@@ -21,7 +21,9 @@ void Run(const std::string& mapdir, const std::string& repodir) {
21int main(int argc, char** argv) { 21int main(int argc, char** argv) {
22 if (argc != 3) { 22 if (argc != 3) {
23 std::cout << "Incorrect argument count." << std::endl; 23 std::cout << "Incorrect argument count." << std::endl;
24 std::cout << "Usage: validator [path to map directory] [path to Lingo 2 repository]" << std::endl; 24 std::cout << "Usage: validator [path to map directory] [path to Lingo 2 "
25 "repository]"
26 << std::endl;
25 return 1; 27 return 1;
26 } 28 }
27 29
diff --git a/tools/validator/structs.h b/tools/validator/structs.h index 958038d..81a0e8f 100644 --- a/tools/validator/structs.h +++ b/tools/validator/structs.h
@@ -27,6 +27,11 @@ struct GameNodeInfo {
27 27
28struct MapInfo { 28struct MapInfo {
29 std::map<std::string, GameNodeInfo> game_nodes; 29 std::map<std::string, GameNodeInfo> game_nodes;
30
31 std::vector<HumanMap> definitions;
32 bool has_rte_id = false;
33
34 std::optional<PortIdentifier> malformed_worldport_entrance;
30}; 35};
31 36
32struct RoomInfo { 37struct RoomInfo {
@@ -35,30 +40,38 @@ struct RoomInfo {
35 std::vector<DoorIdentifier> doors_referenced_by; 40 std::vector<DoorIdentifier> doors_referenced_by;
36 std::vector<PanelIdentifier> panels_referenced_by; 41 std::vector<PanelIdentifier> panels_referenced_by;
37 std::vector<HumanConnection> connections_referenced_by; 42 std::vector<HumanConnection> connections_referenced_by;
43 std::vector<std::string> map_rtes_referenced_by;
38}; 44};
39 45
40struct DoorInfo { 46struct DoorInfo {
41 std::vector<HumanDoor> definitions; 47 std::vector<HumanDoor> definitions;
48 bool has_id = false;
42 49
43 std::vector<HumanConnection> connections_referenced_by; 50 std::vector<HumanConnection> connections_referenced_by;
44 std::vector<DoorIdentifier> doors_referenced_by; 51 std::vector<DoorIdentifier> doors_referenced_by;
45 std::vector<PanelIdentifier> panels_referenced_by; 52 std::vector<PanelIdentifier> panels_referenced_by;
46 std::vector<PaintingIdentifier> paintings_referenced_by; 53 std::vector<PaintingIdentifier> paintings_referenced_by;
47 std::vector<PortIdentifier> ports_referenced_by; 54 std::vector<PortIdentifier> ports_referenced_by;
55 std::vector<std::string> progressives_referenced_by;
56 std::vector<std::string> door_groups_referenced_by;
48 57
49 MalformedIdentifiers malformed_identifiers; 58 MalformedIdentifiers malformed_identifiers;
50}; 59};
51 60
52struct PortInfo { 61struct PortInfo {
53 std::vector<HumanPort> definitions; 62 std::vector<HumanPort> definitions;
63 bool has_id = false;
54 64
55 std::vector<HumanConnection> connections_referenced_by; 65 std::vector<HumanConnection> connections_referenced_by;
66 std::vector<HumanConnection> target_connections_referenced_by;
67 std::vector<std::string> map_worldport_entrances;
56}; 68};
57 69
58struct PaintingInfo { 70struct PaintingInfo {
59 std::vector<HumanPainting> definitions; 71 std::vector<HumanPainting> definitions;
60 72
61 std::vector<HumanConnection> connections_referenced_by; 73 std::vector<HumanConnection> connections_referenced_by;
74 std::vector<HumanConnection> target_connections_referenced_by;
62 std::vector<DoorIdentifier> doors_referenced_by; 75 std::vector<DoorIdentifier> doors_referenced_by;
63}; 76};
64 77
@@ -71,8 +84,12 @@ struct ProxyInfo {
71 84
72struct PanelInfo { 85struct PanelInfo {
73 std::vector<HumanPanel> definitions; 86 std::vector<HumanPanel> definitions;
87 bool has_id = false;
88
89 std::string map_area_name;
74 90
75 std::vector<HumanConnection> connections_referenced_by; 91 std::vector<HumanConnection> connections_referenced_by;
92 std::vector<HumanConnection> target_connections_referenced_by;
76 std::vector<DoorIdentifier> doors_referenced_by; 93 std::vector<DoorIdentifier> doors_referenced_by;
77 94
78 std::map<std::string, ProxyInfo> proxies; 95 std::map<std::string, ProxyInfo> proxies;
@@ -80,6 +97,7 @@ struct PanelInfo {
80 97
81struct KeyholderInfo { 98struct KeyholderInfo {
82 std::vector<HumanKeyholder> definitions; 99 std::vector<HumanKeyholder> definitions;
100 bool has_id = false;
83 101
84 std::vector<DoorIdentifier> doors_referenced_by; 102 std::vector<DoorIdentifier> doors_referenced_by;
85}; 103};
@@ -88,12 +106,30 @@ using LetterIdentifier = std::tuple<char, bool>;
88 106
89struct LetterInfo { 107struct LetterInfo {
90 std::vector<RoomIdentifier> defined_in; 108 std::vector<RoomIdentifier> defined_in;
109 bool has_id = false;
91}; 110};
92 111
93struct EndingInfo { 112struct EndingInfo {
94 std::vector<RoomIdentifier> defined_in; 113 std::vector<RoomIdentifier> defined_in;
114 bool has_id = false;
115};
95 116
96 std::vector<DoorIdentifier> doors_referenced_by; 117struct PanelNameInfo {
118 std::vector<PanelIdentifier> panels_used_by;
119};
120
121struct ProgressiveInfo {
122 std::vector<HumanProgressive> definitions;
123 bool has_id = false;
124
125 std::vector<DoorIdentifier> malformed_doors;
126};
127
128struct DoorGroupInfo {
129 std::vector<HumanDoorGroup> definitions;
130 bool has_id = false;
131
132 std::vector<DoorIdentifier> malformed_doors;
97}; 133};
98 134
99struct CollectedInfo { 135struct CollectedInfo {
@@ -107,6 +143,9 @@ struct CollectedInfo {
107 keyholders; 143 keyholders;
108 std::map<LetterIdentifier, LetterInfo> letters; 144 std::map<LetterIdentifier, LetterInfo> letters;
109 std::map<std::string, EndingInfo> endings; 145 std::map<std::string, EndingInfo> endings;
146 std::map<std::string, PanelNameInfo> panel_names;
147 std::map<std::string, ProgressiveInfo> progressives;
148 std::map<std::string, DoorGroupInfo> door_groups;
110}; 149};
111 150
112} // namespace com::fourisland::lingo2_archipelago 151} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp index f802460..e9fbb74 100644 --- a/tools/validator/validator.cpp +++ b/tools/validator/validator.cpp
@@ -1,5 +1,6 @@
1#include "validator.h" 1#include "validator.h"
2 2
3#include <algorithm>
3#include <iostream> 4#include <iostream>
4 5
5#include "proto/human.pb.h" 6#include "proto/human.pb.h"
@@ -9,291 +10,599 @@
9namespace com::fourisland::lingo2_archipelago { 10namespace com::fourisland::lingo2_archipelago {
10namespace { 11namespace {
11 12
12void ValidateMap(const std::string& map_name, const MapInfo& map_info) { 13class Validator {
13 for (const auto& [node_path, node_info] : map_info.game_nodes) { 14 public:
14 if (node_info.uses > 1) { 15 explicit Validator(const CollectedInfo& info) : info_(info) {}
15 std::cout << "Map " << map_name << " node " << node_path
16 << " is used in multiple places." << std::endl;
17 } else if (node_info.uses == 0) {
18 std::cout << "Map " << map_name << " node " << node_path
19 << " is not used." << std::endl;
20 }
21 16
22 if (!node_info.defined) { 17 void Validate() const {
23 std::cout << "Map " << map_name << " node " << node_path 18 for (const auto& [map_name, map_info] : info_.maps) {
24 << " is not defined in the game file." << std::endl; 19 ValidateMap(map_name, map_info);
20 }
21 for (const auto& [room_identifier, room_info] : info_.rooms) {
22 ValidateRoom(room_identifier, room_info);
23 }
24 for (const auto& [door_identifier, door_info] : info_.doors) {
25 ValidateDoor(door_identifier, door_info);
26 }
27 for (const auto& [port_identifier, port_info] : info_.ports) {
28 ValidatePort(port_identifier, port_info);
29 }
30 for (const auto& [painting_identifier, painting_info] : info_.paintings) {
31 ValidatePainting(painting_identifier, painting_info);
32 }
33 for (const auto& [panel_identifier, panel_info] : info_.panels) {
34 ValidatePanel(panel_identifier, panel_info);
35 }
36 for (const auto& [keyholder_identifier, keyholder_info] :
37 info_.keyholders) {
38 ValidateKeyholder(keyholder_identifier, keyholder_info);
39 }
40 for (const auto& [letter_identifier, letter_info] : info_.letters) {
41 ValidateLetter(letter_identifier, letter_info);
42 }
43 for (const auto& [ending_name, ending_info] : info_.endings) {
44 ValidateEnding(ending_name, ending_info);
45 }
46 for (const auto& [panel_name, panel_info] : info_.panel_names) {
47 ValidatePanelName(panel_name, panel_info);
48 }
49 for (const auto& [prog_name, prog_info] : info_.progressives) {
50 ValidateProgressive(prog_name, prog_info);
51 }
52 for (const auto& [group_name, group_info] : info_.door_groups) {
53 ValidateDoorGroup(group_name, group_info);
25 } 54 }
26 } 55 }
27}
28 56
29void ValidateRoom(const RoomIdentifier& room_identifier, 57 private:
30 const RoomInfo& room_info) { 58 void ValidateMap(const std::string& map_name, const MapInfo& map_info) const {
31 if (room_info.definitions.empty()) { 59 for (const auto& [node_path, node_info] : map_info.game_nodes) {
32 std::cout << "Room " << room_identifier.ShortDebugString() 60 if (node_info.uses > 1) {
33 << " has no definition, but was referenced:" << std::endl; 61 std::cout << "Map " << map_name << " node " << node_path
62 << " is used in multiple places." << std::endl;
63 } else if (node_info.uses == 0) {
64 std::cout << "Map " << map_name << " node " << node_path
65 << " is not used." << std::endl;
66 }
34 67
35 for (const DoorIdentifier& door_identifier : 68 if (!node_info.defined) {
36 room_info.doors_referenced_by) { 69 std::cout << "Map " << map_name << " node " << node_path
37 std::cout << " DOOR " << door_identifier.ShortDebugString() 70 << " is not defined in the game file." << std::endl;
38 << std::endl; 71 }
39 } 72 }
40 73
41 for (const PanelIdentifier& panel_identifier : 74 if (map_info.malformed_worldport_entrance) {
42 room_info.panels_referenced_by) { 75 std::cout << "The worldport entrance for map " << map_name
43 std::cout << " PANEL " << panel_identifier.ShortDebugString() 76 << " is malformed." << std::endl;
44 << std::endl;
45 } 77 }
46 78
47 for (const HumanConnection& connection : 79 if (map_info.has_rte_id) {
48 room_info.connections_referenced_by) { 80 if (!std::any_of(
49 std::cout << " CONNECTION " << connection.ShortDebugString() 81 map_info.definitions.begin(), map_info.definitions.end(),
50 << std::endl; 82 [](const HumanMap& h_map) { return h_map.has_rte_room(); })) {
83 std::cout << "Map " << map_name << " has an RTE ID but no RTE room."
84 << std::endl;
85 }
86 } else {
87 if (std::any_of(
88 map_info.definitions.begin(), map_info.definitions.end(),
89 [](const HumanMap& h_map) { return h_map.has_rte_room(); })) {
90 std::cout << "Map " << map_name << " has an RTE room but no RTE ID."
91 << std::endl;
92 }
51 } 93 }
52 } else if (room_info.definitions.size() > 1) {
53 std::cout << "Room " << room_identifier.ShortDebugString()
54 << " was defined multiple times." << std::endl;
55 } 94 }
56}
57 95
58void ValidateDoor(const DoorIdentifier& door_identifier, 96 void ValidateRoom(const RoomIdentifier& room_identifier,
59 const DoorInfo& door_info) { 97 const RoomInfo& room_info) const {
60 if (door_info.definitions.empty()) { 98 if (room_info.definitions.empty()) {
61 std::cout << "Door " << door_identifier.ShortDebugString() 99 std::cout << "Room " << room_identifier.ShortDebugString()
62 << " has no definition, but was referenced:" << std::endl; 100 << " has no definition, but was referenced:" << std::endl;
63 101
64 for (const DoorIdentifier& other_door_identifier : 102 for (const DoorIdentifier& door_identifier :
65 door_info.doors_referenced_by) { 103 room_info.doors_referenced_by) {
66 std::cout << " DOOR " << other_door_identifier.ShortDebugString() 104 std::cout << " DOOR " << door_identifier.ShortDebugString()
67 << std::endl; 105 << std::endl;
106 }
107
108 for (const PanelIdentifier& panel_identifier :
109 room_info.panels_referenced_by) {
110 std::cout << " PANEL " << panel_identifier.ShortDebugString()
111 << std::endl;
112 }
113
114 for (const HumanConnection& connection :
115 room_info.connections_referenced_by) {
116 std::cout << " CONNECTION " << connection.ShortDebugString()
117 << std::endl;
118 }
119
120 for (const std::string& map_name : room_info.map_rtes_referenced_by) {
121 std::cout << " MAP RTE " << map_name << std::endl;
122 }
123 } else if (room_info.definitions.size() > 1) {
124 std::cout << "Room " << room_identifier.ShortDebugString()
125 << " was defined multiple times." << std::endl;
68 } 126 }
127 }
69 128
70 for (const PanelIdentifier& panel_identifier : 129 bool DoesDoorNeedLocationName(const HumanDoor& h_door,
71 door_info.panels_referenced_by) { 130 const std::string& map_name) const {
72 std::cout << " PANEL " << panel_identifier.ShortDebugString() 131 if (h_door.type() != DoorType::STANDARD) {
73 << std::endl; 132 return false;
74 } 133 }
75 134
76 for (const PaintingIdentifier& painting_identifier : 135 if (h_door.keyholders_size() > 0 || h_door.white_ending() ||
77 door_info.paintings_referenced_by) { 136 h_door.complete_at() > 0) {
78 std::cout << " PAINTING " << painting_identifier.ShortDebugString() 137 return true;
79 << std::endl;
80 } 138 }
81 139
82 for (const PortIdentifier& port_identifier : 140 if (h_door.panels_size() > 4) {
83 door_info.ports_referenced_by) { 141 return true;
84 std::cout << " PORT " << port_identifier.ShortDebugString()
85 << std::endl;
86 } 142 }
87 143
88 for (const HumanConnection& connection : 144 std::set<std::string> map_areas;
89 door_info.connections_referenced_by) { 145 for (const PanelIdentifier& pi : h_door.panels()) {
90 std::cout << " CONNECTION " << connection.ShortDebugString() 146 auto full_pi =
91 << std::endl; 147 GetCompletePanelIdentifierWithoutAnswer(pi, map_name, std::nullopt);
148 if (full_pi) {
149 auto panel_info_it = info_.panels.find(*full_pi);
150 if (panel_info_it != info_.panels.end()) {
151 const PanelInfo& panel_info = panel_info_it->second;
152
153 map_areas.insert(panel_info.map_area_name);
154 }
155 }
92 } 156 }
93 } else if (door_info.definitions.size() > 1) { 157
94 std::cout << "Door " << door_identifier.ShortDebugString() 158 if (map_areas.size() > 1) {
95 << " was defined multiple times." << std::endl; 159 return true;
160 }
161
162 return false;
96 } 163 }
97 164
98 if (door_info.malformed_identifiers.HasAny()) { 165 void ValidateDoor(const DoorIdentifier& door_identifier,
99 std::cout << "Door " << door_identifier.ShortDebugString() 166 const DoorInfo& door_info) const {
100 << " has malformed identifiers:" << std::endl; 167 if (door_info.definitions.empty()) {
168 std::cout << "Door " << door_identifier.ShortDebugString()
169 << " has no definition, but was referenced:" << std::endl;
101 170
102 for (const PaintingIdentifier& painting_identifier : 171 for (const DoorIdentifier& other_door_identifier :
103 door_info.malformed_identifiers.paintings) { 172 door_info.doors_referenced_by) {
104 std::cout << " PAINTING " << painting_identifier.ShortDebugString() 173 std::cout << " DOOR " << other_door_identifier.ShortDebugString()
105 << std::endl; 174 << std::endl;
106 } 175 }
107 176
108 for (const PanelIdentifier& panel_identifier : 177 for (const PanelIdentifier& panel_identifier :
109 door_info.malformed_identifiers.panels) { 178 door_info.panels_referenced_by) {
110 std::cout << " PANEL " << panel_identifier.ShortDebugString() 179 std::cout << " PANEL " << panel_identifier.ShortDebugString()
111 << std::endl; 180 << std::endl;
181 }
182
183 for (const PaintingIdentifier& painting_identifier :
184 door_info.paintings_referenced_by) {
185 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
186 << std::endl;
187 }
188
189 for (const PortIdentifier& port_identifier :
190 door_info.ports_referenced_by) {
191 std::cout << " PORT " << port_identifier.ShortDebugString()
192 << std::endl;
193 }
194
195 for (const HumanConnection& connection :
196 door_info.connections_referenced_by) {
197 std::cout << " CONNECTION " << connection.ShortDebugString()
198 << std::endl;
199 }
200
201 for (const std::string& prog_name :
202 door_info.progressives_referenced_by) {
203 std::cout << " PROGRESSIVE " << prog_name << std::endl;
204 }
205
206 for (const std::string& group_name :
207 door_info.door_groups_referenced_by) {
208 std::cout << " DOOR GROUP " << group_name << std::endl;
209 }
210
211 if (door_info.has_id) {
212 std::cout << " An AP ID is present." << std::endl;
213 }
214 } else if (door_info.definitions.size() > 1) {
215 std::cout << "Door " << door_identifier.ShortDebugString()
216 << " was defined multiple times." << std::endl;
112 } 217 }
113 218
114 for (const KeyholderIdentifier& keyholder_identifier : 219 if (door_info.malformed_identifiers.HasAny()) {
115 door_info.malformed_identifiers.keyholders) { 220 std::cout << "Door " << door_identifier.ShortDebugString()
116 std::cout << " KEYHOLDER " << keyholder_identifier.ShortDebugString() 221 << " has malformed identifiers:" << std::endl;
117 << std::endl; 222
223 for (const PaintingIdentifier& painting_identifier :
224 door_info.malformed_identifiers.paintings) {
225 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
226 << std::endl;
227 }
228
229 for (const PanelIdentifier& panel_identifier :
230 door_info.malformed_identifiers.panels) {
231 std::cout << " PANEL " << panel_identifier.ShortDebugString()
232 << std::endl;
233 }
234
235 for (const KeyholderIdentifier& keyholder_identifier :
236 door_info.malformed_identifiers.keyholders) {
237 std::cout << " KEYHOLDER " << keyholder_identifier.ShortDebugString()
238 << std::endl;
239 }
118 } 240 }
119 }
120}
121 241
122void ValidatePort(const PortIdentifier& port_identifier, 242 for (const HumanDoor& h_door : door_info.definitions) {
123 const PortInfo& port_info) { 243 if (DoesDoorNeedLocationName(h_door, door_identifier.map()) &&
124 if (port_info.definitions.empty()) { 244 !h_door.has_location_name()) {
125 std::cout << "Port " << port_identifier.ShortDebugString() 245 std::cout << "Door " << door_identifier.ShortDebugString()
126 << " has no definition, but was referenced:" << std::endl; 246 << " needs an explicit location name." << std::endl;
247 }
127 248
128 for (const HumanConnection& connection : 249 if (h_door.type() == DoorType::STANDARD ||
129 port_info.connections_referenced_by) { 250 h_door.type() == DoorType::LOCATION_ONLY ||
130 std::cout << " CONNECTION " << connection.ShortDebugString() 251 h_door.type() == DoorType::GRAVESTONE || h_door.legacy_location()) {
131 << std::endl; 252 if (h_door.double_letters()) {
253 std::cout << "Door " << door_identifier.ShortDebugString()
254 << " is a location that depends on double_letters."
255 << std::endl;
256 }
257
258 if (!h_door.has_location_room()) {
259 std::cout << "Door " << door_identifier.ShortDebugString()
260 << " is missing a location_room." << std::endl;
261 }
262 }
263
264 bool needs_id = (h_door.type() != DoorType::EVENT || h_door.latch() ||
265 h_door.legacy_location());
266 if (door_info.has_id != needs_id) {
267 if (needs_id) {
268 std::cout << "Door " << door_identifier.ShortDebugString()
269 << " is missing an AP ID." << std::endl;
270 } else {
271 std::cout << "Door " << door_identifier.ShortDebugString()
272 << " should not have an AP ID." << std::endl;
273 }
274 }
132 } 275 }
133 } else if (port_info.definitions.size() > 1) {
134 std::cout << "Port " << port_identifier.ShortDebugString()
135 << " was defined multiple times." << std::endl;
136 } 276 }
137}
138 277
139void ValidatePainting(const PaintingIdentifier& painting_identifier, 278 void ValidatePort(const PortIdentifier& port_identifier,
140 const PaintingInfo& painting_info) { 279 const PortInfo& port_info) const {
141 if (painting_info.definitions.empty()) { 280 if (port_info.definitions.empty()) {
142 std::cout << "Painting " << painting_identifier.ShortDebugString() 281 std::cout << "Port " << port_identifier.ShortDebugString()
143 << " has no definition, but was referenced:" << std::endl; 282 << " has no definition, but was referenced:" << std::endl;
144 283
145 for (const DoorIdentifier& door_identifier : 284 for (const HumanConnection& connection :
146 painting_info.doors_referenced_by) { 285 port_info.connections_referenced_by) {
147 std::cout << " DOOR " << door_identifier.ShortDebugString() 286 std::cout << " CONNECTION " << connection.ShortDebugString()
148 << std::endl; 287 << std::endl;
288 }
289
290 for (const std::string& map_name : port_info.map_worldport_entrances) {
291 std::cout << " MAP (worldport_entrance) " << map_name << std::endl;
292 }
293
294 if (port_info.has_id) {
295 std::cout << " An AP ID is present." << std::endl;
296 }
297 } else if (port_info.definitions.size() > 1) {
298 std::cout << "Port " << port_identifier.ShortDebugString()
299 << " was defined multiple times." << std::endl;
149 } 300 }
150 301
151 for (const HumanConnection& connection : 302 if (!port_info.target_connections_referenced_by.empty()) {
152 painting_info.connections_referenced_by) { 303 for (const HumanPort& port : port_info.definitions) {
153 std::cout << " CONNECTION " << connection.ShortDebugString() 304 if (port.has_required_door()) {
154 << std::endl; 305 std::cout << "Port " << port_identifier.ShortDebugString()
306 << " has a required door but is the target of a connection:"
307 << std::endl;
308
309 for (const HumanConnection& connection :
310 port_info.target_connections_referenced_by) {
311 std::cout << " CONNECTION " << connection.ShortDebugString()
312 << std::endl;
313 }
314 }
315 }
155 } 316 }
156 } else if (painting_info.definitions.size() > 1) {
157 std::cout << "Painting " << painting_identifier.ShortDebugString()
158 << " was defined multiple times." << std::endl;
159 }
160}
161 317
162void ValidatePanel(const PanelIdentifier& panel_identifier, 318 for (const HumanPort& port : port_info.definitions) {
163 const PanelInfo& panel_info) { 319 if (!port.no_shuffle()) {
164 if (panel_identifier.name().empty()) { 320 if (!port.has_destination()) {
165 std::cout << "Panel " << panel_identifier.ShortDebugString() 321 std::cout << "Port " << port_identifier.ShortDebugString()
166 << " has no name." << std::endl; 322 << " is shuffleable and missing a destination."
323 << std::endl;
324 }
325 if (!port.has_rotation()) {
326 std::cout << "Port " << port_identifier.ShortDebugString()
327 << " is shuffleable and missing a rotation." << std::endl;
328 }
329 if (!port_info.has_id) {
330 std::cout << "Port " << port_identifier.ShortDebugString()
331 << " is missing an AP ID." << std::endl;
332 }
333 } else {
334 if (port_info.has_id) {
335 std::cout << "Port " << port_identifier.ShortDebugString()
336 << " should not have an AP ID." << std::endl;
337 }
338 }
339 }
167 } 340 }
168 341
169 if (panel_info.definitions.empty()) { 342 void ValidatePainting(const PaintingIdentifier& painting_identifier,
170 std::cout << "Panel " << panel_identifier.ShortDebugString() 343 const PaintingInfo& painting_info) const {
171 << " has no definition, but was referenced:" << std::endl; 344 if (painting_info.definitions.empty()) {
345 std::cout << "Painting " << painting_identifier.ShortDebugString()
346 << " has no definition, but was referenced:" << std::endl;
172 347
173 for (const DoorIdentifier& door_identifier : 348 for (const DoorIdentifier& door_identifier :
174 panel_info.doors_referenced_by) { 349 painting_info.doors_referenced_by) {
175 std::cout << " DOOR " << door_identifier.ShortDebugString() 350 std::cout << " DOOR " << door_identifier.ShortDebugString()
176 << std::endl; 351 << std::endl;
352 }
353
354 for (const HumanConnection& connection :
355 painting_info.connections_referenced_by) {
356 std::cout << " CONNECTION " << connection.ShortDebugString()
357 << std::endl;
358 }
359 } else if (painting_info.definitions.size() > 1) {
360 std::cout << "Painting " << painting_identifier.ShortDebugString()
361 << " was defined multiple times." << std::endl;
177 } 362 }
178 363
179 for (const HumanConnection& connection : 364 if (!painting_info.target_connections_referenced_by.empty()) {
180 panel_info.connections_referenced_by) { 365 for (const HumanPainting& painting : painting_info.definitions) {
181 std::cout << " CONNECTION " << connection.ShortDebugString() 366 if (painting.has_required_door()) {
182 << std::endl; 367 std::cout << "Painting " << painting_identifier.ShortDebugString()
368 << " has a required door but is the target of a connection:"
369 << std::endl;
370
371 for (const HumanConnection& connection :
372 painting_info.target_connections_referenced_by) {
373 std::cout << " CONNECTION " << connection.ShortDebugString()
374 << std::endl;
375 }
376 }
377 }
183 } 378 }
184 } else if (panel_info.definitions.size() > 1) {
185 std::cout << "Panel " << panel_identifier.ShortDebugString()
186 << " was defined multiple times." << std::endl;
187 } 379 }
188 380
189 for (const auto& [answer, proxy_info] : panel_info.proxies) { 381 void ValidatePanel(const PanelIdentifier& panel_identifier,
190 if (proxy_info.definitions.empty()) { 382 const PanelInfo& panel_info) const {
383 if (panel_identifier.name().empty()) {
191 std::cout << "Panel " << panel_identifier.ShortDebugString() 384 std::cout << "Panel " << panel_identifier.ShortDebugString()
192 << " with answer \"" << answer 385 << " has no name." << std::endl;
193 << "\" has no definition, but was referenced:" << std::endl; 386 }
387
388 if (panel_info.definitions.empty()) {
389 std::cout << "Panel " << panel_identifier.ShortDebugString()
390 << " has no definition, but was referenced:" << std::endl;
194 391
195 for (const DoorIdentifier& door_identifier : 392 for (const DoorIdentifier& door_identifier :
196 proxy_info.doors_referenced_by) { 393 panel_info.doors_referenced_by) {
197 std::cout << " DOOR " << door_identifier.ShortDebugString() 394 std::cout << " DOOR " << door_identifier.ShortDebugString()
198 << std::endl; 395 << std::endl;
199 } 396 }
200 397
201 for (const HumanConnection& connection : 398 for (const HumanConnection& connection :
202 proxy_info.connections_referenced_by) { 399 panel_info.connections_referenced_by) {
203 std::cout << " CONNECTION " << connection.ShortDebugString() 400 std::cout << " CONNECTION " << connection.ShortDebugString()
204 << std::endl; 401 << std::endl;
205 } 402 }
206 } else if (proxy_info.definitions.size() > 1) { 403
404 if (panel_info.has_id) {
405 std::cout << " An AP ID is present." << std::endl;
406 }
407 } else if (panel_info.definitions.size() > 1) {
408 std::cout << "Panel " << panel_identifier.ShortDebugString()
409 << " was defined multiple times." << std::endl;
410 }
411
412 for (const auto& [answer, proxy_info] : panel_info.proxies) {
413 if (proxy_info.definitions.empty()) {
414 std::cout << "Panel " << panel_identifier.ShortDebugString()
415 << " with answer \"" << answer
416 << "\" has no definition, but was referenced:" << std::endl;
417
418 for (const DoorIdentifier& door_identifier :
419 proxy_info.doors_referenced_by) {
420 std::cout << " DOOR " << door_identifier.ShortDebugString()
421 << std::endl;
422 }
423
424 for (const HumanConnection& connection :
425 proxy_info.connections_referenced_by) {
426 std::cout << " CONNECTION " << connection.ShortDebugString()
427 << std::endl;
428 }
429 } else if (proxy_info.definitions.size() > 1) {
430 std::cout << "Panel " << panel_identifier.ShortDebugString()
431 << " with answer \"" << answer
432 << "\" was defined multiple times." << std::endl;
433 }
434 }
435
436 if (!panel_info.has_id) {
207 std::cout << "Panel " << panel_identifier.ShortDebugString() 437 std::cout << "Panel " << panel_identifier.ShortDebugString()
208 << " with answer \"" << answer 438 << " is missing an AP ID." << std::endl;
209 << "\" was defined multiple times." << std::endl; 439 }
440
441 if (!panel_info.target_connections_referenced_by.empty()) {
442 for (const HumanPanel& panel : panel_info.definitions) {
443 if (panel.has_required_door()) {
444 std::cout << "Panel " << panel_identifier.ShortDebugString()
445 << " has a required door but is the target of a connection:"
446 << std::endl;
447
448 for (const HumanConnection& connection :
449 panel_info.target_connections_referenced_by) {
450 std::cout << " CONNECTION " << connection.ShortDebugString()
451 << std::endl;
452 }
453 }
454 }
210 } 455 }
211 } 456 }
212}
213 457
214void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier, 458 void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier,
215 const KeyholderInfo& keyholder_info) { 459 const KeyholderInfo& keyholder_info) const {
216 if (keyholder_info.definitions.empty()) { 460 if (keyholder_info.definitions.empty()) {
217 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString() 461 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
218 << " has no definition, but was referenced:" << std::endl; 462 << " has no definition, but was referenced:" << std::endl;
463
464 for (const DoorIdentifier& door_identifier :
465 keyholder_info.doors_referenced_by) {
466 std::cout << " DOOR " << door_identifier.ShortDebugString()
467 << std::endl;
468 }
469
470 if (keyholder_info.has_id) {
471 std::cout << " An AP ID is present." << std::endl;
472 }
473 } else if (keyholder_info.definitions.size() > 1) {
474 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
475 << " was defined multiple times." << std::endl;
476 }
219 477
220 for (const DoorIdentifier& door_identifier : 478 for (const HumanKeyholder& h_keyholder : keyholder_info.definitions) {
221 keyholder_info.doors_referenced_by) { 479 bool needs_id = (h_keyholder.has_key());
222 std::cout << " DOOR " << door_identifier.ShortDebugString() 480
481 if (needs_id != keyholder_info.has_id) {
482 if (needs_id) {
483 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
484 << " is missing an AP ID." << std::endl;
485 } else {
486 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
487 << " should not have an AP ID." << std::endl;
488 }
489 }
490 }
491 }
492
493 void ValidateLetter(const LetterIdentifier& letter_identifier,
494 const LetterInfo& letter_info) const {
495 std::string letter_name = std::string(1, std::get<0>(letter_identifier)) +
496 (std::get<1>(letter_identifier) ? "2" : "1");
497
498 if (letter_info.defined_in.empty()) {
499 std::cout << "Letter " << letter_name
500 << " has no definition, but was referenced:" << std::endl;
501
502 if (letter_info.has_id) {
503 std::cout << " An AP ID is present." << std::endl;
504 }
505 } else if (letter_info.defined_in.size() > 1) {
506 std::cout << "Letter " << letter_name
507 << " was defined in multiple places:" << std::endl;
508
509 for (const RoomIdentifier& room_identifier : letter_info.defined_in) {
510 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
511 }
512 }
513
514 if (!letter_info.has_id) {
515 std::cout << "Letter " << letter_name << " is missing an AP ID."
223 << std::endl; 516 << std::endl;
224 } 517 }
225 } else if (keyholder_info.definitions.size() > 1) {
226 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
227 << " was defined multiple times." << std::endl;
228 } 518 }
229}
230 519
231void ValidateLetter(const LetterIdentifier& letter_identifier, 520 void ValidateEnding(const std::string& ending_name,
232 const LetterInfo& letter_info) { 521 const EndingInfo& ending_info) const {
233 std::string letter_name = std::string(1, std::get<0>(letter_identifier)) + 522 if (ending_info.defined_in.empty()) {
234 (std::get<1>(letter_identifier) ? "2" : "1"); 523 std::cout << "Ending " << ending_name
524 << " has no definition, but was referenced:" << std::endl;
235 525
236 if (letter_info.defined_in.size() > 1) { 526 if (ending_info.has_id) {
237 std::cout << "Letter " << letter_name 527 std::cout << " An AP ID is present." << std::endl;
238 << " was defined in multiple places:" << std::endl; 528 }
529 } else if (ending_info.defined_in.size() > 1) {
530 std::cout << "Ending " << ending_name
531 << " was defined in multiple places:" << std::endl;
532
533 for (const RoomIdentifier& room_identifier : ending_info.defined_in) {
534 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
535 }
536 }
239 537
240 for (const RoomIdentifier& room_identifier : letter_info.defined_in) { 538 if (!ending_info.has_id) {
241 std::cout << " " << room_identifier.ShortDebugString() << std::endl; 539 std::cout << "Ending " << ending_name << " is missing an AP ID."
540 << std::endl;
242 } 541 }
243 } 542 }
244}
245 543
246void ValidateEnding(const std::string& ending_name, 544 void ValidatePanelName(const std::string& panel_name,
247 const EndingInfo& ending_info) { 545 const PanelNameInfo& panel_info) const {
248 if (ending_info.defined_in.empty()) { 546 if (panel_info.panels_used_by.size() > 1) {
249 std::cout << "Ending " << ending_name 547 std::cout << "The location name \"" << panel_name
250 << " has no definition, but was referenced:" << std::endl; 548 << "\" is used by multiple panels:" << std::endl;
549
550 for (const PanelIdentifier& panel_identifier :
551 panel_info.panels_used_by) {
552 std::cout << " PANEL " << panel_identifier.ShortDebugString()
553 << std::endl;
554 }
555 }
556 }
557
558 void ValidateProgressive(const std::string& prog_name,
559 const ProgressiveInfo& prog_info) const {
560 if (prog_info.definitions.empty()) {
561 std::cout << "Progressive \"" << prog_name
562 << "\" has no definition, but was referenced:" << std::endl;
563
564 if (prog_info.has_id) {
565 std::cout << " An AP ID is present." << std::endl;
566 }
567 } else if (prog_info.definitions.size() > 1) {
568 std::cout << "Progressive \"" << prog_name
569 << "\" has multiple definitions." << std::endl;
570 }
251 571
252 for (const DoorIdentifier& door_identifier : 572 if (!prog_info.has_id) {
253 ending_info.doors_referenced_by) { 573 std::cout << "Progressive \"" << prog_name << "\" is missing an AP ID."
254 std::cout << " DOOR " << door_identifier.ShortDebugString()
255 << std::endl; 574 << std::endl;
256 } 575 }
257 } else if (ending_info.defined_in.size() > 1) { 576 }
258 std::cout << "Ending " << ending_name 577
259 << " was defined in multiple places:" << std::endl; 578 void ValidateDoorGroup(const std::string& group_name,
579 const DoorGroupInfo& group_info) const {
580 if (group_info.definitions.empty()) {
581 std::cout << "Door group \"" << group_name
582 << "\" has no definition, but was referenced:" << std::endl;
583
584 if (group_info.has_id) {
585 std::cout << " An AP ID is present." << std::endl;
586 }
587 } else if (group_info.definitions.size() > 1) {
588 std::cout << "Door group \"" << group_name
589 << "\" has multiple definitions." << std::endl;
590 }
260 591
261 for (const RoomIdentifier& room_identifier : ending_info.defined_in) { 592 if (!group_info.has_id) {
262 std::cout << " " << room_identifier.ShortDebugString() << std::endl; 593 std::cout << "Door group \"" << group_name << "\" is missing an AP ID."
594 << std::endl;
263 } 595 }
264 } 596 }
265} 597
598 const CollectedInfo& info_;
599};
266 600
267} // namespace 601} // namespace
268 602
269void ValidateCollectedInfo(const CollectedInfo& info) { 603void ValidateCollectedInfo(const CollectedInfo& info) {
270 for (const auto& [map_name, map_info] : info.maps) { 604 Validator validator(info);
271 ValidateMap(map_name, map_info); 605 validator.Validate();
272 }
273 for (const auto& [room_identifier, room_info] : info.rooms) {
274 ValidateRoom(room_identifier, room_info);
275 }
276 for (const auto& [door_identifier, door_info] : info.doors) {
277 ValidateDoor(door_identifier, door_info);
278 }
279 for (const auto& [port_identifier, port_info] : info.ports) {
280 ValidatePort(port_identifier, port_info);
281 }
282 for (const auto& [painting_identifier, painting_info] : info.paintings) {
283 ValidatePainting(painting_identifier, painting_info);
284 }
285 for (const auto& [panel_identifier, panel_info] : info.panels) {
286 ValidatePanel(panel_identifier, panel_info);
287 }
288 for (const auto& [keyholder_identifier, keyholder_info] : info.keyholders) {
289 ValidateKeyholder(keyholder_identifier, keyholder_info);
290 }
291 for (const auto& [letter_identifier, letter_info] : info.letters) {
292 ValidateLetter(letter_identifier, letter_info);
293 }
294 for (const auto& [ending_name, ending_info] : info.endings) {
295 ValidateEnding(ending_name, ending_info);
296 }
297} 606}
298 607
299} // namespace com::fourisland::lingo2_archipelago 608} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/validator.h b/tools/validator/validator.h index b710429..33bc7c9 100644 --- a/tools/validator/validator.h +++ b/tools/validator/validator.h
@@ -1,4 +1,4 @@
1#ifndef TOOLS_VALIDATOR_VALIDATOR_H_ 1#ifndef TOOLS_VALIDATOR_VALIDATOR_H
2#define TOOLS_VALIDATOR_VALIDATOR_H 2#define TOOLS_VALIDATOR_VALIDATOR_H
3 3
4namespace com::fourisland::lingo2_archipelago { 4namespace com::fourisland::lingo2_archipelago {