songs are loading
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -30,11 +30,11 @@
|
||||
|
||||
<a-scene
|
||||
mixin="gameoverAnimation bgColorAnimation tunnelColorAnimation leftLaserColorAnimation rightLaserColorAnimation textGlowColorAnimation floorColorAnimation"
|
||||
bind__beat-loader="challengeId: challenge.id; difficulty: menuSelectedChallenge.difficulty; isPlaying: isPlaying; menuSelectedChallengeId: menuSelectedChallenge.id"
|
||||
bind__beat-loader="challengeId: challenge.id; difficulty: menuSelectedChallenge.difficulty; isPlaying: isPlaying; menuSelectedChallengeId: menuSelectedChallenge.id; difficultyFiles: menuSelectedChallenge.difficultyFiles"
|
||||
bind__gameover="isGameOver: isGameOver"
|
||||
bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching"
|
||||
bind__leaderboard="isVictory: isVictory; menuSelectedChallengeId: menuSelectedChallenge.id; challengeId: challenge.id"
|
||||
bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver; isVictory: isVictory"
|
||||
bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver; isVictory: isVictory; songUrl: menuSelectedChallenge.songUrl"
|
||||
bind__song-preview-system="challengeId: challenge.id; isSearching: isSearching; isSongLoading: isSongLoading; selectedChallengeId: menuSelectedChallenge.id; songUrl: menuSelectedChallenge.songUrl"
|
||||
animation__gameover="property: object3D.background; type: color; to: #750000; startEvents: gameover"
|
||||
console-shortcuts
|
||||
|
||||
Reference in New Issue
Block a user