Skip to content

Commit

Permalink
feat: add new placeholder mode and test qualification
Browse files Browse the repository at this point in the history
  • Loading branch information
unRARed committed Dec 21, 2024
1 parent 033df5a commit 2928980
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 74 deletions.
15 changes: 8 additions & 7 deletions config/common/ball_devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/common/modes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
modes:
- base
- green_flag
- grooveline
10 changes: 4 additions & 6 deletions config/common/variables.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
31 changes: 0 additions & 31 deletions modes/attract/code/attract.py

This file was deleted.

3 changes: 0 additions & 3 deletions modes/attract/config/attract.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#config_version=6

# mode:
# code: attract.Attract

slide_player:
mode_attract_started:
attract_slide:
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions modes/base/code/base.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 12 additions & 10 deletions modes/base/config/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mode:
start_events: ball_starting
priority: 50
code: base.Base

ball_saves:
ball_start_ball_save:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions modes/green_flag/config/green_flag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions modes/grooveline/config/grooveline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#config_version=6

mode:
start_events:
- logicblock_grooveline_counter_complete
restart_on_next_ball: false
priority: 100
17 changes: 17 additions & 0 deletions tests/death_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions tests/death_save_game_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 0 additions & 17 deletions tests/test_green_flag_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
60 changes: 60 additions & 0 deletions tests/test_grooveline_mode.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 2928980

Please sign in to comment.