diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/BooleanParameter.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/BooleanParameter.kt index 9cc3cace..23ac0489 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/BooleanParameter.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/BooleanParameter.kt @@ -7,8 +7,9 @@ class BooleanParameter( key: String, initialValue: Boolean = false, editable: Boolean = true, + autocommit: Boolean = true, onCommit: (oldValue: Boolean, newValue: Boolean, submit: () -> Unit) -> Unit = { _, _, submit -> submit() } -) : Parameter(key, initialValue, editable, true, onCommit, true) { +) : Parameter(key, initialValue, editable, autocommit, onCommit, true) { override val editor = CheckBox() override val editorValueProperty = editor.selectedProperty() diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/AutoTileLayer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/AutoTileLayer.kt index 86964f39..b0b6c57e 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/AutoTileLayer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/model/layer/AutoTileLayer.kt @@ -14,6 +14,8 @@ class AutoTileLayer( rows: Int, columns: Int, autoTileAsset: AutoTileAsset, + animated: Boolean, + animationDuration: Double, layer: Array> = Array(rows) { Array(columns) { 0 } } ) : Layer { var layer = layer @@ -28,8 +30,22 @@ class AutoTileLayer( val autoTileAssetProperty = autoTileAsset.toProperty() var autoTileAsset by autoTileAssetProperty + val animatedProperty = animated.toProperty() + var animated by animatedProperty + + val animationDurationProperty = animationDuration.toProperty() + var animationDuration by animationDurationProperty + val autoTileProperty = Bindings.createObjectBinding({ - autoTileAsset.file.inputStream().use { fis -> AutoTile(autoTileAsset.uid, autoTileAsset.name, Image(fis), autoTileAsset.rows, autoTileAsset.columns) } + autoTileAsset.file.inputStream().use { fis -> + AutoTile( + autoTileAsset.uid, + autoTileAsset.name, + Image(fis), + autoTileAsset.rows, + autoTileAsset.columns + ) + } }, autoTileAssetProperty) val autoTile by autoTileProperty diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/AutoTileLayerParametersBinder.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/AutoTileLayerParametersBinder.kt index c104f65e..ce973432 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/AutoTileLayerParametersBinder.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/parameter/layer/AutoTileLayerParametersBinder.kt @@ -1,5 +1,7 @@ package com.bartlomiejpluta.base.editor.map.parameter.layer +import com.bartlomiejpluta.base.editor.common.parameter.model.BooleanParameter +import com.bartlomiejpluta.base.editor.common.parameter.model.DoubleParameter import com.bartlomiejpluta.base.editor.common.parameter.model.GraphicAssetParameter import com.bartlomiejpluta.base.editor.common.parameter.model.Parameter import com.bartlomiejpluta.base.editor.map.model.layer.AutoTileLayer @@ -20,8 +22,21 @@ class AutoTileLayerParametersBinder : LayerParametersBinder { submit() } - autoTile.bindBidirectional(layer.autoTileAssetProperty) + val animated = BooleanParameter("animated", layer.animated) { _, _, submit -> + onCommit() + submit() + } - parameters.addAll(autoTile) + val animationDuration = + DoubleParameter("animationDuration", layer.animationDuration, autocommit = true) { _, _, submit -> + onCommit() + submit() + } + + autoTile.bindBidirectional(layer.autoTileAssetProperty) + animated.bindBidirectional(layer.animatedProperty) + animationDuration.bindBidirectional(layer.animationDurationProperty) + + parameters.addAll(autoTile, animated, animationDuration) } } \ No newline at end of file diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt index c19a8ab1..e96b483b 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapDeserializer.kt @@ -25,7 +25,11 @@ class ProtobufMapDeserializer : MapDeserializer { override fun deserialize(input: InputStream) = deserialize(input, { _, uid -> uid }, { _, uid -> uid }) - override fun deserialize(input: InputStream, replaceTileSet: (String, String) -> String, replaceAutoTile: (String, String) -> String): GameMap { + override fun deserialize( + input: InputStream, + replaceTileSet: (String, String) -> String, + replaceAutoTile: (String, String) -> String + ): GameMap { val proto = GameMapProto.GameMap.parseFrom(input) val map = GameMap(proto.tileWidth.toDouble(), proto.tileHeight.toDouble()) map.uid = proto.uid @@ -40,7 +44,13 @@ class ProtobufMapDeserializer : MapDeserializer { return map } - private fun deserializeLayer(rows: Int, columns: Int, proto: GameMapProto.Layer, replaceTileSet: (String, String) -> String, replaceAutoTile: (String, String) -> String): Layer { + private fun deserializeLayer( + rows: Int, + columns: Int, + proto: GameMapProto.Layer, + replaceTileSet: (String, String) -> String, + replaceAutoTile: (String, String) -> String + ): Layer { return when { proto.hasTileLayer() -> deserializeTileLayer(rows, columns, proto, replaceTileSet) proto.hasAutoTileLayer() -> deserializeAutoTileLayer(rows, columns, proto, replaceAutoTile) @@ -52,7 +62,12 @@ class ProtobufMapDeserializer : MapDeserializer { } } - private fun deserializeTileLayer(rows: Int, columns: Int, proto: GameMapProto.Layer, replaceTileSet: (String, String) -> String): Layer { + private fun deserializeTileLayer( + rows: Int, + columns: Int, + proto: GameMapProto.Layer, + replaceTileSet: (String, String) -> String + ): Layer { val layer: Array> = Array(rows) { Array(columns) { null } } val tileSetAsset = projectContext.findTileSetAsset(replaceTileSet(proto.name, proto.tileLayer.tilesetUID)) val tileSet = projectContext.loadTileSet(tileSetAsset.uid) @@ -67,7 +82,12 @@ class ProtobufMapDeserializer : MapDeserializer { return TileLayer(proto.name, rows, columns, tileSetAsset, layer) } - private fun deserializeAutoTileLayer(rows: Int, columns: Int, proto: GameMapProto.Layer, replaceTileSet: (String, String) -> String): AutoTileLayer { + private fun deserializeAutoTileLayer( + rows: Int, + columns: Int, + proto: GameMapProto.Layer, + replaceTileSet: (String, String) -> String + ): AutoTileLayer { val layer: Array> = Array(rows) { Array(columns) { 0 } } val autoTile = projectContext.findAutoTileAsset(replaceTileSet(proto.name, proto.autoTileLayer.autotileUID)) @@ -75,7 +95,15 @@ class ProtobufMapDeserializer : MapDeserializer { layer[index / columns][index % columns] = tile } - return AutoTileLayer(proto.name, rows, columns, autoTile, layer) + return AutoTileLayer( + proto.name, + rows, + columns, + autoTile, + proto.autoTileLayer.animated, + proto.autoTileLayer.animationDuration, + layer + ) } private fun deserializeObjectLayer(rows: Int, columns: Int, proto: GameMapProto.Layer): Layer { diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt index b9eb139a..3afde373 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/serial/ProtobufMapSerializer.kt @@ -36,6 +36,8 @@ class ProtobufMapSerializer : MapSerializer { is AutoTileLayer -> layer.layer.flatMap { it.asIterable() } .fold(GameMapProto.AutoTileLayer.newBuilder()) { acc, tile -> acc.addTiles(tile) } .setAutotileUID(layer.autoTileAsset.uid) + .setAnimated(layer.animated) + .setAnimationDuration(layer.animationDuration) .build() .let { GameMapProto.Layer.newBuilder().setName(layer.name).setAutoTileLayer(it).build() } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt index beeb7d06..5fbcf333 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/map/view/editor/MapLayersView.kt @@ -80,7 +80,8 @@ class MapLayersView : View() { val scope = UndoableScope() find>(scope, SelectGraphicAssetFragment::assets to projectContext.project?.autoTiles!!).apply { onComplete { - val layer = AutoTileLayer("Layer ${mapVM.layers.size + 1}", mapVM.rows, mapVM.columns, it) + val layer = + AutoTileLayer("Layer ${mapVM.layers.size + 1}", mapVM.rows, mapVM.columns, it, false, 1.0) val command = CreateLayerCommand(mapVM.item, layer) command.execute() layersPane.selectionModel.select(mapVM.layers.size - 1)