66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
|
from abc import ABC
|
||
|
|
||
|
from level.elements.static.StaticLevelElement import StaticLevelElement
|
||
|
from physics.TickData import TickData
|
||
|
|
||
|
|
||
|
class ReceiverLevelElement(StaticLevelElement, ABC):
|
||
|
def __init__(self, tile: dict, loaded_level):
|
||
|
super().__init__(tile, loaded_level)
|
||
|
|
||
|
self.requires = {
|
||
|
}
|
||
|
if 'requires_and' in tile:
|
||
|
self.requires['and'] = tile['requires_and']
|
||
|
if 'requires_or' in tile:
|
||
|
self.requires['or'] = tile['requires_or']
|
||
|
if 'requires_xor' in tile:
|
||
|
self.requires['xor'] = tile['requires_xor']
|
||
|
|
||
|
self.active_state = False
|
||
|
|
||
|
if 'active_state' in tile:
|
||
|
self.active_state_invert = tile['active_state'] == 'True'
|
||
|
else:
|
||
|
self.active_state_invert = False
|
||
|
|
||
|
def set_active(self, active: bool):
|
||
|
if self.active_state_invert:
|
||
|
self.active_state = not active
|
||
|
else:
|
||
|
self.active_state = active
|
||
|
|
||
|
def tick(self, tick_data: TickData):
|
||
|
super().tick(tick_data)
|
||
|
|
||
|
active = False
|
||
|
|
||
|
if 'and' in self.requires:
|
||
|
for requirement in self.requires['and']:
|
||
|
element = self.loaded_level.get_element_by_id(requirement)
|
||
|
if element and element.emitter_state:
|
||
|
active = True
|
||
|
else:
|
||
|
active = False
|
||
|
break
|
||
|
|
||
|
if 'or' in self.requires:
|
||
|
for requirement in self.requires['or']:
|
||
|
element = self.loaded_level.get_element_by_id(requirement)
|
||
|
if element and element.emitter_state:
|
||
|
active = True
|
||
|
break
|
||
|
|
||
|
if 'xor' in self.requires:
|
||
|
for requirement in self.requires['xor']:
|
||
|
element = self.loaded_level.get_element_by_id(requirement)
|
||
|
if element and element.emitter_state:
|
||
|
if active:
|
||
|
active = False
|
||
|
break
|
||
|
else:
|
||
|
active = True
|
||
|
|
||
|
if active != self.active_state:
|
||
|
self.set_active(active)
|