From 2fb925ddd4209b3773c1b1eb71ab5dea45aedf36 Mon Sep 17 00:00:00 2001 From: "maxence.guitard" Date: Thu, 9 Nov 2023 10:55:42 +0100 Subject: [PATCH] feat : lien Chrono/ProgressBar --- Website/css/progressBar.css | 9 ++++ Website/js/progressBar.js | 73 ++++++++++++++++++++++++++++++ Website/js/scriptChrono.js | 11 ++++- Website/templates/multijoueur.twig | 23 ++++++++-- 4 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 Website/css/progressBar.css create mode 100644 Website/js/progressBar.js diff --git a/Website/css/progressBar.css b/Website/css/progressBar.css new file mode 100644 index 0000000..b98e845 --- /dev/null +++ b/Website/css/progressBar.css @@ -0,0 +1,9 @@ +.progress { + position: relative; +} + +.progress img { + position: absolute; + height: 16px; + width: auto; +} \ No newline at end of file diff --git a/Website/js/progressBar.js b/Website/js/progressBar.js new file mode 100644 index 0000000..ceb5234 --- /dev/null +++ b/Website/js/progressBar.js @@ -0,0 +1,73 @@ +import { tempsExport } from "./scriptChrono.js"; + +$(document).ready(function() { + var timerId, percent; + percent = 0; + var isPaused = false; + + // reset progress bar + percent = 0; + //$('#test').attr('disabled', true); + $('#load').css('width', '0px'); + $('#load').addClass('progress-bar-striped active'); + $('#rocket').show(); + + timerId = setInterval(function() { + if(!isPaused){ + // increment progress bar + percent += 1/12; + $('#load').css('width', percent + '%'); + $('#load').html(percent + '%'); + $('#rocket').css('left','calc('+percent+'% - 19px'); + + if(percent>= 100){ + clearInterval(timerId); + $('#load').removeClass('progress-bar-striped active'); + $('#load').addClass('bg-danger'); + $('#repondbien').attr('disabled', true); + $('#load').html('Finish'); + $('#rocket').hide(); + } + } + }, 250); + + function wait(ms){ + var start = new Date().getTime(); + var end = start; + while(end < start + ms) { + end = new Date().getTime(); + } + } + + $('#repondbien').click(function() { + if (tempsExport <= 6000) { + percent += 12; + } else if (tempsExport > 6000 && tempsExport <= 12000) { + percent += 11; + } else if (tempsExport > 12000 && tempsExport <= 18000) { + percent += 10; + } else if (tempsExport > 18000 && tempsExport <= 24000) { + percent += 9; + } else { + percent += 8; + } + $('#repondbien').attr('disabled', false); + $('#load').css('width', '0px'); + $('#load').addClass('progress-bar-striped active'); + $('#load').removeClass('bg-danger'); + $('#load').css('width', percent + '%'); + $('#load').html(percent + '%'); + + }) + + $('#repondmal').click(function() { + isPaused = true; + $('#repondmal').attr('disabled', false); + //$('#load').css('width', percent+'px'); + $('#load').addClass('progress-bar-striped active'); + $('#load').removeClass('bg-danger'); + wait(3000); + console.log("test"); + isPaused = false; + }) +}) \ No newline at end of file diff --git a/Website/js/scriptChrono.js b/Website/js/scriptChrono.js index 9d7061e..1ed9402 100644 --- a/Website/js/scriptChrono.js +++ b/Website/js/scriptChrono.js @@ -1,22 +1,28 @@ +let tempsExport = 0; const dureeQuiz = 30; // Durée du quiz en secondes const aiguilleElement = document.getElementById("aiguille"); const fondElement = document.getElementById("fond"); let tempsRestant = dureeQuiz; let debutAnimation; const animationDuration = 30 * 1000; // Durée de l'animation en millisecondes + + + function mettreAJourTempsExport(newTemps) { + tempsExport = newTemps; + } function mettreAJourAiguille(timestamp) { if (!debutAnimation) { debutAnimation = timestamp; } const tempsEcoule = timestamp - debutAnimation; + mettreAJourTempsExport(tempsEcoule); const pourcentageTempsEcoule = tempsEcoule / animationDuration; const rotationDeg = pourcentageTempsEcoule * 360; aiguilleElement.style.transform = `rotate(${rotationDeg}deg)`; // Mettez à jour le fond en fonction de la position de l'aiguille fondElement.style.background = `conic-gradient(red 0%, red ${rotationDeg}deg, #4b4b4b ${rotationDeg}deg, #4b4b4b 360deg)`; - if (tempsEcoule < animationDuration) { requestAnimationFrame(mettreAJourAiguille); } else { @@ -25,4 +31,5 @@ const dureeQuiz = 30; // Durée du quiz en secondes // action à foutre à la fin du timer } } -requestAnimationFrame(mettreAJourAiguille); \ No newline at end of file +requestAnimationFrame(mettreAJourAiguille); +export {tempsExport}; \ No newline at end of file diff --git a/Website/templates/multijoueur.twig b/Website/templates/multijoueur.twig index 77ea8c6..21e2531 100644 --- a/Website/templates/multijoueur.twig +++ b/Website/templates/multijoueur.twig @@ -1,12 +1,14 @@ - + Math'Educ + + @@ -19,8 +21,20 @@
- +
+
+
+ +
+ +
+ + + +
+ +

@@ -69,4 +83,7 @@

- \ No newline at end of file + + + + \ No newline at end of file