about summary refs log tree commit diff stats
path: root/tools/assign_ids
diff options
context:
space:
mode:
Diffstat (limited to 'tools/assign_ids')
-rw-r--r--tools/assign_ids/main.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index 3e16f78..4a48b86 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp
@@ -65,6 +65,11 @@ class AssignIds {
65 UpdateNextId(room.panels()); 65 UpdateNextId(room.panels());
66 UpdateNextId(room.masteries()); 66 UpdateNextId(room.masteries());
67 UpdateNextId(room.keyholders()); 67 UpdateNextId(room.keyholders());
68 UpdateNextId(room.ports());
69 }
70
71 if (map.has_rte()) {
72 UpdateNextId(map.rte());
68 } 73 }
69 } 74 }
70 75
@@ -92,10 +97,31 @@ class AssignIds {
92 void ProcessMap(std::filesystem::path path) { 97 void ProcessMap(std::filesystem::path path) {
93 std::string map_name = path.filename().string(); 98 std::string map_name = path.filename().string();
94 99
100 ProcessMapMetadata(path / "metadata.txtpb", map_name);
95 ProcessDoorsFile(path / "doors.txtpb", map_name); 101 ProcessDoorsFile(path / "doors.txtpb", map_name);
96 ProcessRooms(path / "rooms", map_name); 102 ProcessRooms(path / "rooms", map_name);
97 } 103 }
98 104
105 void ProcessMapMetadata(std::filesystem::path path,
106 const std::string& current_map_name) {
107 if (!std::filesystem::exists(path)) {
108 return;
109 }
110
111 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
112 auto& maps = *output_.mutable_maps();
113
114 if (metadata.has_rte_room()) {
115 if (!id_mappings_.maps().contains(current_map_name) ||
116 !id_mappings_.maps().at(current_map_name).has_rte()) {
117 maps[current_map_name].set_rte(next_id_++);
118 } else {
119 maps[current_map_name].set_rte(
120 id_mappings_.maps().at(current_map_name).rte());
121 }
122 }
123 }
124
99 void ProcessDoorsFile(std::filesystem::path path, 125 void ProcessDoorsFile(std::filesystem::path path,
100 const std::string& current_map_name) { 126 const std::string& current_map_name) {
101 if (!std::filesystem::exists(path)) { 127 if (!std::filesystem::exists(path)) {
@@ -111,7 +137,8 @@ class AssignIds {
111 137
112 void ProcessDoor(const HumanDoor& h_door, 138 void ProcessDoor(const HumanDoor& h_door,
113 const std::string& current_map_name) { 139 const std::string& current_map_name) {
114 if (h_door.type() == DoorType::EVENT) { 140 if (h_door.type() == DoorType::EVENT && !h_door.latch() &&
141 !h_door.legacy_location()) {
115 return; 142 return;
116 } 143 }
117 144
@@ -245,6 +272,37 @@ class AssignIds {
245 .at(h_keyholder.name()); 272 .at(h_keyholder.name());
246 } 273 }
247 } 274 }
275
276 for (const HumanPort& h_port : h_room.ports()) {
277 if (h_port.no_shuffle()) {
278 continue;
279 }
280
281 auto& maps = *output_.mutable_maps();
282 auto& rooms = *maps[current_map_name].mutable_rooms();
283 auto& ports = *rooms[h_room.name()].mutable_ports();
284
285 if (!id_mappings_.maps().contains(current_map_name) ||
286 !id_mappings_.maps()
287 .at(current_map_name)
288 .rooms()
289 .contains(h_room.name()) ||
290 !id_mappings_.maps()
291 .at(current_map_name)
292 .rooms()
293 .at(h_room.name())
294 .ports()
295 .contains(h_port.name())) {
296 ports[h_port.name()] = next_id_++;
297 } else {
298 ports[h_port.name()] = id_mappings_.maps()
299 .at(current_map_name)
300 .rooms()
301 .at(h_room.name())
302 .ports()
303 .at(h_port.name());
304 }
305 }
248 } 306 }
249 307
250 void ProcessSpecialIds() { 308 void ProcessSpecialIds() {
@@ -309,9 +367,13 @@ class AssignIds {
309 private: 367 private:
310 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) { 368 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) {
311 for (const auto& [_, id] : ids) { 369 for (const auto& [_, id] : ids) {
312 if (id > next_id_) { 370 UpdateNextId(id);
313 next_id_ = id; 371 }
314 } 372 }
373
374 void UpdateNextId(uint64_t id) {
375 if (id > next_id_) {
376 next_id_ = id;
315 } 377 }
316 } 378 }
317 379