mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
discarding the idea of baking assembledsprite onto a spritesheet; revert to the commit right before this to completely scrap the efforts
This commit is contained in:
@@ -120,7 +120,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
|
||||
// rebuild the disk skimmers
|
||||
INGAME.actorContainerActive.filterIsInstance<IngamePlayer>().forEach {
|
||||
printdbg(this, "Game Save callback -- rebuilding the disk skimmer for IngamePlayer ${it.actorValue.getAsString(AVKey.NAME)}")
|
||||
it.rebuildingDiskSkimmer?.rebuild()
|
||||
// it.rebuildingDiskSkimmer?.rebuild()
|
||||
}
|
||||
|
||||
// return to normal state
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.spriteanimation.AssembledSpriteAnimation
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.itemListHeight
|
||||
@@ -85,11 +87,17 @@ class UIItemInventoryEquippedView(
|
||||
blendNormal(batch)
|
||||
|
||||
batch.color = SPRITE_DRAW_COL
|
||||
batch.draw(
|
||||
it.textureRegion.get(0, 0),
|
||||
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
|
||||
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
|
||||
)
|
||||
|
||||
if (it is SheetSpriteAnimation) {
|
||||
batch.draw(
|
||||
it.textureRegion.get(0, 0),
|
||||
posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(),
|
||||
posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat()
|
||||
)
|
||||
}
|
||||
else if (it is AssembledSpriteAnimation) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import com.badlogic.gdx.utils.JsonReader
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.unicode.EMDASH
|
||||
@@ -28,6 +29,8 @@ import net.torvald.terrarum.serialise.SaveLoadError
|
||||
import net.torvald.terrarum.spriteassembler.ADProperties
|
||||
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X
|
||||
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y
|
||||
import net.torvald.terrarum.spriteassembler.AssembleFrameBase
|
||||
import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap
|
||||
import net.torvald.terrarum.ui.Movement
|
||||
import net.torvald.terrarum.ui.Toolkit
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
@@ -531,7 +534,7 @@ class UIItemPlayerCells(
|
||||
"${d}d${h.toString().padStart(2,'0')}h${m.toString().padStart(2,'0')}m${s.toString().padStart(2,'0')}s"
|
||||
}
|
||||
|
||||
private var sprite: SpriteAnimation? = null
|
||||
private var sprite: TextureRegion? = null
|
||||
|
||||
internal var hasTexture = false
|
||||
private set
|
||||
@@ -556,16 +559,47 @@ class UIItemPlayerCells(
|
||||
if (skimmer.initialised && !hasTexture) {
|
||||
skimmer.getFile(-1L)?.bytes?.let {
|
||||
try {
|
||||
val frameName = "ANIM_IDLE_1"
|
||||
val animFile = skimmer.getFile(-2L)!!
|
||||
val p = ReadPlayer(skimmer, ByteArray64Reader(it, Common.CHARSET))
|
||||
p.sprite = SpriteAnimation(p)
|
||||
p.animDesc = ADProperties(ByteArray64Reader(animFile.bytes, Common.CHARSET))
|
||||
p.reassembleSpriteFromDisk(skimmer, p.sprite, null, null)
|
||||
p.sprite!!.textureRegion.get(0,0).let {
|
||||
thumb = it
|
||||
thumb!!.flip(false, false)
|
||||
}
|
||||
this.sprite = p.sprite
|
||||
val properties = ADProperties(ByteArray64Reader(animFile.bytes, Common.CHARSET))
|
||||
|
||||
val imagesSelfContained = skimmer.hasEntry(-1025L)
|
||||
val bodypartMapping = Properties().also { if (imagesSelfContained) it.load(ByteArray64Reader(skimmer.getFile(-1025L)!!.bytes, Common.CHARSET)) }
|
||||
|
||||
val fileGetter = if (imagesSelfContained)
|
||||
AssembleSheetPixmap.getVirtualDiskFileGetter(bodypartMapping, skimmer)
|
||||
else
|
||||
AssembleSheetPixmap.getAssetsDirFileGetter(properties)
|
||||
|
||||
// println(properties.transforms.keys)
|
||||
|
||||
val canvas = Pixmap(properties.cols * (properties.frameWidth), properties.rows * (properties.frameHeight), Pixmap.Format.RGBA8888).also { it.blending = Pixmap.Blending.SourceOver }
|
||||
val theAnim = properties.getAnimByFrameName(frameName)
|
||||
val skeleton = theAnim.skeleton.joints.reversed()
|
||||
val transforms = properties.getTransform(frameName)
|
||||
val bodypartOrigins = properties.bodypartJoints
|
||||
val bodypartImages = properties.bodypartJoints.keys.map { partname ->
|
||||
fileGetter(partname).let { file ->
|
||||
if (file == null) partname to null
|
||||
else {
|
||||
try {
|
||||
val bytes = file.readAllBytes()
|
||||
partname to Pixmap(bytes, 0, bytes.size)
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
partname to null
|
||||
}
|
||||
}
|
||||
}
|
||||
}.toMap()
|
||||
val transformList = AssembleFrameBase.makeTransformList(skeleton, transforms)
|
||||
|
||||
// manually draw 0th frame of ANIM_IDLE
|
||||
AssembleSheetPixmap.drawFrame(0, 0, canvas, properties, bodypartOrigins, bodypartImages, transformList, null)
|
||||
|
||||
bodypartImages.values.forEach { it?.dispose() }
|
||||
|
||||
this.sprite = TextureRegion(Texture(canvas))
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw SaveLoadError(skimmer.diskFile, e)
|
||||
@@ -620,7 +654,7 @@ class UIItemPlayerCells(
|
||||
override fun dispose() {
|
||||
thumb?.texture?.dispose()
|
||||
thumbPixmap?.dispose()
|
||||
sprite?.dispose()
|
||||
sprite?.texture?.dispose()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user