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/human_processor.cpp59
-rw-r--r--tools/validator/structs.h12
-rw-r--r--tools/validator/validator.cpp79
3 files changed, 145 insertions, 5 deletions
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 5720ba9..2c978bf 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp
@@ -43,6 +43,7 @@ class HumanProcessor {
43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
44 ProcessMaps(datadir_path); 44 ProcessMaps(datadir_path);
45 ProcessProgressivesFile(datadir_path / "progressives.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
46 ProcessIdsFile(datadir_path / "ids.yaml"); 47 ProcessIdsFile(datadir_path / "ids.yaml");
47 } 48 }
48 49
@@ -393,7 +394,9 @@ class HumanProcessor {
393 } 394 }
394 } else if (human_connection.has_from()) { 395 } else if (human_connection.has_from()) {
395 ProcessSingleConnection(human_connection, human_connection.from(), 396 ProcessSingleConnection(human_connection, human_connection.from(),
396 current_map_name); 397 current_map_name,
398 /*is_target=*/!human_connection.oneway() &&
399 !human_connection.bypass_target_door());
397 } 400 }
398 401
399 if (human_connection.has_to_room()) { 402 if (human_connection.has_to_room()) {
@@ -409,8 +412,9 @@ class HumanProcessor {
409 std::cout << "A global connection used to_room." << std::endl; 412 std::cout << "A global connection used to_room." << std::endl;
410 } 413 }
411 } else if (human_connection.has_to()) { 414 } else if (human_connection.has_to()) {
412 ProcessSingleConnection(human_connection, human_connection.to(), 415 ProcessSingleConnection(
413 current_map_name); 416 human_connection, human_connection.to(), current_map_name,
417 /*is_target=*/!human_connection.bypass_target_door());
414 } 418 }
415 419
416 if (human_connection.has_door()) { 420 if (human_connection.has_door()) {
@@ -431,7 +435,7 @@ class HumanProcessor {
431 void ProcessSingleConnection( 435 void ProcessSingleConnection(
432 const HumanConnection& human_connection, 436 const HumanConnection& human_connection,
433 const HumanConnection::Endpoint& endpoint, 437 const HumanConnection::Endpoint& endpoint,
434 const std::optional<std::string>& current_map_name) { 438 const std::optional<std::string>& current_map_name, bool is_target) {
435 if (endpoint.has_room()) { 439 if (endpoint.has_room()) {
436 auto room_identifier = 440 auto room_identifier =
437 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 441 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -450,6 +454,11 @@ class HumanProcessor {
450 if (painting_identifier) { 454 if (painting_identifier) {
451 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 455 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
452 painting_info.connections_referenced_by.push_back(human_connection); 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 }
453 } else { 462 } else {
454 // Not sure where else to store this right now. 463 // Not sure where else to store this right now.
455 std::cout 464 std::cout
@@ -462,6 +471,11 @@ class HumanProcessor {
462 if (port_identifier) { 471 if (port_identifier) {
463 PortInfo& port_info = info_.ports[*port_identifier]; 472 PortInfo& port_info = info_.ports[*port_identifier];
464 port_info.connections_referenced_by.push_back(human_connection); 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 }
465 } else { 479 } else {
466 // Not sure where else to store this right now. 480 // Not sure where else to store this right now.
467 std::cout 481 std::cout
@@ -479,6 +493,11 @@ class HumanProcessor {
479 panel_info.proxies[endpoint.panel().answer()] 493 panel_info.proxies[endpoint.panel().answer()]
480 .connections_referenced_by.push_back(human_connection); 494 .connections_referenced_by.push_back(human_connection);
481 } 495 }
496
497 if (is_target) {
498 panel_info.target_connections_referenced_by.push_back(
499 human_connection);
500 }
482 } 501 }
483 } 502 }
484 } 503 }
@@ -510,6 +529,33 @@ class HumanProcessor {
510 } 529 }
511 } 530 }
512 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
513 void ProcessIdsFile(std::filesystem::path path) { 559 void ProcessIdsFile(std::filesystem::path path) {
514 auto ids = ReadIdsFromYaml(path.string()); 560 auto ids = ReadIdsFromYaml(path.string());
515 561
@@ -573,6 +619,11 @@ class HumanProcessor {
573 ProgressiveInfo& prog_info = info_.progressives[prog_name]; 619 ProgressiveInfo& prog_info = info_.progressives[prog_name];
574 prog_info.has_id = true; 620 prog_info.has_id = true;
575 } 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 }
576 } 627 }
577 628
578 std::string mapdir_; 629 std::string mapdir_;
diff --git a/tools/validator/structs.h b/tools/validator/structs.h index e24ed3d..d1d45f2 100644 --- a/tools/validator/structs.h +++ b/tools/validator/structs.h
@@ -47,6 +47,7 @@ struct DoorInfo {
47 std::vector<PaintingIdentifier> paintings_referenced_by; 47 std::vector<PaintingIdentifier> paintings_referenced_by;
48 std::vector<PortIdentifier> ports_referenced_by; 48 std::vector<PortIdentifier> ports_referenced_by;
49 std::vector<std::string> progressives_referenced_by; 49 std::vector<std::string> progressives_referenced_by;
50 std::vector<std::string> door_groups_referenced_by;
50 51
51 MalformedIdentifiers malformed_identifiers; 52 MalformedIdentifiers malformed_identifiers;
52}; 53};
@@ -55,12 +56,14 @@ struct PortInfo {
55 std::vector<HumanPort> definitions; 56 std::vector<HumanPort> definitions;
56 57
57 std::vector<HumanConnection> connections_referenced_by; 58 std::vector<HumanConnection> connections_referenced_by;
59 std::vector<HumanConnection> target_connections_referenced_by;
58}; 60};
59 61
60struct PaintingInfo { 62struct PaintingInfo {
61 std::vector<HumanPainting> definitions; 63 std::vector<HumanPainting> definitions;
62 64
63 std::vector<HumanConnection> connections_referenced_by; 65 std::vector<HumanConnection> connections_referenced_by;
66 std::vector<HumanConnection> target_connections_referenced_by;
64 std::vector<DoorIdentifier> doors_referenced_by; 67 std::vector<DoorIdentifier> doors_referenced_by;
65}; 68};
66 69
@@ -78,6 +81,7 @@ struct PanelInfo {
78 std::string map_area_name; 81 std::string map_area_name;
79 82
80 std::vector<HumanConnection> connections_referenced_by; 83 std::vector<HumanConnection> connections_referenced_by;
84 std::vector<HumanConnection> target_connections_referenced_by;
81 std::vector<DoorIdentifier> doors_referenced_by; 85 std::vector<DoorIdentifier> doors_referenced_by;
82 86
83 std::map<std::string, ProxyInfo> proxies; 87 std::map<std::string, ProxyInfo> proxies;
@@ -115,6 +119,13 @@ struct ProgressiveInfo {
115 std::vector<DoorIdentifier> malformed_doors; 119 std::vector<DoorIdentifier> malformed_doors;
116}; 120};
117 121
122struct DoorGroupInfo {
123 std::vector<HumanDoorGroup> definitions;
124 bool has_id = false;
125
126 std::vector<DoorIdentifier> malformed_doors;
127};
128
118struct CollectedInfo { 129struct CollectedInfo {
119 std::map<std::string, MapInfo> maps; 130 std::map<std::string, MapInfo> maps;
120 std::map<RoomIdentifier, RoomInfo, RoomIdentifierLess> rooms; 131 std::map<RoomIdentifier, RoomInfo, RoomIdentifierLess> rooms;
@@ -128,6 +139,7 @@ struct CollectedInfo {
128 std::map<std::string, EndingInfo> endings; 139 std::map<std::string, EndingInfo> endings;
129 std::map<std::string, PanelNameInfo> panel_names; 140 std::map<std::string, PanelNameInfo> panel_names;
130 std::map<std::string, ProgressiveInfo> progressives; 141 std::map<std::string, ProgressiveInfo> progressives;
142 std::map<std::string, DoorGroupInfo> door_groups;
131}; 143};
132 144
133} // namespace com::fourisland::lingo2_archipelago 145} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp index ab1612e..dd41f5c 100644 --- a/tools/validator/validator.cpp +++ b/tools/validator/validator.cpp
@@ -48,6 +48,9 @@ class Validator {
48 for (const auto& [prog_name, prog_info] : info_.progressives) { 48 for (const auto& [prog_name, prog_info] : info_.progressives) {
49 ValidateProgressive(prog_name, prog_info); 49 ValidateProgressive(prog_name, prog_info);
50 } 50 }
51 for (const auto& [group_name, group_info] : info_.door_groups) {
52 ValidateDoorGroup(group_name, group_info);
53 }
51 } 54 }
52 55
53 private: 56 private:
@@ -103,7 +106,8 @@ class Validator {
103 return false; 106 return false;
104 } 107 }
105 108
106 if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0) { 109 if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0 ||
110 h_door.complete_at() > 0) {
107 return true; 111 return true;
108 } 112 }
109 113
@@ -173,6 +177,11 @@ class Validator {
173 std::cout << " PROGRESSIVE " << prog_name << std::endl; 177 std::cout << " PROGRESSIVE " << prog_name << std::endl;
174 } 178 }
175 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
176 if (door_info.has_id) { 185 if (door_info.has_id) {
177 std::cout << " An AP ID is present." << std::endl; 186 std::cout << " An AP ID is present." << std::endl;
178 } 187 }
@@ -248,6 +257,22 @@ class Validator {
248 std::cout << "Port " << port_identifier.ShortDebugString() 257 std::cout << "Port " << port_identifier.ShortDebugString()
249 << " was defined multiple times." << std::endl; 258 << " was defined multiple times." << std::endl;
250 } 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 }
251 } 276 }
252 277
253 void ValidatePainting(const PaintingIdentifier& painting_identifier, 278 void ValidatePainting(const PaintingIdentifier& painting_identifier,
@@ -271,6 +296,22 @@ class Validator {
271 std::cout << "Painting " << painting_identifier.ShortDebugString() 296 std::cout << "Painting " << painting_identifier.ShortDebugString()
272 << " was defined multiple times." << std::endl; 297 << " was defined multiple times." << std::endl;
273 } 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 }
274 } 315 }
275 316
276 void ValidatePanel(const PanelIdentifier& panel_identifier, 317 void ValidatePanel(const PanelIdentifier& panel_identifier,
@@ -332,6 +373,22 @@ class Validator {
332 std::cout << "Panel " << panel_identifier.ShortDebugString() 373 std::cout << "Panel " << panel_identifier.ShortDebugString()
333 << " is missing an AP ID." << std::endl; 374 << " is missing an AP ID." << std::endl;
334 } 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 }
335 } 392 }
336 393
337 void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier, 394 void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier,
@@ -460,6 +517,26 @@ class Validator {
460 } 517 }
461 } 518 }
462 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
463 const CollectedInfo& info_; 540 const CollectedInfo& info_;
464}; 541};
465 542