Skip to content

Commit

Permalink
Include trigger in playfield_active events, prospector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Jun 3, 2024
1 parent 61f4b1c commit a07d18f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mpf/devices/autofire.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _hit(self):
if not self._enabled:
return
if not self._ball_search_in_progress:
self.config['playfield'].mark_playfield_active_from_device_action()
self.config['playfield'].mark_playfield_active_from_device_action(self.name)
if self._timeout_watch_time:
current_time = self.machine.clock.get_time()
self._timeout_hits = [t for t in self._timeout_hits if t > current_time - self._timeout_watch_time / 1000.0]
Expand Down
10 changes: 5 additions & 5 deletions mpf/devices/drop_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _ball_search_phase1(self):
self.reset_coil.pulse()
return True
# if down. knock down again
elif self.complete and self.knockdown_coil:
if self.complete and self.knockdown_coil:
self.info_log(" - complete, firing knockdown coil")
self.knockdown_coil.pulse()
return True
Expand Down Expand Up @@ -221,16 +221,16 @@ def _update_state_from_switch(self, reconcile=False, **kwargs):
is_complete = self.machine.switch_controller.is_active(
self.config['switch'])

self.info_log("Drop target %s switch %s has active value %s compared to drop complete %s",
self.name, self.config['switch'].name, is_complete, self.complete)
self.debug_log("Drop target %s switch %s has active value %s compared to drop complete %s",
self.name, self.config['switch'].name, is_complete, self.complete)
if self._in_ball_search or self._ignore_switch_hits:
self.debug_log("Ignoring state change in drop target %s due to being in ball search "
"or ignoring switch hits", self.name)
return

if not reconcile:
self.info_log("Hit without reconciling, marking playfield as active")
self.config['playfield'].mark_playfield_active_from_device_action()
self.debug_log("Hit without reconciling, marking playfield as active")
self.config['playfield'].mark_playfield_active_from_device_action(self.name)

if is_complete != self.complete:

Expand Down
2 changes: 1 addition & 1 deletion mpf/devices/magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def event_grab_ball(self, **kwargs):
def grab_ball(self):
"""Grab a ball."""
# mark the playfield active no matter what
self.config['playfield'].mark_playfield_active_from_device_action()
self.config['playfield'].mark_playfield_active_from_device_action(self.name)
# check if magnet is enabled or already active
if not self.enabled or self._active or self._release_in_progress:
return
Expand Down
12 changes: 6 additions & 6 deletions mpf/devices/playfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,27 @@ def ball_arrived(self):
incoming_ball.ball_arrived()
break

def _mark_playfield_active(self):
def _mark_playfield_active(self, source=None):
self.ball_arrived()
self.machine.events.post_boolean(self.name + "_active")
self.machine.events.post_boolean(self.name + "_active", source=source)
'''event: (name)_active
desc: The playfield called (name) is now active, meaning there's
at least one loose ball on it.
'''

def mark_playfield_active_from_device_action(self):
def mark_playfield_active_from_device_action(self, device_name=None):
"""Mark playfield active because a device on the playfield detected activity."""
self._playfield_switch_hit()
self._playfield_switch_hit(source=device_name)

def _playfield_switch_hit(self, **kwargs):
def _playfield_switch_hit(self, source=None, **kwargs):
"""Playfield switch was hit.
A switch tagged with '<this playfield name>_active' was just hit,
indicating that there is at least one ball on the playfield.
"""
if self.balls <= 0 or (kwargs.get('balls') and self.balls - kwargs['balls'] < 0):
self._mark_playfield_active()
self._mark_playfield_active(source)

if not self.num_balls_requested:
self.debug_log("Playfield was activated with no balls expected.")
Expand Down
2 changes: 1 addition & 1 deletion mpf/devices/sequence_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _sequence_advance(self, event_name, **kwargs):

# mark playfield active
if self.config['playfield']:
self.config['playfield'].mark_playfield_active_from_device_action()
self.config['playfield'].mark_playfield_active_from_device_action(self.name)

self.debug_log("Sequence advance: %s", event_name)

Expand Down
2 changes: 1 addition & 1 deletion mpf/devices/shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _mark_active(self, **kwargs):
"""Mark playfield active."""
del kwargs
if self.config['mark_playfield_active']:
self.config['playfield'].mark_playfield_active_from_device_action()
self.config['playfield'].mark_playfield_active_from_device_action(self.name)

def device_loaded_in_mode(self, mode: Mode, player: Player):
"""Add device to a mode that was already started.
Expand Down
1 change: 1 addition & 0 deletions mpf/devices/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,5 @@ def unmute(self, **kwargs):

@property
def is_muted(self):
"""True if this switch is currently muted."""
return self._mutes > 0

0 comments on commit a07d18f

Please sign in to comment.