Modern Apps git

← Modern-Apps.git

nonogram: ignore out-of-range restored cell indices

Commit
57edbe3da3d2b093899016e30a70a4d27b929b69
Author
Vayun Mathur <[email protected]>
When
2026-11-19 02:29 UTC (17 days ago)
Parents
96e6064
Restored board marks are parsed from backup-restored DataStore
strings with only a numeric filter, so an index beyond the current
puzzle (or negative) reached puzzle.solution[it] in isWon and
belongsToPicture and threw IndexOutOfBoundsException on every
board load.

Out-of-range indices now simply do not count towards a win and
do not belong to the picture.

Verified: ./gradlew :games:nonogram:testDevUnitTest (pass),
./check games/nonogram (pass).

Diff

games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.ktindex 27f5509e9b..fca65f33e6 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/data/NonogramModels.kt@@ -82,7 +82,9 @@ data class NonogramGameState(      * guarantee.      */     val isWon: Boolean-        get() = filled.size == puzzle.filledCount && filled.all { puzzle.solution[it] }+        // Restored marks may hold indices outside this puzzle; they simply+        // do not count towards a win instead of crashing the board.+        get() = filled.size == puzzle.filledCount && filled.all { puzzle.solution.getOrNull(it) == true }      /** Failed once the hearts run out, unless the last guess also finished the picture. */     val isFailed: Boolean get() = hearts <= 0 && !isWon@@ -90,7 +92,7 @@ data class NonogramGameState(     val isOver: Boolean get() = isWon || isFailed      /** Whether [index] belongs to the picture, which is what a tap on it is judged against. */-    fun belongsToPicture(index: Int): Boolean = puzzle.solution[index]+    fun belongsToPicture(index: Int): Boolean = puzzle.solution.getOrNull(index) == true }  /**