about summary refs log tree commit diff stats
path: root/tools/validator
diff options
context:
space:
mode:
Diffstat (limited to 'tools/validator')
-rw-r--r--tools/validator/CMakeLists.txt13
-rw-r--r--tools/validator/godot_processor.cpp72
-rw-r--r--tools/validator/godot_processor.h14
-rw-r--r--tools/validator/human_processor.cpp640
-rw-r--r--tools/validator/human_processor.h14
-rw-r--r--tools/validator/main.cpp34
-rw-r--r--tools/validator/structs.h147
-rw-r--r--tools/validator/validator.cpp550
-rw-r--r--tools/validator/validator.h12
9 files changed, 1496 insertions, 0 deletions
diff --git a/tools/validator/CMakeLists.txt b/tools/validator/CMakeLists.txt new file mode 100644 index 0000000..1a8fd9c --- /dev/null +++ b/tools/validator/CMakeLists.txt
@@ -0,0 +1,13 @@
1find_package(fmt REQUIRED)
2find_package(Protobuf REQUIRED)
3
4add_executable(validator
5 godot_processor.cpp
6 human_processor.cpp
7 main.cpp
8 validator.cpp
9)
10set_property(TARGET validator PROPERTY CXX_STANDARD 20)
11set_property(TARGET validator PROPERTY CXX_STANDARD_REQUIRED ON)
12target_include_directories(validator PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools)
13target_link_libraries(validator PUBLIC protos util fmt::fmt protobuf::libprotobuf)
diff --git a/tools/validator/godot_processor.cpp b/tools/validator/godot_processor.cpp new file mode 100644 index 0000000..ad2be78 --- /dev/null +++ b/tools/validator/godot_processor.cpp
@@ -0,0 +1,72 @@
1#include "godot_processor.h"
2
3#include <filesystem>
4#include <iostream>
5#include <memory>
6#include <set>
7
8#include "structs.h"
9#include "util/godot_scene.h"
10
11namespace com::fourisland::lingo2_archipelago {
12
13namespace {
14
15static const std::set<std::string> kImportantNodeTypes = {
16 "res://objects/nodes/panel.tscn", "res://objects/nodes/worldport.tscn",
17 "res://objects/nodes/keyHolder.tscn",
18 "res://objects/nodes/collectable.tscn"};
19
20class GodotProcessor {
21 public:
22 GodotProcessor(const std::string& repodir, CollectedInfo& info)
23 : repodir_(repodir), info_(info) {}
24
25 void Run() {
26 for (auto& [map_name, map_info] : info_.maps) {
27 ProcessMap(map_name, map_info);
28 }
29 }
30
31 void ProcessMap(const std::string& map_name, MapInfo& map_info) {
32 std::filesystem::path scene_path = std::filesystem::path(repodir_) /
33 "objects" / "scenes" /
34 (map_name + ".tscn");
35 std::string scene_path_str = scene_path.string();
36 std::cout << "Processing " << scene_path_str << std::endl;
37
38 GodotScene scene = ReadGodotSceneFromFile(scene_path_str);
39 for (const GodotNode& node : scene.GetNodes()) {
40 ProcessMapNode(scene, node, map_info);
41 }
42 }
43
44 void ProcessMapNode(const GodotScene& scene, const GodotNode& node,
45 MapInfo& map_info) {
46 if (std::holds_alternative<GodotExtResourceRef>(node.instance_type)) {
47 const GodotExtResourceRef& ext_resource_ref =
48 std::get<GodotExtResourceRef>(node.instance_type);
49 const GodotExtResource* ext_resource =
50 scene.GetExtResource(ext_resource_ref.id);
51
52 if (ext_resource != nullptr &&
53 (kImportantNodeTypes.count(ext_resource->path) ||
54 ext_resource->path.starts_with("res://objects/meshes/paintings/"))) {
55 map_info.game_nodes[node.GetPath()].defined = true;
56 }
57 }
58 }
59
60 private:
61 std::string repodir_;
62 CollectedInfo& info_;
63};
64
65} // namespace
66
67void ProcessGodotData(const std::string& repodir, CollectedInfo& info) {
68 GodotProcessor godot_processor(repodir, info);
69 godot_processor.Run();
70}
71
72} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/godot_processor.h b/tools/validator/godot_processor.h new file mode 100644 index 0000000..97bcea6 --- /dev/null +++ b/tools/validator/godot_processor.h
@@ -0,0 +1,14 @@
1#ifndef TOOLS_VALIDATOR_GODOT_PROCESSOR_H_
2#define TOOLS_VALIDATOR_GODOT_PROCESSOR_H_
3
4#include <string>
5
6namespace com::fourisland::lingo2_archipelago {
7
8struct CollectedInfo;
9
10void ProcessGodotData(const std::string& repodir, CollectedInfo& info);
11
12} // namespace com::fourisland::lingo2_archipelago
13
14#endif /* TOOLS_VALIDATOR_GODOT_PROCESSOR_H_ */
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp new file mode 100644 index 0000000..2c978bf --- /dev/null +++ b/tools/validator/human_processor.cpp
@@ -0,0 +1,640 @@
1#include "human_processor.h"
2
3#include <fmt/core.h>
4#include <google/protobuf/message.h>
5#include <google/protobuf/text_format.h>
6
7#include <filesystem>
8#include <fstream>
9#include <iostream>
10#include <map>
11#include <optional>
12#include <sstream>
13#include <string>
14
15#include "structs.h"
16#include "util/ids_yaml_format.h"
17
18namespace com::fourisland::lingo2_archipelago {
19namespace {
20
21template <typename T>
22T ReadMessageFromFile(const std::string& path) {
23 std::cout << "Processing " << path << std::endl;
24
25 std::ifstream file(path);
26 std::stringstream buffer;
27 buffer << file.rdbuf();
28
29 T message;
30 google::protobuf::TextFormat::ParseFromString(buffer.str(), &message);
31
32 return message;
33}
34
35class HumanProcessor {
36 public:
37 HumanProcessor(const std::string& mapdir, CollectedInfo& info)
38 : mapdir_(mapdir), info_(info) {}
39
40 void Run() {
41 std::filesystem::path datadir_path = mapdir_;
42
43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
44 ProcessMaps(datadir_path);
45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
48 }
49
50 private:
51 void ProcessMaps(std::filesystem::path path) {
52 std::filesystem::path maps_dir = path / "maps";
53 for (auto const& dir_entry :
54 std::filesystem::directory_iterator(maps_dir)) {
55 ProcessMap(dir_entry.path());
56 }
57 }
58
59 void ProcessMap(std::filesystem::path path) {
60 std::string map_name = path.filename().string();
61
62 ProcessMetadataFile(path / "metadata.txtpb", map_name);
63 ProcessConnectionsFile(path / "connections.txtpb", map_name);
64 ProcessDoorsFile(path / "doors.txtpb", map_name);
65 ProcessRooms(path / "rooms", map_name);
66 }
67
68 void ProcessMetadataFile(std::filesystem::path path,
69 const std::string& current_map_name) {
70 if (!std::filesystem::exists(path)) {
71 return;
72 }
73
74 MapInfo& map_info = info_.maps[current_map_name];
75
76 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
77 for (const std::string& path : metadata.excluded_nodes()) {
78 map_info.game_nodes[path].uses++;
79 }
80 }
81
82 void ProcessRooms(std::filesystem::path path,
83 const std::string& current_map_name) {
84 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
85 auto room = ReadMessageFromFile<HumanRoom>(dir_entry.path().string());
86 ProcessRoom(room, current_map_name);
87 }
88 }
89
90 void ProcessRoom(const HumanRoom& h_room,
91 const std::string& current_map_name) {
92 RoomIdentifier room_identifier;
93 room_identifier.set_map(current_map_name);
94 room_identifier.set_name(h_room.name());
95
96 RoomInfo& room_info = info_.rooms[room_identifier];
97 room_info.definitions.push_back(h_room);
98
99 for (const HumanPanel& h_panel : h_room.panels()) {
100 ProcessPanel(h_panel, current_map_name, h_room);
101 }
102
103 for (const HumanPainting& h_painting : h_room.paintings()) {
104 ProcessPainting(h_painting, current_map_name, h_room.name());
105 }
106
107 for (const HumanPort& h_port : h_room.ports()) {
108 ProcessPort(h_port, current_map_name, h_room.name());
109 }
110
111 for (const HumanLetter& h_letter : h_room.letters()) {
112 ProcessLetter(h_letter, current_map_name, h_room.name());
113 }
114
115 for (const HumanMastery& h_mastery : h_room.masteries()) {
116 ProcessMastery(h_mastery, current_map_name, h_room.name());
117 }
118
119 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
120 ProcessKeyholder(h_keyholder, current_map_name, h_room.name());
121 }
122
123 for (const HumanEnding& h_ending : h_room.endings()) {
124 ProcessEnding(h_ending, current_map_name, h_room.name());
125 }
126 }
127
128 void ProcessPanel(const HumanPanel& h_panel,
129 const std::string& current_map_name,
130 const HumanRoom& h_room) {
131 PanelIdentifier panel_identifier;
132 panel_identifier.set_map(current_map_name);
133 panel_identifier.set_room(h_room.name());
134 panel_identifier.set_name(h_panel.name());
135
136 PanelInfo& panel_info = info_.panels[panel_identifier];
137 panel_info.definitions.push_back(h_panel);
138
139 MapInfo& map_info = info_.maps[current_map_name];
140 map_info.game_nodes[h_panel.path()].uses++;
141
142 for (const Proxy& h_proxy : h_panel.proxies()) {
143 ProxyInfo& proxy_info = panel_info.proxies[h_proxy.answer()];
144 proxy_info.definitions.push_back(h_proxy);
145
146 map_info.game_nodes[h_proxy.path()].uses++;
147 }
148
149 if (h_panel.has_required_door()) {
150 DoorIdentifier required_door_identifier =
151 *GetCompleteDoorIdentifier(h_panel.required_door(), current_map_name);
152 DoorInfo& required_door_info = info_.doors[required_door_identifier];
153 required_door_info.panels_referenced_by.push_back(panel_identifier);
154 }
155
156 if (h_panel.has_required_room()) {
157 RoomIdentifier required_room_identifier =
158 *GetCompleteRoomIdentifier(h_panel.required_room(), current_map_name);
159 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
160 required_room_info.panels_referenced_by.push_back(panel_identifier);
161 }
162
163 std::string map_area_name = current_map_name;
164 if (h_room.has_panel_display_name()) {
165 map_area_name =
166 fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
167 }
168
169 panel_info.map_area_name = map_area_name;
170
171 std::string panelsanity_name;
172 if (h_panel.has_display_name()) {
173 panelsanity_name =
174 fmt::format("{} - {}", map_area_name, h_panel.display_name());
175 } else {
176 panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
177 }
178 info_.panel_names[panelsanity_name].panels_used_by.push_back(
179 panel_identifier);
180 }
181
182 void ProcessPainting(const HumanPainting& h_painting,
183 const std::string& current_map_name,
184 const std::string& current_room_name) {
185 PaintingIdentifier painting_identifier;
186 painting_identifier.set_map(current_map_name);
187 painting_identifier.set_room(current_room_name);
188 painting_identifier.set_name(h_painting.name());
189
190 PaintingInfo& painting_info = info_.paintings[painting_identifier];
191 painting_info.definitions.push_back(h_painting);
192
193 MapInfo& map_info = info_.maps[current_map_name];
194 map_info.game_nodes[h_painting.path()].uses++;
195
196 if (h_painting.has_required_door()) {
197 DoorIdentifier required_door_identifier = *GetCompleteDoorIdentifier(
198 h_painting.required_door(), current_map_name);
199 DoorInfo& required_door_info = info_.doors[required_door_identifier];
200 required_door_info.paintings_referenced_by.push_back(painting_identifier);
201 }
202 }
203
204 void ProcessPort(const HumanPort& h_port, const std::string& current_map_name,
205 const std::string& current_room_name) {
206 PortIdentifier port_identifier;
207 port_identifier.set_map(current_map_name);
208 port_identifier.set_room(current_room_name);
209 port_identifier.set_name(h_port.name());
210
211 PortInfo& port_info = info_.ports[port_identifier];
212 port_info.definitions.push_back(h_port);
213
214 MapInfo& map_info = info_.maps[current_map_name];
215 map_info.game_nodes[h_port.path()].uses++;
216
217 if (h_port.has_required_door()) {
218 DoorIdentifier required_door_identifier =
219 *GetCompleteDoorIdentifier(h_port.required_door(), current_map_name);
220 DoorInfo& required_door_info = info_.doors[required_door_identifier];
221 required_door_info.ports_referenced_by.push_back(port_identifier);
222 }
223 }
224
225 void ProcessLetter(const HumanLetter& h_letter,
226 const std::string& current_map_name,
227 const std::string& current_room_name) {
228 LetterIdentifier letter_identifier =
229 std::make_tuple(h_letter.key()[0], h_letter.level2());
230 LetterInfo& letter_info = info_.letters[letter_identifier];
231
232 RoomIdentifier room_identifier;
233 room_identifier.set_map(current_map_name);
234 room_identifier.set_name(current_room_name);
235 letter_info.defined_in.push_back(room_identifier);
236
237 MapInfo& map_info = info_.maps[current_map_name];
238 map_info.game_nodes[h_letter.path()].uses++;
239 }
240
241 void ProcessMastery(const HumanMastery& h_mastery,
242 const std::string& current_map_name,
243 const std::string& current_room_name) {
244 MapInfo& map_info = info_.maps[current_map_name];
245 map_info.game_nodes[h_mastery.path()].uses++;
246 }
247
248 void ProcessKeyholder(const HumanKeyholder& h_keyholder,
249 const std::string& current_map_name,
250 const std::string& current_room_name) {
251 KeyholderIdentifier keyholder_identifier;
252 keyholder_identifier.set_map(current_map_name);
253 keyholder_identifier.set_room(current_room_name);
254 keyholder_identifier.set_name(h_keyholder.name());
255
256 KeyholderInfo& keyholder_info = info_.keyholders[keyholder_identifier];
257 keyholder_info.definitions.push_back(h_keyholder);
258
259 MapInfo& map_info = info_.maps[current_map_name];
260 map_info.game_nodes[h_keyholder.path()].uses++;
261 }
262
263 void ProcessEnding(const HumanEnding& h_ending,
264 const std::string& current_map_name,
265 const std::string& current_room_name) {
266 EndingInfo& ending_info = info_.endings[h_ending.name()];
267
268 RoomIdentifier room_identifier;
269 room_identifier.set_map(current_map_name);
270 room_identifier.set_name(current_room_name);
271 ending_info.defined_in.push_back(room_identifier);
272
273 MapInfo& map_info = info_.maps[current_map_name];
274 map_info.game_nodes[h_ending.path()].uses++;
275 }
276
277 void ProcessDoorsFile(std::filesystem::path path,
278 const std::string& current_map_name) {
279 if (!std::filesystem::exists(path)) {
280 return;
281 }
282
283 auto doors = ReadMessageFromFile<HumanDoors>(path.string());
284
285 for (const HumanDoor& door : doors.doors()) {
286 ProcessDoor(door, current_map_name);
287 }
288 }
289
290 void ProcessDoor(const HumanDoor& h_door,
291 const std::string& current_map_name) {
292 DoorIdentifier door_identifier;
293 door_identifier.set_map(current_map_name);
294 door_identifier.set_name(h_door.name());
295
296 DoorInfo& door_info = info_.doors[door_identifier];
297 door_info.definitions.push_back(h_door);
298
299 if (h_door.has_location_room()) {
300 RoomIdentifier location_room_identifier;
301 location_room_identifier.set_map(current_map_name);
302 location_room_identifier.set_name(h_door.location_room());
303 info_.rooms[location_room_identifier].doors_referenced_by.push_back(
304 door_identifier);
305 }
306
307 for (const PaintingIdentifier& pi : h_door.move_paintings()) {
308 auto complete_painting_identifier =
309 GetCompletePaintingIdentifier(pi, current_map_name, std::nullopt);
310 if (complete_painting_identifier) {
311 PaintingInfo& move_painting_info =
312 info_.paintings[*complete_painting_identifier];
313 move_painting_info.doors_referenced_by.push_back(door_identifier);
314 } else {
315 door_info.malformed_identifiers.paintings.push_back(pi);
316 }
317 }
318
319 for (const PanelIdentifier& pi : h_door.panels()) {
320 auto complete_panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
321 pi, current_map_name, std::nullopt);
322 if (complete_panel_identifier) {
323 PanelInfo& panel_info = info_.panels[*complete_panel_identifier];
324 panel_info.doors_referenced_by.push_back(door_identifier);
325
326 if (pi.has_answer()) {
327 panel_info.proxies[pi.answer()].doors_referenced_by.push_back(
328 door_identifier);
329 }
330 } else {
331 door_info.malformed_identifiers.panels.push_back(pi);
332 }
333 }
334
335 for (const KeyholderIdentifier& ki : h_door.keyholders()) {
336 auto complete_keyholder_identifier =
337 GetCompleteKeyholderIdentifierWithoutKey(ki, current_map_name,
338 std::nullopt);
339 if (complete_keyholder_identifier) {
340 KeyholderInfo& keyholder_info =
341 info_.keyholders[*complete_keyholder_identifier];
342 keyholder_info.doors_referenced_by.push_back(door_identifier);
343 } else {
344 door_info.malformed_identifiers.keyholders.push_back(ki);
345 }
346 }
347
348 for (const RoomIdentifier& ri : h_door.rooms()) {
349 RoomIdentifier complete_room_identifier =
350 *GetCompleteRoomIdentifier(ri, current_map_name);
351 RoomInfo& room_info = info_.rooms[complete_room_identifier];
352 room_info.doors_referenced_by.push_back(door_identifier);
353 }
354
355 for (const DoorIdentifier& di : h_door.doors()) {
356 DoorIdentifier complete_door_identifier =
357 *GetCompleteDoorIdentifier(di, current_map_name);
358 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
359 other_door_info.doors_referenced_by.push_back(door_identifier);
360 }
361
362 for (const std::string& ei : h_door.endings()) {
363 EndingInfo& ending_info = info_.endings[ei];
364 ending_info.doors_referenced_by.push_back(door_identifier);
365 }
366 }
367
368 void ProcessConnectionsFile(std::filesystem::path path,
369 std::optional<std::string> current_map_name) {
370 if (!std::filesystem::exists(path)) {
371 return;
372 }
373
374 auto connections = ReadMessageFromFile<HumanConnections>(path.string());
375
376 for (const HumanConnection& connection : connections.connections()) {
377 ProcessConnection(connection, current_map_name);
378 }
379 }
380
381 void ProcessConnection(const HumanConnection& human_connection,
382 const std::optional<std::string>& current_map_name) {
383 if (human_connection.has_from_room()) {
384 if (current_map_name) {
385 RoomIdentifier room_identifier;
386 room_identifier.set_map(*current_map_name);
387 room_identifier.set_name(human_connection.from_room());
388
389 RoomInfo& room_info = info_.rooms[room_identifier];
390 room_info.connections_referenced_by.push_back(human_connection);
391 } else {
392 // Not sure where else to store this right now.
393 std::cout << "A global connection used from_room." << std::endl;
394 }
395 } else if (human_connection.has_from()) {
396 ProcessSingleConnection(human_connection, human_connection.from(),
397 current_map_name,
398 /*is_target=*/!human_connection.oneway() &&
399 !human_connection.bypass_target_door());
400 }
401
402 if (human_connection.has_to_room()) {
403 if (current_map_name) {
404 RoomIdentifier room_identifier;
405 room_identifier.set_map(*current_map_name);
406 room_identifier.set_name(human_connection.to_room());
407
408 RoomInfo& room_info = info_.rooms[room_identifier];
409 room_info.connections_referenced_by.push_back(human_connection);
410 } else {
411 // Not sure where else to store this right now.
412 std::cout << "A global connection used to_room." << std::endl;
413 }
414 } else if (human_connection.has_to()) {
415 ProcessSingleConnection(
416 human_connection, human_connection.to(), current_map_name,
417 /*is_target=*/!human_connection.bypass_target_door());
418 }
419
420 if (human_connection.has_door()) {
421 auto door_identifier =
422 GetCompleteDoorIdentifier(human_connection.door(), current_map_name);
423 if (door_identifier) {
424 DoorInfo& door_info = info_.doors[*door_identifier];
425 door_info.connections_referenced_by.push_back(human_connection);
426 } else {
427 // Not sure where else to store this right now.
428 std::cout
429 << "A connection used the following malformed door identifier: "
430 << human_connection.door().ShortDebugString() << std::endl;
431 }
432 }
433 }
434
435 void ProcessSingleConnection(
436 const HumanConnection& human_connection,
437 const HumanConnection::Endpoint& endpoint,
438 const std::optional<std::string>& current_map_name, bool is_target) {
439 if (endpoint.has_room()) {
440 auto room_identifier =
441 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
442 if (room_identifier) {
443 RoomInfo& room_info = info_.rooms[*room_identifier];
444 room_info.connections_referenced_by.push_back(human_connection);
445 } else {
446 // Not sure where else to store this right now.
447 std::cout
448 << "A connection used the following malformed room identifier: "
449 << endpoint.room().ShortDebugString() << std::endl;
450 }
451 } else if (endpoint.has_painting()) {
452 auto painting_identifier = GetCompletePaintingIdentifier(
453 endpoint.painting(), current_map_name, std::nullopt);
454 if (painting_identifier) {
455 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
456 painting_info.connections_referenced_by.push_back(human_connection);
457
458 if (is_target) {
459 painting_info.target_connections_referenced_by.push_back(
460 human_connection);
461 }
462 } else {
463 // Not sure where else to store this right now.
464 std::cout
465 << "A connection used the following malformed painting identifier: "
466 << endpoint.painting().ShortDebugString() << std::endl;
467 }
468 } else if (endpoint.has_port()) {
469 auto port_identifier = GetCompletePortIdentifier(
470 endpoint.port(), current_map_name, std::nullopt);
471 if (port_identifier) {
472 PortInfo& port_info = info_.ports[*port_identifier];
473 port_info.connections_referenced_by.push_back(human_connection);
474
475 if (is_target) {
476 port_info.target_connections_referenced_by.push_back(
477 human_connection);
478 }
479 } else {
480 // Not sure where else to store this right now.
481 std::cout
482 << "A connection used the following malformed port identifier: "
483 << endpoint.port().ShortDebugString() << std::endl;
484 }
485 } else if (endpoint.has_panel()) {
486 auto panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
487 endpoint.panel(), current_map_name, std::nullopt);
488 if (panel_identifier) {
489 PanelInfo& panel_info = info_.panels[*panel_identifier];
490 panel_info.connections_referenced_by.push_back(human_connection);
491
492 if (endpoint.panel().has_answer()) {
493 panel_info.proxies[endpoint.panel().answer()]
494 .connections_referenced_by.push_back(human_connection);
495 }
496
497 if (is_target) {
498 panel_info.target_connections_referenced_by.push_back(
499 human_connection);
500 }
501 }
502 }
503 }
504
505 void ProcessProgressivesFile(std::filesystem::path path) {
506 if (!std::filesystem::exists(path)) {
507 return;
508 }
509
510 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
511
512 for (const HumanProgressive& h_prog : h_progs.progressives()) {
513 ProcessProgressive(h_prog);
514 }
515 }
516
517 void ProcessProgressive(const HumanProgressive& h_prog) {
518 ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
519 prog_info.definitions.push_back(h_prog);
520
521 for (const DoorIdentifier& di : h_prog.doors()) {
522 if (!di.has_map()) {
523 prog_info.malformed_doors.push_back(di);
524 continue;
525 }
526
527 DoorInfo& door_info = info_.doors[di];
528 door_info.progressives_referenced_by.push_back(h_prog.name());
529 }
530 }
531
532 void ProcessDoorGroupsFile(std::filesystem::path path) {
533 if (!std::filesystem::exists(path)) {
534 return;
535 }
536
537 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
538
539 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
540 ProcessDoorGroup(h_group);
541 }
542 }
543
544 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
545 DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
546 group_info.definitions.push_back(h_group);
547
548 for (const DoorIdentifier& di : h_group.doors()) {
549 if (!di.has_map()) {
550 group_info.malformed_doors.push_back(di);
551 continue;
552 }
553
554 DoorInfo& door_info = info_.doors[di];
555 door_info.door_groups_referenced_by.push_back(h_group.name());
556 }
557 }
558
559 void ProcessIdsFile(std::filesystem::path path) {
560 auto ids = ReadIdsFromYaml(path.string());
561
562 DoorIdentifier di;
563 PanelIdentifier pi;
564 KeyholderIdentifier ki;
565
566 for (const auto& [map_name, map] : ids.maps()) {
567 di.set_map(map_name);
568 pi.set_map(map_name);
569 ki.set_map(map_name);
570
571 for (const auto& [door_name, ap_id] : map.doors()) {
572 di.set_name(door_name);
573
574 DoorInfo& door_info = info_.doors[di];
575 door_info.has_id = true;
576 }
577
578 for (const auto& [room_name, room] : map.rooms()) {
579 pi.set_room(room_name);
580 ki.set_room(room_name);
581
582 for (const auto& [panel_name, ap_id] : room.panels()) {
583 pi.set_name(panel_name);
584
585 PanelInfo& panel_info = info_.panels[pi];
586 panel_info.has_id = true;
587 }
588
589 for (const auto& [mastery_name, ap_id] : room.masteries()) {
590 // TODO: Mastery
591 }
592
593 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
594 ki.set_name(keyholder_name);
595
596 KeyholderInfo& keyholder_info = info_.keyholders[ki];
597 keyholder_info.has_id = true;
598 }
599 }
600 }
601
602 for (const auto& [tag, id] : ids.special()) {
603 // TODO: Specials
604 }
605
606 for (const auto& [letter_name, ap_id] : ids.letters()) {
607 LetterIdentifier li =
608 std::make_tuple(letter_name[0], letter_name[1] == '2');
609 LetterInfo& letter_info = info_.letters[li];
610 letter_info.has_id = true;
611 }
612
613 for (const auto& [ending_name, ap_id] : ids.endings()) {
614 EndingInfo& ending_info = info_.endings[ending_name];
615 ending_info.has_id = true;
616 }
617
618 for (const auto& [prog_name, ap_id] : ids.progressives()) {
619 ProgressiveInfo& prog_info = info_.progressives[prog_name];
620 prog_info.has_id = true;
621 }
622
623 for (const auto& [group_name, ap_id] : ids.door_groups()) {
624 DoorGroupInfo& group_info = info_.door_groups[group_name];
625 group_info.has_id = true;
626 }
627 }
628
629 std::string mapdir_;
630 CollectedInfo& info_;
631};
632
633} // namespace
634
635void ProcessHumanData(const std::string& mapdir, CollectedInfo& info) {
636 HumanProcessor human_processor(mapdir, info);
637 human_processor.Run();
638}
639
640} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/human_processor.h b/tools/validator/human_processor.h new file mode 100644 index 0000000..52f174f --- /dev/null +++ b/tools/validator/human_processor.h
@@ -0,0 +1,14 @@
1#ifndef TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_
2#define TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_
3
4#include <string>
5
6namespace com::fourisland::lingo2_archipelago {
7
8struct CollectedInfo;
9
10void ProcessHumanData(const std::string& mapdir, CollectedInfo& info);
11
12} // namespace com::fourisland::lingo2_archipelago
13
14#endif /* TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_ */
diff --git a/tools/validator/main.cpp b/tools/validator/main.cpp new file mode 100644 index 0000000..1a72e9a --- /dev/null +++ b/tools/validator/main.cpp
@@ -0,0 +1,34 @@
1#include "godot_processor.h"
2#include "human_processor.h"
3#include "structs.h"
4#include "validator.h"
5
6namespace com::fourisland::lingo2_archipelago {
7namespace {
8
9void Run(const std::string& mapdir, const std::string& repodir) {
10 CollectedInfo info;
11
12 ProcessHumanData(mapdir, info);
13 ProcessGodotData(repodir, info);
14
15 ValidateCollectedInfo(info);
16}
17
18} // namespace
19} // namespace com::fourisland::lingo2_archipelago
20
21int main(int argc, char** argv) {
22 if (argc != 3) {
23 std::cout << "Incorrect argument count." << std::endl;
24 std::cout << "Usage: validator [path to map directory] [path to Lingo 2 repository]" << std::endl;
25 return 1;
26 }
27
28 std::string mapdir = argv[1];
29 std::string repodir = argv[2];
30
31 com::fourisland::lingo2_archipelago::Run(mapdir, repodir);
32
33 return 0;
34}
diff --git a/tools/validator/structs.h b/tools/validator/structs.h new file mode 100644 index 0000000..d1d45f2 --- /dev/null +++ b/tools/validator/structs.h
@@ -0,0 +1,147 @@
1#ifndef TOOLS_VALIDATOR_STRUCTS_H_
2#define TOOLS_VALIDATOR_STRUCTS_H_
3
4#include <map>
5#include <string>
6#include <vector>
7
8#include "proto/human.pb.h"
9#include "util/identifiers.h"
10
11namespace com::fourisland::lingo2_archipelago {
12
13struct MalformedIdentifiers {
14 std::vector<PaintingIdentifier> paintings;
15 std::vector<PanelIdentifier> panels;
16 std::vector<KeyholderIdentifier> keyholders;
17
18 bool HasAny() const {
19 return !paintings.empty() || !panels.empty() || !keyholders.empty();
20 }
21};
22
23struct GameNodeInfo {
24 bool defined = false;
25 int uses = 0;
26};
27
28struct MapInfo {
29 std::map<std::string, GameNodeInfo> game_nodes;
30};
31
32struct RoomInfo {
33 std::vector<HumanRoom> definitions;
34
35 std::vector<DoorIdentifier> doors_referenced_by;
36 std::vector<PanelIdentifier> panels_referenced_by;
37 std::vector<HumanConnection> connections_referenced_by;
38};
39
40struct DoorInfo {
41 std::vector<HumanDoor> definitions;
42 bool has_id = false;
43
44 std::vector<HumanConnection> connections_referenced_by;
45 std::vector<DoorIdentifier> doors_referenced_by;
46 std::vector<PanelIdentifier> panels_referenced_by;
47 std::vector<PaintingIdentifier> paintings_referenced_by;
48 std::vector<PortIdentifier> ports_referenced_by;
49 std::vector<std::string> progressives_referenced_by;
50 std::vector<std::string> door_groups_referenced_by;
51
52 MalformedIdentifiers malformed_identifiers;
53};
54
55struct PortInfo {
56 std::vector<HumanPort> definitions;
57
58 std::vector<HumanConnection> connections_referenced_by;
59 std::vector<HumanConnection> target_connections_referenced_by;
60};
61
62struct PaintingInfo {
63 std::vector<HumanPainting> definitions;
64
65 std::vector<HumanConnection> connections_referenced_by;
66 std::vector<HumanConnection> target_connections_referenced_by;
67 std::vector<DoorIdentifier> doors_referenced_by;
68};
69
70struct ProxyInfo {
71 std::vector<Proxy> definitions;
72
73 std::vector<HumanConnection> connections_referenced_by;
74 std::vector<DoorIdentifier> doors_referenced_by;
75};
76
77struct PanelInfo {
78 std::vector<HumanPanel> definitions;
79 bool has_id = false;
80
81 std::string map_area_name;
82
83 std::vector<HumanConnection> connections_referenced_by;
84 std::vector<HumanConnection> target_connections_referenced_by;
85 std::vector<DoorIdentifier> doors_referenced_by;
86
87 std::map<std::string, ProxyInfo> proxies;
88};
89
90struct KeyholderInfo {
91 std::vector<HumanKeyholder> definitions;
92 bool has_id = false;
93
94 std::vector<DoorIdentifier> doors_referenced_by;
95};
96
97using LetterIdentifier = std::tuple<char, bool>;
98
99struct LetterInfo {
100 std::vector<RoomIdentifier> defined_in;
101 bool has_id = false;
102};
103
104struct EndingInfo {
105 std::vector<RoomIdentifier> defined_in;
106 bool has_id = false;
107
108 std::vector<DoorIdentifier> doors_referenced_by;
109};
110
111struct PanelNameInfo {
112 std::vector<PanelIdentifier> panels_used_by;
113};
114
115struct ProgressiveInfo {
116 std::vector<HumanProgressive> definitions;
117 bool has_id = false;
118
119 std::vector<DoorIdentifier> malformed_doors;
120};
121
122struct DoorGroupInfo {
123 std::vector<HumanDoorGroup> definitions;
124 bool has_id = false;
125
126 std::vector<DoorIdentifier> malformed_doors;
127};
128
129struct CollectedInfo {
130 std::map<std::string, MapInfo> maps;
131 std::map<RoomIdentifier, RoomInfo, RoomIdentifierLess> rooms;
132 std::map<DoorIdentifier, DoorInfo, DoorIdentifierLess> doors;
133 std::map<PortIdentifier, PortInfo, PortIdentifierLess> ports;
134 std::map<PaintingIdentifier, PaintingInfo, PaintingIdentifierLess> paintings;
135 std::map<PanelIdentifier, PanelInfo, PanelIdentifierLess> panels;
136 std::map<KeyholderIdentifier, KeyholderInfo, KeyholderIdentifierLess>
137 keyholders;
138 std::map<LetterIdentifier, LetterInfo> letters;
139 std::map<std::string, EndingInfo> endings;
140 std::map<std::string, PanelNameInfo> panel_names;
141 std::map<std::string, ProgressiveInfo> progressives;
142 std::map<std::string, DoorGroupInfo> door_groups;
143};
144
145} // namespace com::fourisland::lingo2_archipelago
146
147#endif /* TOOLS_VALIDATOR_STRUCTS_H_ */
diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp new file mode 100644 index 0000000..dd41f5c --- /dev/null +++ b/tools/validator/validator.cpp
@@ -0,0 +1,550 @@
1#include "validator.h"
2
3#include <iostream>
4
5#include "proto/human.pb.h"
6#include "structs.h"
7#include "util/identifiers.h"
8
9namespace com::fourisland::lingo2_archipelago {
10namespace {
11
12class Validator {
13 public:
14 explicit Validator(const CollectedInfo& info) : info_(info) {}
15
16 void Validate() const {
17 for (const auto& [map_name, map_info] : info_.maps) {
18 ValidateMap(map_name, map_info);
19 }
20 for (const auto& [room_identifier, room_info] : info_.rooms) {
21 ValidateRoom(room_identifier, room_info);
22 }
23 for (const auto& [door_identifier, door_info] : info_.doors) {
24 ValidateDoor(door_identifier, door_info);
25 }
26 for (const auto& [port_identifier, port_info] : info_.ports) {
27 ValidatePort(port_identifier, port_info);
28 }
29 for (const auto& [painting_identifier, painting_info] : info_.paintings) {
30 ValidatePainting(painting_identifier, painting_info);
31 }
32 for (const auto& [panel_identifier, panel_info] : info_.panels) {
33 ValidatePanel(panel_identifier, panel_info);
34 }
35 for (const auto& [keyholder_identifier, keyholder_info] :
36 info_.keyholders) {
37 ValidateKeyholder(keyholder_identifier, keyholder_info);
38 }
39 for (const auto& [letter_identifier, letter_info] : info_.letters) {
40 ValidateLetter(letter_identifier, letter_info);
41 }
42 for (const auto& [ending_name, ending_info] : info_.endings) {
43 ValidateEnding(ending_name, ending_info);
44 }
45 for (const auto& [panel_name, panel_info] : info_.panel_names) {
46 ValidatePanelName(panel_name, panel_info);
47 }
48 for (const auto& [prog_name, prog_info] : info_.progressives) {
49 ValidateProgressive(prog_name, prog_info);
50 }
51 for (const auto& [group_name, group_info] : info_.door_groups) {
52 ValidateDoorGroup(group_name, group_info);
53 }
54 }
55
56 private:
57 void ValidateMap(const std::string& map_name, const MapInfo& map_info) const {
58 for (const auto& [node_path, node_info] : map_info.game_nodes) {
59 if (node_info.uses > 1) {
60 std::cout << "Map " << map_name << " node " << node_path
61 << " is used in multiple places." << std::endl;
62 } else if (node_info.uses == 0) {
63 std::cout << "Map " << map_name << " node " << node_path
64 << " is not used." << std::endl;
65 }
66
67 if (!node_info.defined) {
68 std::cout << "Map " << map_name << " node " << node_path
69 << " is not defined in the game file." << std::endl;
70 }
71 }
72 }
73
74 void ValidateRoom(const RoomIdentifier& room_identifier,
75 const RoomInfo& room_info) const {
76 if (room_info.definitions.empty()) {
77 std::cout << "Room " << room_identifier.ShortDebugString()
78 << " has no definition, but was referenced:" << std::endl;
79
80 for (const DoorIdentifier& door_identifier :
81 room_info.doors_referenced_by) {
82 std::cout << " DOOR " << door_identifier.ShortDebugString()
83 << std::endl;
84 }
85
86 for (const PanelIdentifier& panel_identifier :
87 room_info.panels_referenced_by) {
88 std::cout << " PANEL " << panel_identifier.ShortDebugString()
89 << std::endl;
90 }
91
92 for (const HumanConnection& connection :
93 room_info.connections_referenced_by) {
94 std::cout << " CONNECTION " << connection.ShortDebugString()
95 << std::endl;
96 }
97 } else if (room_info.definitions.size() > 1) {
98 std::cout << "Room " << room_identifier.ShortDebugString()
99 << " was defined multiple times." << std::endl;
100 }
101 }
102
103 bool DoesDoorNeedLocationName(const HumanDoor& h_door,
104 const std::string& map_name) const {
105 if (h_door.type() != DoorType::STANDARD) {
106 return false;
107 }
108
109 if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0 ||
110 h_door.complete_at() > 0) {
111 return true;
112 }
113
114 if (h_door.panels_size() > 4) {
115 return true;
116 }
117
118 std::set<std::string> map_areas;
119 for (const PanelIdentifier& pi : h_door.panels()) {
120 auto full_pi =
121 GetCompletePanelIdentifierWithoutAnswer(pi, map_name, std::nullopt);
122 if (full_pi) {
123 auto panel_info_it = info_.panels.find(*full_pi);
124 if (panel_info_it != info_.panels.end()) {
125 const PanelInfo& panel_info = panel_info_it->second;
126
127 map_areas.insert(panel_info.map_area_name);
128 }
129 }
130 }
131
132 if (map_areas.size() > 1) {
133 return true;
134 }
135
136 return false;
137 }
138
139 void ValidateDoor(const DoorIdentifier& door_identifier,
140 const DoorInfo& door_info) const {
141 if (door_info.definitions.empty()) {
142 std::cout << "Door " << door_identifier.ShortDebugString()
143 << " has no definition, but was referenced:" << std::endl;
144
145 for (const DoorIdentifier& other_door_identifier :
146 door_info.doors_referenced_by) {
147 std::cout << " DOOR " << other_door_identifier.ShortDebugString()
148 << std::endl;
149 }
150
151 for (const PanelIdentifier& panel_identifier :
152 door_info.panels_referenced_by) {
153 std::cout << " PANEL " << panel_identifier.ShortDebugString()
154 << std::endl;
155 }
156
157 for (const PaintingIdentifier& painting_identifier :
158 door_info.paintings_referenced_by) {
159 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
160 << std::endl;
161 }
162
163 for (const PortIdentifier& port_identifier :
164 door_info.ports_referenced_by) {
165 std::cout << " PORT " << port_identifier.ShortDebugString()
166 << std::endl;
167 }
168
169 for (const HumanConnection& connection :
170 door_info.connections_referenced_by) {
171 std::cout << " CONNECTION " << connection.ShortDebugString()
172 << std::endl;
173 }
174
175 for (const std::string& prog_name :
176 door_info.progressives_referenced_by) {
177 std::cout << " PROGRESSIVE " << prog_name << std::endl;
178 }
179
180 for (const std::string& group_name :
181 door_info.door_groups_referenced_by) {
182 std::cout << " DOOR GROUP " << group_name << std::endl;
183 }
184
185 if (door_info.has_id) {
186 std::cout << " An AP ID is present." << std::endl;
187 }
188 } else if (door_info.definitions.size() > 1) {
189 std::cout << "Door " << door_identifier.ShortDebugString()
190 << " was defined multiple times." << std::endl;
191 }
192
193 if (door_info.malformed_identifiers.HasAny()) {
194 std::cout << "Door " << door_identifier.ShortDebugString()
195 << " has malformed identifiers:" << std::endl;
196
197 for (const PaintingIdentifier& painting_identifier :
198 door_info.malformed_identifiers.paintings) {
199 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
200 << std::endl;
201 }
202
203 for (const PanelIdentifier& panel_identifier :
204 door_info.malformed_identifiers.panels) {
205 std::cout << " PANEL " << panel_identifier.ShortDebugString()
206 << std::endl;
207 }
208
209 for (const KeyholderIdentifier& keyholder_identifier :
210 door_info.malformed_identifiers.keyholders) {
211 std::cout << " KEYHOLDER " << keyholder_identifier.ShortDebugString()
212 << std::endl;
213 }
214 }
215
216 for (const HumanDoor& h_door : door_info.definitions) {
217 if (DoesDoorNeedLocationName(h_door, door_identifier.map()) &&
218 !h_door.has_location_name()) {
219 std::cout << "Door " << door_identifier.ShortDebugString()
220 << " needs an explicit location name." << std::endl;
221 }
222
223 if (h_door.double_letters() &&
224 (h_door.type() == DoorType::STANDARD ||
225 h_door.type() == DoorType::LOCATION_ONLY ||
226 h_door.type() == DoorType::GRAVESTONE)) {
227 std::cout << "Door " << door_identifier.ShortDebugString()
228 << " is a location that depends on double_letters."
229 << std::endl;
230 }
231
232 bool needs_id = (h_door.type() != DoorType::EVENT);
233 if (door_info.has_id != needs_id) {
234 if (needs_id) {
235 std::cout << "Door " << door_identifier.ShortDebugString()
236 << " is missing an AP ID." << std::endl;
237 } else {
238 std::cout << "Door " << door_identifier.ShortDebugString()
239 << " should not have an AP ID." << std::endl;
240 }
241 }
242 }
243 }
244
245 void ValidatePort(const PortIdentifier& port_identifier,
246 const PortInfo& port_info) const {
247 if (port_info.definitions.empty()) {
248 std::cout << "Port " << port_identifier.ShortDebugString()
249 << " has no definition, but was referenced:" << std::endl;
250
251 for (const HumanConnection& connection :
252 port_info.connections_referenced_by) {
253 std::cout << " CONNECTION " << connection.ShortDebugString()
254 << std::endl;
255 }
256 } else if (port_info.definitions.size() > 1) {
257 std::cout << "Port " << port_identifier.ShortDebugString()
258 << " was defined multiple times." << std::endl;
259 }
260
261 if (!port_info.target_connections_referenced_by.empty()) {
262 for (const HumanPort& port : port_info.definitions) {
263 if (port.has_required_door()) {
264 std::cout << "Port " << port_identifier.ShortDebugString()
265 << " has a required door but is the target of a connection:"
266 << std::endl;
267
268 for (const HumanConnection& connection :
269 port_info.target_connections_referenced_by) {
270 std::cout << " CONNECTION " << connection.ShortDebugString()
271 << std::endl;
272 }
273 }
274 }
275 }
276 }
277
278 void ValidatePainting(const PaintingIdentifier& painting_identifier,
279 const PaintingInfo& painting_info) const {
280 if (painting_info.definitions.empty()) {
281 std::cout << "Painting " << painting_identifier.ShortDebugString()
282 << " has no definition, but was referenced:" << std::endl;
283
284 for (const DoorIdentifier& door_identifier :
285 painting_info.doors_referenced_by) {
286 std::cout << " DOOR " << door_identifier.ShortDebugString()
287 << std::endl;
288 }
289
290 for (const HumanConnection& connection :
291 painting_info.connections_referenced_by) {
292 std::cout << " CONNECTION " << connection.ShortDebugString()
293 << std::endl;
294 }
295 } else if (painting_info.definitions.size() > 1) {
296 std::cout << "Painting " << painting_identifier.ShortDebugString()
297 << " was defined multiple times." << std::endl;
298 }
299
300 if (!painting_info.target_connections_referenced_by.empty()) {
301 for (const HumanPainting& painting : painting_info.definitions) {
302 if (painting.has_required_door()) {
303 std::cout << "Painting " << painting_identifier.ShortDebugString()
304 << " has a required door but is the target of a connection:"
305 << std::endl;
306
307 for (const HumanConnection& connection :
308 painting_info.target_connections_referenced_by) {
309 std::cout << " CONNECTION " << connection.ShortDebugString()
310 << std::endl;
311 }
312 }
313 }
314 }
315 }
316
317 void ValidatePanel(const PanelIdentifier& panel_identifier,
318 const PanelInfo& panel_info) const {
319 if (panel_identifier.name().empty()) {
320 std::cout << "Panel " << panel_identifier.ShortDebugString()
321 << " has no name." << std::endl;
322 }
323
324 if (panel_info.definitions.empty()) {
325 std::cout << "Panel " << panel_identifier.ShortDebugString()
326 << " has no definition, but was referenced:" << std::endl;
327
328 for (const DoorIdentifier& door_identifier :
329 panel_info.doors_referenced_by) {
330 std::cout << " DOOR " << door_identifier.ShortDebugString()
331 << std::endl;
332 }
333
334 for (const HumanConnection& connection :
335 panel_info.connections_referenced_by) {
336 std::cout << " CONNECTION " << connection.ShortDebugString()
337 << std::endl;
338 }
339
340 if (panel_info.has_id) {
341 std::cout << " An AP ID is present." << std::endl;
342 }
343 } else if (panel_info.definitions.size() > 1) {
344 std::cout << "Panel " << panel_identifier.ShortDebugString()
345 << " was defined multiple times." << std::endl;
346 }
347
348 for (const auto& [answer, proxy_info] : panel_info.proxies) {
349 if (proxy_info.definitions.empty()) {
350 std::cout << "Panel " << panel_identifier.ShortDebugString()
351 << " with answer \"" << answer
352 << "\" has no definition, but was referenced:" << std::endl;
353
354 for (const DoorIdentifier& door_identifier :
355 proxy_info.doors_referenced_by) {
356 std::cout << " DOOR " << door_identifier.ShortDebugString()
357 << std::endl;
358 }
359
360 for (const HumanConnection& connection :
361 proxy_info.connections_referenced_by) {
362 std::cout << " CONNECTION " << connection.ShortDebugString()
363 << std::endl;
364 }
365 } else if (proxy_info.definitions.size() > 1) {
366 std::cout << "Panel " << panel_identifier.ShortDebugString()
367 << " with answer \"" << answer
368 << "\" was defined multiple times." << std::endl;
369 }
370 }
371
372 if (!panel_info.has_id) {
373 std::cout << "Panel " << panel_identifier.ShortDebugString()
374 << " is missing an AP ID." << std::endl;
375 }
376
377 if (!panel_info.target_connections_referenced_by.empty()) {
378 for (const HumanPanel& panel : panel_info.definitions) {
379 if (panel.has_required_door()) {
380 std::cout << "Panel " << panel_identifier.ShortDebugString()
381 << " has a required door but is the target of a connection:"
382 << std::endl;
383
384 for (const HumanConnection& connection :
385 panel_info.target_connections_referenced_by) {
386 std::cout << " CONNECTION " << connection.ShortDebugString()
387 << std::endl;
388 }
389 }
390 }
391 }
392 }
393
394 void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier,
395 const KeyholderInfo& keyholder_info) const {
396 if (keyholder_info.definitions.empty()) {
397 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
398 << " has no definition, but was referenced:" << std::endl;
399
400 for (const DoorIdentifier& door_identifier :
401 keyholder_info.doors_referenced_by) {
402 std::cout << " DOOR " << door_identifier.ShortDebugString()
403 << std::endl;
404 }
405
406 if (keyholder_info.has_id) {
407 std::cout << " An AP ID is present." << std::endl;
408 }
409 } else if (keyholder_info.definitions.size() > 1) {
410 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
411 << " was defined multiple times." << std::endl;
412 }
413
414 for (const HumanKeyholder& h_keyholder : keyholder_info.definitions) {
415 bool needs_id = (h_keyholder.has_key());
416
417 if (needs_id != keyholder_info.has_id) {
418 if (needs_id) {
419 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
420 << " is missing an AP ID." << std::endl;
421 } else {
422 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
423 << " should not have an AP ID." << std::endl;
424 }
425 }
426 }
427 }
428
429 void ValidateLetter(const LetterIdentifier& letter_identifier,
430 const LetterInfo& letter_info) const {
431 std::string letter_name = std::string(1, std::get<0>(letter_identifier)) +
432 (std::get<1>(letter_identifier) ? "2" : "1");
433
434 if (letter_info.defined_in.empty()) {
435 std::cout << "Letter " << letter_name
436 << " has no definition, but was referenced:" << std::endl;
437
438 if (letter_info.has_id) {
439 std::cout << " An AP ID is present." << std::endl;
440 }
441 } else if (letter_info.defined_in.size() > 1) {
442 std::cout << "Letter " << letter_name
443 << " was defined in multiple places:" << std::endl;
444
445 for (const RoomIdentifier& room_identifier : letter_info.defined_in) {
446 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
447 }
448 }
449
450 if (!letter_info.has_id) {
451 std::cout << "Letter " << letter_name << " is missing an AP ID."
452 << std::endl;
453 }
454 }
455
456 void ValidateEnding(const std::string& ending_name,
457 const EndingInfo& ending_info) const {
458 if (ending_info.defined_in.empty()) {
459 std::cout << "Ending " << ending_name
460 << " has no definition, but was referenced:" << std::endl;
461
462 for (const DoorIdentifier& door_identifier :
463 ending_info.doors_referenced_by) {
464 std::cout << " DOOR " << door_identifier.ShortDebugString()
465 << std::endl;
466 }
467
468 if (ending_info.has_id) {
469 std::cout << " An AP ID is present." << std::endl;
470 }
471 } else if (ending_info.defined_in.size() > 1) {
472 std::cout << "Ending " << ending_name
473 << " was defined in multiple places:" << std::endl;
474
475 for (const RoomIdentifier& room_identifier : ending_info.defined_in) {
476 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
477 }
478 }
479
480 if (!ending_info.has_id) {
481 std::cout << "Ending " << ending_name << " is missing an AP ID."
482 << std::endl;
483 }
484 }
485
486 void ValidatePanelName(const std::string& panel_name,
487 const PanelNameInfo& panel_info) const {
488 if (panel_info.panels_used_by.size() > 1) {
489 std::cout << "The location name \"" << panel_name
490 << "\" is used by multiple panels:" << std::endl;
491
492 for (const PanelIdentifier& panel_identifier :
493 panel_info.panels_used_by) {
494 std::cout << " PANEL " << panel_identifier.ShortDebugString()
495 << std::endl;
496 }
497 }
498 }
499
500 void ValidateProgressive(const std::string& prog_name,
501 const ProgressiveInfo& prog_info) const {
502 if (prog_info.definitions.empty()) {
503 std::cout << "Progressive \"" << prog_name
504 << "\" has no definition, but was referenced:" << std::endl;
505
506 if (prog_info.has_id) {
507 std::cout << " An AP ID is present." << std::endl;
508 }
509 } else if (prog_info.definitions.size() > 1) {
510 std::cout << "Progressive \"" << prog_name
511 << "\" has multiple definitions." << std::endl;
512 }
513
514 if (!prog_info.has_id) {
515 std::cout << "Progressive \"" << prog_name << "\" is missing an AP ID."
516 << std::endl;
517 }
518 }
519
520 void ValidateDoorGroup(const std::string& group_name,
521 const DoorGroupInfo& group_info) const {
522 if (group_info.definitions.empty()) {
523 std::cout << "Door group \"" << group_name
524 << "\" has no definition, but was referenced:" << std::endl;
525
526 if (group_info.has_id) {
527 std::cout << " An AP ID is present." << std::endl;
528 }
529 } else if (group_info.definitions.size() > 1) {
530 std::cout << "Door group \"" << group_name
531 << "\" has multiple definitions." << std::endl;
532 }
533
534 if (!group_info.has_id) {
535 std::cout << "Door group \"" << group_name << "\" is missing an AP ID."
536 << std::endl;
537 }
538 }
539
540 const CollectedInfo& info_;
541};
542
543} // namespace
544
545void ValidateCollectedInfo(const CollectedInfo& info) {
546 Validator validator(info);
547 validator.Validate();
548}
549
550} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/validator.h b/tools/validator/validator.h new file mode 100644 index 0000000..b710429 --- /dev/null +++ b/tools/validator/validator.h
@@ -0,0 +1,12 @@
1#ifndef TOOLS_VALIDATOR_VALIDATOR_H_
2#define TOOLS_VALIDATOR_VALIDATOR_H
3
4namespace com::fourisland::lingo2_archipelago {
5
6struct CollectedInfo;
7
8void ValidateCollectedInfo(const CollectedInfo& info);
9
10} // namespace com::fourisland::lingo2_archipelago
11
12#endif /* TOOLS_VALIDATOR_VALIDATOR_H */