[Editor] Create MapObject model and enable its serialization
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.bartlomiejpluta.base.editor.map.model.layer
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
||||
import com.bartlomiejpluta.base.editor.map.model.obj.MapObject
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.asObservable
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
|
||||
@@ -9,11 +11,14 @@ class ObjectLayer(
|
||||
name: String,
|
||||
rows: Int,
|
||||
columns: Int,
|
||||
objects: List<MapObject> = emptyList(),
|
||||
passageMap: Array<Array<PassageAbility>> = Array(rows) { Array(columns) { PassageAbility.ALLOW } }
|
||||
) : Layer {
|
||||
var passageMap = passageMap
|
||||
private set
|
||||
|
||||
val objects = objects.asObservable()
|
||||
|
||||
override val nameProperty = SimpleStringProperty(name)
|
||||
|
||||
override fun resize(rows: Int, columns: Int) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.bartlomiejpluta.base.editor.map.model.obj
|
||||
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
import tornadofx.toProperty
|
||||
|
||||
class MapObject(x: Int, y: Int, code: String) {
|
||||
val xProperty = x.toProperty()
|
||||
var x by xProperty
|
||||
|
||||
val yProperty = y.toProperty()
|
||||
var y by yProperty
|
||||
|
||||
val codeProperty = code.toProperty()
|
||||
var code by codeProperty
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.bartlomiejpluta.base.editor.map.model.enumeration.ImageLayerMode
|
||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.*
|
||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
||||
import com.bartlomiejpluta.base.editor.map.model.obj.MapObject
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import com.bartlomiejpluta.base.editor.tileset.model.Tile
|
||||
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
||||
@@ -68,7 +69,11 @@ class ProtobufMapDeserializer : MapDeserializer {
|
||||
}
|
||||
}
|
||||
|
||||
return ObjectLayer(proto.name, rows, columns, passageMap)
|
||||
val objects = proto.objectLayer.objectsList.map {
|
||||
MapObject(it.x, it.y, it.code)
|
||||
}
|
||||
|
||||
return ObjectLayer(proto.name, rows, columns, objects, passageMap)
|
||||
}
|
||||
|
||||
private fun deserializeColorLayer(proto: GameMapProto.Layer): Layer {
|
||||
|
||||
@@ -40,6 +40,15 @@ class ProtobufMapSerializer : MapSerializer {
|
||||
}
|
||||
)
|
||||
}
|
||||
.also { proto ->
|
||||
layer.objects.map {
|
||||
proto.addObjects(GameMapProto.MapObject.newBuilder().apply {
|
||||
x = it.x
|
||||
y = it.y
|
||||
code = it.code
|
||||
})
|
||||
}
|
||||
}
|
||||
.build()
|
||||
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user