songs are loading
This commit is contained in:
@@ -17,6 +17,7 @@ AFRAME.registerComponent('beat-loader', {
|
|||||||
beatWarmupSpeed: {default: BEAT_WARMUP_SPEED},
|
beatWarmupSpeed: {default: BEAT_WARMUP_SPEED},
|
||||||
challengeId: {type: 'string'}, // If clicked play.
|
challengeId: {type: 'string'}, // If clicked play.
|
||||||
difficulty: {type: 'string'},
|
difficulty: {type: 'string'},
|
||||||
|
difficultyFiles: {default: {}},
|
||||||
isPlaying: {default: false},
|
isPlaying: {default: false},
|
||||||
menuSelectedChallengeId: {type: 'string'}
|
menuSelectedChallengeId: {type: 'string'}
|
||||||
},
|
},
|
||||||
@@ -110,22 +111,13 @@ AFRAME.registerComponent('beat-loader', {
|
|||||||
fetchBeats: function () {
|
fetchBeats: function () {
|
||||||
var el = this.el;
|
var el = this.el;
|
||||||
|
|
||||||
if (this.xhr) { this.xhr.abort(); }
|
// Load beats
|
||||||
|
let beat = this.data.difficultyFiles[this.data.difficulty];
|
||||||
// Load beats.
|
el.emit('beatloaderstart')
|
||||||
let url = utils.getS3FileUrl(this.data.menuSelectedChallengeId,
|
this.beatData = beat;
|
||||||
`${this.data.difficulty}.json`);
|
this.beatDataProcessed = false;
|
||||||
const xhr = this.xhr = new XMLHttpRequest();
|
console.log(this.beatData);
|
||||||
el.emit('beatloaderstart');
|
this.el.sceneEl.emit('beatloaderfinish', null, false);
|
||||||
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();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ AFRAME.registerComponent('menu-selected-challenge-image', {
|
|||||||
update: function () {
|
update: function () {
|
||||||
const el = this.el;
|
const el = this.el;
|
||||||
if (!this.data.selectedChallengeId) { return; }
|
if (!this.data.selectedChallengeId) { return; }
|
||||||
|
console.log('menu-selected-challenge-image', this.data.selectedChallengeId)
|
||||||
el.setAttribute(
|
el.setAttribute(
|
||||||
'material', 'src',
|
'material', 'src',
|
||||||
this.data.selectedChallengeId);
|
this.data.selectedChallengeId);
|
||||||
|
el.setAttribute('crossOrigin', 'anonymous');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,16 +64,28 @@ AFRAME.registerComponent('search', {
|
|||||||
const songBlob = await songFile.getData(new zip.BlobWriter());
|
const songBlob = await songFile.getData(new zip.BlobWriter());
|
||||||
const songUrl = URL.createObjectURL(songBlob);
|
const songUrl = URL.createObjectURL(songBlob);
|
||||||
console.log(songUrl);
|
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 {
|
return {
|
||||||
songName: result.metadata.songName,
|
songName: result.metadata.songName,
|
||||||
songSubName: result.metadata.songAuthorName,
|
songSubName: result.metadata.songAuthorName,
|
||||||
imageUrl: result.versions[0].coverURL,
|
imageUrl: coverUrl,
|
||||||
songUrl: songUrl,
|
songUrl: songUrl,
|
||||||
id: result.id,
|
id: result.id,
|
||||||
data: result,
|
data: result,
|
||||||
difficulties: _.map(infoJson._difficultyBeatmapSets[0]._difficultyBeatmaps, '_difficulty'),
|
difficulties: _.map(difficultyInfo, '_difficulty'),
|
||||||
numBeats: result.metadata.duration,
|
numBeats: result.metadata.duration,
|
||||||
|
difficultyFiles: difficultyFiles,
|
||||||
}
|
}
|
||||||
})).then((tmpResults) => {
|
})).then((tmpResults) => {
|
||||||
this.eventDetail.results = tmpResults;
|
this.eventDetail.results = tmpResults;
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ AFRAME.registerComponent('song-preview-system', {
|
|||||||
|
|
||||||
// Prefetch buffer for playing.
|
// Prefetch buffer for playing.
|
||||||
if (audioanalyser.xhr) { audioanalyser.xhr.abort(); }
|
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},
|
isBeatsPreloaded: {default: false},
|
||||||
isGameOver: {default: false},
|
isGameOver: {default: false},
|
||||||
isPlaying: {default: false},
|
isPlaying: {default: false},
|
||||||
isVictory: {default: false}
|
isVictory: {default: false},
|
||||||
|
songUrl: {type: 'string'}
|
||||||
},
|
},
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
@@ -126,7 +127,9 @@ AFRAME.registerComponent('song', {
|
|||||||
this.source = evt.detail;
|
this.source = evt.detail;
|
||||||
resolve(this.source);
|
resolve(this.source);
|
||||||
}, ONCE);
|
}, 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);
|
data.analyserEl.setAttribute('audioanalyser', this.analyserSetter);
|
||||||
|
|
||||||
// Already loaded.
|
// Already loaded.
|
||||||
|
|||||||
@@ -30,11 +30,11 @@
|
|||||||
|
|
||||||
<a-scene
|
<a-scene
|
||||||
mixin="gameoverAnimation bgColorAnimation tunnelColorAnimation leftLaserColorAnimation rightLaserColorAnimation textGlowColorAnimation floorColorAnimation"
|
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__gameover="isGameOver: isGameOver"
|
||||||
bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching"
|
bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching"
|
||||||
bind__leaderboard="isVictory: isVictory; menuSelectedChallengeId: menuSelectedChallenge.id; challengeId: challenge.id"
|
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"
|
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"
|
animation__gameover="property: object3D.background; type: color; to: #750000; startEvents: gameover"
|
||||||
console-shortcuts
|
console-shortcuts
|
||||||
|
|||||||
Reference in New Issue
Block a user