From 292898091e6140ab94c92ecfe1b30b878105b7f9 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 21 Dec 2024 00:48:13 -0800 Subject: [PATCH] feat: add new placeholder mode and test qualification --- config/common/ball_devices.yaml | 15 +++--- config/common/modes.yaml | 1 + config/common/variables.yaml | 10 ++-- modes/attract/code/attract.py | 31 ------------ modes/attract/config/attract.yaml | 3 -- modes/{attract => base}/code/__init__.py | 0 modes/base/code/base.py | 8 ++++ modes/base/config/base.yaml | 22 +++++---- modes/green_flag/config/green_flag.yaml | 13 +++++ modes/grooveline/config/grooveline.yaml | 7 +++ tests/death_save.py | 17 +++++++ tests/death_save_game_testing.py | 6 +++ tests/test_green_flag_mode.py | 17 ------- tests/test_grooveline_mode.py | 60 ++++++++++++++++++++++++ 14 files changed, 136 insertions(+), 74 deletions(-) delete mode 100644 modes/attract/code/attract.py rename modes/{attract => base}/code/__init__.py (100%) create mode 100644 modes/base/code/base.py create mode 100644 modes/grooveline/config/grooveline.yaml create mode 100644 tests/test_grooveline_mode.py diff --git a/config/common/ball_devices.yaml b/config/common/ball_devices.yaml index 22b6494..eac15f3 100644 --- a/config/common/ball_devices.yaml +++ b/config/common/ball_devices.yaml @@ -2,20 +2,21 @@ ball_devices: bd_trough: - tags: - - trough - - home - - drain ball_switches: - s_trough1 - s_trough2 - s_trough3 - jam_switch: s_trough_jam + tags: + - trough + - home + - drain + auto_fire_on_unexpected_ball: false + debug: true eject_coil: c_trough_eject + eject_coil_jam_pulse: 15ms eject_targets: bd_shooter_lane eject_timeouts: 1s - eject_coil_jam_pulse: 15ms - debug: true + jam_switch: s_trough_jam bd_shooter_lane: ball_switches: s_shooter_lane mechanical_eject: true diff --git a/config/common/modes.yaml b/config/common/modes.yaml index 6e272e4..552339d 100644 --- a/config/common/modes.yaml +++ b/config/common/modes.yaml @@ -3,3 +3,4 @@ modes: - base - green_flag +- grooveline diff --git a/config/common/variables.yaml b/config/common/variables.yaml index bd334a9..bcaf7af 100644 --- a/config/common/variables.yaml +++ b/config/common/variables.yaml @@ -1,16 +1,14 @@ #config_version=6 -# NOTE: this is only for machine-wide variables. Put -# player-specific variables in modes player_vars: level_green_flag: initial_value: 0 - # 2 is full, - # 1 is half + # 2 is full + # 1 is partial # 0 is empty level_fuel: - # player begins game with empty tank - initial_value: 0 + # player begins game with partially empty tank + initial_value: 1 level_oil: initial_value: 2 level_tires: diff --git a/modes/attract/code/attract.py b/modes/attract/code/attract.py deleted file mode 100644 index c225cc7..0000000 --- a/modes/attract/code/attract.py +++ /dev/null @@ -1,31 +0,0 @@ -from mpf.core.mode import Mode -from objprint import op -import time - -class Attract(Mode): - - # def mode_init(self): - # pass - - def mode_start(self, **kwargs): - # self.machine.lights.l_backbox_match_00.color('white') - # for each of the lights - while True: - for light in self.machine.lights.values(): - time.sleep(0.333333) - op(light.get_color()) - # turn the light off - # if light.color() == 'white': - # light.color('black') - # else: - # light.color('white') - - # Set a delay to call self.my_callback() in 5 seconds - # self.delay.add(5000, self.my_callback) - - # # turn LED "led01" red - # op(self.machine.lights) - # self.machine.leds.led01.color('red') - - # def mode_stop(self, **kwargs): - # pass diff --git a/modes/attract/config/attract.yaml b/modes/attract/config/attract.yaml index bc2f512..aeef2de 100644 --- a/modes/attract/config/attract.yaml +++ b/modes/attract/config/attract.yaml @@ -1,8 +1,5 @@ #config_version=6 -# mode: -# code: attract.Attract - slide_player: mode_attract_started: attract_slide: diff --git a/modes/attract/code/__init__.py b/modes/base/code/__init__.py similarity index 100% rename from modes/attract/code/__init__.py rename to modes/base/code/__init__.py diff --git a/modes/base/code/base.py b/modes/base/code/base.py new file mode 100644 index 0000000..e6f69db --- /dev/null +++ b/modes/base/code/base.py @@ -0,0 +1,8 @@ +from mpf.core.mode import Mode + +class Base(Mode): + + def mode_start(self, **kwargs): + player = self.machine.game.player + if player.is_player_var('grooveline_counter_count'): + self.machine.counters['grooveline_counter'].reset() diff --git a/modes/base/config/base.yaml b/modes/base/config/base.yaml index b2fb794..275aa53 100644 --- a/modes/base/config/base.yaml +++ b/modes/base/config/base.yaml @@ -3,6 +3,7 @@ mode: start_events: ball_starting priority: 50 + code: base.Base ball_saves: ball_start_ball_save: @@ -89,23 +90,24 @@ variable_player: s_outlane2_active: score: 50 -# To activate "green_flag" mode, the user's vehicle -# must be ready to race: + ##################### + ## Per-ball resets ## + ##################### + ball_will_end: + grooveline_counter_count: + action: set + int: 0 + + event_player: - # Top up her fuel every time (Qualifier1) + # To activate "green_flag" mode, the user's vehicle + # must be ready to race: s_qualifier1_active: - green_flag{current_player.level_green_flag==0} - # - green_flag_fuel_reset - # Change oil after putting some miles on her (Qualifier2) logicblock_seq_green_flag2_complete: - green_flag{current_player.level_green_flag==1} - # She's going to need some tires, now (Qualifier3) logicblock_seq_green_flag3_complete: - green_flag - # s_qualifier2_active: - # # - green_flag_oil_reset - # s_qualifier3_active: - # # - green_flag_tires_reset sequences: seq_green_flag2: diff --git a/modes/green_flag/config/green_flag.yaml b/modes/green_flag/config/green_flag.yaml index cee5fba..5145ab8 100644 --- a/modes/green_flag/config/green_flag.yaml +++ b/modes/green_flag/config/green_flag.yaml @@ -39,6 +39,15 @@ counters: # TODO: maybe consider having a ceiling # where the "race is completed" #count_complete_value: 100 + grooveline_counter: + count_events: logicblock_seq_lap_complete + starting_count: 0 + count_interval: 1 + count_complete_value: 10 + # keep state between mode changes but will + # reset on ball end per base mode + persist_state: true + debug: true # Every 3 laps, a random event will occur random_event_player: @@ -77,6 +86,10 @@ variable_player: lap_counter_count: int: value action: set + logicblock_grooveline_counter_updated: + grooveline_counter_count: + int: value + action: set degrade_fuel: level_fuel: action: add diff --git a/modes/grooveline/config/grooveline.yaml b/modes/grooveline/config/grooveline.yaml new file mode 100644 index 0000000..8b3ea98 --- /dev/null +++ b/modes/grooveline/config/grooveline.yaml @@ -0,0 +1,7 @@ +#config_version=6 + +mode: + start_events: + - logicblock_grooveline_counter_complete + restart_on_next_ball: false + priority: 100 diff --git a/tests/death_save.py b/tests/death_save.py index 2a09826..5671f8c 100644 --- a/tests/death_save.py +++ b/tests/death_save.py @@ -39,3 +39,20 @@ def _start(self): self.hit_and_release_switch("s_shooter_lane") self.advance_time_and_run(4) self.assertEqual(1, self.machine.playfield.balls) + +def _start_green_flag(self): + self._start() + # Player must "fill up" to start racing + self.assertEqual( + 1, self.machine.game.player.level_fuel) + self.assertEqual(1, self.machine.playfield.balls) + + # Hitting the first qualifier fills up the tank + self.hit_and_release_switch("s_qualifier1") + self.advance_time_and_run(1) + self.assertModeRunning("green_flag") + +def _complete_lap(self): + self.hit_and_release_switch("s_spinner") + self.hit_and_release_switch("s_grooveline") + self.advance_time_and_run(1) diff --git a/tests/death_save_game_testing.py b/tests/death_save_game_testing.py index 6eff41f..19099b9 100644 --- a/tests/death_save_game_testing.py +++ b/tests/death_save_game_testing.py @@ -9,3 +9,9 @@ def _assertIncrement(self, var, switch, value): def _start(self): death_save._start(self) + + def _start_green_flag(self): + death_save._start_green_flag(self) + + def _complete_lap(self): + death_save._complete_lap(self) diff --git a/tests/test_green_flag_mode.py b/tests/test_green_flag_mode.py index 8bdb71e..d24b78d 100644 --- a/tests/test_green_flag_mode.py +++ b/tests/test_green_flag_mode.py @@ -175,20 +175,3 @@ def test_random_bad_luck_event(self): self.assertFalse( self.machine.flippers["right_flipper"]._enabled ) - - def _start_green_flag(self): - self._start() - # Player must "fill up" to start racing - self.assertEqual( - 0, self.machine.game.player.level_fuel) - self.assertEqual(1, self.machine.playfield.balls) - - # Hitting the first qualifier fills up the tank - self.hit_and_release_switch("s_qualifier1") - self.advance_time_and_run(1) - self.assertModeRunning("green_flag") - - def _complete_lap(self): - self.hit_and_release_switch("s_spinner") - self.hit_and_release_switch("s_grooveline") - self.advance_time_and_run(1) diff --git a/tests/test_grooveline_mode.py b/tests/test_grooveline_mode.py new file mode 100644 index 0000000..cd140ca --- /dev/null +++ b/tests/test_grooveline_mode.py @@ -0,0 +1,60 @@ +from tests.death_save_game_testing import DeathSaveGameTesting + +class TestGroovelineMode(DeathSaveGameTesting): + + def test_qualification(self): + self._start_green_flag() + + self.hit_and_release_switch("s_spinner") + self.hit_and_release_switch("s_grooveline") + self.assertEqual( + 1, self.machine.game.player.grooveline_counter_count) + + self.machine.events.post("degrade_oil") + self.machine.events.post("degrade_oil") + self.advance_time_and_run(1) + + self.assertModeNotRunning("green_flag") + + # Count doesn't increase outside of green_flag mode + self.hit_and_release_switch("s_spinner") + self.hit_and_release_switch("s_grooveline") + self.assertEqual( + 1, self.machine.game.player.grooveline_counter_count) + + # Player tops up the oil, reactivating green_flag mode + self.hit_and_release_switch("s_qualifier2") + self.advance_time_and_run(1) + self.assertModeRunning("green_flag") + # Grooveline counter still at 1 as its value is + # persisted for a single ball + self.assertEqual( + 1, self.machine.game.player.grooveline_counter_count) + self.assertEqual(1, self.machine.game.player.ball) + + # ball drains and ball 2 begins + for i in range(2): + self.hit_switch_and_run("s_trough1", 4) + self.hit_and_release_switch("s_shooter_lane") + + self.assertModeRunning("base") + + # Green flag mode resumes + self.assertModeRunning("green_flag") + self.assertEqual(2, self.machine.game.player.ball) + # Grooveline counter is reset to 0 + self.assertEqual( + 0, self.machine.game.player.grooveline_counter_count) + + # Players hits the grooveline 10 times (10 laps) + for i in range(10): + # mock the event, so we avoid the random events + self.machine.events. \ + post("logicblock_seq_lap_complete") + self.advance_time_and_run(1) + + # Counter resets + self.assertEqual( + 0, self.machine.game.player.grooveline_counter_count) + # And grooveline mode begins (multiball) + self.assertModeRunning("grooveline")