Split skinelement file

This commit is contained in:
DBotThePony 2022-10-06 18:04:23 +07:00
parent 4801ff01ad
commit 92ae0408e8
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 58 additions and 54 deletions

View File

@ -20,60 +20,6 @@ import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
import ru.dbotthepony.mc.otm.core.set import ru.dbotthepony.mc.otm.core.set
import java.lang.reflect.Type import java.lang.reflect.Type
@Suppress("unused")
data class SkinGrid(
val texture: ResourceLocation,
val width: Float,
val height: Float,
val rows: Int = 16,
val columns: Int = 16,
) {
var row = 0
var column = 0
val imageWidth get() = width * columns
val imageHeight get() = height * rows
val currentX: Float get() = column * width
val currentY: Float get() = row * height
fun skip(): SkinGrid {
column++
if (column >= columns) {
jump()
}
return this
}
fun jump(): SkinGrid {
row++
column = 0
return this
}
fun next(): SkinElement {
val element = SkinElement(texture, currentX, currentY, width, height, imageWidth, imageHeight)
skip()
return element
}
fun reset(): SkinGrid {
row = 0
column = 0
return this
}
fun seek(row: Int, column: Int): SkinGrid {
this.row = row
this.column = column
return this
}
operator fun get(column: Int, row: Int) = SkinElement(texture, column * width, row * height, width, height, imageWidth, imageHeight)
}
fun ResourceLocation.element( fun ResourceLocation.element(
x: Float, x: Float,
y: Float, y: Float,

View File

@ -0,0 +1,58 @@
package ru.dbotthepony.mc.otm.client.render
import net.minecraft.resources.ResourceLocation
@Suppress("unused")
data class SkinGrid(
val texture: ResourceLocation,
val width: Float,
val height: Float,
val rows: Int = 16,
val columns: Int = 16,
) {
var row = 0
var column = 0
val imageWidth get() = width * columns
val imageHeight get() = height * rows
val currentX: Float get() = column * width
val currentY: Float get() = row * height
fun skip(): SkinGrid {
column++
if (column >= columns) {
jump()
}
return this
}
fun jump(): SkinGrid {
row++
column = 0
return this
}
fun next(): SkinElement {
val element = SkinElement(texture, currentX, currentY, width, height, imageWidth, imageHeight)
skip()
return element
}
fun reset(): SkinGrid {
row = 0
column = 0
return this
}
fun seek(row: Int, column: Int): SkinGrid {
this.row = row
this.column = column
return this
}
operator fun get(column: Int, row: Int) =
SkinElement(texture, column * width, row * height, width, height, imageWidth, imageHeight)
}