Auto-commit after successful build: update app gameplay/UI, improve build setup

Changed files:\napp/build.gradle.kts
app/src/main/java/solutions/tretter/githugandroid/AppLog.kt
app/src/main/java/solutions/tretter/githugandroid/GameProgressStore.kt
app/src/main/java/solutions/tretter/githugandroid/GitHugApp.kt
app/src/main/java/solutions/tretter/githugandroid/GitRuntime.kt
This commit is contained in:
Joe Tretter
2026-04-24 13:52:19 -05:00
parent 66b664d9d5
commit eee8827f76
5 changed files with 86 additions and 12 deletions

View File

@@ -40,7 +40,7 @@ fun GitHugApp() {
val paneLayoutStore = remember(context) { PaneLayoutStore(context.applicationContext) }
val gameProgressStore = remember(context) { GameProgressStore(context.applicationContext) }
val persistedPaneLayout by paneLayoutStore.layoutFlow.collectAsState(initial = defaultPaneLayout())
val persistedCompletedLevels by gameProgressStore.completedLevelsFlow.collectAsState(initial = null)
val persistedProgress by gameProgressStore.progressFlow.collectAsState(initial = null)
val scope = rememberCoroutineScope()
val screenScrollState = rememberScrollState()
val screenHeightDp = configuration.screenHeightDp
@@ -81,13 +81,28 @@ fun GitHugApp() {
}
}
LaunchedEffect(persistedCompletedLevels) {
val restoredCompletedLevels = persistedCompletedLevels ?: return@LaunchedEffect
suspend fun persistProgress(completed: Set<String>, activeLevelId: String?) {
gameProgressStore.saveProgress(completed, activeLevelId)
}
LaunchedEffect(persistedProgress) {
val restoredProgress = persistedProgress ?: return@LaunchedEffect
val restoredCompletedLevels = restoredProgress.completedLevels
completedLevels = restoredCompletedLevels
AppLog.d(
"GitHugApp",
"Observed persisted progress completed=${restoredCompletedLevels.sorted()} activeLevelId=${restoredProgress.activeLevelId} restored=$hasRestoredProgress",
)
if (!hasRestoredProgress) {
hasRestoredProgress = true
val firstIncompleteIndex = levels.indexOfFirst { it.id !in restoredCompletedLevels }
val resumeIndex = firstIncompleteIndex.takeIf { it >= 0 } ?: levels.lastIndex
val resumeIndex = restoredProgress.activeLevelId
?.let { activeId -> levels.indexOfFirst { it.id == activeId }.takeIf { it >= 0 } }
?: levels.indexOfFirst { it.id !in restoredCompletedLevels }.takeIf { it >= 0 }
?: levels.lastIndex
AppLog.d(
"GitHugApp",
"Restoring app to levelIndex=$resumeIndex levelId=${levels[resumeIndex].id}",
)
currentLevelIndex = resumeIndex
repo = runtime.prepareLevel(levels[resumeIndex])
output = listOf(
@@ -171,6 +186,7 @@ fun GitHugApp() {
}
fun loadLevel(index: Int) {
AppLog.d("GitHugApp", "Loading level index=$index id=${levels[index].id} title=${levels[index].title}")
currentLevelIndex = index
repo = runtime.prepareLevel(levels[index])
output = listOf("Loaded level: ${levels[index].title}")
@@ -264,6 +280,10 @@ fun GitHugApp() {
val (newRepo, lines) = runtime.execute(currentLevel, repo, raw)
val solvedAfterCommand = currentLevel.validator(newRepo, raw)
val wasAlreadyCompleted = currentLevel.id in completedLevels
AppLog.d(
"GitHugApp",
"Command='$raw' level=${currentLevel.id} solved=$solvedAfterCommand alreadyCompleted=$wasAlreadyCompleted completedBefore=${completedLevels.sorted()}",
)
val newOutput = buildList {
addAll(output)
add("$ $raw")
@@ -275,17 +295,25 @@ fun GitHugApp() {
if (solvedAfterCommand && !wasAlreadyCompleted) {
val updatedCompletedLevels = completedLevels + currentLevel.id
completedLevels = updatedCompletedLevels
scope.launch { gameProgressStore.saveCompletedLevels(updatedCompletedLevels) }
val nextLevelIndex = levels.indexOfFirst { it.id !in updatedCompletedLevels }
if (nextLevelIndex >= 0) {
val nextLevelId = levels[nextLevelIndex].id
AppLog.d(
"GitHugApp",
"Level solved ${currentLevel.id}; advancing to next incomplete index=$nextLevelIndex id=$nextLevelId",
)
scope.launch { persistProgress(updatedCompletedLevels, nextLevelId) }
loadLevel(nextLevelIndex)
} else {
AppLog.d("GitHugApp", "All levels completed")
scope.launch { persistProgress(updatedCompletedLevels, levels.lastOrNull()?.id) }
repo = newRepo
output = listOf("🏁 All Githug levels completed.")
clearCommandInput()
suppressedImeEcho = null
}
} else {
AppLog.d("GitHugApp", "Staying on level=${currentLevel.id}")
repo = newRepo
output = newOutput
applyRecommendedPaneWeights(persist = false)