Skip to content

Commit

Permalink
add new STREET global
Browse files Browse the repository at this point in the history
using for 2 new functions that I pulled from 3dstreet editor
  • Loading branch information
kfarr committed Oct 26, 2023
1 parent b3731c0 commit 348b008
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/json-utils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 });
}
}
});

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -453,7 +488,7 @@ AFRAME.registerComponent('scene-title', {
} else {
this.updateTitleText(titleText);
}
}
}
}
});

Expand Down

0 comments on commit 348b008

Please sign in to comment.