[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
|
package com.bartlomiejpluta.base.editor.map.model.layer
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
||||||
|
import com.bartlomiejpluta.base.editor.map.model.obj.MapObject
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import tornadofx.asObservable
|
||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
|
|
||||||
@@ -9,11 +11,14 @@ class ObjectLayer(
|
|||||||
name: String,
|
name: String,
|
||||||
rows: Int,
|
rows: Int,
|
||||||
columns: Int,
|
columns: Int,
|
||||||
|
objects: List<MapObject> = emptyList(),
|
||||||
passageMap: Array<Array<PassageAbility>> = Array(rows) { Array(columns) { PassageAbility.ALLOW } }
|
passageMap: Array<Array<PassageAbility>> = Array(rows) { Array(columns) { PassageAbility.ALLOW } }
|
||||||
) : Layer {
|
) : Layer {
|
||||||
var passageMap = passageMap
|
var passageMap = passageMap
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
val objects = objects.asObservable()
|
||||||
|
|
||||||
override val nameProperty = SimpleStringProperty(name)
|
override val nameProperty = SimpleStringProperty(name)
|
||||||
|
|
||||||
override fun resize(rows: Int, columns: Int) {
|
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.enumeration.PassageAbility
|
||||||
import com.bartlomiejpluta.base.editor.map.model.layer.*
|
import com.bartlomiejpluta.base.editor.map.model.layer.*
|
||||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
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.project.context.ProjectContext
|
||||||
import com.bartlomiejpluta.base.editor.tileset.model.Tile
|
import com.bartlomiejpluta.base.editor.tileset.model.Tile
|
||||||
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
|
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 {
|
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()
|
.build()
|
||||||
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ message TileLayer {
|
|||||||
|
|
||||||
message ObjectLayer {
|
message ObjectLayer {
|
||||||
repeated PassageAbility passageMap = 1;
|
repeated PassageAbility passageMap = 1;
|
||||||
|
repeated MapObject objects = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PassageAbility {
|
enum PassageAbility {
|
||||||
@@ -36,6 +37,12 @@ enum PassageAbility {
|
|||||||
BLOCK = 1;
|
BLOCK = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message MapObject {
|
||||||
|
required uint32 x = 1;
|
||||||
|
required uint32 y = 2;
|
||||||
|
required string code = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message ColorLayer {
|
message ColorLayer {
|
||||||
required uint32 red = 1;
|
required uint32 red = 1;
|
||||||
required uint32 green = 2;
|
required uint32 green = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user