about summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/assign_ids/main.cpp211
-rw-r--r--tools/datapacker/container.cpp54
-rw-r--r--tools/datapacker/container.h9
-rw-r--r--tools/datapacker/main.cpp162
-rw-r--r--tools/util/CMakeLists.txt8
-rw-r--r--tools/util/godot_scene.cpp207
-rw-r--r--tools/util/godot_scene.h57
-rw-r--r--tools/util/identifiers.cpp102
-rw-r--r--tools/util/identifiers.h85
-rw-r--r--tools/util/ids_yaml_format.cpp190
-rw-r--r--tools/util/ids_yaml_format.h16
-rw-r--r--tools/util/naming.cpp4
-rw-r--r--tools/util/naming.h4
-rw-r--r--tools/validator/CMakeLists.txt13
-rw-r--r--tools/validator/godot_processor.cpp72
-rw-r--r--tools/validator/godot_processor.h14
-rw-r--r--tools/validator/human_processor.cpp640
-rw-r--r--tools/validator/human_processor.h14
-rw-r--r--tools/validator/main.cpp34
-rw-r--r--tools/validator/structs.h147
-rw-r--r--tools/validator/validator.cpp550
-rw-r--r--tools/validator/validator.h12
22 files changed, 2547 insertions, 58 deletions
diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index 2617cf7..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>
@@ -9,6 +10,7 @@
9#include <string> 10#include <string>
10 11
11#include "proto/human.pb.h" 12#include "proto/human.pb.h"
13#include "util/ids_yaml_format.h"
12#include "util/naming.h" 14#include "util/naming.h"
13 15
14namespace com::fourisland::lingo2_archipelago { 16namespace com::fourisland::lingo2_archipelago {
@@ -34,11 +36,15 @@ class AssignIds {
34 36
35 void Run() { 37 void Run() {
36 std::filesystem::path datadir_path = mapdir_; 38 std::filesystem::path datadir_path = mapdir_;
37 std::filesystem::path ids_path = datadir_path / "ids.txtpb"; 39 std::filesystem::path ids_path = datadir_path / "ids.yaml";
38 40
39 ReadIds(ids_path); 41 ReadIds(ids_path);
40 42
41 ProcessMaps(datadir_path); 43 ProcessMaps(datadir_path);
44 ProcessSpecialIds();
45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb");
42 48
43 WriteIds(ids_path); 49 WriteIds(ids_path);
44 50
@@ -46,53 +52,33 @@ class AssignIds {
46 } 52 }
47 53
48 void ReadIds(std::filesystem::path path) { 54 void ReadIds(std::filesystem::path path) {
49 id_mappings_ = ReadMessageFromFile<IdMappings>(path.string()); 55 if (!std::filesystem::exists(path)) {
56 return;
57 }
58
59 id_mappings_ = ReadIdsFromYaml(path.string());
50 60
51 for (const auto& [_, map] : id_mappings_.maps()) { 61 for (const auto& [_, map] : id_mappings_.maps()) {
52 for (const auto& [_, id] : map.doors()) { 62 UpdateNextId(map.doors());
53 if (id > next_id_) {
54 next_id_ = id;
55 }
56 }
57 63
58 for (const auto& [_, room] : map.rooms()) { 64 for (const auto& [_, room] : map.rooms()) {
59 for (const auto& [_, id] : room.panels()) { 65 UpdateNextId(room.panels());
60 if (id > next_id_) { 66 UpdateNextId(room.masteries());
61 next_id_ = id; 67 UpdateNextId(room.keyholders());
62 }
63 }
64
65 for (const auto& [_, id] : room.masteries()) {
66 if (id > next_id_) {
67 next_id_ = id;
68 }
69 }
70 } 68 }
71 } 69 }
72 70
73 for (const auto& [_, id] : id_mappings_.special()) { 71 UpdateNextId(id_mappings_.special());
74 if (id > next_id_) { 72 UpdateNextId(id_mappings_.letters());
75 next_id_ = id; 73 UpdateNextId(id_mappings_.endings());
76 } 74 UpdateNextId(id_mappings_.progressives());
77 } 75 UpdateNextId(id_mappings_.door_groups());
78
79 for (const auto& [_, id] : id_mappings_.letters()) {
80 if (id > next_id_) {
81 next_id_ = id;
82 }
83 }
84 76
85 next_id_++; 77 next_id_++;
86 } 78 }
87 79
88 void WriteIds(std::filesystem::path path) { 80 void WriteIds(std::filesystem::path path) {
89 std::string output; 81 WriteIdsAsYaml(output_, path.string());
90 google::protobuf::TextFormat::PrintToString(id_mappings_, &output);
91
92 {
93 std::ofstream outputfile(path.string());
94 outputfile << output;
95 }
96 } 82 }
97 83
98 void ProcessMaps(std::filesystem::path path) { 84 void ProcessMaps(std::filesystem::path path) {
@@ -104,7 +90,7 @@ class AssignIds {
104 } 90 }
105 91
106 void ProcessMap(std::filesystem::path path) { 92 void ProcessMap(std::filesystem::path path) {
107 std::string map_name = path.filename(); 93 std::string map_name = path.filename().string();
108 94
109 ProcessDoorsFile(path / "doors.txtpb", map_name); 95 ProcessDoorsFile(path / "doors.txtpb", map_name);
110 ProcessRooms(path / "rooms", map_name); 96 ProcessRooms(path / "rooms", map_name);
@@ -129,14 +115,18 @@ class AssignIds {
129 return; 115 return;
130 } 116 }
131 117
118 auto& maps = *output_.mutable_maps();
119 auto& doors = *maps[current_map_name].mutable_doors();
120
132 if (!id_mappings_.maps().contains(current_map_name) || 121 if (!id_mappings_.maps().contains(current_map_name) ||
133 !id_mappings_.maps() 122 !id_mappings_.maps()
134 .at(current_map_name) 123 .at(current_map_name)
135 .doors() 124 .doors()
136 .contains(h_door.name())) { 125 .contains(h_door.name())) {
137 auto& maps = *id_mappings_.mutable_maps();
138 auto& doors = *maps[current_map_name].mutable_doors();
139 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());
140 } 130 }
141 } 131 }
142 132
@@ -151,6 +141,10 @@ class AssignIds {
151 void ProcessRoom(const HumanRoom& h_room, 141 void ProcessRoom(const HumanRoom& h_room,
152 const std::string& current_map_name) { 142 const std::string& current_map_name) {
153 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
154 if (!id_mappings_.maps().contains(current_map_name) || 148 if (!id_mappings_.maps().contains(current_map_name) ||
155 !id_mappings_.maps() 149 !id_mappings_.maps()
156 .at(current_map_name) 150 .at(current_map_name)
@@ -162,23 +156,33 @@ class AssignIds {
162 .at(h_room.name()) 156 .at(h_room.name())
163 .panels() 157 .panels()
164 .contains(h_panel.name())) { 158 .contains(h_panel.name())) {
165 auto& maps = *id_mappings_.mutable_maps();
166 auto& rooms = *maps[current_map_name].mutable_rooms();
167 auto& panels = *rooms[h_room.name()].mutable_panels();
168 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());
169 } 167 }
170 } 168 }
171 169
172 for (const HumanLetter& h_letter : h_room.letters()) { 170 for (const HumanLetter& h_letter : h_room.letters()) {
173 std::string lettername = GetLetterName(h_letter.key(), h_letter.level2()); 171 std::string lettername = GetLetterName(h_letter.key(), h_letter.level2());
174 172
173 auto& letters = *output_.mutable_letters();
175 if (!id_mappings_.letters().contains(lettername)) { 174 if (!id_mappings_.letters().contains(lettername)) {
176 auto& letters = *id_mappings_.mutable_letters();
177 letters[lettername] = next_id_++; 175 letters[lettername] = next_id_++;
176 } else {
177 letters[lettername] = id_mappings_.letters().at(lettername);
178 } 178 }
179 } 179 }
180 180
181 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
182 if (!id_mappings_.maps().contains(current_map_name) || 186 if (!id_mappings_.maps().contains(current_map_name) ||
183 !id_mappings_.maps() 187 !id_mappings_.maps()
184 .at(current_map_name) 188 .at(current_map_name)
@@ -190,20 +194,133 @@ class AssignIds {
190 .at(h_room.name()) 194 .at(h_room.name())
191 .masteries() 195 .masteries()
192 .contains(h_mastery.name())) { 196 .contains(h_mastery.name())) {
193 auto& maps = *id_mappings_.mutable_maps();
194 auto& rooms = *maps[current_map_name].mutable_rooms();
195 auto& masteries = *rooms[h_room.name()].mutable_masteries();
196 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());
205 }
206 }
207
208 for (const HumanEnding& h_ending : h_room.endings()) {
209 auto& endings = *output_.mutable_endings();
210
211 if (!id_mappings_.endings().contains(h_ending.name())) {
212 endings[h_ending.name()] = next_id_++;
213 } else {
214 endings[h_ending.name()] = id_mappings_.endings().at(h_ending.name());
215 }
216 }
217
218 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
219 if (!h_keyholder.has_key()) {
220 continue;
221 }
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
227 if (!id_mappings_.maps().contains(current_map_name) ||
228 !id_mappings_.maps()
229 .at(current_map_name)
230 .rooms()
231 .contains(h_room.name()) ||
232 !id_mappings_.maps()
233 .at(current_map_name)
234 .rooms()
235 .at(h_room.name())
236 .keyholders()
237 .contains(h_keyholder.name())) {
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());
246 }
247 }
248 }
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
258 void ProcessProgressivesFile(std::filesystem::path path) {
259 if (!std::filesystem::exists(path)) {
260 return;
261 }
262
263 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
264 auto& progs = *output_.mutable_progressives();
265
266 for (const HumanProgressive& h_prog : h_progs.progressives()) {
267 if (!id_mappings_.progressives().contains(h_prog.name())) {
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);
197 } 305 }
198 } 306 }
199 } 307 }
200 308
201 private: 309 private:
310 void UpdateNextId(const google::protobuf::Map<std::string, uint64_t>& ids) {
311 for (const auto& [_, id] : ids) {
312 if (id > next_id_) {
313 next_id_ = id;
314 }
315 }
316 }
317
202 std::string mapdir_; 318 std::string mapdir_;
203 319
204 uint64_t next_id_ = 0; 320 uint64_t next_id_ = 1;
205 321
206 IdMappings id_mappings_; 322 IdMappings id_mappings_;
323 IdMappings output_;
207}; 324};
208 325
209} // namespace 326} // namespace
diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp index ffcb75a..4a656b3 100644 --- a/tools/datapacker/container.cpp +++ b/tools/datapacker/container.cpp
@@ -79,7 +79,7 @@ uint64_t Container::FindOrAddPainting(
79 auto it = room_container.find(painting_name); 79 auto it = room_container.find(painting_name);
80 if (it == room_container.end()) { 80 if (it == room_container.end()) {
81 uint64_t new_id = all_objects_.paintings_size(); 81 uint64_t new_id = all_objects_.paintings_size();
82 Painting* painting = all_objects_.add_paintings(); 82 PaintingData* painting = all_objects_.add_paintings();
83 painting->set_id(new_id); 83 painting->set_id(new_id);
84 painting->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); 84 painting->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt));
85 painting->set_name(painting_name); 85 painting->set_name(painting_name);
@@ -205,6 +205,22 @@ uint64_t Container::FindLetterByName(std::string letter_name) {
205 } 205 }
206} 206}
207 207
208uint64_t Container::FindOrAddEnding(std::string ending_name) {
209 auto it = ending_id_by_name_.find(ending_name);
210 if (it == ending_id_by_name_.end()) {
211 uint64_t new_id = all_objects_.endings_size();
212 Ending* ending = all_objects_.add_endings();
213 ending->set_id(new_id);
214 ending->set_name(ending_name);
215
216 ending_id_by_name_[ending_name] = new_id;
217
218 return new_id;
219 } else {
220 return it->second;
221 }
222}
223
208uint64_t Container::FindOrAddMastery(std::optional<std::string> map_name, 224uint64_t Container::FindOrAddMastery(std::optional<std::string> map_name,
209 std::optional<std::string> room_name, 225 std::optional<std::string> room_name,
210 std::string mastery_name, 226 std::string mastery_name,
@@ -273,7 +289,7 @@ uint64_t Container::FindOrAddKeyholder(
273 auto it = room_container.find(keyholder_name); 289 auto it = room_container.find(keyholder_name);
274 if (it == room_container.end()) { 290 if (it == room_container.end()) {
275 uint64_t new_id = all_objects_.keyholders_size(); 291 uint64_t new_id = all_objects_.keyholders_size();
276 Keyholder* keyholder = all_objects_.add_keyholders(); 292 KeyholderData* keyholder = all_objects_.add_keyholders();
277 keyholder->set_id(new_id); 293 keyholder->set_id(new_id);
278 keyholder->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); 294 keyholder->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt));
279 keyholder->set_name(keyholder_name); 295 keyholder->set_name(keyholder_name);
@@ -315,6 +331,40 @@ uint64_t Container::FindOrAddDoor(std::optional<std::string> map_name,
315 } 331 }
316} 332}
317 333
334uint64_t Container::FindOrAddProgressive(std::string prog_name) {
335 auto it = progressive_id_by_name_.find(prog_name);
336
337 if (it == progressive_id_by_name_.end()) {
338 uint64_t new_id = all_objects_.progressives_size();
339 Progressive* progressive = all_objects_.add_progressives();
340 progressive->set_id(new_id);
341 progressive->set_name(prog_name);
342
343 progressive_id_by_name_[prog_name] = new_id;
344
345 return new_id;
346 } else {
347 return it->second;
348 }
349}
350
351uint64_t Container::FindOrAddDoorGroup(std::string group_name) {
352 auto it = door_group_id_by_name_.find(group_name);
353
354 if (it == door_group_id_by_name_.end()) {
355 uint64_t new_id = all_objects_.door_groups_size();
356 DoorGroup* door_group = all_objects_.add_door_groups();
357 door_group->set_id(new_id);
358 door_group->set_name(group_name);
359
360 door_group_id_by_name_[group_name] = new_id;
361
362 return new_id;
363 } else {
364 return it->second;
365 }
366}
367
318void Container::AddConnection(const Connection& connection) { 368void Container::AddConnection(const Connection& connection) {
319 *all_objects_.add_connections() = connection; 369 *all_objects_.add_connections() = connection;
320} 370}
diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h index e1a84d8..bc02ba4 100644 --- a/tools/datapacker/container.h +++ b/tools/datapacker/container.h
@@ -40,6 +40,8 @@ class Container {
40 40
41 uint64_t FindLetterByName(std::string letter_name); 41 uint64_t FindLetterByName(std::string letter_name);
42 42
43 uint64_t FindOrAddEnding(std::string ending_name);
44
43 uint64_t FindOrAddMastery(std::optional<std::string> map_name, 45 uint64_t FindOrAddMastery(std::optional<std::string> map_name,
44 std::optional<std::string> room_name, 46 std::optional<std::string> room_name,
45 std::string mastery_name, 47 std::string mastery_name,
@@ -58,6 +60,10 @@ class Container {
58 60
59 void AddConnection(const Connection& connection); 61 void AddConnection(const Connection& connection);
60 62
63 uint64_t FindOrAddProgressive(std::string prog_name);
64
65 uint64_t FindOrAddDoorGroup(std::string group_name);
66
61 AllObjects& all_objects() { return all_objects_; } 67 AllObjects& all_objects() { return all_objects_; }
62 68
63 private: 69 private:
@@ -79,6 +85,9 @@ class Container {
79 keyholder_id_by_map_room_keyholder_names_; 85 keyholder_id_by_map_room_keyholder_names_;
80 std::map<std::string, std::map<std::string, uint64_t>> 86 std::map<std::string, std::map<std::string, uint64_t>>
81 door_id_by_map_door_names_; 87 door_id_by_map_door_names_;
88 std::map<std::string, uint64_t> ending_id_by_name_;
89 std::map<std::string, uint64_t> progressive_id_by_name_;
90 std::map<std::string, uint64_t> door_group_id_by_name_;
82}; 91};
83 92
84} // namespace com::fourisland::lingo2_archipelago 93} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index 1736ec1..6bbb461 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp
@@ -14,6 +14,7 @@
14#include "container.h" 14#include "container.h"
15#include "proto/data.pb.h" 15#include "proto/data.pb.h"
16#include "proto/human.pb.h" 16#include "proto/human.pb.h"
17#include "util/ids_yaml_format.h"
17 18
18namespace com::fourisland::lingo2_archipelago { 19namespace com::fourisland::lingo2_archipelago {
19namespace { 20namespace {
@@ -42,7 +43,10 @@ class DataPacker {
42 43
43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 44 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
44 ProcessMaps(datadir_path); 45 ProcessMaps(datadir_path);
45 ProcessIdsFile(datadir_path / "ids.txtpb"); 46 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
47 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
48 ProcessGlobalMetadataFile(datadir_path / "metadata.txtpb");
49 ProcessIdsFile(datadir_path / "ids.yaml");
46 50
47 { 51 {
48 std::ofstream outputfile(outputpath_); 52 std::ofstream outputfile(outputpath_);
@@ -65,13 +69,30 @@ class DataPacker {
65 } 69 }
66 70
67 void ProcessMap(std::filesystem::path path) { 71 void ProcessMap(std::filesystem::path path) {
68 std::string map_name = path.filename(); 72 std::string map_name = path.filename().string();
69 73
74 ProcessMapMetadataFile(path / "metadata.txtpb", map_name);
70 ProcessConnectionsFile(path / "connections.txtpb", map_name); 75 ProcessConnectionsFile(path / "connections.txtpb", map_name);
71 ProcessDoorsFile(path / "doors.txtpb", map_name); 76 ProcessDoorsFile(path / "doors.txtpb", map_name);
72 ProcessRooms(path / "rooms", map_name); 77 ProcessRooms(path / "rooms", map_name);
73 } 78 }
74 79
80 void ProcessMapMetadataFile(std::filesystem::path path,
81 const std::string& map_name) {
82 if (!std::filesystem::exists(path)) {
83 return;
84 }
85
86 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
87
88 uint64_t map_id = container_.FindOrAddMap(map_name);
89 Map& map = *container_.all_objects().mutable_maps(map_id);
90
91 if (metadata.has_display_name()) {
92 map.set_display_name(metadata.display_name());
93 }
94 }
95
75 void ProcessRooms(std::filesystem::path path, 96 void ProcessRooms(std::filesystem::path path,
76 const std::string& current_map_name) { 97 const std::string& current_map_name) {
77 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) { 98 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
@@ -86,7 +107,11 @@ class DataPacker {
86 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); 107 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt);
87 Room& room = *container_.all_objects().mutable_rooms(room_id); 108 Room& room = *container_.all_objects().mutable_rooms(room_id);
88 109
89 room.set_display_name(h_room.display_name()); 110 // room.set_display_name(h_room.display_name());
111
112 if (h_room.has_panel_display_name()) {
113 room.set_panel_display_name(h_room.panel_display_name());
114 }
90 115
91 for (const HumanPanel& h_panel : h_room.panels()) { 116 for (const HumanPanel& h_panel : h_room.panels()) {
92 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name())); 117 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name()));
@@ -114,6 +139,10 @@ class DataPacker {
114 room.add_keyholders( 139 room.add_keyholders(
115 ProcessKeyholder(h_keyholder, current_map_name, room.name())); 140 ProcessKeyholder(h_keyholder, current_map_name, room.name()));
116 } 141 }
142
143 for (const HumanEnding& h_ending : h_room.endings()) {
144 room.add_endings(ProcessEnding(h_ending, current_map_name, room.name()));
145 }
117 } 146 }
118 147
119 uint64_t ProcessPanel(const HumanPanel& h_panel, 148 uint64_t ProcessPanel(const HumanPanel& h_panel,
@@ -153,6 +182,10 @@ class DataPacker {
153 map_name, h_panel.required_room().name(), current_map_name)); 182 map_name, h_panel.required_room().name(), current_map_name));
154 } 183 }
155 184
185 if (h_panel.has_display_name()) {
186 panel.set_display_name(h_panel.display_name());
187 }
188
156 return panel_id; 189 return panel_id;
157 } 190 }
158 191
@@ -162,7 +195,7 @@ class DataPacker {
162 uint64_t painting_id = container_.FindOrAddPainting( 195 uint64_t painting_id = container_.FindOrAddPainting(
163 current_map_name, current_room_name, h_painting.name(), std::nullopt, 196 current_map_name, current_room_name, h_painting.name(), std::nullopt,
164 std::nullopt); 197 std::nullopt);
165 Painting& painting = 198 PaintingData& painting =
166 *container_.all_objects().mutable_paintings(painting_id); 199 *container_.all_objects().mutable_paintings(painting_id);
167 200
168 painting.set_path(h_painting.path()); 201 painting.set_path(h_painting.path());
@@ -257,14 +290,31 @@ class DataPacker {
257 uint64_t keyholder_id = container_.FindOrAddKeyholder( 290 uint64_t keyholder_id = container_.FindOrAddKeyholder(
258 current_map_name, current_room_name, h_keyholder.name(), std::nullopt, 291 current_map_name, current_room_name, h_keyholder.name(), std::nullopt,
259 std::nullopt); 292 std::nullopt);
260 Keyholder& keyholder = 293 KeyholderData& keyholder =
261 *container_.all_objects().mutable_keyholders(keyholder_id); 294 *container_.all_objects().mutable_keyholders(keyholder_id);
262 295
263 keyholder.set_path(h_keyholder.path()); 296 keyholder.set_path(h_keyholder.path());
264 297
298 if (h_keyholder.has_key()) {
299 keyholder.set_key(h_keyholder.key());
300 }
301
265 return keyholder_id; 302 return keyholder_id;
266 } 303 }
267 304
305 uint64_t ProcessEnding(const HumanEnding& h_ending,
306 const std::string& current_map_name,
307 const std::string& current_room_name) {
308 uint64_t ending_id = container_.FindOrAddEnding(h_ending.name());
309 Ending& ending = *container_.all_objects().mutable_endings(ending_id);
310
311 ending.set_room_id(container_.FindOrAddRoom(
312 current_map_name, current_room_name, std::nullopt));
313 ending.set_path(h_ending.path());
314
315 return ending_id;
316 }
317
268 void ProcessDoorsFile(std::filesystem::path path, 318 void ProcessDoorsFile(std::filesystem::path path,
269 const std::string& current_map_name) { 319 const std::string& current_map_name) {
270 if (!std::filesystem::exists(path)) { 320 if (!std::filesystem::exists(path)) {
@@ -295,9 +345,6 @@ class DataPacker {
295 std::copy( 345 std::copy(
296 h_door.receivers().begin(), h_door.receivers().end(), 346 h_door.receivers().begin(), h_door.receivers().end(),
297 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers())); 347 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers()));
298 std::copy(
299 h_door.switches().begin(), h_door.switches().end(),
300 google::protobuf::RepeatedFieldBackInserter(door.mutable_switches()));
301 348
302 for (const PaintingIdentifier& pi : h_door.move_paintings()) { 349 for (const PaintingIdentifier& pi : h_door.move_paintings()) {
303 std::optional<std::string> map_name = 350 std::optional<std::string> map_name =
@@ -346,6 +393,10 @@ class DataPacker {
346 container_.FindOrAddDoor(map_name, di.name(), current_map_name)); 393 container_.FindOrAddDoor(map_name, di.name(), current_map_name));
347 } 394 }
348 395
396 for (const std::string& ending_name : h_door.endings()) {
397 door.add_endings(container_.FindOrAddEnding(ending_name));
398 }
399
349 if (h_door.has_control_center_color()) { 400 if (h_door.has_control_center_color()) {
350 door.set_control_center_color(h_door.control_center_color()); 401 door.set_control_center_color(h_door.control_center_color());
351 } 402 }
@@ -355,6 +406,14 @@ class DataPacker {
355 } 406 }
356 407
357 door.set_type(h_door.type()); 408 door.set_type(h_door.type());
409
410 if (h_door.has_location_name()) {
411 door.set_location_name(h_door.location_name());
412 }
413
414 if (h_door.has_double_letters()) {
415 door.set_double_letters(h_door.double_letters());
416 }
358 } 417 }
359 418
360 void ProcessConnectionsFile(std::filesystem::path path, 419 void ProcessConnectionsFile(std::filesystem::path path,
@@ -406,6 +465,11 @@ class DataPacker {
406 r_connection.set_required_door(door_id); 465 r_connection.set_required_door(door_id);
407 } 466 }
408 467
468 if (human_connection.has_roof_access()) {
469 f_connection.set_roof_access(human_connection.roof_access());
470 r_connection.set_roof_access(human_connection.roof_access());
471 }
472
409 container_.AddConnection(f_connection); 473 container_.AddConnection(f_connection);
410 if (!human_connection.oneway()) { 474 if (!human_connection.oneway()) {
411 container_.AddConnection(r_connection); 475 container_.AddConnection(r_connection);
@@ -489,8 +553,65 @@ class DataPacker {
489 } 553 }
490 } 554 }
491 555
556 void ProcessProgressivesFile(std::filesystem::path path) {
557 if (!std::filesystem::exists(path)) {
558 return;
559 }
560
561 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
562
563 for (const HumanProgressive& h_prog : h_progs.progressives()) {
564 ProcessProgressive(h_prog);
565 }
566 }
567
568 void ProcessProgressive(const HumanProgressive& h_prog) {
569 uint64_t prog_id = container_.FindOrAddProgressive(h_prog.name());
570 Progressive& prog = *container_.all_objects().mutable_progressives(prog_id);
571
572 for (const DoorIdentifier& di : h_prog.doors()) {
573 uint64_t door_id =
574 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
575 prog.add_doors(door_id);
576 }
577 }
578
579 void ProcessDoorGroupsFile(std::filesystem::path path) {
580 if (!std::filesystem::exists(path)) {
581 return;
582 }
583
584 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
585
586 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
587 ProcessDoorGroup(h_group);
588 }
589 }
590
591 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
592 uint64_t group_id = container_.FindOrAddDoorGroup(h_group.name());
593 DoorGroup& group = *container_.all_objects().mutable_door_groups(group_id);
594
595 group.set_type(h_group.type());
596
597 for (const DoorIdentifier& di : h_group.doors()) {
598 uint64_t door_id =
599 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
600 group.add_doors(door_id);
601 }
602 }
603
604 void ProcessGlobalMetadataFile(std::filesystem::path path) {
605 if (!std::filesystem::exists(path)) {
606 return;
607 }
608
609 auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string());
610 container_.all_objects().set_version(h_metadata.version());
611 }
612
492 void ProcessIdsFile(std::filesystem::path path) { 613 void ProcessIdsFile(std::filesystem::path path) {
493 auto ids = ReadMessageFromFile<IdMappings>(path.string()); 614 auto ids = ReadIdsFromYaml(path.string());
494 615
495 for (const auto& [map_name, map] : ids.maps()) { 616 for (const auto& [map_name, map] : ids.maps()) {
496 for (const auto& [door_name, ap_id] : map.doors()) { 617 for (const auto& [door_name, ap_id] : map.doors()) {
@@ -513,6 +634,14 @@ class DataPacker {
513 .mutable_masteries(mastery_id) 634 .mutable_masteries(mastery_id)
514 ->set_ap_id(ap_id); 635 ->set_ap_id(ap_id);
515 } 636 }
637
638 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
639 uint64_t keyholder_id = container_.FindOrAddKeyholder(
640 map_name, room_name, keyholder_name, std::nullopt, std::nullopt);
641 container_.all_objects()
642 .mutable_keyholders(keyholder_id)
643 ->set_ap_id(ap_id);
644 }
516 } 645 }
517 } 646 }
518 647
@@ -525,6 +654,21 @@ class DataPacker {
525 uint64_t letter_id = container_.FindLetterByName(letter_name); 654 uint64_t letter_id = container_.FindLetterByName(letter_name);
526 container_.all_objects().mutable_letters(letter_id)->set_ap_id(ap_id); 655 container_.all_objects().mutable_letters(letter_id)->set_ap_id(ap_id);
527 } 656 }
657
658 for (const auto& [ending_name, ap_id] : ids.endings()) {
659 uint64_t ending_id = container_.FindOrAddEnding(ending_name);
660 container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id);
661 }
662
663 for (const auto& [prog_name, ap_id] : ids.progressives()) {
664 uint64_t prog_id = container_.FindOrAddProgressive(prog_name);
665 container_.all_objects().mutable_progressives(prog_id)->set_ap_id(ap_id);
666 }
667
668 for (const auto& [group_name, ap_id] : ids.door_groups()) {
669 uint64_t group_id = container_.FindOrAddDoorGroup(group_name);
670 container_.all_objects().mutable_door_groups(group_id)->set_ap_id(ap_id);
671 }
528 } 672 }
529 673
530 std::string mapdir_; 674 std::string mapdir_;
diff --git a/tools/util/CMakeLists.txt b/tools/util/CMakeLists.txt index 8eb8d3b..0859a58 100644 --- a/tools/util/CMakeLists.txt +++ b/tools/util/CMakeLists.txt
@@ -1,5 +1,13 @@
1find_package(Protobuf REQUIRED)
2find_package(yaml-cpp REQUIRED)
3
1add_library(util 4add_library(util
5 godot_scene.cpp
6 identifiers.cpp
7 ids_yaml_format.cpp
2 naming.cpp 8 naming.cpp
3) 9)
4set_property(TARGET util PROPERTY CXX_STANDARD 20) 10set_property(TARGET util PROPERTY CXX_STANDARD 20)
5set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON) 11set_property(TARGET util PROPERTY CXX_STANDARD_REQUIRED ON)
12target_include_directories(util PUBLIC ${CMAKE_BINARY_DIR})
13target_link_libraries(util PUBLIC protos protobuf::libprotobuf yaml-cpp::yaml-cpp)
diff --git a/tools/util/godot_scene.cpp b/tools/util/godot_scene.cpp new file mode 100644 index 0000000..f788d21 --- /dev/null +++ b/tools/util/godot_scene.cpp
@@ -0,0 +1,207 @@
1#include "godot_scene.h"
2
3#include <fstream>
4#include <sstream>
5#include <string_view>
6#include <variant>
7
8namespace com::fourisland::lingo2_archipelago {
9
10namespace {
11
12struct Heading {
13 std::string type;
14
15 std::string id;
16 std::string path;
17 std::string resource_type;
18
19 std::string name;
20 std::string parent;
21 GodotInstanceType instance_type;
22};
23
24Heading ParseTscnHeading(std::string_view line) {
25 std::string original_line(line);
26 Heading heading;
27
28 if (line[0] != '[') {
29 std::ostringstream errormsg;
30 errormsg << "Heading must start with [." << std::endl
31 << "Bad heading: " << original_line;
32 throw std::invalid_argument(errormsg.str());
33 }
34
35 line.remove_prefix(1);
36 int divider = line.find_first_of(" ]");
37 if (divider == std::string_view::npos) {
38 std::ostringstream errormsg;
39 errormsg << "Malformatted heading: " << line << std::endl
40 << "Original line: " << original_line;
41 throw std::invalid_argument(errormsg.str());
42 }
43
44 heading.type = std::string(line.substr(0, divider));
45 line.remove_prefix(divider + 1);
46
47 while (!line.empty()) {
48 divider = line.find_first_of("=");
49 if (divider == std::string_view::npos) {
50 std::ostringstream errormsg;
51 errormsg << "Malformatted heading: " << line << std::endl
52 << "Original line: " << original_line;
53 throw std::invalid_argument(errormsg.str());
54 }
55
56 std::string key(line.substr(0, divider));
57 line.remove_prefix(divider + 1);
58
59 if (line[0] == '"') {
60 line.remove_prefix(1);
61 divider = line.find_first_of("\"");
62
63 if (divider == std::string_view::npos) {
64 std::ostringstream errormsg;
65 errormsg << "Malformatted heading: " << line << std::endl
66 << "Original line: " << original_line;
67 throw std::invalid_argument(errormsg.str());
68 }
69
70 std::string strval(line.substr(0, divider));
71 line.remove_prefix(divider + 2);
72
73 if (key == "name") {
74 heading.name = strval;
75 } else if (key == "parent") {
76 heading.parent = strval;
77 } else if (key == "path") {
78 heading.path = strval;
79 } else if (key == "type") {
80 heading.resource_type = strval;
81 } else if (key == "id") {
82 heading.id = strval;
83 }
84 } else if (line[0] == 'S' || line[0] == 'E') {
85 GodotInstanceType rrval;
86 char internal = line[0];
87
88 line.remove_prefix(13); // SubResource("
89 divider = line.find_first_of("\"");
90
91 if (divider == std::string_view::npos) {
92 std::ostringstream errormsg;
93 errormsg << "Malformatted heading: " << line << std::endl
94 << "Original line: " << original_line;
95 throw std::invalid_argument(errormsg.str());
96 }
97
98 std::string refid = std::string(line.substr(0, divider));
99 line.remove_prefix(divider + 3);
100
101 GodotInstanceType instance_type;
102 if (internal == 'E') {
103 instance_type = GodotExtResourceRef{.id = refid};
104 } else {
105 // SubResource is not supported right now.
106 }
107
108 if (key == "instance") {
109 heading.instance_type = instance_type;
110 } else {
111 // Other keys aren't supported right now.
112 }
113 } else {
114 divider = line.find_first_of(" ]");
115
116 if (divider == std::string_view::npos) {
117 std::ostringstream errormsg;
118 errormsg << "Malformatted heading: " << line << std::endl
119 << "Original line: " << original_line;
120 throw std::invalid_argument(errormsg.str());
121 }
122
123 int numval = std::atoi(line.substr(0, divider).data());
124 line.remove_prefix(divider + 1);
125
126 // keyvals_[key] = numval;
127 }
128 }
129
130 return heading;
131}
132
133} // namespace
134
135std::string GodotNode::GetPath() const {
136 if (parent.empty() || parent == ".") {
137 return name;
138 } else {
139 return parent + "/" + name;
140 }
141}
142
143GodotScene ReadGodotSceneFromFile(const std::string& path) {
144 std::map<std::string, GodotExtResource> ext_resources;
145 std::vector<GodotNode> nodes;
146
147 std::ifstream input(path);
148
149 std::string line;
150 bool section_started = false;
151 Heading cur_heading;
152 std::ostringstream cur_value;
153 bool value_started = false;
154 auto handle_end_of_section = [&]() {
155 section_started = false;
156 value_started = false;
157
158 if (cur_heading.type == "sub_resource") {
159 // sub_resources_[std::get<int>(cur_heading.GetKeyval("id"))] =
160 // {cur_heading, cur_value.str(), ""};
161 } else {
162 // other_.emplace_back(cur_heading, cur_value.str());
163 }
164
165 cur_value = {};
166 };
167 while (std::getline(input, line)) {
168 if (section_started && (line.empty() || line[0] == '[')) {
169 handle_end_of_section();
170 }
171 if (!line.empty() && line[0] == '[') {
172 Heading heading = ParseTscnHeading(line);
173 if (heading.type == "gd_scene") {
174 // file_descriptor_ = heading;
175 } else if (heading.type == "ext_resource") {
176 GodotExtResource ext_resource;
177 ext_resource.path = heading.path;
178 ext_resource.type = heading.resource_type;
179
180 ext_resources[heading.id] = ext_resource;
181 } else if (heading.type == "node") {
182 if (heading.parent != "") {
183 nodes.push_back(GodotNode{.name = heading.name,
184 .parent = heading.parent,
185 .instance_type = heading.instance_type});
186 }
187 } else {
188 cur_heading = heading;
189 section_started = true;
190 }
191 } else if (!line.empty()) {
192 if (value_started) {
193 cur_value << std::endl;
194 } else {
195 value_started = true;
196 }
197 cur_value << line;
198 }
199 }
200 if (section_started) {
201 handle_end_of_section();
202 }
203
204 return GodotScene(std::move(ext_resources), std::move(nodes));
205}
206
207} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/util/godot_scene.h b/tools/util/godot_scene.h new file mode 100644 index 0000000..17f3f50 --- /dev/null +++ b/tools/util/godot_scene.h
@@ -0,0 +1,57 @@
1#ifndef TOOLS_UTIL_TSCN_H_
2#define TOOLS_UTIL_TSCN_H_
3
4#include <map>
5#include <memory>
6#include <string>
7#include <utility>
8#include <variant>
9#include <vector>
10
11namespace com::fourisland::lingo2_archipelago {
12
13struct GodotExtResource {
14 std::string type;
15 std::string path;
16};
17
18struct GodotExtResourceRef {
19 std::string id;
20};
21
22using GodotInstanceType = std::variant<std::monostate, GodotExtResourceRef>;
23
24struct GodotNode {
25 std::string name;
26 std::string parent;
27 GodotInstanceType instance_type;
28
29 std::string GetPath() const;
30};
31
32class GodotScene {
33 public:
34 GodotScene(std::map<std::string, GodotExtResource> ext_resources,
35 std::vector<GodotNode> nodes)
36 : ext_resources_(std::move(ext_resources)), nodes_(std::move(nodes)) {}
37
38 const GodotExtResource* GetExtResource(const std::string& id) const {
39 auto it = ext_resources_.find(id);
40 if (it != ext_resources_.end()) {
41 return &it->second;
42 } else {
43 return nullptr;
44 }
45 }
46 const std::vector<GodotNode>& GetNodes() const { return nodes_; }
47
48 private:
49 std::map<std::string, GodotExtResource> ext_resources_;
50 std::vector<GodotNode> nodes_;
51};
52
53GodotScene ReadGodotSceneFromFile(const std::string& path);
54
55} // namespace com::fourisland::lingo2_archipelago
56
57#endif /* TOOLS_UTIL_TSCN_H_ */
diff --git a/tools/util/identifiers.cpp b/tools/util/identifiers.cpp new file mode 100644 index 0000000..5b51c57 --- /dev/null +++ b/tools/util/identifiers.cpp
@@ -0,0 +1,102 @@
1#include "identifiers.h"
2
3#include <string>
4
5#include "proto/human.pb.h"
6
7namespace com::fourisland::lingo2_archipelago {
8
9std::optional<RoomIdentifier> GetCompleteRoomIdentifier(
10 RoomIdentifier identifier, std::optional<std::string> map_name) {
11 if (!identifier.has_map()) {
12 if (!map_name) {
13 return std::nullopt;
14 }
15 identifier.set_map(*map_name);
16 }
17 return identifier;
18}
19
20std::optional<DoorIdentifier> GetCompleteDoorIdentifier(
21 DoorIdentifier identifier, std::optional<std::string> map_name) {
22 if (!identifier.has_map()) {
23 if (!map_name) {
24 return std::nullopt;
25 }
26 identifier.set_map(*map_name);
27 }
28 return identifier;
29}
30
31std::optional<PortIdentifier> GetCompletePortIdentifier(
32 PortIdentifier identifier, std::optional<std::string> map_name,
33 std::optional<std::string> room_name) {
34 if (!identifier.has_map()) {
35 if (!map_name) {
36 return std::nullopt;
37 }
38 identifier.set_map(*map_name);
39 }
40 if (!identifier.has_room()) {
41 if (!room_name) {
42 return std::nullopt;
43 }
44 identifier.set_room(*room_name);
45 }
46 return identifier;
47}
48
49std::optional<PaintingIdentifier> GetCompletePaintingIdentifier(
50 PaintingIdentifier identifier, std::optional<std::string> map_name,
51 std::optional<std::string> room_name) {
52 if (!identifier.has_map()) {
53 if (!map_name) {
54 return std::nullopt;
55 }
56 identifier.set_map(*map_name);
57 }
58 if (!identifier.has_room()) {
59 if (!room_name) {
60 return std::nullopt;
61 }
62 identifier.set_room(*room_name);
63 }
64 return identifier;
65}
66
67std::optional<PanelIdentifier> GetCompletePanelIdentifierWithoutAnswer(
68 PanelIdentifier identifier, std::optional<std::string> map_name,
69 std::optional<std::string> room_name) {
70 if (!identifier.has_map()) {
71 if (!map_name) {
72 return std::nullopt;
73 }
74 identifier.set_map(*map_name);
75 }
76 if (!identifier.has_room()) {
77 if (!room_name) {
78 return std::nullopt;
79 }
80 identifier.set_room(*room_name);
81 }
82 identifier.clear_answer();
83 return identifier;
84}
85
86std::optional<KeyholderIdentifier> GetCompleteKeyholderIdentifierWithoutKey(
87 KeyholderIdentifier identifier, const std::string& map_name,
88 std::optional<std::string> room_name) {
89 if (!identifier.has_map()) {
90 identifier.set_map(map_name);
91 }
92 if (!identifier.has_room()) {
93 if (!room_name) {
94 return std::nullopt;
95 }
96 identifier.set_room(*room_name);
97 }
98 identifier.clear_key();
99 return identifier;
100}
101
102} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/util/identifiers.h b/tools/util/identifiers.h new file mode 100644 index 0000000..341dee1 --- /dev/null +++ b/tools/util/identifiers.h
@@ -0,0 +1,85 @@
1#ifndef TOOLS_UTIL_IDENTIFIERS_H_
2#define TOOLS_UTIL_IDENTIFIERS_H_
3
4#include <optional>
5#include <string>
6#include <utility>
7
8#include "proto/human.pb.h"
9
10namespace com::fourisland::lingo2_archipelago {
11
12class RoomIdentifierLess {
13 public:
14 bool operator()(const RoomIdentifier& lhs, const RoomIdentifier& rhs) const {
15 return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name());
16 }
17};
18
19class DoorIdentifierLess {
20 public:
21 bool operator()(const DoorIdentifier& lhs, const DoorIdentifier& rhs) const {
22 return std::tie(lhs.map(), lhs.name()) < std::tie(rhs.map(), rhs.name());
23 }
24};
25
26class PortIdentifierLess {
27 public:
28 bool operator()(const PortIdentifier& lhs, const PortIdentifier& rhs) const {
29 return std::tie(lhs.map(), lhs.room(), lhs.name()) <
30 std::tie(rhs.map(), rhs.room(), rhs.name());
31 }
32};
33
34class PaintingIdentifierLess {
35 public:
36 bool operator()(const PaintingIdentifier& lhs,
37 const PaintingIdentifier& rhs) const {
38 return std::tie(lhs.map(), lhs.room(), lhs.name()) <
39 std::tie(rhs.map(), rhs.room(), rhs.name());
40 }
41};
42
43class PanelIdentifierLess {
44 public:
45 bool operator()(const PanelIdentifier& lhs,
46 const PanelIdentifier& rhs) const {
47 return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.answer()) <
48 std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.answer());
49 }
50};
51
52class KeyholderIdentifierLess {
53 public:
54 bool operator()(const KeyholderIdentifier& lhs,
55 const KeyholderIdentifier& rhs) const {
56 return std::tie(lhs.map(), lhs.room(), lhs.name(), lhs.key()) <
57 std::tie(rhs.map(), rhs.room(), rhs.name(), rhs.key());
58 }
59};
60
61std::optional<RoomIdentifier> GetCompleteRoomIdentifier(
62 RoomIdentifier identifier, std::optional<std::string> map_name);
63
64std::optional<DoorIdentifier> GetCompleteDoorIdentifier(
65 DoorIdentifier identifier, std::optional<std::string> map_name);
66
67std::optional<PortIdentifier> GetCompletePortIdentifier(
68 PortIdentifier identifier, std::optional<std::string> map_name,
69 std::optional<std::string> room_name);
70
71std::optional<PaintingIdentifier> GetCompletePaintingIdentifier(
72 PaintingIdentifier identifier, std::optional<std::string> map_name,
73 std::optional<std::string> room_name);
74
75std::optional<PanelIdentifier> GetCompletePanelIdentifierWithoutAnswer(
76 PanelIdentifier identifier, std::optional<std::string> map_name,
77 std::optional<std::string> room_name);
78
79std::optional<KeyholderIdentifier> GetCompleteKeyholderIdentifierWithoutKey(
80 KeyholderIdentifier identifier, const std::string& map_name,
81 std::optional<std::string> room_name);
82
83} // namespace com::fourisland::lingo2_archipelago
84
85#endif /* TOOLS_UTIL_IDENTIFIERS_H_ */
diff --git a/tools/util/ids_yaml_format.cpp b/tools/util/ids_yaml_format.cpp new file mode 100644 index 0000000..71bfd63 --- /dev/null +++ b/tools/util/ids_yaml_format.cpp
@@ -0,0 +1,190 @@
1#include "ids_yaml_format.h"
2
3#include <yaml-cpp/yaml.h>
4
5#include <fstream>
6#include <functional>
7
8namespace com::fourisland::lingo2_archipelago {
9namespace {
10
11template <typename T>
12void OperateOnSortedMap(
13 const T& map, std::function<void(const std::string& name,
14 const typename T::mapped_type& value)>
15 callback) {
16 std::vector<std::string> names;
17 for (const auto& it : map) {
18 names.push_back(it.first);
19 }
20
21 std::sort(names.begin(), names.end());
22
23 for (const std::string& name : names) {
24 callback(name, map.at(name));
25 }
26}
27
28} // namespace
29
30IdMappings ReadIdsFromYaml(const std::string& filename) {
31 IdMappings result;
32
33 YAML::Node document = YAML::LoadFile(filename);
34
35 if (document["maps"]) {
36 for (const auto& map_it : document["maps"]) {
37 IdMappings::MapIds& map_ids =
38 (*result.mutable_maps())[map_it.first.as<std::string>()];
39
40 if (map_it.second["rooms"]) {
41 for (const auto& room_it : map_it.second["rooms"]) {
42 IdMappings::RoomIds& room_ids =
43 (*map_ids.mutable_rooms())[room_it.first.as<std::string>()];
44
45 if (room_it.second["panels"]) {
46 for (const auto& panel_it : room_it.second["panels"]) {
47 (*room_ids.mutable_panels())[panel_it.first.as<std::string>()] =
48 panel_it.second.as<uint64_t>();
49 }
50 }
51
52 if (room_it.second["masteries"]) {
53 for (const auto& mastery_it : room_it.second["masteries"]) {
54 (*room_ids
55 .mutable_masteries())[mastery_it.first.as<std::string>()] =
56 mastery_it.second.as<uint64_t>();
57 }
58 }
59
60 if (room_it.second["keyholders"]) {
61 for (const auto& keyholder_it : room_it.second["keyholders"]) {
62 (*room_ids.mutable_keyholders())[keyholder_it.first
63 .as<std::string>()] =
64 keyholder_it.second.as<uint64_t>();
65 }
66 }
67 }
68 }
69
70 if (map_it.second["doors"]) {
71 for (const auto& door_it : map_it.second["doors"]) {
72 (*map_ids.mutable_doors())[door_it.first.as<std::string>()] =
73 door_it.second.as<uint64_t>();
74 }
75 }
76 }
77 }
78
79 if (document["letters"]) {
80 for (const auto& letter_it : document["letters"]) {
81 (*result.mutable_letters())[letter_it.first.as<std::string>()] =
82 letter_it.second.as<uint64_t>();
83 }
84 }
85
86 if (document["endings"]) {
87 for (const auto& ending_it : document["endings"]) {
88 (*result.mutable_endings())[ending_it.first.as<std::string>()] =
89 ending_it.second.as<uint64_t>();
90 }
91 }
92
93 if (document["special"]) {
94 for (const auto& special_it : document["special"]) {
95 (*result.mutable_special())[special_it.first.as<std::string>()] =
96 special_it.second.as<uint64_t>();
97 }
98 }
99
100 if (document["progressives"]) {
101 for (const auto& prog_it : document["progressives"]) {
102 (*result.mutable_progressives())[prog_it.first.as<std::string>()] =
103 prog_it.second.as<uint64_t>();
104 }
105 }
106
107 if (document["door_groups"]) {
108 for (const auto& group_it : document["door_groups"]) {
109 (*result.mutable_door_groups())[group_it.first.as<std::string>()] =
110 group_it.second.as<uint64_t>();
111 }
112 }
113
114 return result;
115}
116
117void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename) {
118 YAML::Node result;
119
120 OperateOnSortedMap(ids.maps(), [&result](const std::string& map_name,
121 const IdMappings::MapIds& map_ids) {
122 YAML::Node map_node;
123
124 OperateOnSortedMap(
125 map_ids.rooms(), [&map_node](const std::string& room_name,
126 const IdMappings::RoomIds& room_ids) {
127 YAML::Node room_node;
128
129 OperateOnSortedMap(
130 room_ids.panels(),
131 [&room_node](const std::string& panel_name, uint64_t panel_id) {
132 room_node["panels"][panel_name] = panel_id;
133 });
134
135 OperateOnSortedMap(room_ids.masteries(),
136 [&room_node](const std::string& mastery_name,
137 uint64_t mastery_id) {
138 room_node["masteries"][mastery_name] =
139 mastery_id;
140 });
141
142 OperateOnSortedMap(room_ids.keyholders(),
143 [&room_node](const std::string& keyholder_name,
144 uint64_t keyholder_id) {
145 room_node["keyholders"][keyholder_name] =
146 keyholder_id;
147 });
148
149 map_node["rooms"][room_name] = std::move(room_node);
150 });
151
152 OperateOnSortedMap(
153 map_ids.doors(),
154 [&map_node](const std::string& door_name, uint64_t door_id) {
155 map_node["doors"][door_name] = door_id;
156 });
157
158 result["maps"][map_name] = std::move(map_node);
159 });
160
161 OperateOnSortedMap(ids.letters(), [&result](const std::string& letter_name,
162 uint64_t letter_id) {
163 result["letters"][letter_name] = letter_id;
164 });
165
166 OperateOnSortedMap(ids.endings(), [&result](const std::string& ending_name,
167 uint64_t ending_id) {
168 result["endings"][ending_name] = ending_id;
169 });
170
171 OperateOnSortedMap(ids.special(), [&result](const std::string& special_name,
172 uint64_t special_id) {
173 result["special"][special_name] = special_id;
174 });
175
176 OperateOnSortedMap(ids.progressives(),
177 [&result](const std::string& prog_name, uint64_t prog_id) {
178 result["progressives"][prog_name] = prog_id;
179 });
180
181 OperateOnSortedMap(ids.door_groups(), [&result](const std::string& group_name,
182 uint64_t group_id) {
183 result["door_groups"][group_name] = group_id;
184 });
185
186 std::ofstream output_stream(filename);
187 output_stream << result << std::endl;
188}
189
190} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/util/ids_yaml_format.h b/tools/util/ids_yaml_format.h new file mode 100644 index 0000000..d926369 --- /dev/null +++ b/tools/util/ids_yaml_format.h
@@ -0,0 +1,16 @@
1#ifndef TOOLS_UTIL_IDS_YAML_FORMAT_H_
2#define TOOLS_UTIL_IDS_YAML_FORMAT_H_
3
4#include <string>
5
6#include "proto/human.pb.h"
7
8namespace com::fourisland::lingo2_archipelago {
9
10IdMappings ReadIdsFromYaml(const std::string& filename);
11
12void WriteIdsAsYaml(const IdMappings& ids, const std::string& filename);
13
14} // namespace com::fourisland::lingo2_archipelago
15
16#endif /* TOOLS_UTIL_IDS_YAML_FORMAT_H_ */
diff --git a/tools/util/naming.cpp b/tools/util/naming.cpp index 0ae99f6..8229c6d 100644 --- a/tools/util/naming.cpp +++ b/tools/util/naming.cpp
@@ -2,6 +2,8 @@
2 2
3#include <sstream> 3#include <sstream>
4 4
5namespace com::fourisland::lingo2_archipelago {
6
5std::string GetLetterName(std::string key, bool level2) { 7std::string GetLetterName(std::string key, bool level2) {
6 std::ostringstream lettername_s; 8 std::ostringstream lettername_s;
7 lettername_s << key; 9 lettername_s << key;
@@ -9,3 +11,5 @@ std::string GetLetterName(std::string key, bool level2) {
9 11
10 return lettername_s.str(); 12 return lettername_s.str();
11} 13}
14
15} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/util/naming.h b/tools/util/naming.h index 9a68851..85e2db0 100644 --- a/tools/util/naming.h +++ b/tools/util/naming.h
@@ -3,6 +3,10 @@
3 3
4#include <string> 4#include <string>
5 5
6namespace com::fourisland::lingo2_archipelago {
7
6std::string GetLetterName(std::string key, bool level2); 8std::string GetLetterName(std::string key, bool level2);
7 9
10} // namespace com::fourisland::lingo2_archipelago
11
8#endif /* TOOLS_UTIL_NAMING_H_ */ 12#endif /* TOOLS_UTIL_NAMING_H_ */
diff --git a/tools/validator/CMakeLists.txt b/tools/validator/CMakeLists.txt new file mode 100644 index 0000000..1a8fd9c --- /dev/null +++ b/tools/validator/CMakeLists.txt
@@ -0,0 +1,13 @@
1find_package(fmt REQUIRED)
2find_package(Protobuf REQUIRED)
3
4add_executable(validator
5 godot_processor.cpp
6 human_processor.cpp
7 main.cpp
8 validator.cpp
9)
10set_property(TARGET validator PROPERTY CXX_STANDARD 20)
11set_property(TARGET validator PROPERTY CXX_STANDARD_REQUIRED ON)
12target_include_directories(validator PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/tools)
13target_link_libraries(validator PUBLIC protos util fmt::fmt protobuf::libprotobuf)
diff --git a/tools/validator/godot_processor.cpp b/tools/validator/godot_processor.cpp new file mode 100644 index 0000000..ad2be78 --- /dev/null +++ b/tools/validator/godot_processor.cpp
@@ -0,0 +1,72 @@
1#include "godot_processor.h"
2
3#include <filesystem>
4#include <iostream>
5#include <memory>
6#include <set>
7
8#include "structs.h"
9#include "util/godot_scene.h"
10
11namespace com::fourisland::lingo2_archipelago {
12
13namespace {
14
15static const std::set<std::string> kImportantNodeTypes = {
16 "res://objects/nodes/panel.tscn", "res://objects/nodes/worldport.tscn",
17 "res://objects/nodes/keyHolder.tscn",
18 "res://objects/nodes/collectable.tscn"};
19
20class GodotProcessor {
21 public:
22 GodotProcessor(const std::string& repodir, CollectedInfo& info)
23 : repodir_(repodir), info_(info) {}
24
25 void Run() {
26 for (auto& [map_name, map_info] : info_.maps) {
27 ProcessMap(map_name, map_info);
28 }
29 }
30
31 void ProcessMap(const std::string& map_name, MapInfo& map_info) {
32 std::filesystem::path scene_path = std::filesystem::path(repodir_) /
33 "objects" / "scenes" /
34 (map_name + ".tscn");
35 std::string scene_path_str = scene_path.string();
36 std::cout << "Processing " << scene_path_str << std::endl;
37
38 GodotScene scene = ReadGodotSceneFromFile(scene_path_str);
39 for (const GodotNode& node : scene.GetNodes()) {
40 ProcessMapNode(scene, node, map_info);
41 }
42 }
43
44 void ProcessMapNode(const GodotScene& scene, const GodotNode& node,
45 MapInfo& map_info) {
46 if (std::holds_alternative<GodotExtResourceRef>(node.instance_type)) {
47 const GodotExtResourceRef& ext_resource_ref =
48 std::get<GodotExtResourceRef>(node.instance_type);
49 const GodotExtResource* ext_resource =
50 scene.GetExtResource(ext_resource_ref.id);
51
52 if (ext_resource != nullptr &&
53 (kImportantNodeTypes.count(ext_resource->path) ||
54 ext_resource->path.starts_with("res://objects/meshes/paintings/"))) {
55 map_info.game_nodes[node.GetPath()].defined = true;
56 }
57 }
58 }
59
60 private:
61 std::string repodir_;
62 CollectedInfo& info_;
63};
64
65} // namespace
66
67void ProcessGodotData(const std::string& repodir, CollectedInfo& info) {
68 GodotProcessor godot_processor(repodir, info);
69 godot_processor.Run();
70}
71
72} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/godot_processor.h b/tools/validator/godot_processor.h new file mode 100644 index 0000000..97bcea6 --- /dev/null +++ b/tools/validator/godot_processor.h
@@ -0,0 +1,14 @@
1#ifndef TOOLS_VALIDATOR_GODOT_PROCESSOR_H_
2#define TOOLS_VALIDATOR_GODOT_PROCESSOR_H_
3
4#include <string>
5
6namespace com::fourisland::lingo2_archipelago {
7
8struct CollectedInfo;
9
10void ProcessGodotData(const std::string& repodir, CollectedInfo& info);
11
12} // namespace com::fourisland::lingo2_archipelago
13
14#endif /* TOOLS_VALIDATOR_GODOT_PROCESSOR_H_ */
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp new file mode 100644 index 0000000..2c978bf --- /dev/null +++ b/tools/validator/human_processor.cpp
@@ -0,0 +1,640 @@
1#include "human_processor.h"
2
3#include <fmt/core.h>
4#include <google/protobuf/message.h>
5#include <google/protobuf/text_format.h>
6
7#include <filesystem>
8#include <fstream>
9#include <iostream>
10#include <map>
11#include <optional>
12#include <sstream>
13#include <string>
14
15#include "structs.h"
16#include "util/ids_yaml_format.h"
17
18namespace com::fourisland::lingo2_archipelago {
19namespace {
20
21template <typename T>
22T ReadMessageFromFile(const std::string& path) {
23 std::cout << "Processing " << path << std::endl;
24
25 std::ifstream file(path);
26 std::stringstream buffer;
27 buffer << file.rdbuf();
28
29 T message;
30 google::protobuf::TextFormat::ParseFromString(buffer.str(), &message);
31
32 return message;
33}
34
35class HumanProcessor {
36 public:
37 HumanProcessor(const std::string& mapdir, CollectedInfo& info)
38 : mapdir_(mapdir), info_(info) {}
39
40 void Run() {
41 std::filesystem::path datadir_path = mapdir_;
42
43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
44 ProcessMaps(datadir_path);
45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
48 }
49
50 private:
51 void ProcessMaps(std::filesystem::path path) {
52 std::filesystem::path maps_dir = path / "maps";
53 for (auto const& dir_entry :
54 std::filesystem::directory_iterator(maps_dir)) {
55 ProcessMap(dir_entry.path());
56 }
57 }
58
59 void ProcessMap(std::filesystem::path path) {
60 std::string map_name = path.filename().string();
61
62 ProcessMetadataFile(path / "metadata.txtpb", map_name);
63 ProcessConnectionsFile(path / "connections.txtpb", map_name);
64 ProcessDoorsFile(path / "doors.txtpb", map_name);
65 ProcessRooms(path / "rooms", map_name);
66 }
67
68 void ProcessMetadataFile(std::filesystem::path path,
69 const std::string& current_map_name) {
70 if (!std::filesystem::exists(path)) {
71 return;
72 }
73
74 MapInfo& map_info = info_.maps[current_map_name];
75
76 auto metadata = ReadMessageFromFile<HumanMap>(path.string());
77 for (const std::string& path : metadata.excluded_nodes()) {
78 map_info.game_nodes[path].uses++;
79 }
80 }
81
82 void ProcessRooms(std::filesystem::path path,
83 const std::string& current_map_name) {
84 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
85 auto room = ReadMessageFromFile<HumanRoom>(dir_entry.path().string());
86 ProcessRoom(room, current_map_name);
87 }
88 }
89
90 void ProcessRoom(const HumanRoom& h_room,
91 const std::string& current_map_name) {
92 RoomIdentifier room_identifier;
93 room_identifier.set_map(current_map_name);
94 room_identifier.set_name(h_room.name());
95
96 RoomInfo& room_info = info_.rooms[room_identifier];
97 room_info.definitions.push_back(h_room);
98
99 for (const HumanPanel& h_panel : h_room.panels()) {
100 ProcessPanel(h_panel, current_map_name, h_room);
101 }
102
103 for (const HumanPainting& h_painting : h_room.paintings()) {
104 ProcessPainting(h_painting, current_map_name, h_room.name());
105 }
106
107 for (const HumanPort& h_port : h_room.ports()) {
108 ProcessPort(h_port, current_map_name, h_room.name());
109 }
110
111 for (const HumanLetter& h_letter : h_room.letters()) {
112 ProcessLetter(h_letter, current_map_name, h_room.name());
113 }
114
115 for (const HumanMastery& h_mastery : h_room.masteries()) {
116 ProcessMastery(h_mastery, current_map_name, h_room.name());
117 }
118
119 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
120 ProcessKeyholder(h_keyholder, current_map_name, h_room.name());
121 }
122
123 for (const HumanEnding& h_ending : h_room.endings()) {
124 ProcessEnding(h_ending, current_map_name, h_room.name());
125 }
126 }
127
128 void ProcessPanel(const HumanPanel& h_panel,
129 const std::string& current_map_name,
130 const HumanRoom& h_room) {
131 PanelIdentifier panel_identifier;
132 panel_identifier.set_map(current_map_name);
133 panel_identifier.set_room(h_room.name());
134 panel_identifier.set_name(h_panel.name());
135
136 PanelInfo& panel_info = info_.panels[panel_identifier];
137 panel_info.definitions.push_back(h_panel);
138
139 MapInfo& map_info = info_.maps[current_map_name];
140 map_info.game_nodes[h_panel.path()].uses++;
141
142 for (const Proxy& h_proxy : h_panel.proxies()) {
143 ProxyInfo& proxy_info = panel_info.proxies[h_proxy.answer()];
144 proxy_info.definitions.push_back(h_proxy);
145
146 map_info.game_nodes[h_proxy.path()].uses++;
147 }
148
149 if (h_panel.has_required_door()) {
150 DoorIdentifier required_door_identifier =
151 *GetCompleteDoorIdentifier(h_panel.required_door(), current_map_name);
152 DoorInfo& required_door_info = info_.doors[required_door_identifier];
153 required_door_info.panels_referenced_by.push_back(panel_identifier);
154 }
155
156 if (h_panel.has_required_room()) {
157 RoomIdentifier required_room_identifier =
158 *GetCompleteRoomIdentifier(h_panel.required_room(), current_map_name);
159 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
160 required_room_info.panels_referenced_by.push_back(panel_identifier);
161 }
162
163 std::string map_area_name = current_map_name;
164 if (h_room.has_panel_display_name()) {
165 map_area_name =
166 fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
167 }
168
169 panel_info.map_area_name = map_area_name;
170
171 std::string panelsanity_name;
172 if (h_panel.has_display_name()) {
173 panelsanity_name =
174 fmt::format("{} - {}", map_area_name, h_panel.display_name());
175 } else {
176 panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
177 }
178 info_.panel_names[panelsanity_name].panels_used_by.push_back(
179 panel_identifier);
180 }
181
182 void ProcessPainting(const HumanPainting& h_painting,
183 const std::string& current_map_name,
184 const std::string& current_room_name) {
185 PaintingIdentifier painting_identifier;
186 painting_identifier.set_map(current_map_name);
187 painting_identifier.set_room(current_room_name);
188 painting_identifier.set_name(h_painting.name());
189
190 PaintingInfo& painting_info = info_.paintings[painting_identifier];
191 painting_info.definitions.push_back(h_painting);
192
193 MapInfo& map_info = info_.maps[current_map_name];
194 map_info.game_nodes[h_painting.path()].uses++;
195
196 if (h_painting.has_required_door()) {
197 DoorIdentifier required_door_identifier = *GetCompleteDoorIdentifier(
198 h_painting.required_door(), current_map_name);
199 DoorInfo& required_door_info = info_.doors[required_door_identifier];
200 required_door_info.paintings_referenced_by.push_back(painting_identifier);
201 }
202 }
203
204 void ProcessPort(const HumanPort& h_port, const std::string& current_map_name,
205 const std::string& current_room_name) {
206 PortIdentifier port_identifier;
207 port_identifier.set_map(current_map_name);
208 port_identifier.set_room(current_room_name);
209 port_identifier.set_name(h_port.name());
210
211 PortInfo& port_info = info_.ports[port_identifier];
212 port_info.definitions.push_back(h_port);
213
214 MapInfo& map_info = info_.maps[current_map_name];
215 map_info.game_nodes[h_port.path()].uses++;
216
217 if (h_port.has_required_door()) {
218 DoorIdentifier required_door_identifier =
219 *GetCompleteDoorIdentifier(h_port.required_door(), current_map_name);
220 DoorInfo& required_door_info = info_.doors[required_door_identifier];
221 required_door_info.ports_referenced_by.push_back(port_identifier);
222 }
223 }
224
225 void ProcessLetter(const HumanLetter& h_letter,
226 const std::string& current_map_name,
227 const std::string& current_room_name) {
228 LetterIdentifier letter_identifier =
229 std::make_tuple(h_letter.key()[0], h_letter.level2());
230 LetterInfo& letter_info = info_.letters[letter_identifier];
231
232 RoomIdentifier room_identifier;
233 room_identifier.set_map(current_map_name);
234 room_identifier.set_name(current_room_name);
235 letter_info.defined_in.push_back(room_identifier);
236
237 MapInfo& map_info = info_.maps[current_map_name];
238 map_info.game_nodes[h_letter.path()].uses++;
239 }
240
241 void ProcessMastery(const HumanMastery& h_mastery,
242 const std::string& current_map_name,
243 const std::string& current_room_name) {
244 MapInfo& map_info = info_.maps[current_map_name];
245 map_info.game_nodes[h_mastery.path()].uses++;
246 }
247
248 void ProcessKeyholder(const HumanKeyholder& h_keyholder,
249 const std::string& current_map_name,
250 const std::string& current_room_name) {
251 KeyholderIdentifier keyholder_identifier;
252 keyholder_identifier.set_map(current_map_name);
253 keyholder_identifier.set_room(current_room_name);
254 keyholder_identifier.set_name(h_keyholder.name());
255
256 KeyholderInfo& keyholder_info = info_.keyholders[keyholder_identifier];
257 keyholder_info.definitions.push_back(h_keyholder);
258
259 MapInfo& map_info = info_.maps[current_map_name];
260 map_info.game_nodes[h_keyholder.path()].uses++;
261 }
262
263 void ProcessEnding(const HumanEnding& h_ending,
264 const std::string& current_map_name,
265 const std::string& current_room_name) {
266 EndingInfo& ending_info = info_.endings[h_ending.name()];
267
268 RoomIdentifier room_identifier;
269 room_identifier.set_map(current_map_name);
270 room_identifier.set_name(current_room_name);
271 ending_info.defined_in.push_back(room_identifier);
272
273 MapInfo& map_info = info_.maps[current_map_name];
274 map_info.game_nodes[h_ending.path()].uses++;
275 }
276
277 void ProcessDoorsFile(std::filesystem::path path,
278 const std::string& current_map_name) {
279 if (!std::filesystem::exists(path)) {
280 return;
281 }
282
283 auto doors = ReadMessageFromFile<HumanDoors>(path.string());
284
285 for (const HumanDoor& door : doors.doors()) {
286 ProcessDoor(door, current_map_name);
287 }
288 }
289
290 void ProcessDoor(const HumanDoor& h_door,
291 const std::string& current_map_name) {
292 DoorIdentifier door_identifier;
293 door_identifier.set_map(current_map_name);
294 door_identifier.set_name(h_door.name());
295
296 DoorInfo& door_info = info_.doors[door_identifier];
297 door_info.definitions.push_back(h_door);
298
299 if (h_door.has_location_room()) {
300 RoomIdentifier location_room_identifier;
301 location_room_identifier.set_map(current_map_name);
302 location_room_identifier.set_name(h_door.location_room());
303 info_.rooms[location_room_identifier].doors_referenced_by.push_back(
304 door_identifier);
305 }
306
307 for (const PaintingIdentifier& pi : h_door.move_paintings()) {
308 auto complete_painting_identifier =
309 GetCompletePaintingIdentifier(pi, current_map_name, std::nullopt);
310 if (complete_painting_identifier) {
311 PaintingInfo& move_painting_info =
312 info_.paintings[*complete_painting_identifier];
313 move_painting_info.doors_referenced_by.push_back(door_identifier);
314 } else {
315 door_info.malformed_identifiers.paintings.push_back(pi);
316 }
317 }
318
319 for (const PanelIdentifier& pi : h_door.panels()) {
320 auto complete_panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
321 pi, current_map_name, std::nullopt);
322 if (complete_panel_identifier) {
323 PanelInfo& panel_info = info_.panels[*complete_panel_identifier];
324 panel_info.doors_referenced_by.push_back(door_identifier);
325
326 if (pi.has_answer()) {
327 panel_info.proxies[pi.answer()].doors_referenced_by.push_back(
328 door_identifier);
329 }
330 } else {
331 door_info.malformed_identifiers.panels.push_back(pi);
332 }
333 }
334
335 for (const KeyholderIdentifier& ki : h_door.keyholders()) {
336 auto complete_keyholder_identifier =
337 GetCompleteKeyholderIdentifierWithoutKey(ki, current_map_name,
338 std::nullopt);
339 if (complete_keyholder_identifier) {
340 KeyholderInfo& keyholder_info =
341 info_.keyholders[*complete_keyholder_identifier];
342 keyholder_info.doors_referenced_by.push_back(door_identifier);
343 } else {
344 door_info.malformed_identifiers.keyholders.push_back(ki);
345 }
346 }
347
348 for (const RoomIdentifier& ri : h_door.rooms()) {
349 RoomIdentifier complete_room_identifier =
350 *GetCompleteRoomIdentifier(ri, current_map_name);
351 RoomInfo& room_info = info_.rooms[complete_room_identifier];
352 room_info.doors_referenced_by.push_back(door_identifier);
353 }
354
355 for (const DoorIdentifier& di : h_door.doors()) {
356 DoorIdentifier complete_door_identifier =
357 *GetCompleteDoorIdentifier(di, current_map_name);
358 DoorInfo& other_door_info = info_.doors[complete_door_identifier];
359 other_door_info.doors_referenced_by.push_back(door_identifier);
360 }
361
362 for (const std::string& ei : h_door.endings()) {
363 EndingInfo& ending_info = info_.endings[ei];
364 ending_info.doors_referenced_by.push_back(door_identifier);
365 }
366 }
367
368 void ProcessConnectionsFile(std::filesystem::path path,
369 std::optional<std::string> current_map_name) {
370 if (!std::filesystem::exists(path)) {
371 return;
372 }
373
374 auto connections = ReadMessageFromFile<HumanConnections>(path.string());
375
376 for (const HumanConnection& connection : connections.connections()) {
377 ProcessConnection(connection, current_map_name);
378 }
379 }
380
381 void ProcessConnection(const HumanConnection& human_connection,
382 const std::optional<std::string>& current_map_name) {
383 if (human_connection.has_from_room()) {
384 if (current_map_name) {
385 RoomIdentifier room_identifier;
386 room_identifier.set_map(*current_map_name);
387 room_identifier.set_name(human_connection.from_room());
388
389 RoomInfo& room_info = info_.rooms[room_identifier];
390 room_info.connections_referenced_by.push_back(human_connection);
391 } else {
392 // Not sure where else to store this right now.
393 std::cout << "A global connection used from_room." << std::endl;
394 }
395 } else if (human_connection.has_from()) {
396 ProcessSingleConnection(human_connection, human_connection.from(),
397 current_map_name,
398 /*is_target=*/!human_connection.oneway() &&
399 !human_connection.bypass_target_door());
400 }
401
402 if (human_connection.has_to_room()) {
403 if (current_map_name) {
404 RoomIdentifier room_identifier;
405 room_identifier.set_map(*current_map_name);
406 room_identifier.set_name(human_connection.to_room());
407
408 RoomInfo& room_info = info_.rooms[room_identifier];
409 room_info.connections_referenced_by.push_back(human_connection);
410 } else {
411 // Not sure where else to store this right now.
412 std::cout << "A global connection used to_room." << std::endl;
413 }
414 } else if (human_connection.has_to()) {
415 ProcessSingleConnection(
416 human_connection, human_connection.to(), current_map_name,
417 /*is_target=*/!human_connection.bypass_target_door());
418 }
419
420 if (human_connection.has_door()) {
421 auto door_identifier =
422 GetCompleteDoorIdentifier(human_connection.door(), current_map_name);
423 if (door_identifier) {
424 DoorInfo& door_info = info_.doors[*door_identifier];
425 door_info.connections_referenced_by.push_back(human_connection);
426 } else {
427 // Not sure where else to store this right now.
428 std::cout
429 << "A connection used the following malformed door identifier: "
430 << human_connection.door().ShortDebugString() << std::endl;
431 }
432 }
433 }
434
435 void ProcessSingleConnection(
436 const HumanConnection& human_connection,
437 const HumanConnection::Endpoint& endpoint,
438 const std::optional<std::string>& current_map_name, bool is_target) {
439 if (endpoint.has_room()) {
440 auto room_identifier =
441 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
442 if (room_identifier) {
443 RoomInfo& room_info = info_.rooms[*room_identifier];
444 room_info.connections_referenced_by.push_back(human_connection);
445 } else {
446 // Not sure where else to store this right now.
447 std::cout
448 << "A connection used the following malformed room identifier: "
449 << endpoint.room().ShortDebugString() << std::endl;
450 }
451 } else if (endpoint.has_painting()) {
452 auto painting_identifier = GetCompletePaintingIdentifier(
453 endpoint.painting(), current_map_name, std::nullopt);
454 if (painting_identifier) {
455 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
456 painting_info.connections_referenced_by.push_back(human_connection);
457
458 if (is_target) {
459 painting_info.target_connections_referenced_by.push_back(
460 human_connection);
461 }
462 } else {
463 // Not sure where else to store this right now.
464 std::cout
465 << "A connection used the following malformed painting identifier: "
466 << endpoint.painting().ShortDebugString() << std::endl;
467 }
468 } else if (endpoint.has_port()) {
469 auto port_identifier = GetCompletePortIdentifier(
470 endpoint.port(), current_map_name, std::nullopt);
471 if (port_identifier) {
472 PortInfo& port_info = info_.ports[*port_identifier];
473 port_info.connections_referenced_by.push_back(human_connection);
474
475 if (is_target) {
476 port_info.target_connections_referenced_by.push_back(
477 human_connection);
478 }
479 } else {
480 // Not sure where else to store this right now.
481 std::cout
482 << "A connection used the following malformed port identifier: "
483 << endpoint.port().ShortDebugString() << std::endl;
484 }
485 } else if (endpoint.has_panel()) {
486 auto panel_identifier = GetCompletePanelIdentifierWithoutAnswer(
487 endpoint.panel(), current_map_name, std::nullopt);
488 if (panel_identifier) {
489 PanelInfo& panel_info = info_.panels[*panel_identifier];
490 panel_info.connections_referenced_by.push_back(human_connection);
491
492 if (endpoint.panel().has_answer()) {
493 panel_info.proxies[endpoint.panel().answer()]
494 .connections_referenced_by.push_back(human_connection);
495 }
496
497 if (is_target) {
498 panel_info.target_connections_referenced_by.push_back(
499 human_connection);
500 }
501 }
502 }
503 }
504
505 void ProcessProgressivesFile(std::filesystem::path path) {
506 if (!std::filesystem::exists(path)) {
507 return;
508 }
509
510 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
511
512 for (const HumanProgressive& h_prog : h_progs.progressives()) {
513 ProcessProgressive(h_prog);
514 }
515 }
516
517 void ProcessProgressive(const HumanProgressive& h_prog) {
518 ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
519 prog_info.definitions.push_back(h_prog);
520
521 for (const DoorIdentifier& di : h_prog.doors()) {
522 if (!di.has_map()) {
523 prog_info.malformed_doors.push_back(di);
524 continue;
525 }
526
527 DoorInfo& door_info = info_.doors[di];
528 door_info.progressives_referenced_by.push_back(h_prog.name());
529 }
530 }
531
532 void ProcessDoorGroupsFile(std::filesystem::path path) {
533 if (!std::filesystem::exists(path)) {
534 return;
535 }
536
537 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
538
539 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
540 ProcessDoorGroup(h_group);
541 }
542 }
543
544 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
545 DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
546 group_info.definitions.push_back(h_group);
547
548 for (const DoorIdentifier& di : h_group.doors()) {
549 if (!di.has_map()) {
550 group_info.malformed_doors.push_back(di);
551 continue;
552 }
553
554 DoorInfo& door_info = info_.doors[di];
555 door_info.door_groups_referenced_by.push_back(h_group.name());
556 }
557 }
558
559 void ProcessIdsFile(std::filesystem::path path) {
560 auto ids = ReadIdsFromYaml(path.string());
561
562 DoorIdentifier di;
563 PanelIdentifier pi;
564 KeyholderIdentifier ki;
565
566 for (const auto& [map_name, map] : ids.maps()) {
567 di.set_map(map_name);
568 pi.set_map(map_name);
569 ki.set_map(map_name);
570
571 for (const auto& [door_name, ap_id] : map.doors()) {
572 di.set_name(door_name);
573
574 DoorInfo& door_info = info_.doors[di];
575 door_info.has_id = true;
576 }
577
578 for (const auto& [room_name, room] : map.rooms()) {
579 pi.set_room(room_name);
580 ki.set_room(room_name);
581
582 for (const auto& [panel_name, ap_id] : room.panels()) {
583 pi.set_name(panel_name);
584
585 PanelInfo& panel_info = info_.panels[pi];
586 panel_info.has_id = true;
587 }
588
589 for (const auto& [mastery_name, ap_id] : room.masteries()) {
590 // TODO: Mastery
591 }
592
593 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
594 ki.set_name(keyholder_name);
595
596 KeyholderInfo& keyholder_info = info_.keyholders[ki];
597 keyholder_info.has_id = true;
598 }
599 }
600 }
601
602 for (const auto& [tag, id] : ids.special()) {
603 // TODO: Specials
604 }
605
606 for (const auto& [letter_name, ap_id] : ids.letters()) {
607 LetterIdentifier li =
608 std::make_tuple(letter_name[0], letter_name[1] == '2');
609 LetterInfo& letter_info = info_.letters[li];
610 letter_info.has_id = true;
611 }
612
613 for (const auto& [ending_name, ap_id] : ids.endings()) {
614 EndingInfo& ending_info = info_.endings[ending_name];
615 ending_info.has_id = true;
616 }
617
618 for (const auto& [prog_name, ap_id] : ids.progressives()) {
619 ProgressiveInfo& prog_info = info_.progressives[prog_name];
620 prog_info.has_id = true;
621 }
622
623 for (const auto& [group_name, ap_id] : ids.door_groups()) {
624 DoorGroupInfo& group_info = info_.door_groups[group_name];
625 group_info.has_id = true;
626 }
627 }
628
629 std::string mapdir_;
630 CollectedInfo& info_;
631};
632
633} // namespace
634
635void ProcessHumanData(const std::string& mapdir, CollectedInfo& info) {
636 HumanProcessor human_processor(mapdir, info);
637 human_processor.Run();
638}
639
640} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/human_processor.h b/tools/validator/human_processor.h new file mode 100644 index 0000000..52f174f --- /dev/null +++ b/tools/validator/human_processor.h
@@ -0,0 +1,14 @@
1#ifndef TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_
2#define TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_
3
4#include <string>
5
6namespace com::fourisland::lingo2_archipelago {
7
8struct CollectedInfo;
9
10void ProcessHumanData(const std::string& mapdir, CollectedInfo& info);
11
12} // namespace com::fourisland::lingo2_archipelago
13
14#endif /* TOOLS_VALIDATOR_HUMAN_PROCESSOR_H_ */
diff --git a/tools/validator/main.cpp b/tools/validator/main.cpp new file mode 100644 index 0000000..1a72e9a --- /dev/null +++ b/tools/validator/main.cpp
@@ -0,0 +1,34 @@
1#include "godot_processor.h"
2#include "human_processor.h"
3#include "structs.h"
4#include "validator.h"
5
6namespace com::fourisland::lingo2_archipelago {
7namespace {
8
9void Run(const std::string& mapdir, const std::string& repodir) {
10 CollectedInfo info;
11
12 ProcessHumanData(mapdir, info);
13 ProcessGodotData(repodir, info);
14
15 ValidateCollectedInfo(info);
16}
17
18} // namespace
19} // namespace com::fourisland::lingo2_archipelago
20
21int main(int argc, char** argv) {
22 if (argc != 3) {
23 std::cout << "Incorrect argument count." << std::endl;
24 std::cout << "Usage: validator [path to map directory] [path to Lingo 2 repository]" << std::endl;
25 return 1;
26 }
27
28 std::string mapdir = argv[1];
29 std::string repodir = argv[2];
30
31 com::fourisland::lingo2_archipelago::Run(mapdir, repodir);
32
33 return 0;
34}
diff --git a/tools/validator/structs.h b/tools/validator/structs.h new file mode 100644 index 0000000..d1d45f2 --- /dev/null +++ b/tools/validator/structs.h
@@ -0,0 +1,147 @@
1#ifndef TOOLS_VALIDATOR_STRUCTS_H_
2#define TOOLS_VALIDATOR_STRUCTS_H_
3
4#include <map>
5#include <string>
6#include <vector>
7
8#include "proto/human.pb.h"
9#include "util/identifiers.h"
10
11namespace com::fourisland::lingo2_archipelago {
12
13struct MalformedIdentifiers {
14 std::vector<PaintingIdentifier> paintings;
15 std::vector<PanelIdentifier> panels;
16 std::vector<KeyholderIdentifier> keyholders;
17
18 bool HasAny() const {
19 return !paintings.empty() || !panels.empty() || !keyholders.empty();
20 }
21};
22
23struct GameNodeInfo {
24 bool defined = false;
25 int uses = 0;
26};
27
28struct MapInfo {
29 std::map<std::string, GameNodeInfo> game_nodes;
30};
31
32struct RoomInfo {
33 std::vector<HumanRoom> definitions;
34
35 std::vector<DoorIdentifier> doors_referenced_by;
36 std::vector<PanelIdentifier> panels_referenced_by;
37 std::vector<HumanConnection> connections_referenced_by;
38};
39
40struct DoorInfo {
41 std::vector<HumanDoor> definitions;
42 bool has_id = false;
43
44 std::vector<HumanConnection> connections_referenced_by;
45 std::vector<DoorIdentifier> doors_referenced_by;
46 std::vector<PanelIdentifier> panels_referenced_by;
47 std::vector<PaintingIdentifier> paintings_referenced_by;
48 std::vector<PortIdentifier> ports_referenced_by;
49 std::vector<std::string> progressives_referenced_by;
50 std::vector<std::string> door_groups_referenced_by;
51
52 MalformedIdentifiers malformed_identifiers;
53};
54
55struct PortInfo {
56 std::vector<HumanPort> definitions;
57
58 std::vector<HumanConnection> connections_referenced_by;
59 std::vector<HumanConnection> target_connections_referenced_by;
60};
61
62struct PaintingInfo {
63 std::vector<HumanPainting> definitions;
64
65 std::vector<HumanConnection> connections_referenced_by;
66 std::vector<HumanConnection> target_connections_referenced_by;
67 std::vector<DoorIdentifier> doors_referenced_by;
68};
69
70struct ProxyInfo {
71 std::vector<Proxy> definitions;
72
73 std::vector<HumanConnection> connections_referenced_by;
74 std::vector<DoorIdentifier> doors_referenced_by;
75};
76
77struct PanelInfo {
78 std::vector<HumanPanel> definitions;
79 bool has_id = false;
80
81 std::string map_area_name;
82
83 std::vector<HumanConnection> connections_referenced_by;
84 std::vector<HumanConnection> target_connections_referenced_by;
85 std::vector<DoorIdentifier> doors_referenced_by;
86
87 std::map<std::string, ProxyInfo> proxies;
88};
89
90struct KeyholderInfo {
91 std::vector<HumanKeyholder> definitions;
92 bool has_id = false;
93
94 std::vector<DoorIdentifier> doors_referenced_by;
95};
96
97using LetterIdentifier = std::tuple<char, bool>;
98
99struct LetterInfo {
100 std::vector<RoomIdentifier> defined_in;
101 bool has_id = false;
102};
103
104struct EndingInfo {
105 std::vector<RoomIdentifier> defined_in;
106 bool has_id = false;
107
108 std::vector<DoorIdentifier> doors_referenced_by;
109};
110
111struct PanelNameInfo {
112 std::vector<PanelIdentifier> panels_used_by;
113};
114
115struct ProgressiveInfo {
116 std::vector<HumanProgressive> definitions;
117 bool has_id = false;
118
119 std::vector<DoorIdentifier> malformed_doors;
120};
121
122struct DoorGroupInfo {
123 std::vector<HumanDoorGroup> definitions;
124 bool has_id = false;
125
126 std::vector<DoorIdentifier> malformed_doors;
127};
128
129struct CollectedInfo {
130 std::map<std::string, MapInfo> maps;
131 std::map<RoomIdentifier, RoomInfo, RoomIdentifierLess> rooms;
132 std::map<DoorIdentifier, DoorInfo, DoorIdentifierLess> doors;
133 std::map<PortIdentifier, PortInfo, PortIdentifierLess> ports;
134 std::map<PaintingIdentifier, PaintingInfo, PaintingIdentifierLess> paintings;
135 std::map<PanelIdentifier, PanelInfo, PanelIdentifierLess> panels;
136 std::map<KeyholderIdentifier, KeyholderInfo, KeyholderIdentifierLess>
137 keyholders;
138 std::map<LetterIdentifier, LetterInfo> letters;
139 std::map<std::string, EndingInfo> endings;
140 std::map<std::string, PanelNameInfo> panel_names;
141 std::map<std::string, ProgressiveInfo> progressives;
142 std::map<std::string, DoorGroupInfo> door_groups;
143};
144
145} // namespace com::fourisland::lingo2_archipelago
146
147#endif /* TOOLS_VALIDATOR_STRUCTS_H_ */
diff --git a/tools/validator/validator.cpp b/tools/validator/validator.cpp new file mode 100644 index 0000000..dd41f5c --- /dev/null +++ b/tools/validator/validator.cpp
@@ -0,0 +1,550 @@
1#include "validator.h"
2
3#include <iostream>
4
5#include "proto/human.pb.h"
6#include "structs.h"
7#include "util/identifiers.h"
8
9namespace com::fourisland::lingo2_archipelago {
10namespace {
11
12class Validator {
13 public:
14 explicit Validator(const CollectedInfo& info) : info_(info) {}
15
16 void Validate() const {
17 for (const auto& [map_name, map_info] : info_.maps) {
18 ValidateMap(map_name, map_info);
19 }
20 for (const auto& [room_identifier, room_info] : info_.rooms) {
21 ValidateRoom(room_identifier, room_info);
22 }
23 for (const auto& [door_identifier, door_info] : info_.doors) {
24 ValidateDoor(door_identifier, door_info);
25 }
26 for (const auto& [port_identifier, port_info] : info_.ports) {
27 ValidatePort(port_identifier, port_info);
28 }
29 for (const auto& [painting_identifier, painting_info] : info_.paintings) {
30 ValidatePainting(painting_identifier, painting_info);
31 }
32 for (const auto& [panel_identifier, panel_info] : info_.panels) {
33 ValidatePanel(panel_identifier, panel_info);
34 }
35 for (const auto& [keyholder_identifier, keyholder_info] :
36 info_.keyholders) {
37 ValidateKeyholder(keyholder_identifier, keyholder_info);
38 }
39 for (const auto& [letter_identifier, letter_info] : info_.letters) {
40 ValidateLetter(letter_identifier, letter_info);
41 }
42 for (const auto& [ending_name, ending_info] : info_.endings) {
43 ValidateEnding(ending_name, ending_info);
44 }
45 for (const auto& [panel_name, panel_info] : info_.panel_names) {
46 ValidatePanelName(panel_name, panel_info);
47 }
48 for (const auto& [prog_name, prog_info] : info_.progressives) {
49 ValidateProgressive(prog_name, prog_info);
50 }
51 for (const auto& [group_name, group_info] : info_.door_groups) {
52 ValidateDoorGroup(group_name, group_info);
53 }
54 }
55
56 private:
57 void ValidateMap(const std::string& map_name, const MapInfo& map_info) const {
58 for (const auto& [node_path, node_info] : map_info.game_nodes) {
59 if (node_info.uses > 1) {
60 std::cout << "Map " << map_name << " node " << node_path
61 << " is used in multiple places." << std::endl;
62 } else if (node_info.uses == 0) {
63 std::cout << "Map " << map_name << " node " << node_path
64 << " is not used." << std::endl;
65 }
66
67 if (!node_info.defined) {
68 std::cout << "Map " << map_name << " node " << node_path
69 << " is not defined in the game file." << std::endl;
70 }
71 }
72 }
73
74 void ValidateRoom(const RoomIdentifier& room_identifier,
75 const RoomInfo& room_info) const {
76 if (room_info.definitions.empty()) {
77 std::cout << "Room " << room_identifier.ShortDebugString()
78 << " has no definition, but was referenced:" << std::endl;
79
80 for (const DoorIdentifier& door_identifier :
81 room_info.doors_referenced_by) {
82 std::cout << " DOOR " << door_identifier.ShortDebugString()
83 << std::endl;
84 }
85
86 for (const PanelIdentifier& panel_identifier :
87 room_info.panels_referenced_by) {
88 std::cout << " PANEL " << panel_identifier.ShortDebugString()
89 << std::endl;
90 }
91
92 for (const HumanConnection& connection :
93 room_info.connections_referenced_by) {
94 std::cout << " CONNECTION " << connection.ShortDebugString()
95 << std::endl;
96 }
97 } else if (room_info.definitions.size() > 1) {
98 std::cout << "Room " << room_identifier.ShortDebugString()
99 << " was defined multiple times." << std::endl;
100 }
101 }
102
103 bool DoesDoorNeedLocationName(const HumanDoor& h_door,
104 const std::string& map_name) const {
105 if (h_door.type() != DoorType::STANDARD) {
106 return false;
107 }
108
109 if (h_door.keyholders_size() > 0 || h_door.endings_size() > 0 ||
110 h_door.complete_at() > 0) {
111 return true;
112 }
113
114 if (h_door.panels_size() > 4) {
115 return true;
116 }
117
118 std::set<std::string> map_areas;
119 for (const PanelIdentifier& pi : h_door.panels()) {
120 auto full_pi =
121 GetCompletePanelIdentifierWithoutAnswer(pi, map_name, std::nullopt);
122 if (full_pi) {
123 auto panel_info_it = info_.panels.find(*full_pi);
124 if (panel_info_it != info_.panels.end()) {
125 const PanelInfo& panel_info = panel_info_it->second;
126
127 map_areas.insert(panel_info.map_area_name);
128 }
129 }
130 }
131
132 if (map_areas.size() > 1) {
133 return true;
134 }
135
136 return false;
137 }
138
139 void ValidateDoor(const DoorIdentifier& door_identifier,
140 const DoorInfo& door_info) const {
141 if (door_info.definitions.empty()) {
142 std::cout << "Door " << door_identifier.ShortDebugString()
143 << " has no definition, but was referenced:" << std::endl;
144
145 for (const DoorIdentifier& other_door_identifier :
146 door_info.doors_referenced_by) {
147 std::cout << " DOOR " << other_door_identifier.ShortDebugString()
148 << std::endl;
149 }
150
151 for (const PanelIdentifier& panel_identifier :
152 door_info.panels_referenced_by) {
153 std::cout << " PANEL " << panel_identifier.ShortDebugString()
154 << std::endl;
155 }
156
157 for (const PaintingIdentifier& painting_identifier :
158 door_info.paintings_referenced_by) {
159 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
160 << std::endl;
161 }
162
163 for (const PortIdentifier& port_identifier :
164 door_info.ports_referenced_by) {
165 std::cout << " PORT " << port_identifier.ShortDebugString()
166 << std::endl;
167 }
168
169 for (const HumanConnection& connection :
170 door_info.connections_referenced_by) {
171 std::cout << " CONNECTION " << connection.ShortDebugString()
172 << std::endl;
173 }
174
175 for (const std::string& prog_name :
176 door_info.progressives_referenced_by) {
177 std::cout << " PROGRESSIVE " << prog_name << std::endl;
178 }
179
180 for (const std::string& group_name :
181 door_info.door_groups_referenced_by) {
182 std::cout << " DOOR GROUP " << group_name << std::endl;
183 }
184
185 if (door_info.has_id) {
186 std::cout << " An AP ID is present." << std::endl;
187 }
188 } else if (door_info.definitions.size() > 1) {
189 std::cout << "Door " << door_identifier.ShortDebugString()
190 << " was defined multiple times." << std::endl;
191 }
192
193 if (door_info.malformed_identifiers.HasAny()) {
194 std::cout << "Door " << door_identifier.ShortDebugString()
195 << " has malformed identifiers:" << std::endl;
196
197 for (const PaintingIdentifier& painting_identifier :
198 door_info.malformed_identifiers.paintings) {
199 std::cout << " PAINTING " << painting_identifier.ShortDebugString()
200 << std::endl;
201 }
202
203 for (const PanelIdentifier& panel_identifier :
204 door_info.malformed_identifiers.panels) {
205 std::cout << " PANEL " << panel_identifier.ShortDebugString()
206 << std::endl;
207 }
208
209 for (const KeyholderIdentifier& keyholder_identifier :
210 door_info.malformed_identifiers.keyholders) {
211 std::cout << " KEYHOLDER " << keyholder_identifier.ShortDebugString()
212 << std::endl;
213 }
214 }
215
216 for (const HumanDoor& h_door : door_info.definitions) {
217 if (DoesDoorNeedLocationName(h_door, door_identifier.map()) &&
218 !h_door.has_location_name()) {
219 std::cout << "Door " << door_identifier.ShortDebugString()
220 << " needs an explicit location name." << std::endl;
221 }
222
223 if (h_door.double_letters() &&
224 (h_door.type() == DoorType::STANDARD ||
225 h_door.type() == DoorType::LOCATION_ONLY ||
226 h_door.type() == DoorType::GRAVESTONE)) {
227 std::cout << "Door " << door_identifier.ShortDebugString()
228 << " is a location that depends on double_letters."
229 << std::endl;
230 }
231
232 bool needs_id = (h_door.type() != DoorType::EVENT);
233 if (door_info.has_id != needs_id) {
234 if (needs_id) {
235 std::cout << "Door " << door_identifier.ShortDebugString()
236 << " is missing an AP ID." << std::endl;
237 } else {
238 std::cout << "Door " << door_identifier.ShortDebugString()
239 << " should not have an AP ID." << std::endl;
240 }
241 }
242 }
243 }
244
245 void ValidatePort(const PortIdentifier& port_identifier,
246 const PortInfo& port_info) const {
247 if (port_info.definitions.empty()) {
248 std::cout << "Port " << port_identifier.ShortDebugString()
249 << " has no definition, but was referenced:" << std::endl;
250
251 for (const HumanConnection& connection :
252 port_info.connections_referenced_by) {
253 std::cout << " CONNECTION " << connection.ShortDebugString()
254 << std::endl;
255 }
256 } else if (port_info.definitions.size() > 1) {
257 std::cout << "Port " << port_identifier.ShortDebugString()
258 << " was defined multiple times." << std::endl;
259 }
260
261 if (!port_info.target_connections_referenced_by.empty()) {
262 for (const HumanPort& port : port_info.definitions) {
263 if (port.has_required_door()) {
264 std::cout << "Port " << port_identifier.ShortDebugString()
265 << " has a required door but is the target of a connection:"
266 << std::endl;
267
268 for (const HumanConnection& connection :
269 port_info.target_connections_referenced_by) {
270 std::cout << " CONNECTION " << connection.ShortDebugString()
271 << std::endl;
272 }
273 }
274 }
275 }
276 }
277
278 void ValidatePainting(const PaintingIdentifier& painting_identifier,
279 const PaintingInfo& painting_info) const {
280 if (painting_info.definitions.empty()) {
281 std::cout << "Painting " << painting_identifier.ShortDebugString()
282 << " has no definition, but was referenced:" << std::endl;
283
284 for (const DoorIdentifier& door_identifier :
285 painting_info.doors_referenced_by) {
286 std::cout << " DOOR " << door_identifier.ShortDebugString()
287 << std::endl;
288 }
289
290 for (const HumanConnection& connection :
291 painting_info.connections_referenced_by) {
292 std::cout << " CONNECTION " << connection.ShortDebugString()
293 << std::endl;
294 }
295 } else if (painting_info.definitions.size() > 1) {
296 std::cout << "Painting " << painting_identifier.ShortDebugString()
297 << " was defined multiple times." << std::endl;
298 }
299
300 if (!painting_info.target_connections_referenced_by.empty()) {
301 for (const HumanPainting& painting : painting_info.definitions) {
302 if (painting.has_required_door()) {
303 std::cout << "Painting " << painting_identifier.ShortDebugString()
304 << " has a required door but is the target of a connection:"
305 << std::endl;
306
307 for (const HumanConnection& connection :
308 painting_info.target_connections_referenced_by) {
309 std::cout << " CONNECTION " << connection.ShortDebugString()
310 << std::endl;
311 }
312 }
313 }
314 }
315 }
316
317 void ValidatePanel(const PanelIdentifier& panel_identifier,
318 const PanelInfo& panel_info) const {
319 if (panel_identifier.name().empty()) {
320 std::cout << "Panel " << panel_identifier.ShortDebugString()
321 << " has no name." << std::endl;
322 }
323
324 if (panel_info.definitions.empty()) {
325 std::cout << "Panel " << panel_identifier.ShortDebugString()
326 << " has no definition, but was referenced:" << std::endl;
327
328 for (const DoorIdentifier& door_identifier :
329 panel_info.doors_referenced_by) {
330 std::cout << " DOOR " << door_identifier.ShortDebugString()
331 << std::endl;
332 }
333
334 for (const HumanConnection& connection :
335 panel_info.connections_referenced_by) {
336 std::cout << " CONNECTION " << connection.ShortDebugString()
337 << std::endl;
338 }
339
340 if (panel_info.has_id) {
341 std::cout << " An AP ID is present." << std::endl;
342 }
343 } else if (panel_info.definitions.size() > 1) {
344 std::cout << "Panel " << panel_identifier.ShortDebugString()
345 << " was defined multiple times." << std::endl;
346 }
347
348 for (const auto& [answer, proxy_info] : panel_info.proxies) {
349 if (proxy_info.definitions.empty()) {
350 std::cout << "Panel " << panel_identifier.ShortDebugString()
351 << " with answer \"" << answer
352 << "\" has no definition, but was referenced:" << std::endl;
353
354 for (const DoorIdentifier& door_identifier :
355 proxy_info.doors_referenced_by) {
356 std::cout << " DOOR " << door_identifier.ShortDebugString()
357 << std::endl;
358 }
359
360 for (const HumanConnection& connection :
361 proxy_info.connections_referenced_by) {
362 std::cout << " CONNECTION " << connection.ShortDebugString()
363 << std::endl;
364 }
365 } else if (proxy_info.definitions.size() > 1) {
366 std::cout << "Panel " << panel_identifier.ShortDebugString()
367 << " with answer \"" << answer
368 << "\" was defined multiple times." << std::endl;
369 }
370 }
371
372 if (!panel_info.has_id) {
373 std::cout << "Panel " << panel_identifier.ShortDebugString()
374 << " is missing an AP ID." << std::endl;
375 }
376
377 if (!panel_info.target_connections_referenced_by.empty()) {
378 for (const HumanPanel& panel : panel_info.definitions) {
379 if (panel.has_required_door()) {
380 std::cout << "Panel " << panel_identifier.ShortDebugString()
381 << " has a required door but is the target of a connection:"
382 << std::endl;
383
384 for (const HumanConnection& connection :
385 panel_info.target_connections_referenced_by) {
386 std::cout << " CONNECTION " << connection.ShortDebugString()
387 << std::endl;
388 }
389 }
390 }
391 }
392 }
393
394 void ValidateKeyholder(const KeyholderIdentifier& keyholder_identifier,
395 const KeyholderInfo& keyholder_info) const {
396 if (keyholder_info.definitions.empty()) {
397 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
398 << " has no definition, but was referenced:" << std::endl;
399
400 for (const DoorIdentifier& door_identifier :
401 keyholder_info.doors_referenced_by) {
402 std::cout << " DOOR " << door_identifier.ShortDebugString()
403 << std::endl;
404 }
405
406 if (keyholder_info.has_id) {
407 std::cout << " An AP ID is present." << std::endl;
408 }
409 } else if (keyholder_info.definitions.size() > 1) {
410 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
411 << " was defined multiple times." << std::endl;
412 }
413
414 for (const HumanKeyholder& h_keyholder : keyholder_info.definitions) {
415 bool needs_id = (h_keyholder.has_key());
416
417 if (needs_id != keyholder_info.has_id) {
418 if (needs_id) {
419 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
420 << " is missing an AP ID." << std::endl;
421 } else {
422 std::cout << "Keyholder " << keyholder_identifier.ShortDebugString()
423 << " should not have an AP ID." << std::endl;
424 }
425 }
426 }
427 }
428
429 void ValidateLetter(const LetterIdentifier& letter_identifier,
430 const LetterInfo& letter_info) const {
431 std::string letter_name = std::string(1, std::get<0>(letter_identifier)) +
432 (std::get<1>(letter_identifier) ? "2" : "1");
433
434 if (letter_info.defined_in.empty()) {
435 std::cout << "Letter " << letter_name
436 << " has no definition, but was referenced:" << std::endl;
437
438 if (letter_info.has_id) {
439 std::cout << " An AP ID is present." << std::endl;
440 }
441 } else if (letter_info.defined_in.size() > 1) {
442 std::cout << "Letter " << letter_name
443 << " was defined in multiple places:" << std::endl;
444
445 for (const RoomIdentifier& room_identifier : letter_info.defined_in) {
446 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
447 }
448 }
449
450 if (!letter_info.has_id) {
451 std::cout << "Letter " << letter_name << " is missing an AP ID."
452 << std::endl;
453 }
454 }
455
456 void ValidateEnding(const std::string& ending_name,
457 const EndingInfo& ending_info) const {
458 if (ending_info.defined_in.empty()) {
459 std::cout << "Ending " << ending_name
460 << " has no definition, but was referenced:" << std::endl;
461
462 for (const DoorIdentifier& door_identifier :
463 ending_info.doors_referenced_by) {
464 std::cout << " DOOR " << door_identifier.ShortDebugString()
465 << std::endl;
466 }
467
468 if (ending_info.has_id) {
469 std::cout << " An AP ID is present." << std::endl;
470 }
471 } else if (ending_info.defined_in.size() > 1) {
472 std::cout << "Ending " << ending_name
473 << " was defined in multiple places:" << std::endl;
474
475 for (const RoomIdentifier& room_identifier : ending_info.defined_in) {
476 std::cout << " " << room_identifier.ShortDebugString() << std::endl;
477 }
478 }
479
480 if (!ending_info.has_id) {
481 std::cout << "Ending " << ending_name << " is missing an AP ID."
482 << std::endl;
483 }
484 }
485
486 void ValidatePanelName(const std::string& panel_name,
487 const PanelNameInfo& panel_info) const {
488 if (panel_info.panels_used_by.size() > 1) {
489 std::cout << "The location name \"" << panel_name
490 << "\" is used by multiple panels:" << std::endl;
491
492 for (const PanelIdentifier& panel_identifier :
493 panel_info.panels_used_by) {
494 std::cout << " PANEL " << panel_identifier.ShortDebugString()
495 << std::endl;
496 }
497 }
498 }
499
500 void ValidateProgressive(const std::string& prog_name,
501 const ProgressiveInfo& prog_info) const {
502 if (prog_info.definitions.empty()) {
503 std::cout << "Progressive \"" << prog_name
504 << "\" has no definition, but was referenced:" << std::endl;
505
506 if (prog_info.has_id) {
507 std::cout << " An AP ID is present." << std::endl;
508 }
509 } else if (prog_info.definitions.size() > 1) {
510 std::cout << "Progressive \"" << prog_name
511 << "\" has multiple definitions." << std::endl;
512 }
513
514 if (!prog_info.has_id) {
515 std::cout << "Progressive \"" << prog_name << "\" is missing an AP ID."
516 << std::endl;
517 }
518 }
519
520 void ValidateDoorGroup(const std::string& group_name,
521 const DoorGroupInfo& group_info) const {
522 if (group_info.definitions.empty()) {
523 std::cout << "Door group \"" << group_name
524 << "\" has no definition, but was referenced:" << std::endl;
525
526 if (group_info.has_id) {
527 std::cout << " An AP ID is present." << std::endl;
528 }
529 } else if (group_info.definitions.size() > 1) {
530 std::cout << "Door group \"" << group_name
531 << "\" has multiple definitions." << std::endl;
532 }
533
534 if (!group_info.has_id) {
535 std::cout << "Door group \"" << group_name << "\" is missing an AP ID."
536 << std::endl;
537 }
538 }
539
540 const CollectedInfo& info_;
541};
542
543} // namespace
544
545void ValidateCollectedInfo(const CollectedInfo& info) {
546 Validator validator(info);
547 validator.Validate();
548}
549
550} // namespace com::fourisland::lingo2_archipelago
diff --git a/tools/validator/validator.h b/tools/validator/validator.h new file mode 100644 index 0000000..b710429 --- /dev/null +++ b/tools/validator/validator.h
@@ -0,0 +1,12 @@
1#ifndef TOOLS_VALIDATOR_VALIDATOR_H_
2#define TOOLS_VALIDATOR_VALIDATOR_H
3
4namespace com::fourisland::lingo2_archipelago {
5
6struct CollectedInfo;
7
8void ValidateCollectedInfo(const CollectedInfo& info);
9
10} // namespace com::fourisland::lingo2_archipelago
11
12#endif /* TOOLS_VALIDATOR_VALIDATOR_H */