diff options
Diffstat (limited to 'tools/assign_ids')
| -rw-r--r-- | tools/assign_ids/main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
| diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index e3add66..3e16f78 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #include <google/protobuf/text_format.h> | 2 | #include <google/protobuf/text_format.h> |
| 3 | 3 | ||
| 4 | #include <cstdint> | 4 | #include <cstdint> |
| 5 | #include <filesystem> | ||
| 5 | #include <fstream> | 6 | #include <fstream> |
| 6 | #include <iostream> | 7 | #include <iostream> |
| 7 | #include <map> | 8 | #include <map> |
| @@ -42,6 +43,8 @@ class AssignIds { | |||
| 42 | ProcessMaps(datadir_path); | 43 | ProcessMaps(datadir_path); |
| 43 | ProcessSpecialIds(); | 44 | ProcessSpecialIds(); |
| 44 | ProcessProgressivesFile(datadir_path / "progressives.txtpb"); | 45 | ProcessProgressivesFile(datadir_path / "progressives.txtpb"); |
| 46 | ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb"); | ||
| 47 | ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb"); | ||
| 45 | 48 | ||
| 46 | WriteIds(ids_path); | 49 | WriteIds(ids_path); |
| 47 | 50 | ||
| @@ -61,6 +64,7 @@ class AssignIds { | |||
| 61 | for (const auto& [_, room] : map.rooms()) { | 64 | for (const auto& [_, room] : map.rooms()) { |
| 62 | UpdateNextId(room.panels()); | 65 | UpdateNextId(room.panels()); |
| 63 | UpdateNextId(room.masteries()); | 66 | UpdateNextId(room.masteries()); |
| 67 | UpdateNextId(room.keyholders()); | ||
| 64 | } | 68 | } |
| 65 | } | 69 | } |
| 66 | 70 | ||
| @@ -68,6 +72,7 @@ class AssignIds { | |||
| 68 | UpdateNextId(id_mappings_.letters()); | 72 | UpdateNextId(id_mappings_.letters()); |
| 69 | UpdateNextId(id_mappings_.endings()); | 73 | UpdateNextId(id_mappings_.endings()); |
| 70 | UpdateNextId(id_mappings_.progressives()); | 74 | UpdateNextId(id_mappings_.progressives()); |
| 75 | UpdateNextId(id_mappings_.door_groups()); | ||
| 71 | 76 | ||
| 72 | next_id_++; | 77 | next_id_++; |
| 73 | } | 78 | } |
| @@ -267,6 +272,40 @@ class AssignIds { | |||
| 267 | } | 272 | } |
| 268 | } | 273 | } |
| 269 | 274 | ||
| 275 | void ProcessDoorGroupsFile(std::filesystem::path path) { | ||
| 276 | if (!std::filesystem::exists(path)) { | ||
| 277 | return; | ||
| 278 | } | ||
| 279 | |||
| 280 | auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string()); | ||
| 281 | auto& groups = *output_.mutable_door_groups(); | ||
| 282 | |||
| 283 | for (const HumanDoorGroup& h_group : h_groups.door_groups()) { | ||
| 284 | if (!id_mappings_.door_groups().contains(h_group.name())) { | ||
| 285 | groups[h_group.name()] = next_id_++; | ||
| 286 | } else { | ||
| 287 | groups[h_group.name()] = id_mappings_.door_groups().at(h_group.name()); | ||
| 288 | } | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | void ProcessGlobalMetadataFile(std::filesystem::path path) { | ||
| 293 | if (!std::filesystem::exists(path)) { | ||
| 294 | return; | ||
| 295 | } | ||
| 296 | |||
| 297 | auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string()); | ||
| 298 | auto& specials = *output_.mutable_special(); | ||
| 299 | |||
| 300 | for (const std::string& h_special : h_metadata.special_names()) { | ||
| 301 | if (!id_mappings_.special().contains(h_special)) { | ||
| 302 | specials[h_special] = next_id_++; | ||
| 303 | } else { | ||
| 304 | specials[h_special] = id_mappings_.special().at(h_special); | ||
| 305 | } | ||
| 306 | } | ||
| 307 | } | ||
| 308 | |||
| 270 | private: | 309 | private: |
| 271 | void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) { | 310 | void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) { |
| 272 | for (const auto& [_, id] : ids) { | 311 | for (const auto& [_, id] : ids) { |
