From b7a5f47837e5a062e8b85ab006568f76be0ee9d9 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Sat, 27 Oct 2018 03:45:26 -0700 Subject: [PATCH] genre / num beats / song length / upvotes / downvotes from updated search index --- src/components/song-preview.js | 2 -- src/components/song-progress-ring.js | 4 ++- src/state/index.js | 37 +++++++--------------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/components/song-preview.js b/src/components/song-preview.js index d8f8f53..a7d45be 100644 --- a/src/components/song-preview.js +++ b/src/components/song-preview.js @@ -177,8 +177,6 @@ AFRAME.registerComponent('song-preview-system', { this.fadeIn(); this.updateAnalyser(); - this.el.sceneEl.emit('menuselectedchallengesonglength', this.audio.duration, false); - // Prefetch buffer for playing. if (audioanalyser.xhr) { audioanalyser.xhr.abort(); } audioanalyser.fetchAudioBuffer(utils.getS3FileUrl(challengeId, 'song.ogg')); diff --git a/src/components/song-progress-ring.js b/src/components/song-progress-ring.js index bb8c51c..d89ca60 100644 --- a/src/components/song-progress-ring.js +++ b/src/components/song-progress-ring.js @@ -31,7 +31,9 @@ AFRAME.registerComponent('song-progress-ring', { const source = this.el.sceneEl.components.song.source; if (!source) { return; } - const progress = this.context.currentTime / source.buffer.duration; + const progress = + this.el.sceneEl.components.song.getCurrentTime() / + source.buffer.duration; this.progress.value = progress; } }); diff --git a/src/state/index.js b/src/state/index.js index 2cf4ef3..268fd16 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -39,8 +39,8 @@ AFRAME.registerState({ image: '', isLoading: false, isBeatsPreloaded: false, // Whether we have passed the negative time. + songDuration: 0, songName: '', - songLength: 0, songSubName: '' }, damage: 0, @@ -59,10 +59,12 @@ AFRAME.registerState({ difficulty: '', downloads: '', downloadsText: '', + genre: '', id: '', index: -1, image: '', numBeats: undefined, + songDuration: 0, songInfoText: '', songLength: undefined, songName: '', @@ -135,8 +137,6 @@ AFRAME.registerState({ beatloaderfinish: (state, payload) => { state.challenge.isLoading = false; - state.menuSelectedChallenge.numBeats = payload.numBeats; - computeMenuSelectedChallengeInfoText(state); }, beatloaderpreloadfinish: (state) => { @@ -146,9 +146,6 @@ AFRAME.registerState({ beatloaderstart: (state) => { state.challenge.isBeatsPreloaded = false; state.challenge.isLoading = true; - state.menuSelectedChallenge.songInfoText = ''; - state.menuSelectedChallenge.numBeats = undefined; - state.menuSelectedChallenge.songLength = undefined; }, /** @@ -228,13 +225,13 @@ AFRAME.registerState({ */ menuchallengeselect: (state, id) => { // Copy from challenge store populated from search results. - let challengeData = challengeDataStore[id]; - Object.assign(state.menuSelectedChallenge, challengeData); + let challenge = challengeDataStore[id]; + Object.assign(state.menuSelectedChallenge, challenge); // Populate difficulty options. state.menuDifficulties.length = 0; - for (let i = 0; i < challengeData.difficulties.length; i++) { - state.menuDifficulties.unshift(challengeData.difficulties[i]); + for (let i = 0; i < challenge.difficulties.length; i++) { + state.menuDifficulties.unshift(challenge.difficulties[i]); } state.menuDifficulties.sort(difficultyComparator); @@ -242,9 +239,9 @@ AFRAME.registerState({ state.menuSelectedChallenge.difficulty = state.menuDifficulties[0]; state.menuSelectedChallenge.image = utils.getS3FileUrl(id, 'image.jpg'); - state.menuSelectedChallenge.downloadsText = `${challengeData.downloads} Plays`; - computeMenuSelectedChallengeIndex(state); + state.menuSelectedChallenge.songInfoText = `By ${challenge.author} / ${challenge.genre || 'Uncategorized'}\n${challenge.downloads} Downloads\nUpvotes: ${challenge.upvotes} / Downvotes: ${challenge.downvotes}\n${formatSongLength(challenge.songDuration)} / ${challenge.numBeats[state.menuSelectedChallenge.difficulty]} beats`; + computeMenuSelectedChallengeIndex(state); state.isSearching = false; }, @@ -256,11 +253,6 @@ AFRAME.registerState({ state.menuSelectedChallenge.difficulty = difficulty; }, - menuselectedchallengesonglength: (state, seconds) => { - state.menuSelectedChallenge.songLength = seconds; - computeMenuSelectedChallengeInfoText(state); - }, - minehit: state => { takeDamage(state); }, @@ -489,17 +481,6 @@ function computeMenuSelectedChallengeIndex (state) { } } -function computeMenuSelectedChallengeInfoText (state) { - const challenge = state.menuSelectedChallenge; - - const numBeats = challenge.numBeats; - const songLength = challenge.songLength; - if (!numBeats || !songLength) { return; } - - challenge.songInfoText = - `${challenge.author}\n${challenge.downloadsText}\n${formatSongLength(songLength)} / ${numBeats} beats`; -} - function formatSongLength (songLength) { songLength /= 60; const minutes = `${Math.floor(songLength)}`;