mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-10 05:41:51 +09:00
adproperties now has transforms list; assembler can make transformed skeleton
new fun: LinearSearch(By)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package net.torvald.spriteassembler
|
||||
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.linearSearch
|
||||
import java.awt.Image
|
||||
import java.awt.Toolkit
|
||||
import java.awt.image.BufferedImage
|
||||
@@ -16,6 +16,7 @@ object AssembleFrameAWT {
|
||||
operator fun invoke(properties: ADProperties, frameName: String, assembleConfig: AssembleConfig = AssembleConfig()) {
|
||||
val theAnim = properties.getAnimByFrameName(frameName)
|
||||
val skeleton = theAnim.skeleton.joints.reversed()
|
||||
val transforms = properties.getTransform(frameName)
|
||||
val bodyparts = Array<Image?>(skeleton.size) {
|
||||
// if file does not exist, null it
|
||||
val file = File("assets/" + properties.toFilename(skeleton[it].name))
|
||||
@@ -33,9 +34,13 @@ object AssembleFrameAWT {
|
||||
val canvas = BufferedImage(assembleConfig.fw, assembleConfig.fh, BufferedImage.TYPE_4BYTE_ABGR)
|
||||
|
||||
|
||||
//printdbg(this, "==============================")
|
||||
|
||||
properties[frameName].forEach { printdbg(this, it) }
|
||||
println("Frame name: $frameName")
|
||||
transforms.forEach { println(it) }
|
||||
println("==========================")
|
||||
println("Transformed skeleton:")
|
||||
AssembleFrameBase.makeTransformList(skeleton, transforms).forEach { (name, transform) ->
|
||||
println("$name transformedOut: $transform")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,4 +51,28 @@ object AssembleFrameAWT {
|
||||
* @param ox Origin-X, leftmost point being zero
|
||||
* @param oy Origin-Y, bottommost point being zero
|
||||
*/
|
||||
data class AssembleConfig(val fw: Int = 48, val fh: Int = 56, val ox: Int = 29, val oy: Int = 0)
|
||||
data class AssembleConfig(val fw: Int = 48, val fh: Int = 56, val ox: Int = 29, val oy: Int = 0)
|
||||
|
||||
object AssembleFrameBase {
|
||||
/**
|
||||
* Returns joints list with tranform applied.
|
||||
* @param skeleton list of joints
|
||||
* @param transform ordered list of transforms should be applied. First come first serve.
|
||||
* @return List of pairs that contains joint name on left, final transform value on right
|
||||
*/
|
||||
fun makeTransformList(joints: List<Joint>, transforms: List<Transform>): List<Pair<String, ADPropertyObject.Vector2i>> {
|
||||
// make our mutable list
|
||||
val transformOutput = ArrayList<Pair<String, ADPropertyObject.Vector2i>>()
|
||||
joints.forEach {
|
||||
transformOutput.add(it.name to it.position)
|
||||
}
|
||||
|
||||
// process transform queue
|
||||
transforms.forEach { transform ->
|
||||
val jointToMoveIndex = transformOutput.linearSearch { it.first == transform.joint.name }!!
|
||||
transformOutput[jointToMoveIndex] = transformOutput[jointToMoveIndex].first to transform.getTransformVector()
|
||||
}
|
||||
|
||||
return transformOutput.toList()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user