Added a parser for the rpgmaker CharSet format

This commit is contained in:
dalyjame 2019-06-26 15:08:15 -04:00
parent 2b001a9ab0
commit 6defc0ec04
3 changed files with 57 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import scalafx.util.Duration
class SpriteAnimation(val view: ImageView, val image: Drawable, val duration: Duration) extends JTransition {
setCycleDuration(duration)
setInterpolator(Interpolator.Linear)
setAutoReverse(false)
def interpolate(t: Double): Unit = {
image.draw(view, t)

View File

@ -0,0 +1,52 @@
package fmon.draw
import java.io._
object CharSet {
final val FramesPerPose = 3
final val Poses = IndexedSeq("South", "West", "East", "North")
final val NumAcross = 4
final val NumDown = 2
def apply(file: File, index: Int): Sprite = {
val na = NumAcross * FramesPerPose
val nd = NumDown * Poses.size
val palette = new Palette(new FileInputStream(file), na, nd)
val x = index % NumAcross
val y = index / NumAcross
val xx = x * NumAcross
def pose(i: Int): AnimatedImage = {
val yy = y * NumDown + i
val images = IndexedSeq(palette(xx, yy), palette(xx - 1, yy), palette(xx, yy), palette(xx + 1, yy))
new AnimatedImage(images)
}
val poses = Poses.zipWithIndex.map{case (p, i) => (p, pose(i))}.toMap
new Sprite("South", poses)
}
}
import scalafx.application.JFXApp
import scalafx.scene._
import scalafx.scene.control._
import scalafx.scene.image._
import scalafx.scene.paint.Color._
import scalafx.util.Duration
object CharSetDemo extends JFXApp {
val view = new ImageView
stage = new JFXApp.PrimaryStage {
title.value = "Hello Stage"
width = 600
height = 450
scene = new Scene {
fill = LightGreen
content = view
}
}
val filename = raw"C:\Users\dalyj\Documents\Design\Images\CharSets\remakertp01.png"
val walker = CharSet(new File(filename), 1)
val animation = new SpriteAnimation(view, walker, new Duration(600)) {
setCycleCount(scalafx.animation.Transition.Indefinite)
}
animation.play()
}

View File

@ -86,6 +86,10 @@ object YamlHelper {
mapper.readValue[Map[String, T]](source)
}
def write[T](source: OutputStream, item: T) = {
mapper.writeValue(source, item)
}
def writeMap[T](source: OutputStream, items: Map[String, T])(implicit m: Manifest[T]) = {
mapper.writeValue(source, items)
}