blob: 28b2f05e9a2a41901acc0ed2f65ff1463a10ff23 (
plain) (
blame)
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
49
50
51
52
53
|
import { generateCourts } from "./court.mjs";
import { addToggleBehaviour } from "./utils.mjs";
import { csvToPlayers, generatePlayers } from "./player.mjs";
import { Round, generateDummyGames, proposeGames } from "./game.mjs";
// Court handling
let courts = generateCourts(); // Persist this in local storage with 1 day limit
addToggleBehaviour(courts, "court_");
// Regulars handling
let regulars = generatePlayers(); // Persist this in local storage without limit
addToggleBehaviour(regulars, "regular_");
const fileInput = document.querySelector("#player-load input[type=file]");
if (fileInput !== null) {
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
regulars = csvToPlayers(content);
addToggleBehaviour(regulars, "regular_");
};
reader.readAsText(file);
}
}
}
}
// Game handling
let proposal;
let session = []; // Persist this in local storage with 1 day limit
if (session.length === 0) {session.push(new Round(generateDummyGames(courts, "---"), 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);
regulars = regulars.map(function(p) {
p.skill = Math.ceil(p.skill / normalize);
return p;
})
proposal = proposeGames(regulars, courts);
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();
})
|