-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathplan.py
38 lines (34 loc) · 1.51 KB
/
plan.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
# Helper class to read and store planomizer data
class Plan:
def __init__(self, filename):
self.forced_items = {}
self.item_pool = {}
item_group = {}
for line in open(filename, "rt"):
line = line.strip()
if ";" in line:
line = line[:line.find(";")]
if "#" in line:
line = line[:line.find("#")]
if ":" not in line:
continue
entry_type, params = map(str.strip, line.upper().split(":", 1))
if entry_type == "LOCATION" and ":" in params:
location, item = map(str.strip, params.split(":", 1))
if item == "":
continue
if item.startswith("[") and item.endswith("]"):
item = item_group[item[1:-1]]
if "," in item:
item = list(map(str.strip, item.split(",")))
self.forced_items[location] = item
elif entry_type == "POOL" and ":" in params:
item, count = map(str.strip, params.split(":", 1))
self.item_pool[item] = self.item_pool.get(item, 0) + int(count)
elif entry_type == "GROUP" and ":" in params:
name, item = map(str.strip, params.split(":", 1))
if item == "":
continue
if "," in item:
item = list(map(str.strip, item.split(",")))
item_group[name] = item