From 85b53862da50fe84f856bab0d91732d4a154ff65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Przemys=C5=82aw=20Pluta?= Date: Sun, 21 Feb 2021 20:24:21 +0100 Subject: [PATCH] [Editor] BUGFIX: The grid and background weren't be updated when rows or columns were changed --- .../base/editor/map/canvas/MapCanvas.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt index 5fb273ff..e04f5bd9 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/canvas/MapCanvas.kt @@ -15,15 +15,27 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr private var tileWidth = map.tileWidth private var tileHeight = map.tileHeight - private val grid = WritableImage(map.width.toInt(), map.height.toInt()) - private val background = WritableImage(map.width.toInt(), map.height.toInt()) + private lateinit var grid: WritableImage + private lateinit var background: WritableImage init { + map.widthProperty.addListener { _, _, _ -> + createGridImage() + createBackgroundImage() + } + + map.heightProperty.addListener { _, _, _ -> + createGridImage() + createBackgroundImage() + } + createGridImage() createBackgroundImage() } private fun createGridImage() { + grid = WritableImage(map.width.toInt(), map.height.toInt()) + val writer = grid.pixelWriter val color = Color.BLACK for (x in 0 until map.width.toInt()) { @@ -40,8 +52,9 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr } private fun createBackgroundImage() { - val writer = background.pixelWriter + background = WritableImage(map.width.toInt(), map.height.toInt()) + val writer = background.pixelWriter for (x in 0 until map.width.toInt()) { for (y in 0 until map.height.toInt()) { val color = when (((x / tileWidth.toInt()) + (y / tileHeight.toInt())) % 2) {