wordmaker: credit a solution word on submit, not after its flight (#ux-audit)
- Commit
025b0619b9f69dab7f09a658c31af4270ef44f16- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:24 UTC (23 days ago)
- Parents
495dcc2
Symptom (competitive): a word entered in roughly the last 0.8 s did
not count. If it was the last word of the board, the timer expired,
the level was scored as a loss and the player was penalised even
though they had solved it in time.
Root cause: the submit handler only enqueued the letter flight; the
word was credited (actions.addFoundWord) by rememberWordPlaceAnimations
after the 800 ms flight finished. The competitive timer in
WordGameScreen checks foundWords, so it saw the board as unsolved
until the flight landed and timed out first.
Fix:
- wordSubmitHandler credits the word (addFoundWord) at submit, right
after enqueueing the flight; the flight no longer calls
addFoundWord and is purely cosmetic.
- So the grid does not show the letters before they arrive,
CrosswordBoard now takes hiddenWords (every credited word whose
flight has not landed, i.e. the whole solution queue) instead of the
single in-flight word; cells shared with other found words still
show.
- The duplicate check keeps credited words in a pending set until the
found-words flow (a DataStore round-trip in casual/daily) contains
them, replacing the old "flushed after flight" set.
- Bonus words are unchanged (still recorded when their flight lands;
they never affect winning or the competitive score).
User-visible effect: a word counts the instant it is entered; beating
the clock by a fraction of a second now wins the level. In casual
play the "Next Level" button can appear while the last word's letters
are still flying in; the flight finishes over it.
Verification: new FinalSecondCreditTest spells CAT in competitive
mode with the frame clock paused and checks addFoundWord("CAT") has
happened within 5 frames of Submit (it used to take 800 ms) and no
timeout fired. submissionHandlerDecisionTable now asserts the credit
happens in the handler; placeAnimationsDrainQueues asserts the flight
no longer credits.Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.ktindex c477847519..800b532e60 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerUiContract.kt@@ -57,9 +57,9 @@ interface WordGameActions { fun onCompetitiveTimeout() {} /**- * A solution word was just traced. Separate from [addFoundWord] because the word only- * counts once its letters have flown into the grid, but the achievement fires straight- * away — and achievements belong to the activity, not the ViewModel.+ * A solution word was just traced (and credited through [addFoundWord] in the same step;+ * its letter flight into the grid is cosmetic). Separate from [addFoundWord] because+ * achievements belong to the activity, not the ViewModel. */ fun onSolutionWordFound(word: String) {}
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 8d44aaf4ad..9a579f3f6c 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@@ -207,7 +207,7 @@ fun WordGameScreen( foundWords = foundWords, revealedHints = revealedHints, crosswordData = crosswordData,- wordToAnimate = wordPlaceAnimations.activeSolutionWord,+ hiddenWords = wordPlaceAnimations.flyingSolutionWords, onCellPositioned = { position, offset -> if (crosswordCellPositions[position] != offset) { crosswordCellPositions =
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 422aded048..26cb32dabf 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@@ -55,7 +55,11 @@ fun wordSubmitHandler( j.join() } isSolution && word !in foundWords -> {+ // Credit the word now; the letter flight is cosmetic. Crediting it only when the+ // 800 ms flight landed let the competitive timer run out first, so a word entered in+ // the last ~0.8 s did not count and the player lost points. onAnimateSolution(WordToAnimate(word, ids))+ actions.addFoundWord(word) actions.onSolutionWordFound(word) } // #807: only enqueue — the screen drains the bonus queue one flight at a
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 b4c57fb93e..99e6115541 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@@ -28,12 +28,15 @@ import kotlinx.coroutines.launch * Live state of the queued word-place flights, drained by [rememberWordPlaceAnimations]. */ class WordPlaceAnimations(- /** Solution words accepted but not yet visible in the found-words flow. */+ /**+ * Solution words already credited but possibly not yet visible in the found-words flow+ * (a DataStore round-trip), for the duplicate check.+ */ val pendingSolutionWords: Set<String>, /** Bonus words accepted but not yet visible in the bonus-words flow. */ val queuedBonusWords: Set<String>,- /** Solution word currently flying into the grid, for the board's hide-while-flying slot. */- val activeSolutionWord: String?,+ /** Credited solution words whose letters have not landed yet; the board hides them. */+ val flyingSolutionWords: Set<String>, /** Bonus word currently flying toward the bonus button. */ val activeBonusWord: String?, val bonusProgress: Animatable<Float, AnimationVector1D>,@@ -45,8 +48,10 @@ class WordPlaceAnimations( /** * FIFO word-place flights for the letter wheel (#807), extracted from [WordGameScreen] * 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 (which used to drop- * the first word's grid/bonus credit entirely).+ * 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. */ @Composable fun rememberWordPlaceAnimations(@@ -60,8 +65,7 @@ fun rememberWordPlaceAnimations( crosswordCellPositions: Map<Pair<Int, Int>, Offset>, ): WordPlaceAnimations { var solutionQueue by remember(levelKey) { mutableStateOf<List<WordToAnimate>>(emptyList()) }- var activeSolutionWord by remember(levelKey) { mutableStateOf<String?>(null) }- var flushedSolutions by remember(levelKey) { mutableStateOf<Set<String>>(emptySet()) }+ var awaitingFlow by remember(levelKey) { mutableStateOf<Set<String>>(emptySet()) } var bonusQueue by remember(levelKey) { mutableStateOf<List<String>>(emptyList()) } var activeBonusWord by remember(levelKey) { mutableStateOf<String?>(null) } val bonusProgress = remember(levelKey) { Animatable(0f) }@@ -78,7 +82,6 @@ fun rememberWordPlaceAnimations( solutionQueue = solutionQueue.drop(1) return@LaunchedEffect }- activeSolutionWord = word val letters = word.mapIndexed { index, char -> val id = animationInfo.letterIds[index] val start = (letterChooserPositions[id] ?: Offset.Zero) - rootOffset@@ -89,17 +92,14 @@ fun rememberWordPlaceAnimations( } animatedLetters = letters letters.map { launch { it.progress.animateTo(1f, tween(LETTER_FLIGHT_MILLIS)) } }.joinAll()- actions.addFoundWord(word) animatedLetters = emptyList()- activeSolutionWord = null- flushedSolutions = flushedSolutions + word solutionQueue = solutionQueue.drop(1) } - // A finished flight takes a DataStore round-trip to show up in the found-words flow;+ // A credited word takes a DataStore round-trip to show up in the found-words flow; // keep it in the dedup set until then so re-entering it shakes instead of replaying. LaunchedEffect(foundWords) {- if (flushedSolutions.isNotEmpty()) flushedSolutions = flushedSolutions - foundWords+ if (awaitingFlow.isNotEmpty()) awaitingFlow = awaitingFlow - foundWords } // Bonus flights share one progress Animatable, so they fly one at a time too: a fast@@ -115,13 +115,16 @@ fun rememberWordPlaceAnimations( } return WordPlaceAnimations(- pendingSolutionWords = (solutionQueue.map { it.word } + flushedSolutions).toSet(),+ pendingSolutionWords = (solutionQueue.map { it.word } + awaitingFlow).toSet(), queuedBonusWords = bonusQueue.toSet(),- activeSolutionWord = activeSolutionWord,+ flyingSolutionWords = solutionQueue.mapTo(mutableSetOf()) { it.word }, activeBonusWord = activeBonusWord, bonusProgress = bonusProgress, animatedLetters = animatedLetters,- enqueueSolution = { solutionQueue = solutionQueue + it },+ enqueueSolution = {+ solutionQueue = solutionQueue + it+ awaitingFlow = awaitingFlow + it.word+ }, enqueueBonus = { bonusQueue = bonusQueue + it }, ) }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.ktindex 00520e4433..5f5da3d69f 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/CrosswordBoard.kt@@ -38,7 +38,8 @@ fun CrosswordBoard( foundWords: Set<String>, revealedHints: Set<Pair<Int, Int>>, crosswordData: CrosswordData,- wordToAnimate: String?,+ /** Found words to leave blank for now: their letters are still flying in. */+ hiddenWords: Set<String>, onCellPositioned: (position: Pair<Int, Int>, offset: Offset) -> Unit, onCellClicked: (row: Int, col: Int) -> Unit, scaleUpdated: (Float) -> Unit@@ -46,7 +47,7 @@ fun CrosswordBoard( val allCharPositions = mutableMapOf<Pair<Int, Int>, Char>() crosswordData.letterPositions.forEach { (word, occurrences) -> for (positions in occurrences) {- val isFound = word in foundWords && word != wordToAnimate+ val isFound = word in foundWords && word !in hiddenWords word.forEachIndexed { index, char -> val pos = positions[index] if (isFound || (pos in revealedHints && pos !in allCharPositions)) {
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/FinalSecondCreditTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/FinalSecondCreditTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/FinalSecondCreditTest.ktnew file mode 100644index 0000000000..ce7602fc56--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/FinalSecondCreditTest.kt@@ -0,0 +1,60 @@+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.data.GameMode+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+import kotlin.test.assertFalse++/**+ * A competitive word entered with under a second left must count: it is credited when it is+ * submitted, not when its 800 ms letter flight lands.+ */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w411dp-h891dp")+class FinalSecondCreditTest {+ @get:Rule val rule = createComposeRule()++ @Test fun competitiveWordIsCreditedOnSubmitNotWhenItsFlightLands() {+ val credited = mutableListOf<String>()+ var timedOut = false+ val actions = object : WordGameActions {+ override fun addFoundWord(word: String) { credited += word }+ override fun onCompetitiveTimeout() { timedOut = true }+ }+ val state = WordGameUiState(+ crosswordData = CrosswordData.fromString("CAT\n C \n T ")!!,+ tapToSpell = true,+ gameMode = GameMode.COMPETITIVE,+ competitiveLevelNumber = 1,+ // A running timer, far enough out that a slow test machine cannot hit it: what+ // matters is that the credit lands within frames of the submit, well inside the+ // 800 ms the flight takes (the window in which the timer used to win).+ competitiveDeadline = System.currentTimeMillis() + 60_000,+ )+ rule.setContent {+ DynamicTheme { WordGameScreen(state = state, actions = actions, onOpenGameCenter = {}, onOpenSettings = {}) }+ }+ rule.onNodeWithText("C").performClick()+ rule.onNodeWithText("A").performClick()+ rule.onNodeWithText("T").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("CAT"), credited)+ assertFalse(timedOut)+ }+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/LargeFontTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/LargeFontTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/LargeFontTest.ktindex 361bcba234..577c6c3bd1 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/LargeFontTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/LargeFontTest.kt@@ -85,7 +85,7 @@ class LargeFontTest { setAtDoubleFont { CrosswordBoard( foundWords = setOf("CAT"), revealedHints = emptySet(),- crosswordData = CrosswordData.fromString("CAT\n C \n T ")!!, wordToAnimate = null,+ crosswordData = CrosswordData.fromString("CAT\n C \n T ")!!, hiddenWords = emptySet(), onCellPositioned = { _, _ -> }, onCellClicked = { _, _ -> }, scaleUpdated = {}, ) }
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 fe85a09594..2aaaa11ab3 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@@ -193,7 +193,7 @@ class WordMakerComposeTest { rule.setContent { DynamicTheme { CrosswordBoard(- foundWords = setOf("CAT"), revealedHints = setOf(2 to 1), crosswordData = board(), wordToAnimate = null,+ foundWords = setOf("CAT"), revealedHints = setOf(2 to 1), crosswordData = board(), hiddenWords = emptySet(), onCellPositioned = { _, _ -> }, onCellClicked = { r, c -> clicked = r to c }, scaleUpdated = {}, ) }@@ -206,7 +206,7 @@ class WordMakerComposeTest { rule.setContent { DynamicTheme { CrosswordBoard(- foundWords = setOf("CAT"), revealedHints = emptySet(), crosswordData = board(), wordToAnimate = "CAT",+ foundWords = setOf("CAT"), revealedHints = emptySet(), crosswordData = board(), hiddenWords = setOf("CAT"), onCellPositioned = { _, _ -> }, onCellClicked = { _, _ -> }, scaleUpdated = {}, ) }@@ -366,6 +366,8 @@ class WordMakerComposeTest { ) runBlocking { withContext(frameClock) { with(CoroutineScope(Dispatchers.Unconfined + frameClock)) { handler("CAT", listOf(0, 1, 2)) } } } assertEquals("CAT", solution); assertEquals("CAT", solutionCallback)+ // 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" } val handler2 = wordSubmitHandler(@@ -430,7 +432,9 @@ class WordMakerComposeTest { } rule.runOnUiThread { anims!!.enqueueSolution(com.vayunmathur.games.wordmaker.ui.components.WordToAnimate("CAT", listOf(0, 1, 2))) } rule.waitForIdle()- assertEquals("CAT", added)+ // the solution flight is cosmetic: the submit handler already credited the word+ assertEquals(null, added)+ assertTrue(anims!!.flyingSolutionWords.isEmpty()) rule.runOnUiThread { anims!!.enqueueBonus("DOG") } rule.waitForIdle() assertEquals("DOG", bonusAdded)