Added a tileset builder
This commit is contained in:
parent
07df031670
commit
807970db5e
@ -69,10 +69,7 @@ class AnimationBuilder extends Savable {
|
||||
fileChooser.items = imgFiles
|
||||
fileChooser.selectionModel().selectedIndex.onChange(selectImageFile)
|
||||
|
||||
fileChooser.converter = new StringConverter[File] {
|
||||
override def toString(f: File) = f.getName
|
||||
override def fromString(s: String) = new File(s)
|
||||
}
|
||||
fileChooser.converter = FilenameConverter
|
||||
val dir = new File(imgdir)
|
||||
imgFiles ++= dir.listFiles()
|
||||
|
||||
|
9
Builder/src/fmon/builder/FilenameConverter.scala
Normal file
9
Builder/src/fmon/builder/FilenameConverter.scala
Normal file
@ -0,0 +1,9 @@
|
||||
package fmon.builder
|
||||
|
||||
import java.io.File
|
||||
import scalafx.util.StringConverter
|
||||
|
||||
object FilenameConverter extends StringConverter[File] {
|
||||
override def toString(f: File) = if (f != null) f.getName else "<none>"
|
||||
override def fromString(s: String) = if (s == "<none>") null else new File(s)
|
||||
}
|
@ -62,7 +62,7 @@ class MapBuilder {
|
||||
|
||||
@FXML
|
||||
def initialize(): Unit = {
|
||||
tileset = new Tileset(new TilesetToken(raw"C:\Users\dalyj\Documents\Design\Images\AutoTiles\tilea2.png"))
|
||||
tileset = new Tileset(new TilesetToken("Tileset", null, raw"C:\Users\dalyj\Documents\Design\Images\AutoTiles\tilea2.png", null, null, null, null, null, IndexedSeq()))
|
||||
level = new GameMap(10, 10, tileset)
|
||||
setup()
|
||||
}
|
||||
|
92
Builder/src/fmon/builder/TilesetBuilder.fxml
Normal file
92
Builder/src/fmon/builder/TilesetBuilder.fxml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.TilePane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<SplitPane dividerPositions="0.3110367892976589, 0.5953177257525084" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmon.builder.TilesetBuilder">
|
||||
<items>
|
||||
<VBox>
|
||||
<children>
|
||||
<ListView fx:id="tilesetList" />
|
||||
<Button mnemonicParsing="false" onAction="#addTileset" text="+" />
|
||||
</children>
|
||||
</VBox>
|
||||
<GridPane hgap="2.0" vgap="2.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="72.0" minWidth="10.0" prefWidth="54.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="105.0" minWidth="10.0" prefWidth="105.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<ComboBox fx:id="a1Chooser" onAction="#setA1" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<Label text="Tiles A1" GridPane.rowIndex="1" />
|
||||
<Label text="Tiles A2" GridPane.rowIndex="2" />
|
||||
<Label text="Tiles A3" GridPane.rowIndex="3" />
|
||||
<Label text="Tiles A4" GridPane.rowIndex="4" />
|
||||
<Label text="Tiles A5" GridPane.rowIndex="5" />
|
||||
<Label text="Tiles B" GridPane.rowIndex="6" />
|
||||
<Label text="Tiles C" GridPane.rowIndex="7" />
|
||||
<ComboBox fx:id="a2Chooser" onAction="#setA2" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||
<ComboBox fx:id="a3Chooser" onAction="#setA3" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||
<ComboBox fx:id="a4Chooser" onAction="#setA4" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||
<ComboBox fx:id="a5Chooser" onAction="#setA5" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||
<ComboBox fx:id="bChooser" onAction="#setB" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="6" />
|
||||
<ComboBox fx:id="cChooser" onAction="#setC" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="7" />
|
||||
<Label text="Name" />
|
||||
<TextField fx:id="nameField" onAction="#setName" promptText="Tileset Name" GridPane.columnIndex="1" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefWidth="160.0">
|
||||
<items>
|
||||
<ScrollPane>
|
||||
<content>
|
||||
<TilePane fx:id="tileView" hgap="1.0" prefColumns="8" vgap="1.0">
|
||||
<padding>
|
||||
<Insets bottom="1.0" left="1.0" right="1.0" top="1.0" />
|
||||
</padding></TilePane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<ScrollPane>
|
||||
<content>
|
||||
<VBox spacing="2.0">
|
||||
<children>
|
||||
<CheckBox fx:id="doesPassNorth" mnemonicParsing="false" onAction="#updateTile" text="Pass North" />
|
||||
<CheckBox fx:id="doesPassEast" mnemonicParsing="false" onAction="#updateTile" text="Pass East" />
|
||||
<CheckBox fx:id="doesPassSouth" mnemonicParsing="false" onAction="#updateTile" text="Pass South" />
|
||||
<CheckBox fx:id="doesPassWest" mnemonicParsing="false" onAction="#updateTile" text="Pass West" />
|
||||
<CheckBox fx:id="isCounter" mnemonicParsing="false" onAction="#updateTile" text="Talk Throuh (Counter)" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</items>
|
||||
</SplitPane>
|
319
Builder/src/fmon/builder/TilesetBuilder.scala
Normal file
319
Builder/src/fmon/builder/TilesetBuilder.scala
Normal file
@ -0,0 +1,319 @@
|
||||
package fmon.builder
|
||||
|
||||
import java.io._
|
||||
|
||||
import javafx.application.Application
|
||||
import javafx.fxml.FXML
|
||||
import javafx.fxml.FXMLLoader
|
||||
import javafx.fxml.JavaFXBuilderFactory
|
||||
import javafx.scene.{control => jfxsc, layout => jfxsl, Parent, Scene}
|
||||
import javafx.stage.Stage
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.beans.property._
|
||||
import scalafx.collections.ObservableBuffer
|
||||
import scalafx.scene.control._
|
||||
import scalafx.scene.image.ImageView
|
||||
import scalafx.scene.input.MouseEvent
|
||||
import scalafx.scene.paint.Color
|
||||
import scalafx.scene.layout._
|
||||
|
||||
import fmon.Config
|
||||
import fmon.draw.tile.{AutoTile, AutoTilePalette}
|
||||
import fmon.util.YamlHelper
|
||||
import fmon.world.{Tileset, TileInfo, TilesetToken}
|
||||
|
||||
class ObsTileset(name_ : String) {
|
||||
val name = new StringProperty(this, "name", name_)
|
||||
val a1 = new ObjectProperty[File](this, "a1", null)
|
||||
val a2 = new ObjectProperty[File](this, "a2", null)
|
||||
val a3 = new ObjectProperty[File](this, "a3", null)
|
||||
val a4 = new ObjectProperty[File](this, "a4", null)
|
||||
val a5 = new ObjectProperty[File](this, "a5", null)
|
||||
|
||||
val b = new ObjectProperty[File](this, "b", null)
|
||||
val c = new ObjectProperty[File](this, "c", null)
|
||||
|
||||
val a1Size = new IntegerProperty(this, "a1size", 0)
|
||||
val a2Size = new IntegerProperty(this, "a2size", 0)
|
||||
val a3Size = new IntegerProperty(this, "a3size", 0)
|
||||
val a4Size = new IntegerProperty(this, "a4size", 0)
|
||||
val a5Size = new IntegerProperty(this, "a5size", 0)
|
||||
val bSize = new IntegerProperty(this, "bsize", 0)
|
||||
val cSize = new IntegerProperty(this, "csize", 0)
|
||||
|
||||
val tileInfo = ObservableBuffer[TileInfo]()
|
||||
|
||||
def toToken = {
|
||||
def nm(file: File) = if (file != null) file.getName else null
|
||||
println(tileInfo.size)
|
||||
TilesetToken(name(), nm(a1()), nm(a2()), nm(a3()), nm(a4()), nm(a5()), nm(b()), nm(c()), IndexedSeq(tileInfo: _*))
|
||||
}
|
||||
|
||||
override def toString = name()
|
||||
}
|
||||
|
||||
class TilesetBuilder extends Savable {
|
||||
@FXML var tilesetList: jfxsc.ListView[ObsTileset] = _
|
||||
|
||||
@FXML var nameField: jfxsc.TextField = _
|
||||
@FXML var a1Chooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var a2Chooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var a3Chooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var a4Chooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var a5Chooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var bChooser: jfxsc.ComboBox[File] = _
|
||||
@FXML var cChooser: jfxsc.ComboBox[File] = _
|
||||
|
||||
@FXML var tileView: jfxsl.TilePane = _
|
||||
|
||||
@FXML var doesPassNorth: jfxsc.CheckBox = _
|
||||
@FXML var doesPassEast: jfxsc.CheckBox = _
|
||||
@FXML var doesPassSouth: jfxsc.CheckBox = _
|
||||
@FXML var doesPassWest: jfxsc.CheckBox = _
|
||||
@FXML var isCounter: jfxsc.CheckBox = _
|
||||
|
||||
val tilesets = ObservableBuffer[ObsTileset]()
|
||||
|
||||
var a1Palette = IndexedSeq[AutoTile]()
|
||||
var a2Palette = IndexedSeq[AutoTile]()
|
||||
var a3Palette = IndexedSeq[AutoTile]()
|
||||
var a4Palette = IndexedSeq[AutoTile]()
|
||||
var a5Palette = IndexedSeq[AutoTile]()
|
||||
var bPalette = IndexedSeq[AutoTile]()
|
||||
var cPalette = IndexedSeq[AutoTile]()
|
||||
|
||||
val resourceDir = new File(raw"C:\Users\James\Documents\Design\Project\Progena\Resources\tilesets")
|
||||
val files = resourceDir.listFiles()
|
||||
val filenames = files.map(f => (f.getName(), f)).toMap
|
||||
|
||||
var currTileIndex = 0
|
||||
|
||||
def currTileset = getSelected(tilesetList)
|
||||
|
||||
@FXML
|
||||
def initialize(): Unit = {
|
||||
tilesetList.items = tilesets
|
||||
tilesetList.selectionModel().selectedIndex.onChange(selectionChange)
|
||||
a1Chooser.converter = FilenameConverter
|
||||
a2Chooser.converter = FilenameConverter
|
||||
a3Chooser.converter = FilenameConverter
|
||||
a4Chooser.converter = FilenameConverter
|
||||
a5Chooser.converter = FilenameConverter
|
||||
bChooser.converter = FilenameConverter
|
||||
cChooser.converter = FilenameConverter
|
||||
|
||||
a1Chooser.items() ++= null +: files.filter(f => f.getName.endsWith("A1.png"))
|
||||
a2Chooser.items() ++= null +: files.filter(f => f.getName.endsWith("A2.png"))
|
||||
a3Chooser.items() ++= null +: files.filter(f => f.getName.endsWith("A3.png"))
|
||||
a4Chooser.items() ++= null +: files.filter(f => f.getName.endsWith("A4.png"))
|
||||
a5Chooser.items() ++= null +: files.filter(f => f.getName.endsWith("A5.png"))
|
||||
bChooser.items() ++= null +: files.filter(f => f.getName.endsWith("B.png"))
|
||||
cChooser.items() ++= null +: files.filter(f => f.getName.endsWith("C.png"))
|
||||
|
||||
println(files.size)
|
||||
}
|
||||
|
||||
def addTileset(): Unit = {
|
||||
tilesets += new ObsTileset("Tileset")
|
||||
tilesetList.selectionModel().selectLast()
|
||||
}
|
||||
|
||||
def selectionChange(): Unit = {
|
||||
val ts = getSelected(tilesetList)
|
||||
nameField.text = ts.name()
|
||||
|
||||
def safeSelect(box: ComboBox[File], file: File) = {
|
||||
box.selectionModel().clearSelection()
|
||||
box.selectionModel().select(file)
|
||||
}
|
||||
|
||||
safeSelect(a1Chooser, ts.a1())
|
||||
safeSelect(a2Chooser, ts.a2())
|
||||
safeSelect(a3Chooser, ts.a3())
|
||||
safeSelect(a4Chooser, ts.a4())
|
||||
safeSelect(a5Chooser, ts.a5())
|
||||
safeSelect(bChooser, ts.b())
|
||||
safeSelect(cChooser, ts.c())
|
||||
|
||||
}
|
||||
|
||||
def setName(): Unit = {
|
||||
getSelected(tilesetList).name.value = nameField.text()
|
||||
tilesetList.refresh()
|
||||
}
|
||||
|
||||
def setA1(): Unit = {
|
||||
currTileset.a1.value = getSelected(a1Chooser)
|
||||
a1Palette = if (getSelected(a1Chooser) == null) IndexedSeq() else AutoTilePalette.a2(getSelected(a1Chooser), Config.tileSize).tiles
|
||||
if (a1Palette.size != currTileset.a1Size()) {
|
||||
currTileset.tileInfo.removeRange(0, currTileset.a1Size())
|
||||
currTileset.a1Size() = a1Palette.size
|
||||
val info = a1Palette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(0, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setA2(): Unit = {
|
||||
currTileset.a2.value = getSelected(a2Chooser)
|
||||
a2Palette = if (getSelected(a2Chooser) == null) IndexedSeq() else AutoTilePalette.a2(getSelected(a2Chooser), Config.tileSize).tiles
|
||||
if (a2Palette.size != currTileset.a2Size()) {
|
||||
val priorSize = currTileset.a2Size()
|
||||
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.a2Size())
|
||||
currTileset.a2Size() = a1Palette.size
|
||||
val info = a2Palette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setA3(): Unit = {
|
||||
currTileset.a3.value = getSelected(a3Chooser)
|
||||
a3Palette = if (getSelected(a3Chooser) == null) IndexedSeq() else AutoTilePalette.a3(getSelected(a3Chooser), Config.tileSize).tiles
|
||||
if (a3Palette.size != currTileset.a3Size()) {
|
||||
val priorSize = currTileset.a1Size() + currTileset.a2Size()
|
||||
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.a3Size())
|
||||
currTileset.a3Size() = a1Palette.size
|
||||
val info = a3Palette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setA4(): Unit = {
|
||||
currTileset.a4.value = getSelected(a4Chooser)
|
||||
a4Palette = if (getSelected(a4Chooser) == null) IndexedSeq() else AutoTilePalette.a4(getSelected(a4Chooser), Config.tileSize).tiles
|
||||
if (a4Palette.size != currTileset.a4Size()) {
|
||||
val priorSize = currTileset.a1Size() + currTileset.a2Size() + currTileset.a3Size()
|
||||
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.a4Size())
|
||||
currTileset.a4Size() = a4Palette.size
|
||||
val info = a4Palette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setA5(): Unit = {
|
||||
currTileset.a5.value = getSelected(a5Chooser)
|
||||
a5Palette = if (getSelected(a5Chooser) == null) IndexedSeq() else AutoTilePalette.basic(getSelected(a5Chooser), Config.tileSize).tiles
|
||||
if (a5Palette.size != currTileset.a5Size()) {
|
||||
val priorSize = currTileset.a1Size() + currTileset.a2Size() + currTileset.a3Size() + currTileset.a4Size()
|
||||
currTileset.tileInfo.removeRange(priorSize, priorSize + currTileset.a5Size())
|
||||
currTileset.a5Size() = a5Palette.size
|
||||
val info = a5Palette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setB(): Unit = {
|
||||
currTileset.b.value = getSelected(bChooser)
|
||||
bPalette = if (getSelected(bChooser) == null) IndexedSeq() else AutoTilePalette.basic(getSelected(bChooser), 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())
|
||||
currTileset.bSize() = bPalette.size
|
||||
val info = bPalette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def setC(): Unit = {
|
||||
currTileset.c.value = getSelected(cChooser)
|
||||
cPalette = if (getSelected(cChooser) == null) IndexedSeq() else AutoTilePalette.basic(getSelected(cChooser), 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())
|
||||
currTileset.cSize() = cPalette.size
|
||||
val info = cPalette.map(_ => allPassInfo)
|
||||
currTileset.tileInfo.insert(priorSize, info : _*)
|
||||
}
|
||||
updateTileView()
|
||||
}
|
||||
|
||||
def updateTileView(): Unit = {
|
||||
tileView.children.clear()
|
||||
val tiles = a1Palette ++ a2Palette ++ a3Palette ++ a4Palette ++ a5Palette ++ bPalette ++ cPalette
|
||||
tileView.children ++= tiles.zipWithIndex.map{case (t, i) => new ImageView(t.icon.croppedImage()){
|
||||
handleEvent(MouseEvent.Any) {
|
||||
e: MouseEvent => if (e.eventType == MouseEvent.MouseClicked) {
|
||||
currTileIndex = i
|
||||
setTile(currTileset.tileInfo(i))
|
||||
}
|
||||
}
|
||||
}.delegate}
|
||||
}
|
||||
|
||||
def setTile(info: TileInfo): Unit = {
|
||||
doesPassNorth.selected = info.doesPassNorth
|
||||
doesPassEast.selected = info.doesPassEast
|
||||
doesPassSouth.selected = info.doesPassSouth
|
||||
doesPassWest.selected = info.doesPassWest
|
||||
isCounter.selected = info.isCounter
|
||||
}
|
||||
|
||||
def updateTile(): Unit = {
|
||||
currTileset.tileInfo(currTileIndex) = TileInfo(
|
||||
doesPassNorth.selected(),
|
||||
doesPassEast.selected(),
|
||||
doesPassSouth.selected(),
|
||||
doesPassWest.selected(),
|
||||
isCounter.selected())
|
||||
}
|
||||
|
||||
def saveTo(file: File): Unit = {
|
||||
val tileSeq = tilesets.map(a => a.toToken)
|
||||
YamlHelper.writeSeq(new FileOutputStream(file), tileSeq)
|
||||
}
|
||||
|
||||
def openFrom(file: File): Unit = {
|
||||
def f(name: String) = if (name != null) new File(resourceDir, name) else null
|
||||
|
||||
val tokens = YamlHelper.extractSeq[TilesetToken](new FileInputStream(file))
|
||||
tilesets.clear()
|
||||
tilesets ++= tokens.map(t=> {
|
||||
val ts = new ObsTileset(t.name)
|
||||
ts.a1.value = f(t.a1)
|
||||
ts.a2.value = f(t.a2)
|
||||
ts.a3.value = f(t.a3)
|
||||
ts.a4.value = f(t.a4)
|
||||
ts.a5.value = f(t.a5)
|
||||
ts.b.value = f(t.b)
|
||||
ts.c.value = f(t.c)
|
||||
// TODO : Individual sizes
|
||||
ts.tileInfo ++= t.info
|
||||
ts
|
||||
})
|
||||
tilesetList.refresh()
|
||||
}
|
||||
|
||||
private def allPassInfo = TileInfo(true, true, true, true, false)
|
||||
}
|
||||
|
||||
object TilesetBuilder {
|
||||
class TBA extends Application {
|
||||
override def start(primaryStage: Stage): Unit = {
|
||||
val frameLoader = new FXMLLoader(getClass.getResource("App.fxml"))
|
||||
val root: Parent = frameLoader.load()
|
||||
val controller = frameLoader.getController[App]()
|
||||
|
||||
val builderLoader = new FXMLLoader(getClass.getResource("TilesetBuilder.fxml"))
|
||||
val builder: Parent = builderLoader.load()
|
||||
val builderController = builderLoader.getController[TilesetBuilder]()
|
||||
|
||||
controller.pane.children = builder
|
||||
controller.builder = builderController
|
||||
|
||||
val scene: Scene = new Scene(root)
|
||||
primaryStage.setScene(scene)
|
||||
primaryStage.show()
|
||||
}
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
Application.launch(classOf[TBA], args: _*)
|
||||
}
|
||||
|
||||
}
|
14
Builder/src/fmon/builder/package.scala
Normal file
14
Builder/src/fmon/builder/package.scala
Normal file
@ -0,0 +1,14 @@
|
||||
package fmon
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.scene.control._
|
||||
|
||||
package object builder {
|
||||
def getSelected[T](view: ListView[T]): T = {
|
||||
view.selectionModel().selectedItem()
|
||||
}
|
||||
|
||||
def getSelected[T](view: ComboBox[T]): T = {
|
||||
view.selectionModel().selectedItem()
|
||||
}
|
||||
}
|
@ -6,4 +6,4 @@ resistMult: 0.5
|
||||
immuneMult: 0.0
|
||||
maxBoost: 6
|
||||
newday: 02:00
|
||||
tileSize: 32
|
||||
tileSize: 48
|
||||
|
@ -17,6 +17,10 @@ trait AutoTile {
|
||||
def build(dirs: Set[Direction.Value]): StillImg
|
||||
}
|
||||
|
||||
class BasicTile(val icon: StillImg) extends AutoTile {
|
||||
def build(dirs: Set[Direction.Value]) = icon
|
||||
}
|
||||
|
||||
class AutoFloorTile(val palette: Palette, val size: Int = 48) extends AutoTile {
|
||||
|
||||
def icon: StillImg = palette.apply(0, 0, 2, 2)
|
||||
@ -154,13 +158,81 @@ class AutoWallTile(val palette: Palette, val size: Int = 48) extends AutoTile {
|
||||
}
|
||||
}
|
||||
|
||||
class AutoTilePalette(val palette: Palette, val size: Int) {
|
||||
trait AutoTilePalette {
|
||||
def apply(x: Int, y: Int): AutoTile
|
||||
def tiles: IndexedSeq[AutoTile]
|
||||
}
|
||||
|
||||
class AutoFloorTilePalette(val palette: Palette, val size: Int) extends AutoTilePalette {
|
||||
final val TileWidth = 2
|
||||
final val TileHeight = 3
|
||||
|
||||
def this(file: File, size: Int = 48) = this(Palette.bySize(new FileInputStream(file), size, size), size)
|
||||
|
||||
def apply(x: Int, y: Int) = {
|
||||
val img = palette.apply(x * 2, y * 3, 2, 3).croppedImage()
|
||||
new AutoFloorTile(new Palette(img, 4, 6), size)
|
||||
val img = palette.apply(x * TileWidth, y * TileHeight, TileWidth, TileHeight).croppedImage()
|
||||
new AutoFloorTile(new Palette(img, 2 * TileWidth, 2 * TileHeight), size)
|
||||
}
|
||||
|
||||
def tiles = for (y <- 0 until palette.numDown / TileHeight; x <- 0 until palette.numAcross / TileWidth) yield {
|
||||
this(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
class AutoWallTilePalette(val palette: Palette, val size: Int) extends AutoTilePalette {
|
||||
final val TileWidth = 2
|
||||
final val TileHeight = 2
|
||||
|
||||
def this(file: File, size: Int = 48) = this(Palette.bySize(new FileInputStream(file), size, size), size)
|
||||
|
||||
def apply(x: Int, y: Int) = {
|
||||
val img = palette.apply(x * TileWidth, y * TileHeight, TileWidth, TileHeight).croppedImage()
|
||||
new AutoWallTile(new Palette(img, 2 * TileWidth, 2 * TileHeight), size)
|
||||
}
|
||||
|
||||
def tiles = for (y <- 0 until palette.numDown / TileHeight; x <- 0 until palette.numAcross / TileWidth) yield {
|
||||
this(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
class AutoComboTilePalette(val palette: Palette, val size: Int) extends AutoTilePalette {
|
||||
final val TileWidth = 2
|
||||
final val CeilHeight = 3
|
||||
final val WallHeight = 2
|
||||
final val TotalHeight = CeilHeight + WallHeight
|
||||
|
||||
def this(file: File, size: Int = 48) = this(Palette.bySize(new FileInputStream(file), size, size), size)
|
||||
|
||||
def apply(x: Int, y: Int) = {
|
||||
val yy = y / 2
|
||||
if (y % 2 == 0) {
|
||||
// Ceiling
|
||||
val img = palette.apply(x * TileWidth, yy * TotalHeight, TileWidth, CeilHeight).croppedImage()
|
||||
new AutoFloorTile(new Palette(img, 2 * TileWidth, 2 * CeilHeight), size)
|
||||
} else {
|
||||
// Wall
|
||||
val img = palette.apply(x * TileWidth, yy * TotalHeight + CeilHeight, TileWidth, WallHeight).croppedImage()
|
||||
new AutoWallTile(new Palette(img, 2 * TileWidth, 2 * WallHeight), size)
|
||||
}
|
||||
}
|
||||
|
||||
def tiles = for (y <- 0 until 2 * palette.numDown / TotalHeight; x <- 0 until palette.numAcross / TileWidth) yield {
|
||||
this(x, y)
|
||||
}
|
||||
}
|
||||
|
||||
class BasicTilePalette(val palette: Palette, val size: Int) extends AutoTilePalette {
|
||||
def this(file: File, size: Int = 48) = this(Palette.bySize(new FileInputStream(file), size, size), size)
|
||||
|
||||
def apply(x: Int, y: Int) = new BasicTile(palette(x, y))
|
||||
def tiles = palette.images.map(new BasicTile(_))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
import scalafx.Includes._
|
||||
@ -177,7 +249,7 @@ object AutoTileDemo extends JFXApp {
|
||||
final val MaxY = 3
|
||||
|
||||
val file = raw"C:\Users\dalyj\Documents\Design\Images\AutoTiles\tilea2.png"
|
||||
val palette = new AutoTilePalette(new File(file), 32)
|
||||
val palette = new AutoFloorTilePalette(new File(file), 32)
|
||||
val tile = palette(2, 0)
|
||||
val imgs = for (y <- 0 to MaxY; x <- 0 to MaxX) yield {
|
||||
val dirs = (x, y) match {
|
||||
|
@ -90,6 +90,10 @@ object YamlHelper {
|
||||
mapper.writeValue(source, item)
|
||||
}
|
||||
|
||||
def writeSeq[T](source: OutputStream, items: Seq[T]) = {
|
||||
mapper.writeValue(source, items)
|
||||
}
|
||||
|
||||
def writeMap[T](source: OutputStream, items: Map[String, T])(implicit m: Manifest[T]) = {
|
||||
mapper.writeValue(source, items)
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ 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(istream.readObject().toString))
|
||||
val tileset = new Tileset(new TilesetToken("Tileset", null, istream.readObject().toString, null, null, null, null, null, IndexedSeq()))
|
||||
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))
|
||||
|
@ -8,11 +8,32 @@ import fmon.draw.tile._
|
||||
class Tileset(val token: TilesetToken) {
|
||||
val groundTiles: IndexedSeq[AutoTile] = {
|
||||
val file = new File(token.a2)
|
||||
val palette = new AutoTilePalette(file, Config.tileSize)
|
||||
val palette = new AutoFloorTilePalette(file, Config.tileSize)
|
||||
for (y <- 0 until 4; x <- 0 until 8) yield {
|
||||
palette(x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case class TilesetToken(val a2: String)
|
||||
case class TileInfo(
|
||||
val doesPassNorth: Boolean,
|
||||
val doesPassEast: Boolean,
|
||||
val doesPassSouth: Boolean,
|
||||
val doesPassWest: Boolean,
|
||||
val isCounter: Boolean) {
|
||||
|
||||
}
|
||||
|
||||
case class TilesetToken(
|
||||
val name: String,
|
||||
val a1: String,
|
||||
val a2: String,
|
||||
val a3: String,
|
||||
val a4: String,
|
||||
val a5: String,
|
||||
val b: String,
|
||||
val c: String,
|
||||
val info: IndexedSeq[TileInfo]) {
|
||||
|
||||
override def toString = name
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user