From 8159e18bcbd6f0c748aeefd6f2c6357aa82c8782 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Fri, 12 Oct 2018 01:43:06 -0700 Subject: [PATCH] reset beatsTime on restart --- src/components/beat-loader.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index 3ff0a1d..270a648 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -21,8 +21,10 @@ AFRAME.registerComponent('beat-loader', { this.beams = document.getElementById('beams').components.beams; this.beatData = null; this.beatContainer = document.getElementById('beatContainer'); - this.bpm = undefined; this.beatsTime = undefined; + this.beatsTimeOffset = undefined; + this.bpm = undefined; + this.songCurrentTime = undefined; this.onKeyDown = this.onKeyDown.bind(this); this.el.addEventListener('cleargame', this.clearBeats.bind(this)); @@ -30,7 +32,9 @@ AFRAME.registerComponent('beat-loader', { update: function (oldData) { const data = this.data; + if (!data.challengeId || !data.difficulty) { return; } + if (data.challengeId !== oldData.challengeId || data.difficulty !== oldData.difficulty) { this.loadBeats(); @@ -85,9 +89,6 @@ AFRAME.registerComponent('beat-loader', { */ handleBeats: function (beatData) { this.el.sceneEl.emit('beatloaderfinish', beatData, false); - var lessThan = function (a, b) { - return a._time - b._time; - }; // Reset variables used during playback. // Beats spawn ahead of the song and get to the user in sync with the music. this.beatsTimeOffset = this.data.beatAnticipationTime * 1000; @@ -221,8 +222,14 @@ AFRAME.registerComponent('beat-loader', { * Restart by returning all beats to pool. */ clearBeats: function () { + this.beatsTime = 0; + this.beatsTimeOffset = undefined; for (let i = 0; i < this.beatContainer.children.length; i++) { this.beatContainer.children[i].components.beat.returnToPool(true); } } }); + +function lessThan (a, b) { + return a._time - b._time; +};