Skip to content

Commit bb29e47

Browse files
authored
Merge branch 'dev' into version-update
2 parents e112507 + f1b1d73 commit bb29e47

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ This project uses or references the following open source projects:
4848
- **Sober.js** [[Official Website]](https://soberjs.com) [[GitHub]](https://github.com/apprat/sober)
4949
Sober is a Web Component UI component library that references the Google Material You design specification.
5050

51+
- **canvas-confetti** [[Official Website]](https://catdad.github.io/canvas-confetti/) [[GitHub]](https://github.com/catdad/canvas-confetti)
52+
🎉 performant confetti animation in the browser
53+
5154
Thanks to these projects and their authors.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"vite-plugin-html": "^3.2.2"
1717
},
1818
"dependencies": {
19+
"canvas-confetti": "^1.9.3",
1920
"sober": "~1.1.5"
2021
}
2122
}

src/script.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { lang } from './lang';
2-
import { hideLoading, showLoading, showSnackBar } from './ui';
2+
import { hideLoading, showLoading, showSnackBar, showWinnerConfetti } from './ui';
33

44
let players = [];
55
let totalScores = {};
@@ -147,6 +147,10 @@ export function incrementCurrentMatchScore(playerName) {
147147
)
148148
);
149149
disableScoreButtons();
150+
151+
// Wining Animation
152+
showWinnerConfetti();
153+
150154
setTimeout(() => {
151155
document.getElementById('result').innerText = '';
152156
updatePlayerScoreList();

src/ui.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import confetti from 'canvas-confetti';
12
import { getLanguageList, lang, langForce, setCurrentLanguage, setLanguage, updateElementLanguages } from './lang';
23
import { readConfig, writeConfig } from './utils';
34

@@ -64,6 +65,46 @@ export function hideLoading() {
6465
document.getElementById('top-loading').style.visibility = 'hidden';
6566
}
6667

68+
/**
69+
* @param {number} particleRatio
70+
* @param {confetti.Options} [opts]
71+
*/
72+
function fireConfetti(particleRatio, opts = {}) {
73+
const count = 200;
74+
const defaults = {
75+
origin: { y: 0.7 },
76+
};
77+
confetti({
78+
...defaults,
79+
...opts,
80+
particleCount: Math.floor(count * particleRatio),
81+
});
82+
}
83+
export function showWinnerConfetti() {
84+
fireConfetti(0.25, {
85+
spread: 26,
86+
startVelocity: 55,
87+
});
88+
fireConfetti(0.2, {
89+
spread: 60,
90+
});
91+
fireConfetti(0.35, {
92+
spread: 100,
93+
decay: 0.91,
94+
scalar: 0.8,
95+
});
96+
fireConfetti(0.1, {
97+
spread: 120,
98+
startVelocity: 25,
99+
decay: 0.92,
100+
scalar: 1.2,
101+
});
102+
fireConfetti(0.1, {
103+
spread: 120,
104+
startVelocity: 45,
105+
});
106+
}
107+
67108
export function e_toggleTheme(theme) {
68109
let pageEl = document.getElementById('page');
69110
let themeIconEl = document.getElementById('theme-icon');

0 commit comments

Comments
 (0)