genre / num beats / song length / upvotes / downvotes from updated search index

This commit is contained in:
Kevin Ngo
2018-10-27 03:45:26 -07:00
parent 4e71423cd8
commit b7a5f47837
3 changed files with 12 additions and 31 deletions

View File

@@ -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'));

View File

@@ -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;
}
});

View File

@@ -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)}`;