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.cpp225
1 files changed, 210 insertions, 15 deletions
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index f53dc79..d6fcfa6 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp
@@ -1,5 +1,6 @@
1#include "human_processor.h" 1#include "human_processor.h"
2 2
3#include <fmt/core.h>
3#include <google/protobuf/message.h> 4#include <google/protobuf/message.h>
4#include <google/protobuf/text_format.h> 5#include <google/protobuf/text_format.h>
5 6
@@ -12,6 +13,7 @@
12#include <string> 13#include <string>
13 14
14#include "structs.h" 15#include "structs.h"
16#include "util/ids_yaml_format.h"
15 17
16namespace com::fourisland::lingo2_archipelago { 18namespace com::fourisland::lingo2_archipelago {
17namespace { 19namespace {
@@ -40,7 +42,9 @@ class HumanProcessor {
40 42
41 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
42 ProcessMaps(datadir_path); 44 ProcessMaps(datadir_path);
43 ProcessIdsFile(datadir_path / "ids.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
44 } 48 }
45 49
46 private: 50 private:
@@ -70,9 +74,35 @@ class HumanProcessor {
70 MapInfo& map_info = info_.maps[current_map_name]; 74 MapInfo& map_info = info_.maps[current_map_name];
71 75
72 auto metadata = ReadMessageFromFile<HumanMap>(path.string()); 76 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
77 map_info.definitions.push_back(metadata);
78
73 for (const std::string& path : metadata.excluded_nodes()) { 79 for (const std::string& path : metadata.excluded_nodes()) {
74 map_info.game_nodes[path].uses++; 80 map_info.game_nodes[path].uses++;
75 } 81 }
82
83 for (const std::string& path : metadata.custom_nodes()) {
84 map_info.game_nodes[path].defined = true;
85 }
86
87 if (metadata.has_worldport_entrance()) {
88 auto port_identifier = GetCompletePortIdentifier(
89 metadata.worldport_entrance(), current_map_name, std::nullopt);
90 if (port_identifier) {
91 PortInfo& port_info = info_.ports[*port_identifier];
92 port_info.map_worldport_entrances.push_back(current_map_name);
93 } else {
94 map_info.malformed_worldport_entrance = metadata.worldport_entrance();
95 }
96 }
97
98 if (metadata.has_rte_room()) {
99 RoomIdentifier room_identifier;
100 room_identifier.set_map(current_map_name);
101 room_identifier.set_name(metadata.rte_room());
102
103 RoomInfo& room_info = info_.rooms[room_identifier];
104 room_info.map_rtes_referenced_by.push_back(current_map_name);
105 }
76 } 106 }
77 107
78 void ProcessRooms(std::filesystem::path path, 108 void ProcessRooms(std::filesystem::path path,
@@ -93,7 +123,7 @@ class HumanProcessor {
93 room_info.definitions.push_back(h_room); 123 room_info.definitions.push_back(h_room);
94 124
95 for (const HumanPanel& h_panel : h_room.panels()) { 125 for (const HumanPanel& h_panel : h_room.panels()) {
96 ProcessPanel(h_panel, current_map_name, h_room.name()); 126 ProcessPanel(h_panel, current_map_name, h_room);
97 } 127 }
98 128
99 for (const HumanPainting& h_painting : h_room.paintings()) { 129 for (const HumanPainting& h_painting : h_room.paintings()) {
@@ -123,15 +153,14 @@ class HumanProcessor {
123 153
124 void ProcessPanel(const HumanPanel& h_panel, 154 void ProcessPanel(const HumanPanel& h_panel,
125 const std::string& current_map_name, 155 const std::string& current_map_name,
126 const std::string& current_room_name) { 156 const HumanRoom& h_room) {
127 PanelIdentifier panel_identifier; 157 PanelIdentifier panel_identifier;
128 panel_identifier.set_map(current_map_name); 158 panel_identifier.set_map(current_map_name);
129 panel_identifier.set_room(current_room_name); 159 panel_identifier.set_room(h_room.name());
130 panel_identifier.set_name(h_panel.name()); 160 panel_identifier.set_name(h_panel.name());
131 161
132 PanelInfo& panel_info = info_.panels[panel_identifier]; 162 PanelInfo& panel_info = info_.panels[panel_identifier];
133 panel_info.definitions.push_back(h_panel); 163 panel_info.definitions.push_back(h_panel);
134 panel_info.proxies[h_panel.answer()].definitions.push_back(Proxy());
135 164
136 MapInfo& map_info = info_.maps[current_map_name]; 165 MapInfo& map_info = info_.maps[current_map_name];
137 map_info.game_nodes[h_panel.path()].uses++; 166 map_info.game_nodes[h_panel.path()].uses++;
@@ -156,6 +185,24 @@ class HumanProcessor {
156 RoomInfo& required_room_info = info_.rooms[required_room_identifier]; 185 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
157 required_room_info.panels_referenced_by.push_back(panel_identifier); 186 required_room_info.panels_referenced_by.push_back(panel_identifier);
158 } 187 }
188
189 std::string map_area_name = current_map_name;
190 if (h_room.has_panel_display_name()) {
191 map_area_name =
192 fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
193 }
194
195 panel_info.map_area_name = map_area_name;
196
197 std::string panelsanity_name;
198 if (h_panel.has_display_name()) {
199 panelsanity_name =
200 fmt::format("{} - {}", map_area_name, h_panel.display_name());
201 } else {
202 panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
203 }
204 info_.panel_names[panelsanity_name].panels_used_by.push_back(
205 panel_identifier);
159 } 206 }
160 207
161 void ProcessPainting(const HumanPainting& h_painting, 208 void ProcessPainting(const HumanPainting& h_painting,
@@ -337,11 +384,6 @@ class HumanProcessor {
337 DoorInfo& other_door_info = info_.doors[complete_door_identifier]; 384 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
338 other_door_info.doors_referenced_by.push_back(door_identifier); 385 other_door_info.doors_referenced_by.push_back(door_identifier);
339 } 386 }
340
341 for (const std::string& ei : h_door.endings()) {
342 EndingInfo& ending_info = info_.endings[ei];
343 ending_info.doors_referenced_by.push_back(door_identifier);
344 }
345 } 387 }
346 388
347 void ProcessConnectionsFile(std::filesystem::path path, 389 void ProcessConnectionsFile(std::filesystem::path path,
@@ -373,7 +415,9 @@ class HumanProcessor {
373 } 415 }
374 } else if (human_connection.has_from()) { 416 } else if (human_connection.has_from()) {
375 ProcessSingleConnection(human_connection, human_connection.from(), 417 ProcessSingleConnection(human_connection, human_connection.from(),
376 current_map_name); 418 current_map_name,
419 /*is_target=*/!human_connection.oneway() &&
420 !human_connection.bypass_target_door());
377 } 421 }
378 422
379 if (human_connection.has_to_room()) { 423 if (human_connection.has_to_room()) {
@@ -389,8 +433,9 @@ class HumanProcessor {
389 std::cout << "A global connection used to_room." << std::endl; 433 std::cout << "A global connection used to_room." << std::endl;
390 } 434 }
391 } else if (human_connection.has_to()) { 435 } else if (human_connection.has_to()) {
392 ProcessSingleConnection(human_connection, human_connection.to(), 436 ProcessSingleConnection(
393 current_map_name); 437 human_connection, human_connection.to(), current_map_name,
438 /*is_target=*/!human_connection.bypass_target_door());
394 } 439 }
395 440
396 if (human_connection.has_door()) { 441 if (human_connection.has_door()) {
@@ -411,7 +456,7 @@ class HumanProcessor {
411 void ProcessSingleConnection( 456 void ProcessSingleConnection(
412 const HumanConnection& human_connection, 457 const HumanConnection& human_connection,
413 const HumanConnection::Endpoint& endpoint, 458 const HumanConnection::Endpoint& endpoint,
414 const std::optional<std::string>& current_map_name) { 459 const std::optional<std::string>& current_map_name, bool is_target) {
415 if (endpoint.has_room()) { 460 if (endpoint.has_room()) {
416 auto room_identifier = 461 auto room_identifier =
417 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 462 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -430,6 +475,11 @@ class HumanProcessor {
430 if (painting_identifier) { 475 if (painting_identifier) {
431 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 476 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
432 painting_info.connections_referenced_by.push_back(human_connection); 477 painting_info.connections_referenced_by.push_back(human_connection);
478
479 if (is_target) {
480 painting_info.target_connections_referenced_by.push_back(
481 human_connection);
482 }
433 } else { 483 } else {
434 // Not sure where else to store this right now. 484 // Not sure where else to store this right now.
435 std::cout 485 std::cout
@@ -442,6 +492,11 @@ class HumanProcessor {
442 if (port_identifier) { 492 if (port_identifier) {
443 PortInfo& port_info = info_.ports[*port_identifier]; 493 PortInfo& port_info = info_.ports[*port_identifier];
444 port_info.connections_referenced_by.push_back(human_connection); 494 port_info.connections_referenced_by.push_back(human_connection);
495
496 if (is_target) {
497 port_info.target_connections_referenced_by.push_back(
498 human_connection);
499 }
445 } else { 500 } else {
446 // Not sure where else to store this right now. 501 // Not sure where else to store this right now.
447 std::cout 502 std::cout
@@ -459,12 +514,152 @@ class HumanProcessor {
459 panel_info.proxies[endpoint.panel().answer()] 514 panel_info.proxies[endpoint.panel().answer()]
460 .connections_referenced_by.push_back(human_connection); 515 .connections_referenced_by.push_back(human_connection);
461 } 516 }
517
518 if (is_target) {
519 panel_info.target_connections_referenced_by.push_back(
520 human_connection);
521 }
462 } 522 }
463 } 523 }
464 } 524 }
465 525
526 void ProcessProgressivesFile(std::filesystem::path path) {
527 if (!std::filesystem::exists(path)) {
528 return;
529 }
530
531 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
532
533 for (const HumanProgressive& h_prog : h_progs.progressives()) {
534 ProcessProgressive(h_prog);
535 }
536 }
537
538 void ProcessProgressive(const HumanProgressive& h_prog) {
539 ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
540 prog_info.definitions.push_back(h_prog);
541
542 for (const DoorIdentifier& di : h_prog.doors()) {
543 if (!di.has_map()) {
544 prog_info.malformed_doors.push_back(di);
545 continue;
546 }
547
548 DoorInfo& door_info = info_.doors[di];
549 door_info.progressives_referenced_by.push_back(h_prog.name());
550 }
551 }
552
553 void ProcessDoorGroupsFile(std::filesystem::path path) {
554 if (!std::filesystem::exists(path)) {
555 return;
556 }
557
558 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
559
560 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
561 ProcessDoorGroup(h_group);
562 }
563 }
564
565 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
566 DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
567 group_info.definitions.push_back(h_group);
568
569 for (const DoorIdentifier& di : h_group.doors()) {
570 if (!di.has_map()) {
571 group_info.malformed_doors.push_back(di);
572 continue;
573 }
574
575 DoorInfo& door_info = info_.doors[di];
576 door_info.door_groups_referenced_by.push_back(h_group.name());
577 }
578 }
579
466 void ProcessIdsFile(std::filesystem::path path) { 580 void ProcessIdsFile(std::filesystem::path path) {
467 // Ignore this for now. 581 auto ids = ReadIdsFromYaml(path.string());
582
583 DoorIdentifier di;
584 PanelIdentifier pai;
585 PortIdentifier poi;
586 KeyholderIdentifier ki;
587
588 for (const auto& [map_name, map] : ids.maps()) {
589 di.set_map(map_name);
590 pai.set_map(map_name);
591 poi.set_map(map_name);
592 ki.set_map(map_name);
593
594 for (const auto& [door_name, ap_id] : map.doors()) {
595 di.set_name(door_name);
596
597 DoorInfo& door_info = info_.doors[di];
598 door_info.has_id = true;
599 }
600
601 for (const auto& [room_name, room] : map.rooms()) {
602 pai.set_room(room_name);
603 poi.set_room(room_name);
604 ki.set_room(room_name);
605
606 for (const auto& [panel_name, ap_id] : room.panels()) {
607 pai.set_name(panel_name);
608
609 PanelInfo& panel_info = info_.panels[pai];
610 panel_info.has_id = true;
611 }
612
613 for (const auto& [mastery_name, ap_id] : room.masteries()) {
614 // TODO: Mastery
615 }
616
617 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
618 ki.set_name(keyholder_name);
619
620 KeyholderInfo& keyholder_info = info_.keyholders[ki];
621 keyholder_info.has_id = true;
622 }
623
624 for (const auto& [port_name, ap_id] : room.ports()) {
625 poi.set_name(port_name);
626
627 PortInfo& port_info = info_.ports[poi];
628 port_info.has_id = true;
629 }
630 }
631
632 if (map.has_rte()) {
633 MapInfo& map_info = info_.maps[map_name];
634 map_info.has_rte_id = true;
635 }
636 }
637
638 for (const auto& [tag, id] : ids.special()) {
639 // TODO: Specials
640 }
641
642 for (const auto& [letter_name, ap_id] : ids.letters()) {
643 LetterIdentifier li =
644 std::make_tuple(letter_name[0], letter_name[1] == '2');
645 LetterInfo& letter_info = info_.letters[li];
646 letter_info.has_id = true;
647 }
648
649 for (const auto& [ending_name, ap_id] : ids.endings()) {
650 EndingInfo& ending_info = info_.endings[ending_name];
651 ending_info.has_id = true;
652 }
653
654 for (const auto& [prog_name, ap_id] : ids.progressives()) {
655 ProgressiveInfo& prog_info = info_.progressives[prog_name];
656 prog_info.has_id = true;
657 }
658
659 for (const auto& [group_name, ap_id] : ids.door_groups()) {
660 DoorGroupInfo& group_info = info_.door_groups[group_name];
661 group_info.has_id = true;
662 }
468 } 663 }
469 664
470 std::string mapdir_; 665 std::string mapdir_;