Skip to content

Commit

Permalink
Merge branch 'save-load-fixing' into update-environment-options
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr authored Jul 6, 2023
2 parents dc42c62 + 58f110e commit 1f20a49
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/json-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ and returns a Javascript object
*/
function convertDOMElToObject (entity) {
const data = [];
if (entity.length) {
for (const entry of entity) {
data.push(getElementData(entry));
const environmentElement = document.querySelector('#environment');
const sceneEntities = [entity, environmentElement];

for (const entry of sceneEntities) {
const entityData = getElementData(entry);
if (entityData) {
data.push(entityData);
}
} else {
data.push(getElementData(entity));
}
return {
title: 'scene',
Expand All @@ -21,6 +23,9 @@ function convertDOMElToObject (entity) {
}

function getElementData (entity) {
if (!entity.isEntity) {
return;
}
const elementTree = getAttributes(entity);
const children = entity.childNodes;
if (children.length) {
Expand All @@ -36,7 +41,8 @@ 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;
Expand Down Expand Up @@ -112,7 +118,8 @@ const removeProps = {
normalMap: {},
'set-loader-from-hash': '*',
'create-from-json': '*',
street: { JSON: '*' }
street: { JSON: '*' },
'street-environment': '*'
};
// a list of component_name:new_component_name pairs to rename in JSON string
const renameProps = {
Expand All @@ -122,7 +129,6 @@ 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;
}
Expand Down Expand Up @@ -256,7 +262,6 @@ function getModifiedProperty (entity, componentName) {
return data;
}
}

const diff = {};
for (const key in data) {
const defaultValue = defaultData[key].default;
Expand All @@ -270,19 +275,19 @@ function getModifiedProperty (entity, componentName) {
diff[key] = data[key];
}
}

return diff;
}

function createEntities (entitiesData, parentEl) {
function createEntities (entitiesData, parentEl) {
const sceneElement = document.querySelector('a-scene');
for (const entityData of entitiesData) {
if (entityData.id === 'street-container' &&
entityData.children &&
entityData.children[0].id === 'default-street' &&
entityData.children[0].components.hasOwnProperty('set-loader-from-hash')) {
delete entityData.children[0].components['set-loader-from-hash'];
}
createEntityFromObj(entityData, parentEl);
createEntityFromObj(entityData, sceneElement);
}
}

Expand Down Expand Up @@ -330,12 +335,14 @@ 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);
}
}
});
}

0 comments on commit 1f20a49

Please sign in to comment.