#include #include #include #include #include #include #include #include #include "proto/human.pb.h" #include "util/ids_yaml_format.h" #include "util/naming.h" namespace com::fourisland::lingo2_archipelago { namespace { template 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(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(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
name: "North Castle Area"
panel_display_name: "North Area"
panels {
  name: "A"
  path: "Panels/Castle Entrance/castle_north_helper"
  clue: "a"
  answer: "the"
  symbols: EXAMPLE
}
panels {
  name: "SUMMER"
  path: "Panels/Castle Entrance/castle_north_helper2"
  clue: "summer"
  answer: "winter"
  symbols: EXAMPLE
}
panels {
  name: "PLACE"
  path: "Panels/Castle Entrance/castle_north_helper3"
  clue: "place"
  answer: "palace"
  symbols: SPARKLES
}
panels {
  name: "A SUMMER PLACE"
  path: "Panels/Castle Entrance/castle_north"
  clue: ""
  answer: "castle"
  symbols: EXAMPLE
  symbols: LINGO
  required_door { name: "Castle North Hider" }
}
paintings {
  name: "RELIC2"
  path: "Components/Paintings/Group1/relic2"
}