From 4242dbec4d14708e238cb7faa5c594187a62425d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Fri, 29 Dec 2023 17:17:31 -0300 Subject: [PATCH 1/6] fix save/load mapbox scene - move environment and cameraRig to a-acene parent - fix saving mapbox component data --- mapbox.html | 107 ++++++++-------------------------------------- src/json-utils.js | 17 ++++++-- 2 files changed, 31 insertions(+), 93 deletions(-) diff --git a/mapbox.html b/mapbox.html index 194a9a2e0..ba1621781 100644 --- a/mapbox.html +++ b/mapbox.html @@ -98,17 +98,17 @@ streetmix-loader="streetmixStreetURL: https://streetmix.net/scott/31/south-van-ness-idea-short-term; showBuildings: false;" > - - - - - - - - + + + + + + + + - diff --git a/src/json-utils.js b/src/json-utils.js index 05d471845..d81083aa0 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -108,7 +108,7 @@ function getAttributes (entity) { if (isEmpty(modifiedProperty)) { elemObj['components'][componentName] = ''; } else { - elemObj['components'][componentName] = toPropString(modifiedProperty); + elemObj['components'][componentName] = toPropString(componentName, modifiedProperty); } } } @@ -116,7 +116,14 @@ function getAttributes (entity) { return elemObj; } -function toPropString (propData) { +// properties or attributes that should be stored as a string in saved JSON +const propsToString = ["mapbox"]; + +function toPropString (componentName, propData) { + if (propsToString.includes(componentName)) { + // return a string if key is an attribute or property listed in the propsToString array + return AFRAME.utils.styleParser.stringify(propData); + } if ( typeof propData === 'string' || typeof propData === 'number' || @@ -143,7 +150,7 @@ function toPropString (propData) { return `${key}: ${value}`; } } else { - return `${key}: ${toPropString(value)}`; + return `${key}: ${toPropString(key, value)}`; } }) .join('; '); @@ -184,6 +191,10 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } let stringJSON = JSON.stringify(streetJSON, function replacer (key, value) { + if (propsToString.includes(key)) { + // don't parse if key is an attribute or property listed in the propsToString array + return value; + } const compAttributes = AFRAME.utils.styleParser.parse(value); for (var removeKey in removeProps) { // check for removing components From 6473fd54247b32b57d99afb58c771481a232bf3d Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 19:22:46 -0300 Subject: [PATCH 2/6] save streetmix URLs as strings also add additional comment --- src/json-utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/json-utils.js b/src/json-utils.js index d81083aa0..5e0c42383 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -117,7 +117,8 @@ function getAttributes (entity) { } // properties or attributes that should be stored as a string in saved JSON -const propsToString = ["mapbox"]; +// to prevent parsing and splitting URL +const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; function toPropString (componentName, propData) { if (propsToString.includes(componentName)) { From 2eea31e48d6b716145a56c115e36819f61505674 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 19:23:56 -0300 Subject: [PATCH 3/6] remove unnecessary checkings --- src/json-utils.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index 5e0c42383..ce33a07a2 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -116,15 +116,7 @@ function getAttributes (entity) { return elemObj; } -// properties or attributes that should be stored as a string in saved JSON -// to prevent parsing and splitting URL -const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; - function toPropString (componentName, propData) { - if (propsToString.includes(componentName)) { - // return a string if key is an attribute or property listed in the propsToString array - return AFRAME.utils.styleParser.stringify(propData); - } if ( typeof propData === 'string' || typeof propData === 'number' || @@ -183,6 +175,10 @@ const renameProps = { intersection: 'not-intersection' }; +// properties or attributes that should be stored as a string in saved JSON +// to prevent parsing and splitting URL +const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; + function filterJSONstreet (removeProps, renameProps, streetJSON) { function removeValueCheck (removeVal, value) { if (AFRAME.utils.deepEqual(removeVal, value) || removeVal === '*') { From 881e6992d89bd5b33344d8a9b50cb64706d45de6 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Tue, 16 Jan 2024 20:23:50 -0300 Subject: [PATCH 4/6] fixed the filterJSON code --- src/json-utils.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index ce33a07a2..17024ce7f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -188,14 +188,11 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } let stringJSON = JSON.stringify(streetJSON, function replacer (key, value) { - if (propsToString.includes(key)) { - // don't parse if key is an attribute or property listed in the propsToString array - return value; - } - const compAttributes = AFRAME.utils.styleParser.parse(value); + let compAttributes; for (var removeKey in removeProps) { // check for removing components if (key === removeKey) { + compAttributes = AFRAME.utils.styleParser.parse(value); const removeVal = removeProps[removeKey]; // check for deleting component's attribute if (typeof removeVal === 'object' && !isEmpty(removeVal)) { @@ -218,7 +215,7 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } } - return compAttributes; + return compAttributes ?? value; }); // rename components for (var renameKey in renameProps) { From d4f5806f41048acbc6176c7747852dc84ae5c3fb Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 17 Jan 2024 19:07:11 -0300 Subject: [PATCH 5/6] remove unnecessary variables --- src/json-utils.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index 17024ce7f..abb274c1f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -108,7 +108,7 @@ function getAttributes (entity) { if (isEmpty(modifiedProperty)) { elemObj['components'][componentName] = ''; } else { - elemObj['components'][componentName] = toPropString(componentName, modifiedProperty); + elemObj['components'][componentName] = toPropString(modifiedProperty); } } } @@ -116,7 +116,7 @@ function getAttributes (entity) { return elemObj; } -function toPropString (componentName, propData) { +function toPropString (propData) { if ( typeof propData === 'string' || typeof propData === 'number' || @@ -143,7 +143,7 @@ function toPropString (componentName, propData) { return `${key}: ${value}`; } } else { - return `${key}: ${toPropString(key, value)}`; + return `${key}: ${toPropString(value)}`; } }) .join('; '); @@ -175,10 +175,6 @@ const renameProps = { intersection: 'not-intersection' }; -// properties or attributes that should be stored as a string in saved JSON -// to prevent parsing and splitting URL -const propsToString = ["mapbox", "streetmixStreetURL", "streetmixAPIURL"]; - function filterJSONstreet (removeProps, renameProps, streetJSON) { function removeValueCheck (removeVal, value) { if (AFRAME.utils.deepEqual(removeVal, value) || removeVal === '*') { From 0819b1568a8c34ce0e717ff9b40286537d673542 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 21 Feb 2024 14:02:01 -0300 Subject: [PATCH 6/6] change ?? operator by || --- src/json-utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json-utils.js b/src/json-utils.js index abb274c1f..546954b3f 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -211,7 +211,7 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { } } - return compAttributes ?? value; + return compAttributes || value; }); // rename components for (var renameKey in renameProps) {