Skip to content

Commit d3794fb

Browse files
authored
Merge pull request #338 from alyssaruth/fix-miss-animation
Fix miss animation playing too often
2 parents e00339c + f717971 commit d3794fb

2 files changed

Lines changed: 51 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: 47 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,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

Comments
 (0)