Skip to content

Commit b4d5ca5

Browse files
committed
deprecated ModelComponentData
1 parent 86ef29b commit b4d5ca5

7 files changed

Lines changed: 24 additions & 11 deletions

File tree

kool-editor-model/src/commonMain/kotlin/de/fabmax/kool/editor/api/EditorProject.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fun ProjectData.allEntities(): List<GameEntityData> {
190190

191191
fun ProjectData.checkConsistency() {
192192
if (meta.modelVersion != ProjectData.MODEL_VERSION) {
193-
logW { "Project data model version mismatch: ${meta.modelVersion} (supported version is ${ProjectData.MODEL_VERSION})" }
193+
logW { "Project data model version mismatch: ${meta.modelVersion} (current version is ${ProjectData.MODEL_VERSION})" }
194194
}
195195

196196
scenes.forEach { scene ->

kool-editor-model/src/commonMain/kotlin/de/fabmax/kool/editor/api/GameEntity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import de.fabmax.kool.modules.ui2.mutableStateListOf
66
import de.fabmax.kool.modules.ui2.mutableStateOf
77
import de.fabmax.kool.pipeline.RenderPass
88
import de.fabmax.kool.scene.Node
9-
import de.fabmax.kool.util.logW
9+
import de.fabmax.kool.util.logE
1010
import kotlin.math.max
1111

1212
val GameEntity.project: EditorProject get() = scene.project
@@ -208,7 +208,7 @@ class GameEntity(val entityData: GameEntityData, val scene: EditorScene) {
208208
}
209209

210210
fun createDataComponent(info: ComponentInfo<*>): GameEntityDataComponent<*> {
211-
@Suppress("UNCHECKED_CAST")
211+
@Suppress("UNCHECKED_CAST", "DEPRECATION")
212212
return when (info.data) {
213213
is BehaviorComponentData -> BehaviorComponent(this, info as ComponentInfo<BehaviorComponentData>)
214214
is TransformComponentData -> TransformComponent(this, info as ComponentInfo<TransformComponentData>)
@@ -228,7 +228,7 @@ class GameEntity(val entityData: GameEntityData, val scene: EditorScene) {
228228
is SsaoComponentData -> SsaoComponent(requireScene, info as ComponentInfo<SsaoComponentData>)
229229

230230
is ModelComponentData -> {
231-
logW { "converting ModelComponentData to MeshComponentData" }
231+
logE { "ModelComponentData is deprecated" }
232232
val modelData = info.data as ModelComponentData
233233
val meshData = MeshComponentData(ShapeData.Model(modelData.modelPath, modelData.sceneIndex, modelData.animationIndex))
234234
MeshComponent(requireSceneChild, ComponentInfo(meshData))

kool-editor-model/src/commonMain/kotlin/de/fabmax/kool/editor/api/ProjectDataIo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ProjectWriter private constructor(
7979
private val projFiles = mutableSetOf<WritableFileSystemItem>()
8080

8181
private suspend fun saveTree() {
82-
targetDir.createProjFile("project.json", codec.encodeToString(projData.meta.copy(modelVersion = ProjectData.MODEL_VERSION)))
82+
targetDir.createProjFile("project.json", codec.encodeToString(projData.meta))
8383

8484
val materialDir = targetDir.createProjDir("materials")
8585
projData.materials.toHierarchy().forEach { it.saveEntities(materialDir) }

kool-editor-model/src/commonMain/kotlin/de/fabmax/kool/editor/data/ComponentData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
55
@Serializable
66
sealed interface ComponentData
77

8+
@Deprecated("Replaced by MeshComponentData with ShapeData.Model")
89
@Serializable
910
data class ModelComponentData(
1011
val modelPath: String,

kool-editor-model/src/commonMain/kotlin/de/fabmax/kool/editor/data/ProjectData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ProjectData(
99
val materials: MutableList<GameEntityData> = mutableListOf()
1010
) {
1111
companion object {
12-
const val MODEL_VERSION = "1.0.0"
12+
const val MODEL_VERSION = "1.1.0"
1313
}
1414
}
1515

kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/KoolEditor.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import de.fabmax.kool.editor.actions.EditorActions
66
import de.fabmax.kool.editor.actions.SetVisibilityAction
77
import de.fabmax.kool.editor.api.*
88
import de.fabmax.kool.editor.components.CameraAwareComponent
9+
import de.fabmax.kool.editor.data.ProjectData
910
import de.fabmax.kool.editor.overlays.GridOverlay
1011
import de.fabmax.kool.editor.overlays.SceneObjectsOverlay
1112
import de.fabmax.kool.editor.overlays.SelectionOverlay
@@ -35,21 +36,29 @@ suspend fun KoolEditor(projectFiles: ProjectFiles, ctx: KoolContext): KoolEditor
3536
val projDataDir = projectFiles.projectModelDir
3637
val reader = ProjectReader(projDataDir)
3738
val data = reader.loadTree() ?: EditorProject.emptyProjectData()
38-
if (reader.parserErrors > 0) {
39+
if (reader.parserErrors > 0 || data.meta.modelVersion != ProjectData.MODEL_VERSION) {
3940
fun Int.toString(len: Int): String {
4041
var str = "$this"
4142
while (str.length < len) str = "0$str"
4243
return str
4344
}
4445
val dateTime = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
45-
val backupName = "project_backup_" +
46+
val backupPath = "kool_project_backup_" +
4647
"${dateTime.year}${dateTime.monthNumber.toString(2)}${dateTime.dayOfMonth.toString(2)}_" +
4748
"${dateTime.hour.toString(2)}${dateTime.minute.toString(2)}${dateTime.second.toString(2)}"
48-
logE("KoolEditor") { "ProjectReader reported errors, backing up original project data as $backupName" }
49-
val backupDir = projectFiles.fileSystem.createDirectory("src/commonMain/resources/$backupName")
49+
50+
if (reader.parserErrors > 0) {
51+
logE("KoolEditor") { "ProjectReader reported errors, backing up original project data as $backupPath" }
52+
} else {
53+
logW("KoolEditor") { "Project model version mismatch, backing up original project data as $backupPath" }
54+
}
55+
val backupDir = projectFiles.fileSystem.createDirectory(backupPath)
5056
projDataDir.copyRecursively(backupDir)
5157
}
52-
data.updateData()
58+
if (data.meta.modelVersion != ProjectData.MODEL_VERSION) {
59+
logW("KoolEditor") { "Updating project data: ${data.meta.modelVersion} -> ${ProjectData.MODEL_VERSION}" }
60+
data.updateData()
61+
}
5362
return KoolEditor(projectFiles, EditorProject(data), ctx)
5463
}
5564

kool-editor/src/commonMain/kotlin/de/fabmax/kool/editor/UpdateProjectData.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
@file:Suppress("DEPRECATION")
2+
13
package de.fabmax.kool.editor
24

35
import de.fabmax.kool.editor.data.*
46
import de.fabmax.kool.util.logW
57

68
fun ProjectData.updateData() {
79
replaceModelComponentsByMeshComponents()
10+
meta = meta.copy(modelVersion = ProjectData.MODEL_VERSION)
811
}
912

1013
private fun ProjectData.replaceModelComponentsByMeshComponents() {

0 commit comments

Comments
 (0)