From 4c8a38dfc0121343396d2a0d734cf1445d05b60c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 12 Aug 2025 16:55:17 -0400 Subject: Converted to proto2 This will let us use an older version of protobuf in Python, and allows us to use the Godot protobuf implementation at all. Scalar fields with custom defaults in data.proto were changed to not have a default, because Godot doesn't handle it properly. The equivalent fields in human.proto still have the defaults, and datapacker copies the default value in if necessary. The Panel message in data.proto was also renamed to PanelData because otherwise it conflicts with the native Godot class named Panel. The double field in Letter was renamed to level2, because Godot couldn't handle it well. Finally, common.proto was removed and its contents were moved into data.proto, which allows us to generate code for Python without needing to edit it. NOTE: I had to slightly modify the Godot protobuf code generator. I'll need to upload that somewhere. --- apworld/player_logic.py | 8 +- apworld/static_logic.py | 9 +- data/maps/four_rooms/rooms/A2 Room.txtpb | 2 +- data/maps/the_bearer/rooms/Q2 Room.txtpb | 2 +- data/maps/the_between/rooms/B2 Room.txtpb | 2 +- data/maps/the_colorful/rooms/P2 Room.txtpb | 2 +- data/maps/the_congruent/rooms/C2 Room.txtpb | 2 +- data/maps/the_congruent/rooms/G2 Room.txtpb | 2 +- proto/CMakeLists.txt | 2 +- proto/common.proto | 38 ------ proto/data.proto | 173 +++++++++++++++++----------- proto/human.proto | 112 +++++++++--------- tools/assign_ids/main.cpp | 3 +- tools/datapacker/container.cpp | 10 +- tools/datapacker/container.h | 2 +- tools/datapacker/main.cpp | 16 +-- tools/util/naming.cpp | 4 +- tools/util/naming.h | 2 +- 18 files changed, 192 insertions(+), 199 deletions(-) delete mode 100644 proto/common.proto diff --git a/apworld/player_logic.py b/apworld/player_logic.py index 958abc5..8b240b5 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py @@ -1,4 +1,4 @@ -from .generated import common_pb2 as common_pb2 +from .generated import data_pb2 as data_pb2 from typing import TYPE_CHECKING, NamedTuple if TYPE_CHECKING: @@ -79,11 +79,11 @@ class Lingo2PlayerLogic: self.real_items = list() for door in world.static_logic.objects.doors: - if door.type in [common_pb2.DoorType.STANDARD, common_pb2.DoorType.LOCATION_ONLY]: + if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY]: self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id, self.get_door_reqs(door.id))) - if door.type in [common_pb2.DoorType.STANDARD, common_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: + if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: self.real_items.append(self.world.static_logic.get_door_item_name(door.id)) for letter in world.static_logic.objects.letters: @@ -146,7 +146,7 @@ class Lingo2PlayerLogic: reqs = AccessRequirements() use_item = False - if door.type in [common_pb2.DoorType.STANDARD, common_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: + if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.ITEM_ONLY] and self.world.options.shuffle_doors: use_item = True if use_item: diff --git a/apworld/static_logic.py b/apworld/static_logic.py index ff58e96..6a05f3d 100644 --- a/apworld/static_logic.py +++ b/apworld/static_logic.py @@ -1,4 +1,3 @@ -from .generated import common_pb2 as common_pb2 from .generated import data_pb2 as data_pb2 import pkgutil @@ -18,20 +17,20 @@ class Lingo2StaticLogic: self.objects.ParseFromString(bytearray(file)) for door in self.objects.doors: - if door.type in [common_pb2.DoorType.STANDARD, common_pb2.DoorType.LOCATION_ONLY]: + if door.type in [data_pb2.DoorType.STANDARD, data_pb2.DoorType.LOCATION_ONLY]: location_name = f"{self.objects.maps[door.map_id].name} - {door.name}" self.location_id_to_name[door.ap_id] = location_name - if door.type not in [common_pb2.DoorType.EVENT, common_pb2.DoorType.LOCATION_ONLY]: + if door.type not in [data_pb2.DoorType.EVENT, data_pb2.DoorType.LOCATION_ONLY]: item_name = self.get_door_item_name(door.id) self.item_id_to_name[door.ap_id] = item_name for letter in self.objects.letters: - letter_name = f"{letter.key.upper()}{'' if letter.double else '2'}" + letter_name = f"{letter.key.upper()}{'' if letter.level2 else '2'}" location_name = f"{self.objects.maps[self.objects.rooms[letter.room_id].map_id].name} - {letter_name}" self.location_id_to_name[letter.ap_id] = location_name - if not letter.double: + if not letter.level2: self.item_id_to_name[letter.ap_id] = letter_name for mastery in self.objects.masteries: diff --git a/data/maps/four_rooms/rooms/A2 Room.txtpb b/data/maps/four_rooms/rooms/A2 Room.txtpb index 20c9838..236ce01 100644 --- a/data/maps/four_rooms/rooms/A2 Room.txtpb +++ b/data/maps/four_rooms/rooms/A2 Room.txtpb @@ -2,6 +2,6 @@ name: "A2 Room" display_name: "Hallway" letters { key: "a" - double: true + level2: true path: "Components/Collectables/a2" } diff --git a/data/maps/the_bearer/rooms/Q2 Room.txtpb b/data/maps/the_bearer/rooms/Q2 Room.txtpb index 2c0c276..ab5032a 100644 --- a/data/maps/the_bearer/rooms/Q2 Room.txtpb +++ b/data/maps/the_bearer/rooms/Q2 Room.txtpb @@ -2,6 +2,6 @@ name: "Q2 Room" display_name: "Back Area" letters { key: "q" - double: true + level2: true path: "Components/Collectables/collectable" } diff --git a/data/maps/the_between/rooms/B2 Room.txtpb b/data/maps/the_between/rooms/B2 Room.txtpb index 97b4684..aad5d15 100644 --- a/data/maps/the_between/rooms/B2 Room.txtpb +++ b/data/maps/the_between/rooms/B2 Room.txtpb @@ -2,7 +2,7 @@ name: "B2 Room" display_name: "B2 Room" letters { key: "b" - double: true + level2: true path: "Components/Collectables/collectable" } # Uhh idk if the paintings and door in here should be randomized. diff --git a/data/maps/the_colorful/rooms/P2 Room.txtpb b/data/maps/the_colorful/rooms/P2 Room.txtpb index 8c7e0f1..85dbf20 100644 --- a/data/maps/the_colorful/rooms/P2 Room.txtpb +++ b/data/maps/the_colorful/rooms/P2 Room.txtpb @@ -2,6 +2,6 @@ name: "P2 Room" display_name: "Cyan Room" letters { key: "p" - double: true + level2: true path: "Components/Collectables/p2" } diff --git a/data/maps/the_congruent/rooms/C2 Room.txtpb b/data/maps/the_congruent/rooms/C2 Room.txtpb index 69c9a46..852d4e2 100644 --- a/data/maps/the_congruent/rooms/C2 Room.txtpb +++ b/data/maps/the_congruent/rooms/C2 Room.txtpb @@ -2,6 +2,6 @@ name: "C2 Room" display_name: "Main Area" letters { key: "c" - double: true + level2: true path: "Components/Collectables/collectable2" } diff --git a/data/maps/the_congruent/rooms/G2 Room.txtpb b/data/maps/the_congruent/rooms/G2 Room.txtpb index ba9d772..80a23cb 100644 --- a/data/maps/the_congruent/rooms/G2 Room.txtpb +++ b/data/maps/the_congruent/rooms/G2 Room.txtpb @@ -2,6 +2,6 @@ name: "G2 Room" display_name: "Main Area" letters { key: "g" - double: true + level2: true path: "Components/Collectables/collectable" } diff --git a/proto/CMakeLists.txt b/proto/CMakeLists.txt index c5abd46..95687d7 100644 --- a/proto/CMakeLists.txt +++ b/proto/CMakeLists.txt @@ -5,7 +5,7 @@ add_library(protos) protobuf_generate( LANGUAGE cpp TARGET protos - PROTOS human.proto data.proto common.proto + PROTOS human.proto data.proto ) target_link_libraries(protos PUBLIC protobuf::libprotobuf) diff --git a/proto/common.proto b/proto/common.proto deleted file mode 100644 index e37f670..0000000 --- a/proto/common.proto +++ /dev/null @@ -1,38 +0,0 @@ -edition = "2023"; - -package com.fourisland.lingo2_archipelago; - -message Proxy { - string answer = 1; - string path = 2; -} - -enum DoorType { - DOOR_TYPE_UNKNOWN = 0; - - // This door is a location unless panelsanity is on, and it is an item as long as door shuffle is on. - STANDARD = 1; - - // This door is never an item or a location. - EVENT = 2; - - // This door is never a location, and is an item as long as door shuffle is on. - ITEM_ONLY = 3; - - // This door is never a location, and is an item as long as control center color shuffle is on. - CONTROL_CENTER_COLOR = 4; - - // This door is never an item, and is a location as long as panelsanity is not on. - LOCATION_ONLY = 5; -} - -enum AxisDirection { - AXIS_DIRECTION_UNKNOWN = 0; - - X_PLUS = 1; - X_MINUS = 2; - Y_PLUS = 3; - Y_MINUS = 4; - Z_PLUS = 5; - Z_MINUS = 6; -} diff --git a/proto/data.proto b/proto/data.proto index b590454..f60d54f 100644 --- a/proto/data.proto +++ b/proto/data.proto @@ -1,23 +1,56 @@ -edition = "2023"; - -import "common.proto"; +syntax = "proto2"; package com.fourisland.lingo2_archipelago; +message Proxy { + optional string answer = 1; + optional string path = 2; +} + +enum DoorType { + DOOR_TYPE_UNKNOWN = 0; + + // This door is a location unless panelsanity is on, and it is an item as long as door shuffle is on. + STANDARD = 1; + + // This door is never an item or a location. + EVENT = 2; + + // This door is never a location, and is an item as long as door shuffle is on. + ITEM_ONLY = 3; + + // This door is never a location, and is an item as long as control center color shuffle is on. + CONTROL_CENTER_COLOR = 4; + + // This door is never an item, and is a location as long as panelsanity is not on. + LOCATION_ONLY = 5; +} + +enum AxisDirection { + AXIS_DIRECTION_UNKNOWN = 0; + + X_PLUS = 1; + X_MINUS = 2; + Y_PLUS = 3; + Y_MINUS = 4; + Z_PLUS = 5; + Z_MINUS = 6; +} + message ProxyIdentifier { - uint64 panel = 1; - string answer = 2; + optional uint64 panel = 1; + optional string answer = 2; } message KeyholderAnswer { - uint64 keyholder = 1; - string key = 2; + optional uint64 keyholder = 1; + optional string key = 2; } message Connection { - uint64 from_room = 1; - uint64 to_room = 2; - uint64 required_door = 3; + optional uint64 from_room = 1; + optional uint64 to_room = 2; + optional uint64 required_door = 3; oneof trigger { uint64 port = 4; @@ -27,105 +60,105 @@ message Connection { } message Door { - uint64 id = 1; - uint64 ap_id = 11; - uint64 map_id = 9; - uint64 room_id = 10; - string name = 2; + optional uint64 id = 1; + optional uint64 ap_id = 11; + optional uint64 map_id = 9; + optional uint64 room_id = 10; + optional string name = 2; repeated string receivers = 3; repeated uint64 move_paintings = 4; repeated ProxyIdentifier panels = 5; - uint64 complete_at = 12; + optional uint64 complete_at = 12; - string control_center_color = 6; + optional string control_center_color = 6; repeated string switches = 7; repeated KeyholderAnswer keyholders = 13; repeated uint64 rooms = 14; - DoorType type = 8; + optional DoorType type = 8; } -message Panel { - uint64 id = 1; - uint64 ap_id = 10; - uint64 room_id = 2; - string name = 3; +message PanelData { + optional uint64 id = 1; + optional uint64 ap_id = 10; + optional uint64 room_id = 2; + optional string name = 3; - string path = 4; - string clue = 5; - string answer = 6; + optional string path = 4; + optional string clue = 5; + optional string answer = 6; repeated string symbols = 7; repeated Proxy proxies = 8; - uint64 required_door = 9; - uint64 required_room = 11; + optional uint64 required_door = 9; + optional uint64 required_room = 11; } message Painting { - uint64 id = 1; - uint64 room_id = 2; - string name = 9; - - string path = 10; - string display_name = 4; - - string orientation = 3; - bool move = 6; - bool enter_only = 7; - AxisDirection gravity = 8 [default = Y_MINUS]; - bool exit_only = 11; + optional uint64 id = 1; + optional uint64 room_id = 2; + optional string name = 9; + + optional string path = 10; + optional string display_name = 4; + + optional string orientation = 3; + optional bool move = 6; + optional bool enter_only = 7; + optional AxisDirection gravity = 8; + optional bool exit_only = 11; - uint64 required_door = 5; + optional uint64 required_door = 5; } message Port { - uint64 id = 1; - uint64 room_id = 2; - string name = 3; + optional uint64 id = 1; + optional uint64 room_id = 2; + optional string name = 3; - string path = 4; - string orientation = 5; - AxisDirection gravity = 7 [default = Y_MINUS]; + optional string path = 4; + optional string orientation = 5; + optional AxisDirection gravity = 7; - uint64 required_door = 6; + optional uint64 required_door = 6; } message Keyholder { - uint64 id = 1; - uint64 room_id = 2; + optional uint64 id = 1; + optional uint64 room_id = 2; - string name = 3; - string path = 4; + optional string name = 3; + optional string path = 4; } message Letter { - uint64 id = 3; - uint64 ap_id = 5; - uint64 room_id = 4; + optional uint64 id = 3; + optional uint64 ap_id = 5; + optional uint64 room_id = 4; - string key = 1; - bool double = 2; + optional string key = 1; + optional bool level2 = 2; - string path = 6; + optional string path = 6; } message Mastery { - uint64 id = 1; - uint64 ap_id = 2; - uint64 room_id = 3; + optional uint64 id = 1; + optional uint64 ap_id = 2; + optional uint64 room_id = 3; - string name = 4; - string path = 5; + optional string name = 4; + optional string path = 5; } message Room { - uint64 id = 1; - uint64 map_id = 8; - string name = 2; - string display_name = 3; + optional uint64 id = 1; + optional uint64 map_id = 8; + optional string name = 2; + optional string display_name = 3; repeated uint64 panels = 4; repeated uint64 paintings = 5; @@ -137,15 +170,15 @@ message Room { } message Map { - uint64 id = 1; - string name = 2; + optional uint64 id = 1; + optional string name = 2; } message AllObjects { repeated Map maps = 7; repeated Room rooms = 1; repeated Door doors = 2; - repeated Panel panels = 3; + repeated PanelData panels = 3; repeated Painting paintings = 4; repeated Port ports = 5; repeated Keyholder keyholders = 11; diff --git a/proto/human.proto b/proto/human.proto index 858c88f..b420cb4 100644 --- a/proto/human.proto +++ b/proto/human.proto @@ -1,43 +1,43 @@ -edition = "2023"; +syntax = "proto2"; -import "common.proto"; +import "data.proto"; package com.fourisland.lingo2_archipelago; message RoomIdentifier { - string map = 1; - string name = 2; + optional string map = 1; + optional string name = 2; } message DoorIdentifier { - string map = 1; - string name = 2; + optional string map = 1; + optional string name = 2; } message PortIdentifier { - string map = 1; - string room = 2; - string name = 3; + optional string map = 1; + optional string room = 2; + optional string name = 3; } message PaintingIdentifier { - string map = 1; - string room = 2; - string name = 3; + optional string map = 1; + optional string room = 2; + optional string name = 3; } message PanelIdentifier { - string map = 1; - string room = 2; - string name = 3; - string answer = 4; + optional string map = 1; + optional string room = 2; + optional string name = 3; + optional string answer = 4; } message KeyholderIdentifier { - string map = 1; - string room = 2; - string name = 3; - string key = 4; + optional string map = 1; + optional string room = 2; + optional string name = 3; + optional string key = 4; } message HumanConnection { @@ -60,8 +60,8 @@ message HumanConnection { string to_room = 6; } - bool oneway = 3; - DoorIdentifier door = 4; + optional bool oneway = 3; + optional DoorIdentifier door = 4; } message HumanConnections { @@ -69,7 +69,7 @@ message HumanConnections { } message HumanDoor { - string name = 1; + optional string name = 1; repeated string receivers = 2; repeated PaintingIdentifier move_paintings = 8; @@ -79,15 +79,15 @@ message HumanDoor { // If set, the number of panels from the above set that need to be solved. // Warning: this is a messy kind of OR logic! Consider if there's another way. - uint64 complete_at = 9; + optional uint64 complete_at = 9; - string control_center_color = 6; + optional string control_center_color = 6; repeated string switches = 7; repeated KeyholderIdentifier keyholders = 10; repeated RoomIdentifier rooms = 11; - DoorType type = 4; - string location_room = 5; + optional DoorType type = 4; + optional string location_room = 5; } message HumanDoors { @@ -95,64 +95,64 @@ message HumanDoors { } message HumanPanel { - string name = 1; - string path = 5; + optional string name = 1; + optional string path = 5; - string clue = 2; - string answer = 3; + optional string clue = 2; + optional string answer = 3; repeated string symbols = 4; repeated Proxy proxies = 6; - DoorIdentifier required_door = 7; - RoomIdentifier required_room = 8; + optional DoorIdentifier required_door = 7; + optional RoomIdentifier required_room = 8; } message HumanPainting { - string name = 1; - string path = 2; + optional string name = 1; + optional string path = 2; - string display_name = 4; + optional string display_name = 4; - string orientation = 3; - bool move = 6; - bool enter_only = 7; - AxisDirection gravity = 8 [default = Y_MINUS]; - bool exit_only = 9; + optional string orientation = 3; + optional bool move = 6; + optional bool enter_only = 7; + optional AxisDirection gravity = 8 [default = Y_MINUS]; + optional bool exit_only = 9; - DoorIdentifier required_door = 5; + optional DoorIdentifier required_door = 5; } message HumanPort { - string name = 1; - string path = 2; + optional string name = 1; + optional string path = 2; - string orientation = 3; - AxisDirection gravity = 5 [default = Y_MINUS]; + optional string orientation = 3; + optional AxisDirection gravity = 5 [default = Y_MINUS]; - DoorIdentifier required_door = 4; + optional DoorIdentifier required_door = 4; } message HumanKeyholder { - string name = 1; - string path = 2; + optional string name = 1; + optional string path = 2; } message HumanLetter { - string key = 1; - bool double = 2; + optional string key = 1; + optional bool level2 = 2; - string path = 3; + optional string path = 3; } message HumanMastery { - string name = 1; - string path = 2; + optional string name = 1; + optional string path = 2; } message HumanRoom { - string name = 1; - string display_name = 2; + optional string name = 1; + optional string display_name = 2; repeated HumanPanel panels = 3; repeated HumanPainting paintings = 4; diff --git a/tools/assign_ids/main.cpp b/tools/assign_ids/main.cpp index 349c258..2617cf7 100644 --- a/tools/assign_ids/main.cpp +++ b/tools/assign_ids/main.cpp @@ -170,8 +170,7 @@ class AssignIds { } for (const HumanLetter& h_letter : h_room.letters()) { - std::string lettername = - GetLetterName(h_letter.key(), h_letter.double_()); + std::string lettername = GetLetterName(h_letter.key(), h_letter.level2()); if (!id_mappings_.letters().contains(lettername)) { auto& letters = *id_mappings_.mutable_letters(); diff --git a/tools/datapacker/container.cpp b/tools/datapacker/container.cpp index bb58ec5..ffcb75a 100644 --- a/tools/datapacker/container.cpp +++ b/tools/datapacker/container.cpp @@ -160,7 +160,7 @@ uint64_t Container::FindOrAddPanel(std::optional map_name, auto it = room_container.find(panel_name); if (it == room_container.end()) { uint64_t new_id = all_objects_.panels_size(); - Panel* panel = all_objects_.add_panels(); + PanelData* panel = all_objects_.add_panels(); panel->set_id(new_id); panel->set_room_id(FindOrAddRoom(map_name, *room_name, std::nullopt)); panel->set_name(panel_name); @@ -173,8 +173,8 @@ uint64_t Container::FindOrAddPanel(std::optional map_name, } } -uint64_t Container::FindOrAddLetter(std::string key, bool double_) { - std::string letter_name = GetLetterName(key, double_); +uint64_t Container::FindOrAddLetter(std::string key, bool level2) { + std::string letter_name = GetLetterName(key, level2); auto it = letter_id_by_name_.find(letter_name); if (it == letter_id_by_name_.end()) { @@ -183,8 +183,8 @@ uint64_t Container::FindOrAddLetter(std::string key, bool double_) { letter->set_id(new_id); letter->set_key(key); - if (double_) { - letter->set_double_(double_); + if (level2) { + letter->set_level2(level2); } letter_id_by_name_[letter_name] = new_id; diff --git a/tools/datapacker/container.h b/tools/datapacker/container.h index 7ee5b5b..e1a84d8 100644 --- a/tools/datapacker/container.h +++ b/tools/datapacker/container.h @@ -36,7 +36,7 @@ class Container { std::optional map_fallback, std::optional room_fallback); - uint64_t FindOrAddLetter(std::string key, bool double_); + uint64_t FindOrAddLetter(std::string key, bool level2); uint64_t FindLetterByName(std::string letter_name); diff --git a/tools/datapacker/main.cpp b/tools/datapacker/main.cpp index d3908b4..8b87ab1 100644 --- a/tools/datapacker/main.cpp +++ b/tools/datapacker/main.cpp @@ -122,7 +122,7 @@ class DataPacker { uint64_t panel_id = container_.FindOrAddPanel(current_map_name, current_room_name, h_panel.name(), std::nullopt, std::nullopt); - Panel& panel = *container_.all_objects().mutable_panels(panel_id); + PanelData& panel = *container_.all_objects().mutable_panels(panel_id); panel.set_path(h_panel.path()); panel.set_clue(h_panel.clue()); @@ -169,9 +169,9 @@ class DataPacker { painting.set_display_name(h_painting.display_name()); painting.set_orientation(h_painting.orientation()); - if (h_painting.has_gravity()) { - painting.set_gravity(h_painting.gravity()); - } + // Setting this explicitly because the Godot protobuf doesn't support + // custom defaults. + painting.set_gravity(h_painting.gravity()); if (h_painting.has_move()) { painting.set_move(h_painting.move()); @@ -208,9 +208,9 @@ class DataPacker { port.set_path(h_port.path()); port.set_orientation(h_port.orientation()); - if (h_port.has_gravity()) { - port.set_gravity(h_port.gravity()); - } + // Setting this explicitly because the Godot protobuf doesn't support + // custom defaults. + port.set_gravity(h_port.gravity()); if (h_port.has_required_door()) { std::optional map_name = @@ -228,7 +228,7 @@ class DataPacker { const std::string& current_map_name, const std::string& current_room_name) { uint64_t letter_id = - container_.FindOrAddLetter(h_letter.key(), h_letter.double_()); + container_.FindOrAddLetter(h_letter.key(), h_letter.level2()); Letter& letter = *container_.all_objects().mutable_letters(letter_id); letter.set_room_id(container_.FindOrAddRoom( diff --git a/tools/util/naming.cpp b/tools/util/naming.cpp index 12594c5..0ae99f6 100644 --- a/tools/util/naming.cpp +++ b/tools/util/naming.cpp @@ -2,10 +2,10 @@ #include -std::string GetLetterName(std::string key, bool double_) { +std::string GetLetterName(std::string key, bool level2) { std::ostringstream lettername_s; lettername_s << key; - lettername_s << (double_ ? "2" : "1"); + lettername_s << (level2 ? "2" : "1"); return lettername_s.str(); } diff --git a/tools/util/naming.h b/tools/util/naming.h index 7d61309..9a68851 100644 --- a/tools/util/naming.h +++ b/tools/util/naming.h @@ -3,6 +3,6 @@ #include -std::string GetLetterName(std::string key, bool double_); +std::string GetLetterName(std::string key, bool level2); #endif /* TOOLS_UTIL_NAMING_H_ */ -- cgit 1.4.1