-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathheader_lazy_evaluation.py
More file actions
46 lines (33 loc) · 1.43 KB
/
header_lazy_evaluation.py
File metadata and controls
46 lines (33 loc) · 1.43 KB
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
####################################################################################################################
# Python classes for performing certain calculations at module system build time.
####################################################################################################################
class LazyIdEvaluation:
"""Base class for identifier calculations delayed to module system build time."""
def recurse(self, processor, i):
if isinstance(i, LazyIdEvaluation):
i = i.process(processor)
return processor.process_id(i)
class add(LazyIdEvaluation):
"""Adds multiple identifiers."""
def __init__(self, *args):
self.ids = args
def process(self, processor):
return sum(self.recurse(processor, i) for i in self.ids)
class sub(LazyIdEvaluation):
"""Subtracts one identifier from another."""
def __init__(self, a, b):
self.a = a
self.b = b
def process(self, processor):
return self.recurse(processor, self.a) - self.recurse(processor, self.b)
class price(LazyIdEvaluation):
"""Gets the price of an item id."""
def __init__(self, item_id):
self.item_id = item_id
def process(self, processor):
import module_items
return module_items.items[processor.process_id(self.item_id, "itm")][5]
class block:
"""Inserts a list of operations inside an exisiting block."""
def __init__(self, block):
self.block = block