def add_control_events_in_mode(self, mode: Mode) -> None: """Add control events in mode if this device has any mode control events. Args: mode: Mode which loaded the device """ if "enable_events" in self.config and not self.config['enable_events']: mode.add_mode_event_handler("mode_{}_started".format(mode.name), self.event_enable, priority=100)
def _process_config(self, config: dict, mode: Mode, priority: int = 0): del priority self.debug_log("Processing LogicBlock configuration.") blocks_added = self._create_logic_blocks( config=config, player=self.machine.game.player) for block in blocks_added: block.create_control_events() mode.add_mode_event_handler("mode_{}_started".format(mode.name), block.mode_started) return self._unload_logic_blocks, blocks_added
def device_loaded_in_mode(self, mode: Mode, player: Player): """Restore internal state from player if persist_state is set or create new state.""" super().device_loaded_in_mode(mode, player) if self.config['persist_state']: if not player.is_player_var(self.player_state_variable): player[self.player_state_variable] = LogicBlockState( self.get_start_value()) # enable device ONLY when we create a new entry in the player if self._start_enabled: mode.add_mode_event_handler("mode_{}_started".format( mode.name), self.enable, priority=100) self._state = player[self.player_state_variable] else: self._state = LogicBlockState(self.get_start_value()) if self._start_enabled: mode.add_mode_event_handler("mode_{}_started".format( mode.name), self.enable, priority=100) mode.add_mode_event_handler("mode_{}_started".format(mode.name), self.post_update_event)
def device_added_to_mode(self, mode: Mode, player: Player): """Load device on mode start and restore state. Args: mode: mode which was contains the device player: player which is currently active """ super().device_added_to_mode(mode, player) self._mode = mode states = [ 'disabled', 'enabled', 'started', 'stopped', 'selected', 'completed' ] for ach in self.config['achievements']: for state in states: mode.add_mode_event_handler( ach.config['events_when_{}'.format(state)][0], self._member_state_changed, achievement=ach)