From 52b9b19cf57a5af6948437c6bb593b93118ee3c7 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Tue, 9 Oct 2018 17:17:41 -0700 Subject: [PATCH] clean up state --- src/components/beat-loader.js | 4 ++-- src/components/gameover.js | 14 ++++++++------ src/index.html | 7 ++----- src/state/index.js | 2 +- src/templates/dialogs.html | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index f6f0a32..a422856 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -9,7 +9,7 @@ AFRAME.registerComponent('beat-loader', { beatSpeed: {default: 4.0}, challengeId: {type: 'string'}, difficulty: {type: 'string'}, - isPaused: {default: false} + isPlaying: {default: false} }, orientations: [180, 0, 270, 90, 225, 135, 315, 45, 0], @@ -88,7 +88,7 @@ AFRAME.registerComponent('beat-loader', { delta *= this.speed; - if (this.data.isPaused || !this.data.challengeId || !this.beatData || !audioEl) { return; } + if (!this.data.isPlaying || !this.data.challengeId || !this.beatData || !audioEl) { return; } notes = this.beatData._notes; obstacles = this.beatData._obstacles; diff --git a/src/components/gameover.js b/src/components/gameover.js index adefc6e..5da62ae 100644 --- a/src/components/gameover.js +++ b/src/components/gameover.js @@ -1,25 +1,27 @@ AFRAME.registerComponent('gameover', { schema: { - start: {default: false}, - reset: {default: false} + isGameOver: {default: false} }, + init: function () { this.beatContainer = document.getElementById('beatContainer'); }, + update: function (oldData) { var data = this.data; - if (data.start){ + if (!oldData.isGameOver && this.data.isGameOver){ console.log('starting slow down...'); this.el.sceneEl.setAttribute('stage-colors', 'red'); this.countDown = 1; this.lastTime = performance.now(); } - if (data.reset && data.reset !== oldData.reset){ + if (oldData.isGameOver && !this.data.isGameOver){ this.resetStage(); } }, + tick: function (time, delta) { - if (!this.data.start) return; + if (!this.data.isGameOver) { return; } if (this.countDown >= 0){ this.el.sceneEl.emit('slowdown', {progress: this.countDown}); //this.beatContainer.object3D.position.z = -Math.pow(1 - this.countDown, 2) * 1.5; @@ -37,4 +39,4 @@ AFRAME.registerComponent('gameover', { this.el.sceneEl.systems.beat.speed = 1.0; this.el.sceneEl.setAttribute('stage-colors', 'blue'); } -}); \ No newline at end of file +}); diff --git a/src/index.html b/src/index.html index d401427..e9e085d 100644 --- a/src/index.html +++ b/src/index.html @@ -8,15 +8,13 @@ - {% include './templates/debugStates.html' %} - diff --git a/src/state/index.js b/src/state/index.js index 74cce30..2f19c5c 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -234,7 +234,7 @@ AFRAME.registerState({ * Post-process the state after each action. */ computeState: (state) => { - state.isPlaying = !state.menu.active && !state.isPaused && !state.isVictory; + state.isPlaying = !state.menu.active && !state.isPaused && !state.isVictory && !state.isGameOver; state.leftRaycasterActive = !state.isPlaying && state.activeHand === 'left' && state.inVR; state.rightRaycasterActive = !state.isPlaying && state.activeHand === 'right' && state.inVR; state.multiplierText = `${state.score.multiplier}x`; diff --git a/src/templates/dialogs.html b/src/templates/dialogs.html index bfb3763..395412a 100644 --- a/src/templates/dialogs.html +++ b/src/templates/dialogs.html @@ -14,7 +14,7 @@ - +