Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1190 modes in subfolders #1396

Merged
merged 3 commits into from Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions mpf/core/mode_controller.py
Expand Up @@ -156,7 +156,7 @@ def _get_mode_config_file(self, mode_string):
self.machine.config['mpf']['paths']['modes'],
self._machine_mode_folders[mode_string],
'config',
self._machine_mode_folders[mode_string] + '.yaml')
os.path.basename(self._machine_mode_folders[mode_string]) + '.yaml')
if not os.path.isfile(mode_config_file):
return False
except KeyError:
Expand Down Expand Up @@ -310,10 +310,29 @@ def _get_mode_folder(self, base_folder):
folder)

if os.path.isdir(this_mode_folder) and not folder.startswith('_'):
final_mode_folders[folder] = folder
if 'config' not in os.listdir(this_mode_folder):
sub_folders = self._get_sub_folders(base_folder, this_mode_folder)
final_mode_folders.update(sub_folders)
else:
final_mode_folders[folder] = folder

return final_mode_folders

def _get_sub_folders(self, root_folder, base_folder):
final_sub_folders = dict()

for folder in os.listdir(base_folder):
this_mode_folder = os.path.join(base_folder, folder)

if os.path.isdir(this_mode_folder) and not folder.startswith('_'):
if 'config' not in os.listdir(this_mode_folder):
final_sub_folders.update(self._get_sub_folders(root_folder, this_mode_folder))
else:
final_sub_folders[folder] = os.path.relpath(this_mode_folder, os.path.join(
root_folder, self.machine.config['mpf']['paths']['modes']))

return final_sub_folders

@classmethod
def _player_added(cls, player, num, **kwargs):
del num
Expand Down
3 changes: 3 additions & 0 deletions mpf/tests/machine_files/mode_tests/config/test_modes.yaml
Expand Up @@ -5,3 +5,6 @@ modes:
- mode2
- mode3
- mode4
- mode5
- mode6
- mode7
@@ -0,0 +1,14 @@
#config_version=5
mode:
start_events: start_mode1
stop_events: stop_mode1
priority: 200
start_priority: 1
stop_on_ball_end: false
game_mode: False

mode_settings:
this: true

config:
- test.yaml
@@ -0,0 +1,3 @@
#config_version=5
mode_settings:
test: 123
@@ -0,0 +1,14 @@
#config_version=5
mode:
start_events: start_mode1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick: This should be start_mode6. Otherwise other tests will accidentally start this mode. Same for the other new modes

stop_events: stop_mode1
priority: 200
start_priority: 1
stop_on_ball_end: false
game_mode: False

mode_settings:
this: true

config:
- test.yaml
@@ -0,0 +1,3 @@
#config_version=5
mode_settings:
test: 123
@@ -0,0 +1,14 @@
#config_version=5
mode:
start_events: start_mode1
stop_events: stop_mode1
priority: 200
start_priority: 1
stop_on_ball_end: false
game_mode: False

mode_settings:
this: true

config:
- test.yaml
@@ -0,0 +1,3 @@
#config_version=5
mode_settings:
test: 123
3 changes: 3 additions & 0 deletions mpf/tests/test_Modes.py
Expand Up @@ -19,6 +19,9 @@ def test_loading_modes(self):
self.assertIn('mode2', self.machine.modes)
self.assertIn('mode3', self.machine.modes)
self.assertIn('mode4', self.machine.modes)
self.assertIn('mode5', self.machine.modes)
self.assertIn('mode6', self.machine.modes)
self.assertIn('mode7', self.machine.modes)

def test_mode_start_stop(self):
# Setup mocked event handlers for mode start/stop sequence
Expand Down