diff options
Diffstat (limited to 'apworld')
| -rw-r--r-- | apworld/__init__.py | 6 | ||||
| -rw-r--r-- | apworld/player_logic.py | 10 | ||||
| -rw-r--r-- | apworld/regions.py | 3 | ||||
| -rw-r--r-- | apworld/static_logic.py | 23 |
4 files changed, 30 insertions, 12 deletions
| diff --git a/apworld/__init__.py b/apworld/__init__.py index 013910e..1544c7b 100644 --- a/apworld/__init__.py +++ b/apworld/__init__.py | |||
| @@ -25,10 +25,10 @@ class Lingo2World(World): | |||
| 25 | options_dataclass = Lingo2Options | 25 | options_dataclass = Lingo2Options |
| 26 | options: Lingo2Options | 26 | options: Lingo2Options |
| 27 | 27 | ||
| 28 | item_name_to_id = {} | ||
| 29 | location_name_to_id = {} | ||
| 30 | |||
| 31 | static_logic = Lingo2StaticLogic() | 28 | static_logic = Lingo2StaticLogic() |
| 29 | item_name_to_id = static_logic.item_name_to_id | ||
| 30 | location_name_to_id = static_logic.location_name_to_id | ||
| 31 | |||
| 32 | player_logic: Lingo2PlayerLogic | 32 | player_logic: Lingo2PlayerLogic |
| 33 | 33 | ||
| 34 | def generate_early(self): | 34 | def generate_early(self): |
| diff --git a/apworld/player_logic.py b/apworld/player_logic.py index f54573f..675c6ae 100644 --- a/apworld/player_logic.py +++ b/apworld/player_logic.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | from .generated import common_pb2 as common_pb2 | ||
| 1 | from typing import TYPE_CHECKING, NamedTuple | 2 | from typing import TYPE_CHECKING, NamedTuple |
| 2 | 3 | ||
| 3 | if TYPE_CHECKING: | 4 | if TYPE_CHECKING: |
| @@ -5,7 +6,6 @@ if TYPE_CHECKING: | |||
| 5 | 6 | ||
| 6 | 7 | ||
| 7 | class PlayerLocation(NamedTuple): | 8 | class PlayerLocation(NamedTuple): |
| 8 | name: str | ||
| 9 | code: int | None | 9 | code: int | None |
| 10 | 10 | ||
| 11 | 11 | ||
| @@ -15,10 +15,6 @@ class Lingo2PlayerLogic: | |||
| 15 | def __init__(self, world: "Lingo2World"): | 15 | def __init__(self, world: "Lingo2World"): |
| 16 | self.locations_by_room = {} | 16 | self.locations_by_room = {} |
| 17 | 17 | ||
| 18 | code = 1 | ||
| 19 | for door in world.static_logic.objects.doors: | 18 | for door in world.static_logic.objects.doors: |
| 20 | if not door.HasField("room_id"): | 19 | if door.type == common_pb2.DoorType.STANDARD: |
| 21 | continue | 20 | self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.ap_id)) |
| 22 | |||
| 23 | self.locations_by_room.setdefault(door.room_id, []).append(PlayerLocation(door.name, code)) | ||
| 24 | code += 1 | ||
| diff --git a/apworld/regions.py b/apworld/regions.py index 24c2281..d388678 100644 --- a/apworld/regions.py +++ b/apworld/regions.py | |||
| @@ -11,7 +11,8 @@ def create_region(room, world: "Lingo2World") -> Region: | |||
| 11 | new_region = Region(room.name, world.player, world.multiworld) | 11 | new_region = Region(room.name, world.player, world.multiworld) |
| 12 | 12 | ||
| 13 | for location in world.player_logic.locations_by_room.get(room.id, {}): | 13 | for location in world.player_logic.locations_by_room.get(room.id, {}): |
| 14 | new_location = Lingo2Location(world.player, location.name, location.code, new_region) | 14 | new_location = Lingo2Location(world.player, world.static_logic.location_id_to_name[location.code], |
| 15 | location.code, new_region) | ||
| 15 | new_region.locations.append(new_location) | 16 | new_region.locations.append(new_location) |
| 16 | 17 | ||
| 17 | return new_region | 18 | return new_region |
| diff --git a/apworld/static_logic.py b/apworld/static_logic.py index 6c38f1f..d3ed85c 100644 --- a/apworld/static_logic.py +++ b/apworld/static_logic.py | |||
| @@ -1,9 +1,30 @@ | |||
| 1 | from .generated import common_pb2 as common_pb2 | ||
| 1 | from .generated import data_pb2 as data_pb2 | 2 | from .generated import data_pb2 as data_pb2 |
| 2 | import pkgutil | 3 | import pkgutil |
| 3 | 4 | ||
| 4 | class Lingo2StaticLogic: | 5 | class Lingo2StaticLogic: |
| 6 | item_id_to_name: dict[int, str] | ||
| 7 | location_id_to_name: dict[int, str] | ||
| 8 | |||
| 9 | item_name_to_id: dict[str, int] | ||
| 10 | location_name_to_id: dict[str, int] | ||
| 11 | |||
| 5 | def __init__(self): | 12 | def __init__(self): |
| 6 | file = pkgutil.get_data(__name__, "generated/data.binpb") | 13 | self.item_id_to_name = {} |
| 14 | self.location_id_to_name = {} | ||
| 7 | 15 | ||
| 16 | file = pkgutil.get_data(__name__, "generated/data.binpb") | ||
| 8 | self.objects = data_pb2.AllObjects() | 17 | self.objects = data_pb2.AllObjects() |
| 9 | self.objects.ParseFromString(bytearray(file)) | 18 | self.objects.ParseFromString(bytearray(file)) |
| 19 | |||
| 20 | for door in self.objects.doors: | ||
| 21 | if door.type == common_pb2.DoorType.STANDARD: | ||
| 22 | location_name = f"{self.objects.rooms[door.room_id].display_name} - {door.name}" | ||
| 23 | self.location_id_to_name[door.ap_id] = location_name | ||
| 24 | |||
| 25 | if door.type != common_pb2.DoorType.EVENT: | ||
| 26 | item_name = f"{self.objects.rooms[door.room_id].display_name} - {door.name}" | ||
| 27 | self.item_id_to_name[door.ap_id] = item_name | ||
| 28 | |||
| 29 | self.item_name_to_id = {name: ap_id for ap_id, name in self.item_id_to_name.items()} | ||
| 30 | self.location_name_to_id = {name: ap_id for ap_id, name in self.location_id_to_name.items()} | ||
