-
Notifications
You must be signed in to change notification settings - Fork 0
/
chips.py
62 lines (41 loc) · 1.98 KB
/
chips.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
from behaviour import BuiltInChipBehaviour, CustomChipBehaviour, BehaviourInterface
'''A library of chip objects that includes the base chip class, a built in chip class and would probably include
a custom chip class that would get implemented in the future.
Built in chips are existing logic components in the game that are described within <item> tags in the chip_collection.xml
file. There would also be a user defined chip that is made up of built-in chips created using the HDL. However, it has
not been implemented yet'''
class Chip:
'''basic chip class that has an identifier and a bunch of properties that would need to correspond to the
attributes in the XML file'''
def __init__(self, identifier, **kwargs):
self.identifier = identifier
self.properties = kwargs
self.io_behaviour = BehaviourInterface()
def set_behaviour(self, obj):
#sets the chip's behaviour to either a built-in chip or a custom chip
self.io_behaviour = obj
def get_behaviour(self):
return self.io_behaviour
@property
def input_pins(self):
return self.io_behaviour.get_input_pins()
@property
def output_pins(self):
return self.io_behaviour.get_output_pins()
class BuiltInChip(Chip):
def __init__(self, identifier, **kwargs):
super().__init__(identifier, **kwargs)
self.set_behaviour(BuiltInChipBehaviour(self.identifier))
class And(BuiltInChip):
'''Not sure if this approach is a good one because it would require a massive number of classes
to implement all of the built-in chips.'''
_identifier = "andcomponent"
def __init__(self, **kwargs):
super().__init__(self._identifier, **kwargs)
class Or(BuiltInChip):
_identifier = "orcomponent"
def __init__(self, **kwargs):
super().__init__(self._identifier, **kwargs)
if __name__ == "__main__":
c = And(id=3, noneinterfactable=True)
print(c.properties)