diff options
Diffstat (limited to 'tools/validator/human_processor.cpp')
| -rw-r--r-- | tools/validator/human_processor.cpp | 179 |
1 files changed, 169 insertions, 10 deletions
| diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index f53dc79..2c978bf 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 | ||
| 16 | namespace com::fourisland::lingo2_archipelago { | 18 | namespace com::fourisland::lingo2_archipelago { |
| 17 | namespace { | 19 | namespace { |
| @@ -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: |
| @@ -93,7 +97,7 @@ class HumanProcessor { | |||
| 93 | room_info.definitions.push_back(h_room); | 97 | room_info.definitions.push_back(h_room); |
| 94 | 98 | ||
| 95 | for (const HumanPanel& h_panel : h_room.panels()) { | 99 | for (const HumanPanel& h_panel : h_room.panels()) { |
| 96 | ProcessPanel(h_panel, current_map_name, h_room.name()); | 100 | ProcessPanel(h_panel, current_map_name, h_room); |
| 97 | } | 101 | } |
| 98 | 102 | ||
| 99 | for (const HumanPainting& h_painting : h_room.paintings()) { | 103 | for (const HumanPainting& h_painting : h_room.paintings()) { |
| @@ -123,15 +127,14 @@ class HumanProcessor { | |||
| 123 | 127 | ||
| 124 | void ProcessPanel(const HumanPanel& h_panel, | 128 | void ProcessPanel(const HumanPanel& h_panel, |
| 125 | const std::string& current_map_name, | 129 | const std::string& current_map_name, |
| 126 | const std::string& current_room_name) { | 130 | const HumanRoom& h_room) { |
| 127 | PanelIdentifier panel_identifier; | 131 | PanelIdentifier panel_identifier; |
| 128 | panel_identifier.set_map(current_map_name); | 132 | panel_identifier.set_map(current_map_name); |
| 129 | panel_identifier.set_room(current_room_name); | 133 | panel_identifier.set_room(h_room.name()); |
| 130 | panel_identifier.set_name(h_panel.name()); | 134 | panel_identifier.set_name(h_panel.name()); |
| 131 | 135 | ||
| 132 | PanelInfo& panel_info = info_.panels[panel_identifier]; | 136 | PanelInfo& panel_info = info_.panels[panel_identifier]; |
| 133 | panel_info.definitions.push_back(h_panel); | 137 | panel_info.definitions.push_back(h_panel); |
| 134 | panel_info.proxies[h_panel.answer()].definitions.push_back(Proxy()); | ||
| 135 | 138 | ||
| 136 | MapInfo& map_info = info_.maps[current_map_name]; | 139 | MapInfo& map_info = info_.maps[current_map_name]; |
| 137 | map_info.game_nodes[h_panel.path()].uses++; | 140 | map_info.game_nodes[h_panel.path()].uses++; |
| @@ -156,6 +159,24 @@ class HumanProcessor { | |||
| 156 | RoomInfo& required_room_info = info_.rooms[required_room_identifier]; | 159 | RoomInfo& required_room_info = info_.rooms[required_room_identifier]; |
| 157 | required_room_info.panels_referenced_by.push_back(panel_identifier); | 160 | required_room_info.panels_referenced_by.push_back(panel_identifier); |
| 158 | } | 161 | } |
| 162 | |||
| 163 | std::string map_area_name = current_map_name; | ||
| 164 | if (h_room.has_panel_display_name()) { | ||
| 165 | map_area_name = | ||
| 166 | fmt::format("{} ({})", current_map_name, h_room.panel_display_name()); | ||
| 167 | } | ||
| 168 | |||
| 169 | panel_info.map_area_name = map_area_name; | ||
| 170 | |||
| 171 | std::string panelsanity_name; | ||
| 172 | if (h_panel.has_display_name()) { | ||
| 173 | panelsanity_name = | ||
| 174 | fmt::format("{} - {}", map_area_name, h_panel.display_name()); | ||
| 175 | } else { | ||
| 176 | panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name()); | ||
| 177 | } | ||
| 178 | info_.panel_names[panelsanity_name].panels_used_by.push_back( | ||
| 179 | panel_identifier); | ||
| 159 | } | 180 | } |
| 160 | 181 | ||
| 161 | void ProcessPainting(const HumanPainting& h_painting, | 182 | void ProcessPainting(const HumanPainting& h_painting, |
| @@ -373,7 +394,9 @@ class HumanProcessor { | |||
| 373 | } | 394 | } |
| 374 | } else if (human_connection.has_from()) { | 395 | } else if (human_connection.has_from()) { |
| 375 | ProcessSingleConnection(human_connection, human_connection.from(), | 396 | ProcessSingleConnection(human_connection, human_connection.from(), |
| 376 | current_map_name); | 397 | current_map_name, |
| 398 | /*is_target=*/!human_connection.oneway() && | ||
| 399 | !human_connection.bypass_target_door()); | ||
| 377 | } | 400 | } |
| 378 | 401 | ||
| 379 | if (human_connection.has_to_room()) { | 402 | if (human_connection.has_to_room()) { |
| @@ -389,8 +412,9 @@ class HumanProcessor { | |||
| 389 | std::cout << "A global connection used to_room." << std::endl; | 412 | std::cout << "A global connection used to_room." << std::endl; |
| 390 | } | 413 | } |
| 391 | } else if (human_connection.has_to()) { | 414 | } else if (human_connection.has_to()) { |
| 392 | ProcessSingleConnection(human_connection, human_connection.to(), | 415 | ProcessSingleConnection( |
| 393 | current_map_name); | 416 | human_connection, human_connection.to(), current_map_name, |
| 417 | /*is_target=*/!human_connection.bypass_target_door()); | ||
| 394 | } | 418 | } |
| 395 | 419 | ||
| 396 | if (human_connection.has_door()) { | 420 | if (human_connection.has_door()) { |
| @@ -411,7 +435,7 @@ class HumanProcessor { | |||
| 411 | void ProcessSingleConnection( | 435 | void ProcessSingleConnection( |
| 412 | const HumanConnection& human_connection, | 436 | const HumanConnection& human_connection, |
| 413 | const HumanConnection::Endpoint& endpoint, | 437 | const HumanConnection::Endpoint& endpoint, |
| 414 | const std::optional<std::string>& current_map_name) { | 438 | const std::optional<std::string>& current_map_name, bool is_target) { |
| 415 | if (endpoint.has_room()) { | 439 | if (endpoint.has_room()) { |
| 416 | auto room_identifier = | 440 | auto room_identifier = |
| 417 | GetCompleteRoomIdentifier(endpoint.room(), current_map_name); | 441 | GetCompleteRoomIdentifier(endpoint.room(), current_map_name); |
| @@ -430,6 +454,11 @@ class HumanProcessor { | |||
| 430 | if (painting_identifier) { | 454 | if (painting_identifier) { |
| 431 | PaintingInfo& painting_info = info_.paintings[*painting_identifier]; | 455 | PaintingInfo& painting_info = info_.paintings[*painting_identifier]; |
| 432 | 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 | } | ||
| 433 | } else { | 462 | } else { |
| 434 | // Not sure where else to store this right now. | 463 | // Not sure where else to store this right now. |
| 435 | std::cout | 464 | std::cout |
| @@ -442,6 +471,11 @@ class HumanProcessor { | |||
| 442 | if (port_identifier) { | 471 | if (port_identifier) { |
| 443 | PortInfo& port_info = info_.ports[*port_identifier]; | 472 | PortInfo& port_info = info_.ports[*port_identifier]; |
| 444 | 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 | } | ||
| 445 | } else { | 479 | } else { |
| 446 | // Not sure where else to store this right now. | 480 | // Not sure where else to store this right now. |
| 447 | std::cout | 481 | std::cout |
| @@ -459,12 +493,137 @@ class HumanProcessor { | |||
| 459 | panel_info.proxies[endpoint.panel().answer()] | 493 | panel_info.proxies[endpoint.panel().answer()] |
| 460 | .connections_referenced_by.push_back(human_connection); | 494 | .connections_referenced_by.push_back(human_connection); |
| 461 | } | 495 | } |
| 496 | |||
| 497 | if (is_target) { | ||
| 498 | panel_info.target_connections_referenced_by.push_back( | ||
| 499 | human_connection); | ||
| 500 | } | ||
| 462 | } | 501 | } |
| 463 | } | 502 | } |
| 464 | } | 503 | } |
| 465 | 504 | ||
| 505 | void ProcessProgressivesFile(std::filesystem::path path) { | ||
| 506 | if (!std::filesystem::exists(path)) { | ||
| 507 | return; | ||
| 508 | } | ||
| 509 | |||
| 510 | auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string()); | ||
| 511 | |||
| 512 | for (const HumanProgressive& h_prog : h_progs.progressives()) { | ||
| 513 | ProcessProgressive(h_prog); | ||
| 514 | } | ||
| 515 | } | ||
| 516 | |||
| 517 | void ProcessProgressive(const HumanProgressive& h_prog) { | ||
| 518 | ProgressiveInfo& prog_info = info_.progressives[h_prog.name()]; | ||
| 519 | prog_info.definitions.push_back(h_prog); | ||
| 520 | |||
| 521 | for (const DoorIdentifier& di : h_prog.doors()) { | ||
| 522 | if (!di.has_map()) { | ||
| 523 | prog_info.malformed_doors.push_back(di); | ||
| 524 | continue; | ||
| 525 | } | ||
| 526 | |||
| 527 | DoorInfo& door_info = info_.doors[di]; | ||
| 528 | door_info.progressives_referenced_by.push_back(h_prog.name()); | ||
| 529 | } | ||
| 530 | } | ||
| 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 | |||
| 466 | void ProcessIdsFile(std::filesystem::path path) { | 559 | void ProcessIdsFile(std::filesystem::path path) { |
| 467 | // Ignore this for now. | 560 | auto ids = ReadIdsFromYaml(path.string()); |
| 561 | |||
| 562 | DoorIdentifier di; | ||
| 563 | PanelIdentifier pi; | ||
| 564 | KeyholderIdentifier ki; | ||
| 565 | |||
| 566 | for (const auto& [map_name, map] : ids.maps()) { | ||
| 567 | di.set_map(map_name); | ||
| 568 | pi.set_map(map_name); | ||
| 569 | ki.set_map(map_name); | ||
| 570 | |||
| 571 | for (const auto& [door_name, ap_id] : map.doors()) { | ||
| 572 | di.set_name(door_name); | ||
| 573 | |||
| 574 | DoorInfo& door_info = info_.doors[di]; | ||
| 575 | door_info.has_id = true; | ||
| 576 | } | ||
| 577 | |||
| 578 | for (const auto& [room_name, room] : map.rooms()) { | ||
| 579 | pi.set_room(room_name); | ||
| 580 | ki.set_room(room_name); | ||
| 581 | |||
| 582 | for (const auto& [panel_name, ap_id] : room.panels()) { | ||
| 583 | pi.set_name(panel_name); | ||
| 584 | |||
| 585 | PanelInfo& panel_info = info_.panels[pi]; | ||
| 586 | panel_info.has_id = true; | ||
| 587 | } | ||
| 588 | |||
| 589 | for (const auto& [mastery_name, ap_id] : room.masteries()) { | ||
| 590 | // TODO: Mastery | ||
| 591 | } | ||
| 592 | |||
| 593 | for (const auto& [keyholder_name, ap_id] : room.keyholders()) { | ||
| 594 | ki.set_name(keyholder_name); | ||
| 595 | |||
| 596 | KeyholderInfo& keyholder_info = info_.keyholders[ki]; | ||
| 597 | keyholder_info.has_id = true; | ||
| 598 | } | ||
| 599 | } | ||
| 600 | } | ||
| 601 | |||
| 602 | for (const auto& [tag, id] : ids.special()) { | ||
| 603 | // TODO: Specials | ||
| 604 | } | ||
| 605 | |||
| 606 | for (const auto& [letter_name, ap_id] : ids.letters()) { | ||
| 607 | LetterIdentifier li = | ||
| 608 | std::make_tuple(letter_name[0], letter_name[1] == '2'); | ||
| 609 | LetterInfo& letter_info = info_.letters[li]; | ||
| 610 | letter_info.has_id = true; | ||
| 611 | } | ||
| 612 | |||
| 613 | for (const auto& [ending_name, ap_id] : ids.endings()) { | ||
| 614 | EndingInfo& ending_info = info_.endings[ending_name]; | ||
| 615 | ending_info.has_id = true; | ||
| 616 | } | ||
| 617 | |||
| 618 | for (const auto& [prog_name, ap_id] : ids.progressives()) { | ||
| 619 | ProgressiveInfo& prog_info = info_.progressives[prog_name]; | ||
| 620 | prog_info.has_id = true; | ||
| 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 | } | ||
| 468 | } | 627 | } |
| 469 | 628 | ||
| 470 | std::string mapdir_; | 629 | std::string mapdir_; |
