diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/JavaClassParameter.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/JavaClassParameter.kt index 6e6b2fce..9e2f28ce 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/JavaClassParameter.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/common/parameter/model/JavaClassParameter.kt @@ -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(key, initialValue, editable, false, onCommit) { diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt index ebe02a8a..ae621ffe 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/model/Project.kt @@ -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() val tileSets = observableListOf() val images = observableListOf() diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectDeserializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectDeserializer.kt index 319251e4..681e78bf 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectDeserializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectDeserializer.kt @@ -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) }) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectSerializer.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectSerializer.kt index d60eaacb..ea4612e8 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectSerializer.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/serial/ProtobufProjectSerializer.kt @@ -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)) diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectParametersView.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectParametersView.kt index 64b99526..a18cb8e6 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectParametersView.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectParametersView.kt @@ -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) } } } diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt index 3ceba004..8c2e5cec 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/view/ProjectSettingsFragment.kt @@ -65,16 +65,23 @@ class ProjectSettingsFragment : Fragment("Project Settings") { trimWhitespace() projectVM.validationContext.addValidator(this, projectDirectory) { - when { - it.isNullOrBlank() -> error("Field is required") - File(directory.value).exists() -> error("The directory ${directory.value} already exists") - else -> null - } + when { + it.isNullOrBlank() -> error("Field is required") + File(directory.value).exists() -> error("The directory ${directory.value} already exists") + else -> null } + } } } label(Bindings.format("Directory:\n%s", directory)) + + field("Game Runner class") { + textfield(projectVM.runnerProperty) { + required() + trimWhitespace() + } + } } buttonbar { diff --git a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt index 39105c6e..ad4c04ca 100644 --- a/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt +++ b/editor/src/main/kotlin/com/bartlomiejpluta/base/editor/project/viewmodel/ProjectVM.kt @@ -7,6 +7,7 @@ class ProjectVM(project: Project) : ItemViewModel(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) diff --git a/proto/src/main/proto/project.proto b/proto/src/main/proto/project.proto index bc6ce3f7..6adbda51 100644 --- a/proto/src/main/proto/project.proto +++ b/proto/src/main/proto/project.proto @@ -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 {