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.cpp208
1 files changed, 194 insertions, 14 deletions
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index fb06d31..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:
@@ -73,6 +77,21 @@ class HumanProcessor {
73 for (const std::string& path : metadata.excluded_nodes()) { 77 for (const std::string& path : metadata.excluded_nodes()) {
74 map_info.game_nodes[path].uses++; 78 map_info.game_nodes[path].uses++;
75 } 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 }
76 } 95 }
77 96
78 void ProcessRooms(std::filesystem::path path, 97 void ProcessRooms(std::filesystem::path path,
@@ -93,7 +112,7 @@ class HumanProcessor {
93 room_info.definitions.push_back(h_room); 112 room_info.definitions.push_back(h_room);
94 113
95 for (const HumanPanel& h_panel : h_room.panels()) { 114 for (const HumanPanel& h_panel : h_room.panels()) {
96 ProcessPanel(h_panel, current_map_name, h_room.name()); 115 ProcessPanel(h_panel, current_map_name, h_room);
97 } 116 }
98 117
99 for (const HumanPainting& h_painting : h_room.paintings()) { 118 for (const HumanPainting& h_painting : h_room.paintings()) {
@@ -123,10 +142,10 @@ class HumanProcessor {
123 142
124 void ProcessPanel(const HumanPanel& h_panel, 143 void ProcessPanel(const HumanPanel& h_panel,
125 const std::string& current_map_name, 144 const std::string& current_map_name,
126 const std::string& current_room_name) { 145 const HumanRoom& h_room) {
127 PanelIdentifier panel_identifier; 146 PanelIdentifier panel_identifier;
128 panel_identifier.set_map(current_map_name); 147 panel_identifier.set_map(current_map_name);
129 panel_identifier.set_room(current_room_name); 148 panel_identifier.set_room(h_room.name());
130 panel_identifier.set_name(h_panel.name()); 149 panel_identifier.set_name(h_panel.name());
131 150
132 PanelInfo& panel_info = info_.panels[panel_identifier]; 151 PanelInfo& panel_info = info_.panels[panel_identifier];
@@ -155,6 +174,24 @@ class HumanProcessor {
155 RoomInfo& required_room_info = info_.rooms[required_room_identifier]; 174 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
156 required_room_info.panels_referenced_by.push_back(panel_identifier); 175 required_room_info.panels_referenced_by.push_back(panel_identifier);
157 } 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);
158 } 195 }
159 196
160 void ProcessPainting(const HumanPainting& h_painting, 197 void ProcessPainting(const HumanPainting& h_painting,
@@ -336,11 +373,6 @@ class HumanProcessor {
336 DoorInfo& other_door_info = info_.doors[complete_door_identifier]; 373 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
337 other_door_info.doors_referenced_by.push_back(door_identifier); 374 other_door_info.doors_referenced_by.push_back(door_identifier);
338 } 375 }
339
340 for (const std::string& ei : h_door.endings()) {
341 EndingInfo& ending_info = info_.endings[ei];
342 ending_info.doors_referenced_by.push_back(door_identifier);
343 }
344 } 376 }
345 377
346 void ProcessConnectionsFile(std::filesystem::path path, 378 void ProcessConnectionsFile(std::filesystem::path path,
@@ -372,7 +404,9 @@ class HumanProcessor {
372 } 404 }
373 } else if (human_connection.has_from()) { 405 } else if (human_connection.has_from()) {
374 ProcessSingleConnection(human_connection, human_connection.from(), 406 ProcessSingleConnection(human_connection, human_connection.from(),
375 current_map_name); 407 current_map_name,
408 /*is_target=*/!human_connection.oneway() &&
409 !human_connection.bypass_target_door());
376 } 410 }
377 411
378 if (human_connection.has_to_room()) { 412 if (human_connection.has_to_room()) {
@@ -388,8 +422,9 @@ class HumanProcessor {
388 std::cout << "A global connection used to_room." << std::endl; 422 std::cout << "A global connection used to_room." << std::endl;
389 } 423 }
390 } else if (human_connection.has_to()) { 424 } else if (human_connection.has_to()) {
391 ProcessSingleConnection(human_connection, human_connection.to(), 425 ProcessSingleConnection(
392 current_map_name); 426 human_connection, human_connection.to(), current_map_name,
427 /*is_target=*/!human_connection.bypass_target_door());
393 } 428 }
394 429
395 if (human_connection.has_door()) { 430 if (human_connection.has_door()) {
@@ -410,7 +445,7 @@ class HumanProcessor {
410 void ProcessSingleConnection( 445 void ProcessSingleConnection(
411 const HumanConnection& human_connection, 446 const HumanConnection& human_connection,
412 const HumanConnection::Endpoint& endpoint, 447 const HumanConnection::Endpoint& endpoint,
413 const std::optional<std::string>& current_map_name) { 448 const std::optional<std::string>& current_map_name, bool is_target) {
414 if (endpoint.has_room()) { 449 if (endpoint.has_room()) {
415 auto room_identifier = 450 auto room_identifier =
416 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 451 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -429,6 +464,11 @@ class HumanProcessor {
429 if (painting_identifier) { 464 if (painting_identifier) {
430 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 465 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
431 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 }
432 } else { 472 } else {
433 // Not sure where else to store this right now. 473 // Not sure where else to store this right now.
434 std::cout 474 std::cout
@@ -441,6 +481,11 @@ class HumanProcessor {
441 if (port_identifier) { 481 if (port_identifier) {
442 PortInfo& port_info = info_.ports[*port_identifier]; 482 PortInfo& port_info = info_.ports[*port_identifier];
443 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 }
444 } else { 489 } else {
445 // Not sure where else to store this right now. 490 // Not sure where else to store this right now.
446 std::cout 491 std::cout
@@ -458,12 +503,147 @@ class HumanProcessor {
458 panel_info.proxies[endpoint.panel().answer()] 503 panel_info.proxies[endpoint.panel().answer()]
459 .connections_referenced_by.push_back(human_connection); 504 .connections_referenced_by.push_back(human_connection);
460 } 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;
461 } 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;
562 }
563
564 DoorInfo& door_info = info_.doors[di];
565 door_info.door_groups_referenced_by.push_back(h_group.name());
462 } 566 }
463 } 567 }
464 568
465 void ProcessIdsFile(std::filesystem::path path) { 569 void ProcessIdsFile(std::filesystem::path path) {
466 // 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 }
467 } 647 }
468 648
469 std::string mapdir_; 649 std::string mapdir_;