aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js40
1 files changed, 9 insertions, 31 deletions
diff --git a/index.js b/index.js
index 949ea80..6d74bd2 100644
--- a/index.js
+++ b/index.js
@@ -1,48 +1,26 @@
-import { generateCourts } from "./court.mjs";
-import { addToggleBehaviour } from "./utils.mjs";
-import { csvToPlayers, generatePlayers } from "./player.mjs";
+import { CourtManager } from "./court.mjs";
+import { PlayerManager, addLoadBehaviour } 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);
- }
- }
- }
-}
+// 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(courts, "---"), 0))};
+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);
- regulars = regulars.map(function(p) {
+ let players = p.listData.map(function(p) {
p.skill = Math.ceil(p.skill / normalize);
return p;
})
- proposal = proposeGames(regulars, courts);
+ proposal = proposeGames(players, c.listData);
document.getElementById("game_list").innerHTML = new Round(proposal).render();
})
document.getElementById("confirm").addEventListener("click", () => {