diff --git a/src/json-utils.js b/src/json-utils.js index 9c08f23ef..3d9819bd3 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -6,14 +6,12 @@ and returns a Javascript object */ function convertDOMElToObject (entity) { const data = []; - const environmentElement = document.querySelector('#environment'); - const sceneEntities = [entity, environmentElement]; - - for (const entry of sceneEntities) { - const entityData = getElementData(entry); - if (entityData) { - data.push(entityData); + if (entity.length) { + for (const entry of entity) { + data.push(getElementData(entry)); } + } else { + data.push(getElementData(entity)); } return { title: 'scene', @@ -23,9 +21,6 @@ function convertDOMElToObject (entity) { } function getElementData (entity) { - if (!entity.isEntity) { - return; - } const elementTree = getAttributes(entity); const children = entity.childNodes; if (children.length) { @@ -41,8 +36,7 @@ function getElementData (entity) { function getAttributes (entity) { const elemObj = {}; - - elemObj['element'] = entity.tagName.toLowerCase(); + elemObj['element'] = entity.tagName.toLowerCase(); if (entity.id) { elemObj['id'] = entity.id; @@ -118,8 +112,7 @@ const removeProps = { normalMap: {}, 'set-loader-from-hash': '*', 'create-from-json': '*', - street: { JSON: '*' }, - 'street-environment': '*' + street: { JSON: '*' } }; // a list of component_name:new_component_name pairs to rename in JSON string const renameProps = { @@ -129,6 +122,7 @@ const renameProps = { function filterJSONstreet (removeProps, renameProps, streetJSON) { function removeValueCheck (removeVal, value) { + // console.error(removeVal, value, AFRAME.utils.deepEqual(removeVal, value)) if (AFRAME.utils.deepEqual(removeVal, value) || removeVal === '*') { return true; } @@ -262,6 +256,7 @@ function getModifiedProperty (entity, componentName) { return data; } } + const diff = {}; for (const key in data) { const defaultValue = defaultData[key].default; @@ -275,11 +270,11 @@ function getModifiedProperty (entity, componentName) { diff[key] = data[key]; } } + return diff; } -function createEntities (entitiesData, parentEl) { - const sceneElement = document.querySelector('a-scene'); +function createEntities (entitiesData, parentEl) { for (const entityData of entitiesData) { if (entityData.id === 'street-container' && entityData.children && @@ -287,7 +282,7 @@ function createEntities (entitiesData, parentEl) { entityData.children[0].components.hasOwnProperty('set-loader-from-hash')) { delete entityData.children[0].components['set-loader-from-hash']; } - createEntityFromObj(entityData, sceneElement); + createEntityFromObj(entityData, parentEl); } } @@ -335,14 +330,12 @@ function createEntityFromObj (entityData, parentEl) { entity.setAttribute('mixin', entityData.mixin); } // Ensure the components are loaded before update the UI - entity.emit('entitycreated', {}, false); }); - if (entityData.children) { - for (const childEntityData of entityData.children) { - createEntityFromObj(childEntityData, entity); - } - } - }); + if (entityData.children) { + for (const childEntityData of entityData.children) { + createEntityFromObj(childEntityData, entity); + } + } }