mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 15:46:06 +09:00
new save format wip (no branching on this commit)
This commit is contained in:
@@ -2,6 +2,7 @@ package net.torvald.spriteassembler
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import net.torvald.terrarum.linearSearchBy
|
||||
import net.torvald.terrarum.serialise.Common
|
||||
import java.io.InputStream
|
||||
import java.io.Reader
|
||||
import java.util.*
|
||||
@@ -33,6 +34,7 @@ internal data class Transform(val joint: Joint, val translate: ADPropertyObject.
|
||||
|
||||
class ADProperties {
|
||||
private var fileFrom = ""
|
||||
private var adlString = ""
|
||||
private val javaProp = Properties()
|
||||
|
||||
/** Every key is CAPITALISED */
|
||||
@@ -68,30 +70,31 @@ class ADProperties {
|
||||
var rows = -1; private set
|
||||
var cols = -1; private set
|
||||
|
||||
fun getRawADL() = adlString
|
||||
|
||||
companion object {
|
||||
const val ALL_JOINT_SELECT_KEY = "ALL"
|
||||
}
|
||||
|
||||
constructor(gdxFile: FileHandle) {
|
||||
fileFrom = gdxFile.path()
|
||||
adlString = gdxFile.readString(Common.CHARSET.name())
|
||||
javaProp.load(gdxFile.read())
|
||||
continueLoad()
|
||||
}
|
||||
|
||||
constructor(reader: Reader) {
|
||||
adlString = reader.readText()
|
||||
javaProp.load(reader)
|
||||
continueLoad()
|
||||
}
|
||||
|
||||
constructor(inputStream: InputStream) {
|
||||
adlString = inputStream.readAllBytes().toString(Common.CHARSET)
|
||||
javaProp.load(inputStream)
|
||||
continueLoad()
|
||||
}
|
||||
|
||||
constructor(javaProp: Properties) {
|
||||
this.javaProp.putAll(javaProp.toMap())
|
||||
}
|
||||
|
||||
private fun continueLoad() {
|
||||
// sanity check
|
||||
reservedProps.forEach {
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.torvald.spriteassembler
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||
import net.torvald.terrarum.linearSearch
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Assembles the single frame of the animation, outputs GDX Pixmap.
|
||||
@@ -17,10 +19,13 @@ object AssembleSheetPixmap {
|
||||
val canvas = Pixmap(properties.cols * properties.frameWidth, properties.rows * properties.frameHeight, Pixmap.Format.RGBA8888)
|
||||
canvas.blending = Pixmap.Blending.SourceOver
|
||||
|
||||
val fileGetter = { path: String ->
|
||||
Gdx.files.internal(path).read()
|
||||
}
|
||||
|
||||
// actually draw
|
||||
properties.transforms.forEach { t, _ ->
|
||||
drawThisFrame(t, canvas, properties)
|
||||
drawThisFrame(t, canvas, properties, fileGetter)
|
||||
}
|
||||
|
||||
return canvas
|
||||
@@ -28,15 +33,21 @@ object AssembleSheetPixmap {
|
||||
|
||||
private fun drawThisFrame(frameName: String,
|
||||
canvas: Pixmap,
|
||||
properties: ADProperties
|
||||
properties: ADProperties,
|
||||
fileGetter: (String) -> InputStream
|
||||
) {
|
||||
val theAnim = properties.getAnimByFrameName(frameName)
|
||||
val skeleton = theAnim.skeleton.joints.reversed()
|
||||
val transforms = properties.getTransform(frameName)
|
||||
val bodypartOrigins = properties.bodyparts
|
||||
val bodypartImages = properties.bodyparts.keys.map {
|
||||
val file = Gdx.files.internal("assets/${properties.toFilename(it)}")
|
||||
it to (if (file.exists()) Pixmap(file) else null)
|
||||
try {
|
||||
val bytes = fileGetter("assets/${properties.toFilename(it)}").readAllBytes()
|
||||
it to Pixmap(bytes, 0, bytes.size)
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
it to null
|
||||
}
|
||||
}.toMap()
|
||||
val transformList = AssembleFrameBase.makeTransformList(skeleton, transforms)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user