From d5bb21253c3ff983dd2ca5e15137086855637004 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Thu, 25 Oct 2018 06:37:17 -0700 Subject: [PATCH] play song during victory --- src/components/song.js | 25 ++++++++++++++++++++++++- src/index.html | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/song.js b/src/components/song.js index 3172353..f1a0dd2 100644 --- a/src/components/song.js +++ b/src/components/song.js @@ -13,7 +13,8 @@ AFRAME.registerComponent('song', { challengeId: {default: ''}, isBeatsPreloaded: {default: false}, isGameOver: {default: false}, - isPlaying: {default: false} + isPlaying: {default: false}, + isVictory: {default: false} }, init: function () { @@ -30,6 +31,14 @@ AFRAME.registerComponent('song', { this.el.addEventListener('gamemenurestart', this.onRestart.bind(this)); this.el.addEventListener('wallhitstart', this.onWallHitStart.bind(this)); this.el.addEventListener('wallhitend', this.onWallHitEnd.bind(this)); + + if (process.env.NODE_ENV !== 'production') { + this.el.addEventListener('fakevictory', () => { + this.source.stop(); + this.source.disconnect(); + this.victory(); + }); + } }, update: function (oldData) { @@ -45,6 +54,20 @@ AFRAME.registerComponent('song', { this.audioAnalyser.gainNode.value = BASE_VOLUME; } + // On victory screen, play song in background. + if (!oldData.isVictory && data.isVictory) { + this.data.analyserEl.addEventListener('audioanalyserbuffersource', evt => { + this.audioAnalyser.resumeContext(); + const gain = this.audioAnalyser.gainNode.gain; + gain.cancelScheduledValues(0); + gain.setValueAtTime(0.05, 0); + this.source = evt.detail; + this.source.start(); + }, ONCE); + this.audioAnalyser.refreshSource(); + return; + } + // New challenge, play if we have loaded and were waiting for beats to preload. if (!oldData.isBeatsPreloaded && this.data.isBeatsPreloaded && this.source) { this.startAudio(); diff --git a/src/index.html b/src/index.html index e2a75b7..16f293b 100644 --- a/src/index.html +++ b/src/index.html @@ -20,7 +20,7 @@ bind__gameover="isGameOver: isGameOver" bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching" bind__overlay="enabled: !isPlaying" - bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver" + bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver; isVictory: isVictory" bind__song-preview-system="challengeId: challenge.id; isSearching: isSearching; isSongLoading: isSongLoading; selectedChallengeId: menuSelectedChallenge.id" animation__gameover="property: object3D.background; type: color; to: #750000; startEvents: gameover" animation__gameoverfog="property: components.fog.el.object3D.fog.color; type: color; to: #330000; startEvents: gameover; dur: 500; easing: easeInQuad"