[Editor] Refactor editor code (i.e. 3-space tabs) | optimize imports
This commit is contained in:
@@ -4,29 +4,32 @@ import com.bartlomiejpluta.base.editor.view.main.MainView
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
import tornadofx.*
|
||||
import tornadofx.App
|
||||
import tornadofx.DIContainer
|
||||
import tornadofx.FX
|
||||
import tornadofx.launch
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@SpringBootApplication
|
||||
open class EditorApp : App(MainView::class) {
|
||||
private lateinit var context: ConfigurableApplicationContext
|
||||
private lateinit var context: ConfigurableApplicationContext
|
||||
|
||||
override fun init() {
|
||||
this.context = SpringApplication.run(this.javaClass)
|
||||
context.autowireCapableBeanFactory.autowireBean(this)
|
||||
override fun init() {
|
||||
this.context = SpringApplication.run(this.javaClass)
|
||||
context.autowireCapableBeanFactory.autowireBean(this)
|
||||
|
||||
FX.dicontainer = object : DIContainer {
|
||||
override fun <T : Any> getInstance(type: KClass<T>): T = context.getBean(type.java)
|
||||
override fun <T : Any> getInstance(type: KClass<T>, name: String): T = context.getBean(name, type.java)
|
||||
}
|
||||
}
|
||||
FX.dicontainer = object : DIContainer {
|
||||
override fun <T : Any> getInstance(type: KClass<T>): T = context.getBean(type.java)
|
||||
override fun <T : Any> getInstance(type: KClass<T>, name: String): T = context.getBean(name, type.java)
|
||||
}
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
context.close()
|
||||
}
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
context.close()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
launch<EditorApp>(args)
|
||||
launch<EditorApp>(args)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.bartlomiejpluta.base.editor.command.model
|
||||
|
||||
interface Command {
|
||||
fun execute()
|
||||
fun execute()
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.bartlomiejpluta.base.editor.command.model
|
||||
|
||||
class SimpleCommand<T>(
|
||||
override val commandName: String,
|
||||
private val formerValue: T,
|
||||
private val value: T,
|
||||
private val execute: (T) -> Unit
|
||||
override val commandName: String,
|
||||
private val formerValue: T,
|
||||
private val value: T,
|
||||
private val execute: (T) -> Unit
|
||||
) : Undoable, Command {
|
||||
|
||||
override fun undo() {
|
||||
execute(formerValue)
|
||||
}
|
||||
override fun undo() {
|
||||
execute(formerValue)
|
||||
}
|
||||
|
||||
override fun redo() {
|
||||
execute()
|
||||
}
|
||||
override fun redo() {
|
||||
execute()
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
execute(value)
|
||||
}
|
||||
override fun execute() {
|
||||
execute(value)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.bartlomiejpluta.base.editor.command.model
|
||||
|
||||
interface Undoable {
|
||||
fun undo()
|
||||
fun redo()
|
||||
val commandName: String
|
||||
fun undo()
|
||||
fun redo()
|
||||
val commandName: String
|
||||
}
|
||||
@@ -1,71 +1,70 @@
|
||||
package com.bartlomiejpluta.base.editor.command.service
|
||||
|
||||
import com.bartlomiejpluta.base.editor.command.model.Undoable
|
||||
import org.apache.commons.logging.LogFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.*
|
||||
|
||||
@Component
|
||||
class DefaultUndoRedoService : UndoRedoService {
|
||||
private val undo: Deque<Undoable> = ArrayDeque()
|
||||
private val redo: Deque<Undoable> = ArrayDeque()
|
||||
private val undo: Deque<Undoable> = ArrayDeque()
|
||||
private val redo: Deque<Undoable> = ArrayDeque()
|
||||
|
||||
override var sizeMax = 30
|
||||
set(value) {
|
||||
if(value >= 0) {
|
||||
for(i in 0 until undo.size - value) {
|
||||
undo.removeLast()
|
||||
}
|
||||
|
||||
field = value
|
||||
override var sizeMax = 30
|
||||
set(value) {
|
||||
if (value >= 0) {
|
||||
for (i in 0 until undo.size - value) {
|
||||
undo.removeLast()
|
||||
}
|
||||
}
|
||||
|
||||
override fun push(undoable: Undoable) {
|
||||
if(undo.size == sizeMax) {
|
||||
log.debug("The max size of [undo] list has been reached. Removing the last item...")
|
||||
undo.removeLast()
|
||||
}
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("Pushing item to [undo] list: ${undoable.commandName}")
|
||||
undo.push(undoable)
|
||||
redo.clear()
|
||||
}
|
||||
override fun push(undoable: Undoable) {
|
||||
if (undo.size == sizeMax) {
|
||||
log.debug("The max size of [undo] list has been reached. Removing the last item...")
|
||||
undo.removeLast()
|
||||
}
|
||||
|
||||
override fun undo() {
|
||||
if(undo.isNotEmpty()) {
|
||||
undo.pop().let {
|
||||
log.debug("Performing undo: ${it.commandName}")
|
||||
it.undo()
|
||||
redo.push(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.debug("Pushing item to [undo] list: ${undoable.commandName}")
|
||||
undo.push(undoable)
|
||||
redo.clear()
|
||||
}
|
||||
|
||||
override fun redo() {
|
||||
if(redo.isNotEmpty()) {
|
||||
redo.pop().let {
|
||||
log.debug("Performing redo: ${it.commandName}")
|
||||
it.redo()
|
||||
undo.push(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun undo() {
|
||||
if (undo.isNotEmpty()) {
|
||||
undo.pop().let {
|
||||
log.debug("Performing undo: ${it.commandName}")
|
||||
it.undo()
|
||||
redo.push(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val lastUndoable: Undoable?
|
||||
get() = undo.last
|
||||
override fun redo() {
|
||||
if (redo.isNotEmpty()) {
|
||||
redo.pop().let {
|
||||
log.debug("Performing redo: ${it.commandName}")
|
||||
it.redo()
|
||||
undo.push(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val lastRedoable: Undoable?
|
||||
get() = redo.last
|
||||
override val lastUndoable: Undoable?
|
||||
get() = undo.last
|
||||
|
||||
override val undoCommandName: String
|
||||
get() = undo.last?.commandName ?: ""
|
||||
override val lastRedoable: Undoable?
|
||||
get() = redo.last
|
||||
|
||||
override val redoCommandName: String
|
||||
get() = redo.last?.commandName ?: ""
|
||||
override val undoCommandName: String
|
||||
get() = undo.last?.commandName ?: ""
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(DefaultUndoRedoService::class.java)
|
||||
}
|
||||
override val redoCommandName: String
|
||||
get() = redo.last?.commandName ?: ""
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(DefaultUndoRedoService::class.java)
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ package com.bartlomiejpluta.base.editor.command.service
|
||||
import com.bartlomiejpluta.base.editor.command.model.Undoable
|
||||
|
||||
interface UndoRedoService {
|
||||
fun push(undoable: Undoable)
|
||||
fun undo()
|
||||
fun redo()
|
||||
fun push(undoable: Undoable)
|
||||
fun undo()
|
||||
fun redo()
|
||||
|
||||
val lastUndoable: Undoable?
|
||||
val lastRedoable: Undoable?
|
||||
val undoCommandName: String
|
||||
val redoCommandName: String
|
||||
var sizeMax: Int
|
||||
val lastUndoable: Undoable?
|
||||
val lastRedoable: Undoable?
|
||||
val undoCommandName: String
|
||||
val redoCommandName: String
|
||||
var sizeMax: Int
|
||||
}
|
||||
@@ -8,15 +8,15 @@ import tornadofx.Controller
|
||||
|
||||
@Component
|
||||
class MapController : Controller() {
|
||||
private val undoRedoService: UndoRedoService by inject()
|
||||
private val tileSetController: TileSetController by inject()
|
||||
private val undoRedoService: UndoRedoService by inject()
|
||||
private val tileSetController: TileSetController by inject()
|
||||
|
||||
private val map1 = GameMap(tileSetController.tileset, 20, 20)
|
||||
private val map1 = GameMap(tileSetController.tileset, 20, 20)
|
||||
|
||||
private val map2 = GameMap(tileSetController.tileset, 50, 50)
|
||||
private val map2 = GameMap(tileSetController.tileset, 50, 50)
|
||||
|
||||
fun getMap(id: Int) = when(id) {
|
||||
1 -> map1
|
||||
else -> map2
|
||||
}
|
||||
fun getMap(id: Int) = when (id) {
|
||||
1 -> map1
|
||||
else -> map2
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,5 @@ import tornadofx.Controller
|
||||
|
||||
@Component
|
||||
class TileSetController : Controller() {
|
||||
val tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8)
|
||||
val tileset = TileSet(resources.image("/textures/tileset.png"), 160, 8)
|
||||
}
|
||||
@@ -2,35 +2,37 @@ package com.bartlomiejpluta.base.editor.model.map.brush
|
||||
|
||||
import com.bartlomiejpluta.base.editor.model.tileset.Tile
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import tornadofx.*
|
||||
import tornadofx.getValue
|
||||
import tornadofx.observableListOf
|
||||
import tornadofx.setValue
|
||||
|
||||
class Brush(newBrush: Array<Array<Tile>>) {
|
||||
val brush = observableListOf<Tile>()
|
||||
val rowsProperty = SimpleIntegerProperty(this, "", 0)
|
||||
var rows by rowsProperty
|
||||
val columnsProperty = SimpleIntegerProperty(0)
|
||||
var columns by columnsProperty
|
||||
val centerRowProperty = SimpleIntegerProperty(0)
|
||||
var centerRow by centerRowProperty
|
||||
val centerColumnProperty = SimpleIntegerProperty(0)
|
||||
var centerColumn by centerColumnProperty
|
||||
val brush = observableListOf<Tile>()
|
||||
val rowsProperty = SimpleIntegerProperty(this, "", 0)
|
||||
var rows by rowsProperty
|
||||
val columnsProperty = SimpleIntegerProperty(0)
|
||||
var columns by columnsProperty
|
||||
val centerRowProperty = SimpleIntegerProperty(0)
|
||||
var centerRow by centerRowProperty
|
||||
val centerColumnProperty = SimpleIntegerProperty(0)
|
||||
var centerColumn by centerColumnProperty
|
||||
|
||||
init {
|
||||
rowsProperty.value = newBrush.size
|
||||
init {
|
||||
rowsProperty.value = newBrush.size
|
||||
|
||||
newBrush.forEach { brush.addAll(it) }
|
||||
newBrush.forEach { brush.addAll(it) }
|
||||
|
||||
if(rowsProperty.value > 0) {
|
||||
columns = brush.size / rowsProperty.value
|
||||
}
|
||||
if (rowsProperty.value > 0) {
|
||||
columns = brush.size / rowsProperty.value
|
||||
}
|
||||
|
||||
centerRow = rows/2
|
||||
centerColumn = columns/2
|
||||
}
|
||||
centerRow = rows / 2
|
||||
centerColumn = columns / 2
|
||||
}
|
||||
|
||||
fun forEach(consumer: (row: Int, column: Int, tile: Tile) -> Unit) {
|
||||
brush.forEachIndexed { id, tile ->
|
||||
consumer(id / columns, id % columns, tile)
|
||||
}
|
||||
}
|
||||
fun forEach(consumer: (row: Int, column: Int, tile: Tile) -> Unit) {
|
||||
brush.forEachIndexed { id, tile ->
|
||||
consumer(id / columns, id % columns, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package com.bartlomiejpluta.base.editor.model.map.layer
|
||||
import javafx.beans.property.StringProperty
|
||||
|
||||
interface Layer {
|
||||
val name: String
|
||||
val nameProperty: StringProperty
|
||||
val name: String
|
||||
val nameProperty: StringProperty
|
||||
}
|
||||
@@ -2,14 +2,13 @@ package com.bartlomiejpluta.base.editor.model.map.layer
|
||||
|
||||
import com.bartlomiejpluta.base.editor.model.tileset.Tile
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
|
||||
import tornadofx.*
|
||||
import tornadofx.getValue
|
||||
|
||||
class TileLayer(name: String, val layer: Array<Array<Tile?>>) : Layer {
|
||||
|
||||
fun setTile(row: Int, column: Int, tile: Tile?) = apply { layer[row][column] = tile }
|
||||
fun setTile(row: Int, column: Int, tile: Tile?) = apply { layer[row][column] = tile }
|
||||
|
||||
override val nameProperty = SimpleStringProperty(name)
|
||||
override val nameProperty = SimpleStringProperty(name)
|
||||
|
||||
override val name: String by nameProperty
|
||||
override val name: String by nameProperty
|
||||
}
|
||||
@@ -7,37 +7,37 @@ import tornadofx.observableListOf
|
||||
|
||||
|
||||
class GameMap(val tileSet: TileSet, val rows: Int, val columns: Int) {
|
||||
val layers = observableListOf<Layer>()
|
||||
val layers = observableListOf<Layer>()
|
||||
|
||||
val width = columns * tileSet.tileWidth
|
||||
val width = columns * tileSet.tileWidth
|
||||
|
||||
val height = columns * tileSet.tileWidth
|
||||
val height = columns * tileSet.tileWidth
|
||||
|
||||
fun createTileLayer(name: String, tile: Int) = createTileLayer(name).apply {
|
||||
val layerId = layers.size - 1
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
setTile(layerId, row, column, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun createTileLayer(name: String, tile: Int) = createTileLayer(name).apply {
|
||||
val layerId = layers.size - 1
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
setTile(layerId, row, column, tile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createTileLayer(name: String, tileRow: Int, tileColumn: Int) = createTileLayer(name).apply {
|
||||
val layerId = layers.size - 1
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
setTile(layerId, row, column, tileRow, tileColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun createTileLayer(name: String, tileRow: Int, tileColumn: Int) = createTileLayer(name).apply {
|
||||
val layerId = layers.size - 1
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
setTile(layerId, row, column, tileRow, tileColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createTileLayer(name: String) = apply { layers.add(TileLayer(name, Array(rows) { Array(columns) { null } })) }
|
||||
fun createTileLayer(name: String) = apply { layers.add(TileLayer(name, Array(rows) { Array(columns) { null } })) }
|
||||
|
||||
fun setTile(layer: Int, row: Int, column: Int, tile: Int) = apply {
|
||||
(layers[layer] as TileLayer).setTile(row, column, tileSet.getTile(tile))
|
||||
}
|
||||
fun setTile(layer: Int, row: Int, column: Int, tile: Int) = apply {
|
||||
(layers[layer] as TileLayer).setTile(row, column, tileSet.getTile(tile))
|
||||
}
|
||||
|
||||
fun setTile(layer: Int, row: Int, column: Int, tileRow: Int, tileColumn: Int) = apply {
|
||||
(layers[layer] as TileLayer).setTile(row, column, tileSet.getTile(tileRow, tileColumn))
|
||||
}
|
||||
fun setTile(layer: Int, row: Int, column: Int, tileRow: Int, tileColumn: Int) = apply {
|
||||
(layers[layer] as TileLayer).setTile(row, column, tileSet.getTile(tileRow, tileColumn))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,48 +8,48 @@ import javafx.scene.image.WritableImage
|
||||
|
||||
|
||||
class Tile(
|
||||
tileSet: TileSet,
|
||||
row: Int,
|
||||
column: Int,
|
||||
val image: Image,
|
||||
tileSet: TileSet,
|
||||
row: Int,
|
||||
column: Int,
|
||||
val image: Image,
|
||||
) {
|
||||
val id = row * tileSet.columns + column
|
||||
val id = row * tileSet.columns + column
|
||||
|
||||
private fun cloneImage(image: Image): Image {
|
||||
val height = image.height.toInt()
|
||||
val width = image.width.toInt()
|
||||
val pixelReader = image.pixelReader
|
||||
val writableImage = WritableImage(width, height)
|
||||
val pixelWriter = writableImage.pixelWriter
|
||||
private fun cloneImage(image: Image): Image {
|
||||
val height = image.height.toInt()
|
||||
val width = image.width.toInt()
|
||||
val pixelReader = image.pixelReader
|
||||
val writableImage = WritableImage(width, height)
|
||||
val pixelWriter = writableImage.pixelWriter
|
||||
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val color = pixelReader.getColor(x, y)
|
||||
pixelWriter.setColor(x, y, color)
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val color = pixelReader.getColor(x, y)
|
||||
pixelWriter.setColor(x, y, color)
|
||||
}
|
||||
}
|
||||
return writableImage
|
||||
}
|
||||
|
||||
fun scale(image: Image, factor: Int): Image {
|
||||
val width = image.width.toInt()
|
||||
val height = image.height.toInt()
|
||||
val output = WritableImage(width * factor, height * factor)
|
||||
|
||||
val reader: PixelReader = image.pixelReader
|
||||
val writer = output.pixelWriter
|
||||
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val argb = reader.getArgb(x, y)
|
||||
for (dy in 0 until factor) {
|
||||
for (dx in 0 until factor) {
|
||||
writer.setArgb(x * factor + dx, y * factor + dy, argb)
|
||||
}
|
||||
}
|
||||
}
|
||||
return writableImage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun scale(image: Image, factor: Int): Image {
|
||||
val width = image.width.toInt()
|
||||
val height = image.height.toInt()
|
||||
val output = WritableImage(width * factor, height * factor)
|
||||
|
||||
val reader: PixelReader = image.pixelReader
|
||||
val writer = output.pixelWriter
|
||||
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
val argb = reader.getArgb(x, y)
|
||||
for (dy in 0 until factor) {
|
||||
for (dx in 0 until factor) {
|
||||
writer.setArgb(x * factor + dx, y * factor + dy, argb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
||||
@@ -8,29 +8,37 @@ import java.nio.ByteBuffer
|
||||
|
||||
|
||||
class TileSet(private val image: Image, val rows: Int, val columns: Int) {
|
||||
val tileWidth = image.width.toInt() / columns
|
||||
val tileHeight = image.height.toInt() / rows
|
||||
val width = tileWidth * columns
|
||||
val height = tileHeight * rows
|
||||
val tileWidth = image.width.toInt() / columns
|
||||
val tileHeight = image.height.toInt() / rows
|
||||
val width = tileWidth * columns
|
||||
val height = tileHeight * rows
|
||||
|
||||
val tiles: Array<Array<Tile>> =
|
||||
Array(rows) { row -> Array(columns) { column -> cropTile(row, column) } }
|
||||
val tiles: Array<Array<Tile>> =
|
||||
Array(rows) { row -> Array(columns) { column -> cropTile(row, column) } }
|
||||
|
||||
val baseBrush: Brush
|
||||
get() = Brush(arrayOf(arrayOf(tiles[0][0])))
|
||||
val baseBrush: Brush
|
||||
get() = Brush(arrayOf(arrayOf(tiles[0][0])))
|
||||
|
||||
private fun cropTile(row: Int, column: Int): Tile {
|
||||
val reader = image.pixelReader
|
||||
val buffer = ByteBuffer.allocate(tileWidth * tileHeight * 4)
|
||||
reader.getPixels(column * tileWidth, row * tileHeight, tileWidth, tileHeight, PixelFormat.getByteBgraInstance(), buffer, 4 * tileWidth)
|
||||
val tile = WritableImage(tileWidth, tileHeight)
|
||||
val writer = tile.pixelWriter
|
||||
writer.setPixels(0, 0, tileWidth, tileHeight, PixelFormat.getByteBgraInstance(), buffer, 4 * tileWidth)
|
||||
private fun cropTile(row: Int, column: Int): Tile {
|
||||
val reader = image.pixelReader
|
||||
val buffer = ByteBuffer.allocate(tileWidth * tileHeight * 4)
|
||||
reader.getPixels(
|
||||
column * tileWidth,
|
||||
row * tileHeight,
|
||||
tileWidth,
|
||||
tileHeight,
|
||||
PixelFormat.getByteBgraInstance(),
|
||||
buffer,
|
||||
4 * tileWidth
|
||||
)
|
||||
val tile = WritableImage(tileWidth, tileHeight)
|
||||
val writer = tile.pixelWriter
|
||||
writer.setPixels(0, 0, tileWidth, tileHeight, PixelFormat.getByteBgraInstance(), buffer, 4 * tileWidth)
|
||||
|
||||
return Tile(this, row, column, tile)
|
||||
}
|
||||
return Tile(this, row, column, tile)
|
||||
}
|
||||
|
||||
fun getTile(row: Int, column: Int) = tiles[row.coerceIn(0 until rows)][column.coerceIn(0 until columns)]
|
||||
fun getTile(row: Int, column: Int) = tiles[row.coerceIn(0 until rows)][column.coerceIn(0 until columns)]
|
||||
|
||||
fun getTile(id: Int) = tiles[id / columns][id % columns]
|
||||
fun getTile(id: Int) = tiles[id / columns][id % columns]
|
||||
}
|
||||
@@ -7,12 +7,12 @@ import javafx.scene.input.MouseEvent
|
||||
|
||||
class MapMouseEvent(val row: Int, val column: Int, val type: EventType<out MouseEvent>, val button: MouseButton) {
|
||||
|
||||
companion object {
|
||||
fun of(event: MouseEvent, tileSet: TileSet) = MapMouseEvent(
|
||||
(event.y / tileSet.tileHeight).toInt(),
|
||||
(event.x / tileSet.tileWidth).toInt(),
|
||||
event.eventType,
|
||||
event.button
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
fun of(event: MouseEvent, tileSet: TileSet) = MapMouseEvent(
|
||||
(event.y / tileSet.tileHeight).toInt(),
|
||||
(event.x / tileSet.tileWidth).toInt(),
|
||||
event.eventType,
|
||||
event.button
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.bartlomiejpluta.base.editor.render.canvas.input
|
||||
|
||||
interface MapMouseEventHandler {
|
||||
fun handleMouseInput(event: MapMouseEvent)
|
||||
fun handleMouseInput(event: MapMouseEvent)
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import javafx.scene.canvas.GraphicsContext
|
||||
|
||||
class TileLayerCanvas(private val tileLayer: TileLayer) : Renderable {
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
for ((row, columns) in tileLayer.layer.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
if (tile != null) {
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
override fun render(gc: GraphicsContext) {
|
||||
for ((row, columns) in tileLayer.layer.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
if (tile != null) {
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,72 +9,72 @@ import javafx.scene.paint.Color
|
||||
|
||||
|
||||
class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderable {
|
||||
var tileSet = map.tileSet
|
||||
private var layers = map.layers
|
||||
private var rows = map.rows
|
||||
private var columns = map.columns
|
||||
private var tileWidth = tileSet.tileWidth.toDouble()
|
||||
private var tileHeight = tileSet.tileHeight.toDouble()
|
||||
private var mapWidth = map.width.toDouble()
|
||||
private var mapHeight = map.height.toDouble()
|
||||
var tileSet = map.tileSet
|
||||
private var layers = map.layers
|
||||
private var rows = map.rows
|
||||
private var columns = map.columns
|
||||
private var tileWidth = tileSet.tileWidth.toDouble()
|
||||
private var tileHeight = tileSet.tileHeight.toDouble()
|
||||
private var mapWidth = map.width.toDouble()
|
||||
private var mapHeight = map.height.toDouble()
|
||||
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height);
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height)
|
||||
|
||||
renderBackground(gc)
|
||||
renderBackground(gc)
|
||||
|
||||
layers.forEach { dispatchLayerRender(gc, it) }
|
||||
layers.forEach { dispatchLayerRender(gc, it) }
|
||||
|
||||
renderGrid(gc)
|
||||
renderGrid(gc)
|
||||
|
||||
painter.render(gc)
|
||||
}
|
||||
painter.render(gc)
|
||||
}
|
||||
|
||||
private fun dispatchLayerRender(gc: GraphicsContext, layer: Layer) {
|
||||
when (layer) {
|
||||
is TileLayer -> renderTileLayer(gc, layer)
|
||||
}
|
||||
}
|
||||
private fun dispatchLayerRender(gc: GraphicsContext, layer: Layer) {
|
||||
when (layer) {
|
||||
is TileLayer -> renderTileLayer(gc, layer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderBackground(gc: GraphicsContext) {
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
gc.fill = if ((row + column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2
|
||||
gc.fillRect(column * tileWidth, row * tileHeight, tileWidth, tileHeight)
|
||||
private fun renderBackground(gc: GraphicsContext) {
|
||||
for (row in 0 until rows) {
|
||||
for (column in 0 until columns) {
|
||||
gc.fill = if ((row + column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2
|
||||
gc.fillRect(column * tileWidth, row * tileHeight, tileWidth, tileHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderTileLayer(gc: GraphicsContext, tileLayer: TileLayer) {
|
||||
for ((row, columns) in tileLayer.layer.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
if (tile != null) {
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderTileLayer(gc: GraphicsContext, tileLayer: TileLayer) {
|
||||
for ((row, columns) in tileLayer.layer.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
if (tile != null) {
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun renderGrid(gc: GraphicsContext) {
|
||||
gc.lineWidth = 1.5
|
||||
|
||||
private fun renderGrid(gc: GraphicsContext) {
|
||||
gc.lineWidth = 1.5
|
||||
gc.strokeLine(0.0, 0.0, mapWidth, 0.0)
|
||||
gc.strokeLine(0.0, 0.0, 0.0, mapHeight)
|
||||
gc.strokeLine(mapWidth, 0.0, mapWidth, mapHeight)
|
||||
gc.strokeLine(0.0, mapHeight, mapWidth, mapHeight)
|
||||
|
||||
gc.strokeLine(0.0, 0.0, mapWidth, 0.0)
|
||||
gc.strokeLine(0.0, 0.0, 0.0, mapHeight)
|
||||
gc.strokeLine(mapWidth, 0.0, mapWidth, mapHeight)
|
||||
gc.strokeLine(0.0, mapHeight, mapWidth, mapHeight)
|
||||
for (row in 0 until rows) {
|
||||
gc.strokeLine(0.0, row * tileHeight, mapWidth, row * tileHeight)
|
||||
}
|
||||
|
||||
for (row in 0 until rows) {
|
||||
gc.strokeLine(0.0, row * tileHeight, mapWidth, row * tileHeight)
|
||||
}
|
||||
for (column in 0 until columns) {
|
||||
gc.strokeLine(column * tileWidth, 0.0, column * tileWidth, mapHeight)
|
||||
}
|
||||
}
|
||||
|
||||
for (column in 0 until columns) {
|
||||
gc.strokeLine(column * tileWidth, 0.0, column * tileWidth, mapHeight)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0)
|
||||
private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95)
|
||||
}
|
||||
companion object {
|
||||
private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0)
|
||||
private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95)
|
||||
}
|
||||
}
|
||||
@@ -4,92 +4,92 @@ import com.bartlomiejpluta.base.editor.model.tileset.Tile
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.input.MapMouseEvent
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.input.MapMouseEventHandler
|
||||
import com.bartlomiejpluta.base.editor.render.model.Renderable
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.beans.property.IntegerProperty
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.input.MouseButton
|
||||
import javafx.scene.input.MouseEvent
|
||||
|
||||
class MapPainter(
|
||||
private val map: GameMapVM,
|
||||
private val brushVM: BrushVM,
|
||||
private val selectedLayer: IntegerProperty,
|
||||
private val paintingCallback: (MapPaintingTrace) -> Unit
|
||||
private val map: GameMapVM,
|
||||
private val brushVM: BrushVM,
|
||||
private val selectedLayer: IntegerProperty,
|
||||
private val paintingCallback: (MapPaintingTrace) -> Unit
|
||||
) : Renderable, MapMouseEventHandler {
|
||||
private val tileWidth = map.tileSet.tileWidth.toDouble()
|
||||
private val tileHeight = map.tileSet.tileHeight.toDouble()
|
||||
private val tileWidth = map.tileSet.tileWidth.toDouble()
|
||||
private val tileHeight = map.tileSet.tileHeight.toDouble()
|
||||
|
||||
private var mouseRow = -1
|
||||
private var mouseColumn = -1
|
||||
private var mouseRow = -1
|
||||
private var mouseColumn = -1
|
||||
|
||||
private var currentTrace: MapPaintingTrace? = null
|
||||
private var currentTrace: MapPaintingTrace? = null
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
val alpha = gc.globalAlpha
|
||||
gc.globalAlpha = 0.4
|
||||
override fun render(gc: GraphicsContext) {
|
||||
val alpha = gc.globalAlpha
|
||||
gc.globalAlpha = 0.4
|
||||
|
||||
brushVM.forEach { row, column, tile -> renderTile(gc, tile, column, row) }
|
||||
brushVM.forEach { row, column, tile -> renderTile(gc, tile, column, row) }
|
||||
|
||||
gc.globalAlpha = alpha
|
||||
gc.globalAlpha = alpha
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderTile(gc: GraphicsContext, tile: Tile, column: Int, row: Int) {
|
||||
gc.drawImage(
|
||||
tile.image,
|
||||
tileWidth * (mouseColumn - brushVM.centerColumn + column),
|
||||
tileHeight * (mouseRow - brushVM.centerRow + row)
|
||||
)
|
||||
}
|
||||
private fun renderTile(gc: GraphicsContext, tile: Tile, column: Int, row: Int) {
|
||||
gc.drawImage(
|
||||
tile.image,
|
||||
tileWidth * (mouseColumn - brushVM.centerColumn + column),
|
||||
tileHeight * (mouseRow - brushVM.centerRow + row)
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleMouseInput(event: MapMouseEvent) {
|
||||
mouseRow = event.row
|
||||
mouseColumn = event.column
|
||||
override fun handleMouseInput(event: MapMouseEvent) {
|
||||
mouseRow = event.row
|
||||
mouseColumn = event.column
|
||||
|
||||
when (event.type) {
|
||||
MouseEvent.MOUSE_PRESSED -> beginTrace(event)
|
||||
MouseEvent.MOUSE_DRAGGED -> proceedTrace(event)
|
||||
MouseEvent.MOUSE_RELEASED -> commitTrace(event)
|
||||
}
|
||||
}
|
||||
when (event.type) {
|
||||
MouseEvent.MOUSE_PRESSED -> beginTrace(event)
|
||||
MouseEvent.MOUSE_DRAGGED -> proceedTrace(event)
|
||||
MouseEvent.MOUSE_RELEASED -> commitTrace(event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun beginTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace = MapPaintingTrace(map, "Paint trace").apply {
|
||||
brushVM.forEach { row, column, tile ->
|
||||
paint(
|
||||
selectedLayer.value,
|
||||
mouseRow - brushVM.centerRow + row,
|
||||
mouseColumn - brushVM.centerColumn + column,
|
||||
tile
|
||||
)
|
||||
}
|
||||
private fun beginTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace = MapPaintingTrace(map, "Paint trace").apply {
|
||||
brushVM.forEach { row, column, tile ->
|
||||
paint(
|
||||
selectedLayer.value,
|
||||
mouseRow - brushVM.centerRow + row,
|
||||
mouseColumn - brushVM.centerColumn + column,
|
||||
tile
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.apply {
|
||||
brushVM.forEach { row, column, tile ->
|
||||
paint(
|
||||
selectedLayer.value,
|
||||
mouseRow - brushVM.centerRow + row,
|
||||
mouseColumn - brushVM.centerColumn + column,
|
||||
tile
|
||||
)
|
||||
}
|
||||
private fun proceedTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.apply {
|
||||
brushVM.forEach { row, column, tile ->
|
||||
paint(
|
||||
selectedLayer.value,
|
||||
mouseRow - brushVM.centerRow + row,
|
||||
mouseColumn - brushVM.centerColumn + column,
|
||||
tile
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun commitTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.let {
|
||||
paintingCallback(it)
|
||||
currentTrace = null
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun commitTrace(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
currentTrace?.let {
|
||||
paintingCallback(it)
|
||||
currentTrace = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,50 +7,50 @@ import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
|
||||
|
||||
data class MapPaintingTrace(val map: GameMapVM, override val commandName: String) : Undoable {
|
||||
private val trace = mutableListOf<Element>()
|
||||
private val trace = mutableListOf<Element>()
|
||||
|
||||
fun paint(layerIndex: Int, row: Int, column: Int, tile: Tile?) {
|
||||
if (row >= map.rows || column >= map.columns || row < 0 || column < 0 || layerIndex < 0) {
|
||||
return
|
||||
}
|
||||
fun paint(layerIndex: Int, row: Int, column: Int, tile: Tile?) {
|
||||
if (row >= map.rows || column >= map.columns || row < 0 || column < 0 || layerIndex < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
val layer = (map.layers[layerIndex] as TileLayer).layer
|
||||
val formerTile = layer[row][column]
|
||||
val layer = (map.layers[layerIndex] as TileLayer).layer
|
||||
val formerTile = layer[row][column]
|
||||
|
||||
if (trace.isEmpty()) {
|
||||
trace += Element(layerIndex, row, column, formerTile, tile)
|
||||
layer[row][column] = tile
|
||||
return
|
||||
}
|
||||
if (trace.isEmpty()) {
|
||||
trace += Element(layerIndex, row, column, formerTile, tile)
|
||||
layer[row][column] = tile
|
||||
return
|
||||
}
|
||||
|
||||
val tileAlreadyPainted =
|
||||
trace.find { it.layerIndex == layerIndex && it.row == row && it.column == column } != null
|
||||
val tileAlreadyPainted =
|
||||
trace.find { it.layerIndex == layerIndex && it.row == row && it.column == column } != null
|
||||
|
||||
if (!tileAlreadyPainted) {
|
||||
trace += Element(layerIndex, row, column, formerTile, tile)
|
||||
layer[row][column] = tile
|
||||
}
|
||||
}
|
||||
if (!tileAlreadyPainted) {
|
||||
trace += Element(layerIndex, row, column, formerTile, tile)
|
||||
layer[row][column] = tile
|
||||
}
|
||||
}
|
||||
|
||||
override fun undo() {
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as TileLayer).layer[it.row][it.column] = it.formerTile
|
||||
}
|
||||
}
|
||||
override fun undo() {
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as TileLayer).layer[it.row][it.column] = it.formerTile
|
||||
}
|
||||
}
|
||||
|
||||
override fun redo() {
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as TileLayer).layer[it.row][it.column] = it.tile
|
||||
}
|
||||
}
|
||||
override fun redo() {
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as TileLayer).layer[it.row][it.column] = it.tile
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private data class Element(
|
||||
val layerIndex: Int,
|
||||
val row: Int,
|
||||
val column: Int,
|
||||
val formerTile: Tile?,
|
||||
val tile: Tile?
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
private data class Element(
|
||||
val layerIndex: Int,
|
||||
val row: Int,
|
||||
val column: Int,
|
||||
val formerTile: Tile?,
|
||||
val tile: Tile?
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -11,60 +11,65 @@ import javafx.scene.input.MouseEvent
|
||||
import javafx.scene.paint.Color
|
||||
|
||||
class TileSetCanvas(private val tileSet: TileSet, brushVM: BrushVM) : Renderable, MapMouseEventHandler {
|
||||
private val tiles = tileSet.tiles
|
||||
private var selection = TileSetSelection(tileSet, brushVM)
|
||||
private val tiles = tileSet.tiles
|
||||
private var selection = TileSetSelection(tileSet, brushVM)
|
||||
|
||||
private var mouseRow = -1
|
||||
private var mouseColumn = -1
|
||||
private var mouseRow = -1
|
||||
private var mouseColumn = -1
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height);
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height)
|
||||
|
||||
renderTiles(gc)
|
||||
selection.render(gc)
|
||||
}
|
||||
renderTiles(gc)
|
||||
selection.render(gc)
|
||||
}
|
||||
|
||||
private fun renderTiles(gc: GraphicsContext) {
|
||||
for ((row, columns) in tiles.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
gc.fill = if((row+column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2
|
||||
gc.fillRect(column * tile.image.width, row * tile.image.height, tileSet.tileWidth.toDouble(), tileSet.tileHeight.toDouble())
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun renderTiles(gc: GraphicsContext) {
|
||||
for ((row, columns) in tiles.withIndex()) {
|
||||
for ((column, tile) in columns.withIndex()) {
|
||||
gc.fill = if ((row + column) % 2 == 0) BACKGROUND_COLOR1 else BACKGROUND_COLOR2
|
||||
gc.fillRect(
|
||||
column * tile.image.width,
|
||||
row * tile.image.height,
|
||||
tileSet.tileWidth.toDouble(),
|
||||
tileSet.tileHeight.toDouble()
|
||||
)
|
||||
gc.drawImage(tile.image, column * tile.image.width, row * tile.image.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleMouseInput(event: MapMouseEvent) {
|
||||
mouseRow = event.row
|
||||
mouseColumn = event.column
|
||||
override fun handleMouseInput(event: MapMouseEvent) {
|
||||
mouseRow = event.row
|
||||
mouseColumn = event.column
|
||||
|
||||
when (event.type) {
|
||||
MouseEvent.MOUSE_PRESSED -> beginSelection(event)
|
||||
MouseEvent.MOUSE_DRAGGED -> proceedSelection(event)
|
||||
MouseEvent.MOUSE_RELEASED -> finishSelection(event)
|
||||
}
|
||||
}
|
||||
when (event.type) {
|
||||
MouseEvent.MOUSE_PRESSED -> beginSelection(event)
|
||||
MouseEvent.MOUSE_DRAGGED -> proceedSelection(event)
|
||||
MouseEvent.MOUSE_RELEASED -> finishSelection(event)
|
||||
}
|
||||
}
|
||||
|
||||
private fun beginSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
selection.begin(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
private fun beginSelection(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.begin(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
selection.proceed(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
private fun proceedSelection(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.proceed(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
selection.finish(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
private fun finishSelection(event: MapMouseEvent) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.finish(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0)
|
||||
private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95)
|
||||
}
|
||||
companion object {
|
||||
private val BACKGROUND_COLOR1 = Color.color(1.0, 1.0, 1.0, 1.0)
|
||||
private val BACKGROUND_COLOR2 = Color.color(0.95, 0.95, 0.95, 0.95)
|
||||
}
|
||||
}
|
||||
@@ -12,75 +12,75 @@ import kotlin.math.min
|
||||
|
||||
|
||||
class TileSetSelection(
|
||||
private val tileSet: TileSet,
|
||||
private val brushVM: BrushVM
|
||||
private val tileSet: TileSet,
|
||||
private val brushVM: BrushVM
|
||||
) : Renderable {
|
||||
private val tileWidth = tileSet.tileWidth.toDouble()
|
||||
private val tileHeight = tileSet.tileHeight.toDouble()
|
||||
private val tileWidth = tileSet.tileWidth.toDouble()
|
||||
private val tileHeight = tileSet.tileHeight.toDouble()
|
||||
|
||||
private var startRow = 0.0
|
||||
private var startColumn = 0.0
|
||||
private var offsetRow = 0.0
|
||||
private var offsetColumn = 0.0
|
||||
private var x = 0.0
|
||||
private var y = 0.0
|
||||
private var width = tileWidth
|
||||
private var height = tileHeight
|
||||
private var startRow = 0.0
|
||||
private var startColumn = 0.0
|
||||
private var offsetRow = 0.0
|
||||
private var offsetColumn = 0.0
|
||||
private var x = 0.0
|
||||
private var y = 0.0
|
||||
private var width = tileWidth
|
||||
private var height = tileHeight
|
||||
|
||||
|
||||
fun begin(row: Double, column: Double) {
|
||||
startRow = row
|
||||
offsetRow = 0.0
|
||||
startColumn = column
|
||||
offsetColumn = 0.0
|
||||
fun begin(row: Double, column: Double) {
|
||||
startRow = row
|
||||
offsetRow = 0.0
|
||||
startColumn = column
|
||||
offsetColumn = 0.0
|
||||
|
||||
updateRect(row, column)
|
||||
}
|
||||
updateRect(row, column)
|
||||
}
|
||||
|
||||
private fun updateRect(row: Double, column: Double) {
|
||||
x = min(column, startColumn) * tileWidth
|
||||
y = min(row, startRow) * tileHeight
|
||||
width = (offsetColumn + 1) * tileWidth
|
||||
height = (offsetRow + 1) * tileHeight
|
||||
}
|
||||
private fun updateRect(row: Double, column: Double) {
|
||||
x = min(column, startColumn) * tileWidth
|
||||
y = min(row, startRow) * tileHeight
|
||||
width = (offsetColumn + 1) * tileWidth
|
||||
height = (offsetRow + 1) * tileHeight
|
||||
}
|
||||
|
||||
fun proceed(row: Double, column: Double) {
|
||||
offsetRow = abs(row - startRow)
|
||||
offsetColumn = abs(column - startColumn)
|
||||
fun proceed(row: Double, column: Double) {
|
||||
offsetRow = abs(row - startRow)
|
||||
offsetColumn = abs(column - startColumn)
|
||||
|
||||
updateRect(row, column)
|
||||
}
|
||||
updateRect(row, column)
|
||||
}
|
||||
|
||||
fun finish(row: Double, column: Double) {
|
||||
proceed(row, column)
|
||||
fun finish(row: Double, column: Double) {
|
||||
proceed(row, column)
|
||||
|
||||
startRow = min(row, startRow)
|
||||
startColumn = min(column, startColumn)
|
||||
startRow = min(row, startRow)
|
||||
startColumn = min(column, startColumn)
|
||||
|
||||
val firstRow = startRow.toInt()
|
||||
val firstColumn = startColumn.toInt()
|
||||
val rows = offsetRow.toInt() + 1
|
||||
val columns = offsetColumn.toInt() + 1
|
||||
val firstRow = startRow.toInt()
|
||||
val firstColumn = startColumn.toInt()
|
||||
val rows = offsetRow.toInt() + 1
|
||||
val columns = offsetColumn.toInt() + 1
|
||||
|
||||
var brushArray = Array<Array<Tile>>(rows) { rowIndex ->
|
||||
Array<Tile>(columns) { columnIndex ->
|
||||
tileSet.getTile(firstRow + rowIndex, firstColumn + columnIndex)
|
||||
}
|
||||
}
|
||||
var brushArray = Array<Array<Tile>>(rows) { rowIndex ->
|
||||
Array<Tile>(columns) { columnIndex ->
|
||||
tileSet.getTile(firstRow + rowIndex, firstColumn + columnIndex)
|
||||
}
|
||||
}
|
||||
|
||||
brushVM.item = Brush(brushArray)
|
||||
}
|
||||
brushVM.item = Brush(brushArray)
|
||||
}
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.fill = SELECTION_FILL_COLOR
|
||||
gc.fillRect(x, y, width, height)
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.fill = SELECTION_FILL_COLOR
|
||||
gc.fillRect(x, y, width, height)
|
||||
|
||||
gc.stroke = SELECTION_STROKE_COLOR
|
||||
gc.strokeRect(x, y, width, height)
|
||||
}
|
||||
gc.stroke = SELECTION_STROKE_COLOR
|
||||
gc.strokeRect(x, y, width, height)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SELECTION_FILL_COLOR = Color.color(0.0, 0.7, 1.0, 0.4)
|
||||
private val SELECTION_STROKE_COLOR = Color.color(0.0, 0.7, 1.0, 1.0)
|
||||
}
|
||||
companion object {
|
||||
private val SELECTION_FILL_COLOR = Color.color(0.0, 0.7, 1.0, 0.4)
|
||||
private val SELECTION_STROKE_COLOR = Color.color(0.0, 0.7, 1.0, 1.0)
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,5 @@ package com.bartlomiejpluta.base.editor.render.model
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
|
||||
interface Renderable {
|
||||
fun render(gc: GraphicsContext)
|
||||
fun render(gc: GraphicsContext)
|
||||
}
|
||||
@@ -4,41 +4,46 @@ import com.bartlomiejpluta.base.editor.render.canvas.input.MapMouseEvent
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.map.MapCanvas
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.map.MapPainter
|
||||
import com.bartlomiejpluta.base.editor.render.canvas.map.MapPaintingTrace
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.beans.property.IntegerProperty
|
||||
import javafx.event.EventHandler
|
||||
import javafx.scene.canvas.Canvas
|
||||
import javafx.scene.input.MouseEvent
|
||||
|
||||
|
||||
class MapPane(map: GameMapVM, brushVM: BrushVM, selectedLayer: IntegerProperty, paintingCallback: (MapPaintingTrace) -> Unit) : Canvas(), EventHandler<MouseEvent> {
|
||||
private var tileSet = map.tileSet
|
||||
private val painter = MapPainter(map, brushVM, selectedLayer, paintingCallback)
|
||||
private val mapCanvas = MapCanvas(map, painter)
|
||||
class MapPane(
|
||||
map: GameMapVM,
|
||||
brushVM: BrushVM,
|
||||
selectedLayer: IntegerProperty,
|
||||
paintingCallback: (MapPaintingTrace) -> Unit
|
||||
) : Canvas(), EventHandler<MouseEvent> {
|
||||
private var tileSet = map.tileSet
|
||||
private val painter = MapPainter(map, brushVM, selectedLayer, paintingCallback)
|
||||
private val mapCanvas = MapCanvas(map, painter)
|
||||
|
||||
init {
|
||||
onMouseMoved = this
|
||||
onMouseDragged = this
|
||||
onMousePressed = this
|
||||
onMouseReleased = this
|
||||
init {
|
||||
onMouseMoved = this
|
||||
onMouseDragged = this
|
||||
onMousePressed = this
|
||||
onMouseReleased = this
|
||||
|
||||
tileSet = map.tileSet
|
||||
width = map.width.toDouble()
|
||||
height = map.height.toDouble()
|
||||
render()
|
||||
}
|
||||
tileSet = map.tileSet
|
||||
width = map.width.toDouble()
|
||||
height = map.height.toDouble()
|
||||
render()
|
||||
}
|
||||
|
||||
|
||||
fun render() {
|
||||
mapCanvas.render(graphicsContext2D)
|
||||
}
|
||||
fun render() {
|
||||
mapCanvas.render(graphicsContext2D)
|
||||
}
|
||||
|
||||
override fun handle(event: MouseEvent?) {
|
||||
if (event != null) {
|
||||
painter.handleMouseInput(MapMouseEvent.of(event, tileSet))
|
||||
}
|
||||
override fun handle(event: MouseEvent?) {
|
||||
if (event != null) {
|
||||
painter.handleMouseInput(MapMouseEvent.of(event, tileSet))
|
||||
}
|
||||
|
||||
mapCanvas.render(graphicsContext2D)
|
||||
}
|
||||
mapCanvas.render(graphicsContext2D)
|
||||
}
|
||||
}
|
||||
@@ -9,29 +9,29 @@ import javafx.scene.canvas.Canvas
|
||||
import javafx.scene.input.MouseEvent
|
||||
|
||||
class TileSetPane(private val tileSet: TileSet, brushVM: BrushVM) : Canvas(), EventHandler<MouseEvent> {
|
||||
private val tileSetCanvas = TileSetCanvas(tileSet, brushVM)
|
||||
private val tileSetCanvas = TileSetCanvas(tileSet, brushVM)
|
||||
|
||||
init {
|
||||
onMouseMoved = this
|
||||
onMouseDragged = this
|
||||
onMousePressed = this
|
||||
onMouseReleased = this
|
||||
init {
|
||||
onMouseMoved = this
|
||||
onMouseDragged = this
|
||||
onMousePressed = this
|
||||
onMouseReleased = this
|
||||
|
||||
width = tileSet.width.toDouble()
|
||||
height = tileSet.height.toDouble()
|
||||
width = tileSet.width.toDouble()
|
||||
height = tileSet.height.toDouble()
|
||||
|
||||
render()
|
||||
}
|
||||
render()
|
||||
}
|
||||
|
||||
fun render() {
|
||||
tileSetCanvas.render(graphicsContext2D)
|
||||
}
|
||||
fun render() {
|
||||
tileSetCanvas.render(graphicsContext2D)
|
||||
}
|
||||
|
||||
override fun handle(event: MouseEvent?) {
|
||||
if (event != null) {
|
||||
tileSetCanvas.handleMouseInput(MapMouseEvent.of(event, tileSet))
|
||||
}
|
||||
override fun handle(event: MouseEvent?) {
|
||||
if (event != null) {
|
||||
tileSetCanvas.handleMouseInput(MapMouseEvent.of(event, tileSet))
|
||||
}
|
||||
|
||||
tileSetCanvas.render(graphicsContext2D)
|
||||
}
|
||||
tileSetCanvas.render(graphicsContext2D)
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import com.bartlomiejpluta.base.editor.model.map.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
|
||||
import com.bartlomiejpluta.base.editor.view.component.map.MapPane
|
||||
import com.bartlomiejpluta.base.editor.view.component.tileset.TileSetPane
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.viewmodel.map.GameMapVM
|
||||
import javafx.beans.property.SimpleDoubleProperty
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import javafx.scene.control.TableView
|
||||
@@ -19,114 +19,117 @@ import tornadofx.*
|
||||
|
||||
|
||||
class MapFragment : Fragment() {
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
|
||||
val map: GameMap by param()
|
||||
val map: GameMap by param()
|
||||
|
||||
private val brushVM = find<BrushVM>().apply { item = map.tileSet.baseBrush }
|
||||
private val mapVM = find<GameMapVM>().apply { item = map }
|
||||
private val brushVM = find<BrushVM>().apply { item = map.tileSet.baseBrush }
|
||||
private val mapVM = find<GameMapVM>().apply { item = map }
|
||||
|
||||
val scaleProperty = SimpleDoubleProperty(1.0)
|
||||
val scaleProperty = SimpleDoubleProperty(1.0)
|
||||
|
||||
private val selectedLayer = SimpleIntegerProperty(0)
|
||||
private val selectedLayer = SimpleIntegerProperty(0)
|
||||
|
||||
private val mapPane = MapPane(mapVM, brushVM, selectedLayer) { undoRedoService.push(it) }
|
||||
private val tileSetPane = TileSetPane(map.tileSet, brushVM)
|
||||
private var layersPane: TableView<Layer> by singleAssign()
|
||||
private val mapPane = MapPane(mapVM, brushVM, selectedLayer) { undoRedoService.push(it) }
|
||||
private val tileSetPane = TileSetPane(map.tileSet, brushVM)
|
||||
private var layersPane: TableView<Layer> by singleAssign()
|
||||
|
||||
private val transformation = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||
xProperty().bind(scaleProperty)
|
||||
yProperty().bind(scaleProperty)
|
||||
}
|
||||
private val transformation = Scale(1.0, 1.0, 0.0, 0.0).apply {
|
||||
xProperty().bind(scaleProperty)
|
||||
yProperty().bind(scaleProperty)
|
||||
}
|
||||
|
||||
init {
|
||||
subscribe<RedrawMapRequestEvent> { mapPane.render() }
|
||||
}
|
||||
init {
|
||||
subscribe<RedrawMapRequestEvent> { mapPane.render() }
|
||||
}
|
||||
|
||||
override val root = borderpane {
|
||||
center = scrollpane {
|
||||
prefWidth = 640.0
|
||||
prefHeight = 480.0
|
||||
isPannable = true
|
||||
override val root = borderpane {
|
||||
center = scrollpane {
|
||||
prefWidth = 640.0
|
||||
prefHeight = 480.0
|
||||
isPannable = true
|
||||
|
||||
group {
|
||||
|
||||
// Let the ScrollPane.viewRect only pan on middle button.
|
||||
addEventHandler(MouseEvent.ANY) {
|
||||
if (it.button != MouseButton.MIDDLE) {
|
||||
it.consume()
|
||||
}
|
||||
}
|
||||
|
||||
group {
|
||||
|
||||
// Let the ScrollPane.viewRect only pan on middle button.
|
||||
addEventHandler(MouseEvent.ANY) {
|
||||
if (it.button != MouseButton.MIDDLE) {
|
||||
it.consume()
|
||||
}
|
||||
}
|
||||
|
||||
group {
|
||||
this += mapPane
|
||||
transforms += transformation
|
||||
}
|
||||
this += mapPane
|
||||
transforms += transformation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
right = drawer(multiselect = true) {
|
||||
item("Layers", expanded = true) {
|
||||
borderpane {
|
||||
layersPane = tableview(mapVM.layers) {
|
||||
column("Layer Name", Layer::nameProperty).makeEditable()
|
||||
right = drawer(multiselect = true) {
|
||||
item("Layers", expanded = true) {
|
||||
borderpane {
|
||||
layersPane = tableview(mapVM.layers) {
|
||||
column("Layer Name", Layer::nameProperty).makeEditable()
|
||||
|
||||
selectedLayer.bind(selectionModel.selectedIndexProperty())
|
||||
}
|
||||
selectedLayer.bind(selectionModel.selectedIndexProperty())
|
||||
}
|
||||
|
||||
center = layersPane
|
||||
center = layersPane
|
||||
|
||||
bottom = toolbar {
|
||||
button(graphic = FontIcon("fa-plus")) {
|
||||
action {
|
||||
mapVM.item.createTileLayer("Layer ${mapVM.layers.size+1}")
|
||||
layersPane.selectionModel.select(mapVM.layers.size - 1)
|
||||
}
|
||||
bottom = toolbar {
|
||||
button(graphic = FontIcon("fa-plus")) {
|
||||
action {
|
||||
mapVM.item.createTileLayer("Layer ${mapVM.layers.size + 1}")
|
||||
layersPane.selectionModel.select(mapVM.layers.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-chevron-up")) {
|
||||
enableWhen(selectedLayer.greaterThan(0))
|
||||
action {
|
||||
val newIndex = selectedLayer.value - 1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-chevron-down")) {
|
||||
enableWhen(
|
||||
selectedLayer.lessThan(mapVM.layers.sizeProperty().minus(1))
|
||||
.and(selectedLayer.greaterThanOrEqualTo(0))
|
||||
)
|
||||
action {
|
||||
val newIndex = selectedLayer.value + 1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-trash")) {
|
||||
enableWhen(selectedLayer.greaterThanOrEqualTo(0))
|
||||
action {
|
||||
var index = selectedLayer.value
|
||||
mapVM.layers.removeAt(index)
|
||||
|
||||
if (--index >= 0) {
|
||||
layersPane.selectionModel.select(index)
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-chevron-up")) {
|
||||
enableWhen(selectedLayer.greaterThan(0))
|
||||
action {
|
||||
val newIndex = selectedLayer.value-1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-chevron-down")) {
|
||||
enableWhen(selectedLayer.lessThan(mapVM.layers.sizeProperty().minus(1)).and(selectedLayer.greaterThanOrEqualTo(0)))
|
||||
action {
|
||||
val newIndex = selectedLayer.value+1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-trash")) {
|
||||
enableWhen(selectedLayer.greaterThanOrEqualTo(0))
|
||||
action {
|
||||
var index = selectedLayer.value
|
||||
mapVM.layers.removeAt(index)
|
||||
|
||||
if(--index >= 0) {
|
||||
layersPane.selectionModel.select(index)
|
||||
}
|
||||
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item("Tile Set", expanded = true) {
|
||||
scrollpane {
|
||||
maxHeightProperty().bind(this@item.heightProperty())
|
||||
this += tileSetPane
|
||||
}
|
||||
item("Tile Set", expanded = true) {
|
||||
scrollpane {
|
||||
maxHeightProperty().bind(this@item.heightProperty())
|
||||
this += tileSetPane
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,61 +10,61 @@ import tornadofx.*
|
||||
|
||||
|
||||
class MainView : View() {
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
private val mapController: MapController by di()
|
||||
private val tabPane = TabPane()
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
private val mapController: MapController by di()
|
||||
private val tabPane = TabPane()
|
||||
|
||||
private val mapScale = SimpleDoubleProperty(1.0)
|
||||
private val mapScale = SimpleDoubleProperty(1.0)
|
||||
|
||||
override val root = borderpane {
|
||||
top = hbox {
|
||||
button("Map 1") {
|
||||
action {
|
||||
val map = mapController.getMap(1)
|
||||
tabPane += find<MapFragment>(Scope(), MapFragment::map to map).apply {
|
||||
title = "Map 1"
|
||||
scaleProperty.bind(mapScale)
|
||||
}
|
||||
}
|
||||
override val root = borderpane {
|
||||
top = hbox {
|
||||
button("Map 1") {
|
||||
action {
|
||||
val map = mapController.getMap(1)
|
||||
tabPane += find<MapFragment>(Scope(), MapFragment::map to map).apply {
|
||||
title = "Map 1"
|
||||
scaleProperty.bind(mapScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
button("Map 2") {
|
||||
action {
|
||||
val map = mapController.getMap(2)
|
||||
tabPane += find<MapFragment>(Scope(), MapFragment::map to map).apply {
|
||||
title = "Map 2"
|
||||
scaleProperty.bind(mapScale)
|
||||
}
|
||||
}
|
||||
button("Map 2") {
|
||||
action {
|
||||
val map = mapController.getMap(2)
|
||||
tabPane += find<MapFragment>(Scope(), MapFragment::map to map).apply {
|
||||
title = "Map 2"
|
||||
scaleProperty.bind(mapScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
button("+") {
|
||||
action {
|
||||
mapScale.value += 0.1
|
||||
}
|
||||
button("+") {
|
||||
action {
|
||||
mapScale.value += 0.1
|
||||
}
|
||||
}
|
||||
|
||||
button("-") {
|
||||
action {
|
||||
mapScale.value -= 0.1
|
||||
}
|
||||
button("-") {
|
||||
action {
|
||||
mapScale.value -= 0.1
|
||||
}
|
||||
}
|
||||
|
||||
button("Undo") {
|
||||
action {
|
||||
undoRedoService.undo()
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
button("Undo") {
|
||||
action {
|
||||
undoRedoService.undo()
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
|
||||
button("Redo") {
|
||||
action {
|
||||
undoRedoService.redo()
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
button("Redo") {
|
||||
action {
|
||||
undoRedoService.redo()
|
||||
fire(RedrawMapRequestEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
center = tabPane
|
||||
}
|
||||
center = tabPane
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,23 @@ package com.bartlomiejpluta.base.editor.viewmodel.map
|
||||
|
||||
import com.bartlomiejpluta.base.editor.model.map.brush.Brush
|
||||
import com.bartlomiejpluta.base.editor.model.tileset.Tile
|
||||
import tornadofx.*
|
||||
import tornadofx.ItemViewModel
|
||||
import tornadofx.getValue
|
||||
|
||||
class BrushVM : ItemViewModel<Brush>(Brush(arrayOf(arrayOf()))) {
|
||||
val brush = bind(Brush::brush)
|
||||
val brush = bind(Brush::brush)
|
||||
|
||||
val rowsProperty = bind(Brush::rowsProperty)
|
||||
val rows by rowsProperty
|
||||
val rowsProperty = bind(Brush::rowsProperty)
|
||||
val rows by rowsProperty
|
||||
|
||||
val columnsProperty = bind(Brush::columnsProperty)
|
||||
val columns by columnsProperty
|
||||
val columnsProperty = bind(Brush::columnsProperty)
|
||||
val columns by columnsProperty
|
||||
|
||||
val centerRowProperty = bind(Brush::centerRowProperty)
|
||||
val centerRow by centerRowProperty
|
||||
val centerRowProperty = bind(Brush::centerRowProperty)
|
||||
val centerRow by centerRowProperty
|
||||
|
||||
val centerColumnProperty = bind(Brush::centerColumnProperty)
|
||||
val centerColumn by centerColumnProperty
|
||||
val centerColumnProperty = bind(Brush::centerColumnProperty)
|
||||
val centerColumn by centerColumnProperty
|
||||
|
||||
fun forEach(consumer: (row: Int, column: Int, tile: Tile) -> Unit) = item.forEach(consumer)
|
||||
fun forEach(consumer: (row: Int, column: Int, tile: Tile) -> Unit) = item.forEach(consumer)
|
||||
}
|
||||
@@ -3,25 +3,26 @@ package com.bartlomiejpluta.base.editor.viewmodel.map
|
||||
import com.bartlomiejpluta.base.editor.model.map.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.model.map.map.GameMap
|
||||
import javafx.beans.property.SimpleListProperty
|
||||
import tornadofx.*
|
||||
import tornadofx.ItemViewModel
|
||||
import tornadofx.getValue
|
||||
|
||||
class GameMapVM : ItemViewModel<GameMap>() {
|
||||
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
||||
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
||||
|
||||
val tileSetProperty = bind(GameMap::tileSet)
|
||||
val tileSet by tileSetProperty
|
||||
val tileSetProperty = bind(GameMap::tileSet)
|
||||
val tileSet by tileSetProperty
|
||||
|
||||
val rowsProperty = bind(GameMap::rows)
|
||||
val rows by rowsProperty
|
||||
val rowsProperty = bind(GameMap::rows)
|
||||
val rows by rowsProperty
|
||||
|
||||
val columnsProperty = bind(GameMap::columns)
|
||||
val columns by columnsProperty
|
||||
val columnsProperty = bind(GameMap::columns)
|
||||
val columns by columnsProperty
|
||||
|
||||
val widthProperty = bind(GameMap::width)
|
||||
val width by widthProperty
|
||||
val widthProperty = bind(GameMap::width)
|
||||
val width by widthProperty
|
||||
|
||||
val heightProperty = bind(GameMap::height)
|
||||
val height by heightProperty
|
||||
val heightProperty = bind(GameMap::height)
|
||||
val height by heightProperty
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user