summary refs log tree commit diff stats
path: root/apworld/static_logic.py
blob: 4fc38f8c67f487357d8aa94bb3956cbc4b40306b (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
31
32
33
34
35
36
37
38
39
40
41
42
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

        for letter in self.objects.letters:
            letter_name = f"{letter.key.upper()}{'' if letter.double 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:
                self.item_id_to_name[letter.ap_id] = letter_name

        for mastery in self.objects.masteries:
            location_name = f"{self.objects.maps[self.objects.rooms[mastery.room_id].map_id].name} - Mastery"
            self.location_id_to_name[mastery.ap_id] = location_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()}