about summary refs log tree commit diff stats
path: root/data/maps/daedalus/rooms/Eye Temple 1F.txtpb
blob: e15afc196643c55d1fff7a64e97ed37b66242ca0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
name: "Eye Temple 1F"
panel_display_name: "Temple of the Eyes"
paintings {
  name: "EYEREDTOEXITMAIN2"
  path: "Components/Paintings/Temple of the Eyes/eyeRedToExitMain2"
}
paintings {
  name: "EYEREDTOBACKSIDE3"
  path: "Components/Paintings/Temple of the Eyes/eyeRedToBackside3"
}
paintings {
  name: "EYEREDTOPILLAR3"
  path: "Components/Paintings/Temple of the Eyes/eyeRedToPillar3"
}
paintings {
  name: "EYEREDTOPILLAR2"
  path: "Components/Paintings/Temple of the Eyes/eyeRedToPillar2"
}
paintings {
  name: "EYEREDTOPILLAR1"
  path: "Components/Paintings/Temple of the Eyes/eyeRedToPillar1"
}
paintings {
  name: "EYEREDEXITBACKSIDE"
  path: "Components/Paintings/Temple of the Eyes/eyeRedExitBackside"
  exit_only: true
}
ht: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>

#include <cstdint>
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

#include "proto/human.pb.h"
#include "util/ids_yaml_format.h"
#include "util/naming.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 AssignIds {
 public:
  AssignIds(const std::string& mapdir) : mapdir_(mapdir) {}

  void Run() {
    std::filesystem::path datadir_path = mapdir_;
    std::filesystem::path ids_path = datadir_path / "ids.yaml";

    ReadIds(ids_path);

    ProcessMaps(datadir_path);

    WriteIds(ids_path);

    std::cout << "Next ID: " << next_id_ << std::endl;
  }

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

    id_mappings_ = ReadIdsFromYaml(path.string());

    for (const auto& [_, map] : id_mappings_.maps()) {
      for (const auto& [_, id] : map.doors()) {
        if (id > next_id_) {
          next_id_ = id;
        }
      }

      for (const auto& [_, room] : map.rooms()) {
        for (const auto& [_, id] : room.panels()) {
          if (id > next_id_) {
            next_id_ = id;
          }
        }

        for (const auto& [_, id] : room.masteries()) {
          if (id > next_id_) {
            next_id_ = id;
          }
        }
      }
    }

    for (const auto& [_, id] : id_mappings_.special()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    for (const auto& [_, id] : id_mappings_.letters()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    for (const auto& [_, id] : id_mappings_.endings()) {
      if (id > next_id_) {
        next_id_ = id;
      }
    }

    next_id_++;
  }

  void WriteIds(std::filesystem::path path) {
    WriteIdsAsYaml(id_mappings_, path.string());
  }

  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();

    ProcessDoorsFile(path / "doors.txtpb", map_name);
    ProcessRooms(path / "rooms", map_name);
  }

  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) {
    if (h_door.type() == DoorType::EVENT) {
      return;
    }

    if (!id_mappings_.maps().contains(current_map_name) ||
        !id_mappings_.maps()
             .at(current_map_name)
             .doors()
             .contains(h_door.name())) {
      auto& maps = *id_mappings_.mutable_maps();
      auto& doors = *maps[current_map_name].mutable_doors();
      doors[h_door.name()] = next_id_++;
    }
  }

  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) {
    for (const HumanPanel& h_panel : h_room.panels()) {
      if (!id_mappings_.maps().contains(current_map_name) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .contains(h_room.name()) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .at(h_room.name())
               .panels()
               .contains(h_panel.name())) {
        auto& maps = *id_mappings_.mutable_maps();
        auto& rooms = *maps[current_map_name].mutable_rooms();
        auto& panels = *rooms[h_room.name()].mutable_panels();
        panels[h_panel.name()] = next_id_++;
      }
    }

    for (const HumanLetter& h_letter : h_room.letters()) {
      std::string lettername = GetLetterName(h_letter.key(), h_letter.level2());

      if (!id_mappings_.letters().contains(lettername)) {
        auto& letters = *id_mappings_.mutable_letters();
        letters[lettername] = next_id_++;
      }
    }

    for (const HumanMastery& h_mastery : h_room.masteries()) {
      if (!id_mappings_.maps().contains(current_map_name) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .contains(h_room.name()) ||
          !id_mappings_.maps()
               .at(current_map_name)
               .rooms()
               .at(h_room.name())
               .masteries()
               .contains(h_mastery.name())) {
        auto& maps = *id_mappings_.mutable_maps();
        auto& rooms = *maps[current_map_name].mutable_rooms();
        auto& masteries = *rooms[h_room.name()].mutable_masteries();
        masteries[h_mastery.name()] = next_id_++;
      }
    }

    for (const HumanEnding& h_ending : h_room.endings()) {
      if (!id_mappings_.endings().contains(h_ending.name())) {
        auto& endings = *id_mappings_.mutable_endings();
        endings[h_ending.name()] = next_id_++;
      }
    }
  }

 private:
  std::string mapdir_;

  uint64_t next_id_ = 1;

  IdMappings id_mappings_;
};

}  // namespace
}  // namespace com::fourisland::lingo2_archipelago

int main(int argc, char** argv) {
  if (argc != 2) {
    std::cout << "Incorrect argument count." << std::endl;
    std::cout << "Usage: assign_ids [path to map directory]" << std::endl;
    return 1;
  }

  std::string mapdir = argv[1];

  com::fourisland::lingo2_archipelago::AssignIds assign_ids(mapdir);
  assign_ids.Run();

  return 0;
}