[Editor] Refactor brush code
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -39,6 +39,7 @@ class MapView : View() {
|
||||
|
||||
init {
|
||||
brushVM.item = mapVM.tileSet.baseBrush
|
||||
brushVM.commit()
|
||||
|
||||
subscribe<RedrawMapRequestEvent> { mapPane.render() }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user