From 3a4a0f6f2bf9aff14c00c6acee637319d7458bbb Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Wed, 12 Nov 2025 14:18:36 +0100 Subject: Memory added --- index.js | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) (limited to 'index.js') 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", () => { -- cgit v1.3.1