Create MapHandler API scaffolding

This commit is contained in:
2021-03-01 20:56:59 +01:00
parent a4fe85e87c
commit 0b6137c0ca
16 changed files with 67 additions and 5 deletions

View File

@@ -56,6 +56,7 @@ class MainController : Controller() {
val map = GameMap(tileSet).apply {
rows = vm.rows
columns = vm.columns
handler = vm.handler
}
projectContext.importMap(vm.name, map)
openItems[scope] = map

View File

@@ -2,13 +2,11 @@ package com.bartlomiejpluta.base.editor.map.model.map
import com.bartlomiejpluta.base.editor.map.model.layer.Layer
import com.bartlomiejpluta.base.editor.tileset.model.TileSet
import javafx.beans.property.ReadOnlyStringWrapper
import javafx.beans.property.SimpleDoubleProperty
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleStringProperty
import javafx.collections.FXCollections
import tornadofx.getValue
import tornadofx.observableListOf
import tornadofx.setValue
@@ -35,6 +33,9 @@ class GameMap(val tileSet: TileSet) {
var height by heightProperty
private set
val handlerProperty = SimpleStringProperty()
var handler by handlerProperty
init {
rowsProperty.addListener { _, _, newValue ->
val newRows = newValue.toInt()

View File

@@ -19,4 +19,7 @@ class GameMapBuilder {
val columnsProperty = SimpleIntegerProperty(20)
var columns by columnsProperty
val handlerProperty = SimpleStringProperty()
var handler by handlerProperty
}

View File

@@ -25,6 +25,7 @@ class ProtobufMapDeserializer : MapDeserializer {
map.uid = proto.uid
map.rows = proto.rows
map.columns = proto.columns
map.handler = proto.handler
proto.layersList.forEach {
map.layers.add(deserializeLayer(map.rows, map.columns, tileSet, it))

View File

@@ -17,6 +17,7 @@ class ProtobufMapSerializer : MapSerializer {
protoMap.rows = item.rows
protoMap.columns = item.columns
protoMap.tileSetUID = item.tileSet.uid
protoMap.handler = item.handler
item.layers.forEach { layer -> protoMap.addLayers(serializeLayer(layer)) }

View File

@@ -1,6 +1,7 @@
package com.bartlomiejpluta.base.editor.map.view.editor
import com.bartlomiejpluta.base.editor.common.parameter.model.IntegerParameter
import com.bartlomiejpluta.base.editor.common.parameter.model.JavaClassParameter
import com.bartlomiejpluta.base.editor.common.parameter.view.ParametersTableFragment
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
import tornadofx.View
@@ -12,6 +13,7 @@ class MapParameters : View() {
private val parameters = observableListOf(
IntegerParameter("rows", mapVM.rows, 1, 100).apply { bindBidirectional(mapVM.item.rowsProperty) },
IntegerParameter("columns", mapVM.columns, 1, 100).apply { bindBidirectional(mapVM.item.columnsProperty) },
JavaClassParameter("handler", mapVM.handler).apply { bindBidirectional(mapVM.item.handlerProperty) }
)
override val root = find<ParametersTableFragment>(ParametersTableFragment::parameters to parameters).root

View File

@@ -7,7 +7,12 @@ import tornadofx.*
class MapCreationBasicDataView : View("Basic Data") {
private val mapBuilderVM = find<GameMapBuilderVM>()
override val complete = mapBuilderVM.valid(mapBuilderVM.nameProperty, mapBuilderVM.rowsProperty, mapBuilderVM.columnsProperty)
override val complete = mapBuilderVM.valid(
mapBuilderVM.nameProperty,
mapBuilderVM.rowsProperty,
mapBuilderVM.columnsProperty,
mapBuilderVM.handlerProperty
)
override val root = form {
fieldset("Map Settings") {
@@ -47,6 +52,13 @@ class MapCreationBasicDataView : View("Basic Data") {
}
}
}
field("Map Handler class") {
textfield(mapBuilderVM.handlerProperty) {
required()
trimWhitespace()
}
}
}
}
}

View File

@@ -17,4 +17,7 @@ class GameMapBuilderVM : ItemViewModel<GameMapBuilder>(GameMapBuilder()) {
val columnsProperty = bind(GameMapBuilder::columnsProperty, autocommit = true)
var columns by columnsProperty
val handlerProperty = bind(GameMapBuilder::handlerProperty, autocommit = true)
var handler by handlerProperty
}

View File

@@ -30,6 +30,9 @@ class GameMapVM(map: GameMap) : ItemViewModel<GameMap>(map) {
val heightProperty = bind(GameMap::heightProperty)
val height by heightProperty
val handlerProperty = bind(GameMap::handlerProperty)
var handler by handlerProperty
}

View File

@@ -91,6 +91,7 @@ class DefaultProjectContext : ProjectContext {
it.maps += asset
save()
javaClassService.createClassFile(map.handler, it.codeFSNode, "map_handler.ftl")
File(it.mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
}
}

View File

@@ -0,0 +1,12 @@
package ${package};
import com.bartlomiejpluta.base.api.map.MapHandler;
import com.bartlomiejpluta.base.api.context.Context;
public class ${className} implements MapHandler {
@Override
public void init(Context context) {
throw new RuntimeException("Not implemented yet");
}
}