2026-01-15 11:51:48 +00:00
|
|
|
import { Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js";
|
|
|
|
|
|
|
|
|
|
export class WelcomeController extends Controller {
|
2026-01-16 11:12:30 +00:00
|
|
|
static targets = ["simpleHighScores"];
|
|
|
|
|
|
|
|
|
|
connect() {
|
|
|
|
|
this._buildHighScores();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 11:51:48 +00:00
|
|
|
startGame(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
|
|
this.element.classList.add('hidden');
|
2026-01-16 11:12:30 +00:00
|
|
|
window.dispatchEvent(new CustomEvent("startCountdown"));
|
2026-01-15 11:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gameEnded(ev) {
|
|
|
|
|
this.element.classList.remove('hidden');
|
|
|
|
|
}
|
2026-01-16 11:12:30 +00:00
|
|
|
|
|
|
|
|
_buildHighScores() {
|
|
|
|
|
let scores = {
|
|
|
|
|
last: 12,
|
|
|
|
|
high: 10,
|
|
|
|
|
streak: 3
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let newEls = [
|
|
|
|
|
`<span>🏆 ${scores.last}</span>`,
|
|
|
|
|
`<span>🔥 ${scores.streak}</span>`,
|
|
|
|
|
`<span>↩️ ${scores.high}</span>`
|
|
|
|
|
];
|
|
|
|
|
this.simpleHighScoresTarget.innerHTML = newEls.join('');
|
|
|
|
|
}
|
2026-01-15 11:51:48 +00:00
|
|
|
}
|