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 __init__(self, machine: MachineController, name: str, player: Player, config: dict): """Initialize logic block.""" self.machine = machine self.name = name self.player = player self.handler_keys = set() # LogicBlocks are loaded multiple times and config_validator changes the config # therefore we have to copy the config config = copy.deepcopy(config) self.config = self.machine.config_validator.validate_config( 'logic_blocks:{}'.format(self.config_section_name), config, base_spec='logic_blocks:common') self.configure_logging('Logicblock.' + name, self.config['console_log'], self.config['file_log']) self.player_state_variable = "{}_state".format(self.name) '''player_var: (logic_block)_state desc: A dictionary that stores the internal state of the logic block with the name (logic_block). (In other words, a logic block called *mode1_hit_counter* will store its state in a player variable called ``mode1_hit_counter_state``). The state that's stored in this variable include whether the logic block is enabled and whether it's complete. The actual value of the logic block is stored in another player variable whose name you can specify via the ``player_variable:`` setting in the individual logic block config. ''' if not player.is_player_var(self.player_state_variable ) or not self.config['persist_state']: player[self.player_state_variable] = { "enabled": False, "completed": False } if not self.config['enable_events']: self.enabled = True if not self.config['events_when_complete']: self.config['events_when_complete'] = [ 'logicblock_' + self.name + '_complete' ] if not self.config['events_when_hit']: self.config['events_when_hit'] = [ 'logicblock_' + self.name + '_hit' ]
def device_loaded_in_mode(self, mode: Mode, player: Player): """Load extra ball in mode and initialise player. Args: mode: Mode which is loaded player: Current player """ del mode self.player = player if not player.is_player_var('extra_ball_{}_num_awarded'.format( self.name)): player['extra_ball_{}_num_awarded'.format(self.name)] = 0 '''player_var: extra_ball_(name)_awarded
def device_loaded_in_mode(self, mode: Mode, player: Player): """Load extra ball in mode and initialise player. Args: ---- mode: Mode which is loaded player: Current player """ del mode self.player = player if not player.is_player_var(self._player_var_name): player[self._player_var_name] = 0 '''player_var: extra_ball_(name)_awarded
def __init__(self, machine: MachineController, name: str, player: Player, config: dict): """Initialise logic block.""" self.machine = machine self.name = name self.player = player self.handler_keys = set() self.log = None # LogicBlocks are loaded multiple times and config_validator changes the config # therefore we have to copy the config config = copy.deepcopy(config) self.config = self.machine.config_validator.validate_config( 'logic_blocks:{}'.format(self.config_section_name), config, base_spec='logic_blocks:common') self.player_state_variable = "{}_state".format(self.name) if not player.is_player_var(self.player_state_variable ) or not self.config['persist_state']: player[self.player_state_variable] = { "enabled": False, "completed": False } if not self.config['enable_events']: self.enabled = True if not self.config['events_when_complete']: self.config['events_when_complete'] = [ 'logicblock_' + self.name + '_complete' ] if not self.config['events_when_hit']: self.config['events_when_hit'] = [ 'logicblock_' + self.name + '_hit' ]