[Editor] Make the project back stores maps as lists
This commit is contained in:
@@ -30,7 +30,7 @@ class MainView : View("BASE Game Editor") {
|
||||
Tab().apply {
|
||||
val vm = GameMapVM(map)
|
||||
setInScope(vm, scope)
|
||||
projectContext.project?.maps?.get(map.uid)?.let { textProperty().bindBidirectional(it.nameProperty) }
|
||||
projectContext.project?.maps?.first { it.uid == map.uid }?.let { textProperty().bindBidirectional(it.nameProperty) }
|
||||
content = find<MapFragment>(scope).root
|
||||
setOnClosed { mainController.openMaps.remove(scope) }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.main.view
|
||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.project.context.ProjectContext
|
||||
import com.bartlomiejpluta.base.editor.util.fx.BindingUtil
|
||||
import javafx.beans.binding.Bindings
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.scene.control.TreeItem
|
||||
@@ -21,7 +22,7 @@ class ProjectStructureView : View() {
|
||||
projectContext.projectProperty.addListener { _, _, project ->
|
||||
project?.let {
|
||||
structureRoot.nameProperty.bind(it.nameProperty)
|
||||
BindingUtil.bindMapValues(structureMaps.items, project.maps)
|
||||
Bindings.bindContent(structureMaps.items, project.maps)
|
||||
root.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ class DefaultProjectContext : ProjectContext {
|
||||
|
||||
override fun importMap(name: String, map: GameMap) {
|
||||
project?.let {
|
||||
UID.next(it.maps.keys).let { uid ->
|
||||
UID.next(it.maps.map(Asset::uid)).let { uid ->
|
||||
val asset = GameMapAsset(uid, name, map.rows, map.columns)
|
||||
map.uid = uid
|
||||
it.maps[uid] = asset
|
||||
it.maps += asset
|
||||
|
||||
save()
|
||||
File(mapsDirectory, asset.source).outputStream().use { fos -> mapSerializer.serialize(map, fos) }
|
||||
|
||||
@@ -5,7 +5,6 @@ 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
|
||||
|
||||
@@ -16,5 +15,5 @@ class Project {
|
||||
val sourceDirectoryProperty = SimpleObjectProperty<File>()
|
||||
val sourceDirectory by sourceDirectoryProperty
|
||||
|
||||
val maps = observableMapOf<String, GameMapAsset>()
|
||||
val maps = observableListOf<GameMapAsset>()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||
import com.bartlomiejpluta.base.proto.ProjectProto
|
||||
import org.springframework.stereotype.Component
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
@Component
|
||||
@@ -14,7 +13,7 @@ class ProtobufProjectDeserializer : ProjectDeserializer {
|
||||
val proto = ProjectProto.Project.parseFrom(input)
|
||||
val project = Project()
|
||||
project.name = proto.name
|
||||
project.maps.putAll(proto.mapsList.map { it.uid to deserializeMap(it) })
|
||||
project.maps.addAll(proto.mapsList.map(this::deserializeMap))
|
||||
|
||||
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.values.map(this::serializeMap))
|
||||
proto.addAllMaps(item.maps.map(this::serializeMap))
|
||||
proto.build().writeTo(output)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user