diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index c619bce..a4bfb18 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -8,7 +8,8 @@ AFRAME.registerComponent('beat-loader', { beatAnticipationTime: {default: 2.0}, beatSpeed: {default: 4.0}, challengeId: {type: 'string'}, - difficulty: {type: 'string'} + difficulty: {type: 'string'}, + isPaused: {default: false} }, orientations: [180, 0, 270, 90, 225, 135, 315, 45, 0], @@ -53,6 +54,9 @@ AFRAME.registerComponent('beat-loader', { console.log('Finished loading challenge data.'); }, + /** + * Generate beats and stuff according to timestamp. + */ tick: function (time, delta) { var audioEl = this.el.components.song.audio; var i; @@ -62,7 +66,7 @@ AFRAME.registerComponent('beat-loader', { var msPerBeat; var noteTime; - if (!this.data.challengeId || !this.beatData || !audioEl) { return; } + if (this.data.isPaused || !this.data.challengeId || !this.beatData || !audioEl) { return; } notes = this.beatData._notes; obstacles = this.beatData._obstacles; diff --git a/src/components/beat-pauser.js b/src/components/beat-pauser.js new file mode 100644 index 0000000..8bbd47e --- /dev/null +++ b/src/components/beat-pauser.js @@ -0,0 +1,16 @@ +/** + * Pause all beats. + */ +AFRAME.registerComponent('beat-pauser', { + pause: function () { + for (let i = 0; i < this.el.children.length; i++) { + this.el.children[i].pause(); + } + }, + + play: function () { + for (let i = 0; i < this.el.children.length; i++) { + this.el.children[i].play(); + } + } +}); diff --git a/src/components/pause.js b/src/components/pause.js new file mode 100644 index 0000000..175d095 --- /dev/null +++ b/src/components/pause.js @@ -0,0 +1,13 @@ +AFRAME.registerComponent('pause', { + schema: { + isPaused: {default: false} + }, + + update: function () { + if (this.data.isPaused && this.el.isPlaying) { + this.el.pause(); + } else if (!this.data.isPaused && !this.el.isPlaying && this.el.sceneEl.isPlaying) { + this.el.play(); + } + } +}); diff --git a/src/components/song.js b/src/components/song.js index d63a863..e2cfd55 100644 --- a/src/components/song.js +++ b/src/components/song.js @@ -30,7 +30,7 @@ AFRAME.registerComponent('song', { } // Keep playback state up to date. - if ((data.isPlaying && data.challengeId) && this.audio.paused) { + if (data.isPlaying && data.challengeId && this.audio.paused) { console.log(`Playing ${this.audio.src}...`); this.data.analyserEl.setAttribute('audioanalyser', 'src', audio); audio.play(); diff --git a/src/index.html b/src/index.html index 5bb7b38..a26cbe8 100644 --- a/src/index.html +++ b/src/index.html @@ -9,15 +9,15 @@ - + @@ -114,10 +114,10 @@ mixin="raycaster" bind__hand-swapper="enabled: {{ otherHand }}RaycasterActive" bind__menu-controls="page: search.page; selectedChallengeId: menuSelectedChallenge.id" - bind__pauser="enabled: !menu.active" + bind__pauser="enabled: isPlaying" bind__raycaster="enabled: {{ hand }}RaycasterActive" - bind__saber-controls="bladeEnabled: !menu.active" - bind__trail="enabled: !menu.active" + bind__saber-controls="bladeEnabled: isPlaying" + bind__trail="enabled: isPlaying" haptics="events: mouseenter; dur: 35; force: 0.075" saber-controls="hand: {{ hand }}" thumb-controls @@ -133,7 +133,7 @@ - + diff --git a/src/state/index.js b/src/state/index.js index a5fdb86..1a468ec 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -27,8 +27,8 @@ AFRAME.registerState({ songSubName: '' }, inVR: false, - isPaused: false, - showKeyboard: false, + isPaused: false, // Playing, but paused. Not active during menu. + isPlaying: false, // Not in the menu AND not paused. menu: { active: true, playButtonText: 'Play' @@ -56,7 +56,8 @@ AFRAME.registerState({ hasPrev: false, results: [], }, - searchResultsPage: [] + searchResultsPage: [], + showKeyboard: false }, handlers: { @@ -184,6 +185,7 @@ AFRAME.registerState({ * Post-process the state after each action. */ computeState: (state) => { + state.isPlaying = !state.menu.active && !state.isPaused; state.leftRaycasterActive = state.menu.active && state.activeHand === 'left' && state.inVR; state.rightRaycasterActive = state.menu.active && state.activeHand === 'right' && diff --git a/src/templates/gameUi.html b/src/templates/gameUi.html index f2b47b3..ae425da 100644 --- a/src/templates/gameUi.html +++ b/src/templates/gameUi.html @@ -1,29 +1,29 @@ - - + rotation="-90 0 0"> - + scale="5 5 5"> - + scale="5 5 5">