diff options
Diffstat (limited to 'tools/validator/human_processor.cpp')
| -rw-r--r-- | tools/validator/human_processor.cpp | 199 |
1 files changed, 188 insertions, 11 deletions
| diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 0f63936..d6fcfa6 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 | ||
| 17 | namespace com::fourisland::lingo2_archipelago { | 18 | namespace com::fourisland::lingo2_archipelago { |
| 18 | namespace { | 19 | namespace { |
| @@ -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: |
| @@ -71,9 +74,35 @@ class HumanProcessor { | |||
| 71 | MapInfo& map_info = info_.maps[current_map_name]; | 74 | MapInfo& map_info = info_.maps[current_map_name]; |
| 72 | 75 | ||
| 73 | auto metadata = ReadMessageFromFile<HumanMap>(path.string()); | 76 | auto metadata = ReadMessageFromFile<HumanMap>(path.string()); |
| 77 | map_info.definitions.push_back(metadata); | ||
| 78 | |||
| 74 | for (const std::string& path : metadata.excluded_nodes()) { | 79 | for (const std::string& path : metadata.excluded_nodes()) { |
| 75 | map_info.game_nodes[path].uses++; | 80 | map_info.game_nodes[path].uses++; |
| 76 | } | 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 | } | ||
| 77 | } | 106 | } |
| 78 | 107 | ||
| 79 | void ProcessRooms(std::filesystem::path path, | 108 | void ProcessRooms(std::filesystem::path path, |
| @@ -355,11 +384,6 @@ class HumanProcessor { | |||
| 355 | DoorInfo& other_door_info = info_.doors[complete_door_identifier]; | 384 | DoorInfo& other_door_info = info_.doors[complete_door_identifier]; |
| 356 | other_door_info.doors_referenced_by.push_back(door_identifier); | 385 | other_door_info.doors_referenced_by.push_back(door_identifier); |
| 357 | } | 386 | } |
| 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 | } | 387 | } |
| 364 | 388 | ||
| 365 | void ProcessConnectionsFile(std::filesystem::path path, | 389 | void ProcessConnectionsFile(std::filesystem::path path, |
| @@ -391,7 +415,9 @@ class HumanProcessor { | |||
| 391 | } | 415 | } |
| 392 | } else if (human_connection.has_from()) { | 416 | } else if (human_connection.has_from()) { |
| 393 | ProcessSingleConnection(human_connection, human_connection.from(), | 417 | ProcessSingleConnection(human_connection, human_connection.from(), |
| 394 | current_map_name); | 418 | current_map_name, |
| 419 | /*is_target=*/!human_connection.oneway() && | ||
| 420 | !human_connection.bypass_target_door()); | ||
| 395 | } | 421 | } |
| 396 | 422 | ||
| 397 | if (human_connection.has_to_room()) { | 423 | if (human_connection.has_to_room()) { |
| @@ -407,8 +433,9 @@ class HumanProcessor { | |||
| 407 | std::cout << "A global connection used to_room." << std::endl; | 433 | std::cout << "A global connection used to_room." << std::endl; |
| 408 | } | 434 | } |
| 409 | } else if (human_connection.has_to()) { | 435 | } else if (human_connection.has_to()) { |
| 410 | ProcessSingleConnection(human_connection, human_connection.to(), | 436 | ProcessSingleConnection( |
| 411 | current_map_name); | 437 | human_connection, human_connection.to(), current_map_name, |
| 438 | /*is_target=*/!human_connection.bypass_target_door()); | ||
| 412 | } | 439 | } |
| 413 | 440 | ||
| 414 | if (human_connection.has_door()) { | 441 | if (human_connection.has_door()) { |
| @@ -429,7 +456,7 @@ class HumanProcessor { | |||
| 429 | void ProcessSingleConnection( | 456 | void ProcessSingleConnection( |
| 430 | const HumanConnection& human_connection, | 457 | const HumanConnection& human_connection, |
| 431 | const HumanConnection::Endpoint& endpoint, | 458 | const HumanConnection::Endpoint& endpoint, |
| 432 | const std::optional<std::string>& current_map_name) { | 459 | const std::optional<std::string>& current_map_name, bool is_target) { |
| 433 | if (endpoint.has_room()) { | 460 | if (endpoint.has_room()) { |
| 434 | auto room_identifier = | 461 | auto room_identifier = |
| 435 | GetCompleteRoomIdentifier(endpoint.room(), current_map_name); | 462 | GetCompleteRoomIdentifier(endpoint.room(), current_map_name); |
| @@ -448,6 +475,11 @@ class HumanProcessor { | |||
| 448 | if (painting_identifier) { | 475 | if (painting_identifier) { |
| 449 | PaintingInfo& painting_info = info_.paintings[*painting_identifier]; | 476 | PaintingInfo& painting_info = info_.paintings[*painting_identifier]; |
| 450 | 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 | } | ||
| 451 | } else { | 483 | } else { |
| 452 | // Not sure where else to store this right now. | 484 | // Not sure where else to store this right now. |
| 453 | std::cout | 485 | std::cout |
| @@ -460,6 +492,11 @@ class HumanProcessor { | |||
| 460 | if (port_identifier) { | 492 | if (port_identifier) { |
| 461 | PortInfo& port_info = info_.ports[*port_identifier]; | 493 | PortInfo& port_info = info_.ports[*port_identifier]; |
| 462 | 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 | } | ||
| 463 | } else { | 500 | } else { |
| 464 | // Not sure where else to store this right now. | 501 | // Not sure where else to store this right now. |
| 465 | std::cout | 502 | std::cout |
| @@ -477,12 +514,152 @@ class HumanProcessor { | |||
| 477 | panel_info.proxies[endpoint.panel().answer()] | 514 | panel_info.proxies[endpoint.panel().answer()] |
| 478 | .connections_referenced_by.push_back(human_connection); | 515 | .connections_referenced_by.push_back(human_connection); |
| 479 | } | 516 | } |
| 517 | |||
| 518 | if (is_target) { | ||
| 519 | panel_info.target_connections_referenced_by.push_back( | ||
| 520 | human_connection); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | } | ||
| 524 | } | ||
| 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; | ||
| 480 | } | 573 | } |
| 574 | |||
| 575 | DoorInfo& door_info = info_.doors[di]; | ||
| 576 | door_info.door_groups_referenced_by.push_back(h_group.name()); | ||
| 481 | } | 577 | } |
| 482 | } | 578 | } |
| 483 | 579 | ||
| 484 | void ProcessIdsFile(std::filesystem::path path) { | 580 | void ProcessIdsFile(std::filesystem::path path) { |
| 485 | // 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 | } | ||
| 486 | } | 663 | } |
| 487 | 664 | ||
| 488 | std::string mapdir_; | 665 | std::string mapdir_; |
