Implement undo functionality

Not quite sure about its usability though
This commit is contained in:
Christian Basler
2025-03-14 06:32:12 +01:00
parent 63f6fca83f
commit a3611cb9a7
6 changed files with 116 additions and 28 deletions

View File

@@ -127,10 +127,8 @@ fun PuzzleGrid(
allOptions.map { Toggleable(it, item.options.contains(it)) }
}
LaunchedEffect(item) {
item.optionsRemovedListeners.add { removed ->
options
.filter { removed.contains(it.item) }
.forEach { it.enabled = false }
item.optionsChangedListeners.add { enabled ->
options.forEach { it.enabled = enabled.contains(it.item) }
}
item.selectionChangedListeners.add {
selection = it
@@ -151,9 +149,17 @@ fun PuzzleGrid(
},
selectedItem = selection,
onSelectItem = {
item.selection = it
if (it != null) {
grid.snapshot()
item.selection = it
row.cleanupOptions()
} else {
while (item.selection != null) {
if (!grid.undo()) break
}
options.forEach {
it.enabled = item.options.contains(it.item)
}
}
}
)