[Editor] Add support for animated auto tiles #2
This commit is contained in:
@@ -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<Boolean>(key, initialValue, editable, true, onCommit, true) {
|
||||
) : Parameter<Boolean>(key, initialValue, editable, autocommit, onCommit, true) {
|
||||
override val editor = CheckBox()
|
||||
|
||||
override val editorValueProperty = editor.selectedProperty()
|
||||
|
||||
@@ -14,6 +14,8 @@ class AutoTileLayer(
|
||||
rows: Int,
|
||||
columns: Int,
|
||||
autoTileAsset: AutoTileAsset,
|
||||
animated: Boolean,
|
||||
animationDuration: Double,
|
||||
layer: Array<Array<Int>> = 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
|
||||
|
||||
|
||||
@@ -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<AutoTileLayer> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -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<Tile?>> = 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<Int>> = 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 {
|
||||
|
||||
@@ -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() }
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ class MapLayersView : View() {
|
||||
val scope = UndoableScope()
|
||||
find<SelectGraphicAssetFragment<AutoTileAsset>>(scope, SelectGraphicAssetFragment<AutoTileAsset>::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)
|
||||
|
||||
Reference in New Issue
Block a user