mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
animation metadata now contains discovered frame count
...in hacky way
This commit is contained in:
@@ -14,8 +14,8 @@ data class Skeleton(val name: String, val joints: List<Joint>) {
|
|||||||
override fun toString() = "$name=$joints"
|
override fun toString() = "$name=$joints"
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Animation(val name: String, val delay: Float, val row: Int, val skeleton: Skeleton) {
|
data class Animation(val name: String, val delay: Float, val row: Int, val frames: Int, val skeleton: Skeleton) {
|
||||||
override fun toString() = "$name delay: $delay, row: $row, skeleton: ${skeleton.name}"
|
override fun toString() = "$name delay: $delay, row: $row, frames: $frames, skeleton: ${skeleton.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ADProperties {
|
class ADProperties {
|
||||||
@@ -38,6 +38,8 @@ class ADProperties {
|
|||||||
lateinit var baseFilename: String; private set
|
lateinit var baseFilename: String; private set
|
||||||
lateinit var extension: String; private set
|
lateinit var extension: String; private set
|
||||||
|
|
||||||
|
private val animFrameSuffixRegex = Regex("""_[0-9]+""")
|
||||||
|
|
||||||
constructor(reader: Reader) {
|
constructor(reader: Reader) {
|
||||||
javaProp.load(reader)
|
javaProp.load(reader)
|
||||||
continueLoad()
|
continueLoad()
|
||||||
@@ -63,6 +65,23 @@ class ADProperties {
|
|||||||
val bodyparts = HashSet<String>()
|
val bodyparts = HashSet<String>()
|
||||||
val skeletons = HashMap<String, Skeleton>()
|
val skeletons = HashMap<String, Skeleton>()
|
||||||
val animations = HashMap<String, Animation>()
|
val animations = HashMap<String, Animation>()
|
||||||
|
val animFrames = HashMap<String, Int>()
|
||||||
|
// scan every props, write down anim frames for later use
|
||||||
|
propTable.keys.forEach {
|
||||||
|
if (animFrameSuffixRegex.containsMatchIn(it)) {
|
||||||
|
val animName = getAnimNameFromFrame(it)
|
||||||
|
val frameNumber = it.drop(animName.length + 1).toInt()
|
||||||
|
|
||||||
|
// if animFrames does not have our entry, add it.
|
||||||
|
// otherwise, max() against the existing value
|
||||||
|
if (animFrames.containsKey(animName)) {
|
||||||
|
animFrames[animName] = maxOf(animFrames[animName]!!, frameNumber)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
animFrames[animName] = frameNumber
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// populate skeletons and animations
|
// populate skeletons and animations
|
||||||
forEach { s, list ->
|
forEach { s, list ->
|
||||||
// Map-ify. If it has variable == "SKELETON", the 's' is likely an animation
|
// Map-ify. If it has variable == "SKELETON", the 's' is likely an animation
|
||||||
@@ -82,6 +101,7 @@ class ADProperties {
|
|||||||
s,
|
s,
|
||||||
propsHashMap["DELAY"] as Float,
|
propsHashMap["DELAY"] as Float,
|
||||||
(propsHashMap["ROW"] as Float).toInt(),
|
(propsHashMap["ROW"] as Float).toInt(),
|
||||||
|
animFrames[s]!!,
|
||||||
Skeleton(skeletonName, skeletonDef.toJoints())
|
Skeleton(skeletonName, skeletonDef.toJoints())
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -97,7 +117,7 @@ class ADProperties {
|
|||||||
this.bodyparts = bodyparts.toList().sorted()
|
this.bodyparts = bodyparts.toList().sorted()
|
||||||
this.skeletons = skeletons
|
this.skeletons = skeletons
|
||||||
this.animations = animations
|
this.animations = animations
|
||||||
this.bodypartFiles = this.bodyparts.map { getFullFilename(it) }
|
this.bodypartFiles = this.bodyparts.map { toFilename(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(identifier: String) = propTable[identifier.toUpperCase()]
|
operator fun get(identifier: String) = propTable[identifier.toUpperCase()]
|
||||||
@@ -106,14 +126,15 @@ class ADProperties {
|
|||||||
fun containsKey(key: String) = propTable.containsKey(key)
|
fun containsKey(key: String) = propTable.containsKey(key)
|
||||||
fun forEach(predicate: (String, List<ADPropertyObject>) -> Unit) = propTable.forEach(predicate)
|
fun forEach(predicate: (String, List<ADPropertyObject>) -> Unit) = propTable.forEach(predicate)
|
||||||
|
|
||||||
fun getFullFilename(partName: String) =
|
fun toFilename(partName: String) =
|
||||||
"${this.baseFilename}${partName.toLowerCase()}${this.extension}"
|
"${this.baseFilename}${partName.toLowerCase()}${this.extension}"
|
||||||
|
|
||||||
fun getAnimByFrameName(frameName: String): Animation {
|
fun getAnimByFrameName(frameName: String): Animation {
|
||||||
val animName = frameName.substring(0 until frameName.lastIndexOf('_'))
|
return animations[getAnimNameFromFrame(frameName)]!!
|
||||||
return animations[animName]!!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getAnimNameFromFrame(s: String) = s.substring(0 until s.lastIndexOf('_'))
|
||||||
|
|
||||||
private fun List<ADPropertyObject>.toJoints() = List(this.size) {
|
private fun List<ADPropertyObject>.toJoints() = List(this.size) {
|
||||||
Joint(this[it].variable, this[it].input!! as ADPropertyObject.Vector2i)
|
Joint(this[it].variable, this[it].input!! as ADPropertyObject.Vector2i)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,14 @@ object AssembleFrameGdxPixmap {
|
|||||||
|
|
||||||
operator fun invoke(properties: ADProperties, frameName: String) {
|
operator fun invoke(properties: ADProperties, frameName: String) {
|
||||||
val theAnim = properties.getAnimByFrameName(frameName)
|
val theAnim = properties.getAnimByFrameName(frameName)
|
||||||
val skeleton = theAnim.skeleton
|
val skeleton = theAnim.skeleton.joints
|
||||||
|
|
||||||
|
println("Test")
|
||||||
|
|
||||||
|
// test print required body part filename
|
||||||
|
skeleton.reversed().forEach {
|
||||||
|
println(properties.toFilename(it.name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,9 +41,6 @@ class ADLParsingTest {
|
|||||||
ANIM_IDLE_1=
|
ANIM_IDLE_1=
|
||||||
! ANIM_IDLE_1 will not make any transformation
|
! ANIM_IDLE_1 will not make any transformation
|
||||||
ANIM_IDLE_2=UPPER_TORSO 0,-1
|
ANIM_IDLE_2=UPPER_TORSO 0,-1
|
||||||
|
|
||||||
ANIM_CROUCH=DELAY 1;ROW 3;SKELETON SKELETON_CROUCH
|
|
||||||
ANIM_CROUCH_1=
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
operator fun invoke() {
|
operator fun invoke() {
|
||||||
|
|||||||
21
src/net/torvald/terrarum/tests/SpriteAssemblerTest.kt
Normal file
21
src/net/torvald/terrarum/tests/SpriteAssemblerTest.kt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package net.torvald.terrarum.tests
|
||||||
|
|
||||||
|
import net.torvald.spriteassembler.ADProperties
|
||||||
|
import net.torvald.spriteassembler.AssembleFrameGdxPixmap
|
||||||
|
import java.io.StringReader
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2019-01-06.
|
||||||
|
*/
|
||||||
|
class SpriteAssemblerTest {
|
||||||
|
|
||||||
|
operator fun invoke() {
|
||||||
|
val properties = ADProperties(StringReader(ADLParsingTest().TEST_STR))
|
||||||
|
AssembleFrameGdxPixmap.invoke(properties, "ANIM_RUN_1")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
SpriteAssemblerTest().invoke()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user