[Editor] Refactor brush code

This commit is contained in:
2021-02-07 16:07:29 +01:00
parent dc0de51b90
commit f96160614f
5 changed files with 8 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ import tornadofx.setValue
class Brush {
val brush: ObservableList<Tile>
val rowsProperty = SimpleIntegerProperty(this, "", 0)
val rowsProperty = SimpleIntegerProperty(0)
var rows by rowsProperty
private set
@@ -87,7 +87,7 @@ class Brush {
this.range = range
}
fun withBrushMode(mode: BrushMode) = clone().apply {
fun withMode(mode: BrushMode) = clone().apply {
this.mode = mode
}

View File

@@ -62,6 +62,7 @@ class TileSetSelection(private val gameMapVM: GameMapVM, private val brushVM: Br
}
brushVM.item = Brush.of(brushArray)
brushVM.commit()
}
override fun render(gc: GraphicsContext) {

View File

@@ -101,6 +101,7 @@ class MapToolbarView : View() {
action {
brushVM.item = brushVM.withMode(BrushMode.PAINTING_MODE)
brushVM.commit()
}
}
@@ -109,6 +110,7 @@ class MapToolbarView : View() {
action {
brushVM.item = brushVM.withMode(BrushMode.ERASING_MODE)
brushVM.commit()
}
}
@@ -121,6 +123,7 @@ class MapToolbarView : View() {
valueProperty().addListener { _, _, newValue ->
brushVM.item = brushVM.withRange(newValue.toInt())
brushVM.commit()
}
brushVM.itemProperty.addListener { _, _, brush ->

View File

@@ -39,6 +39,7 @@ class MapView : View() {
init {
brushVM.item = mapVM.tileSet.baseBrush
brushVM.commit()
subscribe<RedrawMapRequestEvent> { mapPane.render() }
}

View File

@@ -25,5 +25,5 @@ class BrushVM : ItemViewModel<Brush>(Brush.of(arrayOf(arrayOf()))) {
fun withRange(range: Int) = item.withRange(range)
fun withMode(mode: BrushMode) = item.withBrushMode(mode)
fun withMode(mode: BrushMode) = item.withMode(mode)
}