def _initialize_switches(self): self.update_switches_from_hw() for switch in self.machine.switches: # Populate self.switches self.set_state(switch.name, switch.state, reset_time=True) # Populate self.registered_switches self.registered_switches[switch.name + '-0'] = list() self.registered_switches[switch.name + '-1'] = list() if self.machine.config['mpf']['auto_create_switch_events']: switch.activation_events.add( self.machine.config['mpf']['switch_event_active'].replace( '%', switch.name)) switch.deactivation_events.add( self.machine.config['mpf'][ 'switch_event_inactive'].replace( '%', switch.name)) if 'activation_events' in switch.config: for event in Util.string_to_lowercase_list( switch.config['activation_events']): if "|" in event: ev_name, ev_time = event.split("|") self.add_switch_handler( switch_name=switch.name, callback=self.machine.events.post, state=1, ms=Timing.string_to_ms(ev_time), callback_kwargs={'event': ev_name} ) else: switch.activation_events.add(event) if 'deactivation_events' in switch.config: for event in Util.string_to_lowercase_list( switch.config['deactivation_events']): if "|" in event: ev_name, ev_time = event.split("|") self.add_switch_handler( switch_name=switch.name, callback=self.machine.events.post, state=0, ms=Timing.string_to_ms(ev_time), callback_kwargs={'event': ev_name} ) else: switch.deactivation_events.add(event)
def _initialize_switches(self): self.update_switches_from_hw() for switch in self.machine.switches: # Populate self.switches self.set_state(switch.name, switch.state, reset_time=True) # Populate self.registered_switches self.registered_switches[switch.name + '-0'] = list() self.registered_switches[switch.name + '-1'] = list() if self.machine.config['mpf']['auto_create_switch_events']: switch.activation_events.add( self.machine.config['mpf']['switch_event_active'].replace( '%', switch.name)) switch.deactivation_events.add( self.machine.config['mpf'] ['switch_event_inactive'].replace('%', switch.name)) if 'activation_events' in switch.config: for event in Util.string_to_lowercase_list( switch.config['activation_events']): if "|" in event: ev_name, ev_time = event.split("|") self.add_switch_handler( switch_name=switch.name, callback=self.machine.events.post, state=1, ms=Timing.string_to_ms(ev_time), callback_kwargs={'event': ev_name}) else: switch.activation_events.add(event) if 'deactivation_events' in switch.config: for event in Util.string_to_lowercase_list( switch.config['deactivation_events']): if "|" in event: ev_name, ev_time = event.split("|") self.add_switch_handler( switch_name=switch.name, callback=self.machine.events.post, state=0, ms=Timing.string_to_ms(ev_time), callback_kwargs={'event': ev_name}) else: switch.deactivation_events.add(event)
def _configure(self): self.config = self.machine.config['languages'] self.machine.language = self self.languages = Util.string_to_lowercase_list( self.machine.config['languages']) # Set the default language to the first entry in the list self.set_language(self.languages[0]) self.default_language = self.languages[0] self.find_text = re.compile('(\(.*?\))')
def _configure(self): self.config = self.machine.config['languages'] self.machine.language = self self.languages = Util.string_to_lowercase_list( self.machine.config['languages']) # Set the default language to the first entry in the list self.set_language(self.languages[0]) self.default_language = self.languages[0] self.find_text = re.compile('(\(.*?\))')
def do_load(self, callback, show_actions=None): self.show_actions = list() self.asset_manager.log.debug("Loading Show %s", self.file_name) if not show_actions: show_actions = self.load_show_from_disk() for step_num in range(len(show_actions)): step_actions = dict() step_actions['tocks'] = show_actions[step_num]['tocks'] # look for empty steps. If we find them we'll just add their tock # time to the previous step. if len(show_actions[step_num] ) == 1: # 1 because it still has tocks show_actions[-1]['tocks'] += step_actions['tocks'] continue # Events # make sure events is a list of strings if ('events' in show_actions[step_num] and show_actions[step_num]['events']): event_list = (Util.string_to_lowercase_list( show_actions[step_num]['events'])) step_actions['events'] = event_list # slide_player if ('display' in show_actions[step_num] and show_actions[step_num]['display']): step_actions['display'] = ( self.machine.display.slide_builder.preprocess_settings( show_actions[step_num]['display'])) # Sounds if ('sounds' in show_actions[step_num] and show_actions[step_num]['sounds']): # make sure we have a list of dicts if type(show_actions[step_num]['sounds']) is dict: show_actions[step_num]['sounds'] = ([ show_actions[step_num]['sounds'] ]) for entry in show_actions[step_num]['sounds']: try: entry['sound'] = self.machine.sounds[entry['sound']] except KeyError: self.asset_manager.log.critical( "Invalid sound '%s' " "found in show. ", entry['sound']) raise step_actions['sounds'] = show_actions[step_num]['sounds'] self.show_actions.append(step_actions) # count how many total locations are in the show. We need this later # so we can know when we're at the end of a show self.total_locations = len(self.show_actions) self.loaded = True if callback: callback() self._asset_loaded()
def rotate(self, direction=None, steps=1, states=None, exclude_states=None, mode=None, **kwargs): """Rotates (or "shifts") the state of all the shots in this group. This is used for things like lane change, where hitting the flipper button shifts all the states of the shots in the group to the left or right. This method actually transfers the current state of each shot profile to the left or the right, and the shot on the end rolls over to the taret on the other end. Args: direction: String that specifies whether the rotation direction is to the left or right. Values are 'right' or 'left'. Default of None will cause the shot group to rotate in the direction as specified by the rotation_pattern. steps: Integer of how many steps you want to rotate. Default is 1. states: A string of a state or a list of strings that represent the targets that will be selected to rotate. If None (default), then all targets will be included. exclude_states: A string of a state or a list of strings that controls whether any targets will *not* be rotated. (Any targets with an active profile in one of these states will not be included in the rotation. Default is None which means all targets will be rotated) Note that this shot group must, and rotation_events for this shot group, must both be enabled for the rotation events to work. """ if not self.machine.game: return if not self.rotation_enabled: if self.debug: self.log.debug("Received rotation request. " "Rotation Enabled: %s. Will NOT rotate", self.rotation_enabled) return # if we don't have states or exclude_states, we'll see if the first shot # in the group has them and use those. Since all the shots should have # the same profile applied, it's ok to just pick from the first one. if states: states = Util.string_to_lowercase_list(states) else: states = self.shots[0].enable_table[mode]['settings']['state_names_to_rotate'] if exclude_states: exclude_states = Util.string_to_lowercase_list(exclude_states) else: exclude_states = ( self.shots[0].enable_table[mode]['settings']['state_names_to_not_rotate']) shot_list = list() # build of a list of shots we're actually going to rotate for shot in self.shots: if ((not states or shot.enable_table[mode]['current_state_name'] in states) and shot.enable_table[mode]['current_state_name'] not in exclude_states): shot_list.append(shot) # shot_state_list is deque of tuples (state num, light show step num) shot_state_list = deque() for shot in shot_list: try: current_state = shot.running_light_show.current_location except AttributeError: current_state = -1 shot_state_list.append( (shot.player[shot.enable_table[mode]['settings']['player_variable']], current_state)) if self.debug: self.log.debug('Rotating. Mode: %s, Direction: %s, Include states:' ' %s, Exclude states: %s, Shots to be rotated: %s', mode, direction, states, exclude_states, [x.name for x in shot_list]) for shot in shot_list: shot.log.debug("This shot is part of a rotation event. Current" " state: %s", shot.enable_table[mode]['current_state_name']) # figure out which direction we're going to rotate if not direction: direction = shot_list[0].enable_table[mode]['settings']['rotation_pattern'][0] shot_list[0].enable_table[mode]['settings']['rotation_pattern'].rotate(-1) if self.debug: self.log.debug("Since no direction was specified, pulling from" " rotation pattern: '%s'", direction) # rotate that list if direction == 'right': shot_state_list.rotate(steps) else: shot_state_list.rotate(steps * -1) # step through all our shots and update their states for i in range(len(shot_list)): shot_list[i].jump(mode=mode, state=shot_state_list[i][0], lightshow_step=shot_state_list[i][1])
def do_load(self, callback, show_actions=None): self.show_actions = list() self.asset_manager.log.debug("Loading Show %s", self.file_name) if not show_actions: show_actions = self.load_show_from_disk() for step_num in range(len(show_actions)): step_actions = dict() step_actions['tocks'] = show_actions[step_num]['tocks'] # look for empty steps. If we find them we'll just add their tock # time to the previous step. if len(show_actions[step_num]) == 1: # 1 because it still has tocks show_actions[-1]['tocks'] += step_actions['tocks'] continue # Events # make sure events is a list of strings if ('events' in show_actions[step_num] and show_actions[step_num]['events']): event_list = (Util.string_to_lowercase_list( show_actions[step_num]['events'])) step_actions['events'] = event_list # slide_player if ('display' in show_actions[step_num] and show_actions[step_num]['display']): step_actions['display'] = ( self.machine.display.slide_builder.preprocess_settings( show_actions[step_num]['display'])) # Sounds if ('sounds' in show_actions[step_num] and show_actions[step_num]['sounds']): # make sure we have a list of dicts if type(show_actions[step_num]['sounds']) is dict: show_actions[step_num]['sounds'] = ( [show_actions[step_num]['sounds']]) for entry in show_actions[step_num]['sounds']: try: entry['sound'] = self.machine.sounds[entry['sound']] except KeyError: self.asset_manager.log.critical("Invalid sound '%s' " "found in show. ", entry['sound']) raise step_actions['sounds'] = show_actions[step_num]['sounds'] self.show_actions.append(step_actions) # count how many total locations are in the show. We need this later # so we can know when we're at the end of a show self.total_locations = len(self.show_actions) self.loaded = True if callback: callback() self._asset_loaded()