From 6e8f820859f91d0fce48b4dadba043a11eba7541 Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Thu, 12 Dec 2024 10:49:51 +0100 Subject: [PATCH] use const/let instead of var in new code --- src/components/managed-street.js | 33 +++++++++++---------- src/components/street-generated-clones.js | 2 +- src/components/street-generated-stencil.js | 2 +- src/components/street-generated-striping.js | 8 ++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/components/managed-street.js b/src/components/managed-street.js index 852dc357..7580cbaa 100644 --- a/src/components/managed-street.js +++ b/src/components/managed-street.js @@ -1,9 +1,9 @@ /* global AFRAME */ // Orientation - default model orientation is "outbound" (away from camera) -var { segmentVariants } = require('../segments-variants.js'); -var streetmixUtils = require('../tested/streetmix-utils'); -var streetmixParsersTested = require('../tested/aframe-streetmix-parsers-tested'); +const { segmentVariants } = require('../segments-variants.js'); +const streetmixUtils = require('../tested/streetmix-utils'); +const streetmixParsersTested = require('../tested/aframe-streetmix-parsers-tested'); // invoking from js console /* @@ -438,22 +438,23 @@ function supportCheck(segmentType, segmentVariantString) { // NEW: takes a `segments` (array) from streetmix and return an element and its children which represent the 3D street scene function parseStreetmixSegments(segments, showStriping, length, showVehicles) { // create and center offset to center the street around global x position of 0 - var segmentEls = []; + const segmentEls = []; - var cumulativeWidthInMeters = 0; - for (var i = 0; i < segments.length; i++) { - var segmentColor = null; - var segmentParentEl = document.createElement('a-entity'); + let cumulativeWidthInMeters = 0; + for (let i = 0; i < segments.length; i++) { + let segmentColor = null; + const segmentParentEl = document.createElement('a-entity'); segmentParentEl.classList.add('segment-parent-' + i); - var segmentWidthInMeters = segments[i].width; + const segmentWidthInMeters = segments[i].width; // console.log('Type: ' + segments[i].type + '; Width: ' + segmentWidthInFeet + 'ft / ' + segmentWidthInMeters + 'm'); cumulativeWidthInMeters = cumulativeWidthInMeters + segmentWidthInMeters; - var segmentPositionX = cumulativeWidthInMeters - 0.5 * segmentWidthInMeters; + const segmentPositionX = + cumulativeWidthInMeters - 0.5 * segmentWidthInMeters; // get variantString - var variantList = segments[i].variantString + const variantList = segments[i].variantString ? segments[i].variantString.split('|') : ''; @@ -463,13 +464,13 @@ function parseStreetmixSegments(segments, showStriping, length, showVehicles) { // elevation property from streetmix segment const elevation = segments[i].elevation; - var direction = + const direction = variantList[0] === 'inbound' || variantList[1] === 'inbound' ? 'inbound' : 'outbound'; // the A-Frame mixin ID is often identical to the corresponding streetmix segment "type" by design, let's start with that - var segmentPreset = segments[i].type; + let segmentPreset = segments[i].type; // look at segment type and variant(s) to determine specific cases if (segments[i].type === 'drive-lane' && variantList[1] === 'sharrow') { @@ -530,7 +531,7 @@ function parseStreetmixSegments(segments, showStriping, length, showVehicles) { count: ${getRandomIntInclusive(2, 4)};` ); } - var markerMixinId = variantList[1]; // set the mixin of the road markings to match the current variant name + let markerMixinId = variantList[1]; // set the mixin of the road markings to match the current variant name // Fix streetmix inbound turn lane orientation (change left to right) per: https://github.com/streetmix/streetmix/issues/683 if (variantList[0] === 'inbound') { markerMixinId = markerMixinId.replace(/left|right/g, function (m) { @@ -788,7 +789,7 @@ function parseStreetmixSegments(segments, showStriping, length, showVehicles) { `model: lamp-modern-double; length: ${length}; cycleOffset: 0.4;` ); } else { - var rotationCloneY = variantList[0] === 'right' ? 0 : 180; + const rotationCloneY = variantList[0] === 'right' ? 0 : 180; segmentParentEl.setAttribute( 'street-generated-clones', `model: lamp-modern; length: ${length}; facing: ${rotationCloneY}; cycleOffset: 0.4;` @@ -822,7 +823,7 @@ function parseStreetmixSegments(segments, showStriping, length, showVehicles) { `model: lamp-traditional; length: ${length};` ); } else if (segments[i].type === 'transit-shelter') { - var rotationBusStopY = variantList[0] === 'left' ? 90 : 270; + const rotationBusStopY = variantList[0] === 'left' ? 90 : 270; segmentParentEl.setAttribute( 'street-generated-clones', `mode: single; model: bus-stop; length: ${length}; facing: ${rotationBusStopY};` diff --git a/src/components/street-generated-clones.js b/src/components/street-generated-clones.js index 2c714862..79d93e94 100644 --- a/src/components/street-generated-clones.js +++ b/src/components/street-generated-clones.js @@ -107,7 +107,7 @@ AFRAME.registerComponent('street-generated-clones', { z: positionZ }); - var rotationY = data.facing; + let rotationY = data.facing; if (data.direction === 'inbound') { rotationY = 0 + data.facing; } diff --git a/src/components/street-generated-stencil.js b/src/components/street-generated-stencil.js index 53945585..b78e3396 100644 --- a/src/components/street-generated-stencil.js +++ b/src/components/street-generated-stencil.js @@ -150,7 +150,7 @@ AFRAME.registerComponent('street-generated-stencil', { } // Set rotation - either random, specified facing, or inbound/outbound - var rotationY = data.facing; + let rotationY = data.facing; if (data.direction === 'inbound') { rotationY = 180 + data.facing; } diff --git a/src/components/street-generated-striping.js b/src/components/street-generated-striping.js index 395ca98c..8714eb72 100644 --- a/src/components/street-generated-striping.js +++ b/src/components/street-generated-striping.js @@ -80,10 +80,10 @@ AFRAME.registerComponent('street-generated-striping', { }, calculateStripingMaterial: function (stripingName, length) { // calculate the repeatCount for the material - var stripingTextureId = 'striping-solid-stripe'; // drive-lane, bus-lane, bike-lane - var repeatY = length / 6; - var color = '#ffffff'; - var stripingWidth = 0.2; + let stripingTextureId = 'striping-solid-stripe'; // drive-lane, bus-lane, bike-lane + let repeatY = length / 6; + let color = '#ffffff'; + let stripingWidth = 0.2; if (stripingName === 'solid-stripe') { stripingTextureId = 'striping-solid-stripe'; } else if (stripingName === 'dashed-stripe') {