about summary refs log tree commit diff stats
path: root/tools/datapacker/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/datapacker/main.cpp')
-rw-r--r--tools/datapacker/main.cpp230
1 files changed, 214 insertions, 16 deletions
diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index d3908b4..8109bf5 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,38 @@ 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 map.set_type(metadata.type());
92
93 if (metadata.has_display_name()) {
94 map.set_display_name(metadata.display_name());
95 }
96
97 if (metadata.has_worldport_entrance()) {
98 map.set_worldport_entrance(container_.FindOrAddPort(
99 map_name, metadata.worldport_entrance().room(),
100 metadata.worldport_entrance().name(), std::nullopt, std::nullopt));
101 }
102 }
103
75 void ProcessRooms(std::filesystem::path path, 104 void ProcessRooms(std::filesystem::path path,
76 const std::string& current_map_name) { 105 const std::string& current_map_name) {
77 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) { 106 for (auto const& dir_entry : std::filesystem::directory_iterator(path)) {
@@ -86,7 +115,11 @@ class DataPacker {
86 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt); 115 container_.FindOrAddRoom(current_map_name, h_room.name(), std::nullopt);
87 Room& room = *container_.all_objects().mutable_rooms(room_id); 116 Room& room = *container_.all_objects().mutable_rooms(room_id);
88 117
89 room.set_display_name(h_room.display_name()); 118 // room.set_display_name(h_room.display_name());
119
120 if (h_room.has_panel_display_name()) {
121 room.set_panel_display_name(h_room.panel_display_name());
122 }
90 123
91 for (const HumanPanel& h_panel : h_room.panels()) { 124 for (const HumanPanel& h_panel : h_room.panels()) {
92 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name())); 125 room.add_panels(ProcessPanel(h_panel, current_map_name, room.name()));
@@ -114,6 +147,10 @@ class DataPacker {
114 room.add_keyholders( 147 room.add_keyholders(
115 ProcessKeyholder(h_keyholder, current_map_name, room.name())); 148 ProcessKeyholder(h_keyholder, current_map_name, room.name()));
116 } 149 }
150
151 for (const HumanEnding& h_ending : h_room.endings()) {
152 room.add_endings(ProcessEnding(h_ending, current_map_name, room.name()));
153 }
117 } 154 }
118 155
119 uint64_t ProcessPanel(const HumanPanel& h_panel, 156 uint64_t ProcessPanel(const HumanPanel& h_panel,
@@ -122,7 +159,7 @@ class DataPacker {
122 uint64_t panel_id = 159 uint64_t panel_id =
123 container_.FindOrAddPanel(current_map_name, current_room_name, 160 container_.FindOrAddPanel(current_map_name, current_room_name,
124 h_panel.name(), std::nullopt, std::nullopt); 161 h_panel.name(), std::nullopt, std::nullopt);
125 Panel& panel = *container_.all_objects().mutable_panels(panel_id); 162 PanelData& panel = *container_.all_objects().mutable_panels(panel_id);
126 163
127 panel.set_path(h_panel.path()); 164 panel.set_path(h_panel.path());
128 panel.set_clue(h_panel.clue()); 165 panel.set_clue(h_panel.clue());
@@ -153,6 +190,10 @@ class DataPacker {
153 map_name, h_panel.required_room().name(), current_map_name)); 190 map_name, h_panel.required_room().name(), current_map_name));
154 } 191 }
155 192
193 if (h_panel.has_display_name()) {
194 panel.set_display_name(h_panel.display_name());
195 }
196
156 return panel_id; 197 return panel_id;
157 } 198 }
158 199
@@ -162,16 +203,16 @@ class DataPacker {
162 uint64_t painting_id = container_.FindOrAddPainting( 203 uint64_t painting_id = container_.FindOrAddPainting(
163 current_map_name, current_room_name, h_painting.name(), std::nullopt, 204 current_map_name, current_room_name, h_painting.name(), std::nullopt,
164 std::nullopt); 205 std::nullopt);
165 Painting& painting = 206 PaintingData& painting =
166 *container_.all_objects().mutable_paintings(painting_id); 207 *container_.all_objects().mutable_paintings(painting_id);
167 208
168 painting.set_path(h_painting.path()); 209 painting.set_path(h_painting.path());
169 painting.set_display_name(h_painting.display_name()); 210 painting.set_display_name(h_painting.display_name());
170 painting.set_orientation(h_painting.orientation()); 211 painting.set_orientation(h_painting.orientation());
171 212
172 if (h_painting.has_gravity()) { 213 // Setting this explicitly because the Godot protobuf doesn't support
173 painting.set_gravity(h_painting.gravity()); 214 // custom defaults.
174 } 215 painting.set_gravity(h_painting.gravity());
175 216
176 if (h_painting.has_move()) { 217 if (h_painting.has_move()) {
177 painting.set_move(h_painting.move()); 218 painting.set_move(h_painting.move());
@@ -206,12 +247,19 @@ class DataPacker {
206 Port& port = *container_.all_objects().mutable_ports(port_id); 247 Port& port = *container_.all_objects().mutable_ports(port_id);
207 248
208 port.set_path(h_port.path()); 249 port.set_path(h_port.path());
209 port.set_orientation(h_port.orientation()); 250 port.set_display_name(h_port.display_name());
210 251
211 if (h_port.has_gravity()) { 252 if (h_port.no_shuffle()) {
212 port.set_gravity(h_port.gravity()); 253 port.set_no_shuffle(h_port.no_shuffle());
254 } else {
255 *port.mutable_destination() = h_port.destination();
256 port.set_rotation(h_port.rotation());
213 } 257 }
214 258
259 // Setting this explicitly because the Godot protobuf doesn't support
260 // custom defaults.
261 port.set_gravity(h_port.gravity());
262
215 if (h_port.has_required_door()) { 263 if (h_port.has_required_door()) {
216 std::optional<std::string> map_name = 264 std::optional<std::string> map_name =
217 h_port.required_door().has_map() 265 h_port.required_door().has_map()
@@ -228,7 +276,7 @@ class DataPacker {
228 const std::string& current_map_name, 276 const std::string& current_map_name,
229 const std::string& current_room_name) { 277 const std::string& current_room_name) {
230 uint64_t letter_id = 278 uint64_t letter_id =
231 container_.FindOrAddLetter(h_letter.key(), h_letter.double_()); 279 container_.FindOrAddLetter(h_letter.key(), h_letter.level2());
232 Letter& letter = *container_.all_objects().mutable_letters(letter_id); 280 Letter& letter = *container_.all_objects().mutable_letters(letter_id);
233 281
234 letter.set_room_id(container_.FindOrAddRoom( 282 letter.set_room_id(container_.FindOrAddRoom(
@@ -257,14 +305,31 @@ class DataPacker {
257 uint64_t keyholder_id = container_.FindOrAddKeyholder( 305 uint64_t keyholder_id = container_.FindOrAddKeyholder(
258 current_map_name, current_room_name, h_keyholder.name(), std::nullopt, 306 current_map_name, current_room_name, h_keyholder.name(), std::nullopt,
259 std::nullopt); 307 std::nullopt);
260 Keyholder& keyholder = 308 KeyholderData& keyholder =
261 *container_.all_objects().mutable_keyholders(keyholder_id); 309 *container_.all_objects().mutable_keyholders(keyholder_id);
262 310
263 keyholder.set_path(h_keyholder.path()); 311 keyholder.set_path(h_keyholder.path());
264 312
313 if (h_keyholder.has_key()) {
314 keyholder.set_key(h_keyholder.key());
315 }
316
265 return keyholder_id; 317 return keyholder_id;
266 } 318 }
267 319
320 uint64_t ProcessEnding(const HumanEnding& h_ending,
321 const std::string& current_map_name,
322 const std::string& current_room_name) {
323 uint64_t ending_id = container_.FindOrAddEnding(h_ending.name());
324 Ending& ending = *container_.all_objects().mutable_endings(ending_id);
325
326 ending.set_room_id(container_.FindOrAddRoom(
327 current_map_name, current_room_name, std::nullopt));
328 ending.set_path(h_ending.path());
329
330 return ending_id;
331 }
332
268 void ProcessDoorsFile(std::filesystem::path path, 333 void ProcessDoorsFile(std::filesystem::path path,
269 const std::string& current_map_name) { 334 const std::string& current_map_name) {
270 if (!std::filesystem::exists(path)) { 335 if (!std::filesystem::exists(path)) {
@@ -296,8 +361,8 @@ class DataPacker {
296 h_door.receivers().begin(), h_door.receivers().end(), 361 h_door.receivers().begin(), h_door.receivers().end(),
297 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers())); 362 google::protobuf::RepeatedFieldBackInserter(door.mutable_receivers()));
298 std::copy( 363 std::copy(
299 h_door.switches().begin(), h_door.switches().end(), 364 h_door.senders().begin(), h_door.senders().end(),
300 google::protobuf::RepeatedFieldBackInserter(door.mutable_switches())); 365 google::protobuf::RepeatedFieldBackInserter(door.mutable_senders()));
301 366
302 for (const PaintingIdentifier& pi : h_door.move_paintings()) { 367 for (const PaintingIdentifier& pi : h_door.move_paintings()) {
303 std::optional<std::string> map_name = 368 std::optional<std::string> map_name =
@@ -339,6 +404,17 @@ class DataPacker {
339 container_.FindOrAddRoom(map_name, ri.name(), current_map_name)); 404 container_.FindOrAddRoom(map_name, ri.name(), current_map_name));
340 } 405 }
341 406
407 for (const DoorIdentifier& di : h_door.doors()) {
408 std::optional<std::string> map_name =
409 di.has_map() ? std::optional<std::string>(di.map()) : std::nullopt;
410 door.add_doors(
411 container_.FindOrAddDoor(map_name, di.name(), current_map_name));
412 }
413
414 if (h_door.has_white_ending()) {
415 door.set_white_ending(h_door.white_ending());
416 }
417
342 if (h_door.has_control_center_color()) { 418 if (h_door.has_control_center_color()) {
343 door.set_control_center_color(h_door.control_center_color()); 419 door.set_control_center_color(h_door.control_center_color());
344 } 420 }
@@ -348,6 +424,22 @@ class DataPacker {
348 } 424 }
349 425
350 door.set_type(h_door.type()); 426 door.set_type(h_door.type());
427
428 if (h_door.has_location_name()) {
429 door.set_location_name(h_door.location_name());
430 }
431
432 if (h_door.has_double_letters()) {
433 door.set_double_letters(h_door.double_letters());
434 }
435
436 if (h_door.has_latch()) {
437 door.set_latch(h_door.latch());
438 }
439
440 if (h_door.has_legacy_location()) {
441 door.set_legacy_location(h_door.legacy_location());
442 }
351 } 443 }
352 444
353 void ProcessConnectionsFile(std::filesystem::path path, 445 void ProcessConnectionsFile(std::filesystem::path path,
@@ -399,6 +491,26 @@ class DataPacker {
399 r_connection.set_required_door(door_id); 491 r_connection.set_required_door(door_id);
400 } 492 }
401 493
494 if (human_connection.has_roof_access()) {
495 f_connection.set_roof_access(human_connection.roof_access());
496 r_connection.set_roof_access(human_connection.roof_access());
497 }
498
499 if (human_connection.has_purple_ending()) {
500 f_connection.set_purple_ending(human_connection.purple_ending());
501 r_connection.set_purple_ending(human_connection.purple_ending());
502 }
503
504 if (human_connection.has_cyan_ending()) {
505 f_connection.set_cyan_ending(human_connection.cyan_ending());
506 r_connection.set_cyan_ending(human_connection.cyan_ending());
507 }
508
509 if (human_connection.has_vanilla_only()) {
510 f_connection.set_vanilla_only(human_connection.vanilla_only());
511 r_connection.set_vanilla_only(human_connection.vanilla_only());
512 }
513
402 container_.AddConnection(f_connection); 514 container_.AddConnection(f_connection);
403 if (!human_connection.oneway()) { 515 if (!human_connection.oneway()) {
404 container_.AddConnection(r_connection); 516 container_.AddConnection(r_connection);
@@ -482,8 +594,65 @@ class DataPacker {
482 } 594 }
483 } 595 }
484 596
597 void ProcessProgressivesFile(std::filesystem::path path) {
598 if (!std::filesystem::exists(path)) {
599 return;
600 }
601
602 auto h_progs = ReadMessageFromFile<HumanProgressives>(path.string());
603
604 for (const HumanProgressive& h_prog : h_progs.progressives()) {
605 ProcessProgressive(h_prog);
606 }
607 }
608
609 void ProcessProgressive(const HumanProgressive& h_prog) {
610 uint64_t prog_id = container_.FindOrAddProgressive(h_prog.name());
611 Progressive& prog = *container_.all_objects().mutable_progressives(prog_id);
612
613 for (const DoorIdentifier& di : h_prog.doors()) {
614 uint64_t door_id =
615 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
616 prog.add_doors(door_id);
617 }
618 }
619
620 void ProcessDoorGroupsFile(std::filesystem::path path) {
621 if (!std::filesystem::exists(path)) {
622 return;
623 }
624
625 auto h_groups = ReadMessageFromFile<HumanDoorGroups>(path.string());
626
627 for (const HumanDoorGroup& h_group : h_groups.door_groups()) {
628 ProcessDoorGroup(h_group);
629 }
630 }
631
632 void ProcessDoorGroup(const HumanDoorGroup& h_group) {
633 uint64_t group_id = container_.FindOrAddDoorGroup(h_group.name());
634 DoorGroup& group = *container_.all_objects().mutable_door_groups(group_id);
635
636 group.set_type(h_group.type());
637
638 for (const DoorIdentifier& di : h_group.doors()) {
639 uint64_t door_id =
640 container_.FindOrAddDoor(di.map(), di.name(), std::nullopt);
641 group.add_doors(door_id);
642 }
643 }
644
645 void ProcessGlobalMetadataFile(std::filesystem::path path) {
646 if (!std::filesystem::exists(path)) {
647 return;
648 }
649
650 auto h_metadata = ReadMessageFromFile<HumanGlobalMetadata>(path.string());
651 *container_.all_objects().mutable_version() = h_metadata.version();
652 }
653
485 void ProcessIdsFile(std::filesystem::path path) { 654 void ProcessIdsFile(std::filesystem::path path) {
486 auto ids = ReadMessageFromFile<IdMappings>(path.string()); 655 auto ids = ReadIdsFromYaml(path.string());
487 656
488 for (const auto& [map_name, map] : ids.maps()) { 657 for (const auto& [map_name, map] : ids.maps()) {
489 for (const auto& [door_name, ap_id] : map.doors()) { 658 for (const auto& [door_name, ap_id] : map.doors()) {
@@ -506,6 +675,20 @@ class DataPacker {
506 .mutable_masteries(mastery_id) 675 .mutable_masteries(mastery_id)
507 ->set_ap_id(ap_id); 676 ->set_ap_id(ap_id);
508 } 677 }
678
679 for (const auto& [keyholder_name, ap_id] : room.keyholders()) {
680 uint64_t keyholder_id = container_.FindOrAddKeyholder(
681 map_name, room_name, keyholder_name, std::nullopt, std::nullopt);
682 container_.all_objects()
683 .mutable_keyholders(keyholder_id)
684 ->set_ap_id(ap_id);
685 }
686
687 for (const auto& [port_name, ap_id] : room.ports()) {
688 uint64_t port_id = container_.FindOrAddPort(
689 map_name, room_name, port_name, std::nullopt, std::nullopt);
690 container_.all_objects().mutable_ports(port_id)->set_ap_id(ap_id);
691 }
509 } 692 }
510 } 693 }
511 694
@@ -518,6 +701,21 @@ class DataPacker {
518 uint64_t letter_id = container_.FindLetterByName(letter_name); 701 uint64_t letter_id = container_.FindLetterByName(letter_name);
519 container_.all_objects().mutable_letters(letter_id)->set_ap_id(ap_id); 702 container_.all_objects().mutable_letters(letter_id)->set_ap_id(ap_id);
520 } 703 }
704
705 for (const auto& [ending_name, ap_id] : ids.endings()) {
706 uint64_t ending_id = container_.FindOrAddEnding(ending_name);
707 container_.all_objects().mutable_endings(ending_id)->set_ap_id(ap_id);
708 }
709
710 for (const auto& [prog_name, ap_id] : ids.progressives()) {
711 uint64_t prog_id = container_.FindOrAddProgressive(prog_name);
712 container_.all_objects().mutable_progressives(prog_id)->set_ap_id(ap_id);
713 }
714
715 for (const auto& [group_name, ap_id] : ids.door_groups()) {
716 uint64_t group_id = container_.FindOrAddDoorGroup(group_name);
717 container_.all_objects().mutable_door_groups(group_id)->set_ap_id(ap_id);
718 }
521 } 719 }
522 720
523 std::string mapdir_; 721 std::string mapdir_;