Slowed down animation and renamed variables.

- Unified html elements for smaller footprint.
- winnersNameDrawn is used to have separte messages for before and after
the winners name is decided.
This commit is contained in:
2020-12-31 17:21:32 +01:00
parent 50ea05cad3
commit d0cf99e8f8

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="current-drawn-container" v-if="drawing"> <div class="current-drawn-container" v-if="drawing">
<h2 v-if="vinnersNameDrawn !== true">TREKKER {{ ordinalNumber() }} VINNER</h2> <h2 v-if="winnersNameDrawn !== true">TREKKER {{ ordinalNumber() }} VINNER</h2>
<h2 v-else>VINNER</h2> <h2 v-else>VINNER</h2>
<div <div
@@ -43,14 +43,13 @@ export default {
nameTimeout: null, nameTimeout: null,
colorDone: false, colorDone: false,
drawing: false, drawing: false,
drawingDone: false, winnersNameDrawn: false,
winnerQueue: [] winnerQueue: []
}; };
}, },
watch: { watch: {
currentWinner: function(currentWinner) { currentWinner: function(currentWinner) {
if (currentWinner == null) { if (currentWinner == null) {
this.drawingDone = false;
return; return;
} }
if (this.drawing) { if (this.drawing) {
@@ -58,6 +57,7 @@ export default {
return; return;
} }
this.drawing = true; this.drawing = true;
this.winnersNameDrawn = false;
this.currentName = null; this.currentName = null;
this.currentColor = null; this.currentColor = null;
this.nameRounds = 0; this.nameRounds = 0;
@@ -81,8 +81,7 @@ export default {
this.drawColor(this.currentWinnerLocal.color); this.drawColor(this.currentWinnerLocal.color);
return; return;
} }
this.drawing = false; this.winnersNameDrawn = true;
this.drawingDone = true;
this.startConfetti(this.currentName); this.startConfetti(this.currentName);
return; return;
} }
@@ -96,7 +95,7 @@ export default {
}, 50); }, 50);
}, },
drawColor: function(winnerColor) { drawColor: function(winnerColor) {
this.drawingDone = false; this.winnersNameDrawn = false;
if (this.colorRounds == 100) { if (this.colorRounds == 100) {
this.currentColor = winnerColor; this.currentColor = winnerColor;
this.colorDone = true; this.colorDone = true;
@@ -111,7 +110,7 @@ export default {
clearTimeout(this.colorTimeout); clearTimeout(this.colorTimeout);
this.colorTimeout = setTimeout(() => { this.colorTimeout = setTimeout(() => {
this.drawColor(winnerColor); this.drawColor(winnerColor);
}, 50); }, 70);
}, },
getRotation: function() { getRotation: function() {
if (this.colorDone) { if (this.colorDone) {
@@ -133,7 +132,7 @@ export default {
return "yellow"; return "yellow";
} }
}, },
startConfetti(currentName){ startConfetti(currentName) {
//duration is computed as x * 1000 miliseconds, in this case 7*1000 = 7000 miliseconds ==> 7 seconds. //duration is computed as x * 1000 miliseconds, in this case 7*1000 = 7000 miliseconds ==> 7 seconds.
var duration = 7 * 1000; var duration = 7 * 1000;
var animationEnd = Date.now() + duration; var animationEnd = Date.now() + duration;
@@ -143,22 +142,25 @@ export default {
function randomInRange(min, max) { function randomInRange(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;
} }
const self = this;
var interval = setInterval(function() { var interval = setInterval(function() {
var timeLeft = animationEnd - Date.now(); var timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) { if (timeLeft <= 0) {
self.drawing = false;
console.time("drawing finished")
return clearInterval(interval); return clearInterval(interval);
} }
if(currentName == "Amund Brandsrud"){ if (currentName == "Amund Brandsrud") {
runCannon(uberDefaults, {x: 1, y: 1 }, {angle: 135}); runCannon(uberDefaults, {x: 1, y: 1 }, {angle: 135});
runCannon(uberDefaults, {x: 0, y: 1 }, {angle: 45}); runCannon(uberDefaults, {x: 0, y: 1 }, {angle: 45});
runCannon(uberDefaults, {y: 1 }, {angle: 90}); runCannon(uberDefaults, {y: 1 }, {angle: 90});
runCannon(uberDefaults, {x: 0 }, {angle: 45}); runCannon(uberDefaults, {x: 0 }, {angle: 45});
runCannon(uberDefaults, {x: 1 }, {angle: 135}); runCannon(uberDefaults, {x: 1 }, {angle: 135});
}else{ } else {
runCannon(defaults, {x: 0 }, {angle: 45}); runCannon(defaults, {x: 0 }, {angle: 45});
runCannon(defaults, {x: 1 }, {angle: 135}); runCannon(defaults, {x: 1 }, {angle: 135});
runCannon(defaults, {y: 1 }, {angle: 90}); runCannon(defaults, {y: 1 }, {angle: 90});
} }
}, 250); }, 250);