Skip to content

Commit 7dd058f

Browse files
Merge branch 'missionpinball:dev' into dev
2 parents ae93e49 + 7a96651 commit 7dd058f

File tree

12 files changed

+104
-37
lines changed

12 files changed

+104
-37
lines changed

mpf/modes/bonus/code/bonus.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ def _bonus_next_item(self):
9191
self._subtotal()
9292
return
9393

94-
# Calling player.vars.get() instead of player.get() bypasses the
95-
# auto-fill zero and will throw if there is no player variable.
96-
# The fallback value of 1 is used for bonus entries that don't use
97-
# a player score, which are multiplied by one to get the bonus.
98-
hits = self.player.vars.get(entry['player_score_entry'], 1)
94+
# If a player_score_entry is provided, use player getattr to get a
95+
# fallback value of zero if the variable is not set. Otherwise
96+
# use 1 as the multiplier for non-player-score bonuses.
97+
hits = self.player[entry['player_score_entry']] if entry['player_score_entry'] else 1
9998
score = entry['score'].evaluate([]) * hits
10099

101100
if (not score and entry['skip_if_zero']) or (score < 0 and entry['skip_if_negative']):

mpf/modes/high_score/code/high_score.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ async def _run(self) -> None:
196196
# ask player for initials if we do not know them
197197
if not player.initials:
198198
try:
199-
player.initials = await self._ask_player_for_initials(player, award_names[i], value, category_name)
199+
player.initials = await self._ask_player_for_initials(player, award_names[i],
200+
value, category_name)
200201
except asyncio.TimeoutError:
201202
del new_list[i]
202203
# no entry when the player missed the timeout

mpf/platforms/fast/communicators/net_neuron.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def update_switches_from_hw_data(self):
293293
This will silently sync the switch.hw_state. If the logical state changes,
294294
it will process it like any switch change.
295295
"""
296-
for switch in self.machine.switches:
296+
for switch in self.machine.switches.values():
297297
hw_state = self.platform.hw_switch_data[switch.hw_switch.number]
298298

299299
if hw_state != switch.hw_state:

mpf/platforms/fast/fast_exp_board.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
from base64 import b16decode
5+
from binascii import Error as binasciiError
56
from importlib import import_module
67

78
from packaging import version
@@ -176,7 +177,7 @@ def update_leds(self):
176177

177178
try:
178179
self.communicator.send_bytes(b16decode(f'{msg_header}{msg}'), log_msg)
179-
except Exception as e:
180+
except binasciiError as e:
180181
self.log.error(
181182
f"Error decoding the following message for board {breakout_address} : {msg_header}{msg}")
182183
self.log.info("Attempted update that caused this error: %s", dirty_leds)

mpf/platforms/virtual.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ async def get_hw_switch_states(self):
105105

106106
if 'virtual_platform_start_active_switches' in self.machine.config:
107107
initial_active_switches = []
108-
for switch in Util.string_to_list(self.machine.config['virtual_platform_start_active_switches']):
109-
if switch not in self.machine.switches:
110-
if " " in switch:
108+
for switch_name in Util.string_to_list(self.machine.config['virtual_platform_start_active_switches']):
109+
if switch_name not in self.machine.switches.keys():
110+
if " " in switch_name:
111111
self.raise_config_error("MPF no longer supports lists separated by space in "
112112
"virtual_platform_start_active_switches. Please separate "
113-
"switches by comma: {}.".format(switch), 1)
113+
"switches by comma: {}.".format(switch_name), 1)
114114
else:
115115
self.raise_config_error("Switch {} used in virtual_platform_start_active_switches was not "
116-
"found in switches section.".format(switch), 1)
117-
initial_active_switches.append(self.machine.switches[switch].hw_switch.number)
116+
"found in switches section.".format(switch_name), 1)
117+
initial_active_switches.append(self.machine.switches[switch_name].hw_switch.number)
118118

119119
for k in self.hw_switches:
120120
if k in initial_active_switches:

mpf/plugins/platform_integration_test_runner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ async def move_ball_from_drain_to_trough(self, **kwargs):
227227
drain_switches = self.machine.ball_devices.items_tagged('drain')[0].config.get('ball_switches')
228228
self.info_log("Found drain switches: %s of type %s", drain_switches, type(drain_switches))
229229
# If there's only one drain switch it might be a single value, rather than a list
230-
drain_switch = drain_switches if type(drain_switches) is str else drain_switches[-1]
230+
drain_switch = drain_switches if isinstance(drain_switches, str) else drain_switches[-1]
231231
self.info_log("Setting drain switch '%s' to zero", drain_switch)
232232
self.set_switch_sync(drain_switch, 0)
233233
await asyncio.sleep(0.25)

mpf/tests/machine_files/bonus/modes/bonus/config/bonus.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ mode_settings:
1212
score: 5000
1313
player_score_entry: modes
1414
reset_player_score_entry: False
15+
- event: bonus_undefined_var
16+
score: 5000
17+
skip_if_zero: false
18+
player_score_entry: undefined_var
19+
- event: bonus_static
20+
score: 2000

mpf/tests/machine_files/shots/config/test_shot_groups.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ switches:
1212
number:
1313
switch_4:
1414
number:
15+
switch_5:
16+
number:
17+
switch_6:
18+
number:
1519
s_rotate_l:
1620
number:
1721
s_rotate_r:

mpf/tests/machine_files/shots/modes/base2/config/base2.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ shots:
2020
light: tag1
2121
shot_4:
2222
switch: switch_1
23+
shot_5:
24+
switch: switch_5
25+
shot_6:
26+
switch: switch_6
2327
led_1:
2428
switch: switch_1
2529
show_tokens:

mpf/tests/machine_files/shots/modes/mode1/config/mode1.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ shots:
2424
mode1_shot_3:
2525
switch: switch_3
2626
profile: mode1_shot_3
27+
mode1_shot_5:
28+
switch: switch_5
29+
profile: mode1_shot_5
30+
mode1_shot_6:
31+
switch: switch_6
32+
profile: mode1_shot_6
2733

2834
shot_profiles:
2935
mode1_shot_2:
@@ -32,10 +38,21 @@ shot_profiles:
3238
- name: mode1_one
3339
- name: mode1_two
3440
- name: mode1_three
35-
mode1_shot_3:
41+
mode1_shot_3: # Test block: True
3642
show: rainbow2
3743
block: True
3844
states:
3945
- name: mode1_one
4046
- name: mode1_two
4147
- name: mode1_three
48+
mode1_shot_5: # Test block: False
49+
show: rainbow2
50+
block: False
51+
states:
52+
- name: mode1_one
53+
- name: mode1_two
54+
mode1_shot_6: # Test block default
55+
show: rainbow2
56+
states:
57+
- name: mode1_one
58+
- name: mode1_two

mpf/tests/test_Bonus.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def test_slam_tilt_in_service(self):
3838
def testBonus(self):
3939
self.mock_event("bonus_ramps")
4040
self.mock_event("bonus_modes")
41+
self.mock_event("bonus_undefined_var")
42+
self.mock_event("bonus_static")
4143
self.mock_event("bonus_subtotal")
4244
self.mock_event("bonus_multiplier")
4345
self.mock_event("bonus_total")
@@ -78,10 +80,14 @@ def testBonus(self):
7880
self.assertEqual(3, self._last_event_kwargs["bonus_ramps"]["hits"])
7981
self.assertEqual(10000, self._last_event_kwargs["bonus_modes"]["score"])
8082
self.assertEqual(2, self._last_event_kwargs["bonus_modes"]["hits"])
81-
self.assertEqual(13000, self._last_event_kwargs["bonus_subtotal"]["score"])
83+
self.assertEqual(0, self._last_event_kwargs["bonus_undefined_var"]["score"])
84+
self.assertEqual(0, self._last_event_kwargs["bonus_undefined_var"]["hits"])
85+
self.assertEqual(2000, self._last_event_kwargs["bonus_static"]["score"])
86+
self.assertEqual(1, self._last_event_kwargs["bonus_static"]["hits"])
87+
self.assertEqual(15000, self._last_event_kwargs["bonus_subtotal"]["score"])
8288
self.assertEqual(5, self._last_event_kwargs["bonus_multiplier"]["multiplier"])
83-
self.assertEqual(65000, self._last_event_kwargs["bonus_total"]["score"])
84-
self.assertEqual(66337, self.machine.game.player.score)
89+
self.assertEqual(75000, self._last_event_kwargs["bonus_total"]["score"])
90+
self.assertEqual(76337, self.machine.game.player.score)
8591

8692
# check resets
8793
self.assertEqual(0, self.machine.game.player.ramps)
@@ -102,10 +108,10 @@ def testBonus(self):
102108
self.assertEqual(0, self._last_event_kwargs["bonus_ramps"]["hits"])
103109
self.assertEqual(10000, self._last_event_kwargs["bonus_modes"]["score"])
104110
self.assertEqual(2, self._last_event_kwargs["bonus_modes"]["hits"])
105-
self.assertEqual(10000, self._last_event_kwargs["bonus_subtotal"]["score"])
111+
self.assertEqual(12000, self._last_event_kwargs["bonus_subtotal"]["score"])
106112
self.assertEqual(5, self._last_event_kwargs["bonus_multiplier"]["multiplier"])
107-
self.assertEqual(50000, self._last_event_kwargs["bonus_total"]["score"])
108-
self.assertEqual(116337, self.machine.game.player.score)
113+
self.assertEqual(60000, self._last_event_kwargs["bonus_total"]["score"])
114+
self.assertEqual(136337, self.machine.game.player.score)
109115

110116
# multiplier should stay the same
111117
self.assertEqual(0, self.machine.game.player.ramps)
@@ -128,6 +134,8 @@ def testBonus(self):
128134
self.mock_event("bonus_start")
129135
self.mock_event("bonus_ramps")
130136
self.mock_event("bonus_modes")
137+
self.mock_event("bonus_undefined_var")
138+
self.mock_event("bonus_static")
131139
self.mock_event("bonus_subtotal")
132140
self.mock_event("bonus_multiplier")
133141
self.mock_event("bonus_total")
@@ -157,6 +165,18 @@ def testBonus(self):
157165
self.assertEventNotCalled('bonus_multiplier')
158166
self.assertEventNotCalled('bonus_total')
159167

168+
self.advance_time_and_run(.5)
169+
self.assertEventCalled('bonus_undefined_var')
170+
self.assertEventNotCalled('bonus_subtotal')
171+
self.assertEventNotCalled('bonus_multiplier')
172+
self.assertEventNotCalled('bonus_total')
173+
174+
self.advance_time_and_run(.5)
175+
self.assertEventCalled('bonus_static')
176+
self.assertEventNotCalled('bonus_subtotal')
177+
self.assertEventNotCalled('bonus_multiplier')
178+
self.assertEventNotCalled('bonus_total')
179+
160180
self.advance_time_and_run(.5)
161181
self.assertEventCalled('bonus_subtotal')
162182
self.assertEventNotCalled('bonus_multiplier')

mpf/tests/test_Shots.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,51 @@ def stop_game(self):
2929
self.advance_time_and_run()
3030
self.assertIsNone(self.machine.game)
3131

32-
def test_block(self):
32+
def block_test(self, switch, shot, should_block):
33+
high_priority_shot = "mode1_" + shot
3334
self.mock_event("playfield_active")
34-
self.hit_and_release_switch("switch_3")
35+
self.hit_and_release_switch(switch)
3536
self.advance_time_and_run(.1)
3637
self.assertEventCalled("playfield_active")
3738

3839
self.start_game()
39-
self.assertEqual("unlit", self.machine.shots["shot_3"].state_name)
40+
self.assertEqual("unlit", self.machine.shots[shot].state_name)
4041

41-
self.hit_and_release_switch("switch_3")
42+
self.hit_and_release_switch(switch)
4243
self.advance_time_and_run(.1)
43-
self.assertTrue(self.machine.shots["shot_3"].enabled)
44-
self.assertEqual("lit", self.machine.shots["shot_3"].state_name)
44+
self.assertFalse(self.machine.shots[high_priority_shot].enabled)
45+
self.assertTrue(self.machine.shots[shot].enabled)
46+
self.assertEqual("lit", self.machine.shots[shot].state_name)
4547

46-
self.machine.shots["shot_3"].reset()
47-
self.assertEqual("unlit", self.machine.shots["shot_3"].state_name)
48+
self.machine.shots[shot].reset()
49+
self.assertEqual("unlit", self.machine.shots[shot].state_name)
4850

4951
# Start the mode and make sure those shots load
5052
self.start_mode("mode1")
5153

52-
self.assertTrue(self.machine.shots["shot_3"].enabled)
53-
self.assertTrue(self.machine.shots["mode1_shot_3"].enabled)
54-
self.assertEqual("unlit", self.machine.shots["shot_3"].state_name)
55-
self.assertEqual("mode1_one", self.machine.shots["mode1_shot_3"].state_name)
54+
self.assertTrue(self.machine.shots[shot].enabled)
55+
self.assertTrue(self.machine.shots[high_priority_shot].enabled)
56+
self.assertEqual("unlit", self.machine.shots[shot].state_name)
57+
self.assertEqual("mode1_one", self.machine.shots[high_priority_shot].state_name)
5658

57-
self.hit_and_release_switch("switch_3")
59+
self.hit_and_release_switch(switch)
5860
self.advance_time_and_run(.1)
5961

60-
self.assertEqual("unlit", self.machine.shots["shot_3"].state_name)
61-
self.assertEqual("mode1_two", self.machine.shots["mode1_shot_3"].state_name)
62+
if should_block:
63+
self.assertEqual("unlit", self.machine.shots[shot].state_name)
64+
else:
65+
self.assertEqual("lit", self.machine.shots[shot].state_name)
66+
67+
self.assertEqual("mode1_two", self.machine.shots[high_priority_shot].state_name)
68+
69+
def test_block_true(self):
70+
self.block_test("switch_3", "shot_3", True)
71+
72+
def test_block_false(self):
73+
self.block_test("switch_5", "shot_5", False)
74+
75+
def test_block_default(self): #Default behaves as false
76+
self.block_test("switch_6", "shot_6", False)
6277

6378
def test_loading_shots(self):
6479
# Make sure machine-wide shots load & mode-specific shots do not

0 commit comments

Comments
 (0)