diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt index 548fdc58..d049ce17 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/model/map/map/GameMap.kt @@ -3,6 +3,8 @@ package com.bartlomiejpluta.base.editor.model.map.map import com.bartlomiejpluta.base.editor.model.map.layer.Layer import com.bartlomiejpluta.base.editor.model.tileset.TileSet import javafx.beans.property.ReadOnlyDoubleWrapper +import javafx.beans.property.ReadOnlyFloatProperty +import javafx.beans.property.SimpleDoubleProperty import javafx.beans.property.SimpleIntegerProperty import tornadofx.* @@ -11,9 +13,31 @@ class GameMap(val tileSet: TileSet, initialColumns: Int, initialRows: Int) { val layers = observableListOf() val mapProperties = observableListOf() + + val tileWidth = tileSet.tileWidth.toDouble() + val tileHeight = tileSet.tileHeight.toDouble() + val rowsProperty = SimpleIntegerProperty(initialRows) val rows by rowsProperty val columnsProperty = SimpleIntegerProperty(initialColumns) val columns by columnsProperty + + val widthProperty = SimpleDoubleProperty(initialColumns * tileWidth) + var width by widthProperty + private set + + val heightProperty = SimpleDoubleProperty(initialRows * tileHeight) + var height by heightProperty + private set + + init { + rowsProperty.addListener { _, _, newValue -> + height = newValue.toInt() * tileWidth + } + + columnsProperty.addListener { _, _, newValue -> + width = newValue.toInt() * tileWidth + } + } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt index 2df1f86c..688ca4b3 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/render/canvas/map/MapCanvas.kt @@ -11,13 +11,13 @@ import org.slf4j.LoggerFactory class MapCanvas(val map: GameMapVM, private val painter: MapPainter) : Renderable { var tileSet = map.tileSet - private var tileWidth = tileSet.tileWidth.toDouble() - private var tileHeight = tileSet.tileHeight.toDouble() + private var tileWidth = map.tileWidth + private var tileHeight = map.tileHeight override fun render(gc: GraphicsContext) { log.debug("vm.dim = ${map.rows}x${map.columns} | map.dim = ${map.item.rows}x${map.item.columns}") -// log.debug("vm.size = ${map.width}x${map.height} | map.size = ${map.item.width}x${map.item.height}") + log.debug("vm.size = ${map.width}x${map.height} | map.size = ${map.item.width}x${map.item.height}") gc.clearRect(0.0, 0.0, gc.canvas.width, gc.canvas.height) renderBackground(gc) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt index 034d38a5..a6b86e86 100755 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/viewmodel/map/GameMapVM.kt @@ -3,6 +3,7 @@ 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 com.bartlomiejpluta.base.editor.model.map.map.MapProperty +import com.bartlomiejpluta.base.editor.model.tileset.TileSet import javafx.beans.property.ReadOnlyDoubleWrapper import javafx.beans.property.SimpleIntegerProperty import javafx.beans.property.SimpleListProperty @@ -21,11 +22,22 @@ class GameMapVM : ItemViewModel() { val columnsProperty = bind(GameMap::columnsProperty) var columns by columnsProperty - val widthProperty = ReadOnlyDoubleWrapper().apply { bind(columnsProperty.multiply(32.0)) } + val tileWidthProperty = bind(GameMap::tileWidth) + val tileWidth by tileWidthProperty + + val tileHeightProperty = bind(GameMap::tileHeight) + val tileHeight by tileHeightProperty + + val widthProperty = bind(GameMap::widthProperty) val width by widthProperty - val heightProperty = ReadOnlyDoubleWrapper().apply { bind(rowsProperty.multiply(32.0)) } + val heightProperty = bind(GameMap::heightProperty) val height by heightProperty +// val widthProperty = ReadOnlyDoubleWrapper().apply { bind(tileSetProperty.getProperty(TileSet::tileWidthProperty)) } +// val width by widthProperty +// +// val heightProperty = ReadOnlyDoubleWrapper().apply { bind(rowsProperty.multiply(32.0)) } +// val height by heightProperty val selectedLayerProperty = SimpleIntegerProperty(0) val selectedLayer by selectedLayerProperty