about summary refs log tree commit diff stats
path: root/tools/validator/human_processor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/validator/human_processor.cpp')
-rw-r--r--tools/validator/human_processor.cpp259
1 files changed, 247 insertions, 12 deletions
diff --git a/tools/validator/human_processor.cpp b/tools/validator/human_processor.cpp index 5382443..ffa9765 100644 --- a/tools/validator/human_processor.cpp +++ b/tools/validator/human_processor.cpp
@@ -1,5 +1,6 @@
1#include "human_processor.h" 1#include "human_processor.h"
2 2
3#include <fmt/core.h>
3#include <google/protobuf/message.h> 4#include <google/protobuf/message.h>
4#include <google/protobuf/text_format.h> 5#include <google/protobuf/text_format.h>
5 6
@@ -12,6 +13,7 @@
12#include <string> 13#include <string>
13 14
14#include "structs.h" 15#include "structs.h"
16#include "util/ids_yaml_format.h"
15 17
16namespace com::fourisland::lingo2_archipelago { 18namespace com::fourisland::lingo2_archipelago {
17namespace { 19namespace {
@@ -40,7 +42,9 @@ class HumanProcessor {
40 42
41 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt); 43 ProcessConnectionsFile(datadir_path / "connections.txtpb", std::nullopt);
42 ProcessMaps(datadir_path); 44 ProcessMaps(datadir_path);
43 ProcessIdsFile(datadir_path / "ids.txtpb"); 45 ProcessProgressivesFile(datadir_path / "progressives.txtpb");
46 ProcessDoorGroupsFile(datadir_path / "door_groups.txtpb");
47 ProcessIdsFile(datadir_path / "ids.yaml");
44 } 48 }
45 49
46 private: 50 private:
@@ -53,13 +57,43 @@ class HumanProcessor {
53 } 57 }
54 58
55 void ProcessMap(std::filesystem::path path) { 59 void ProcessMap(std::filesystem::path path) {
56 std::string map_name = path.filename(); 60 std::string map_name = path.filename().string();
57 61
62 ProcessMetadataFile(path / "metadata.txtpb", map_name);
58 ProcessConnectionsFile(path / "connections.txtpb", map_name); 63 ProcessConnectionsFile(path / "connections.txtpb", map_name);
59 ProcessDoorsFile(path / "doors.txtpb", map_name); 64 ProcessDoorsFile(path / "doors.txtpb", map_name);
60 ProcessRooms(path / "rooms", map_name); 65 ProcessRooms(path / "rooms", map_name);
61 } 66 }
62 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 for (const std::string& path : metadata.custom_nodes()) {
82 map_info.game_nodes[path].defined = true;
83 }
84
85 if (metadata.has_worldport_entrance()) {
86 auto port_identifier = GetCompletePortIdentifier(
87 metadata.worldport_entrance(), current_map_name, std::nullopt);
88 if (port_identifier) {
89 PortInfo& port_info = info_.ports[*port_identifier];
90 port_info.map_worldport_entrances.push_back(current_map_name);
91 } else {
92 map_info.malformed_worldport_entrance = metadata.worldport_entrance();
93 }
94 }
95 }
96
63 void ProcessRooms(std::filesystem::path path, 97 void ProcessRooms(std::filesystem::path path,
64 const std::string& current_map_name) { 98 const std::string& current_map_name) {
65 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) { 99 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
@@ -78,7 +112,7 @@ class HumanProcessor {
78 room_info.definitions.push_back(h_room); 112 room_info.definitions.push_back(h_room);
79 113
80 for (const HumanPanel& h_panel : h_room.panels()) { 114 for (const HumanPanel& h_panel : h_room.panels()) {
81 ProcessPanel(h_panel, current_map_name, h_room.name()); 115 ProcessPanel(h_panel, current_map_name, h_room);
82 } 116 }
83 117
84 for (const HumanPainting& h_painting : h_room.paintings()) { 118 for (const HumanPainting& h_painting : h_room.paintings()) {
@@ -100,23 +134,31 @@ class HumanProcessor {
100 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) { 134 for (const HumanKeyholder& h_keyholder : h_room.keyholders()) {
101 ProcessKeyholder(h_keyholder, current_map_name, h_room.name()); 135 ProcessKeyholder(h_keyholder, current_map_name, h_room.name());
102 } 136 }
137
138 for (const HumanEnding& h_ending : h_room.endings()) {
139 ProcessEnding(h_ending, current_map_name, h_room.name());
140 }
103 } 141 }
104 142
105 void ProcessPanel(const HumanPanel& h_panel, 143 void ProcessPanel(const HumanPanel& h_panel,
106 const std::string& current_map_name, 144 const std::string& current_map_name,
107 const std::string& current_room_name) { 145 const HumanRoom& h_room) {
108 PanelIdentifier panel_identifier; 146 PanelIdentifier panel_identifier;
109 panel_identifier.set_map(current_map_name); 147 panel_identifier.set_map(current_map_name);
110 panel_identifier.set_room(current_room_name); 148 panel_identifier.set_room(h_room.name());
111 panel_identifier.set_name(h_panel.name()); 149 panel_identifier.set_name(h_panel.name());
112 150
113 PanelInfo& panel_info = info_.panels[panel_identifier]; 151 PanelInfo& panel_info = info_.panels[panel_identifier];
114 panel_info.definitions.push_back(h_panel); 152 panel_info.definitions.push_back(h_panel);
115 panel_info.proxies[h_panel.answer()].definitions.push_back(Proxy()); 153
154 MapInfo& map_info = info_.maps[current_map_name];
155 map_info.game_nodes[h_panel.path()].uses++;
116 156
117 for (const Proxy& h_proxy : h_panel.proxies()) { 157 for (const Proxy& h_proxy : h_panel.proxies()) {
118 ProxyInfo& proxy_info = panel_info.proxies[h_proxy.answer()]; 158 ProxyInfo& proxy_info = panel_info.proxies[h_proxy.answer()];
119 proxy_info.definitions.push_back(h_proxy); 159 proxy_info.definitions.push_back(h_proxy);
160
161 map_info.game_nodes[h_proxy.path()].uses++;
120 } 162 }
121 163
122 if (h_panel.has_required_door()) { 164 if (h_panel.has_required_door()) {
@@ -132,6 +174,24 @@ class HumanProcessor {
132 RoomInfo& required_room_info = info_.rooms[required_room_identifier]; 174 RoomInfo& required_room_info = info_.rooms[required_room_identifier];
133 required_room_info.panels_referenced_by.push_back(panel_identifier); 175 required_room_info.panels_referenced_by.push_back(panel_identifier);
134 } 176 }
177
178 std::string map_area_name = current_map_name;
179 if (h_room.has_panel_display_name()) {
180 map_area_name =
181 fmt::format("{} ({})", current_map_name, h_room.panel_display_name());
182 }
183
184 panel_info.map_area_name = map_area_name;
185
186 std::string panelsanity_name;
187 if (h_panel.has_display_name()) {
188 panelsanity_name =
189 fmt::format("{} - {}", map_area_name, h_panel.display_name());
190 } else {
191 panelsanity_name = fmt::format("{} - {}", map_area_name, h_panel.name());
192 }
193 info_.panel_names[panelsanity_name].panels_used_by.push_back(
194 panel_identifier);
135 } 195 }
136 196
137 void ProcessPainting(const HumanPainting& h_painting, 197 void ProcessPainting(const HumanPainting& h_painting,
@@ -145,6 +205,9 @@ class HumanProcessor {
145 PaintingInfo& painting_info = info_.paintings[painting_identifier]; 205 PaintingInfo& painting_info = info_.paintings[painting_identifier];
146 painting_info.definitions.push_back(h_painting); 206 painting_info.definitions.push_back(h_painting);
147 207
208 MapInfo& map_info = info_.maps[current_map_name];
209 map_info.game_nodes[h_painting.path()].uses++;
210
148 if (h_painting.has_required_door()) { 211 if (h_painting.has_required_door()) {
149 DoorIdentifier required_door_identifier = *GetCompleteDoorIdentifier( 212 DoorIdentifier required_door_identifier = *GetCompleteDoorIdentifier(
150 h_painting.required_door(), current_map_name); 213 h_painting.required_door(), current_map_name);
@@ -163,6 +226,9 @@ class HumanProcessor {
163 PortInfo& port_info = info_.ports[port_identifier]; 226 PortInfo& port_info = info_.ports[port_identifier];
164 port_info.definitions.push_back(h_port); 227 port_info.definitions.push_back(h_port);
165 228
229 MapInfo& map_info = info_.maps[current_map_name];
230 map_info.game_nodes[h_port.path()].uses++;
231
166 if (h_port.has_required_door()) { 232 if (h_port.has_required_door()) {
167 DoorIdentifier required_door_identifier = 233 DoorIdentifier required_door_identifier =
168 *GetCompleteDoorIdentifier(h_port.required_door(), current_map_name); 234 *GetCompleteDoorIdentifier(h_port.required_door(), current_map_name);
@@ -182,12 +248,16 @@ class HumanProcessor {
182 room_identifier.set_map(current_map_name); 248 room_identifier.set_map(current_map_name);
183 room_identifier.set_name(current_room_name); 249 room_identifier.set_name(current_room_name);
184 letter_info.defined_in.push_back(room_identifier); 250 letter_info.defined_in.push_back(room_identifier);
251
252 MapInfo& map_info = info_.maps[current_map_name];
253 map_info.game_nodes[h_letter.path()].uses++;
185 } 254 }
186 255
187 void ProcessMastery(const HumanMastery& h_mastery, 256 void ProcessMastery(const HumanMastery& h_mastery,
188 const std::string& current_map_name, 257 const std::string& current_map_name,
189 const std::string& current_room_name) { 258 const std::string& current_room_name) {
190 // Nothing really to validate about masteries yet. 259 MapInfo& map_info = info_.maps[current_map_name];
260 map_info.game_nodes[h_mastery.path()].uses++;
191 } 261 }
192 262
193 void ProcessKeyholder(const HumanKeyholder& h_keyholder, 263 void ProcessKeyholder(const HumanKeyholder& h_keyholder,
@@ -200,6 +270,23 @@ class HumanProcessor {
200 270
201 KeyholderInfo& keyholder_info = info_.keyholders[keyholder_identifier]; 271 KeyholderInfo& keyholder_info = info_.keyholders[keyholder_identifier];
202 keyholder_info.definitions.push_back(h_keyholder); 272 keyholder_info.definitions.push_back(h_keyholder);
273
274 MapInfo& map_info = info_.maps[current_map_name];
275 map_info.game_nodes[h_keyholder.path()].uses++;
276 }
277
278 void ProcessEnding(const HumanEnding& h_ending,
279 const std::string& current_map_name,
280 const std::string& current_room_name) {
281 EndingInfo& ending_info = info_.endings[h_ending.name()];
282
283 RoomIdentifier room_identifier;
284 room_identifier.set_map(current_map_name);
285 room_identifier.set_name(current_room_name);
286 ending_info.defined_in.push_back(room_identifier);
287
288 MapInfo& map_info = info_.maps[current_map_name];
289 map_info.game_nodes[h_ending.path()].uses++;
203 } 290 }
204 291
205 void ProcessDoorsFile(std::filesystem::path path, 292 void ProcessDoorsFile(std::filesystem::path path,
@@ -317,7 +404,9 @@ class HumanProcessor {
317 } 404 }
318 } else if (human_connection.has_from()) { 405 } else if (human_connection.has_from()) {
319 ProcessSingleConnection(human_connection, human_connection.from(), 406 ProcessSingleConnection(human_connection, human_connection.from(),
320 current_map_name); 407 current_map_name,
408 /*is_target=*/!human_connection.oneway() &&
409 !human_connection.bypass_target_door());
321 } 410 }
322 411
323 if (human_connection.has_to_room()) { 412 if (human_connection.has_to_room()) {
@@ -333,8 +422,9 @@ class HumanProcessor {
333 std::cout << "A global connection used to_room." << std::endl; 422 std::cout << "A global connection used to_room." << std::endl;
334 } 423 }
335 } else if (human_connection.has_to()) { 424 } else if (human_connection.has_to()) {
336 ProcessSingleConnection(human_connection, human_connection.to(), 425 ProcessSingleConnection(
337 current_map_name); 426 human_connection, human_connection.to(), current_map_name,
427 /*is_target=*/!human_connection.bypass_target_door());
338 } 428 }
339 429
340 if (human_connection.has_door()) { 430 if (human_connection.has_door()) {
@@ -355,7 +445,7 @@ class HumanProcessor {
355 void ProcessSingleConnection( 445 void ProcessSingleConnection(
356 const HumanConnection& human_connection, 446 const HumanConnection& human_connection,
357 const HumanConnection::Endpoint& endpoint, 447 const HumanConnection::Endpoint& endpoint,
358 const std::optional<std::string>& current_map_name) { 448 const std::optional<std::string>& current_map_name, bool is_target) {
359 if (endpoint.has_room()) { 449 if (endpoint.has_room()) {
360 auto room_identifier = 450 auto room_identifier =
361 GetCompleteRoomIdentifier(endpoint.room(), current_map_name); 451 GetCompleteRoomIdentifier(endpoint.room(), current_map_name);
@@ -374,6 +464,11 @@ class HumanProcessor {
374 if (painting_identifier) { 464 if (painting_identifier) {
375 PaintingInfo& painting_info = info_.paintings[*painting_identifier]; 465 PaintingInfo& painting_info = info_.paintings[*painting_identifier];
376 painting_info.connections_referenced_by.push_back(human_connection); 466 painting_info.connections_referenced_by.push_back(human_connection);
467
468 if (is_target) {
469 painting_info.target_connections_referenced_by.push_back(
470 human_connection);
471 }
377 } else { 472 } else {
378 // Not sure where else to store this right now. 473 // Not sure where else to store this right now.
379 std::cout 474 std::cout
@@ -386,6 +481,11 @@ class HumanProcessor {
386 if (port_identifier) { 481 if (port_identifier) {
387 PortInfo& port_info = info_.ports[*port_identifier]; 482 PortInfo& port_info = info_.ports[*port_identifier];
388 port_info.connections_referenced_by.push_back(human_connection); 483 port_info.connections_referenced_by.push_back(human_connection);
484
485 if (is_target) {
486 port_info.target_connections_referenced_by.push_back(
487 human_connection);
488 }
389 } else { 489 } else {
390 // Not sure where else to store this right now. 490 // Not sure where else to store this right now.
391 std::cout 491 std::cout
@@ -403,12 +503,147 @@ class HumanProcessor {
403 panel_info.proxies[endpoint.panel().answer()] 503 panel_info.proxies[endpoint.panel().answer()]
404 .connections_referenced_by.push_back(human_connection); 504 .connections_referenced_by.push_back(human_connection);
405 } 505 }
506
507 if (is_target) {
508 panel_info.target_connections_referenced_by.push_back(
509 human_connection);
510 }
511 }
512 }
513 }
514
515 void ProcessProgressivesFile(std::filesystem::path path) {
516 if (!std::filesystem::exists(path)) {
517 return;
518 }
519
520 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
521
522 for (const HumanProgressive& h_prog : h_progs.progressives()) {
523 ProcessProgressive(h_prog);
524 }
525 }
526
527 void ProcessProgressive(const HumanProgressive& h_prog) {
528 ProgressiveInfo& prog_info = info_.progressives[h_prog.name()];
529 prog_info.definitions.push_back(h_prog);
530
531 for (const DoorIdentifier& di : h_prog.doors()) {
532 if (!di.has_map()) {
533 prog_info.malformed_doors.push_back(di);
534 continue;
535 }
536
537 DoorInfo& door_info = info_.doors[di];
538 door_info.progressives_referenced_by.push_back(h_prog.name());
539 }
540 }
541
542 void ProcessDoorGroupsFile(std::filesystem::path path) {
543 if (!std::filesystem::exists(path)) {
544 return;
545 }
546
547 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
548
549 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
550 ProcessDoorGroup(h_group);
551 }
552 }
553
554 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
555 DoorGroupInfo& group_info = info_.door_groups[h_group.name()];
556 group_info.definitions.push_back(h_group);
557
558 for (const DoorIdentifier& di : h_group.doors()) {
559 if (!di.has_map()) {
560 group_info.malformed_doors.push_back(di);
561 continue;
406 } 562 }
563
564 DoorInfo& door_info = info_.doors[di];
565 door_info.door_groups_referenced_by.push_back(h_group.name());
407 } 566 }
408 } 567 }
409 568
410 void ProcessIdsFile(std::filesystem::path path) { 569 void ProcessIdsFile(std::filesystem::path path) {
411 // Ignore this for now. 570 auto ids = ReadIdsFromYaml(path.string());
571
572 DoorIdentifier di;
573 PanelIdentifier pai;
574 PortIdentifier poi;
575 KeyholderIdentifier ki;
576
577 for (const auto& [map_name, map] : ids.maps()) {
578 di.set_map(map_name);
579 pai.set_map(map_name);
580 poi.set_map(map_name);
581 ki.set_map(map_name);
582
583 for (const auto& [door_name, ap_id] : map.doors()) {
584 di.set_name(door_name);
585
586 DoorInfo& door_info = info_.doors[di];
587 door_info.has_id = true;
588 }
589
590 for (const auto& [room_name, room] : map.rooms()) {
591 pai.set_room(room_name);
592 poi.set_room(room_name);
593 ki.set_room(room_name);
594
595 for (const auto& [panel_name, ap_id] : room.panels()) {
596 pai.set_name(panel_name);
597
598 PanelInfo& panel_info = info_.panels[pai];
599 panel_info.has_id = true;
600 }
601
602 for (const auto& [mastery_name, ap_id] : room.masteries()) {
603 // TODO: Mastery
604 }
605
606 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
607 ki.set_name(keyholder_name);
608
609 KeyholderInfo& keyholder_info = info_.keyholders[ki];
610 keyholder_info.has_id = true;
611 }
612
613 for (const auto& [port_name, ap_id] : room.ports()) {
614 poi.set_name(port_name);
615
616 PortInfo& port_info = info_.ports[poi];
617 port_info.has_id = true;
618 }
619 }
620 }
621
622 for (const auto& [tag, id] : ids.special()) {
623 // TODO: Specials
624 }
625
626 for (const auto& [letter_name, ap_id] : ids.letters()) {
627 LetterIdentifier li =
628 std::make_tuple(letter_name[0], letter_name[1] == '2');
629 LetterInfo& letter_info = info_.letters[li];
630 letter_info.has_id = true;
631 }
632
633 for (const auto& [ending_name, ap_id] : ids.endings()) {
634 EndingInfo& ending_info = info_.endings[ending_name];
635 ending_info.has_id = true;
636 }
637
638 for (const auto& [prog_name, ap_id] : ids.progressives()) {
639 ProgressiveInfo& prog_info = info_.progressives[prog_name];
640 prog_info.has_id = true;
641 }
642
643 for (const auto& [group_name, ap_id] : ids.door_groups()) {
644 DoorGroupInfo& group_info = info_.door_groups[group_name];
645 group_info.has_id = true;
646 }
412 } 647 }
413 648
414 std::string mapdir_; 649 std::string mapdir_;