[Editor] Add support for importing fonts
This commit is contained in:
@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.editor.asset.component
|
|||||||
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
import com.bartlomiejpluta.base.editor.asset.model.AssetCategory
|
import com.bartlomiejpluta.base.editor.asset.model.AssetCategory
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||||
@@ -70,6 +71,7 @@ class AssetTreeCell(renameAsset: (asset: Asset, name: String) -> Asset, deleteAs
|
|||||||
is TileSetAsset -> FontIcon("fa-th")
|
is TileSetAsset -> FontIcon("fa-th")
|
||||||
is ImageAsset -> FontIcon("fa-image")
|
is ImageAsset -> FontIcon("fa-image")
|
||||||
is EntitySet -> FontIcon("fa-male")
|
is EntitySet -> FontIcon("fa-male")
|
||||||
|
is FontAsset -> FontIcon("fa-font")
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,17 @@ class AssetsListView : View() {
|
|||||||
menuitem("Import Entity Set...") { mainController.importEntitySet() }
|
menuitem("Import Entity Set...") { mainController.importEntitySet() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val fonts = AssetCategory("Fonts").apply {
|
||||||
|
menuitem("Import Font...") { mainController.importFont() }
|
||||||
|
}
|
||||||
|
|
||||||
private val rootItem = AssetCategory(
|
private val rootItem = AssetCategory(
|
||||||
name = "Project", items = observableListOf(
|
name = "Project", items = observableListOf(
|
||||||
maps,
|
maps,
|
||||||
tileSets,
|
tileSets,
|
||||||
images,
|
images,
|
||||||
entitySet
|
entitySet,
|
||||||
|
fonts
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,6 +53,7 @@ class AssetsListView : View() {
|
|||||||
Bindings.bindContent(tileSets.items, it.tileSets)
|
Bindings.bindContent(tileSets.items, it.tileSets)
|
||||||
Bindings.bindContent(images.items, it.images)
|
Bindings.bindContent(images.items, it.images)
|
||||||
Bindings.bindContent(entitySet.items, it.entitySets)
|
Bindings.bindContent(entitySet.items, it.entitySets)
|
||||||
|
Bindings.bindContent(fonts.items, it.fonts)
|
||||||
root.root.expandAll()
|
root.root.expandAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class DefaultProjectAssembler : ProjectAssembler {
|
|||||||
packager.pack(project.tileSetsDirectory, targetJar, "BOOT-INF/classes/project/tilesets")
|
packager.pack(project.tileSetsDirectory, targetJar, "BOOT-INF/classes/project/tilesets")
|
||||||
packager.pack(project.imagesDirectory, targetJar, "BOOT-INF/classes/project/images")
|
packager.pack(project.imagesDirectory, targetJar, "BOOT-INF/classes/project/images")
|
||||||
packager.pack(project.entitySetsDirectory, targetJar, "BOOT-INF/classes/project/entsets")
|
packager.pack(project.entitySetsDirectory, targetJar, "BOOT-INF/classes/project/entsets")
|
||||||
|
packager.pack(project.fontsDirectory, targetJar, "BOOT-INF/classes/project/fonts")
|
||||||
packager.copy(project.projectFile, targetJar, "BOOT-INF/classes/project")
|
packager.copy(project.projectFile, targetJar, "BOOT-INF/classes/project")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.common.component
|
||||||
|
|
||||||
|
import javafx.beans.property.ObjectProperty
|
||||||
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import javafx.scene.layout.HBox
|
||||||
|
import tornadofx.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class SingleFileChooserField(
|
||||||
|
private val fileProperty: ObjectProperty<File> = SimpleObjectProperty(),
|
||||||
|
var type: Type = Type.FILE,
|
||||||
|
var validationContext: ValidationContext? = null,
|
||||||
|
op: SingleFileChooserField.() -> Unit = {}
|
||||||
|
) : HBox() {
|
||||||
|
private val filePath = SimpleStringProperty()
|
||||||
|
private var openDialog: (() -> List<File>) = { chooseFile("File Location", emptyArray()) }
|
||||||
|
|
||||||
|
fun dialogFormat(op: () -> List<File>) {
|
||||||
|
this.openDialog = op
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
textfield(filePath) {
|
||||||
|
trimWhitespace()
|
||||||
|
|
||||||
|
validationContext?.addValidator(this, filePath) {
|
||||||
|
if (it.isNullOrBlank()) {
|
||||||
|
error("Field is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
val file = File(it!!)
|
||||||
|
when {
|
||||||
|
!file.exists() -> error("Provide valid path to the ${type.name.toLowerCase()}")
|
||||||
|
type == Type.FILE && file.isDirectory -> error("Expected file, but directory is provided")
|
||||||
|
type == Type.DIRECTORY && file.isFile -> error("Expected directory, but file is provided")
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Choose") {
|
||||||
|
action {
|
||||||
|
filePath.value = openDialog().getOrNull(0)?.absolutePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath.addListener { _, _, value ->
|
||||||
|
value?.let {
|
||||||
|
fileProperty.value = File(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
op(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Type {
|
||||||
|
FILE,
|
||||||
|
DIRECTORY
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.gui.font.asset
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.asset.model.Asset
|
||||||
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
|
|
||||||
|
class FontAsset(project: Project, uid: String, source: String, name: String) :
|
||||||
|
Asset(project.fontsDirectoryProperty, uid, source, name)
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.gui.font.asset
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import tornadofx.getValue
|
||||||
|
import tornadofx.setValue
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class FontAssetData {
|
||||||
|
val nameProperty = SimpleStringProperty()
|
||||||
|
var name by nameProperty
|
||||||
|
|
||||||
|
val fileProperty = SimpleObjectProperty<File>()
|
||||||
|
var file by fileProperty
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.gui.font.view.importing
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.common.component.SingleFileChooserField
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAssetData
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.viewmodel.FontAssetDataVM
|
||||||
|
import javafx.stage.FileChooser
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class ImportFontFragment : Fragment("Import Font") {
|
||||||
|
private val dataVM = find<FontAssetDataVM>()
|
||||||
|
|
||||||
|
private var onCompleteConsumer: ((FontAssetData) -> Unit)? = null
|
||||||
|
|
||||||
|
fun onComplete(consumer: (FontAssetData) -> Unit) {
|
||||||
|
this.onCompleteConsumer = consumer
|
||||||
|
}
|
||||||
|
|
||||||
|
override val root = form {
|
||||||
|
fieldset("Import Font") {
|
||||||
|
field("Font Name") {
|
||||||
|
textfield(dataVM.nameProperty) {
|
||||||
|
requestFocus()
|
||||||
|
required()
|
||||||
|
trimWhitespace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field("Font File") {
|
||||||
|
this += SingleFileChooserField(dataVM.fileProperty) {
|
||||||
|
type = SingleFileChooserField.Type.FILE
|
||||||
|
validationContext = dataVM.validationContext
|
||||||
|
|
||||||
|
dialogFormat {
|
||||||
|
chooseFile("Font File Location", arrayOf(FileChooser.ExtensionFilter("TTF File", "*.ttf")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonbar {
|
||||||
|
button("Ok") {
|
||||||
|
action {
|
||||||
|
if (dataVM.commit()) {
|
||||||
|
onCompleteConsumer?.let { it(dataVM.item) }
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
button("Cancel") {
|
||||||
|
action { close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.bartlomiejpluta.base.editor.gui.font.viewmodel
|
||||||
|
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAssetData
|
||||||
|
import tornadofx.ItemViewModel
|
||||||
|
import tornadofx.getValue
|
||||||
|
import tornadofx.setValue
|
||||||
|
|
||||||
|
class FontAssetDataVM : ItemViewModel<FontAssetData>(FontAssetData()) {
|
||||||
|
val nameProperty = bind(FontAssetData::nameProperty)
|
||||||
|
var name by nameProperty
|
||||||
|
|
||||||
|
val fileProperty = bind(FontAssetData::fileProperty)
|
||||||
|
var file by fileProperty
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ import com.bartlomiejpluta.base.editor.entityset.view.importing.ImportEntitySetF
|
|||||||
import com.bartlomiejpluta.base.editor.entityset.viewmodel.EntitySetAssetDataVM
|
import com.bartlomiejpluta.base.editor.entityset.viewmodel.EntitySetAssetDataVM
|
||||||
import com.bartlomiejpluta.base.editor.event.SelectMainViewTabEvent
|
import com.bartlomiejpluta.base.editor.event.SelectMainViewTabEvent
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.view.importing.ImportFontFragment
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.viewmodel.FontAssetDataVM
|
||||||
import com.bartlomiejpluta.base.editor.image.view.importing.ImportImageFragment
|
import com.bartlomiejpluta.base.editor.image.view.importing.ImportImageFragment
|
||||||
import com.bartlomiejpluta.base.editor.image.viewmodel.ImageAssetDataVM
|
import com.bartlomiejpluta.base.editor.image.viewmodel.ImageAssetDataVM
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
@@ -167,6 +169,20 @@ class MainController : Controller() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun importFont() {
|
||||||
|
val vm = FontAssetDataVM()
|
||||||
|
val scope = Scope()
|
||||||
|
setInScope(vm, scope)
|
||||||
|
|
||||||
|
find<ImportFontFragment>(scope).apply {
|
||||||
|
onComplete {
|
||||||
|
projectContext.importFont(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
openModal(block = true, resizable = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun closeScript(fsNode: FileNode) {
|
fun closeScript(fsNode: FileNode) {
|
||||||
openItems.entries.firstOrNull { (_, item) -> item is Code && item.fileNode.absolutePath == fsNode.absolutePath }?.key?.let {
|
openItems.entries.firstOrNull { (_, item) -> item is Code && item.fileNode.absolutePath == fsNode.absolutePath }?.key?.let {
|
||||||
openItems.remove(it)
|
openItems.remove(it)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import com.bartlomiejpluta.base.editor.code.service.JavaClassService
|
|||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySetAssetData
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySetAssetData
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAsset
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAssetData
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAssetData
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAssetData
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
@@ -177,6 +179,19 @@ class DefaultProjectContext : ProjectContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun importFont(data: FontAssetData) {
|
||||||
|
project?.let {
|
||||||
|
UID.next(it.fonts.map(Asset::uid)).let { uid ->
|
||||||
|
val source = "$uid.${data.file.extension}"
|
||||||
|
val targetFile = File(it.fontsDirectory, source)
|
||||||
|
data.file.copyTo(targetFile)
|
||||||
|
it.fonts += FontAsset(it, uid, source, data.name)
|
||||||
|
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun deleteAsset(asset: Asset) {
|
override fun deleteAsset(asset: Asset) {
|
||||||
project?.let {
|
project?.let {
|
||||||
it.assetLists.firstOrNull { assets -> assets.remove(asset) }
|
it.assetLists.firstOrNull { assets -> assets.remove(asset) }
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.bartlomiejpluta.base.editor.asset.model.Asset
|
|||||||
import com.bartlomiejpluta.base.editor.code.model.Code
|
import com.bartlomiejpluta.base.editor.code.model.Code
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySetAssetData
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySetAssetData
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
import com.bartlomiejpluta.base.editor.file.model.FileNode
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAssetData
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAssetData
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAssetData
|
||||||
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
import com.bartlomiejpluta.base.editor.map.model.map.GameMap
|
||||||
@@ -35,6 +36,8 @@ interface ProjectContext {
|
|||||||
|
|
||||||
fun importEntitySet(data: EntitySetAssetData)
|
fun importEntitySet(data: EntitySetAssetData)
|
||||||
|
|
||||||
|
fun importFont(data: FontAssetData)
|
||||||
|
|
||||||
fun deleteAsset(asset: Asset)
|
fun deleteAsset(asset: Asset)
|
||||||
fun loadScript(fileNode: FileNode): Code
|
fun loadScript(fileNode: FileNode): Code
|
||||||
fun saveScript(code: Code)
|
fun saveScript(code: Code)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.editor.project.model
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
||||||
import com.bartlomiejpluta.base.editor.file.model.FileSystemNode
|
import com.bartlomiejpluta.base.editor.file.model.FileSystemNode
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
import com.bartlomiejpluta.base.editor.tileset.asset.TileSetAsset
|
||||||
@@ -30,8 +31,9 @@ class Project {
|
|||||||
val tileSets = observableListOf<TileSetAsset>()
|
val tileSets = observableListOf<TileSetAsset>()
|
||||||
val images = observableListOf<ImageAsset>()
|
val images = observableListOf<ImageAsset>()
|
||||||
val entitySets = observableListOf<EntitySet>()
|
val entitySets = observableListOf<EntitySet>()
|
||||||
|
val fonts = observableListOf<FontAsset>()
|
||||||
|
|
||||||
val assetLists = listOf(maps, tileSets, images, entitySets)
|
val assetLists = listOf(maps, tileSets, images, entitySets, fonts)
|
||||||
|
|
||||||
val mapsDirectoryProperty = SimpleObjectProperty<File>()
|
val mapsDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
var mapsDirectory by mapsDirectoryProperty
|
var mapsDirectory by mapsDirectoryProperty
|
||||||
@@ -49,6 +51,10 @@ class Project {
|
|||||||
var entitySetsDirectory by entitySetsDirectoryProperty
|
var entitySetsDirectory by entitySetsDirectoryProperty
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
val fontsDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
|
var fontsDirectory by fontsDirectoryProperty
|
||||||
|
private set
|
||||||
|
|
||||||
val codeDirectoryProperty = SimpleObjectProperty<File>()
|
val codeDirectoryProperty = SimpleObjectProperty<File>()
|
||||||
var codeDirectory by codeDirectoryProperty
|
var codeDirectory by codeDirectoryProperty
|
||||||
private set
|
private set
|
||||||
@@ -83,6 +89,7 @@ class Project {
|
|||||||
tileSetsDirectory = File(it, TILE_SETS_DIR)
|
tileSetsDirectory = File(it, TILE_SETS_DIR)
|
||||||
imagesDirectory = File(it, IMAGES_DIR)
|
imagesDirectory = File(it, IMAGES_DIR)
|
||||||
entitySetsDirectory = File(it, ENTITY_SETS_DIR)
|
entitySetsDirectory = File(it, ENTITY_SETS_DIR)
|
||||||
|
fontsDirectory = File(it, FONTS_DIR)
|
||||||
codeDirectory = File(it, CODE_DIR)
|
codeDirectory = File(it, CODE_DIR)
|
||||||
buildDirectory = File(it, BUILD_DIR)
|
buildDirectory = File(it, BUILD_DIR)
|
||||||
buildClassesDirectory = File(it, BUILD_CLASSES_DIR)
|
buildClassesDirectory = File(it, BUILD_CLASSES_DIR)
|
||||||
@@ -98,6 +105,7 @@ class Project {
|
|||||||
tileSetsDirectory?.mkdirs()
|
tileSetsDirectory?.mkdirs()
|
||||||
imagesDirectory?.mkdirs()
|
imagesDirectory?.mkdirs()
|
||||||
entitySetsDirectory?.mkdirs()
|
entitySetsDirectory?.mkdirs()
|
||||||
|
fontsDirectory?.mkdirs()
|
||||||
codeDirectory?.mkdirs()
|
codeDirectory?.mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +117,7 @@ class Project {
|
|||||||
const val TILE_SETS_DIR = "tilesets"
|
const val TILE_SETS_DIR = "tilesets"
|
||||||
const val IMAGES_DIR = "images"
|
const val IMAGES_DIR = "images"
|
||||||
const val ENTITY_SETS_DIR = "entsets"
|
const val ENTITY_SETS_DIR = "entsets"
|
||||||
|
const val FONTS_DIR = "fonts"
|
||||||
const val CODE_DIR = "code"
|
const val CODE_DIR = "code"
|
||||||
const val BUILD_DIR = "build"
|
const val BUILD_DIR = "build"
|
||||||
const val BUILD_CLASSES_DIR = "$BUILD_DIR/classes"
|
const val BUILD_CLASSES_DIR = "$BUILD_DIR/classes"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.project.serial
|
package com.bartlomiejpluta.base.editor.project.serial
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
@@ -21,6 +22,7 @@ class ProtobufProjectDeserializer : ProjectDeserializer {
|
|||||||
project.tileSets.addAll(proto.tileSetsList.map { deserializeTileSet(project, it) })
|
project.tileSets.addAll(proto.tileSetsList.map { deserializeTileSet(project, it) })
|
||||||
project.images.addAll(proto.imagesList.map { deserializeImage(project, it) })
|
project.images.addAll(proto.imagesList.map { deserializeImage(project, it) })
|
||||||
project.entitySets.addAll(proto.entitySetsList.map { deserializeEntitySet(project, it) })
|
project.entitySets.addAll(proto.entitySetsList.map { deserializeEntitySet(project, it) })
|
||||||
|
project.fonts.addAll(proto.fontsList.map { deserializeFont(project, it) })
|
||||||
|
|
||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
@@ -55,4 +57,11 @@ class ProtobufProjectDeserializer : ProjectDeserializer {
|
|||||||
rows = entitySetAsset.rows,
|
rows = entitySetAsset.rows,
|
||||||
columns = entitySetAsset.columns
|
columns = entitySetAsset.columns
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
private fun deserializeFont(project: Project, fontAsset: ProjectProto.FontAsset) = FontAsset(
|
||||||
|
project = project,
|
||||||
|
uid = fontAsset.uid,
|
||||||
|
source = fontAsset.source,
|
||||||
|
name = fontAsset.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.editor.project.serial
|
package com.bartlomiejpluta.base.editor.project.serial
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
import com.bartlomiejpluta.base.editor.entityset.asset.EntitySet
|
||||||
|
import com.bartlomiejpluta.base.editor.gui.font.asset.FontAsset
|
||||||
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
import com.bartlomiejpluta.base.editor.image.asset.ImageAsset
|
||||||
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
import com.bartlomiejpluta.base.editor.map.asset.GameMapAsset
|
||||||
import com.bartlomiejpluta.base.editor.project.model.Project
|
import com.bartlomiejpluta.base.editor.project.model.Project
|
||||||
@@ -20,6 +21,7 @@ class ProtobufProjectSerializer : ProjectSerializer {
|
|||||||
proto.addAllTileSets(item.tileSets.map(this::serializeTileSet))
|
proto.addAllTileSets(item.tileSets.map(this::serializeTileSet))
|
||||||
proto.addAllImages(item.images.map(this::serializeImage))
|
proto.addAllImages(item.images.map(this::serializeImage))
|
||||||
proto.addAllEntitySets(item.entitySets.map(this::serializeEntitySet))
|
proto.addAllEntitySets(item.entitySets.map(this::serializeEntitySet))
|
||||||
|
proto.addAllFonts(item.fonts.map(this::serializeFont))
|
||||||
proto.build().writeTo(output)
|
proto.build().writeTo(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,4 +52,10 @@ class ProtobufProjectSerializer : ProjectSerializer {
|
|||||||
.setRows(entitySet.rows)
|
.setRows(entitySet.rows)
|
||||||
.setColumns(entitySet.columns)
|
.setColumns(entitySet.columns)
|
||||||
.build()
|
.build()
|
||||||
}
|
|
||||||
|
private fun serializeFont(font: FontAsset) = ProjectProto.FontAsset.newBuilder()
|
||||||
|
.setUid(font.uid)
|
||||||
|
.setSource(font.source)
|
||||||
|
.setName(font.name)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ message Project {
|
|||||||
repeated TileSetAsset tileSets = 4;
|
repeated TileSetAsset tileSets = 4;
|
||||||
repeated ImageAsset images = 5;
|
repeated ImageAsset images = 5;
|
||||||
repeated EntitySetAsset entitySets = 6;
|
repeated EntitySetAsset entitySets = 6;
|
||||||
|
repeated FontAsset fonts = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GameMapAsset {
|
message GameMapAsset {
|
||||||
@@ -38,4 +39,10 @@ message EntitySetAsset {
|
|||||||
required string name = 3;
|
required string name = 3;
|
||||||
required uint32 rows = 4;
|
required uint32 rows = 4;
|
||||||
required uint32 columns = 5;
|
required uint32 columns = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FontAsset {
|
||||||
|
required string uid = 1;
|
||||||
|
required string source = 2;
|
||||||
|
required string name = 3;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user