From 2c4f5d2ba83296584ec0ad42503d804a8717bcdd Mon Sep 17 00:00:00 2001 From: Robert Long Date: Fri, 2 Oct 2020 12:29:06 -0700 Subject: [PATCH] Continue combining nodes in existing scenes --- src/editor/nodes/SceneNode.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/editor/nodes/SceneNode.js b/src/editor/nodes/SceneNode.js index 3c666e25..381af286 100644 --- a/src/editor/nodes/SceneNode.js +++ b/src/editor/nodes/SceneNode.js @@ -138,6 +138,33 @@ function migrateV3ToV4(json) { return json; } +const combineComponents = ["gltf-model", "kit-piece"]; + +function migrateV4ToV5(json) { + json.version = 5; + + for (const entityId in json.entities) { + if (!Object.prototype.hasOwnProperty.call(json.entities, entityId)) continue; + + const entity = json.entities[entityId]; + + if (!entity.components) { + continue; + } + + const hasCombineComponent = entity.components.find(c => combineComponents.indexOf(c.name) !== -1); + + if (hasCombineComponent) { + entity.components.push({ + name: "combine", + props: {} + }); + } + } + + return json; +} + export const FogType = { Disabled: "disabled", Linear: "linear", @@ -166,6 +193,10 @@ export default class SceneNode extends EditorNodeMixin(Scene) { json = migrateV3ToV4(json); } + if (json.version === 4) { + json = migrateV4ToV5(json); + } + const { root, metadata, entities } = json; let scene = null; @@ -403,7 +434,7 @@ export default class SceneNode extends EditorNodeMixin(Scene) { serialize() { const sceneJson = { - version: 4, + version: 5, root: this.uuid, metadata: JSON.parse(JSON.stringify(this.metadata)), entities: {