about summary refs log tree commit diff stats
path: root/tools/validator/human_processor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/validator/human_processor.cpp')
-rw-r--r--tools/validator/human_processor.cpp183
1 files changed, 172 insertions, 11 deletions
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 0f63936..ffa9765 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp
@@ -13,6 +13,7 @@
13#include <string> 13#include <string>
14 14
15#include "structs.h" 15#include "structs.h"
16#include "util/ids_yaml_format.h"
16 17
17namespace com::fourisland::lingo2_archipelago { 18namespace com::fourisland::lingo2_archipelago {
18namespace { 19namespace {
@@ -41,7 +42,9 @@ class HumanProcessor {
41 42
42 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
43 ProcessMaps(datadir_path); 44 ProcessMaps(datadir_path);
44 ProcessIdsFile(datadir_path / "ids.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
45 } 48 }
46 49
47 private: 50 private:
@@ -74,6 +77,21 @@ class HumanProcessor {
74 for (const std::string& path : metadata.excluded_nodes()) { 77 for (const std::string& path : metadata.excluded_nodes()) {
75 map_info.game_nodes[path].uses++; 78 map_info.game_nodes[path].uses++;
76 } 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 }
77 } 95 }
78 96
79 void ProcessRooms(std::filesystem::path path, 97 void ProcessRooms(std::filesystem::path path,
@@ -355,11 +373,6 @@ class HumanProcessor {
355 DoorInfo& other_door_info = info_.doors[complete_door_identifier]; 373 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
356 other_door_info.doors_referenced_by.push_back(door_identifier); 374 other_door_info.doors_referenced_by.push_back(door_identifier);
357 } 375 }
358
359 for (const std::string& ei : h_door.endings()) {
360 EndingInfo& ending_info = info_.endings[ei];
361 ending_info.doors_referenced_by.push_back(door_identifier);
362 }
363 } 376 }
364 377
365 void ProcessConnectionsFile(std::filesystem::path path, 378 void ProcessConnectionsFile(std::filesystem::path path,
@@ -391,7 +404,9 @@ class HumanProcessor {
391 } 404 }
392 } else if (human_connection.has_from()) { 405 } else if (human_connection.has_from()) {
393 ProcessSingleConnection(human_connection, human_connection.from(), 406 ProcessSingleConnection(human_connection, human_connection.from(),
394 current_map_name); 407 current_map_name,
408 /*is_target=*/!human_connection.oneway() &&
409 !human_connection.bypass_target_door());
395 } 410 }
396 411
397 if (human_connection.has_to_room()) { 412 if (human_connection.has_to_room()) {
@@ -407,8 +422,9 @@ class HumanProcessor {
407 std::cout << "A global connection used to_room." << std::endl; 422 std::cout << "A global connection used to_room." << std::endl;
408 } 423 }
409 } else if (human_connection.has_to()) { 424 } else if (human_connection.has_to()) {
410 ProcessSingleConnection(human_connection, human_connection.to(), 425 ProcessSingleConnection(
411 current_map_name); 426 human_connection, human_connection.to(), current_map_name,
427 /*is_target=*/!human_connection.bypass_target_door());
412 } 428 }
413 429
414 if (human_connection.has_door()) { 430 if (human_connection.has_door()) {
@@ -429,7 +445,7 @@ class HumanProcessor {
429 void ProcessSingleConnection( 445 void ProcessSingleConnection(
430 const HumanConnection& human_connection, 446 const HumanConnection& human_connection,
431 const HumanConnection::Endpoint& endpoint, 447 const HumanConnection::Endpoint& endpoint,
432 const std::optional<std::string>& current_map_name) { 448 const std::optional<std::string>& current_map_name, bool is_target) {
433 if (endpoint.has_room()) { 449 if (endpoint.has_room()) {
434 auto room_identifier = 450 auto room_identifier =
435 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 451 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -448,6 +464,11 @@ class HumanProcessor {
448 if (painting_identifier) { 464 if (painting_identifier) {
449 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 465 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
450 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 }
451 } else { 472 } else {
452 // Not sure where else to store this right now. 473 // Not sure where else to store this right now.
453 std::cout 474 std::cout
@@ -460,6 +481,11 @@ class HumanProcessor {
460 if (port_identifier) { 481 if (port_identifier) {
461 PortInfo& port_info = info_.ports[*port_identifier]; 482 PortInfo& port_info = info_.ports[*port_identifier];
462 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 }
463 } else { 489 } else {
464 // Not sure where else to store this right now. 490 // Not sure where else to store this right now.
465 std::cout 491 std::cout
@@ -477,12 +503,147 @@ class HumanProcessor {
477 panel_info.proxies[endpoint.panel().answer()] 503 panel_info.proxies[endpoint.panel().answer()]
478 .connections_referenced_by.push_back(human_connection); 504 .connections_referenced_by.push_back(human_connection);
479 } 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;
480 } 562 }
563
564 DoorInfo& door_info = info_.doors[di];
565 door_info.door_groups_referenced_by.push_back(h_group.name());
481 } 566 }
482 } 567 }
483 568
484 void ProcessIdsFile(std::filesystem::path path) { 569 void ProcessIdsFile(std::filesystem::path path) {
485 // 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 }
486 } 647 }
487 648
488 std::string mapdir_; 649 std::string mapdir_;