Skip to content

Commit

Permalink
add disable_random (groups auto selected in sequential order)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samdal committed Aug 9, 2022
1 parent 3473a3c commit 7a28d9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 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 Down
19 changes: 13 additions & 6 deletions mpf/devices/achievement_group.py
Original file line number Diff line number Diff line change
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 7a28d9d

Please sign in to comment.