Remove unnecessary PassageAbility (other than ALLOW and BLOCK)
This commit is contained in:
@@ -28,7 +28,7 @@ class MapPainter(
|
||||
editorStateVM.selectedLayerProperty.addListener { _, _, layer ->
|
||||
cursor = when (layer) {
|
||||
is TileLayer -> TilePaintingCursor(tileWidth, tileHeight, editorStateVM, brushVM)
|
||||
is ObjectLayer -> ObjectPaintingCursor(tileWidth, tileHeight, editorStateVM)
|
||||
is ObjectLayer -> ObjectPaintingCursor(tileWidth, tileHeight, editorStateVM, brushVM)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bartlomiejpluta.base.editor.map.canvas
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.model.brush.BrushMode
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.BrushVM
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.EditorStateVM
|
||||
import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.paint.Color
|
||||
@@ -7,19 +9,30 @@ import javafx.scene.paint.Color
|
||||
class ObjectPaintingCursor(
|
||||
private val tileWidth: Double,
|
||||
private val tileHeight: Double,
|
||||
private val editorStateVM: EditorStateVM
|
||||
private val editorStateVM: EditorStateVM,
|
||||
private val brushVM: BrushVM
|
||||
) : PaintingCursor {
|
||||
|
||||
override fun render(gc: GraphicsContext) {
|
||||
brushVM.forEach { row, column, centerRow, centerColumn, tile ->
|
||||
renderTile(gc, row, column, centerRow, centerColumn)
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderTile(gc: GraphicsContext, row: Int, column: Int, centerRow: Int, centerColumn: Int) {
|
||||
val alpha = gc.globalAlpha
|
||||
val stroke = gc.stroke
|
||||
val width = gc.lineWidth
|
||||
gc.globalAlpha = 1.0
|
||||
gc.stroke = Color.WHITE
|
||||
gc.stroke = when (brushVM.mode!!) {
|
||||
BrushMode.PAINTING_MODE -> Color.RED
|
||||
BrushMode.ERASING_MODE -> Color.WHITE
|
||||
}
|
||||
gc.lineWidth = 3.0
|
||||
|
||||
val x = editorStateVM.cursorColumn * tileWidth
|
||||
val y = editorStateVM.cursorRow * tileHeight
|
||||
|
||||
val x = tileWidth * (editorStateVM.cursorColumn - centerColumn + column)
|
||||
val y = tileHeight * (editorStateVM.cursorRow - centerRow + row)
|
||||
gc.strokeLine(x + tileWidth / 2, y + (1 - SIZE) * tileHeight, x + tileWidth / 2, y + SIZE * tileHeight)
|
||||
gc.strokeLine(x + (1 - SIZE) * tileWidth, y + tileHeight / 2, x + SIZE * tileWidth, y + tileHeight / 2)
|
||||
|
||||
|
||||
@@ -10,56 +10,86 @@ import com.bartlomiejpluta.base.editor.render.input.MapMouseEvent
|
||||
import javafx.scene.input.MouseButton
|
||||
|
||||
class ObjectPaintingTrace(val map: GameMapVM, override val commandName: String) : PaintingTrace {
|
||||
private var layerIndex = 0
|
||||
private var row = 0
|
||||
private var column = 0
|
||||
private lateinit var layer: ObjectLayer
|
||||
private lateinit var formerPassageAbility: PassageAbility
|
||||
private lateinit var passageAbility: PassageAbility
|
||||
|
||||
|
||||
override fun beginTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
override fun proceedTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
override fun commitTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
this.layerIndex = editorStateVM.selectedLayerIndex
|
||||
this.row = editorStateVM.cursorRow
|
||||
this.column = editorStateVM.cursorColumn
|
||||
private val trace = mutableListOf<Element>()
|
||||
|
||||
private fun paint(layerIndex: Int, row: Int, column: Int, passageAbility: PassageAbility) {
|
||||
if (row >= map.rows || column >= map.columns || row < 0 || column < 0 || layerIndex < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.layer = (map.layers[layerIndex] as ObjectLayer)
|
||||
val passageMap = (map.layers[layerIndex] as ObjectLayer).passageMap
|
||||
val formerPassageAbility = passageMap[row][column]
|
||||
|
||||
formerPassageAbility = layer.passageMap[row][column]
|
||||
|
||||
passageAbility = when (mouseEvent.button) {
|
||||
MouseButton.PRIMARY -> when (brushVM.mode!!) {
|
||||
BrushMode.PAINTING_MODE -> PassageAbility.values()[(formerPassageAbility.ordinal + 1) % PassageAbility.values().size]
|
||||
BrushMode.ERASING_MODE -> PassageAbility.ALLOW
|
||||
}
|
||||
|
||||
MouseButton.SECONDARY -> PassageAbility.ALLOW
|
||||
|
||||
else -> throw IllegalStateException("Unsupported mouse button")
|
||||
if (trace.isEmpty()) {
|
||||
trace += Element(layerIndex, row, column, formerPassageAbility, passageAbility)
|
||||
passageMap[row][column] = passageAbility
|
||||
return
|
||||
}
|
||||
|
||||
layer.passageMap[row][column] = passageAbility
|
||||
val tileAlreadyPainted =
|
||||
trace.find { it.layerIndex == layerIndex && it.row == row && it.column == column } != null
|
||||
|
||||
if (!tileAlreadyPainted) {
|
||||
trace += Element(layerIndex, row, column, formerPassageAbility, passageAbility)
|
||||
passageMap[row][column] = passageAbility
|
||||
}
|
||||
}
|
||||
|
||||
override fun beginTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
brushVM.forEach { row, column, centerRow, centerColumn, _ ->
|
||||
paint(
|
||||
editorStateVM.selectedLayerIndex,
|
||||
editorStateVM.cursorRow - centerRow + row,
|
||||
editorStateVM.cursorColumn - centerColumn + column,
|
||||
when {
|
||||
brushVM.mode == BrushMode.ERASING_MODE -> PassageAbility.ALLOW
|
||||
mouseEvent.button == MouseButton.PRIMARY -> PassageAbility.BLOCK
|
||||
else -> PassageAbility.ALLOW
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun proceedTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
brushVM.forEach { row, column, centerRow, centerColumn, _ ->
|
||||
paint(
|
||||
editorStateVM.selectedLayerIndex,
|
||||
editorStateVM.cursorRow - centerRow + row,
|
||||
editorStateVM.cursorColumn - centerColumn + column,
|
||||
when {
|
||||
brushVM.mode == BrushMode.ERASING_MODE -> PassageAbility.ALLOW
|
||||
mouseEvent.button == MouseButton.PRIMARY -> PassageAbility.BLOCK
|
||||
else -> PassageAbility.ALLOW
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun commitTrace(editorStateVM: EditorStateVM, brushVM: BrushVM, mouseEvent: MapMouseEvent) {
|
||||
|
||||
}
|
||||
|
||||
override fun undo() {
|
||||
layer.passageMap[row][column] = formerPassageAbility
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as ObjectLayer).passageMap[it.row][it.column] = it.formerPassageAbility
|
||||
}
|
||||
}
|
||||
|
||||
override fun redo() {
|
||||
layer.passageMap[row][column] = passageAbility
|
||||
trace.forEach {
|
||||
(map.layers[it.layerIndex] as ObjectLayer).passageMap[it.row][it.column] = it.passageAbility
|
||||
}
|
||||
}
|
||||
|
||||
override val supportedButtons = arrayOf(MouseButton.PRIMARY, MouseButton.SECONDARY)
|
||||
|
||||
companion object {
|
||||
private data class Element(
|
||||
val layerIndex: Int,
|
||||
val row: Int,
|
||||
val column: Int,
|
||||
val formerPassageAbility: PassageAbility,
|
||||
val passageAbility: PassageAbility
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,6 @@ object PassageAbilitySymbol {
|
||||
when (passageAbility) {
|
||||
PassageAbility.ALLOW -> allow(gc, x, y, w, h)
|
||||
PassageAbility.BLOCK -> block(gc, x, y, w, h)
|
||||
PassageAbility.UP_ONLY -> up(gc, x, y, w, h)
|
||||
PassageAbility.DOWN_ONLY -> down(gc, x, y, w, h)
|
||||
PassageAbility.LEFT_ONLY -> left(gc, x, y, w, h)
|
||||
PassageAbility.RIGHT_ONLY -> right(gc, x, y, w, h)
|
||||
}
|
||||
|
||||
gc.fill = fill
|
||||
@@ -35,68 +31,4 @@ object PassageAbilitySymbol {
|
||||
gc.globalAlpha = 0.4
|
||||
gc.fillRect(x, y, w, h)
|
||||
}
|
||||
|
||||
fun down(gc: GraphicsContext, x: Double, y: Double, w: Double, h: Double) {
|
||||
gc.fill = Color.GREEN
|
||||
gc.globalAlpha = 0.1
|
||||
gc.fillRect(x, y, w, h)
|
||||
gc.globalAlpha = 1.0
|
||||
|
||||
gc.fill = Color.WHITE
|
||||
gc.beginPath()
|
||||
gc.moveTo(x + (1 - SIZE) * w, y + (1 - SIZE) * h)
|
||||
gc.lineTo(x + w * SIZE, y + (1 - SIZE) * h)
|
||||
gc.lineTo(x + w / 2, y + h * SIZE)
|
||||
gc.closePath()
|
||||
|
||||
gc.fill()
|
||||
}
|
||||
|
||||
fun up(gc: GraphicsContext, x: Double, y: Double, w: Double, h: Double) {
|
||||
gc.fill = Color.GREEN
|
||||
gc.globalAlpha = 0.1
|
||||
gc.fillRect(x, y, w, h)
|
||||
gc.globalAlpha = 1.0
|
||||
|
||||
gc.fill = Color.WHITE
|
||||
gc.beginPath()
|
||||
gc.moveTo(x + (1 - SIZE) * w, y + h * SIZE)
|
||||
gc.lineTo(x + w * SIZE, y + h * SIZE)
|
||||
gc.lineTo(x + w / 2, y + (1 - SIZE) * h)
|
||||
gc.closePath()
|
||||
|
||||
gc.fill()
|
||||
}
|
||||
|
||||
fun left(gc: GraphicsContext, x: Double, y: Double, w: Double, h: Double) {
|
||||
gc.fill = Color.GREEN
|
||||
gc.globalAlpha = 0.1
|
||||
gc.fillRect(x, y, w, h)
|
||||
gc.globalAlpha = 1.0
|
||||
|
||||
gc.fill = Color.WHITE
|
||||
gc.beginPath()
|
||||
gc.moveTo(x + (1 - SIZE) * w, y + h / 2)
|
||||
gc.lineTo(x + SIZE * w, y + (1 - SIZE) * h)
|
||||
gc.lineTo(x + w * SIZE, y + h * SIZE)
|
||||
gc.closePath()
|
||||
|
||||
gc.fill()
|
||||
}
|
||||
|
||||
fun right(gc: GraphicsContext, x: Double, y: Double, w: Double, h: Double) {
|
||||
gc.fill = Color.GREEN
|
||||
gc.globalAlpha = 0.1
|
||||
gc.fillRect(x, y, w, h)
|
||||
gc.globalAlpha = 1.0
|
||||
|
||||
gc.fill = Color.WHITE
|
||||
gc.beginPath()
|
||||
gc.moveTo(x + SIZE * w, y + h / 2)
|
||||
gc.lineTo(x + (1 - SIZE) * w, y + (1 - SIZE) * h)
|
||||
gc.lineTo(x + w * (1 - SIZE), y + h * SIZE)
|
||||
gc.closePath()
|
||||
|
||||
gc.fill()
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,5 @@ package com.bartlomiejpluta.base.editor.map.model.enumeration
|
||||
|
||||
enum class PassageAbility {
|
||||
ALLOW,
|
||||
BLOCK,
|
||||
UP_ONLY,
|
||||
DOWN_ONLY,
|
||||
LEFT_ONLY,
|
||||
RIGHT_ONLY
|
||||
BLOCK
|
||||
}
|
||||
@@ -65,10 +65,6 @@ class ProtobufMapDeserializer : MapDeserializer {
|
||||
passageMap[index / columns][index % columns] = when (passage!!) {
|
||||
GameMapProto.PassageAbility.ALLOW -> PassageAbility.ALLOW
|
||||
GameMapProto.PassageAbility.BLOCK -> PassageAbility.BLOCK
|
||||
GameMapProto.PassageAbility.UP_ONLY -> PassageAbility.UP_ONLY
|
||||
GameMapProto.PassageAbility.DOWN_ONLY -> PassageAbility.DOWN_ONLY
|
||||
GameMapProto.PassageAbility.LEFT_ONLY -> PassageAbility.LEFT_ONLY
|
||||
GameMapProto.PassageAbility.RIGHT_ONLY -> PassageAbility.RIGHT_ONLY
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,6 @@ class ProtobufMapSerializer : MapSerializer {
|
||||
when (passage) {
|
||||
PassageAbility.ALLOW -> GameMapProto.PassageAbility.ALLOW
|
||||
PassageAbility.BLOCK -> GameMapProto.PassageAbility.BLOCK
|
||||
PassageAbility.UP_ONLY -> GameMapProto.PassageAbility.UP_ONLY
|
||||
PassageAbility.DOWN_ONLY -> GameMapProto.PassageAbility.DOWN_ONLY
|
||||
PassageAbility.LEFT_ONLY -> GameMapProto.PassageAbility.LEFT_ONLY
|
||||
PassageAbility.RIGHT_ONLY -> GameMapProto.PassageAbility.RIGHT_ONLY
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class MapToolbarView : View() {
|
||||
isSnapToTicks = true
|
||||
minorTickCount = 0
|
||||
|
||||
enableWhen(isTileLayerSelected)
|
||||
enableWhen(isTileLayerSelected.or(isObjectLayerSelected))
|
||||
|
||||
valueProperty().addListener { _, _, newValue ->
|
||||
brushVM.item = brushVM.withRange(newValue.toInt())
|
||||
|
||||
Reference in New Issue
Block a user