Add Keyboard Control

This commit is contained in:
2025-06-02 06:06:11 +02:00
parent 54b1810606
commit 93103e4e49
38 changed files with 1824 additions and 418 deletions

View File

@@ -1,6 +1,5 @@
package ch.dissem.yaep.domain
@Suppress("JavaDefaultMethodsNotOverriddenByDelegation")
class GameRow<C : ItemClass<C>>(
val category: ItemClassCompanion<C>,
val options: List<Item<C>>,
@@ -22,12 +21,8 @@ class GameRow<C : ItemClass<C>>(
fun indexOf(element: C): Int = indexOfFirst { it.selection?.itemType == element }
fun cleanupOptions() {
if (isSolved && all {
it.solution != null
&& it.options.size == 1
&& it.options.single() == it.selection
}
) return
if (isSolved && all { it.options.size == 1 && it.options.single() == it.selection })
return
do {
var changed = false
val selections = filter { it.selection != null }.let { cellsWithSelection ->
@@ -58,11 +53,7 @@ class GameRow<C : ItemClass<C>>(
}
}
} while (changed)
isSolved = all {
it.solution != null
&& it.options.size == 1
&& it.options.single() == it.selection
}
isSolved = all { it.options.size == 1 && it.options.single() == it.selection }
}
fun snapshot() {
@@ -72,11 +63,7 @@ class GameRow<C : ItemClass<C>>(
fun undo(): Boolean {
val didChange = cells.map { it.undo() }.reduce { a, b -> a || b }
if (didChange) {
isSolved = all {
it.solution != null
&& it.options.size == 1
&& it.options.single() == it.selection
}
isSolved = all { it.options.size == 1 && it.options.single() == it.selection }
}
return didChange
}