[Editor] Remove name property from GameMap object
This commit is contained in:
@@ -3,4 +3,5 @@ package com.bartlomiejpluta.base.editor.asset.model
|
|||||||
interface Asset {
|
interface Asset {
|
||||||
val uid: String
|
val uid: String
|
||||||
val source: String
|
val source: String
|
||||||
|
var name: String
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ class MainController : Controller() {
|
|||||||
find<MapCreationWizard>(scope).apply {
|
find<MapCreationWizard>(scope).apply {
|
||||||
onComplete {
|
onComplete {
|
||||||
vm.item.build().let { map ->
|
vm.item.build().let { map ->
|
||||||
projectContext.attachMap(map)
|
projectContext.importMap(vm.name, map)
|
||||||
openMaps[scope] = map
|
openMaps[scope] = map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class MainView : View("BASE Game Editor") {
|
|||||||
Tab().apply {
|
Tab().apply {
|
||||||
val vm = GameMapVM(map)
|
val vm = GameMapVM(map)
|
||||||
setInScope(vm, scope)
|
setInScope(vm, scope)
|
||||||
textProperty().bindBidirectional(map.nameProperty)
|
projectContext.project?.maps?.get(map.uid)?.let { textProperty().bindBidirectional(it.nameProperty) }
|
||||||
content = find<MapFragment>(scope).root
|
content = find<MapFragment>(scope).root
|
||||||
setOnClosed { mainController.openMaps.remove(scope) }
|
setOnClosed { mainController.openMaps.remove(scope) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package com.bartlomiejpluta.base.editor.map.asset
|
package com.bartlomiejpluta.base.editor.map.asset
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
// TODO(Add tileSetUID field)
|
// TODO(Add tileSetUID field)
|
||||||
data class GameMapAsset(
|
class GameMapAsset(
|
||||||
override val uid: String,
|
override val uid: String,
|
||||||
val name: String,
|
name: String,
|
||||||
val rows: Int,
|
val rows: Int,
|
||||||
val columns: Int,
|
val columns: Int,
|
||||||
) : Asset {
|
) : Asset {
|
||||||
override val source = "$uid.dat"
|
override val source = "$uid.dat"
|
||||||
|
|
||||||
|
val nameProperty = SimpleStringProperty(name)
|
||||||
|
override var name by nameProperty
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,6 @@ class GameMap(val tileSet: TileSet) {
|
|||||||
|
|
||||||
val layers = observableListOf<Layer>()
|
val layers = observableListOf<Layer>()
|
||||||
|
|
||||||
val nameProperty = SimpleStringProperty()
|
|
||||||
var name by nameProperty
|
|
||||||
|
|
||||||
val tileWidth = tileSet.tileWidth.toDouble()
|
val tileWidth = tileSet.tileWidth.toDouble()
|
||||||
val tileHeight = tileSet.tileHeight.toDouble()
|
val tileHeight = tileSet.tileHeight.toDouble()
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ class GameMapBuilder {
|
|||||||
var columns by columnsProperty
|
var columns by columnsProperty
|
||||||
|
|
||||||
fun build() = GameMap(tileSet).apply {
|
fun build() = GameMap(tileSet).apply {
|
||||||
name = this@GameMapBuilder.name
|
this.rows = this@GameMapBuilder.rows
|
||||||
rows = this@GameMapBuilder.rows
|
this.columns = this@GameMapBuilder.columns
|
||||||
columns = this@GameMapBuilder.columns
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,6 @@ class ProtobufMapDeserializer : MapDeserializer {
|
|||||||
val map = GameMap(tileset)
|
val map = GameMap(tileset)
|
||||||
val proto = GameMapProto.GameMap.parseFrom(input)
|
val proto = GameMapProto.GameMap.parseFrom(input)
|
||||||
map.uid = proto.uid
|
map.uid = proto.uid
|
||||||
map.name = proto.name
|
|
||||||
map.rows = proto.rows
|
map.rows = proto.rows
|
||||||
map.columns = proto.columns
|
map.columns = proto.columns
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class ProtobufMapSerializer : MapSerializer {
|
|||||||
override fun serialize(item: GameMap, output: OutputStream) {
|
override fun serialize(item: GameMap, output: OutputStream) {
|
||||||
val protoMap = GameMapProto.GameMap.newBuilder()
|
val protoMap = GameMapProto.GameMap.newBuilder()
|
||||||
protoMap.uid = item.uid
|
protoMap.uid = item.uid
|
||||||
protoMap.name = item.name
|
|
||||||
protoMap.rows = item.rows
|
protoMap.rows = item.rows
|
||||||
protoMap.columns = item.columns
|
protoMap.columns = item.columns
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
|||||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class MapBasicDataSettingsFragment : Fragment("Map Settings") {
|
class MapSettingsFragment : Fragment("Map Settings") {
|
||||||
override val scope = super.scope as UndoableScope
|
override val scope = super.scope as UndoableScope
|
||||||
private val undoRedoService: UndoRedoService by di()
|
private val undoRedoService: UndoRedoService by di()
|
||||||
|
|
||||||
@@ -16,13 +16,6 @@ class MapBasicDataSettingsFragment : Fragment("Map Settings") {
|
|||||||
|
|
||||||
override val root = form {
|
override val root = form {
|
||||||
fieldset("Map Settings") {
|
fieldset("Map Settings") {
|
||||||
field("Map name") {
|
|
||||||
textfield(mapVM.nameProperty) {
|
|
||||||
required()
|
|
||||||
whenDocked { requestFocus() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
field("Rows") {
|
field("Rows") {
|
||||||
|
|
||||||
textfield(mapVM.rowsProperty) {
|
textfield(mapVM.rowsProperty) {
|
||||||
@@ -98,7 +98,7 @@ class MapToolbarView : View() {
|
|||||||
|
|
||||||
button(graphic = FontIcon("fa-sliders")) {
|
button(graphic = FontIcon("fa-sliders")) {
|
||||||
action {
|
action {
|
||||||
find<MapBasicDataSettingsFragment>().openModal(block = true, resizable = false)
|
find<MapSettingsFragment>().openModal(block = true, resizable = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ import tornadofx.setValue
|
|||||||
class GameMapVM(map: GameMap) : ItemViewModel<GameMap>(map) {
|
class GameMapVM(map: GameMap) : ItemViewModel<GameMap>(map) {
|
||||||
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
val layers: SimpleListProperty<Layer> = bind(GameMap::layers)
|
||||||
|
|
||||||
val nameProperty = bind(GameMap::nameProperty)
|
|
||||||
var name by nameProperty
|
|
||||||
|
|
||||||
val tileSetProperty = bind(GameMap::tileSet)
|
val tileSetProperty = bind(GameMap::tileSet)
|
||||||
val tileSet by tileSetProperty
|
val tileSet by tileSetProperty
|
||||||
|
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
.let { project = it }
|
.let { project = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachMap(map: GameMap) {
|
override fun importMap(name: String, map: GameMap) {
|
||||||
project?.let {
|
project?.let {
|
||||||
UID.next(it.maps.map(Asset::uid)).let { uid ->
|
UID.next(it.maps.keys).let { uid ->
|
||||||
val asset = GameMapAsset(uid, map.name, map.rows, map.columns)
|
val asset = GameMapAsset(uid, name, map.rows, map.columns)
|
||||||
map.uid = uid
|
map.uid = uid
|
||||||
it.maps += asset
|
it.maps[uid] = asset
|
||||||
|
|
||||||
save()
|
save()
|
||||||
File(mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
|
File(mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ interface ProjectContext {
|
|||||||
fun save()
|
fun save()
|
||||||
fun open(file: File)
|
fun open(file: File)
|
||||||
|
|
||||||
fun attachMap(map: GameMap)
|
fun importMap(name: String, map: GameMap)
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import javafx.beans.property.SimpleObjectProperty
|
|||||||
import javafx.beans.property.SimpleStringProperty
|
import javafx.beans.property.SimpleStringProperty
|
||||||
import tornadofx.getValue
|
import tornadofx.getValue
|
||||||
import tornadofx.observableListOf
|
import tornadofx.observableListOf
|
||||||
|
import tornadofx.observableMapOf
|
||||||
import tornadofx.setValue
|
import tornadofx.setValue
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -15,5 +16,5 @@ class Project {
|
|||||||
val sourceDirectoryProperty = SimpleObjectProperty<File>()
|
val sourceDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
val sourceDirectory by sourceDirectoryProperty
|
val sourceDirectory by sourceDirectoryProperty
|
||||||
|
|
||||||
val maps = observableListOf<GameMapAsset>()
|
val maps = observableMapOf<String, GameMapAsset>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,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.maps.addAll(proto.mapsList.map(this::deserializeMap))
|
project.maps.putAll(proto.mapsList.map { it.uid to deserializeMap(it) })
|
||||||
|
|
||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,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.addAllMaps(item.maps.map(this::serializeMap))
|
proto.addAllMaps(item.maps.values.map(this::serializeMap))
|
||||||
proto.build().writeTo(output)
|
proto.build().writeTo(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package com.bartlomiejpluta.base.editor.util.uid
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object UID {
|
object UID {
|
||||||
fun next(sequence: List<String>): String {
|
fun next(sequence: Iterable<String>): String {
|
||||||
var uid: String
|
var uid: String
|
||||||
|
|
||||||
do {
|
do {
|
||||||
uid = UUID.randomUUID().toString()
|
uid = UUID.randomUUID().toString()
|
||||||
} while(uid in sequence)
|
} while (uid in sequence)
|
||||||
|
|
||||||
return uid
|
return uid
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ option java_outer_classname = "GameMapProto";
|
|||||||
|
|
||||||
message GameMap {
|
message GameMap {
|
||||||
required string uid = 1;
|
required string uid = 1;
|
||||||
required string name = 2;
|
required uint32 rows = 2;
|
||||||
required uint32 rows = 3;
|
required uint32 columns = 3;
|
||||||
required uint32 columns = 4;
|
repeated Layer layers = 4;
|
||||||
repeated Layer layers = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Layer {
|
message Layer {
|
||||||
|
|||||||
Reference in New Issue
Block a user