From 89d80fbe6fa09acfd9e7e4ff9238b054ef9796e0 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 2 Aug 2023 18:52:41 -0400 Subject: [PATCH 1/2] fix saving issue - saving car position. Fix issue - prevent save/load streets twice --- src/aframe-streetmix-parsers.js | 11 +++++------ src/json-utils.js | 5 ++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/aframe-streetmix-parsers.js b/src/aframe-streetmix-parsers.js index 364fd32f0..269d754f6 100644 --- a/src/aframe-streetmix-parsers.js +++ b/src/aframe-streetmix-parsers.js @@ -413,14 +413,13 @@ function createDriveLaneElement (variantList, positionX, segmentWidthInMeters, s const params = carParams[carType]; const reusableObjectEl = document.createElement('a-entity'); - reusableObjectEl.object3D.position.setX(positionX); - if (positionZ) { - reusableObjectEl.object3D.position.setZ(positionZ); - } else { - randomPosition(reusableObjectEl, 'z', streetLength, params['length']); + + if (!positionZ) { + positionZ = randomPosition(reusableObjectEl, 'z', streetLength, params['length']); } + reusableObjectEl.setAttribute('position', `${positionX} 0 ${positionZ}`); reusableObjectEl.setAttribute('mixin', params['mixin']); - reusableObjectEl.object3D.rotation.set(0, THREE.MathUtils.degToRad(rotationY), 0); + reusableObjectEl.setAttribute('rotation', `0 ${rotationY} 0`); if (animated) { speed = 5; // meters per second diff --git a/src/json-utils.js b/src/json-utils.js index af45e94f4..c850112f5 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -169,8 +169,8 @@ function filterJSONstreet (removeProps, renameProps, streetJSON) { }); // rename components for (var renameKey in renameProps) { - const reKey = new RegExp(`"${renameKey}":`); - stringJSON = stringJSON.replace(reKey, `"${renameProps[renameKey]}":`); + const reKey = new RegExp(`"${renameKey}":`, 'g'); + stringJSON = stringJSON.replaceAll(reKey, `"${renameProps[renameKey]}":`); } return stringJSON; } @@ -250,7 +250,6 @@ function getModifiedProperty (entity, componentName) { // skip properties, if they exists in element's mixin return null; } - // If its single-property like position, rotation, etc if (isSingleProperty(defaultData)) { const defaultValue = defaultData.default; From 97ff91f25c599457787826df49f9e8382f03178a Mon Sep 17 00:00:00 2001 From: Kieran Farr Date: Thu, 3 Aug 2023 12:17:32 -0400 Subject: [PATCH 2/2] tiny lint fix --- src/aframe-streetmix-parsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aframe-streetmix-parsers.js b/src/aframe-streetmix-parsers.js index 269d754f6..d3dd28ba1 100644 --- a/src/aframe-streetmix-parsers.js +++ b/src/aframe-streetmix-parsers.js @@ -413,7 +413,7 @@ function createDriveLaneElement (variantList, positionX, segmentWidthInMeters, s const params = carParams[carType]; const reusableObjectEl = document.createElement('a-entity'); - + if (!positionZ) { positionZ = randomPosition(reusableObjectEl, 'z', streetLength, params['length']); }