2023-03-27 16:07:42 +02:00
|
|
|
from abc import ABC
|
|
|
|
|
2023-03-27 18:37:30 +02:00
|
|
|
from level.elements.static.StaticLevelElement import StaticLevelElement
|
2023-03-27 16:07:42 +02:00
|
|
|
from physics.TickData import TickData
|
|
|
|
|
|
|
|
|
|
|
|
class ReceiverLevelElement(StaticLevelElement, ABC):
|
2023-03-29 15:40:15 +02:00
|
|
|
def __init__(self, tile: dict, loaded_level, level_screen_manager: 'LevelScreenManager'):
|
|
|
|
super().__init__(tile, loaded_level, level_screen_manager)
|
2023-03-27 16:07:42 +02:00
|
|
|
|
|
|
|
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
|
2023-03-27 18:37:30 +02:00
|
|
|
|
2023-03-27 16:07:42 +02:00
|
|
|
if 'active_state' in tile:
|
2023-03-27 18:37:30 +02:00
|
|
|
self.active_state_invert = tile['active_state'] == 'True'
|
2023-03-27 16:07:42 +02:00
|
|
|
else:
|
2023-03-27 18:37:30 +02:00
|
|
|
self.active_state_invert = False
|
2023-03-27 16:07:42 +02:00
|
|
|
|
|
|
|
def set_active(self, active: bool):
|
2023-03-27 18:37:30 +02:00
|
|
|
if self.active_state_invert:
|
|
|
|
self.active_state = not active
|
|
|
|
else:
|
|
|
|
self.active_state = active
|
2023-03-27 16:07:42 +02:00
|
|
|
|
|
|
|
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)
|