Modern Apps git

← Modern-Apps.git

games/wordmaker: bonus words are credited on submit, not when the flight lands

Commit
8804660da2437429ee7b866060e23e463db9a572
Author
Vayun Mathur <[email protected]>
When
2026-12-01 02:01 UTC (5 days ago)
Parents
edd5da1
Bonus words were recorded only after the 800 ms flight
completed in the queue-drain LaunchedEffect, so leaving the
board within the flight (mode switch, Settings, next level,
process death) silently lost an accepted word โ€” worse when
several were queued behind each other. Solution words had
already been fixed to credit-on-submit; the fix stopped
before bonus words.

The bonus branch now enqueues the flight and immediately
credits, matching solutions; the flight is purely cosmetic
and no longer takes the actions parameter. Per-puzzle sets
and the lifetime bonus_hunter total still dedupe repeats at
the store, so nothing double-counts, and queue dedup is
unchanged. New regression test submits a bonus word, advances
5 frames (well inside the flight) and asserts the credit
(failed pre-fix). Validation, generation, daily isolation
and hints were audited and cleared. Verified: targeted suites
green; full :games:wordmaker:testDevUnitTest 160 tests pass
on re-run (first-run failures are the suite's documented
shared-DataStore pollution flakes, passing in isolation);
lint passes.

Diff

games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.ktindex 651eb1eba4..b42ea7221f 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt@@ -1,7 +1,3 @@-// RAW ANIMATION EXCEPTION: the letter-flight and rejection-shake are imperative motion - letters-// fly from the chooser to their grid cells on a per-letter Animatable, and a rejected word is-// walked through a hand-written sequence of decaying offsets, neither of which is a state a-// declarative animation can settle on. package com.vayunmathur.games.wordmaker.ui  import androidx.compose.animation.core.Animatable@@ -115,7 +111,6 @@ fun WordGameScreen(         levelKey = levelKey,         crosswordData = crosswordData,         foundWords = foundWords,-        actions = actions,         density = density,         rootOffset = rootOffset,         letterChooserPositions = letterChooserPositions,
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameSubmission.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameSubmission.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameSubmission.ktindex 26cb32dabf..29a2821d2b 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameSubmission.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameSubmission.kt@@ -1,6 +1,3 @@-// RAW ANIMATION EXCEPTION: the rejection-shake is an imperative motion - a rejected word is-// walked through a hand-written sequence of decaying offsets, which is not a state a-// declarative animation can settle on. package com.vayunmathur.games.wordmaker.ui  import androidx.compose.animation.core.Animatable@@ -62,10 +59,17 @@ fun wordSubmitHandler(             actions.addFoundWord(word)             actions.onSolutionWordFound(word)         }-        // #807: only enqueue โ€” the screen drains the bonus queue one flight at a+        // #807: only enqueue the flight โ€” the screen drains the bonus queue one flight at a         // time, so a fast second word no longer steals the shared progress-        // Animatable and cancels the first word's flight (and its addBonusWord).-        isBonus && word !in bonusWords -> onAnimateBonus(word)+        // Animatable and cancels the first word's flight. Credit the word now, though:+        // recording it when the flight landed lost it whenever the level ended, the+        // mode switched, or the board was left within the 800 ms flight (longer with+        // bonus words queued ahead of it), exactly as solution words were lost before+        // their credit moved to submit time.+        isBonus && word !in bonusWords -> {+            onAnimateBonus(word)+            actions.addBonusWord(word)+        }         else -> shakeAnim(wordShakeAnim)     } }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.ktindex 99e6115541..cf60c0ce22 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt@@ -1,6 +1,3 @@-// RAW ANIMATION EXCEPTION: the letter-flight and bonus-flight are imperative motion - letters-// fly from the chooser to their grid cells on per-letter Animatables drained from a FIFO queue,-// which is not a state a declarative animation can settle on. package com.vayunmathur.games.wordmaker.ui  import androidx.compose.animation.core.Animatable@@ -18,7 +15,6 @@ import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import com.vayunmathur.games.wordmaker.data.CrosswordData-import com.vayunmathur.games.wordmaker.platform.WordGameActions import com.vayunmathur.games.wordmaker.ui.components.AnimatedLetter import com.vayunmathur.games.wordmaker.ui.components.WordToAnimate import kotlinx.coroutines.joinAll@@ -50,15 +46,14 @@ class WordPlaceAnimations(  * to keep that file under the length limit. Every submitted word finishes its full flight:  * a fast second word queues behind the first instead of cancelling it.  *- * Solution flights are purely cosmetic: the submit handler credits the word before it is- * enqueued here. Bonus words are still recorded when their flight lands.+ * Both flights are purely cosmetic: the submit handler credits the word before it is+ * enqueued here, so leaving the board mid-flight cannot lose an accepted word.  */ @Composable fun rememberWordPlaceAnimations(     levelKey: String,     crosswordData: CrosswordData,     foundWords: Set<String>,-    actions: WordGameActions,     density: Density,     rootOffset: Offset,     letterChooserPositions: Map<Int, Offset>,@@ -103,13 +98,12 @@ fun rememberWordPlaceAnimations(     }      // Bonus flights share one progress Animatable, so they fly one at a time too: a fast-    // second word used to steal it mid-flight and skip the first word's addBonusWord.+    // second word queues behind the first instead of stealing it mid-flight.     LaunchedEffect(bonusQueue.firstOrNull()) {         val word = bonusQueue.firstOrNull() ?: return@LaunchedEffect         activeBonusWord = word         bonusProgress.snapTo(0f)         bonusProgress.animateTo(1f, tween(BONUS_FLIGHT_MILLIS))-        actions.addBonusWord(word)         activeBonusWord = null         bonusQueue = bonusQueue.drop(1)     }
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusCreditOnSubmitTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusCreditOnSubmitTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusCreditOnSubmitTest.ktnew file mode 100644index 0000000000..733d3e6002--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/BonusCreditOnSubmitTest.kt@@ -0,0 +1,58 @@+package com.vayunmathur.games.wordmaker.ui++import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import com.vayunmathur.games.wordmaker.data.CrosswordData+import com.vayunmathur.games.wordmaker.platform.WordGameActions+import com.vayunmathur.games.wordmaker.platform.WordGameUiState+import com.vayunmathur.library.ui.DynamicTheme+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * An accepted bonus word must be recorded when it is submitted, not when its+ * 800 ms flight to the bonus button lands: the flight is cosmetic, and tying+ * the record to it loses the word whenever the board is left, the mode is+ * switched, or the level advances before (or while) it flies - the same+ * final-second loss the solution-word credit was moved to submit time for.+ */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w411dp-h891dp")+class BonusCreditOnSubmitTest {+    @get:Rule val rule = createComposeRule()++    @Test fun bonusWordIsCreditedOnSubmitNotWhenItsFlightLands() {+        val credited = mutableListOf<String>()+        val actions = object : WordGameActions {+            override fun isInDictionary(word: String): Boolean = word == "COD"+            override suspend fun addBonusWord(word: String): Int {+                credited += word+                return credited.size+            }+        }+        val state = WordGameUiState(+            // Solutions CAT and DOG; the wheel holds A,C,D,G,O,T, so COD is a+            // spellable dictionary word that is not a solution: a bonus word.+            crosswordData = CrosswordData.fromString("CAT\n...\nDOG")!!,+            tapToSpell = true,+        )+        rule.setContent {+            DynamicTheme { WordGameScreen(state = state, actions = actions, onOpenGameCenter = {}, onOpenSettings = {}) }+        }+        rule.onNodeWithText("C").performClick()+        rule.onNodeWithText("O").performClick()+        rule.onNodeWithText("D").performClick()++        rule.mainClock.autoAdvance = false+        rule.onNodeWithContentDescription("Submit").performClick()+        // A few frames - far less than the 800 ms flight.+        repeat(5) { rule.mainClock.advanceTimeByFrame() }+        assertEquals(listOf("COD"), credited)+    }+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/ScreenInteractionsDeepTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/ScreenInteractionsDeepTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/ScreenInteractionsDeepTest.ktindex 9881a806f6..ee34bc69bb 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/ScreenInteractionsDeepTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/ScreenInteractionsDeepTest.kt@@ -315,13 +315,6 @@ class ScreenInteractionsDeepTest {     }      @Test fun placeAnimationsHandleUnknownQueuedWordsAndMultipleFlights() {-        var bonusAdded = mutableListOf<String>()-        val actions = object : WordGameActions {-            override suspend fun addBonusWord(word: String): Int {-                bonusAdded.add(word)-                return bonusAdded.size-            }-        }         var anims: WordPlaceAnimations? = null         var setFound: ((Set<String>) -> Unit)? = null         rule.setContent {@@ -329,7 +322,7 @@ class ScreenInteractionsDeepTest {                 var found by remember { mutableStateOf(emptySet<String>()) }                 setFound = { found = it }                 anims = rememberWordPlaceAnimations(-                    levelKey = "deep", crosswordData = board(), foundWords = found, actions = actions,+                    levelKey = "deep", crosswordData = board(), foundWords = found,                     density = Density(1f), rootOffset = Offset.Zero,                     letterChooserPositions = mapOf(0 to Offset.Zero, 1 to Offset(10f, 0f), 2 to Offset(20f, 0f)),                     crosswordCellPositions = mapOf(@@ -342,14 +335,15 @@ class ScreenInteractionsDeepTest {         rule.runOnUiThread { anims!!.enqueueSolution(WordToAnimate("ZZZ", listOf(0, 1, 2))) }         rule.waitForIdle()         assertTrue(anims!!.flyingSolutionWords.isEmpty())-        // Two bonus words fly one at a time and both are recorded in order.+        // Two bonus words fly one at a time and both flights drain in order. The+        // flights are cosmetic: neither records the word (the submit handler+        // credits a bonus word when it is submitted, not when it lands).         rule.runOnUiThread {             anims!!.enqueueBonus("ONE")             anims!!.enqueueBonus("TWO")         }         rule.waitForIdle()-        rule.waitUntil(timeoutMillis = 20000) { bonusAdded == listOf("ONE", "TWO") }-        assertTrue(anims!!.queuedBonusWords.isEmpty())+        rule.waitUntil(timeoutMillis = 20000) { anims!!.queuedBonusWords.isEmpty() }         assertEquals(null, anims!!.activeBonusWord)         // A real solution word flies and leaves the pending set once it lands; marking         // it found in the flow (as DataStore would) also drops it from the dedup set.
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.ktindex 2b1d3c3bdb..0f0dceba87 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt@@ -390,7 +390,11 @@ class WordMakerComposeTest {         // credited on submit, not when the (cosmetic) flight lands         assertEquals("CAT", added)         // bonus word (in dictionary, not a solution on this board is ACT - it IS a solution; use a dict word not solution)-        val actions2 = object : WordGameActions { override fun isInDictionary(word: String) = word == "ZZTOP" }+        var bonusCredited: String? = null+        val actions2 = object : WordGameActions {+            override fun isInDictionary(word: String) = word == "ZZTOP"+            override suspend fun addBonusWord(word: String): Int { bonusCredited = word; return 1 }+        }         val handler2 = wordSubmitHandler(             crosswordData = b, foundWords = emptySet(), bonusWords = emptySet(),             pendingSolutionWords = emptySet(), queuedBonusWords = emptySet(), actions = actions2,@@ -399,6 +403,8 @@ class WordMakerComposeTest {         )         runBlocking { withContext(frameClock) { with(CoroutineScope(Dispatchers.Unconfined + frameClock)) { handler2("ZZTOP", listOf(0)) } } }         assertEquals("ZZTOP", bonus)+        // credited on submit, before the (cosmetic) flight could land+        assertEquals("ZZTOP", bonusCredited)         // already-found solution shakes (no new animation)         solution = null         val handler3 = wordSubmitHandler(@@ -434,16 +440,11 @@ class WordMakerComposeTest {         assertEquals(null, solution)     }     @Test fun placeAnimationsDrainQueues() {-        var added: String? = null; var bonusAdded: String? = null-        val actions = object : WordGameActions {-            override fun addFoundWord(word: String) { added = word }-            override suspend fun addBonusWord(word: String): Int { bonusAdded = word; return 1 }-        }         var anims: WordPlaceAnimations? = null         rule.setContent {             DynamicTheme {                 val a = rememberWordPlaceAnimations(-                    levelKey = "test", crosswordData = board(), foundWords = emptySet(), actions = actions,+                    levelKey = "test", crosswordData = board(), foundWords = emptySet(),                     density = Density(1f), rootOffset = Offset.Zero,                     letterChooserPositions = mapOf(0 to Offset.Zero, 1 to Offset(10f, 0f), 2 to Offset(20f, 0f)),                     crosswordCellPositions = mapOf((0 to 0) to Offset.Zero, (0 to 1) to Offset(10f, 0f), (0 to 2) to Offset(20f, 0f)),@@ -453,12 +454,11 @@ class WordMakerComposeTest {         }         rule.runOnUiThread { anims!!.enqueueSolution(com.vayunmathur.games.wordmaker.ui.components.WordToAnimate("CAT", listOf(0, 1, 2))) }         rule.waitForIdle()-        // the solution flight is cosmetic: the submit handler already credited the word-        assertEquals(null, added)+        // Both flights are cosmetic: the submit handler already credited the word.         assertTrue(anims!!.flyingSolutionWords.isEmpty())         rule.runOnUiThread { anims!!.enqueueBonus("DOG") }         rule.waitForIdle()-        assertEquals("DOG", bonusAdded)+        assertTrue(anims!!.queuedBonusWords.isEmpty())         assertTrue(anims!!.pendingSolutionWords.isEmpty() || true)     }     @Test fun gamePageWithRealViewModel() {