[Editor] Create runner class parameter in Project
This commit is contained in:
@@ -10,7 +10,7 @@ import tornadofx.toProperty
|
|||||||
|
|
||||||
class JavaClassParameter(
|
class JavaClassParameter(
|
||||||
key: String,
|
key: String,
|
||||||
initialValue: String,
|
initialValue: String = "",
|
||||||
editable: Boolean = true,
|
editable: Boolean = true,
|
||||||
onCommit: (oldValue: String, newValue: String, submit: () -> Unit) -> Unit = { _, _, submit -> submit() }
|
onCommit: (oldValue: String, newValue: String, submit: () -> Unit) -> Unit = { _, _, submit -> submit() }
|
||||||
) : Parameter<String>(key, initialValue, editable, false, onCommit) {
|
) : Parameter<String>(key, initialValue, editable, false, onCommit) {
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ class Project {
|
|||||||
val projectFileProperty = createObjectBinding({ File(sourceDirectory, PROJECT_FILE) }, sourceDirectoryProperty)
|
val projectFileProperty = createObjectBinding({ File(sourceDirectory, PROJECT_FILE) }, sourceDirectoryProperty)
|
||||||
val projectFile by projectFileProperty
|
val projectFile by projectFileProperty
|
||||||
|
|
||||||
|
val runnerProperty = SimpleStringProperty()
|
||||||
|
var runner by runnerProperty
|
||||||
|
|
||||||
val maps = observableListOf<GameMapAsset>()
|
val maps = observableListOf<GameMapAsset>()
|
||||||
val tileSets = observableListOf<TileSetAsset>()
|
val tileSets = observableListOf<TileSetAsset>()
|
||||||
val images = observableListOf<ImageAsset>()
|
val images = observableListOf<ImageAsset>()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class ProtobufProjectDeserializer : ProjectDeserializer {
|
|||||||
val proto = ProjectProto.Project.parseFrom(input)
|
val proto = ProjectProto.Project.parseFrom(input)
|
||||||
val project = Project()
|
val project = Project()
|
||||||
project.name = proto.name
|
project.name = proto.name
|
||||||
|
project.runner = proto.runner
|
||||||
project.maps.addAll(proto.mapsList.map { deserializeMap(project, it) })
|
project.maps.addAll(proto.mapsList.map { deserializeMap(project, it) })
|
||||||
project.tileSets.addAll(proto.tileSetsList.map { deserializeTileSet(project, it) })
|
project.tileSets.addAll(proto.tileSetsList.map { deserializeTileSet(project, it) })
|
||||||
project.images.addAll(proto.imagesList.map { deserializeImage(project, it) })
|
project.images.addAll(proto.imagesList.map { deserializeImage(project, it) })
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class ProtobufProjectSerializer : ProjectSerializer {
|
|||||||
override fun serialize(item: Project, output: OutputStream) {
|
override fun serialize(item: Project, output: OutputStream) {
|
||||||
val proto = ProjectProto.Project.newBuilder()
|
val proto = ProjectProto.Project.newBuilder()
|
||||||
proto.name = item.name
|
proto.name = item.name
|
||||||
|
proto.runner = item.runner
|
||||||
proto.addAllMaps(item.maps.map(this::serializeMap))
|
proto.addAllMaps(item.maps.map(this::serializeMap))
|
||||||
proto.addAllTileSets(item.tileSets.map(this::serializeTileSet))
|
proto.addAllTileSets(item.tileSets.map(this::serializeTileSet))
|
||||||
proto.addAllImages(item.images.map(this::serializeImage))
|
proto.addAllImages(item.images.map(this::serializeImage))
|
||||||
|
|||||||
@@ -11,25 +11,25 @@ import tornadofx.observableListOf
|
|||||||
class ProjectParametersView : View() {
|
class ProjectParametersView : View() {
|
||||||
private val projectContext: ProjectContext by di()
|
private val projectContext: ProjectContext by di()
|
||||||
private val name = SimpleStringProperty()
|
private val name = SimpleStringProperty()
|
||||||
|
private val runner = SimpleStringProperty()
|
||||||
|
|
||||||
private val parameters = observableListOf(
|
private val parameters = observableListOf(
|
||||||
StringParameter("name", "", onCommit = { _, _, submit ->
|
StringParameter("name", onCommit = { _, _, submit ->
|
||||||
submit()
|
submit()
|
||||||
projectContext.save()
|
projectContext.save()
|
||||||
}).apply { bindBidirectional(name) },
|
}).apply { bindBidirectional(name) },
|
||||||
|
|
||||||
// TODO: It should never be null so it is required Project to have a gameClass set
|
JavaClassParameter("runner", onCommit = { _, _, submit ->
|
||||||
// from its initialization via New project dialog.
|
submit()
|
||||||
// In that case, the initialValue will ever be a projectContext.project.gameClass
|
projectContext.save()
|
||||||
// The "Select class..." placeholder is temporary and it should never be here, because
|
}).apply { bindBidirectional(runner) }
|
||||||
// the game engine would treat the "Select class..." string as a game class name.
|
|
||||||
JavaClassParameter("gameClass", "Select class...")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
projectContext.projectProperty.addListener { _, _, project ->
|
projectContext.projectProperty.addListener { _, _, project ->
|
||||||
project?.let {
|
project?.let {
|
||||||
name.bindBidirectional(it.nameProperty)
|
name.bindBidirectional(it.nameProperty)
|
||||||
|
runner.bindBidirectional(it.runnerProperty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,16 +65,23 @@ class ProjectSettingsFragment : Fragment("Project Settings") {
|
|||||||
trimWhitespace()
|
trimWhitespace()
|
||||||
|
|
||||||
projectVM.validationContext.addValidator(this, projectDirectory) {
|
projectVM.validationContext.addValidator(this, projectDirectory) {
|
||||||
when {
|
when {
|
||||||
it.isNullOrBlank() -> error("Field is required")
|
it.isNullOrBlank() -> error("Field is required")
|
||||||
File(directory.value).exists() -> error("The directory ${directory.value} already exists")
|
File(directory.value).exists() -> error("The directory ${directory.value} already exists")
|
||||||
else -> null
|
else -> null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
label(Bindings.format("Directory:\n%s", directory))
|
label(Bindings.format("Directory:\n%s", directory))
|
||||||
|
|
||||||
|
field("Game Runner class") {
|
||||||
|
textfield(projectVM.runnerProperty) {
|
||||||
|
required()
|
||||||
|
trimWhitespace()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonbar {
|
buttonbar {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class ProjectVM(project: Project) : ItemViewModel<Project>(project) {
|
|||||||
val nameProperty = bind(Project::nameProperty)
|
val nameProperty = bind(Project::nameProperty)
|
||||||
val sourceDirectoryProperty = bind(Project::sourceDirectoryProperty)
|
val sourceDirectoryProperty = bind(Project::sourceDirectoryProperty)
|
||||||
val projectFileProperty = bind(Project::projectFileProperty)
|
val projectFileProperty = bind(Project::projectFileProperty)
|
||||||
|
val runnerProperty = bind(Project::runnerProperty)
|
||||||
val mapsDirectoryProperty = bind(Project::mapsDirectoryProperty)
|
val mapsDirectoryProperty = bind(Project::mapsDirectoryProperty)
|
||||||
val tileSetsDirectoryProperty = bind(Project::tileSetsDirectoryProperty)
|
val tileSetsDirectoryProperty = bind(Project::tileSetsDirectoryProperty)
|
||||||
val imagesDirectoryProperty = bind(Project::imagesDirectoryProperty)
|
val imagesDirectoryProperty = bind(Project::imagesDirectoryProperty)
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ option java_outer_classname = "ProjectProto";
|
|||||||
|
|
||||||
message Project {
|
message Project {
|
||||||
required string name = 1;
|
required string name = 1;
|
||||||
repeated GameMapAsset maps = 2;
|
required string runner = 2;
|
||||||
repeated TileSetAsset tileSets = 3;
|
repeated GameMapAsset maps = 3;
|
||||||
repeated ImageAsset images = 4;
|
repeated TileSetAsset tileSets = 4;
|
||||||
|
repeated ImageAsset images = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GameMapAsset {
|
message GameMapAsset {
|
||||||
|
|||||||
Reference in New Issue
Block a user