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