Fix cleanup
This commit is contained in:
@@ -6,14 +6,14 @@ class GameCell<C : ItemClass<C>>(
|
||||
options: Collection<Item<C>>
|
||||
) {
|
||||
val selectionChangedListeners = mutableListOf<(Item<C>?) -> Unit>()
|
||||
val removedListeners = mutableListOf<(Collection<Item<C>>) -> Unit>()
|
||||
val optionsRemovedListeners = mutableListOf<(Collection<Item<C>>) -> Unit>()
|
||||
|
||||
var selection: Item<C>? = selection
|
||||
set(value) {
|
||||
field = value
|
||||
selectionChangedListeners.forEach { listener -> listener(value) }
|
||||
}
|
||||
val options = ObservableSet(options.toMutableSet()) { removedListeners.forEach { listener -> listener(it) } }
|
||||
val options = ObservableSet(options.toMutableSet()) { optionsRemovedListeners.forEach { listener -> listener(it) } }
|
||||
}
|
||||
|
||||
fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>, mayHaveSelection: Boolean = true) =
|
||||
|
||||
@@ -11,12 +11,14 @@ class GameRow<C : ItemClass<C>>(
|
||||
cells.forEach { cleanupOptions(it) }
|
||||
}
|
||||
|
||||
private fun cleanupOptions(cell: GameCell<C>) {
|
||||
if (cell.options.size == 1 && cell.selection == null) {
|
||||
cell.selection = cell.options.first()
|
||||
private fun cleanupOptions(cell: GameCell<C>, firstCall: Boolean = true) {
|
||||
if ((firstCall && cell.selection != null) || (cell.options.size == 1 && cell.selection == null)) {
|
||||
if (cell.selection == null) {
|
||||
cell.selection = cell.options.first()
|
||||
}
|
||||
filter { otherCell -> otherCell != cell && otherCell.selection == null }.forEach { otherCell ->
|
||||
otherCell.options.remove(cell.selection)
|
||||
cleanupOptions(otherCell)
|
||||
cleanupOptions(otherCell, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user