From a3972a65b9b443a6085a6ac40b153442e190f382 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 1 Sep 2025 12:54:46 -0400 Subject: Added progressive doors --- tools/assign_ids/main.cpp | 64 ++++++++++++++++++------------------- tools/datapacker/container.cpp | 17 ++++++++++ tools/datapacker/container.h | 3 ++ tools/datapacker/main.cpp | 33 +++++++++++++++++-- tools/util/ids_yaml_format.cpp | 12 +++++++ tools/validator/human_processor.cpp | 28 ++++++++++++++++ tools/validator/structs.h | 8 +++++ tools/validator/validator.cpp | 16 ++++++++++ 8 files changed, 146 insertions(+), 35 deletions(-) (limited to 'tools') diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index e65e5e4..3a2f347 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp @@ -40,6 +40,7 @@ class AssignIds { ReadIds(ids_path); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); WriteIds(ids_path); @@ -54,44 +55,18 @@ class AssignIds { 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; - } - } + UpdateNextId(map.doors()); 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; + UpdateNextId(room.panels()); + UpdateNextId(room.masteries()); } } - 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; - } - } + UpdateNextId(id_mappings_.special()); + UpdateNextId(id_mappings_.letters()); + UpdateNextId(id_mappings_.endings()); + UpdateNextId(id_mappings_.progressives()); next_id_++; } @@ -210,7 +185,30 @@ class AssignIds { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(path.string()); + auto& progs = *id_mappings_.mutable_progressives(); + + for (const HumanProgressive& h_prog : h_progs.progressives()) { + if (!progs.contains(h_prog.name())) { + progs[h_prog.name()] = next_id_++; + } + } + } + private: + void UpdateNextId(const google::protobuf::Map& ids) { + for (const auto& [_, id] : ids) { + if (id > next_id_) { + next_id_ = id; + } + } + } + std::string mapdir_; uint64_t next_id_ = 1; diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp index 2c68552..624caf8 100644 --- a/tools/datapacker/container.cpp +++ b/tools/datapacker/container.cpp @@ -331,6 +331,23 @@ uint64_t Container::FindOrAddDoor(std::optional map_name, } } +uint64_t Container::FindOrAddProgressive(std::string prog_name) { + auto it = progressive_id_by_name_.find(prog_name); + + if (it == progressive_id_by_name_.end()) { + uint64_t new_id = all_objects_.progressives_size(); + Progressive* progressive = all_objects_.add_progressives(); + progressive->set_id(new_id); + progressive->set_name(prog_name); + + progressive_id_by_name_[prog_name] = new_id; + + return new_id; + } else { + return it->second; + } +} + void Container::AddConnection(const Connection& connection) { *all_objects_.add_connections() = connection; } diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h index 68f5875..8cec560 100644 --- a/tools/datapacker/container.h +++ b/tools/datapacker/container.h @@ -60,6 +60,8 @@ class Container { void AddConnection(const Connection& connection); + uint64_t FindOrAddProgressive(std::string prog_name); + AllObjects& all_objects() { return all_objects_; } private: @@ -82,6 +84,7 @@ class Container { std::map> door_id_by_map_door_names_; std::map ending_id_by_name_; + std::map progressive_id_by_name_; }; } // namespace com::fourisland::lingo2_archipelago diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index 4923fce..5ed82cc 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp @@ -43,6 +43,7 @@ class DataPacker { ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); ProcessIdsFile(datadir_path / "ids.yaml"); { @@ -104,7 +105,7 @@ class DataPacker { container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); Room& room = *container_.all_objects().mutable_rooms(room_id); - //room.set_display_name(h_room.display_name()); + // room.set_display_name(h_room.display_name()); if (h_room.has_panel_display_name()) { room.set_panel_display_name(h_room.panel_display_name()); @@ -388,7 +389,7 @@ class DataPacker { door.add_doors( container_.FindOrAddDoor(map_name, di.name(), current_map_name)); } - + for (const std::string& ending_name : h_door.endings()) { door.add_endings(container_.FindOrAddEnding(ending_name)); } @@ -544,6 +545,29 @@ class DataPacker { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(path.string()); + + for (const HumanProgressive& h_prog : h_progs.progressives()) { + ProcessProgressive(h_prog); + } + } + + void ProcessProgressive(const HumanProgressive& h_prog) { + uint64_t prog_id = container_.FindOrAddProgressive(h_prog.name()); + Progressive& prog = *container_.all_objects().mutable_progressives(prog_id); + + for (const DoorIdentifier& di : h_prog.doors()) { + uint64_t door_id = + container_.FindOrAddDoor(di.map(), di.name(), std::nullopt); + prog.add_doors(door_id); + } + } + void ProcessIdsFile(std::filesystem::path path) { auto ids = ReadIdsFromYaml(path.string()); @@ -585,6 +609,11 @@ class DataPacker { uint64_t ending_id = container_.FindOrAddEnding(ending_name); container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id); } + + for (const auto& [prog_name, ap_id] : ids.progressives()) { + uint64_t prog_id = container_.FindOrAddProgressive(prog_name); + container_.all_objects().mutable_progressives(prog_id)->set_ap_id(ap_id); + } } std::string mapdir_; diff --git a/tools/util/ids_yaml_format.cpp b/tools/util/ids_yaml_format.cpp index f72f60e..ae62073 100644 --- a/tools/util/ids_yaml_format.cpp +++ b/tools/util/ids_yaml_format.cpp @@ -89,6 +89,13 @@ IdMappings ReadIdsFromYaml(const std::string& filename) { } } + if (document["progressives"]) { + for (const auto& prog_it : document["progressives"]) { + (*result.mutable_progressives())[prog_it.first.as()] = + prog_it.second.as(); + } + } + return result; } @@ -144,6 +151,11 @@ void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) { result["special"][special_name] = special_id; }); + OperateOnSortedMap(ids.progressives(), + [&result](const std::string& prog_name, uint64_t prog_id) { + result["progressives"][prog_name] = prog_id; + }); + std::ofstream output_stream(filename); output_stream << result << std::endl; } diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 0f63936..49e7578 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp @@ -41,6 +41,7 @@ class HumanProcessor { ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); ProcessMaps(datadir_path); + ProcessProgressivesFile(datadir_path / "progressives.txtpb"); ProcessIdsFile(datadir_path / "ids.txtpb"); } @@ -481,6 +482,33 @@ class HumanProcessor { } } + void ProcessProgressivesFile(std::filesystem::path path) { + if (!std::filesystem::exists(path)) { + return; + } + + auto h_progs = ReadMessageFromFile(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 ProcessIdsFile(std::filesystem::path path) { // Ignore this for now. } diff --git a/tools/validator/structs.h b/tools/validator/structs.h index 0ca96fe..717fccf 100644 --- a/tools/validator/structs.h +++ b/tools/validator/structs.h @@ -45,6 +45,7 @@ struct DoorInfo { std::vector panels_referenced_by; std::vector paintings_referenced_by; std::vector ports_referenced_by; + std::vector progressives_referenced_by; MalformedIdentifiers malformed_identifiers; }; @@ -102,6 +103,12 @@ struct PanelNameInfo { std::vector panels_used_by; }; +struct ProgressiveInfo { + std::vector definitions; + + std::vector malformed_doors; +}; + struct CollectedInfo { std::map maps; std::map rooms; @@ -114,6 +121,7 @@ struct CollectedInfo { std::map letters; std::map endings; std::map panel_names; + std::map progressives; }; } // namespace com::fourisland::lingo2_archipelago diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp index 9c66e09..fd004d7 100644 --- a/tools/validator/validator.cpp +++ b/tools/validator/validator.cpp @@ -45,6 +45,9 @@ class Validator { 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); + } } private: @@ -164,6 +167,11 @@ class Validator { 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; + } } else if (door_info.definitions.size() > 1) { std::cout << "Door " << door_identifier.ShortDebugString() << " was defined multiple times." << std::endl; @@ -369,6 +377,14 @@ class Validator { } } + void ValidateProgressive(const std::string& prog_name, + const ProgressiveInfo& prog_info) const { + if (prog_info.definitions.size() > 1) { + std::cout << "Progressive \"" << prog_name + << "\" has multiple definitions." << std::endl; + } + } + const CollectedInfo& info_; }; -- cgit 1.4.1