[Editor] Enable serialization and deserialization for passage map of ObjectLayer
This commit is contained in:
@@ -5,7 +5,7 @@ import javafx.scene.canvas.GraphicsContext
|
||||
import javafx.scene.paint.Color
|
||||
|
||||
object PassageAbilitySymbol {
|
||||
private const val SIZE = 0.6
|
||||
private const val SIZE = 0.7
|
||||
|
||||
fun render(gc: GraphicsContext, x: Double, y: Double, w: Double, h: Double, passageAbility: PassageAbility) {
|
||||
val fill = gc.fill
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.editor.map.serial
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||
@@ -58,7 +59,21 @@ class ProtobufMapDeserializer : MapDeserializer {
|
||||
}
|
||||
|
||||
private fun deserializeObjectLayer(rows: Int, columns: Int, proto: GameMapProto.Layer): Layer {
|
||||
return ObjectLayer(proto.name, rows, columns)
|
||||
val passageMap: Array<Array<PassageAbility>> = Array(rows) { Array(columns) { PassageAbility.ALLOW } }
|
||||
|
||||
proto.objectLayer.passageMapList.forEachIndexed { index, passage ->
|
||||
passageMap[index / columns][index % columns] = when (passage) {
|
||||
GameMapProto.PassageAbility.ALLOW -> PassageAbility.ALLOW
|
||||
GameMapProto.PassageAbility.BLOCK -> PassageAbility.BLOCK
|
||||
GameMapProto.PassageAbility.UP_ONLY -> PassageAbility.UP_ONLY
|
||||
GameMapProto.PassageAbility.DOWN_ONLY -> PassageAbility.DOWN_ONLY
|
||||
GameMapProto.PassageAbility.LEFT_ONLY -> PassageAbility.LEFT_ONLY
|
||||
GameMapProto.PassageAbility.RIGHT_ONLY -> PassageAbility.RIGHT_ONLY
|
||||
else -> throw IllegalStateException("Unknown passage ability type")
|
||||
}
|
||||
}
|
||||
|
||||
return ObjectLayer(proto.name, rows, columns, passageMap)
|
||||
}
|
||||
|
||||
private fun deserializeImageLayer(proto: GameMapProto.Layer): Layer {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bartlomiejpluta.base.editor.map.serial
|
||||
|
||||
import com.bartlomiejpluta.base.editor.map.model.enumeration.PassageAbility
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.ImageLayer
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.Layer
|
||||
import com.bartlomiejpluta.base.editor.map.model.layer.ObjectLayer
|
||||
@@ -31,7 +32,19 @@ class ProtobufMapSerializer : MapSerializer {
|
||||
.build()
|
||||
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setTileLayer(it).build() }
|
||||
|
||||
is ObjectLayer -> GameMapProto.ObjectLayer.newBuilder()
|
||||
is ObjectLayer -> layer.passageMap.flatMap { it.asIterable() }
|
||||
.fold(GameMapProto.ObjectLayer.newBuilder()) { acc, passage ->
|
||||
acc.addPassageMap(
|
||||
when (passage) {
|
||||
PassageAbility.ALLOW -> GameMapProto.PassageAbility.ALLOW
|
||||
PassageAbility.BLOCK -> GameMapProto.PassageAbility.BLOCK
|
||||
PassageAbility.UP_ONLY -> GameMapProto.PassageAbility.UP_ONLY
|
||||
PassageAbility.DOWN_ONLY -> GameMapProto.PassageAbility.DOWN_ONLY
|
||||
PassageAbility.LEFT_ONLY -> GameMapProto.PassageAbility.LEFT_ONLY
|
||||
PassageAbility.RIGHT_ONLY -> GameMapProto.PassageAbility.RIGHT_ONLY
|
||||
}
|
||||
)
|
||||
}
|
||||
.build()
|
||||
.let { GameMapProto.Layer.newBuilder().setName(layer.name).setObjectLayer(it).build() }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.game.map.serial;
|
||||
|
||||
import com.bartlomiejpluta.base.core.error.AppException;
|
||||
import com.bartlomiejpluta.base.game.map.layer.object.PassageAbility;
|
||||
import com.bartlomiejpluta.base.game.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.game.tileset.manager.TileSetManager;
|
||||
import com.bartlomiejpluta.base.proto.GameMapProto;
|
||||
@@ -58,6 +59,19 @@ public class ProtobufMapDeserializer extends MapDeserializer {
|
||||
|
||||
private void deserializeObjectLayer(GameMap map, GameMapProto.Layer proto) {
|
||||
var layer = map.createObjectLayer();
|
||||
var columns = map.getColumns();
|
||||
var passageMap = proto.getObjectLayer().getPassageMapList();
|
||||
|
||||
for (var i = 0; i < passageMap.size(); ++i) {
|
||||
map.setPassageAbility(layer, i / columns, i % columns, switch (passageMap.get(i)) {
|
||||
case ALLOW -> PassageAbility.ALLOW;
|
||||
case BLOCK -> PassageAbility.BLOCK;
|
||||
case RIGHT_ONLY -> PassageAbility.RIGHT_ONLY;
|
||||
case LEFT_ONLY -> PassageAbility.LEFT_ONLY;
|
||||
case DOWN_ONLY -> PassageAbility.DOWN_ONLY;
|
||||
case UP_ONLY -> PassageAbility.UP_ONLY;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void deserializeImageLayer(GameMap map, GameMapProto.Layer proto) {
|
||||
|
||||
@@ -26,7 +26,16 @@ message TileLayer {
|
||||
}
|
||||
|
||||
message ObjectLayer {
|
||||
// TODO list of passage abilities
|
||||
repeated PassageAbility passageMap = 1;
|
||||
}
|
||||
|
||||
enum PassageAbility {
|
||||
ALLOW = 0;
|
||||
BLOCK = 1;
|
||||
UP_ONLY = 2;
|
||||
DOWN_ONLY = 3;
|
||||
LEFT_ONLY = 4;
|
||||
RIGHT_ONLY = 5;
|
||||
}
|
||||
|
||||
message ImageLayer {
|
||||
|
||||
Reference in New Issue
Block a user