From 348b008e62b5c8db69cea5522c4fc1321c238b10 Mon Sep 17 00:00:00 2001 From: Kieran Farr Date: Thu, 26 Oct 2023 16:17:24 -0700 Subject: [PATCH] add new STREET global using for 2 new functions that I pulled from 3dstreet editor --- src/json-utils.js | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/json-utils.js b/src/json-utils.js index a4160a9ea..1019312f6 100644 --- a/src/json-utils.js +++ b/src/json-utils.js @@ -1,5 +1,38 @@ /* global AFRAME, Node */ /* version: 1.0 */ + +var STREET = {}; +STREET.utils = {}; + +function getSceneUuidFromURLHash() { + const currentHash = window.location.hash; + const match = currentHash.match(/#\/scenes\/([a-zA-Z0-9-]+)\.json/); + return match && match[1] ? match[1] : null; +} + +function getCurrentSceneId() { + let currentSceneId = AFRAME.scenes[0].getAttribute('metadata').sceneId; + console.log('currentSceneId from scene metadata', currentSceneId); + const urlSceneId = getSceneUuidFromURLHash(); + console.log('urlSceneId', urlSceneId); + if (!currentSceneId) { + console.log('no currentSceneId from state'); + if (urlSceneId) { + currentSceneId = urlSceneId; + console.log('setting currentSceneId to urlSceneId'); + } + } + return currentSceneId; +} +STREET.utils.getCurrentSceneId = getCurrentSceneId; + +getCurrentSceneTitle = () => { + let currentSceneTitle = AFRAME.scenes[0].getAttribute('metadata').sceneTitle; + console.log('currentSceneTitle', currentSceneTitle); + return currentSceneTitle; +}; +STREET.utils.getCurrentSceneTitle = getCurrentSceneTitle; + /* Takes one or more elements (from a DOM queryselector call) and returns a Javascript object @@ -410,12 +443,12 @@ AFRAME.registerComponent('metadata', { sceneTitle: { default: '' }, sceneId: { default: '' } }, - init: function () { }, + init: function () {}, update: function (oldData) { const sceneTitle = this.data.sceneTitle; if (sceneTitle !== oldData.sceneTitle) { - this.el.emit('newTitle', {sceneTitle: sceneTitle}); - } + this.el.emit('newTitle', { sceneTitle: sceneTitle }); + } } }); @@ -430,7 +463,7 @@ AFRAME.registerComponent('scene-title', { }); }, createTitleElement: function (titleText) { - const titleDiv = this.titleElement = document.createElement('div'); + const titleDiv = (this.titleElement = document.createElement('div')); const newContent = document.createTextNode(titleText); titleDiv.setAttribute('id', 'sceneTitle'); titleDiv.appendChild(newContent); @@ -442,7 +475,9 @@ AFRAME.registerComponent('scene-title', { update: function (oldData) { // If `oldData` is empty, then this means we're in the initialization process. // No need to update. - if (Object.keys(oldData).length === 0) { return; } + if (Object.keys(oldData).length === 0) { + return; + } const titleText = this.data.titleText; const titleElement = this.titleElement; @@ -453,7 +488,7 @@ AFRAME.registerComponent('scene-title', { } else { this.updateTitleText(titleText); } - } + } } });