From c897a5855253c9fa1e0dddad4b93b413c5c12334 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 15 Oct 2018 16:41:08 -0700 Subject: [PATCH] hook up stage-colors to cleargame event --- src/components/stage-colors.js | 31 ++++++++++++++++++++----------- src/index.html | 1 - 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/stage-colors.js b/src/components/stage-colors.js index 7ad8794..da75f55 100644 --- a/src/components/stage-colors.js +++ b/src/components/stage-colors.js @@ -4,8 +4,7 @@ AFRAME.registerComponent('stage-colors', { dependencies: ['background', 'fog'], schema: { - color: {default: 'blue', oneOf: ['blue', 'red']}, - isGameOver: {default: false} + color: {default: 'blue', oneOf: ['blue', 'red']} }, init: function () { @@ -51,13 +50,29 @@ AFRAME.registerComponent('stage-colors', { }); this.colorCodes = ['off', 'blue', 'blue', 'bluefade', '', 'red', 'red', 'redfade']; + + this.el.addEventListener('cleargame', this.resetColors.bind(this)); }, update: function (oldData) { - const red = this.data.color === 'red'; + this.updateColors(this.data.color); + }, - // Let game over animations do the work. Only update when leaving game over state. - if (!oldData.isGameOver && this.data.isGameOver) { return; } + setColor: function (target, code) { + const mesh = this.targets[target].getObject3D('mesh'); + if (mesh) { mesh.material.opacity = 1; } + this.targets[target].emit('color' + this.colorCodes[code], null, false); + }, + + resetColors: function () { + this.updateColors('blue'); + for (let target in this.targets) { + this.targets[target].emit('colorblue', null, false); + } + }, + + updateColors: function (color) { + const red = color === 'red'; // Init or reset. this.backglow.getObject3D('mesh').material.color.set(red ? '#f10' : '#00acfc'); @@ -72,11 +87,5 @@ AFRAME.registerComponent('stage-colors', { this.mineMaterial.emissive = this.mineEmission[red ? 'red' : 'blue']; this.mineMaterial.envMap = this.mineEnvMap[red ? 'red' : 'blue']; this.mineMaterial.needsUpdate = true; - }, - - setColor: function (target, code) { - const mesh = this.targets[target].getObject3D('mesh'); - if (mesh) { mesh.material.opacity = 1; } - this.targets[target].emit('color' + this.colorCodes[code], null, false); } }); diff --git a/src/index.html b/src/index.html index e545b35..debf7a8 100644 --- a/src/index.html +++ b/src/index.html @@ -21,7 +21,6 @@ bind__overlay="enabled: !isPlaying" bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver" bind__song-preview-system="challengeId: challenge.id; isSongLoading: isSongLoading; selectedChallengeId: menuSelectedChallenge.id" - bind__stage-colors="isGameOver: isGameOver" animation__gameover="property: object3D.background; type: color; to: #750000; startEvents: gameover" animation__gameoverfog="property: components.fog.el.object3D.fog.color; type: color; to: #330000; startEvents: gameover; dur: 500; easing: easeInQuad" console-shortcuts