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