Implement undo functionality
Not quite sure about its usability though
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user