games: wire kart into the hub; wordmaker achievements report; shared haptics
- Commit
b17bf5f70999ee53526285b621982ebe004ed5d9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-21 04:20 UTC (15 days ago)
- Parents
7f09a99
Kart was listed in the hub but had no sdk:games dependency or achievements, so it could never report sessions or XP. It now binds GameHubComposeHook with a starter achievement set (first race/win/cup), back-filling from its stored stats. Wordmaker's achievements manager was never bound to the hub reporter - it now uses the compose hook like its siblings. Minesweeper used LocalHapticFeedback directly; it uses the shared rememberHaptics like chess/logicgate/nonogram. Verified: compile for kart/wordmaker/minesweeper and kart's unit tests.
Diff
games/kart/build.gradle.kts
diff --git a/games/kart/build.gradle.kts b/games/kart/build.gradle.ktsindex d9df3c4d35..fb2deb94e8 100644--- a/games/kart/build.gradle.kts+++ b/games/kart/build.gradle.kts@@ -47,6 +47,7 @@ rustNativeLib( ) dependencies {+ implementation(project(":sdk:games")) implementation(project(":sdk:controller")) implementation(project(":library:e2ee-p2p")) implementation(libs.androidx.datastore.preferences)
games/kart/src/main/assets/achievements.json
diff --git a/games/kart/src/main/assets/achievements.json b/games/kart/src/main/assets/achievements.jsonnew file mode 100644index 0000000000..baede9563f--- /dev/null+++ b/games/kart/src/main/assets/achievements.json@@ -0,0 +1,17 @@+[+ {+ "id": "first_race",+ "name": "Off The Line",+ "description": "Finish your first race!"+ },+ {+ "id": "first_win",+ "name": "First Win",+ "description": "Win your first race!"+ },+ {+ "id": "cup_complete",+ "name": "Cup Complete",+ "description": "Complete a cup!"+ }+]
games/kart/src/main/java/com/vayunmathur/games/kart/Navigation.kt
diff --git a/games/kart/src/main/java/com/vayunmathur/games/kart/Navigation.kt b/games/kart/src/main/java/com/vayunmathur/games/kart/Navigation.ktindex 19e835ab03..98c156ecb0 100644--- a/games/kart/src/main/java/com/vayunmathur/games/kart/Navigation.kt+++ b/games/kart/src/main/java/com/vayunmathur/games/kart/Navigation.kt@@ -8,6 +8,7 @@ import com.vayunmathur.games.kart.platform.KartViewModel import com.vayunmathur.games.kart.platform.RacePhase import com.vayunmathur.games.kart.ui.KartGamePage import com.vayunmathur.library.util.FullscreenPage+import com.vayunmathur.library.util.GameHubComposeHook import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.rememberNavBackStack@@ -15,6 +16,7 @@ import com.vayunmathur.library.util.rememberNavBackStack @Composable fun Navigation(viewModel: KartViewModel) { val backStack = rememberNavBackStack<Route>(Route.Lobby)+ GameHubComposeHook("kart", viewModel.achievementsManager) KartRouteEffect(backStack, viewModel) MainNavigation(backStack) { entry<Route.Lobby>(metadata = FullscreenPage()) { KartGamePage(viewModel) }
games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartAchievementsManager.kt
diff --git a/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartAchievementsManager.kt b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartAchievementsManager.ktnew file mode 100644index 0000000000..ef608763d1--- /dev/null+++ b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartAchievementsManager.kt@@ -0,0 +1,37 @@+package com.vayunmathur.games.kart.platform++import android.content.Context+import com.vayunmathur.games.kart.data.KartDataStore+import com.vayunmathur.library.util.AchievementsManager+import kotlinx.coroutines.CoroutineScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.launch++/** Reports Kart achievements and progress to the shared games hub. */+class KartAchievementsManager(+ context: Context,+ json: String,+ private val dataStore: KartDataStore,+) : AchievementsManager(context, json) {++ /**+ * Back-fills from stored progress on launch, so an achievement added in a later release is awarded+ * for work the player has already done rather than only for the next race they finish.+ *+ * The reads are flows, so this hands off to a coroutine rather than blocking. Finishing a race is+ * what banks the next cup (see KartViewModel.finishRace), so a cup pointer past the first cup —+ * or a recorded win — proves a race was finished, and a win proves [first_win]. Whether the final+ * cup was completed cannot be told from the pointer alone (it stays on the last cup), so+ * `cup_complete` is only unlocked live from the finish handler.+ */+ override fun checkExistingAchievements() {+ CoroutineScope(Dispatchers.IO).launch {+ val racesWon = dataStore.racesWon.first()+ val currentCup = dataStore.currentCup.first()+ if (racesWon > 0 || currentCup > 0) onAchievementUnlocked("first_race")+ if (racesWon > 0) onAchievementUnlocked("first_win")+ if (currentCup > 0) onAchievementUnlocked("cup_complete")+ }+ }+}
games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartViewModel.kt
diff --git a/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartViewModel.kt b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartViewModel.ktindex d48192ffe9..b622c12390 100644--- a/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartViewModel.kt+++ b/games/kart/src/main/java/com/vayunmathur/games/kart/platform/KartViewModel.kt@@ -11,6 +11,7 @@ import com.vayunmathur.games.kart.domain.LapTracker import com.vayunmathur.games.kart.domain.PlaceholderRace import com.vayunmathur.games.kart.domain.RumbleDecider import com.vayunmathur.games.kart.util.KartNative+import com.vayunmathur.library.util.AchievementsManager import com.vayunmathur.sdk.controller.RumbleFeedback import kotlinx.coroutines.Job import kotlinx.coroutines.delay@@ -33,6 +34,11 @@ class KartViewModel(application: Application) : AndroidViewModel(application), val dataStore = KartDataStore(application) + val achievementsManager: AchievementsManager = run {+ val json = application.assets.open("achievements.json").bufferedReader().readText()+ KartAchievementsManager(application, json, dataStore)+ }+ private val _uiState = MutableStateFlow(KartUiState()) val uiState: StateFlow<KartUiState> = _uiState.asStateFlow() @@ -75,6 +81,8 @@ class KartViewModel(application: Application) : AndroidViewModel(application), private set init {+ achievementsManager.checkExistingAchievements()+ // Load (or mint) the PQC identity off the main thread, then open the // lobby. First run pays keygen; every later start reads persisted keys. viewModelScope.launch {@@ -304,6 +312,10 @@ class KartViewModel(application: Application) : AndroidViewModel(application), // Celebration buzz for every remote phone still on the grid. celebrate(order) kartHost.host?.endRace()+ achievementsManager.onAchievementUnlocked("first_race")+ if (winner == localPlayerId) achievementsManager.onAchievementUnlocked("first_win")+ // Finishing banks the next cup below, so a finish is a cup completion.+ achievementsManager.onAchievementUnlocked("cup_complete") _racePhase.value = RacePhase.Results(winner = winner, order = order) val state = _uiState.value viewModelScope.launch {
games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt
diff --git a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.ktindex 2c91368231..e738961069 100644--- a/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt+++ b/games/minesweeper/src/main/java/com/vayunmathur/games/minesweeper/ui/components/MineFieldGrid.kt@@ -17,8 +17,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.luminance import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalDensity-import androidx.compose.ui.platform.LocalHapticFeedback-import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.clearAndSetSemantics@@ -40,6 +38,7 @@ import com.vayunmathur.library.ui.IconFlag import com.vayunmathur.library.ui.IconMine import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.rememberHaptics /** * The mine field.@@ -99,7 +98,7 @@ private fun MineCell( ) { val scheme = MaterialTheme.colorScheme val density = LocalDensity.current- val haptics = LocalHapticFeedback.current+ val haptics = rememberHaptics() val revealed = game.revealed[index] val flagged = game.flagged[index]@@ -147,7 +146,7 @@ private fun MineCell( // Confirms the flag without the player having to look away from the field. // Only for a real change: buzzing for a press that did nothing (an open // cell, an unstarted field) told the player a flag went in when none did.- if (onLongPress()) haptics.performHapticFeedback(HapticFeedbackType.LongPress)+ if (onLongPress()) haptics.longPress() }, ) }@@ -158,7 +157,7 @@ private fun MineCell( // tap/long-press split that detectTapGestures above preserves. onClick { onTap(); true } onLongClick {- if (onLongPress()) haptics.performHapticFeedback(HapticFeedbackType.LongPress)+ if (onLongPress()) haptics.longPress() true } },
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.ktindex c19ea41e4f..68410c0b42 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/Navigation.kt@@ -16,7 +16,7 @@ import com.vayunmathur.games.wordmaker.ui.WordMakerGameLoader import com.vayunmathur.library.ui.GameCenterScreen import com.vayunmathur.library.util.AchievementsManager import com.vayunmathur.library.util.FullscreenPage-import com.vayunmathur.library.util.GameHubSessionHook+import com.vayunmathur.library.util.GameHubComposeHook import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.OpenSettingsIfRequested@@ -29,7 +29,8 @@ fun Navigation(viewModel: WordMakerViewModel) { val backStack = rememberNavBackStack<Route>(Route.Game) backStack.OpenSettingsIfRequested(Route.Settings) WordMakerRouteEffect(backStack, viewModel)- GameHubSessionHook("wordmaker", "Wordmaker")+ val achievementsManager = rememberAchievementsManager(viewModel.levelDataStore)+ GameHubComposeHook("wordmaker", achievementsManager) MainNavigation(backStack) { entry<Route.Game>(metadata = FullscreenPage()) { WordMakerGameLoader(backStack, viewModel)@@ -42,7 +43,6 @@ fun Navigation(viewModel: WordMakerViewModel) { ) } entry<Route.GameCenter> {- val achievementsManager = rememberAchievementsManager(viewModel.levelDataStore) if (achievementsManager != null) { GameCenterScreen( manager = achievementsManager,