Skip to content

Commit 7e0c80a

Browse files
committed
music and animations for halloween
1 parent dcfef6e commit 7e0c80a

16 files changed

Lines changed: 121 additions & 1 deletion

File tree

‎src/main/kotlin/dartzee/screen/DartsApp.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class DartsApp(commandBar: CheatBar) : AbstractDevScreen(commandBar), WindowList
130130
logger.info(CODE_SWITCHED_SCREEN, "Switched to screen ${scrn.getScreenName()}")
131131

132132
contentPane.remove(this.currentScreen)
133+
this.currentScreen.unInit()
133134

134135
this.currentScreen = scrn
135136
contentPane.add(scrn, BorderLayout.CENTER)

‎src/main/kotlin/dartzee/screen/EmbeddedScreen.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ abstract class EmbeddedScreen : JPanel(), ActionListener {
6161
lblNext.text = getNextText()
6262
}
6363

64+
open fun unInit() {}
65+
6466
open fun getBackTarget(): EmbeddedScreen = ScreenCache.get<MenuScreen>()
6567

6668
override fun actionPerformed(arg0: ActionEvent) {

‎src/main/kotlin/dartzee/screen/MenuScreen.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class MenuScreen : EmbeddedScreen() {
8080
override fun postInit() {
8181
super.postInit()
8282
layoutScreen()
83+
84+
InjectedThings.theme?.menuMusic?.loop()
85+
}
86+
87+
override fun unInit() {
88+
InjectedThings.theme?.menuMusic?.stop()
8389
}
8490

8591
override fun fireAppearancePreferencesChanged() {
@@ -190,6 +196,8 @@ class MenuScreen : EmbeddedScreen() {
190196
}
191197

192198
private fun newGame() {
199+
InjectedThings.theme?.newGameSfx?.playOnce()
200+
193201
if (InjectedThings.partyMode) {
194202
ScreenCache.switch<SimplePlayerSelectionScreen>()
195203
} else {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dartzee.theme
2+
3+
import javax.sound.sampled.AudioInputStream
4+
import javax.sound.sampled.AudioSystem
5+
import javax.sound.sampled.Clip
6+
import javax.sound.sampled.LineEvent
7+
8+
data class AudioClip(private val stream: AudioInputStream) {
9+
init {
10+
stream.mark(Int.MAX_VALUE)
11+
}
12+
13+
private var lastClip: Clip? = null
14+
15+
fun playOnce() {
16+
stop()
17+
18+
stream.reset()
19+
val clip = AudioSystem.getClip()
20+
clip.open(stream)
21+
clip.start()
22+
clip.addLineListener { event ->
23+
if (event.type === LineEvent.Type.STOP) {
24+
clip.stop()
25+
clip.close()
26+
}
27+
}
28+
29+
lastClip = clip
30+
}
31+
32+
fun loop() {
33+
if (lastClip == null) {
34+
val clip = AudioSystem.getClip()
35+
clip.open(stream)
36+
lastClip = clip
37+
}
38+
39+
lastClip?.loop(Clip.LOOP_CONTINUOUSLY)
40+
}
41+
42+
fun stop() {
43+
lastClip?.stop()
44+
}
45+
}

‎src/main/kotlin/dartzee/theme/Theme.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ data class Theme(
2727
val dartboardFont = fontForResource("/theme/$name/dartboard.ttf") ?: font
2828
val banner = svgForResource("/theme/$name/banner.svg")
2929

30+
val menuMusic = clipForResource("/theme/$name/menu.wav")
31+
val newGameSfx = clipForResource("/theme/$name/newGame.wav")
32+
3033
fun apply() {
3134
logger.info(CODE_THEME_APPLIED, "Applying theme $name")
3235

‎src/main/kotlin/dartzee/theme/ThemeUtils.kt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.awt.Font
1010
import java.time.DayOfWeek
1111
import java.time.LocalDate
1212
import java.time.Month
13+
import javax.sound.sampled.AudioSystem
1314
import javax.swing.ImageIcon
1415

1516
fun autoApplyTheme() {
@@ -19,7 +20,7 @@ fun autoApplyTheme() {
1920

2021
fun pickThemeForDate(now: LocalDate): Theme? {
2122
if (DartsClient.devMode) {
22-
return Themes.OKTOBERFEST
23+
return Themes.HALLOWEEN
2324
}
2425

2526
val easterSunday = findEasterSunday(now.year)
@@ -91,6 +92,13 @@ fun fontForResource(resourcePath: String): Font? {
9192
return Font.createFont(Font.TRUETYPE_FONT, fontStream)
9293
}
9394

95+
fun clipForResource(resourcePath: String): AudioClip? {
96+
val stream = Theme::class.java.getResourceAsStream(resourcePath) ?: return null
97+
98+
val audioStream = AudioSystem.getAudioInputStream(stream) ?: return null
99+
return AudioClip(audioStream)
100+
}
101+
94102
fun svgForResource(resourcePath: String): SVGDocument? {
95103
val uri = Theme::class.java.getResource(resourcePath) ?: return null
96104

‎src/main/kotlin/dartzee/theme/Themes.kt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ private val oktoberfestDartboardColours =
5555
)
5656

5757
object Themes {
58+
private val witchAnimation =
59+
CompositeAnimation(
60+
(1..3).map { Animation("witch$it", "/theme/halloween/horrific/witch.png") }
61+
)
62+
63+
private val halloweenAnimations: List<Pair<IAnimationTrigger, IAnimation>> =
64+
GameType.values().flatMap { gameType ->
65+
listOf(
66+
DartScoreTrigger(gameType, 0) to witchAnimation,
67+
DartScoreTrigger(gameType, 50) to
68+
Animation("wolf", "/theme/halloween/horrific/wolf.png"),
69+
DartScoreTrigger(gameType, 25) to
70+
Animation("wolf", "/theme/halloween/horrific/wolf.png"),
71+
)
72+
}
73+
5874
val HALLOWEEN =
5975
Theme(
6076
"halloween",
@@ -65,6 +81,7 @@ object Themes {
6581
linkColour = Color.decode("#009900"),
6682
fontColor = bloodRed,
6783
dartboardColours = halloweenDartboardColours,
84+
animations = halloweenAnimations.toMap(),
6885
)
6986

7087
private val easterAnimations: List<Pair<IAnimationTrigger, IAnimation>> =
137 KB
Loading
237 KB
Loading
3.48 MB
Binary file not shown.

0 commit comments

Comments
 (0)