[Editor] Refactor editor code (i.e. 3-space tabs) | optimize imports
This commit is contained in:
@@ -4,7 +4,10 @@ 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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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.*
|
||||
@@ -13,8 +12,8 @@ class DefaultUndoRedoService : UndoRedoService {
|
||||
|
||||
override var sizeMax = 30
|
||||
set(value) {
|
||||
if(value >= 0) {
|
||||
for(i in 0 until undo.size - value) {
|
||||
if (value >= 0) {
|
||||
for (i in 0 until undo.size - value) {
|
||||
undo.removeLast()
|
||||
}
|
||||
|
||||
@@ -23,7 +22,7 @@ class DefaultUndoRedoService : UndoRedoService {
|
||||
}
|
||||
|
||||
override fun push(undoable: Undoable) {
|
||||
if(undo.size == sizeMax) {
|
||||
if (undo.size == sizeMax) {
|
||||
log.debug("The max size of [undo] list has been reached. Removing the last item...")
|
||||
undo.removeLast()
|
||||
}
|
||||
@@ -34,7 +33,7 @@ class DefaultUndoRedoService : UndoRedoService {
|
||||
}
|
||||
|
||||
override fun undo() {
|
||||
if(undo.isNotEmpty()) {
|
||||
if (undo.isNotEmpty()) {
|
||||
undo.pop().let {
|
||||
log.debug("Performing undo: ${it.commandName}")
|
||||
it.undo()
|
||||
@@ -44,7 +43,7 @@ class DefaultUndoRedoService : UndoRedoService {
|
||||
}
|
||||
|
||||
override fun redo() {
|
||||
if(redo.isNotEmpty()) {
|
||||
if (redo.isNotEmpty()) {
|
||||
redo.pop().let {
|
||||
log.debug("Performing redo: ${it.commandName}")
|
||||
it.redo()
|
||||
|
||||
@@ -15,7 +15,7 @@ class MapController : Controller() {
|
||||
|
||||
private val map2 = GameMap(tileSetController.tileset, 50, 50)
|
||||
|
||||
fun getMap(id: Int) = when(id) {
|
||||
fun getMap(id: Int) = when (id) {
|
||||
1 -> map1
|
||||
else -> map2
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ 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>()
|
||||
@@ -20,12 +22,12 @@ class Brush(newBrush: Array<Array<Tile>>) {
|
||||
|
||||
newBrush.forEach { brush.addAll(it) }
|
||||
|
||||
if(rowsProperty.value > 0) {
|
||||
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) {
|
||||
|
||||
@@ -2,8 +2,7 @@ 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 {
|
||||
|
||||
|
||||
@@ -22,7 +22,15 @@ class TileSet(private val image: Image, val rows: Int, val columns: Int) {
|
||||
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)
|
||||
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)
|
||||
|
||||
@@ -20,7 +20,7 @@ class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderabl
|
||||
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height);
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height)
|
||||
|
||||
renderBackground(gc)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ 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
|
||||
|
||||
@@ -18,7 +18,7 @@ class TileSetCanvas(private val tileSet: TileSet, brushVM: BrushVM) : Renderable
|
||||
private var mouseColumn = -1
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height);
|
||||
gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height)
|
||||
|
||||
renderTiles(gc)
|
||||
selection.render(gc)
|
||||
@@ -27,8 +27,13 @@ class TileSetCanvas(private val tileSet: TileSet, brushVM: BrushVM) : Renderable
|
||||
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.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)
|
||||
}
|
||||
}
|
||||
@@ -46,19 +51,19 @@ class TileSetCanvas(private val tileSet: TileSet, brushVM: BrushVM) : Renderable
|
||||
}
|
||||
|
||||
private fun beginSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.begin(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.proceed(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishSelection(event: MapMouseEvent) {
|
||||
if(event.button == MouseButton.PRIMARY) {
|
||||
if (event.button == MouseButton.PRIMARY) {
|
||||
selection.finish(event.row.toDouble(), event.column.toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,20 @@ 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> {
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
@@ -79,7 +79,7 @@ class MapFragment : Fragment() {
|
||||
bottom = toolbar {
|
||||
button(graphic = FontIcon("fa-plus")) {
|
||||
action {
|
||||
mapVM.item.createTileLayer("Layer ${mapVM.layers.size+1}")
|
||||
mapVM.item.createTileLayer("Layer ${mapVM.layers.size + 1}")
|
||||
layersPane.selectionModel.select(mapVM.layers.size - 1)
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class MapFragment : Fragment() {
|
||||
button(graphic = FontIcon("fa-chevron-up")) {
|
||||
enableWhen(selectedLayer.greaterThan(0))
|
||||
action {
|
||||
val newIndex = selectedLayer.value-1
|
||||
val newIndex = selectedLayer.value - 1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
@@ -95,9 +95,12 @@ class MapFragment : Fragment() {
|
||||
}
|
||||
|
||||
button(graphic = FontIcon("fa-chevron-down")) {
|
||||
enableWhen(selectedLayer.lessThan(mapVM.layers.sizeProperty().minus(1)).and(selectedLayer.greaterThanOrEqualTo(0)))
|
||||
enableWhen(
|
||||
selectedLayer.lessThan(mapVM.layers.sizeProperty().minus(1))
|
||||
.and(selectedLayer.greaterThanOrEqualTo(0))
|
||||
)
|
||||
action {
|
||||
val newIndex = selectedLayer.value+1
|
||||
val newIndex = selectedLayer.value + 1
|
||||
mapVM.layers.swap(selectedLayer.value, newIndex)
|
||||
layersPane.selectionModel.select(newIndex)
|
||||
fire(RedrawMapRequestEvent)
|
||||
@@ -110,7 +113,7 @@ class MapFragment : Fragment() {
|
||||
var index = selectedLayer.value
|
||||
mapVM.layers.removeAt(index)
|
||||
|
||||
if(--index >= 0) {
|
||||
if (--index >= 0) {
|
||||
layersPane.selectionModel.select(index)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ 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)
|
||||
|
||||
@@ -3,7 +3,8 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user