@@ -4,6 +4,7 @@ import com.github.alyssaburlton.swingtest.clickChild
44import com.github.alyssaburlton.swingtest.clickNo
55import com.github.alyssaburlton.swingtest.clickYes
66import com.github.alyssaburlton.swingtest.findChild
7+ import com.github.alyssaburlton.swingtest.flushEdt
78import com.github.alyssaburlton.swingtest.getChild
89import com.github.alyssaburlton.swingtest.purgeWindows
910import com.github.alyssaburlton.swingtest.shouldBeVisible
@@ -30,6 +31,9 @@ import dartzee.helper.retrieveAchievementsForPlayer
3031import dartzee.`object`.ComputedPoint
3132import dartzee.`object`.Dart
3233import dartzee.only
34+ import dartzee.screen.animation.BAD_MISS
35+ import dartzee.screen.animation.DartScoreTrigger
36+ import dartzee.screen.animation.MISS_DEV
3337import dartzee.screen.game.scorer.AchievementOverlay
3438import dartzee.screen.game.scorer.DartsScorerX01
3539import dartzee.screen.game.x01.GameStatisticsPanelX01
@@ -40,6 +44,7 @@ import io.kotest.matchers.nulls.shouldBeNull
4044import io.kotest.matchers.nulls.shouldNotBeNull
4145import io.kotest.matchers.shouldBe
4246import javax.swing.JButton
47+ import javax.swing.JLabel
4348import org.junit.jupiter.api.Test
4449
4550class TestDartsGamePanel : AbstractTest () {
@@ -259,6 +264,45 @@ class TestDartsGamePanel : AbstractTest() {
259264 panel.dartboard.findChild<DartLabel >() shouldBe null
260265 }
261266
267+ @Test
268+ fun `Should only play miss animation if allowed` () {
269+ InjectedThings .animations = mapOf (DartScoreTrigger (GameType .X01 , 0 ) to BAD_MISS )
270+
271+ val panel = TestGamePanel (animateMiss = false )
272+ val pt = makeSingleParticipant(insertPlayer(strategy = " " ), panel.gameEntity.rowId)
273+ panel.startNewGame(listOf (pt))
274+
275+ panel.dartThrown(Dart (20 , 0 ))
276+ flushEdt()
277+ panel.findChild<JLabel >(" DodgyLabel" ) shouldBe null
278+
279+ panel.animateMiss = true
280+ panel.dartThrown(Dart (20 , 0 ))
281+ flushEdt()
282+ panel.getChild<JLabel >(" DodgyLabel" ).shouldBeVisible()
283+ }
284+
285+ @Test
286+ fun `Should trigger animation for the right score and game type` () {
287+ InjectedThings .animations =
288+ mapOf (
289+ DartScoreTrigger (GameType .X01 , 5 ) to BAD_MISS ,
290+ DartScoreTrigger (GameType .GOLF , 10 ) to MISS_DEV ,
291+ )
292+
293+ val panel = TestGamePanel (animateMiss = true )
294+ val pt = makeSingleParticipant(insertPlayer(strategy = " " ), panel.gameEntity.rowId)
295+ panel.startNewGame(listOf (pt))
296+
297+ panel.dartThrown(Dart (10 , 1 ))
298+ flushEdt()
299+ panel.findChild<JLabel >(" DodgyLabel" ) shouldBe null
300+
301+ panel.dartThrown(Dart (5 , 1 ))
302+ flushEdt()
303+ panel.getChild<JLabel >(" DodgyLabel" ).shouldBeVisible()
304+ }
305+
262306 private fun TestGamePanel.clickResign () =
263307 clickChild<JButton >(async = true ) { it.toolTipText == " Resign" }
264308
@@ -272,6 +316,7 @@ class TestDartsGamePanel : AbstractTest() {
272316 class TestGamePanel (
273317 private val config : X01Config = X01Config (501, FinishType .Doubles ),
274318 totalPlayers : Int = 1 ,
319+ var animateMiss : Boolean = false ,
275320 ) :
276321 GamePanelPausable <DartsScorerX01 , X01PlayerState >(
277322 FakeDartsScreen (),
@@ -293,5 +338,7 @@ class TestDartsGamePanel : AbstractTest() {
293338
294339 override fun factoryScorer (participant : IWrappedParticipant ) =
295340 DartsScorerX01 (this , config.target, participant)
341+
342+ override fun shouldAnimateMiss (dart : Dart ) = animateMiss
296343 }
297344}
0 commit comments