Skip to content

Commit

Permalink
remove ball_add_live and move it into the playfield. fix #930
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed May 17, 2017
1 parent c890d65 commit 262d870
Show file tree
Hide file tree
Showing 39 changed files with 186 additions and 78 deletions.
1 change: 1 addition & 0 deletions mpf/core/config_spec.py
Expand Up @@ -725,6 +725,7 @@
ball_search_unblock_events: dict|str:ms|flipper_cradle_release
ball_search_enable_events: dict|str:ms|None
ball_search_disable_events: dict|str:ms|None
default_source_device: single|machine(ball_devices)|
playfield_transfers:
__valid_in__: machine
ball_switch: single|machine(switches)|None
Expand Down
19 changes: 3 additions & 16 deletions mpf/devices/playfield.py
Expand Up @@ -185,9 +185,8 @@ def add_ball(self, balls=1, source_device=None,
The source_device arg is included to give you an options for specifying
the source of the ball(s) to be added. This argument is optional, so if
you don't supply them then MPF will look for a device
tagged with 'ball_add_live'. If you don't provide a source and you don't
have a device with the 'ball_add_live' tag, MPF will quit.
you don't supply them then MPF will use the default_source_device of
this playfield.
This method does *not* increase the game controller's count of the
number of balls in play. So if you want to add balls (like in a
Expand Down Expand Up @@ -234,20 +233,8 @@ def add_ball(self, balls=1, source_device=None,
"doesn't make sense. Not adding any balls...")

# Figure out which device we'll get a ball from

if source_device:
pass
else:
for device in self.machine.ball_devices.items_tagged('ball_add_live'):
if self in device.config['eject_targets']:
source_device = device
break

if not source_device:
raise AssertionError("Received request to add a ball to the playfield"
", but no source device was passed and no ball "
"devices are tagged with 'ball_add_live'. Cannot"
" add a ball.")
source_device = self.config['default_source_device']

self.debug_log("Received request to add %s ball(s). Source device: %s."
" Player-controlled: %s", balls,
Expand Down
4 changes: 0 additions & 4 deletions mpf/mpfconfig.yaml
Expand Up @@ -397,10 +397,6 @@ psus:
default:
voltage: 48

playfields:
playfield:
tags: default

hardware:
platform: smart_virtual
coils: default
Expand Down
14 changes: 12 additions & 2 deletions mpf/tests/MpfTestCase.py
Expand Up @@ -46,9 +46,10 @@ class TestMachineController(MachineController):
"""
local_mpf_config_cache = {} # type: Any

def __init__(self, mpf_path, machine_path, options, config_patches, clock, mock_data,
def __init__(self, mpf_path, machine_path, options, config_patches, config_defaults, clock, mock_data,
enable_plugins=False):
self.test_config_patches = config_patches
self.test_config_defaults = config_defaults
self._enable_plugins = enable_plugins
self._test_clock = clock
self._mock_data = mock_data
Expand All @@ -75,6 +76,7 @@ def _register_plugin_config_players(self):

def _load_config(self):
super()._load_config()
self.config = Util.dict_merge(self.test_config_defaults, self.config)
self.config = Util.dict_merge(self.config, self.test_config_patches)


Expand All @@ -95,6 +97,13 @@ def __init__(self, methodName='runTest'):
self.machine_config_patches['mpf']['default_platform_hz'] = 100
self.machine_config_patches['mpf']['plugins'] = list()
self.machine_config_patches['bcp'] = []

self.machine_config_defaults = dict()
self.machine_config_defaults['playfields'] = dict()
self.machine_config_defaults['playfields']['playfield'] = dict()
self.machine_config_defaults['playfields']['playfield']['tags'] = "default"
self.machine_config_defaults['playfields']['playfield']['default_source_device'] = None

self._last_event_kwargs = {}
self._events = {}
self.expected_duration = 0.5
Expand Down Expand Up @@ -411,7 +420,8 @@ def setUp(self):
self.machine = TestMachineController(
os.path.abspath(os.path.join(
mpf.core.__path__[0], os.pardir)), machine_path,
self.getOptions(), self.machine_config_patches, self.clock, self._get_mock_data(),
self.getOptions(), self.machine_config_patches, self.machine_config_defaults,
self.clock, self._get_mock_data(),
self.get_enable_plugins())

self._initialise_machine()
Expand Down
7 changes: 6 additions & 1 deletion mpf/tests/machine_files/auditor/config/config.yaml
Expand Up @@ -16,8 +16,13 @@ coils:
c_eject:
number:

playfields:
playfield:
default_source_device: s_trough
tags: default

ball_devices:
s_trough:
ball_switches: s_ball
eject_coil: c_eject
tags: trough, drain, home, ball_add_live
tags: trough, drain, home
6 changes: 5 additions & 1 deletion mpf/tests/machine_files/ball_controller/config/config.yaml
Expand Up @@ -34,6 +34,11 @@ switches:
number:
tags: playfield_active

playfields:
playfield:
default_source_device: test_launcher
tags: default

ball_devices:
test_trough:
eject_coil: eject_coil1
Expand All @@ -44,7 +49,6 @@ ball_devices:
test_launcher:
eject_coil: eject_coil2
ball_switches: s_ball_switch_launcher
tags: ball_add_live
debug: true
test_vuk:
eject_coil: eject_coil3
Expand Down
Expand Up @@ -3,6 +3,11 @@
game:
balls_per_game: 1

playfields:
playfield:
default_source_device: test_target1
tags: default

coils:
eject_coil1:
number:
Expand Down Expand Up @@ -61,7 +66,6 @@ ball_devices:
eject_coil: eject_coil3
ball_switches: s_ball_switch_target1
debug: true
tags: ball_add_live
confirm_eject_type: target
test_target2:
eject_coil: eject_coil4
Expand Down
Expand Up @@ -6,6 +6,11 @@ coils:
plunger_eject:
number:

playfields:
playfield:
default_source_device: plunger
tags: default

switches:
s_trough_1:
number:
Expand Down Expand Up @@ -33,5 +38,4 @@ ball_devices:
ball_switches: s_plunger
debug: true
mechanical_eject: true
tags: ball_add_live
player_controlled_eject_event: sw_launch
Expand Up @@ -3,6 +3,11 @@
game:
balls_per_game: 1

playfields:
playfield:
default_source_device: test_target1
tags: default

coils:
eject_coil1:
number:
Expand Down Expand Up @@ -57,7 +62,6 @@ ball_devices:
eject_coil: eject_coil3
ball_switches: s_ball_switch_target1
debug: true
tags: ball_add_live
confirm_eject_type: target
test_target2:
eject_coil: eject_coil4
Expand Down
Expand Up @@ -6,6 +6,11 @@ coils:
plunger_eject:
number:

playfields:
playfield:
default_source_device: plunger
tags: default

switches:
s_trough_1:
number:
Expand Down Expand Up @@ -42,5 +47,4 @@ ball_devices:
ball_switches: s_plunger
debug: true
mechanical_eject: true
tags: ball_add_live
player_controlled_eject_event: sw_launch
@@ -1,5 +1,10 @@
#config_version=4

playfields:
playfield:
default_source_device: test_launcher
tags: default

coils:
eject_coil1:
number:
Expand Down Expand Up @@ -54,7 +59,6 @@ ball_devices:
eject_targets: playfield, test_target
mechanical_eject: true
confirm_eject_type: target
tags: ball_add_live
test_target:
eject_coil: eject_coil3
ball_switches: s_ball_switch_target
Expand Down
@@ -1,5 +1,10 @@
#config_version=4

playfields:
playfield:
default_source_device: trough
tags: default

coils:
trough_eject:
number:
Expand All @@ -24,4 +29,4 @@ ball_devices:
eject_coil: trough_eject
ball_switches: s_trough_1, s_trough_2, s_trough_3, s_trough_4
debug: true
tags: trough, drain, home, ball_add_live
tags: trough, drain, home
Expand Up @@ -3,6 +3,11 @@
game:
balls_per_game: 1

playfields:
playfield:
default_source_device: test_target1
tags: default

coils:
c_trough1:
number:
Expand Down Expand Up @@ -47,7 +52,6 @@ ball_devices:
test_target1:
eject_coil: c_target1
ball_switches: s_target1
tags: ball_add_live
test_trough2:
eject_coil: c_trough2
ball_switches: s_trough2_1, s_trough2_2
Expand Down
Expand Up @@ -3,6 +3,11 @@
game:
balls_per_game: 1

playfields:
playfield:
default_source_device: test_target1
tags: default

coils:
eject_coil1:
number:
Expand Down Expand Up @@ -59,7 +64,6 @@ ball_devices:
eject_coil: eject_coil3
ball_switches: s_ball_switch_target1
debug: true
tags: ball_add_live
confirm_eject_type: target
test_target2:
eject_coil: eject_coil4
Expand Down
@@ -1,5 +1,10 @@
#config_version=4

playfields:
playfield:
default_source_device: test_launcher
tags: default

coils:
eject_coil1:
number:
Expand All @@ -14,8 +19,6 @@ coils:
c_diverter:
number:



switches:
s_ball_switch1:
number:
Expand Down Expand Up @@ -49,7 +52,6 @@ ball_devices:
eject_timeouts: 6s, 10s
eject_targets: playfield, test_target
confirm_eject_type: target
tags: ball_add_live
player_controlled_eject_event: sw_launch
test_target:
eject_coil: eject_coil3
Expand Down
Expand Up @@ -3,9 +3,15 @@
game:
balls_per_game: 3
allow_start_with_ball_in_drain: True

machine:
min_balls: 3

playfields:
playfield:
default_source_device: plunger
tags: default

coils:
outhole:
number: 1
Expand Down Expand Up @@ -45,7 +51,6 @@ ball_devices:
ball_capacity: 3
debug: true
plunger:
tags: ball_add_live
ball_switches: plunger
mechanical_eject: true
eject_timeouts: 4s
Expand Down
@@ -1,5 +1,10 @@
#config_version=4

playfields:
playfield:
default_source_device: test
tags: default

coils:
hold_coil:
number:
Expand All @@ -10,7 +15,6 @@ coils:
hold_coil4:
number:


switches:
s_entrance:
number:
Expand Down
@@ -1,5 +1,10 @@
#config_version=4

playfields:
playfield:
default_source_device: trough
tags: default

coils:
c_eject:
number:
Expand All @@ -15,5 +20,5 @@ ball_devices:
trough:
eject_coil: c_eject
ball_switches: s_trough
tags: home, trough, drain, ball_add_live
tags: home, trough, drain
debug: True
Expand Up @@ -4,6 +4,11 @@ game:
balls_per_game: 3
allow_start_with_ball_in_drain: True

playfields:
playfield:
default_source_device: plunger
tags: default

coils:
outhole:
number: C09
Expand Down Expand Up @@ -46,9 +51,7 @@ ball_devices:
confirm_eject_type: target
debug: true
plunger:
tags: ball_add_live
ball_switches: plunger
mechanical_eject: true
eject_timeouts: 4s
# ball_missing_timeouts: 1s
debug: true

0 comments on commit 262d870

Please sign in to comment.