Skip to content

Commit

Permalink
Merge pull request #1646 from Samdal/patch-2
Browse files Browse the repository at this point in the history
Add niceties to achievement_group
  • Loading branch information
toomanybrians authored Jan 16, 2023
2 parents 3364403 + 7a28d9d commit a54e05a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions mpf/config_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ achievement_groups:
disable_events: event_handler|event_handler:ms|None
start_selected_events: event_handler|event_handler:ms|None
select_random_achievement_events: event_handler|event_handler:ms|None
disable_random: single|bool|false
allow_selection_change_while_disabled: single|bool|false
auto_select: single|bool|false
disable_while_achievement_started: single|bool|true
Expand All @@ -28,6 +29,7 @@ achievement_groups:
events_when_no_more_enabled: list|event_posted|None
events_when_enabled: list|event_posted|None
show_tokens: dict|str:str|None
sync_ms: single|int|None
show_when_enabled: single|machine(shows)|None
achievements:
__valid_in__: mode
Expand Down
21 changes: 14 additions & 7 deletions mpf/devices/achievement_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def enable(self):
if show:
self._show = show.play(
priority=self.mode.priority,
loops=-1,
loops=-1, sync_ms=self.config['sync_ms'],
show_tokens=self.config['show_tokens'])

for e in self.config['events_when_enabled']:
Expand Down Expand Up @@ -204,11 +204,14 @@ def _all_complete(self):
def event_select_random_achievement(self, **kwargs):
"""Event handler for select_random_achievement event."""
del kwargs
self.select_random_achievement()
if self.config['disable_random']:
self.rotate_right()
else:
self.select_random_achievement()

def select_random_achievement(self):
"""Select a random achievement."""
self.debug_log("Selecting random achievement")
"""Select a random or sequential achievement."""
self.debug_log("Selecting an achievement")

if not self._is_ok_to_change_selection():
self.debug_log("Not ok to change selection. Aborting")
Expand All @@ -218,10 +221,14 @@ def select_random_achievement(self):
self._selected_member.unselect()

try:
ach = choice(self._get_available_achievements_for_selection())
# todo change this to use our Randomizer class
if self.config['disable_random']:
ach = self._get_available_achievements_for_selection()[0]
self.debug_log("Picked new non-random achievement: %s", ach)
else:
ach = choice(self._get_available_achievements_for_selection())
self.debug_log("Picked new random achievement: %s", ach)
self._selected_member = ach
self.debug_log("Picked new random achievement: %s", ach)
ach.select()
except IndexError:
self._no_more_enabled()
Expand Down Expand Up @@ -290,7 +297,7 @@ def _update_selected(self):
self.debug_log("Do not have a current selected member")

if self.config['auto_select']:
self.debug_log("Auto select is true. Getting random achievement")
self.debug_log("Auto select is true. Getting achievement")
self.select_random_achievement()

return False
Expand Down

0 comments on commit a54e05a

Please sign in to comment.