Modern Apps git

← Modern-Apps.git

wordmaker: add a letter wheel spacing setting (#569)

Commit
645b0f8543f2fa9b0d046f9ffa413a3a43024761
Author
vayun-mathur <[email protected]>
When
2026-09-07 04:02 UTC (3 months ago)
Parents
d43331e

Diff

games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.ktindex acef1d6466..1c555e7e3d 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/LevelDataStore.kt@@ -24,6 +24,7 @@ class LevelDataStore(context: Context) {         private val BONUS_WORDS_KEY = stringSetPreferencesKey("bonus_words")         private val TOTAL_BONUS_WORDS_KEY = intPreferencesKey("total_bonus_words")         private val TAP_TO_SPELL_KEY = booleanPreferencesKey("tap_to_spell")+        private val WHEEL_SPACING_KEY = stringPreferencesKey("wheel_spacing")         private val REVEALED_HINTS_KEY = stringSetPreferencesKey("revealed_hints")         private val GAME_MODE_KEY = stringPreferencesKey("game_mode")         private val DIFFICULTY_KEY = stringPreferencesKey("competitive_difficulty")@@ -52,6 +53,11 @@ class LevelDataStore(context: Context) {      val tapToSpell: Flow<Boolean> = appContext.dataStore.data.map { it[TAP_TO_SPELL_KEY] ?: false } +    val wheelSpacing: Flow<WheelSpacing> = appContext.dataStore.data.map { prefs ->+        prefs[WHEEL_SPACING_KEY]?.let { runCatching { WheelSpacing.valueOf(it) }.getOrNull() }+            ?: WheelSpacing.DEFAULT+    }+     val gameMode: Flow<GameMode> = appContext.dataStore.data.map { prefs ->         prefs[GAME_MODE_KEY]?.let { runCatching { GameMode.valueOf(it) }.getOrNull() } ?: GameMode.CASUAL     }@@ -117,6 +123,10 @@ class LevelDataStore(context: Context) {         appContext.dataStore.edit { it[TAP_TO_SPELL_KEY] = enabled }     } +    suspend fun setWheelSpacing(spacing: WheelSpacing) {+        appContext.dataStore.edit { it[WHEEL_SPACING_KEY] = spacing.name }+    }+     suspend fun setGameMode(mode: GameMode) {         appContext.dataStore.edit { it[GAME_MODE_KEY] = mode.name }     }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/WheelSpacing.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/WheelSpacing.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/WheelSpacing.ktnew file mode 100644index 0000000000..a0e24111b4--- /dev/null+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/data/WheelSpacing.kt@@ -0,0 +1,22 @@+package com.vayunmathur.games.wordmaker.data++import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp++/**+ * How far apart the letters sit on the wheel.+ *+ * Letter tiles are a fixed 70.dp, so at [DEFAULT] an 8-letter puzzle leaves only about 65.dp+ * between neighbouring centres — the tiles touch and the trace lines between them are hard to+ * see and to aim at (#569). Widening the ring is what buys the gap back, so the setting scales+ * the ring radius (and the box that has to hold it) rather than shrinking the letters.+ */+enum class WheelSpacing(val ringRadius: Dp) {+    DEFAULT(85.dp),+    WIDE(100.dp),+    WIDER(115.dp),+    WIDEST(130.dp);++    /** Side of the square the wheel occupies: the ring plus a tile's worth of margin. */+    val boxSize: Dp get() = ringRadius * 2 + 80.dp+}
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 b2a089ce36..c477847519 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@@ -3,6 +3,7 @@ package com.vayunmathur.games.wordmaker.platform import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.data.Difficulty import com.vayunmathur.games.wordmaker.data.GameMode+import com.vayunmathur.games.wordmaker.data.WheelSpacing  /**  * The UI contract between [WordMakerViewModel] and the screens.@@ -20,6 +21,7 @@ data class WordGameUiState(     val foundWords: Set<String> = emptySet(),     val bonusWords: Set<String> = emptySet(),     val tapToSpell: Boolean = false,+    val wheelSpacing: WheelSpacing = WheelSpacing.DEFAULT,     val revealedHints: Set<Pair<Int, Int>> = emptySet(),     /** Epoch millis until which the hint button stays disabled; 0 means available now. */     val hintCooldownEnd: Long = 0L,@@ -83,6 +85,7 @@ interface CompetitiveLobbyActions { /** What the settings screen draws. */ data class SettingsUiState(     val tapToSpell: Boolean = false,+    val wheelSpacing: WheelSpacing = WheelSpacing.DEFAULT,     val reminderEnabled: Boolean = false,     val reminderHour: Int = 20,     val reminderMinute: Int = 0,@@ -91,6 +94,7 @@ data class SettingsUiState( /** Settings callbacks. Same no-op-default arrangement as [WordGameActions]. */ interface SettingsActions {     fun setTapToSpell(enabled: Boolean) {}+    fun setWheelSpacing(spacing: WheelSpacing) {}     fun setReminderEnabled(enabled: Boolean) {}     fun setReminderTime(hour: Int, minute: Int) {} 
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.ktindex 8e73011ff7..27161757f7 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/platform/WordMakerViewModel.kt@@ -9,6 +9,7 @@ import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.data.Difficulty import com.vayunmathur.games.wordmaker.data.GameMode import com.vayunmathur.games.wordmaker.data.LevelDataStore+import com.vayunmathur.games.wordmaker.data.WheelSpacing import com.vayunmathur.games.wordmaker.domain.CompetitiveLevelGenerator import com.vayunmathur.games.wordmaker.domain.Dictionary import com.vayunmathur.library.util.DailyChallengeStore@@ -53,6 +54,9 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio     val tapToSpell: StateFlow<Boolean> = levelDataStore.tapToSpell         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false) +    val wheelSpacing: StateFlow<WheelSpacing> = levelDataStore.wheelSpacing+        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), WheelSpacing.DEFAULT)+     private val reminderSettings = DailyReminderSettings(application, DAILY_KEY_PREFIX)      val reminderEnabled: StateFlow<Boolean> = reminderSettings.enabled@@ -353,6 +357,10 @@ class WordMakerViewModel(application: Application) : AndroidViewModel(applicatio         viewModelScope.launch { levelDataStore.setTapToSpell(enabled) }     } +    fun setWheelSpacing(spacing: WheelSpacing) {+        viewModelScope.launch { levelDataStore.setWheelSpacing(spacing) }+    }+     fun setReminderEnabled(enabled: Boolean) {         viewModelScope.launch {             reminderSettings.setEnabled(enabled)
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.ktindex 4ef7c17541..d0635b7220 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/SettingsPage.kt@@ -7,6 +7,7 @@ import com.vayunmathur.library.ui.DailyReminderSettingsSection import com.vayunmathur.library.ui.DetailScaffold import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.SettingsSection+import com.vayunmathur.library.ui.SettingsSelectRow import com.vayunmathur.library.ui.SettingsSwitchRow import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.rememberPermissionRequest@@ -15,6 +16,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.res.stringResource import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.data.WheelSpacing import com.vayunmathur.games.wordmaker.platform.SettingsActions import com.vayunmathur.games.wordmaker.platform.SettingsUiState import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel@@ -23,6 +25,7 @@ import com.vayunmathur.games.wordmaker.platform.WordMakerViewModel @Composable fun SettingsPage(viewModel: WordMakerViewModel, onBack: () -> Unit) {     val tapToSpell by viewModel.tapToSpell.collectAsState()+    val wheelSpacing by viewModel.wheelSpacing.collectAsState()     val reminderEnabled by viewModel.reminderEnabled.collectAsState()     val reminderMinutes by viewModel.reminderMinutesOfDay.collectAsState() @@ -31,6 +34,7 @@ fun SettingsPage(viewModel: WordMakerViewModel, onBack: () -> Unit) {     SettingsScreen(         state = SettingsUiState(             tapToSpell = tapToSpell,+            wheelSpacing = wheelSpacing,             reminderEnabled = reminderEnabled,             reminderHour = (reminderMinutes / 60).toInt(),             reminderMinute = (reminderMinutes % 60).toInt(),@@ -38,6 +42,8 @@ fun SettingsPage(viewModel: WordMakerViewModel, onBack: () -> Unit) {         actions = object : SettingsActions {             override fun setTapToSpell(enabled: Boolean) = viewModel.setTapToSpell(enabled) +            override fun setWheelSpacing(spacing: WheelSpacing) = viewModel.setWheelSpacing(spacing)+             override fun setReminderEnabled(enabled: Boolean) {                 // Asked for lazily, on opt-in only, so the screen never blocks on a prompt.                 if (enabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {@@ -72,6 +78,21 @@ fun SettingsScreen(state: SettingsUiState, actions: SettingsActions, onBack: ()                 checked = state.tapToSpell,                 onCheckedChange = { actions.setTapToSpell(it) },             )+            // Pre-resolved because SettingsSelectRow's `label` is a plain lambda, not a+            // composable one, so stringResource cannot be called inside it.+            val spacingLabels = mapOf(+                WheelSpacing.DEFAULT to stringResource(R.string.wheel_spacing_default),+                WheelSpacing.WIDE to stringResource(R.string.wheel_spacing_wide),+                WheelSpacing.WIDER to stringResource(R.string.wheel_spacing_wider),+                WheelSpacing.WIDEST to stringResource(R.string.wheel_spacing_widest),+            )+            SettingsSelectRow(+                title = stringResource(R.string.wheel_spacing),+                selected = state.wheelSpacing,+                options = WheelSpacing.entries,+                label = { spacingLabels.getValue(it) },+                onSelect = { actions.setWheelSpacing(it) },+            )         }         DailyReminderSettingsSection(             enabled = state.reminderEnabled,
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.ktindex b749e322a5..3401647f20 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGamePage.kt@@ -24,6 +24,7 @@ fun WordGamePage(     val foundWords by viewModel.foundWords.collectAsState()     val bonusWords by viewModel.bonusWords.collectAsState()     val tapToSpell by viewModel.tapToSpell.collectAsState()+    val wheelSpacing by viewModel.wheelSpacing.collectAsState()     val revealedHints by viewModel.revealedHints.collectAsState()     val hintCooldownEnd by viewModel.hintCooldownEnd.collectAsState()     val gameMode by viewModel.gameMode.collectAsState()@@ -87,6 +88,7 @@ fun WordGamePage(             foundWords = foundWords,             bonusWords = bonusWords,             tapToSpell = tapToSpell,+            wheelSpacing = wheelSpacing,             revealedHints = revealedHints,             hintCooldownEnd = hintCooldownEnd,             gameMode = gameMode,
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 5527f74cc1..4fec54d849 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@@ -82,6 +82,9 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch +/** Room above the wheel for the formed-word box and its padding. */+private val WHEEL_HEADROOM = 70.dp+ @Composable fun WordGameScreen(     state: WordGameUiState,@@ -94,6 +97,7 @@ fun WordGameScreen(     val foundWords = state.foundWords     val bonusWords = state.bonusWords     val tapToSpell = state.tapToSpell+    val wheelSpacing = state.wheelSpacing     val revealedHints = state.revealedHints     val hintCooldownEnd = state.hintCooldownEnd     val gameMode = state.gameMode@@ -234,11 +238,12 @@ fun WordGameScreen(                 }         ) {             // Puzzle board occupies the space above the letter wheel so it stays-            // vertically centred there. The wheel below is 320.dp tall.+            // vertically centred there. The wheel below reserves its own height.+            val wheelHeight = wheelSpacing.boxSize + WHEEL_HEADROOM             Box(                 modifier = Modifier                     .fillMaxSize()-                    .padding(bottom = 320.dp),+                    .padding(bottom = wheelHeight),                 contentAlignment = Alignment.Center             ) {                 CrosswordBoard(@@ -276,7 +281,7 @@ fun WordGameScreen(                 }                 Spacer(modifier = Modifier.weight(1f))                 Box(-                    modifier = Modifier.height(320.dp),+                    modifier = Modifier.height(wheelHeight),                     contentAlignment = Alignment.Center                 ) {                     if (isWon && isDaily) {@@ -294,6 +299,7 @@ fun WordGameScreen(                         LetterChooser(                             letters = shuffledLetters,                             tapToSpell = tapToSpell,+                            wheelSpacing = wheelSpacing,                             onShuffle = {                                 var nextLetters = shuffledLetters.shuffled()                                 while (nextLetters == shuffledLetters && shuffledLetters.size > 1) {
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.ktindex fea82ea85a..4fbf386d78 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt@@ -44,6 +44,7 @@ import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.games.wordmaker.R+import com.vayunmathur.games.wordmaker.data.WheelSpacing import com.vayunmathur.games.wordmaker.ui.ChooserLetter import com.vayunmathur.library.ui.animatedDp import kotlinx.coroutines.CoroutineScope@@ -57,6 +58,7 @@ import kotlin.math.sin fun LetterChooser(     letters: List<ChooserLetter>,     tapToSpell: Boolean,+    wheelSpacing: WheelSpacing,     onShuffle: () -> Unit,     onWordSubmitted: suspend CoroutineScope.(String, List<Int>) -> Unit,     onWordBoxPositioned: (Offset) -> Unit,@@ -78,11 +80,12 @@ fun LetterChooser(      val density = LocalDensity.current     val letterCircleRadius = with(density) { 35.dp.toPx() }-    val boxSizePx = with(density) { 250.dp.toPx() }+    val boxSize = wheelSpacing.boxSize+    val boxSizePx = with(density) { boxSize.toPx() }     val boxCenter = Offset(boxSizePx / 2, boxSizePx / 2)      val angleStep = 2 * Math.PI / letters.size.toDouble()-    val radius = 85.dp+    val radius = wheelSpacing.ringRadius     val radiusPx = with(density) { radius.toPx() }     val letterCenters = remember(letters, boxCenter, radiusPx) {         List(letters.size) { index ->@@ -158,11 +161,16 @@ fun LetterChooser(             }             Box(                 modifier = Modifier-                    .size(250.dp)+                    .size(boxSize)                     .onGloballyPositioned {                         dragStartOffset = it.localToRoot(Offset.Zero)                     }-                    .pointerInput(letters) {+                    // Keyed on the spacing as well as the letters: the gesture coroutine keeps+                    // the closures from the composition that started it, and getLetterAtArc /+                    // getLetterAtCircle capture boxCenter, radiusPx and letterCenters. Without+                    // the extra key, changing the spacing mid-puzzle redraws the wheel at the+                    // new radius but keeps hit-testing against the old one.+                    .pointerInput(letters, wheelSpacing) {                         detectDragGestures(                             onDragStart = { startOffset ->                                 currentDragPosition = startOffset
games/wordmaker/src/main/res/values/strings.xml
diff --git a/games/wordmaker/src/main/res/values/strings.xml b/games/wordmaker/src/main/res/values/strings.xmlindex 16af1d8e3a..b07e2d361a 100644--- a/games/wordmaker/src/main/res/values/strings.xml+++ b/games/wordmaker/src/main/res/values/strings.xml@@ -13,6 +13,16 @@     <string name="tap_to_spell">Tap to Spell</string>     <!-- SettingsPage: Subtitle explaining tap-to-spell behavior. Sentence -->     <string name="tap_to_spell_description">Tap letters to build words instead of dragging</string>+    <!-- SettingsPage: Label for the row choosing how far apart the letters sit on the wheel. Noun phrase -->+    <string name="wheel_spacing">Letter Wheel Spacing</string>+    <!-- SettingsPage: Letter wheel spacing option, the standard spacing. Adjective -->+    <string name="wheel_spacing_default">Default</string>+    <!-- SettingsPage: Letter wheel spacing option, letters further apart than default. Adjective -->+    <string name="wheel_spacing_wide">Wide</string>+    <!-- SettingsPage: Letter wheel spacing option, one step wider than Wide. Comparative adjective -->+    <string name="wheel_spacing_wider">Wider</string>+    <!-- SettingsPage: Letter wheel spacing option, the widest available. Superlative adjective -->+    <string name="wheel_spacing_widest">Widest</string>     <!-- Hint confirmation dialog: Title asking confirm before using hint (consumes cooldown). Question sentence -->     <string name="hint_confirmation">Are you sure you want to use a hint?</string>     <!-- Hint confirmation dialog: Confirm button. Yes -->