Skip to content

Commit

Permalink
feat: layer refactors and features
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 14, 2024
1 parent c2f5d98 commit 274bafb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 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.8.1
mod_version=1.9
maven_group=net.mcbrawls
mod_id=slate
32 changes: 24 additions & 8 deletions src/main/kotlin/net/mcbrawls/slate/Slate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,45 @@ open class Slate {
action.invoke(tiles)
}

/**
* Adds a layer to this slate at the given tile index.
*/
fun addLayer(index: Int, layer: SlateLayer) {
layers.add(LayerWithIndex(index, layer))
}

/**
* Adds a layer to this slate at the given coordinates.
*/
fun addLayer(x: Int, y: Int, layer: SlateLayer) {
addLayer(TileGrid.toIndex(x, y, tiles.width), layer)
}

/**
* Adds a layer to this slate.
* @return the created layer
*/
inline fun layer(
inline fun addLayer(
index: Int,
width: Int,
height: Int,
factory: SlateLayer.Factory = SlateLayer.Factory(::SlateLayer),
builder: SlateLayer.() -> Unit,
) : SlateLayer {
val layer = factory.create(width, height)
layer.apply(builder)
layers.add(LayerWithIndex(index, layer))
val layer = factory
.create(width, height)
.apply(builder)

addLayer(index, layer)

return layer
}

/**
* Adds a paged layer to this slate.
* @return the created layer
*/
inline fun pagedLayer(
inline fun addPagedLayer(
index: Int,
width: Int,
height: Int,
Expand All @@ -121,10 +138,9 @@ open class Slate {
override fun createTile(index: Int): Tile? {
return slotFactory.invoke(this, index)
}
}
}.apply(builder)

layer.apply(builder)
layers.add(LayerWithIndex(index, layer))
addLayer(index, layer)

return layer
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/net/mcbrawls/slate/test/SlateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SlateTest : ModInitializer {
val slate = slate {
title = Text.literal("Slate Innit")

layer(4, 3, 2) {
addLayer(4, 3, 2) {
for (i in 0 until size) {
tiles[i] = tile(Items.STONE) {
tooltip(Text.literal("Layer tile at $i"))
Expand Down

0 comments on commit 274bafb

Please sign in to comment.