diff --git a/src/components/intro-song.js b/src/components/intro-song.js index 4365a3a..79e1256 100644 --- a/src/components/intro-song.js +++ b/src/components/intro-song.js @@ -1,9 +1,33 @@ AFRAME.registerComponent('intro-song', { - multiple: true, + schema: { + isPlaying: {default: true} + }, + + init: function () { + this.analyserEl = document.getElementById('audioAnalyser'); + this.audio = document.getElementById('introSong'); + }, + + update: function (oldData) { + const audio = this.audio; + + if (!this.el.sceneEl.isPlaying) { return; } + + if (!oldData.isPlaying && this.data.isPlaying) { + setTimeout(() => { + // TODO: Fade in volume. + this.analyserEl.setAttribute('audioanalyser', 'src', audio); + audio.play(); + }, 1000); + } + + if (oldData.isPlaying && !this.data.isPlaying) { + audio.pause(); + } + }, play: function () { - const audio = document.getElementById('introSong'); - audio.volume = 0.5; - audio.play(); + this.audio.volume = 0.5; + this.audio.play(); } }); diff --git a/src/components/menu-controls.js b/src/components/menu-controls.js index 8e6cb0f..33dc811 100644 --- a/src/components/menu-controls.js +++ b/src/components/menu-controls.js @@ -111,7 +111,9 @@ AFRAME.registerComponent('menu-controls', { unselect: function () { if (!this.data.enabled) { return; } - this.el.sceneEl.emit('menuunselect', null, false); + if (this.data.selectedChallengeId) { + this.el.sceneEl.emit('menuchallengeunselect', null, false); + } }, hoverResult: function (i) { diff --git a/src/components/song-preview.js b/src/components/song-preview.js index f35ed52..a7ff1a6 100644 --- a/src/components/song-preview.js +++ b/src/components/song-preview.js @@ -9,6 +9,7 @@ AFRAME.registerComponent('song-preview-system', { }, init: function () { + this.analyserEl = document.getElementById('audioAnalyser'); this.audio = null; this.audioStore = {}; this.preloadedAudioIds = []; @@ -162,8 +163,7 @@ AFRAME.registerComponent('song-preview-system', { }, updateAnalyser: function () { - document.getElementById('audioAnalyser').setAttribute('audioanalyser', 'src', this.audio); - document.getElementById('introSong').pause(); + this.analyserEl.setAttribute('audioanalyser', 'src', this.audio); }, /** diff --git a/src/index.html b/src/index.html index 605ba6a..1e5054d 100644 --- a/src/index.html +++ b/src/index.html @@ -10,19 +10,20 @@ diff --git a/src/state/index.js b/src/state/index.js index 975412f..617d3ff 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -131,6 +131,10 @@ AFRAME.registerState({ state.menuSelectedChallenge.downloadsText = `${challengeData.downloads} Plays`; }, + menuchallengeunselect: () => { + state.menuSelectedChallenge.id = ''; + }, + menudifficultyselect: (state, difficulty) => { state.menuSelectedChallenge.difficulty = difficulty; }, diff --git a/src/templates/menu.html b/src/templates/menu.html index 77cfe47..29eeec5 100644 --- a/src/templates/menu.html +++ b/src/templates/menu.html @@ -93,40 +93,32 @@ - + class="menuAnimation" + animation__menuleft="property: object3D.position.x; to: -0.59; dur: 200; easing: easeOutCubic; startEvents: menuchallengeselect" + animation__menuright="property: object3D.position.x; to: 0; dur: 200; easing: easeOutCubic; startEvents: menuchallengeunselect"> + material="shader: flat; color: #fff; transparent: true; opacity: 0"> {{ searchResults() }} - - + + material="shader: flat; color: #fff; transparent: true; opacity: 0.0">