Skip to content

Commit 7a00238

Browse files
committed
fix: Trigger game-over haptic only once
1 parent 98fc3b3 commit 7a00238

5 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/src/main/java/app/morphe/manager/ui/screen/patcher/game/DinoGame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class DinoGameState(
206206

207207
@Composable
208208
fun DinoGame(state: DinoGameState) {
209-
GameOverHaptic(state.isGameOver)
209+
GameOverHaptic { state.isGameOver }
210210
LaunchedEffect(Unit) {
211211
while (isActive) {
212212
withFrameMillis { state.tick(it) }

app/src/main/java/app/morphe/manager/ui/screen/patcher/game/FlappyGame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class FlappyGameState(
140140

141141
@Composable
142142
fun FlappyBirdGame(state: FlappyGameState) {
143-
GameOverHaptic(state.isGameOver)
143+
GameOverHaptic { state.isGameOver }
144144
// Runs every vsync; tick() is a no-op when the game is paused or over
145145
LaunchedEffect(Unit) {
146146
while (isActive) {

app/src/main/java/app/morphe/manager/ui/screen/patcher/game/Game2048.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private val TileGap = 8.dp
165165

166166
@Composable
167167
fun Game2048Board(state: Game2048State) {
168-
GameOverHaptic(state.isGameOver)
168+
GameOverHaptic { state.isGameOver }
169169
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
170170
BoardGrid(state = state, size = maxWidth)
171171
if (state.hasWon && !state.isGameOver) {

app/src/main/java/app/morphe/manager/ui/screen/patcher/game/MiniGameConfig.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,17 @@ internal fun GamePauseOverlay(onResume: () -> Unit, modifier: Modifier = Modifie
401401

402402
/** Fires a double-buzz haptic pattern once when [isGameOver] transitions to `true`. */
403403
@Composable
404-
internal fun GameOverHaptic(isGameOver: Boolean) {
404+
internal fun GameOverHaptic(isGameOver: () -> Boolean) {
405405
val context = LocalContext.current
406-
LaunchedEffect(isGameOver) {
407-
if (!isGameOver) return@LaunchedEffect
408-
val vibrator = context.getSystemService(Vibrator::class.java) ?: return@LaunchedEffect
409-
vibrator.vibrate(VibrationEffect.createWaveform(longArrayOf(0, 80, 50, 80), -1))
406+
LaunchedEffect(Unit) {
407+
var seenFalse = false
408+
snapshotFlow(isGameOver).collect { current ->
409+
if (!current) {
410+
seenFalse = true
411+
} else if (seenFalse) {
412+
val vibrator = context.getSystemService(Vibrator::class.java) ?: return@collect
413+
vibrator.vibrate(VibrationEffect.createWaveform(longArrayOf(0, 80, 50, 80), -1))
414+
}
415+
}
410416
}
411417
}

app/src/main/java/app/morphe/manager/ui/screen/patcher/game/SnakeGame.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ enum class SnakeDir {
116116

117117
@Composable
118118
fun SnakeGame(state: SnakeGameState) {
119-
GameOverHaptic(state.isGameOver)
119+
GameOverHaptic { state.isGameOver }
120120
LaunchedEffect(Unit) {
121121
while (isActive) {
122122
delay(state.tickMs)

0 commit comments

Comments
 (0)