def remove_component(self, comp_type: Type[Component]): if comp_type in self.components.keys(): del self.components[comp_type] keys = self.key.get_keys() keys.remove(comp_type) self.key = ComponentKey(keys) PyBus.Instance().post(ComponentRemovedEvent(self))
def add_component(self, comp_type: Type[Component]): if comp_type not in self.components.keys(): keys = self.key.get_keys() keys.append(comp_type) self.key = ComponentKey(keys) self.components[comp_type] = comp_type() PyBus.Instance().post(ComponentAddedEvent(self))
def __init__(self, process): self._callbacks: Dict[str, List[Callable[[Message], None]]] = {} self.process: BaseProcess = process self.broadcast_sync_message = None self.letterbox = deque() self.state = None self.answered_process = set() self.answered_process_broadcast_sync = set() self.answered_process_heartbit = set() self.have_process_sync_responded = False self.process_number = 1 self.heartbit_process = HeartbitProcess(self.process, self) PyBus.Instance().register(self, self)
def post(self): """Post this message on the bus""" PyBus.Instance().post(self)
def __init__(self): super(TestScene, self).__init__([WorldSystem, RenderSystem, InputSystem], [Player]) PyBus.Instance().register(self, self.__class__.__name__) self.player: Player self.player_transform: Transform
def destroy(self, entity: Entity): del self.current_scene.entities[entity.id] PyBus.Instance().post(EntityRemovedEvent(self, entity))
def instantiate(self, entity: Type[E]) -> E: new_ent: E = entity() self.current_scene.entities[new_ent.id] = new_ent PyBus.Instance().post(EntityAddedEvent(self, new_ent)) return new_ent
def load_system(self, system_type: Type[S]) -> S: if system_type not in self.current_scene.systems.keys(): new_sys: S = system_type() PyBus.Instance().register(new_sys, system_type) self.current_scene.systems[system_type] = new_sys return system_type()
def key_pressed(self, window, key, scancode, action, mods): PyBus.Instance().post(KeyEvent(Key(key), Action(action)))