Skip to content

Commit 8629c54

Browse files
committed
fix miss animation playing too often
1 parent e00339c commit 8629c54

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎src/main/kotlin/dartzee/screen/game/DartsGamePanel.kt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,10 @@ abstract class DartsGamePanel<
479479
}
480480

481481
private fun doAnimations(dart: Dart) {
482-
if (dart.multiplier == 0 && shouldAnimateMiss(dart)) {
483-
dartboard.doDodgy(DartScoreTrigger(gameEntity.gameType, 0))
482+
if (dart.multiplier == 0) {
483+
if (shouldAnimateMiss(dart)) {
484+
dartboard.doDodgy(DartScoreTrigger(gameEntity.gameType, 0))
485+
}
484486
} else {
485487
dartboard.doDodgy(DartScoreTrigger(gameEntity.gameType, dart.getTotal()))
486488
}

‎src/test/kotlin/dartzee/screen/game/TestDartsGamePanel.kt‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.github.alyssaburlton.swingtest.clickChild
44
import com.github.alyssaburlton.swingtest.clickNo
55
import com.github.alyssaburlton.swingtest.clickYes
66
import com.github.alyssaburlton.swingtest.findChild
7+
import com.github.alyssaburlton.swingtest.flushEdt
78
import com.github.alyssaburlton.swingtest.getChild
89
import com.github.alyssaburlton.swingtest.purgeWindows
910
import com.github.alyssaburlton.swingtest.shouldBeVisible
@@ -30,6 +31,9 @@ import dartzee.helper.retrieveAchievementsForPlayer
3031
import dartzee.`object`.ComputedPoint
3132
import dartzee.`object`.Dart
3233
import dartzee.only
34+
import dartzee.screen.animation.BAD_MISS
35+
import dartzee.screen.animation.DartScoreTrigger
36+
import dartzee.screen.animation.MISS_DEV
3337
import dartzee.screen.game.scorer.AchievementOverlay
3438
import dartzee.screen.game.scorer.DartsScorerX01
3539
import dartzee.screen.game.x01.GameStatisticsPanelX01
@@ -40,6 +44,7 @@ import io.kotest.matchers.nulls.shouldBeNull
4044
import io.kotest.matchers.nulls.shouldNotBeNull
4145
import io.kotest.matchers.shouldBe
4246
import javax.swing.JButton
47+
import javax.swing.JLabel
4348
import org.junit.jupiter.api.Test
4449

4550
class TestDartsGamePanel : AbstractTest() {
@@ -259,6 +264,46 @@ 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 = false)
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.animateMiss = true
302+
panel.dartThrown(Dart(5, 1))
303+
flushEdt()
304+
panel.getChild<JLabel>("DodgyLabel").shouldBeVisible()
305+
}
306+
262307
private fun TestGamePanel.clickResign() =
263308
clickChild<JButton>(async = true) { it.toolTipText == "Resign" }
264309

@@ -272,6 +317,7 @@ class TestDartsGamePanel : AbstractTest() {
272317
class TestGamePanel(
273318
private val config: X01Config = X01Config(501, FinishType.Doubles),
274319
totalPlayers: Int = 1,
320+
var animateMiss: Boolean = false,
275321
) :
276322
GamePanelPausable<DartsScorerX01, X01PlayerState>(
277323
FakeDartsScreen(),
@@ -293,5 +339,7 @@ class TestDartsGamePanel : AbstractTest() {
293339

294340
override fun factoryScorer(participant: IWrappedParticipant) =
295341
DartsScorerX01(this, config.target, participant)
342+
343+
override fun shouldAnimateMiss(dart: Dart) = animateMiss
296344
}
297345
}

0 commit comments

Comments
 (0)