#include "validator.h" #include #include "proto/human.pb.h" #include "structs.h" #include "util/identifiers.h" namespace com::fourisland::lingo2_archipelago { namespace { class Validator { public: explicit Validator(const CollectedInfo& info) : info_(info) {} void Validate() const { for (const auto& [map_name, map_info] : info_.maps) { ValidateMap(map_name, map_info); } for (const auto& [room_identifier, room_info] : info_.rooms) { ValidateRoom(room_identifier, room_info); } for (const auto& [door_identifier, door_info] : info_.doors) { ValidateDoor(door_identifier, door_info); } for (const auto& [port_identifier, port_info] : info_.ports) { ValidatePort(port_identifier, port_info); } for (const auto& [painting_identifier, painting_info] : info_.paintings) { ValidatePainting(painting_identifier, painting_info); } for (const auto& [panel_identifier, panel_info] : info_.panels) { ValidatePanel(panel_identifier, panel_info); } for (const auto& [keyholder_identifier, keyholder_info] : info_.keyholders) { ValidateKeyholder(keyholder_identifier, keyholder_info); } for (const auto& [letter_identifier, letter_info] : info_.letters) { ValidateLetter(letter_identifier, letter_info); } for (const auto& [ending_name, ending_info] : info_.endings) { ValidateEnding(ending_name, ending_info); } for (const auto& [panel_name, panel_info] : info_.panel_names) { ValidatePanelName(panel_name, panel_info); } for (const auto& [prog_name, prog_info] : info_.progressives) { ValidateProgressive(prog_name, prog_info); } for (const auto& [group_name, group_info] : info_.door_groups) { ValidateDoorGroup(group_name, group_info); } } private: void ValidateMap(const std::string& map_name, const MapInfo& map_info) const { for (const auto& [node_path, node_info] : map_info.game_nodes) { if (node_info.uses > 1) { std::cout << "Map " << map_name << " node " << node_path << " is used in multiple places." << std::endl; } else if (node_info.uses == 0) { std::cout << "Map " << map_name << " node " << node_path << " is not used." << std::endl; } if (!node_info.defined) { std::cout << "Map " << map_name << " node " << node_path << " is not defined in the game file." << std::endl; } } } void ValidateRoom(const RoomIdentifier& room_identifier, const RoomInfo& room_info) const { if (room_info.definitions.empty()) { std::cout << "Room " << room_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : room_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } for (const PanelIdentifier& panel_identifier : room_info.panels_referenced_by) { std::cout << " PANEL " << panel_identifier.ShortDebugString() << std::endl; } for (const HumanConnection& connection : room_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } } else if (room_info.definitions.size() > 1) { std::cout << "Room " << room_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } } bool DoesDoorNeedLocationName(const HumanDoor& h_door, const std::string& map_name) const { if (h_door.type() != DoorType::STANDARD) { return false; } if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0) { return true; } if (h_door.panels_size() > 4) { return true; } std::set map_areas; for (const PanelIdentifier& pi : h_door.panels()) { auto full_pi = GetCompletePanelIdentifierWithoutAnswer(pi, map_name, std::nullopt); if (full_pi) { auto panel_info_it = info_.panels.find(*full_pi); if (panel_info_it != info_.panels.end()) { const PanelInfo& panel_info = panel_info_it->second; map_areas.insert(panel_info.map_area_name); } } } if (map_areas.size() > 1) { return true; } return false; } void ValidateDoor(const DoorIdentifier& door_identifier, const DoorInfo& door_info) const { if (door_info.definitions.empty()) { std::cout << "Door " << door_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& other_door_identifier : door_info.doors_referenced_by) { std::cout << " DOOR " << other_door_identifier.ShortDebugString() << std::endl; } for (const PanelIdentifier& panel_identifier : door_info.panels_referenced_by) { std::cout << " PANEL " << panel_identifier.ShortDebugString() << std::endl; } for (const PaintingIdentifier& painting_identifier : door_info.paintings_referenced_by) { std::cout << " PAINTING " << painting_identifier.ShortDebugString() << std::endl; } for (const PortIdentifier& port_identifier : door_info.ports_referenced_by) { std::cout << " PORT " << port_identifier.ShortDebugString() << std::endl; } for (const HumanConnection& connection : door_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } for (const std::string& prog_name : door_info.progressives_referenced_by) { std::cout << " PROGRESSIVE " << prog_name << std::endl; } for (const std::string& group_name : door_info.door_groups_referenced_by) { std::cout << " DOOR GROUP " << group_name << std::endl; } if (door_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (door_info.definitions.size() > 1) { std::cout << "Door " << door_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } if (door_info.malformed_identifiers.HasAny()) { std::cout << "Door " << door_identifier.ShortDebugString() << " has malformed identifiers:" << std::endl; for (const PaintingIdentifier& painting_identifier : door_info.malformed_identifiers.paintings) { std::cout << " PAINTING " << painting_identifier.ShortDebugString() << std::endl; } for (const PanelIdentifier& panel_identifier : door_info.malformed_identifiers.panels) { std::cout << " PANEL " << panel_identifier.ShortDebugString() << std::endl; } for (const KeyholderIdentifier& keyholder_identifier : door_info.malformed_identifiers.keyholders) { std::cout << " KEYHOLDER " << keyholder_identifier.ShortDebugString() << std::endl; } } for (const HumanDoor& h_door : door_info.definitions) { if (DoesDoorNeedLocationName(h_door, door_identifier.map()) && !h_door.has_location_name()) { std::cout << "Door " << door_identifier.ShortDebugString() << " needs an explicit location name." << std::endl; } if (h_door.double_letters() && (h_door.type() == DoorType::STANDARD || h_door.type() == DoorType::LOCATION_ONLY || h_door.type() == DoorType::GRAVESTONE)) { std::cout << "Door " << door_identifier.ShortDebugString() << " is a location that depends on double_letters." << std::endl; } bool needs_id = (h_door.type() != DoorType::EVENT); if (door_info.has_id != needs_id) { if (needs_id) { std::cout << "Door " << door_identifier.ShortDebugString() << " is missing an AP ID." << std::endl; } else { std::cout << "Door " << door_identifier.ShortDebugString() << " should not have an AP ID." << std::endl; } } } } void ValidatePort(const PortIdentifier& port_identifier, const PortInfo& port_info) const { if (port_info.definitions.empty()) { std::cout << "Port " << port_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const HumanConnection& connection : port_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } } else if (port_info.definitions.size() > 1) { std::cout << "Port " << port_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } } void ValidatePainting(const PaintingIdentifier& painting_identifier, const PaintingInfo& painting_info) const { if (painting_info.definitions.empty()) { std::cout << "Painting " << painting_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : painting_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } for (const HumanConnection& connection : painting_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } } else if (painting_info.definitions.size() > 1) { std::cout << "Painting " << painting_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } } void ValidatePanel(const PanelIdentifier& panel_identifier, const PanelInfo& panel_info) const { if (panel_identifier.name().empty()) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " has no name." << std::endl; } if (panel_info.definitions.empty()) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : panel_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } for (const HumanConnection& connection : panel_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } if (panel_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (panel_info.definitions.size() > 1) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } for (const auto& [answer, proxy_info] : panel_info.proxies) { if (proxy_info.definitions.empty()) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " with answer \"" << answer << "\" has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : proxy_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } for (const HumanConnection& connection : proxy_info.connections_referenced_by) { std::cout << " CONNECTION " << connection.ShortDebugString() << std::endl; } } else if (proxy_info.definitions.size() > 1) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " with answer \"" << answer << "\" was defined multiple times." << std::endl; } } if (!panel_info.has_id) { std::cout << "Panel " << panel_identifier.ShortDebugString() << " is missing an AP ID." << std::endl; } } void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier, const KeyholderInfo& keyholder_info) const { if (keyholder_info.definitions.empty()) { std::cout << "Keyholder " << keyholder_identifier.ShortDebugString() << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : keyholder_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } if (keyholder_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (keyholder_info.definitions.size() > 1) { std::cout << "Keyholder " << keyholder_identifier.ShortDebugString() << " was defined multiple times." << std::endl; } for (const HumanKeyholder& h_keyholder : keyholder_info.definitions) { bool needs_id = (h_keyholder.has_key()); if (needs_id != keyholder_info.has_id) { if (needs_id) { std::cout << "Keyholder " << keyholder_identifier.ShortDebugString() << " is missing an AP ID." << std::endl; } else { std::cout << "Keyholder " << keyholder_identifier.ShortDebugString() << " should not have an AP ID." << std::endl; } } } } void ValidateLetter(const LetterIdentifier& letter_identifier, const LetterInfo& letter_info) const { std::string letter_name = std::string(1, std::get<0>(letter_identifier)) + (std::get<1>(letter_identifier) ? "2" : "1"); if (letter_info.defined_in.empty()) { std::cout << "Letter " << letter_name << " has no definition, but was referenced:" << std::endl; if (letter_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (letter_info.defined_in.size() > 1) { std::cout << "Letter " << letter_name << " was defined in multiple places:" << std::endl; for (const RoomIdentifier& room_identifier : letter_info.defined_in) { std::cout << " " << room_identifier.ShortDebugString() << std::endl; } } if (!letter_info.has_id) { std::cout << "Letter " << letter_name << " is missing an AP ID." << std::endl; } } void ValidateEnding(const std::string& ending_name, const EndingInfo& ending_info) const { if (ending_info.defined_in.empty()) { std::cout << "Ending " << ending_name << " has no definition, but was referenced:" << std::endl; for (const DoorIdentifier& door_identifier : ending_info.doors_referenced_by) { std::cout << " DOOR " << door_identifier.ShortDebugString() << std::endl; } if (ending_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (ending_info.defined_in.size() > 1) { std::cout << "Ending " << ending_name << " was defined in multiple places:" << std::endl; for (const RoomIdentifier& room_identifier : ending_info.defined_in) { std::cout << " " << room_identifier.ShortDebugString() << std::endl; } } if (!ending_info.has_id) { std::cout << "Ending " << ending_name << " is missing an AP ID." << std::endl; } } void ValidatePanelName(const std::string& panel_name, const PanelNameInfo& panel_info) const { if (panel_info.panels_used_by.size() > 1) { std::cout << "The location name \"" << panel_name << "\" is used by multiple panels:" << std::endl; for (const PanelIdentifier& panel_identifier : panel_info.panels_used_by) { std::cout << " PANEL " << panel_identifier.ShortDebugString() << std::endl; } } } void ValidateProgressive(const std::string& prog_name, const ProgressiveInfo& prog_info) const { if (prog_info.definitions.empty()) { std::cout << "Progressive \"" << prog_name << "\" has no definition, but was referenced:" << std::endl; if (prog_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (prog_info.definitions.size() > 1) { std::cout << "Progressive \"" << prog_name << "\" has multiple definitions." << std::endl; } if (!prog_info.has_id) { std::cout << "Progressive \"" << prog_name << "\" is missing an AP ID." << std::endl; } } void ValidateDoorGroup(const std::string& group_name, const DoorGroupInfo& group_info) const { if (group_info.definitions.empty()) { std::cout << "Door group \"" << group_name << "\" has no definition, but was referenced:" << std::endl; if (group_info.has_id) { std::cout << " An AP ID is present." << std::endl; } } else if (group_info.definitions.size() > 1) { std::cout << "Door group \"" << group_name << "\" has multiple definitions." << std::endl; } if (!group_info.has_id) { std::cout << "Door group \"" << group_name << "\" is missing an AP ID." << std::endl; } } const CollectedInfo& info_; }; } // namespace void ValidateCollectedInfo(const CollectedInfo& info) { Validator validator(info); validator.Validate(); } } // namespace com::fourisland::lingo2_archipelago 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
#include "human_processor.h"

#include <fmt/core.h>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>

#include <filesystem>
#include <fstream>
#include <iostream>
#include <map>
#include <optional>
#include <sstream>
#include <string>

#include "structs.h"
#include "util/ids_yaml_format.h"

namespace com::fourisland::lingo2_archipelago {
namespace {

template <typename T>
T ReadMessageFromFile(const std::string& path) {
  std::cout << "Processing " << path << std::endl;

  std::ifstream file(path);
  std::stringstream buffer;
  buffer << file.rdbuf();

  T message;
  google::protobuf::TextFormat::ParseFromString(buffer.str(), &message);

  return message;
}

class HumanProcessor {
 public:
  HumanProcessor(const std::string& mapdir, CollectedInfo& info)
      : mapdir_(mapdir), info_(info) {}

  void Run() {
    std::filesystem::path datadir_path = mapdir_;

    ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
    ProcessMaps(datadir_path);
    ProcessProgressivesFile(datadir_path / "progressives.txtpb");
    ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
    ProcessIdsFile(datadir_path / "ids.yaml");
  }

 private:
  void ProcessMaps(std::filesystem::path path) {
    std::filesystem::path maps_dir = path / "maps";
    for (auto const& dir_entry :
         std::filesystem::directory_iterator(maps_dir)) {
      ProcessMap(dir_entry.path());
    }
  }

  void ProcessMap(std::filesystem::path path) {
    std::string map_name = path.filename().string();

    ProcessMetadataFile(path / "metadata.txtpb", map_name);
    ProcessConnectionsFile(path / "connections.txtpb", map_name);
    ProcessDoorsFile(path / "doors.txtpb", map_name);
    ProcessRooms(path / "rooms", map_name);
  }

  void ProcessMetadataFile(std::filesystem::path path,
                           const std::string& current_map_name) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    MapInfo& map_info = info_.maps[current_map_name];

    auto metadata = ReadMessageFromFile<HumanMap>(path.string());
    for (const std::string& path : metadata.excluded_nodes()) {
      map_info.game_nodes[path].uses++;
    }
  }

  void ProcessRooms(std::filesystem::path path,
                    const std::string& current_map_name) {
    for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
      auto room = ReadMessageFromFile<HumanRoom>(dir_entry.path().string());
      ProcessRoom(room, current_map_name);
    }
  }

  void ProcessRoom(const HumanRoom& h_room,
                   const std::string& current_map_name) {
    RoomIdentifier room_identifier;
    room_identifier.set_map(current_map_name);
    room_identifier.set_name(h_room.name());

    RoomInfo& room_info = info_.rooms[room_identifier];
    room_info.definitions.push_back(h_room);

    for (const HumanPanel& h_panel : h_room.panels()) {
      ProcessPanel(h_panel, current_map_name, h_room);
    }

    for (const HumanPainting& h_painting : h_room.paintings()) {
      ProcessPainting(h_painting, current_map_name, h_room.name());
    }

    for (const HumanPort& h_port : h_room.ports()) {
      ProcessPort(h_port, current_map_name, h_room.name());
    }

    for (const HumanLetter& h_letter : h_room.letters()) {
      ProcessLetter(h_letter, current_map_name, h_room.name());
    }

    for (const HumanMastery& h_mastery : h_room.masteries()) {
      ProcessMastery(h_mastery, current_map_name, h_room.name());
    }

    for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
      ProcessKeyholder(h_keyholder, current_map_name, h_room.name());
    }

    for (const HumanEnding& h_ending : h_room.endings()) {
      ProcessEnding(h_ending, current_map_name, h_room.name());
    }
  }

  void ProcessPanel(const HumanPanel& h_panel,
                    const std::string& current_map_name,
                    const HumanRoom& h_room) {
    PanelIdentifier panel_identifier;
    panel_identifier.set_map(current_map_name);
    panel_identifier.set_room(h_room.name());
    panel_identifier.set_name(h_panel.name());

    PanelInfo& panel_info = info_.panels[panel_identifier];
    panel_info.definitions.push_back(h_panel);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_panel.path()].uses++;

    for (const Proxy& h_proxy : h_panel.proxies()) {
      ProxyInfo& proxy_info = panel_info.proxies[h_proxy.answer()];
      proxy_info.definitions.push_back(h_proxy);

      map_info.game_nodes[h_proxy.path()].uses++;
    }

    if (h_panel.has_required_door()) {
      DoorIdentifier required_door_identifier =
          *GetCompleteDoorIdentifier(h_panel.required_door(), current_map_name);
      DoorInfo& required_door_info = info_.doors[required_door_identifier];
      required_door_info.panels_referenced_by.push_back(panel_identifier);
    }

    if (h_panel.has_required_room()) {
      RoomIdentifier required_room_identifier =
          *GetCompleteRoomIdentifier(h_panel.required_room(), current_map_name);
      RoomInfo& required_room_info = info_.rooms[required_room_identifier];
      required_room_info.panels_referenced_by.push_back(panel_identifier);
    }

    std::string map_area_name = current_map_name;
    if (h_room.has_panel_display_name()) {
      map_area_name =
          fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
    }

    panel_info.map_area_name = map_area_name;

    std::string panelsanity_name;
    if (h_panel.has_display_name()) {
      panelsanity_name =
          fmt::format("{} - {}", map_area_name, h_panel.display_name());
    } else {
      panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
    }
    info_.panel_names[panelsanity_name].panels_used_by.push_back(
        panel_identifier);
  }

  void ProcessPainting(const HumanPainting& h_painting,
                       const std::string& current_map_name,
                       const std::string& current_room_name) {
    PaintingIdentifier painting_identifier;
    painting_identifier.set_map(current_map_name);
    painting_identifier.set_room(current_room_name);
    painting_identifier.set_name(h_painting.name());

    PaintingInfo& painting_info = info_.paintings[painting_identifier];
    painting_info.definitions.push_back(h_painting);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_painting.path()].uses++;

    if (h_painting.has_required_door()) {
      DoorIdentifier required_door_identifier = *GetCompleteDoorIdentifier(
          h_painting.required_door(), current_map_name);
      DoorInfo& required_door_info = info_.doors[required_door_identifier];
      required_door_info.paintings_referenced_by.push_back(painting_identifier);
    }
  }

  void ProcessPort(const HumanPort& h_port, const std::string& current_map_name,
                   const std::string& current_room_name) {
    PortIdentifier port_identifier;
    port_identifier.set_map(current_map_name);
    port_identifier.set_room(current_room_name);
    port_identifier.set_name(h_port.name());

    PortInfo& port_info = info_.ports[port_identifier];
    port_info.definitions.push_back(h_port);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_port.path()].uses++;

    if (h_port.has_required_door()) {
      DoorIdentifier required_door_identifier =
          *GetCompleteDoorIdentifier(h_port.required_door(), current_map_name);
      DoorInfo& required_door_info = info_.doors[required_door_identifier];
      required_door_info.ports_referenced_by.push_back(port_identifier);
    }
  }

  void ProcessLetter(const HumanLetter& h_letter,
                     const std::string& current_map_name,
                     const std::string& current_room_name) {
    LetterIdentifier letter_identifier =
        std::make_tuple(h_letter.key()[0], h_letter.level2());
    LetterInfo& letter_info = info_.letters[letter_identifier];

    RoomIdentifier room_identifier;
    room_identifier.set_map(current_map_name);
    room_identifier.set_name(current_room_name);
    letter_info.defined_in.push_back(room_identifier);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_letter.path()].uses++;
  }

  void ProcessMastery(const HumanMastery& h_mastery,
                      const std::string& current_map_name,
                      const std::string& current_room_name) {
    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_mastery.path()].uses++;
  }

  void ProcessKeyholder(const HumanKeyholder& h_keyholder,
                        const std::string& current_map_name,
                        const std::string& current_room_name) {
    KeyholderIdentifier keyholder_identifier;
    keyholder_identifier.set_map(current_map_name);
    keyholder_identifier.set_room(current_room_name);
    keyholder_identifier.set_name(h_keyholder.name());

    KeyholderInfo& keyholder_info = info_.keyholders[keyholder_identifier];
    keyholder_info.definitions.push_back(h_keyholder);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_keyholder.path()].uses++;
  }

  void ProcessEnding(const HumanEnding& h_ending,
                     const std::string& current_map_name,
                     const std::string& current_room_name) {
    EndingInfo& ending_info = info_.endings[h_ending.name()];

    RoomIdentifier room_identifier;
    room_identifier.set_map(current_map_name);
    room_identifier.set_name(current_room_name);
    ending_info.defined_in.push_back(room_identifier);

    MapInfo& map_info = info_.maps[current_map_name];
    map_info.game_nodes[h_ending.path()].uses++;
  }

  void ProcessDoorsFile(std::filesystem::path path,
                        const std::string& current_map_name) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    auto doors = ReadMessageFromFile<HumanDoors>(path.string());

    for (const HumanDoor& door : doors.doors()) {
      ProcessDoor(door, current_map_name);
    }
  }

  void ProcessDoor(const HumanDoor& h_door,
                   const std::string& current_map_name) {
    DoorIdentifier door_identifier;
    door_identifier.set_map(current_map_name);
    door_identifier.set_name(h_door.name());

    DoorInfo& door_info = info_.doors[door_identifier];
    door_info.definitions.push_back(h_door);

    if (h_door.has_location_room()) {
      RoomIdentifier location_room_identifier;
      location_room_identifier.set_map(current_map_name);
      location_room_identifier.set_name(h_door.location_room());
      info_.rooms[location_room_identifier].doors_referenced_by.push_back(
          door_identifier);
    }

    for (const PaintingIdentifier& pi : h_door.move_paintings()) {
      auto complete_painting_identifier =
          GetCompletePaintingIdentifier(pi, current_map_name, std::nullopt);
      if (complete_painting_identifier) {
        PaintingInfo& move_painting_info =
            info_.paintings[*complete_painting_identifier];
        move_painting_info.doors_referenced_by.push_back(door_identifier);
      } else {
        door_info.malformed_identifiers.paintings.push_back(pi);
      }
    }

    for (const PanelIdentifier& pi : h_door.panels()) {
      auto complete_panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
          pi, current_map_name, std::nullopt);
      if (complete_panel_identifier) {
        PanelInfo& panel_info = info_.panels[*complete_panel_identifier];
        panel_info.doors_referenced_by.push_back(door_identifier);

        if (pi.has_answer()) {
          panel_info.proxies[pi.answer()].doors_referenced_by.push_back(
              door_identifier);
        }
      } else {
        door_info.malformed_identifiers.panels.push_back(pi);
      }
    }

    for (const KeyholderIdentifier& ki : h_door.keyholders()) {
      auto complete_keyholder_identifier =
          GetCompleteKeyholderIdentifierWithoutKey(ki, current_map_name,
                                                   std::nullopt);
      if (complete_keyholder_identifier) {
        KeyholderInfo& keyholder_info =
            info_.keyholders[*complete_keyholder_identifier];
        keyholder_info.doors_referenced_by.push_back(door_identifier);
      } else {
        door_info.malformed_identifiers.keyholders.push_back(ki);
      }
    }

    for (const RoomIdentifier& ri : h_door.rooms()) {
      RoomIdentifier complete_room_identifier =
          *GetCompleteRoomIdentifier(ri, current_map_name);
      RoomInfo& room_info = info_.rooms[complete_room_identifier];
      room_info.doors_referenced_by.push_back(door_identifier);
    }

    for (const DoorIdentifier& di : h_door.doors()) {
      DoorIdentifier complete_door_identifier =
          *GetCompleteDoorIdentifier(di, current_map_name);
      DoorInfo& other_door_info = info_.doors[complete_door_identifier];
      other_door_info.doors_referenced_by.push_back(door_identifier);
    }

    for (const std::string& ei : h_door.endings()) {
      EndingInfo& ending_info = info_.endings[ei];
      ending_info.doors_referenced_by.push_back(door_identifier);
    }
  }

  void ProcessConnectionsFile(std::filesystem::path path,
                              std::optional<std::string> current_map_name) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    auto connections = ReadMessageFromFile<HumanConnections>(path.string());

    for (const HumanConnection& connection : connections.connections()) {
      ProcessConnection(connection, current_map_name);
    }
  }

  void ProcessConnection(const HumanConnection& human_connection,
                         const std::optional<std::string>& current_map_name) {
    if (human_connection.has_from_room()) {
      if (current_map_name) {
        RoomIdentifier room_identifier;
        room_identifier.set_map(*current_map_name);
        room_identifier.set_name(human_connection.from_room());

        RoomInfo& room_info = info_.rooms[room_identifier];
        room_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout << "A global connection used from_room." << std::endl;
      }
    } else if (human_connection.has_from()) {
      ProcessSingleConnection(human_connection, human_connection.from(),
                              current_map_name);
    }

    if (human_connection.has_to_room()) {
      if (current_map_name) {
        RoomIdentifier room_identifier;
        room_identifier.set_map(*current_map_name);
        room_identifier.set_name(human_connection.to_room());

        RoomInfo& room_info = info_.rooms[room_identifier];
        room_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout << "A global connection used to_room." << std::endl;
      }
    } else if (human_connection.has_to()) {
      ProcessSingleConnection(human_connection, human_connection.to(),
                              current_map_name);
    }

    if (human_connection.has_door()) {
      auto door_identifier =
          GetCompleteDoorIdentifier(human_connection.door(), current_map_name);
      if (door_identifier) {
        DoorInfo& door_info = info_.doors[*door_identifier];
        door_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout
            << "A connection used the following malformed door identifier: "
            << human_connection.door().ShortDebugString() << std::endl;
      }
    }
  }

  void ProcessSingleConnection(
      const HumanConnection& human_connection,
      const HumanConnection::Endpoint& endpoint,
      const std::optional<std::string>& current_map_name) {
    if (endpoint.has_room()) {
      auto room_identifier =
          GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
      if (room_identifier) {
        RoomInfo& room_info = info_.rooms[*room_identifier];
        room_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout
            << "A connection used the following malformed room identifier: "
            << endpoint.room().ShortDebugString() << std::endl;
      }
    } else if (endpoint.has_painting()) {
      auto painting_identifier = GetCompletePaintingIdentifier(
          endpoint.painting(), current_map_name, std::nullopt);
      if (painting_identifier) {
        PaintingInfo& painting_info = info_.paintings[*painting_identifier];
        painting_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout
            << "A connection used the following malformed painting identifier: "
            << endpoint.painting().ShortDebugString() << std::endl;
      }
    } else if (endpoint.has_port()) {
      auto port_identifier = GetCompletePortIdentifier(
          endpoint.port(), current_map_name, std::nullopt);
      if (port_identifier) {
        PortInfo& port_info = info_.ports[*port_identifier];
        port_info.connections_referenced_by.push_back(human_connection);
      } else {
        // Not sure where else to store this right now.
        std::cout
            << "A connection used the following malformed port identifier: "
            << endpoint.port().ShortDebugString() << std::endl;
      }
    } else if (endpoint.has_panel()) {
      auto panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
          endpoint.panel(), current_map_name, std::nullopt);
      if (panel_identifier) {
        PanelInfo& panel_info = info_.panels[*panel_identifier];
        panel_info.connections_referenced_by.push_back(human_connection);

        if (endpoint.panel().has_answer()) {
          panel_info.proxies[endpoint.panel().answer()]
              .connections_referenced_by.push_back(human_connection);
        }
      }
    }
  }

  void ProcessProgressivesFile(std::filesystem::path path) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());

    for (const HumanProgressive& h_prog : h_progs.progressives()) {
      ProcessProgressive(h_prog);
    }
  }

  void ProcessProgressive(const HumanProgressive& h_prog) {
    ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
    prog_info.definitions.push_back(h_prog);

    for (const DoorIdentifier& di : h_prog.doors()) {
      if (!di.has_map()) {
        prog_info.malformed_doors.push_back(di);
        continue;
      }

      DoorInfo& door_info = info_.doors[di];
      door_info.progressives_referenced_by.push_back(h_prog.name());
    }
  }

  void ProcessDoorGroupsFile(std::filesystem::path path) {
    if (!std::filesystem::exists(path)) {
      return;
    }

    auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());

    for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
      ProcessDoorGroup(h_group);
    }
  }

  void ProcessDoorGroup(const HumanDoorGroup& h_group) {
    DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
    group_info.definitions.push_back(h_group);

    for (const DoorIdentifier& di : h_group.doors()) {
      if (!di.has_map()) {
        group_info.malformed_doors.push_back(di);
        continue;
      }

      DoorInfo& door_info = info_.doors[di];
      door_info.door_groups_referenced_by.push_back(h_group.name());
    }
  }

  void ProcessIdsFile(std::filesystem::path path) {
    auto ids = ReadIdsFromYaml(path.string());

    DoorIdentifier di;
    PanelIdentifier pi;
    KeyholderIdentifier ki;

    for (const auto& [map_name, map] : ids.maps()) {
      di.set_map(map_name);
      pi.set_map(map_name);
      ki.set_map(map_name);

      for (const auto& [door_name, ap_id] : map.doors()) {
        di.set_name(door_name);

        DoorInfo& door_info = info_.doors[di];
        door_info.has_id = true;
      }

      for (const auto& [room_name, room] : map.rooms()) {
        pi.set_room(room_name);
        ki.set_room(room_name);

        for (const auto& [panel_name, ap_id] : room.panels()) {
          pi.set_name(panel_name);

          PanelInfo& panel_info = info_.panels[pi];
          panel_info.has_id = true;
        }

        for (const auto& [mastery_name, ap_id] : room.masteries()) {
          // TODO: Mastery
        }

        for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
          ki.set_name(keyholder_name);

          KeyholderInfo& keyholder_info = info_.keyholders[ki];
          keyholder_info.has_id = true;
        }
      }
    }

    for (const auto& [tag, id] : ids.special()) {
      // TODO: Specials
    }

    for (const auto& [letter_name, ap_id] : ids.letters()) {
      LetterIdentifier li =
          std::make_tuple(letter_name[0], letter_name[1] == '2');
      LetterInfo& letter_info = info_.letters[li];
      letter_info.has_id = true;
    }

    for (const auto& [ending_name, ap_id] : ids.endings()) {
      EndingInfo& ending_info = info_.endings[ending_name];
      ending_info.has_id = true;
    }

    for (const auto& [prog_name, ap_id] : ids.progressives()) {
      ProgressiveInfo& prog_info = info_.progressives[prog_name];
      prog_info.has_id = true;
    }

    for (const auto& [group_name, ap_id] : ids.door_groups()) {
      DoorGroupInfo& group_info = info_.door_groups[group_name];
      group_info.has_id = true;
    }
  }

  std::string mapdir_;
  CollectedInfo& info_;
};

}  // namespace

void ProcessHumanData(const std::string& mapdir, CollectedInfo& info) {
  HumanProcessor human_processor(mapdir, info);
  human_processor.Run();
}

}  // namespace com::fourisland::lingo2_archipelago