diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index d1d77d6..cfef14e 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -17,6 +17,7 @@ AFRAME.registerComponent('beat-loader', { beatWarmupSpeed: {default: BEAT_WARMUP_SPEED}, challengeId: {type: 'string'}, // If clicked play. difficulty: {type: 'string'}, + difficultyFiles: {default: {}}, isPlaying: {default: false}, menuSelectedChallengeId: {type: 'string'} }, @@ -110,22 +111,13 @@ AFRAME.registerComponent('beat-loader', { fetchBeats: function () { var el = this.el; - if (this.xhr) { this.xhr.abort(); } - - // Load beats. - let url = utils.getS3FileUrl(this.data.menuSelectedChallengeId, - `${this.data.difficulty}.json`); - const xhr = this.xhr = new XMLHttpRequest(); - el.emit('beatloaderstart'); - console.log(`[beat-loader] Fetching ${url}...`); - xhr.open('GET', url); - xhr.addEventListener('load', () => { - this.beatData = JSON.parse(xhr.responseText); - this.beatDataProcessed = false; - this.xhr = null; - this.el.sceneEl.emit('beatloaderfinish', null, false); - }); - xhr.send(); + // Load beats + let beat = this.data.difficultyFiles[this.data.difficulty]; + el.emit('beatloaderstart') + this.beatData = beat; + this.beatDataProcessed = false; + console.log(this.beatData); + this.el.sceneEl.emit('beatloaderfinish', null, false); }, /** diff --git a/src/components/menu-selected-challenge-image.js b/src/components/menu-selected-challenge-image.js index 912e2ec..99ad675 100644 --- a/src/components/menu-selected-challenge-image.js +++ b/src/components/menu-selected-challenge-image.js @@ -8,8 +8,10 @@ AFRAME.registerComponent('menu-selected-challenge-image', { update: function () { const el = this.el; if (!this.data.selectedChallengeId) { return; } + console.log('menu-selected-challenge-image', this.data.selectedChallengeId) el.setAttribute( 'material', 'src', this.data.selectedChallengeId); + el.setAttribute('crossOrigin', 'anonymous'); } }); diff --git a/src/components/search.js b/src/components/search.js index 61952f7..0aba4d5 100644 --- a/src/components/search.js +++ b/src/components/search.js @@ -64,16 +64,28 @@ AFRAME.registerComponent('search', { const songBlob = await songFile.getData(new zip.BlobWriter()); const songUrl = URL.createObjectURL(songBlob); console.log(songUrl); - + const coverFile = _.find(files, {filename: infoJson._coverImageFilename}); + const coverBlob = await coverFile.getData(new zip.BlobWriter()); + const coverUrl = URL.createObjectURL(coverBlob); + const difficultyInfo = infoJson._difficultyBeatmapSets[0]._difficultyBeatmaps; + const difficultyFiles = {}; + difficultyInfo.forEach(async (d) => { + const file = _.find(files, {filename: d._beatmapFilename}); + const fileBlob = await file.getData(new zip.BlobWriter()); + const fileJson = JSON.parse(await fileBlob.text()); + fileJson._beatsPerMinute = infoJson._beatsPerMinute; + difficultyFiles[d._difficulty] = fileJson; + }); return { songName: result.metadata.songName, songSubName: result.metadata.songAuthorName, - imageUrl: result.versions[0].coverURL, + imageUrl: coverUrl, songUrl: songUrl, id: result.id, data: result, - difficulties: _.map(infoJson._difficultyBeatmapSets[0]._difficultyBeatmaps, '_difficulty'), + difficulties: _.map(difficultyInfo, '_difficulty'), numBeats: result.metadata.duration, + difficultyFiles: difficultyFiles, } })).then((tmpResults) => { this.eventDetail.results = tmpResults; diff --git a/src/components/song-preview.js b/src/components/song-preview.js index 27ca4bb..60985fd 100644 --- a/src/components/song-preview.js +++ b/src/components/song-preview.js @@ -184,7 +184,7 @@ AFRAME.registerComponent('song-preview-system', { // Prefetch buffer for playing. if (audioanalyser.xhr) { audioanalyser.xhr.abort(); } - audioanalyser.fetchAudioBuffer(data.songUrl); + audioanalyser.fetchAudioBuffer(this.data.songUrl); }, /** diff --git a/src/components/song.js b/src/components/song.js index a892896..4863173 100644 --- a/src/components/song.js +++ b/src/components/song.js @@ -31,7 +31,8 @@ AFRAME.registerComponent('song', { isBeatsPreloaded: {default: false}, isGameOver: {default: false}, isPlaying: {default: false}, - isVictory: {default: false} + isVictory: {default: false}, + songUrl: {type: 'string'} }, init: function () { @@ -126,7 +127,9 @@ AFRAME.registerComponent('song', { this.source = evt.detail; resolve(this.source); }, ONCE); - this.analyserSetter.src = utils.getS3FileUrl(data.challengeId, 'song.ogg'); + // this.analyserSetter.src = utils.getS3FileUrl(data.challengeId, 'song.ogg'); + this.analyserSetter.src = this.data.songUrl; + data.analyserEl.setAttribute('audioanalyser', this.analyserSetter); // Already loaded. diff --git a/src/index.html b/src/index.html index bbe8117..4c518cc 100644 --- a/src/index.html +++ b/src/index.html @@ -30,11 +30,11 @@