From 35ea0bf4824f1c3d3e2c61c6cfd05e3a1d28f207 Mon Sep 17 00:00:00 2001 From: Diego Marcos Date: Wed, 31 Oct 2018 18:07:21 -0700 Subject: [PATCH] Restoring some consts and events code removed by mistake --- src/components/beat-loader.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index 3bbb93a..69dd802 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -144,34 +144,34 @@ AFRAME.registerComponent('beat-loader', { * Generate beats and stuff according to timestamp. */ tick: function (time, delta) { - var bpm; var i; - var notes; - var obstacles; - var beatsTime = this.beatsTime; - var msPerBeat; var noteTime; if (!this.data.isPlaying || !this.data.challengeId || !this.beatData) { return; } // Re-sync song with beats playback. - if (this.beatsTimeOffset !== undefined && this.songCurrentTime !== this.el.components.song.context.currentTime) { - this.songCurrentTime = this.el.components.song.context.currentTime; - this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime + this.data.beatWarmupTime) * 1000; + const songComponent = this.el.components.song; + const currentTime = songComponent.getCurrentTime(); + + if (songComponent.songStartTime && this.beatsTimeOffset !== undefined && + this.songCurrentTime !== currentTime) { + this.songCurrentTime = currentTime; + this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000; } - notes = this.beatData._notes; - obstacles = this.beatData._obstacles; - bpm = this.beatData._beatsPerMinute; - msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute; + const beatsTime = this.beatsTime; + const bpm = this.beatData._beatsPerMinute; + const msPerBeat = 1000 * 60 / this.beatData._beatsPerMinute; + const notes = this.beatData._notes; for (i = 0; i < notes.length; ++i) { noteTime = notes[i]._time * msPerBeat; - if (noteTime > beatsTime && noteTime <= beatsTime + delta) { + if (noteTime > beatsTime && noteTime <= (beatsTime + delta)) { notes[i].time = noteTime; this.generateBeat(notes[i]); } } + const obstacles = this.beatData._obstacles; for (i=0; i < obstacles.length; ++i) { noteTime = obstacles[i]._time * msPerBeat; if (noteTime > beatsTime && noteTime <= beatsTime + delta) { @@ -179,6 +179,14 @@ AFRAME.registerComponent('beat-loader', { } } + const events = this.beatData._events; + for (i=0; i < events.length; ++i) { + noteTime = events[i]._time * msPerBeat; + if (noteTime > beatsTime && noteTime <= beatsTime + delta) { + this.generateEvent(events[i]); + } + } + if (this.beatsTimeOffset !== undefined) { if (this.beatsTimeOffset <= 0) { this.el.sceneEl.emit('beatloaderpreloadfinish', null, false);