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