-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.py
101 lines (80 loc) · 2.75 KB
/
items.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import enum
import json
from typing import NamedTuple, Dict, List, Set
from BaseClasses import ItemClassification
from . import data
class ItemGroup(enum.Enum):
Friends = enum.auto()
Crafting_Materials = enum.auto()
Traversal = enum.auto()
Hat = enum.auto()
Quest_Item = enum.auto()
Sword = enum.auto()
Shield = enum.auto()
Ranged = enum.auto()
Craft = enum.auto()
Item = enum.auto()
Cardboard_Destroyer = enum.auto()
class GatorItemData(NamedTuple):
long_name: str
short_name: str
item_id: int
classification: ItemClassification
base_quantity_in_item_pool: int
item_groups: List[ItemGroup]
class GatorItemTable(Dict[str, GatorItemData]):
def short_to_long(self, short_name: str) -> str:
for _, data in self.items():
if data.short_name == short_name:
return data.long_name
return None
# Cardboard Destroyer Group
def load_item_json() -> GatorItemTable:
try:
from importlib.resources import files
except ImportError:
from importlib_resources import files # type: ignore
items: GatorItemTable = GatorItemTable()
with files(data).joinpath("items.json").open() as file:
item_reader = json.load(file)
gator_items = item_reader[0]
for _, item in gator_items.items():
id = int(item["item_id"]) if item["item_id"] else None
classification = ItemClassification[item["classification"]]
quantity = (
int(item["base_quantity_in_item_pool"])
if item["base_quantity_in_item_pool"]
else 0
)
groups = [
ItemGroup[group] for group in item["item_groups"].split(",") if group
]
items[item["long_name"]] = GatorItemData(
item["long_name"],
item["short_name"],
id,
classification,
quantity,
groups,
)
return items
item_table: GatorItemTable = load_item_json()
item_name_to_id: Dict[str, int] = {
name: data.item_id for name, data in item_table.items()
}
filler_items: List[str] = [
name
for name, data in item_table.items()
if data.classification == ItemClassification.filler
]
# Items can be grouped using their names to allow easy checking if any item
# from that group has been collected. Group names can also be used for !hint
def items_for_group(group: ItemGroup) -> List[str]:
item_names = []
for name, data in item_table.items():
if group in data.item_groups:
item_names.append(name)
return item_names
item_name_groups: Dict[str, Set[str]] = {}
for group in ItemGroup:
item_name_groups[group.name] = items_for_group(group)