1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import { CourtManager } from "./court.mjs";
import { PlayerManager, addLoadBehaviour } from "./player.mjs";
import { Round, generateDummyGames, proposeGames } from "./game.mjs";
// Court and player handling
let c = new CourtManager();
let p = new PlayerManager();
addLoadBehaviour(p);
// Game handling
let proposal;
let session = []; // Persist this in local storage with 1 day limit
if (session.length === 0) {
session.push(new Round(generateDummyGames(c.listData, "---"), 0));
}
document.getElementById("game_list").innerHTML = session.at(-1).render();
document.getElementById("propose").addEventListener("click", () => {
let normalize = Number(document.getElementById("skill").value);
console.log(normalize);
let players = p.listData.map(function (p) {
p.skill = Math.ceil(p.skill / normalize);
return p;
});
proposal = proposeGames(players, c.listData);
document.getElementById("game_list").innerHTML = new Round(proposal).render();
});
document.getElementById("confirm").addEventListener("click", () => {
console.log(
"Confirm the proposal on screen for round " + session.length + "."
);
session.push(new Round(proposal, session.length));
// Need to update the number of games played here
document.getElementById("game_list").innerHTML = session.at(-1).render();
document.getElementById("timer-start").click();
const notification = new Notyf({
duration: 30 * 1000,
position: { x: "center", y: "top" },
types: [
{
type: "success",
background: "green",
duration: 1000 * 1000,
dismissible: true,
},
],
});
notification.success("Round confirmed!");
});
|