Skip to content

Commit

Permalink
feat: move layer to modify function
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 12, 2024
1 parent befdbdc commit 0e98603
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ kotlin_version=2.0.21
fabric_kotlin_version=1.12.3

# mod properties
mod_version=1.7
mod_version=1.8
maven_group=net.mcbrawls
mod_id=slate
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ package net.mcbrawls.slate.layer.paged
* Listens to modifications to the internal collection and updates the layer accordingly.
*/
class LayerPageSourceListener<T>(
val layer: PagedSlateLayer,
private val _collection: MutableCollection<T> = mutableListOf(),
collection: MutableCollection<T>,
) {
private val _collection: MutableCollection<T> = collection

val collection: Collection<T> get() = _collection.toList()

/**
* Modify and update the internal collection.
*/
fun modify(action: MutableCollection<T>.() -> Unit) {
fun modify(layer: PagedSlateLayer, action: MutableCollection<T>.() -> Unit) {
synchronized(_collection) {
action.invoke(_collection)
layer.slotCount = _collection.size
Expand All @@ -24,6 +25,6 @@ class LayerPageSourceListener<T>(
/**
* Creates a page source listener from this collection.
*/
fun <T> MutableCollection<T>.layerPageListener(layer: PagedSlateLayer) = LayerPageSourceListener(layer, this)
fun <T> MutableCollection<T>.layerPageListener(layer: PagedSlateLayer) = LayerPageSourceListener(this)
}
}

0 comments on commit 0e98603

Please sign in to comment.