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:
@@ -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._
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user