本文整理汇总了Python中mpf.system.tasks.DelayManager类的典型用法代码示例。如果您正苦于以下问题:Python DelayManager类的具体用法?Python DelayManager怎么用?Python DelayManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DelayManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timer_tick
def timer_tick(self):
"""Called by the platform each machine tick based on self.HZ"""
self.timing.timer_tick() # notifies the timing module
self.events.post('timer_tick') # sends the timer_tick system event
self.tick_num += 1
Task.timer_tick() # notifies tasks
DelayManager.timer_tick(self)
self.events._process_event_queue()
示例2: __init__
def __init__(self, machine):
self.log = logging.getLogger('switchplayer')
if 'switchplayer' not in machine.config:
machine.log.debug('"switchplayer:" section not found in '
'machine configuration, so the Switch Player'
'plugin will not be used.')
return
self.machine = machine
self.delay = DelayManager()
self.current_step = 0
config_spec = '''
start_event: string|machine_reset_phase_3
start_delay: secs|0
'''
self.config = Config.process_config(config_spec,
self.machine.config['switchplayer'])
self.machine.events.add_handler(self.config['start_event'],
self._start_event_callback)
self.step_list = self.config['steps']
self.start_delay = self.config['start_delay']
示例3: __init__
def __init__(self, machine):
self.log = logging.getLogger("switch_player")
if "switch_player" not in machine.config:
machine.log.debug(
'"switch_player:" section not found in '
"machine configuration, so the Switch Player"
"plugin will not be used."
)
return
self.machine = machine
self.delay = DelayManager()
self.current_step = 0
config_spec = """
start_event: string|machine_reset_phase_3
start_delay: secs|0
"""
self.config = Config.process_config(config_spec, self.machine.config["switch_player"])
self.machine.events.add_handler(self.config["start_event"], self._start_event_callback)
self.step_list = self.config["steps"]
self.start_delay = self.config["start_delay"]
示例4: __init__
def __init__(self, machine, name, config, priority):
"""SequenceShot is where you need certain switches to be hit in the
right order, possibly within a time limit.
Subclass of `Shot`
Args:
machine: The MachineController object
name: String name of this shot.
config: Dictionary that holds the configuration for this shot.
"""
super(SequenceShot, self).__init__(machine, name, config, priority)
self.delay = DelayManager()
self.progress_index = 0
"""Tracks how far along through this sequence the current shot is."""
# convert our switches config to a list
if 'switches' in self.config:
self.config['switches'] = \
Config.string_to_list(self.config['switches'])
# convert our timout to ms
if 'time' in self.config:
self.config['time'] = Timing.string_to_ms(self.config['time'])
else:
self.config['time'] = 0
self.active_delay = False
self.enable()
示例5: __init__
def __init__(self, machine, name):
self.log = logging.getLogger(__name__)
self.machine = machine
self.task = None
self.name = name
self.delays = DelayManager()
self.registered_event_handlers = list()
self.registered_switch_handlers = list()
示例6: __init__
def __init__(self, machine, mode, name, config):
self.machine = machine
self.mode = mode
self.name = name
self.config = config
self.tick_var = self.mode.name + '_' + self.name + '_tick'
self.mode.player[self.tick_var] = 0
self.running = False
self.start_value = 0
self.restart_on_complete = False
self._ticks = 0
self.end_value = 0
self.max_value = None
self.direction = 'up'
self.tick_secs = 1
self.timer = None
self.bcp = False
self.event_keys = set()
self.delay = DelayManager()
if 'start_value' in self.config:
self.start_value = self.config['start_value']
else:
self.start_value = 0
if 'start_running' in self.config and self.config['start_running']:
self.running = True
if 'end_value' in self.config:
self.end_value = self.config['end_value']
if 'control_events' in self.config and self.config['control_events']:
if type(self.config['control_events']) is dict:
self.config['control_events'] = [self.config['control_events']]
else:
self.config['control_events'] = list()
if 'direction' in self.config and self.config['direction'] == 'down':
self.direction = 'down'
if 'tick_interval' in self.config:
self.tick_secs = Timing.string_to_secs(self.config['tick_interval'])
if 'max_value' in self.config:
self.max_value = self.config['max_value']
if ('restart_on_complete' in self.config and
self.config['restart_on_complete']):
self.restart_on_complete = True
if 'bcp' in self.config and self.config['bcp']:
self.bcp = True
self.mode.player[self.tick_var] = self.start_value
self._setup_control_events(self.config['control_events'])
示例7: __init__
def __init__(self, machine, name, config, collection=None, validate=True):
super(Multiball, self).__init__(machine, name, config, collection,
validate=validate)
self.delay = DelayManager()
# let ball devices initialise first
self.machine.events.add_handler('init_phase_3',
self._initialize)
示例8: __init__
def __init__(self, machine, config, name, path):
self.machine = machine
self.config = config
self.name = name.lower()
self.path = path
self.log = logging.getLogger("Mode." + name)
self.delay = DelayManager()
self.priority = 0
self._active = False
self._mode_start_wait_queue = None
self.stop_methods = list()
self.timers = dict()
self.start_callback = None
self.stop_callback = None
self.event_handlers = set()
self.switch_handlers = list()
self.mode_start_kwargs = dict()
self.mode_stop_kwargs = dict()
self.mode_devices = set()
self.player = None
"""Reference to the current player object."""
self._validate_mode_config()
self.configure_mode_settings(config.get("mode", dict()))
self.auto_stop_on_ball_end = self.config["mode"]["stop_on_ball_end"]
"""Controls whether this mode is stopped when the ball ends,
regardless of its stop_events settings.
"""
self.restart_on_next_ball = self.config["mode"]["restart_on_next_ball"]
"""Controls whether this mode will restart on the next ball. This only
works if the mode was running when the ball ended. It's tracked per-
player in the '_restart_modes_on_next_ball' untracked player variable.
"""
for asset_manager in self.machine.asset_managers.values():
config_data = self.config.get(asset_manager.config_section, dict())
self.config[asset_manager.config_section] = asset_manager.register_assets(
config=config_data, mode_path=self.path
)
# Call registered remote loader methods
for item in self.machine.mode_controller.loader_methods:
if item.config_section and item.config_section in self.config and self.config[item.config_section]:
item.method(config=self.config[item.config_section], mode_path=self.path, **item.kwargs)
elif not item.config_section:
item.method(config=self.config, mode_path=self.path, **item.kwargs)
self.mode_init()
示例9: __init__
def __init__(self, machine, config, name, path):
self.machine = machine
self.config = config
self.name = name.lower()
self.path = path
self.log = logging.getLogger('Mode.' + name)
self.delay = DelayManager()
self.priority = 0
self._active = False
self._mode_start_wait_queue = None
self.stop_methods = list()
self.timers = dict()
self.start_callback = None
self.stop_callback = None
self.event_handlers = set()
self.switch_handlers = list()
self.mode_start_kwargs = dict()
self.mode_stop_kwargs = dict()
self.mode_devices = set()
self.auto_stop_on_ball_end = True
'''Controls whether this mode is stopped when the ball ends,
regardless of its stop_events settings.
'''
self.player = None
'''Reference to the current player object.'''
self._validate_mode_config()
self.configure_mode_settings(config.get('mode', dict()))
for asset_manager in self.machine.asset_managers.values():
config_data = self.config.get(asset_manager.config_section, dict())
self.config[asset_manager.config_section] = (
asset_manager.register_assets(config=config_data,
mode_path=self.path))
# Call registered remote loader methods
for item in self.machine.mode_controller.loader_methods:
if (item.config_section and
item.config_section in self.config and
self.config[item.config_section]):
item.method(config=self.config[item.config_section],
mode_path=self.path,
**item.kwargs)
elif not item.config_section:
item.method(config=self.config, mode_path=self.path,
**item.kwargs)
self.mode_init()
示例10: BallSave
class BallSave(Device):
config_section = "ball_saves"
collection = "ball_saves"
class_label = "ball_save"
def __init__(self, machine, name, config, collection=None, validate=True):
super(BallSave, self).__init__(machine, name, config, collection, validate=validate)
self.delay = DelayManager()
self.source_playfield = self.config["source_playfield"]
def enable(self, **kwargs):
self.log.debug("Enabling...")
# Enable shoot again
self.machine.events.add_handler("ball_drain", self._ball_drain_shoot_again, priority=1000)
if self.config["auto_disable_time"] > 0:
self.delay.add("disable_shoot_again", self.config["auto_disable_time"], self.disable)
self.machine.events.post("ball_save_" + self.name + "_enabled")
def disable(self, **kwargs):
self.log.debug("Disabling...")
self.machine.events.remove_handler(self._ball_drain_shoot_again)
self.delay.remove("disable_shoot_again")
self.machine.events.post("ball_save_" + self.name + "_disabled")
def _ball_drain_shoot_again(self, balls, **kwargs):
if balls <= 0:
return {"balls": balls}
self.machine.events.post("ball_save_" + self.name + "_shoot_again", balls=balls)
self.log.debug("Ball drained during ball save. Requesting a new one.")
self.source_playfield.add_ball(balls=balls)
return {"balls": 0}
示例11: __init__
def __init__(self, machine, name, config, collection=None, validate=True):
super(BallSave, self).__init__(machine, name, config, collection, validate=validate)
self.delay = DelayManager()
self.enabled = False
self.saves_remaining = 0
if self.config["balls_to_save"] == -1:
self.unlimited_saves = True
else:
self.unlimited_saves = False
self.source_playfield = self.config["source_playfield"]
示例12: __init__
def __init__(self, machine, name, collection):
self.log = logging.getLogger('Playfield')
self.machine = machine
self.name = name
self.tags = list()
self.config = defaultdict(lambda: None)
self.config['eject_targets'] = list()
self.ball_controller = self.machine.ball_controller
self.delay = DelayManager()
# Add the playfield ball device to the existing device collection
collection_object = getattr(self.machine, collection)[name] = self
# Attributes
self._balls = 0
self.num_balls_requested = 0
self.player_controlled_eject_in_progress = None
self.queued_balls = list()
# Set up event handlers
# Watch for balls added to the playfield
for device in self.machine.balldevices:
for target in device.config['eject_targets']:
if target == self.name:
self.machine.events.add_handler(
event='balldevice_' + device.name +
'_ball_eject_success',
handler=self._source_device_eject_success)
self.machine.events.add_handler(
event='balldevice_' + device.name +
'_ball_eject_attempt',
handler=self._source_device_eject_attempt)
break
# Watch for balls removed from the playfield
self.machine.events.add_handler('balldevice_captured_from_playfield',
self._ball_removed_handler)
# Watch for any switch hit which indicates a ball on the playfield
self.machine.events.add_handler('sw_playfield_active',
self.playfield_switch_hit)
示例13: __init__
def __init__(self, machine):
self.machine = machine
self.log = logging.getLogger("BallController")
self.log.debug("Loading the BallController")
self.delay = DelayManager()
self.game = None
self._num_balls_known = -999
self.num_balls_missing = 0
# Balls lost and/or not installed.
# register for events
self.machine.events.add_handler('request_to_start_game',
self.request_to_start_game)
self.machine.events.add_handler('machine_reset_phase_2',
self._initialize)
示例14: __init__
def __init__(self, machine, name, player, config):
self.log = logging.getLogger('Counter.' + name)
self.log.debug("Creating Counter LogicBlock")
super(Counter, self).__init__(machine, name, player, config)
self.delay = DelayManager()
self.ignore_hits = False
self.hit_value = -1
config_spec = '''
count_events: list|None
count_complete_value: int|None
multiple_hit_window: ms|0
count_interval: int|1
direction: string|up
starting_count: int|0
'''
self.config = Config.process_config(config_spec=config_spec,
source=self.config)
if 'event_when_hit' not in self.config:
self.config['event_when_hit'] = ('counter_' + self.name +
'_hit')
if 'player_variable' not in self.config:
self.config['player_variable'] = self.name + '_count'
self.hit_value = self.config['count_interval']
if self.config['direction'] == 'down' and self.hit_value > 0:
self.hit_value *= -1
elif self.config['direction'] == 'up' and self.hit_value < 0:
self.hit_value *= -1
if not self.config['persist_state']:
self.player[self.config['player_variable']] = (
self.config['starting_count'])
示例15: __init__
def __init__(self, machine, name, config, collection=None, validate=True):
super(Diverter, self).__init__(machine, name, config, collection,
validate=validate)
self.delay = DelayManager()
# Attributes
self.active = False
self.enabled = False
self.platform = None
self.diverting_ejects_count = 0
self.eject_state = False
self.eject_attempt_queue = deque()
self.trigger_type = 'software' # 'software' or 'hardware'
# Create a list of ball device objects when active and inactive. We need
# this because ball eject attempts pass the target device as an object
# rather than by name.
# register for feeder device eject events
for feeder_device in self.config['feeder_devices']:
self.machine.events.add_handler('balldevice_' + feeder_device.name +
'_ball_eject_attempt',
self._feeder_eject_attempt)
self.machine.events.add_handler('balldevice_' + feeder_device.name +
'_ball_eject_failed',
self._feeder_eject_count_decrease)
self.machine.events.add_handler('balldevice_' + feeder_device.name +
'_ball_eject_success',
self._feeder_eject_count_decrease)
self.machine.events.add_handler('init_phase_3', self._register_switches)
self.platform = self.config['activation_coil'].platform