From 0ff64797d91dbe494f0a54248ee10041f809f28a Mon Sep 17 00:00:00 2001 From: James Daly Date: Sun, 14 Jul 2019 22:27:22 -0400 Subject: [PATCH] Adjusted the tileset class to have ground and doodad tiles and made it so that doodad tiles get ripped into left and right halves --- Builder/src/fmon/builder/MapBuilder.scala | 16 +++++++------ Builder/src/fmon/builder/TilesetBuilder.scala | 4 ++-- .../src/fmon/draw/tile/AutoFloorTile.scala | 18 ++++++++++++++ FakeMon/src/fmon/world/GameMap.scala | 7 ++++-- FakeMon/src/fmon/world/Tileset.scala | 24 ++++++++++++------- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Builder/src/fmon/builder/MapBuilder.scala b/Builder/src/fmon/builder/MapBuilder.scala index 2f4e22e..6fd508a 100644 --- a/Builder/src/fmon/builder/MapBuilder.scala +++ b/Builder/src/fmon/builder/MapBuilder.scala @@ -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() diff --git a/Builder/src/fmon/builder/TilesetBuilder.scala b/Builder/src/fmon/builder/TilesetBuilder.scala index a063c0d..f0bb6ac 100644 --- a/Builder/src/fmon/builder/TilesetBuilder.scala +++ b/Builder/src/fmon/builder/TilesetBuilder.scala @@ -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()) diff --git a/FakeMon/src/fmon/draw/tile/AutoFloorTile.scala b/FakeMon/src/fmon/draw/tile/AutoFloorTile.scala index 8c2fe37..c0bc18c 100644 --- a/FakeMon/src/fmon/draw/tile/AutoFloorTile.scala +++ b/FakeMon/src/fmon/draw/tile/AutoFloorTile.scala @@ -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._ diff --git a/FakeMon/src/fmon/world/GameMap.scala b/FakeMon/src/fmon/world/GameMap.scala index fe9b40f..362a665 100644 --- a/FakeMon/src/fmon/world/GameMap.scala +++ b/FakeMon/src/fmon/world/GameMap.scala @@ -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)) diff --git a/FakeMon/src/fmon/world/Tileset.scala b/FakeMon/src/fmon/world/Tileset.scala index f590410..b954675 100644 --- a/FakeMon/src/fmon/world/Tileset.scala +++ b/FakeMon/src/fmon/world/Tileset.scala @@ -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 } \ No newline at end of file