Adjusted the tileset class to have ground and doodad tiles and made it so that doodad tiles get ripped into left and right halves

This commit is contained in:
James Daly 2019-07-14 22:27:22 -04:00
parent 807970db5e
commit 0ff64797d9
5 changed files with 50 additions and 19 deletions

View File

@ -26,7 +26,7 @@ import FileChooser.ExtensionFilter
import fmon._
import fmon.draw.Palette
import fmon.draw.tile._
import fmon.util.Direction
import fmon.util.{Direction, YamlHelper}
import fmon.world._
import Direction._
@ -40,6 +40,10 @@ class MapBuilder {
var imgSeq: IndexedSeq[ImageView] = _
val tilesets = {
val dir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Data")
YamlHelper.extractSeq[TilesetToken](new FileInputStream(new File(dir, "Tilesets.yaml"))).map(t => (t.name, t)).toMap
}
var tileset: Tileset = _
var currTile: AutoTile = _
@ -62,7 +66,8 @@ class MapBuilder {
@FXML
def initialize(): Unit = {
tileset = new Tileset(new TilesetToken("Tileset", null, raw"C:\Users\dalyj\Documents\Design\Images\AutoTiles\tilea2.png", null, null, null, null, null, IndexedSeq()))
val resourceDir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Resources\tilesets")
tileset = tilesets("Outside").load(resourceDir)
level = new GameMap(10, 10, tileset)
setup()
}
@ -82,11 +87,8 @@ class MapBuilder {
tileSelector.children ++= icons
currTile = tileset.groundTiles.head
val doodadFile = new File(raw"C:\Users\dalyj\Documents\Design\Images\Icons\equipment-icons-tileset.png")
val doodadPalette = Palette.bySize(doodadFile, Config.tileSize, Config.tileSize)
val doodads = doodadPalette.images.map(d => {
val view = new ImageView(d.croppedImage())
val doodads = tileset.doodadTiles.map(d => {
val view = new ImageView(d.icon.croppedImage())
view.delegate
})
doodadSelector.children.clear()

View File

@ -209,7 +209,7 @@ class TilesetBuilder extends Savable {
def setB(): Unit = {
currTileset.b.value = getSelected(bChooser)
bPalette = if (getSelected(bChooser) == null) IndexedSeq() else AutoTilePalette.basic(getSelected(bChooser), Config.tileSize).tiles
bPalette = if (getSelected(bChooser) == null) IndexedSeq() else AutoTilePalette.partitioned(getSelected(bChooser), 2, Config.tileSize).tiles
if (bPalette.size != currTileset.bSize()) {
val priorSize = currTileset.a1Size() + currTileset.a2Size() + currTileset.a3Size() + currTileset.a4Size() + currTileset.a5Size()
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.bSize())
@ -222,7 +222,7 @@ class TilesetBuilder extends Savable {
def setC(): Unit = {
currTileset.c.value = getSelected(cChooser)
cPalette = if (getSelected(cChooser) == null) IndexedSeq() else AutoTilePalette.basic(getSelected(cChooser), Config.tileSize).tiles
cPalette = if (getSelected(cChooser) == null) IndexedSeq() else AutoTilePalette.partitioned(getSelected(cChooser), 2, Config.tileSize).tiles
if (cPalette.size != currTileset.cSize()) {
val priorSize = currTileset.a1Size() + currTileset.a2Size() + currTileset.a3Size() + currTileset.a4Size() + currTileset.a5Size() + currTileset.bSize()
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.cSize())

View File

@ -228,11 +228,29 @@ class BasicTilePalette(val palette: Palette, val size: Int) extends AutoTilePale
def tiles = palette.images.map(new BasicTile(_))
}
class PartitionedTilePalette(val palette: Palette, val parts: Int, val size: Int) extends AutoTilePalette {
val subwidth = palette.numAcross / parts
def this(file: File, parts: Int, size: Int = 48) = this(Palette.bySize(new FileInputStream(file), size, size), parts, size)
def apply(x: Int, y: Int) = {
val yy = y % palette.numDown
val xx = (y / palette.numDown) * subwidth
new BasicTile(palette(xx, yy))
}
def tiles = {
val tiles = palette.images.map(new BasicTile(_))
val windows = tiles.sliding(subwidth, subwidth).toSeq
(0 until parts).flatMap(i => windows.drop(i).sliding(1, parts).flatten).flatten
}
}
object AutoTilePalette {
def a2(file: File, size: Int = 48) = new AutoFloorTilePalette(file, size)
def a3(file: File, size: Int = 48) = new AutoWallTilePalette(file, size)
def a4(file: File, size: Int = 48) = new AutoComboTilePalette(file, size)
def basic(file: File, size: Int = 48) = new BasicTilePalette(file, size)
def partitioned(file: File, parts: Int = 2, size: Int = 48) = new PartitionedTilePalette(file, parts, size)
}
import scalafx.Includes._

View File

@ -13,7 +13,7 @@ class GameMap(val width: Int, val height: Int, val tileset: Tileset) {
val ostream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
ostream.writeInt(width)
ostream.writeInt(height)
ostream.writeObject(tileset.token.a2)// Tileset
//ostream.writeObject(tileset.token.a2)// Tileset
val tileIndices = tileset.groundTiles.zipWithIndex.toMap
tiles.foreach(t => ostream.writeInt(tileIndices(t)))
//ostream.writeObject(tiles.map(tileIndices(_)).mkString(" "))
@ -31,7 +31,10 @@ object GameMap {
val istream = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))
val width = istream.readInt()
val height = istream.readInt()
val tileset = new Tileset(new TilesetToken("Tileset", null, istream.readObject().toString, null, null, null, null, null, IndexedSeq()))
val dir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Data")
val resourceDir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Resources\tilesets")
val tokens = YamlHelper.extractSeq[TilesetToken](new FileInputStream(new File(dir, "Tilesets.yaml"))).map(t => (t.name, t)).toMap
val tileset = tokens("Outside").load(resourceDir)
val indices = for (y <- 0 until height; x <- 0 until width) yield istream.readInt()
val map = new GameMap(width, height, tileset)
val tiles = indices.map(i => tileset.groundTiles(i))

View File

@ -5,14 +5,9 @@ import java.io._
import fmon.Config
import fmon.draw.tile._
class Tileset(val token: TilesetToken) {
val groundTiles: IndexedSeq[AutoTile] = {
val file = new File(token.a2)
val palette = new AutoFloorTilePalette(file, Config.tileSize)
for (y <- 0 until 4; x <- 0 until 8) yield {
palette(x, y)
}
}
class Tileset(val groundTiles: IndexedSeq[AutoTile], val doodadTiles: IndexedSeq[AutoTile], val info: IndexedSeq[TileInfo]) {
def groundInfo(index: Int) = info(index)
def doodadTiles(index: Int) = info(index - groundTiles.size)
}
case class TileInfo(
@ -35,5 +30,18 @@ case class TilesetToken(
val c: String,
val info: IndexedSeq[TileInfo]) {
def load(dir: File): Tileset = {
val a1Tiles = AutoTilePalette.a2(new File(dir, a1), Config.tileSize).tiles
val a2Tiles = AutoTilePalette.a2(new File(dir, a2), Config.tileSize).tiles
val a3Tiles = AutoTilePalette.a3(new File(dir, a3), Config.tileSize).tiles
val a4Tiles = AutoTilePalette.a4(new File(dir, a4), Config.tileSize).tiles
val a5Tiles = AutoTilePalette.basic(new File(dir, a5), Config.tileSize).tiles
val groundTiles = a1Tiles ++ a2Tiles ++ a3Tiles ++ a4Tiles ++ a5Tiles
val bTiles = AutoTilePalette.partitioned(new File(dir, b), 2, Config.tileSize).tiles
val cTiles = AutoTilePalette.partitioned(new File(dir, c), 2, Config.tileSize).tiles
val doodadTiles = bTiles ++ cTiles
new Tileset(groundTiles, doodadTiles, info)
}
override def toString = name
}