about summary refs log tree commit diff stats
path: root/tools/assign_ids/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assign_ids/main.cpp')
-rw-r--r--tools/assign_ids/main.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index d212767..4cf7c3f 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>
@@ -43,6 +44,7 @@ class AssignIds {
43 ProcessSpecialIds(); 44 ProcessSpecialIds();
44 ProcessProgressivesFile(datadir_path / "progressives.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
45 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb"); 46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb");
46 48
47 WriteIds(ids_path); 49 WriteIds(ids_path);
48 50
@@ -63,6 +65,7 @@ class AssignIds {
63 UpdateNextId(room.panels()); 65 UpdateNextId(room.panels());
64 UpdateNextId(room.masteries()); 66 UpdateNextId(room.masteries());
65 UpdateNextId(room.keyholders()); 67 UpdateNextId(room.keyholders());
68 UpdateNextId(room.ports());
66 } 69 }
67 } 70 }
68 71
@@ -109,7 +112,8 @@ class AssignIds {
109 112
110 void ProcessDoor(const HumanDoor& h_door, 113 void ProcessDoor(const HumanDoor& h_door,
111 const std::string& current_map_name) { 114 const std::string& current_map_name) {
112 if (h_door.type() == DoorType::EVENT) { 115 if (h_door.type() == DoorType::EVENT && !h_door.latch() &&
116 !h_door.legacy_location()) {
113 return; 117 return;
114 } 118 }
115 119
@@ -243,6 +247,37 @@ class AssignIds {
243 .at(h_keyholder.name()); 247 .at(h_keyholder.name());
244 } 248 }
245 } 249 }
250
251 for (const HumanPort& h_port : h_room.ports()) {
252 if (h_port.no_shuffle()) {
253 continue;
254 }
255
256 auto& maps = *output_.mutable_maps();
257 auto& rooms = *maps[current_map_name].mutable_rooms();
258 auto& ports = *rooms[h_room.name()].mutable_ports();
259
260 if (!id_mappings_.maps().contains(current_map_name) ||
261 !id_mappings_.maps()
262 .at(current_map_name)
263 .rooms()
264 .contains(h_room.name()) ||
265 !id_mappings_.maps()
266 .at(current_map_name)
267 .rooms()
268 .at(h_room.name())
269 .ports()
270 .contains(h_port.name())) {
271 ports[h_port.name()] = next_id_++;
272 } else {
273 ports[h_port.name()] = id_mappings_.maps()
274 .at(current_map_name)
275 .rooms()
276 .at(h_room.name())
277 .ports()
278 .at(h_port.name());
279 }
280 }
246 } 281 }
247 282
248 void ProcessSpecialIds() { 283 void ProcessSpecialIds() {
@@ -287,6 +322,23 @@ class AssignIds {
287 } 322 }
288 } 323 }
289 324
325 void ProcessGlobalMetadataFile(std::filesystem::path path) {
326 if (!std::filesystem::exists(path)) {
327 return;
328 }
329
330 auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string());
331 auto& specials = *output_.mutable_special();
332
333 for (const std::string& h_special : h_metadata.special_names()) {
334 if (!id_mappings_.special().contains(h_special)) {
335 specials[h_special] = next_id_++;
336 } else {
337 specials[h_special] = id_mappings_.special().at(h_special);
338 }
339 }
340 }
341
290 private: 342 private:
291 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) { 343 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) {
292 for (const auto& [_, id] : ids) { 344 for (const auto& [_, id] : ids) {