summary refs log tree commit diff stats
path: root/apworld/static_logic.py
blob: 1cab340a43d142a3122e12a125404c18bda12df9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from .generated import common_pb2 as common_pb2
from .generated import data_pb2 as data_pb2
import pkgutil

class Lingo2StaticLogic:
    item_id_to_name: dict[int, str]
    location_id_to_name: dict[int, str]

    item_name_to_id: dict[str, int]
    location_name_to_id: dict[str, int]

    def __init__(self):
        self.item_id_to_name = {}
        self.location_id_to_name = {}

        file = pkgutil.get_data(__name__, "generated/data.binpb")
        self.objects = data_pb2.AllObjects()
        self.objects.ParseFromString(bytearray(file))

        for door in self.objects.doors:
            if door.type in [common_pb2.DoorType.STANDARD, common_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]:
                item_name = f"{self.objects.maps[door.map_id].name} - {door.name}"
                self.item_id_to_name[door.ap_id] = item_name

        self.item_name_to_id = {name: ap_id for ap_id, name in self.item_id_to_name.items()}
        self.location_name_to_id = {name: ap_id for ap_id, name in self.location_id_to_name.items()}