about summary refs log tree commit diff stats
path: root/data/maps/the_parthenon
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-08-29 13:30:58 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2025-08-29 13:30:58 -0400
commit8566f6e7fb54f5f52241ac86ebd1a6636ceb4a08 (patch)
treefb1374cb88bcbb30aff54ddb6a01b4864e185966 /data/maps/the_parthenon
parentcda8cb3349483146d23ab020fe73f3e2c54b10eb (diff)
downloadlingo2-archipelago-8566f6e7fb54f5f52241ac86ebd1a6636ceb4a08.tar.gz
lingo2-archipelago-8566f6e7fb54f5f52241ac86ebd1a6636ceb4a08.tar.bz2
lingo2-archipelago-8566f6e7fb54f5f52241ac86ebd1a6636ceb4a08.zip
[Client] Added ending locations
Getting an ending (other than White) also does not send you to the credits.
Diffstat (limited to 'data/maps/the_parthenon')
0 files changed, 0 insertions, 0 deletions
id='n122' href='#n122'>122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
#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;
}