GridInSprite

This commit is contained in:
DBotThePony 2023-01-13 16:43:58 +07:00
parent 6305886775
commit 027b4bcc3d
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -1,7 +1,7 @@
package ru.dbotthepony.mc.otm.client.render package ru.dbotthepony.mc.otm.client.render
@Suppress("unused") @Suppress("unused")
data class GridSprite( data class GridInSprite(
val parent: AbstractMatterySprite, val parent: AbstractMatterySprite,
val width: Float, val width: Float,
val height: Float, val height: Float,
@ -14,7 +14,7 @@ data class GridSprite(
val currentX: Float get() = column * width val currentX: Float get() = column * width
val currentY: Float get() = row * height val currentY: Float get() = row * height
fun skip(): GridSprite { fun skip(): GridInSprite {
column++ column++
if (column >= columns) { if (column >= columns) {
@ -24,37 +24,37 @@ data class GridSprite(
return this return this
} }
fun jump(): GridSprite { fun jump(): GridInSprite {
row++ row++
column = 0 column = 0
return this return this
} }
fun next(): AbstractMatterySprite { fun next(): AbstractMatterySprite {
val element = parent.subElement(currentX, currentY, width, height) val element = parent.sprite(currentX, currentY, width, height)
skip() skip()
return element return element
} }
fun reset(): GridSprite { fun reset(): GridInSprite {
row = 0 row = 0
column = 0 column = 0
return this return this
} }
fun seek(row: Int, column: Int): GridSprite { fun seek(row: Int, column: Int): GridInSprite {
this.row = row this.row = row
this.column = column this.column = column
return this return this
} }
operator fun get(column: Int, row: Int) = operator fun get(column: Int, row: Int) =
parent.subElement(column * width, row * height, width, height) parent.sprite(column * width, row * height, width, height)
} }
fun AbstractMatterySprite.subGrid( fun AbstractMatterySprite.grid(
width: Float, width: Float,
height: Float, height: Float,
columns: Int = 16, columns: Int = 16,
rows: Int = 16, rows: Int = 16,
) = GridSprite(this, width, height, columns, rows) ) = GridInSprite(this, width, height, columns, rows)