From 1b965d741f2fd7d1e7aa6116f8ca3f94cf0cf3d7 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Sun, 2 Dec 2018 20:13:05 -0800 Subject: [PATCH] no allocate obj on walls --- src/components/beat-loader.js | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/components/beat-loader.js b/src/components/beat-loader.js index e071c96..a3b66d6 100644 --- a/src/components/beat-loader.js +++ b/src/components/beat-loader.js @@ -216,21 +216,18 @@ AFRAME.registerComponent('beat-loader', { const beatObj = {}; return function (noteInfo) { - var beatEl; - var color; const data = this.data; - // if (Math.random() < 0.8) noteInfo._type = 3; // just to DEBUG MINES! + // if (Math.random() < 0.8) { noteInfo._type = 3; } // To debug mines. + const type = noteInfo._cutDirection === 8 ? 'dot' : 'arrow'; - var type = noteInfo._cutDirection === 8 ? 'dot' : 'arrow'; - - color = noteInfo._type === 0 ? 'red' : 'blue'; + let color = noteInfo._type === 0 ? 'red' : 'blue'; if (noteInfo._type === 3) { type = 'mine'; color = undefined; } - beatEl = this.requestBeat(type, color); + const beatEl = this.requestBeat(type, color); if (!beatEl) { return; } // Apply sword offset. Blocks arrive on beat in front of the user. @@ -250,25 +247,30 @@ AFRAME.registerComponent('beat-loader', { }; })(), - generateWall: function (wallInfo) { - var el = this.el.sceneEl.components.pool__wall.requestEntity(); - const data = this.data; - var speed = this.data.beatSpeed; + generateWall: (function () { const wallObj = {}; - if (!el) { return; } + return function (wallInfo) { + const el = this.el.sceneEl.components.pool__wall.requestEntity(); - const durationSeconds = 60 * (wallInfo._duration / this.bpm); - wallObj.anticipationPosition = -data.beatAnticipationTime * data.beatSpeed - this.swordOffset; - wallObj.durationSeconds = durationSeconds; - wallObj.horizontalPosition = this.horizontalPositionsHumanized[wallInfo._lineIndex]; - wallObj.speed = speed; - wallObj.warmupPosition = -data.beatWarmupTime * data.beatWarmupSpeed; - wallObj.width = wallInfo._width; - el.setAttribute('wall', wallObj); - el.components.wall.updatePosition(); - el.play(); - }, + if (!el) { return; } + + const data = this.data; + const speed = this.data.beatSpeed; + + const durationSeconds = 60 * (wallInfo._duration / this.bpm); + wallObj.anticipationPosition = + -data.beatAnticipationTime * data.beatSpeed - this.swordOffset; + wallObj.durationSeconds = durationSeconds; + wallObj.horizontalPosition = this.horizontalPositionsHumanized[wallInfo._lineIndex]; + wallObj.speed = speed; + wallObj.warmupPosition = -data.beatWarmupTime * data.beatWarmupSpeed; + wallObj.width = wallInfo._width; + el.setAttribute('wall', wallObj); + el.components.wall.updatePosition(); + el.play(); + }; + })(), generateEvent: function (event) { switch(event._type) {