diff options
Diffstat (limited to 'tools/assign_ids/main.cpp')
| -rw-r--r-- | tools/assign_ids/main.cpp | 116 |
1 files changed, 100 insertions, 16 deletions
| diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index 6eb41e3..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> |
| @@ -40,7 +41,10 @@ class AssignIds { | |||
| 40 | ReadIds(ids_path); | 41 | ReadIds(ids_path); |
| 41 | 42 | ||
| 42 | ProcessMaps(datadir_path); | 43 | ProcessMaps(datadir_path); |
| 44 | ProcessSpecialIds(); | ||
| 43 | ProcessProgressivesFile(datadir_path / "progressives.txtpb"); | 45 | ProcessProgressivesFile(datadir_path / "progressives.txtpb"); |
| 46 | ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb"); | ||
| 47 | ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb"); | ||
| 44 | 48 | ||
| 45 | WriteIds(ids_path); | 49 | WriteIds(ids_path); |
| 46 | 50 | ||
| @@ -60,6 +64,7 @@ class AssignIds { | |||
| 60 | for (const auto& [_, room] : map.rooms()) { | 64 | for (const auto& [_, room] : map.rooms()) { |
| 61 | UpdateNextId(room.panels()); | 65 | UpdateNextId(room.panels()); |
| 62 | UpdateNextId(room.masteries()); | 66 | UpdateNextId(room.masteries()); |
| 67 | UpdateNextId(room.keyholders()); | ||
| 63 | } | 68 | } |
| 64 | } | 69 | } |
| 65 | 70 | ||
| @@ -67,12 +72,13 @@ class AssignIds { | |||
| 67 | UpdateNextId(id_mappings_.letters()); | 72 | UpdateNextId(id_mappings_.letters()); |
| 68 | UpdateNextId(id_mappings_.endings()); | 73 | UpdateNextId(id_mappings_.endings()); |
| 69 | UpdateNextId(id_mappings_.progressives()); | 74 | UpdateNextId(id_mappings_.progressives()); |
| 75 | UpdateNextId(id_mappings_.door_groups()); | ||
| 70 | 76 | ||
| 71 | next_id_++; | 77 | next_id_++; |
| 72 | } | 78 | } |
| 73 | 79 | ||
| 74 | void WriteIds(std::filesystem::path path) { | 80 | void WriteIds(std::filesystem::path path) { |
| 75 | WriteIdsAsYaml(id_mappings_, path.string()); | 81 | WriteIdsAsYaml(output_, path.string()); |
| 76 | } | 82 | } |
| 77 | 83 | ||
| 78 | void ProcessMaps(std::filesystem::path path) { | 84 | void ProcessMaps(std::filesystem::path path) { |
| @@ -109,14 +115,18 @@ class AssignIds { | |||
| 109 | return; | 115 | return; |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 118 | auto& maps = *output_.mutable_maps(); | ||
| 119 | auto& doors = *maps[current_map_name].mutable_doors(); | ||
| 120 | |||
| 112 | if (!id_mappings_.maps().contains(current_map_name) || | 121 | if (!id_mappings_.maps().contains(current_map_name) || |
| 113 | !id_mappings_.maps() | 122 | !id_mappings_.maps() |
| 114 | .at(current_map_name) | 123 | .at(current_map_name) |
| 115 | .doors() | 124 | .doors() |
| 116 | .contains(h_door.name())) { | 125 | .contains(h_door.name())) { |
| 117 | auto& maps = *id_mappings_.mutable_maps(); | ||
| 118 | auto& doors = *maps[current_map_name].mutable_doors(); | ||
| 119 | doors[h_door.name()] = next_id_++; | 126 | doors[h_door.name()] = next_id_++; |
| 127 | } else { | ||
| 128 | doors[h_door.name()] = | ||
| 129 | id_mappings_.maps().at(current_map_name).doors().at(h_door.name()); | ||
| 120 | } | 130 | } |
| 121 | } | 131 | } |
| 122 | 132 | ||
| @@ -131,6 +141,10 @@ class AssignIds { | |||
| 131 | void ProcessRoom(const HumanRoom& h_room, | 141 | void ProcessRoom(const HumanRoom& h_room, |
| 132 | const std::string& current_map_name) { | 142 | const std::string& current_map_name) { |
| 133 | for (const HumanPanel& h_panel : h_room.panels()) { | 143 | for (const HumanPanel& h_panel : h_room.panels()) { |
| 144 | auto& maps = *output_.mutable_maps(); | ||
| 145 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 146 | auto& panels = *rooms[h_room.name()].mutable_panels(); | ||
| 147 | |||
| 134 | if (!id_mappings_.maps().contains(current_map_name) || | 148 | if (!id_mappings_.maps().contains(current_map_name) || |
| 135 | !id_mappings_.maps() | 149 | !id_mappings_.maps() |
| 136 | .at(current_map_name) | 150 | .at(current_map_name) |
| @@ -142,23 +156,33 @@ class AssignIds { | |||
| 142 | .at(h_room.name()) | 156 | .at(h_room.name()) |
| 143 | .panels() | 157 | .panels() |
| 144 | .contains(h_panel.name())) { | 158 | .contains(h_panel.name())) { |
| 145 | auto& maps = *id_mappings_.mutable_maps(); | ||
| 146 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 147 | auto& panels = *rooms[h_room.name()].mutable_panels(); | ||
| 148 | panels[h_panel.name()] = next_id_++; | 159 | panels[h_panel.name()] = next_id_++; |
| 160 | } else { | ||
| 161 | panels[h_panel.name()] = id_mappings_.maps() | ||
| 162 | .at(current_map_name) | ||
| 163 | .rooms() | ||
| 164 | .at(h_room.name()) | ||
| 165 | .panels() | ||
| 166 | .at(h_panel.name()); | ||
| 149 | } | 167 | } |
| 150 | } | 168 | } |
| 151 | 169 | ||
| 152 | for (const HumanLetter& h_letter : h_room.letters()) { | 170 | for (const HumanLetter& h_letter : h_room.letters()) { |
| 153 | std::string lettername = GetLetterName(h_letter.key(), h_letter.level2()); | 171 | std::string lettername = GetLetterName(h_letter.key(), h_letter.level2()); |
| 154 | 172 | ||
| 173 | auto& letters = *output_.mutable_letters(); | ||
| 155 | if (!id_mappings_.letters().contains(lettername)) { | 174 | if (!id_mappings_.letters().contains(lettername)) { |
| 156 | auto& letters = *id_mappings_.mutable_letters(); | ||
| 157 | letters[lettername] = next_id_++; | 175 | letters[lettername] = next_id_++; |
| 176 | } else { | ||
| 177 | letters[lettername] = id_mappings_.letters().at(lettername); | ||
| 158 | } | 178 | } |
| 159 | } | 179 | } |
| 160 | 180 | ||
| 161 | for (const HumanMastery& h_mastery : h_room.masteries()) { | 181 | for (const HumanMastery& h_mastery : h_room.masteries()) { |
| 182 | auto& maps = *output_.mutable_maps(); | ||
| 183 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 184 | auto& masteries = *rooms[h_room.name()].mutable_masteries(); | ||
| 185 | |||
| 162 | if (!id_mappings_.maps().contains(current_map_name) || | 186 | if (!id_mappings_.maps().contains(current_map_name) || |
| 163 | !id_mappings_.maps() | 187 | !id_mappings_.maps() |
| 164 | .at(current_map_name) | 188 | .at(current_map_name) |
| @@ -170,17 +194,24 @@ class AssignIds { | |||
| 170 | .at(h_room.name()) | 194 | .at(h_room.name()) |
| 171 | .masteries() | 195 | .masteries() |
| 172 | .contains(h_mastery.name())) { | 196 | .contains(h_mastery.name())) { |
| 173 | auto& maps = *id_mappings_.mutable_maps(); | ||
| 174 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 175 | auto& masteries = *rooms[h_room.name()].mutable_masteries(); | ||
| 176 | masteries[h_mastery.name()] = next_id_++; | 197 | masteries[h_mastery.name()] = next_id_++; |
| 198 | } else { | ||
| 199 | masteries[h_mastery.name()] = id_mappings_.maps() | ||
| 200 | .at(current_map_name) | ||
| 201 | .rooms() | ||
| 202 | .at(h_room.name()) | ||
| 203 | .masteries() | ||
| 204 | .at(h_mastery.name()); | ||
| 177 | } | 205 | } |
| 178 | } | 206 | } |
| 179 | 207 | ||
| 180 | for (const HumanEnding& h_ending : h_room.endings()) { | 208 | for (const HumanEnding& h_ending : h_room.endings()) { |
| 209 | auto& endings = *output_.mutable_endings(); | ||
| 210 | |||
| 181 | if (!id_mappings_.endings().contains(h_ending.name())) { | 211 | if (!id_mappings_.endings().contains(h_ending.name())) { |
| 182 | auto& endings = *id_mappings_.mutable_endings(); | ||
| 183 | endings[h_ending.name()] = next_id_++; | 212 | endings[h_ending.name()] = next_id_++; |
| 213 | } else { | ||
| 214 | endings[h_ending.name()] = id_mappings_.endings().at(h_ending.name()); | ||
| 184 | } | 215 | } |
| 185 | } | 216 | } |
| 186 | 217 | ||
| @@ -189,6 +220,10 @@ class AssignIds { | |||
| 189 | continue; | 220 | continue; |
| 190 | } | 221 | } |
| 191 | 222 | ||
| 223 | auto& maps = *output_.mutable_maps(); | ||
| 224 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 225 | auto& keyholders = *rooms[h_room.name()].mutable_keyholders(); | ||
| 226 | |||
| 192 | if (!id_mappings_.maps().contains(current_map_name) || | 227 | if (!id_mappings_.maps().contains(current_map_name) || |
| 193 | !id_mappings_.maps() | 228 | !id_mappings_.maps() |
| 194 | .at(current_map_name) | 229 | .at(current_map_name) |
| @@ -200,25 +235,73 @@ class AssignIds { | |||
| 200 | .at(h_room.name()) | 235 | .at(h_room.name()) |
| 201 | .keyholders() | 236 | .keyholders() |
| 202 | .contains(h_keyholder.name())) { | 237 | .contains(h_keyholder.name())) { |
| 203 | auto& maps = *id_mappings_.mutable_maps(); | ||
| 204 | auto& rooms = *maps[current_map_name].mutable_rooms(); | ||
| 205 | auto& keyholders = *rooms[h_room.name()].mutable_keyholders(); | ||
| 206 | keyholders[h_keyholder.name()] = next_id_++; | 238 | keyholders[h_keyholder.name()] = next_id_++; |
| 239 | } else { | ||
| 240 | keyholders[h_keyholder.name()] = id_mappings_.maps() | ||
| 241 | .at(current_map_name) | ||
| 242 | .rooms() | ||
| 243 | .at(h_room.name()) | ||
| 244 | .keyholders() | ||
| 245 | .at(h_keyholder.name()); | ||
| 207 | } | 246 | } |
| 208 | } | 247 | } |
| 209 | } | 248 | } |
| 210 | 249 | ||
| 250 | void ProcessSpecialIds() { | ||
| 251 | auto& specials = *output_.mutable_special(); | ||
| 252 | |||
| 253 | for (const auto& [special_name, ap_id] : id_mappings_.special()) { | ||
| 254 | specials[special_name] = ap_id; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 211 | void ProcessProgressivesFile(std::filesystem::path path) { | 258 | void ProcessProgressivesFile(std::filesystem::path path) { |
| 212 | if (!std::filesystem::exists(path)) { | 259 | if (!std::filesystem::exists(path)) { |
| 213 | return; | 260 | return; |
| 214 | } | 261 | } |
| 215 | 262 | ||
| 216 | auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string()); | 263 | auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string()); |
| 217 | auto& progs = *id_mappings_.mutable_progressives(); | 264 | auto& progs = *output_.mutable_progressives(); |
| 218 | 265 | ||
| 219 | for (const HumanProgressive& h_prog : h_progs.progressives()) { | 266 | for (const HumanProgressive& h_prog : h_progs.progressives()) { |
| 220 | if (!progs.contains(h_prog.name())) { | 267 | if (!id_mappings_.progressives().contains(h_prog.name())) { |
| 221 | progs[h_prog.name()] = next_id_++; | 268 | progs[h_prog.name()] = next_id_++; |
| 269 | } else { | ||
| 270 | progs[h_prog.name()] = id_mappings_.progressives().at(h_prog.name()); | ||
| 271 | } | ||
| 272 | } | ||
| 273 | } | ||
| 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); | ||
| 222 | } | 305 | } |
| 223 | } | 306 | } |
| 224 | } | 307 | } |
| @@ -237,6 +320,7 @@ class AssignIds { | |||
| 237 | uint64_t next_id_ = 1; | 320 | uint64_t next_id_ = 1; |
| 238 | 321 | ||
| 239 | IdMappings id_mappings_; | 322 | IdMappings id_mappings_; |
| 323 | IdMappings output_; | ||
| 240 | }; | 324 | }; |
| 241 | 325 | ||
| 242 | } // namespace | 326 | } // namespace |
