From 34d77cd777bd44d7bfe0e3ab3379f9be256ca88b Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sun, 9 Nov 2025 09:56:59 +0100 Subject: Moved to javascript codebase --- .gitignore | 181 ------------------------------------------------------------- 1 file changed, 181 deletions(-) delete mode 100644 .gitignore (limited to '.gitignore') diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 7e5d5dd..0000000 --- a/.gitignore +++ /dev/null @@ -1,181 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -# VS Code -.vscode - -# Data -data -*.csv - -# Scripts -*.ps1 -*.cmd -*.sh - -# Mac specfic -.DS_Store - -# Databases -*.db - -# Environmental variables -*.flaskenv - -# Caches -.ruff_cache \ No newline at end of file -- cgit v1.3.1 From ef064591d9f31c88df27624277ee9747bd806a74 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sun, 9 Nov 2025 15:58:20 +0100 Subject: Add the changes to the gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore (limited to '.gitignore') diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc0846e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Data files +*.csv \ No newline at end of file -- cgit v1.3.1 From 02d11ff6d5392ae6207380ea7656f8060a5a8c0b Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sun, 9 Nov 2025 16:38:22 +0100 Subject: Updated the deploy step --- .gitignore | 5 ++++- .gitlab-ci.yml | 6 ------ index.html | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index fc0846e..e8f5eb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Data files -*.csv \ No newline at end of file +*.csv + +# Output files +public \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 31bc86e..96fb3e5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,13 +2,7 @@ image: node:lts create-pages: pages: - # The folder that contains the files to be exposed at the Page URL publish: public - rules: - # This ensures that only pushes to the default branch will trigger - # a pages deploy - - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH - # Functions that should be executed before the build script is run before_script: - mkdir public script: diff --git a/index.html b/index.html index e85e6f9..bd3c8cb 100644 --- a/index.html +++ b/index.html @@ -13,6 +13,7 @@
+

Match Up!

-- cgit v1.3.1 From 4693fcf941e1ab30821b8d514beb5d79e5e2b20a Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Thu, 13 Nov 2025 21:49:33 +0100 Subject: Cleaned up the home folder --- .gitignore | 143 +++++++++++++++++++++++++++++++++++++++++++++- court.mjs | 53 ----------------- favicon.ico | Bin 13054 -> 0 bytes game.mjs | 185 ------------------------------------------------------------ guest.mjs | 69 ----------------------- icon.png | Bin 1453 -> 0 bytes icon.svg | 54 ------------------ index.css | 12 ---- index.js | 15 ----- main.html | 102 --------------------------------- player.mjs | 150 ------------------------------------------------ timer.js | 88 ----------------------------- utils.mjs | 51 ----------------- 13 files changed, 141 insertions(+), 781 deletions(-) delete mode 100644 court.mjs delete mode 100644 favicon.ico delete mode 100644 game.mjs delete mode 100644 guest.mjs delete mode 100644 icon.png delete mode 100644 icon.svg delete mode 100644 index.css delete mode 100644 index.js delete mode 100644 main.html delete mode 100644 player.mjs delete mode 100644 timer.js delete mode 100644 utils.mjs (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index e8f5eb9..bb4dc45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,144 @@ # Data files *.csv -# Output files -public \ No newline at end of file +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.* +!.env.example + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist +.output + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Sveltekit cache directory +.svelte-kit/ + +# vitepress build output +**/.vitepress/dist + +# vitepress cache directory +**/.vitepress/cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# Firebase cache directory +.firebase/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v3 +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions + +# Vite files +vite.config.js.timestamp-* +vite.config.ts.timestamp-* +.vite/ \ No newline at end of file diff --git a/court.mjs b/court.mjs deleted file mode 100644 index 713c488..0000000 --- a/court.mjs +++ /dev/null @@ -1,53 +0,0 @@ -import { Manager } from "./utils.mjs"; - -class Court { - constructor(id, status) { - this.id = id; - this.status = typeof status !== "undefined" ? status : true; - this.name = "Court " + (id + 1); - } - toggle() { - this.status = !this.status; - this.print(); - } - print() { - let status = this.status ? "active" : "inactive"; - console.log(this.name + " is currently " + status); - } - render() { - let color = this.status ? "is-success" : "is-danger"; - let type = `class="button is-medium ${color}"`; - return ``; - } -} - -export class CourtManager extends Manager { - maxCourtCount = 12; - - constructor() { - super("court", []); - console.log("Loading court data."); - let data = JSON.parse(localStorage.getItem(this.description)); - if (data === null || data.length != this.maxCourtCount) { - console.log("Court data unavailable: " + data); - this.generate(); - return; - } - for (let i = 0; i < this.maxCourtCount; i++) { - this.listData.push(new Court(data[i].id, data[i].status)); - } - console.log("Loaded " + this.listData.length + " courts."); - this.render(); - this.addBehaviour(); - } - generate() { - console.log("Generating court data."); - for (let i = 0; i < this.maxCourtCount; i++) { - this.listData.push(new Court(i)); - } - console.log("Generated data for " + this.listData.length + " courts"); - this.store(); - this.render(); - this.addBehaviour(); - } -} diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index 6cb5040..0000000 Binary files a/favicon.ico and /dev/null differ diff --git a/game.mjs b/game.mjs deleted file mode 100644 index c67041f..0000000 --- a/game.mjs +++ /dev/null @@ -1,185 +0,0 @@ -import { Manager } from "./utils.mjs"; -import { CourtManager } from "./court.mjs"; -import { PlayerManager } from "./player.mjs"; - -class Team { - constructor(playerOne, playerTwo) { - this.playerOne = playerOne; - this.playerTwo = playerTwo; - } - print() { - console.log(this.playerOne + " and " + this.playerTwo); - } - render() { - let p1 = `${this.playerOne}`; - let p2 = `${this.playerTwo}`; - return p1 + p2; - } -} - -class Game { - constructor(id, teamOne, teamTwo, status) { - this.id = id; - this.teamOne = teamOne; - this.teamTwo = teamTwo; - this.status = typeof status !== "undefined" ? status : false; - } - print() { - let teamOne = this.teamOne.playerOne + " and " + this.teamOne.playerTwo; - let teamTwo = this.teamTwo.playerOne + " and " + this.teamTwo.playerTwo; - console.log(teamOne + " is playing against " + teamTwo); - } - render() { - let blockedState = this.teamOne.playerOne === "RESERVED"; - let type = blockedState ? `class="is-danger is-dark"` : ``; - return `${ - this.id + 1 - }${this.teamOne.render()}${this.teamTwo.render()}`; - } -} - -function generateDummyGames(courts, description) { - let team = new Team(description, description); - let games = []; - for (const court of courts) { - let game = new Game(court.id, team, team); - games.push(game); - } - return games; -} - -export class GameManager extends Manager { - courts = new CourtManager(); - players = new PlayerManager(); - - constructor() { - super("game", []); - this.round = Number(localStorage.getItem("round")) || 0; - console.log("Loading game data."); - let data = JSON.parse(localStorage.getItem(this.description)); - if (data === null || data.length === 0) { - console.log("Game data unavailable: " + data); - this.generate(); - return; - } - for (let i = 0; i < data.length; i++) { - let id = Number(data[i].id); - let teamOne = new Team( - data[i].teamOne.playerOne, - data[i].teamOne.playerTwo - ); - let teamTwo = new Team( - data[i].teamTwo.playerOne, - data[i].teamTwo.playerTwo - ); - let status = Boolean(data[i].status); - this.listData.push(new Game(id, teamOne, teamTwo, status)); - } - console.log("Loaded " + this.listData.length + " games."); - this.render(); - } - isConfirmed() { - return this.listData[0].status; - } - generate() { - console.log("Generating the dummy round."); - this.listData = generateDummyGames(this.courts.listData, "---"); - console.log("Loaded " + this.listData.length + " dummy round."); - for (let i = 0; i < this.listData.length; i++) { - this.listData[i].status = true; - } - console.log(this.listData); - this.store(); - this.render(); - } - addBehaviour() { - let description = this.isConfirmed() ? "Round " + this.round : "Proposal"; - document.getElementById("game_description").innerHTML = description; - } - getBlockedGames() { - const inactiveCourts = this.courts.inactive(); - console.log("Total reserved courts are " + inactiveCourts.length + "."); - return generateDummyGames(inactiveCourts, "RESERVED"); - } - inactive(courts) { - return generateDummyGames(courts, "---"); - } - active(courts, players) { - let games = []; - for (let index = 0; index < courts.length; index++) { - const startIndex = 4 * index; - const endIndex = startIndex + 4; - const courtPlayers = players.slice(startIndex, endIndex); - const team_1 = new Team(courtPlayers[0].name, courtPlayers[3].name); - const team_2 = new Team(courtPlayers[1].name, courtPlayers[2].name); - const game = new Game(courts[index].id, team_1, team_2); - game.print(); - games.push(game); - } - return games; - } - propose() { - console.log("Proposing new games!"); - let possibleMatches = getMatchCount( - this.players.listData, - this.courts.listData - ); - console.log("Total possible matches are " + possibleMatches + "."); - this.listData = this.getBlockedGames(); - const activeCourts = this.courts.active(); - const unusedCourts = activeCourts.slice(possibleMatches + 1); - this.listData = this.listData.concat(this.inactive(unusedCourts)); - const usedCourts = activeCourts.slice(0, possibleMatches); - let requiredPlayerCount = possibleMatches * 4; - const selectedPlayers = this.players.propose(requiredPlayerCount); - console.log("The matches are:"); - this.listData = this.listData.concat( - this.active(usedCourts, selectedPlayers) - ); - this.listData.sort((a, b) => a.id - b.id); - this.render(); - } - confirm() { - if (this.isConfirmed()) { - const notification = new Notyf(); - notification.error("Create a proposal first!"); - return; - } - console.log("Confirm the proposal for round " + this.round + "."); - this.round += 1; - localStorage.setItem("round", this.round); - for (let i = 0; i < this.listData.length; i++) { - this.listData[i].status = true; - } - // Need to update the number of games played here - this.store(); - this.render(); - document.getElementById("timer-start").click(); - const notification = new Notyf(); - notification.success("Round confirmed!"); - } - reset() { - localStorage.removeItem("round"); - localStorage.removeItem(this.description); - localStorage.removeItem(this.courts.description); - document.getElementById("timer-stop").click(); - window.location.reload(); - const notification = new Notyf(); - notification.error("Session has been reset!"); - } -} - -function getMatchCount(players, courts) { - courts = courts.filter(function (c) { - return c.status; - }); - console.log("There are a total of " + courts.length + " courts available."); - console.log(players); - players = players.filter(function (p) { - return p.status; - }); - console.log("There are a total of " + players.length + " players available."); - var possibleMatches = Math.floor(players.length / 4); - possibleMatches = Math.min(possibleMatches, courts.length); - return possibleMatches; -} diff --git a/guest.mjs b/guest.mjs deleted file mode 100644 index ba9e8cc..0000000 --- a/guest.mjs +++ /dev/null @@ -1,69 +0,0 @@ -import { Manager } from "./utils.mjs"; - -export class Guest { - constructor(id, name, level, status, totalPlayed) { - this.id = id; - this.status = typeof status !== "undefined" ? status : false; - this.name = name; - this.level = typeof level !== "undefined" ? level : 1; - this.totalPlayed = typeof totalPlayed !== "undefined" ? status : 0; - } - toggle() { - this.status = !this.status; - this.print(); - } - print() { - let status = this.status ? "active" : "inactive"; - console.log(this.name + " is currently " + status); - } - render() { - let color = this.status ? "is-success" : "is-danger"; - let type = `class="button is-medium ${color}"`; - return ``; - } -} - -export class GuestManager extends Manager { - constructor() { - super("guest", []); - console.log("Loading guest data."); - let data = JSON.parse(localStorage.getItem(this.description)); - if (data === null || data.length === 0) { - console.log("Guest data unavailable: " + data); - this.generate(); - return; - } - for (let i = 0; i < data.length; i++) { - let id = Number(data[i].id); - let name = data[i].name; - let level = data[i].level; - let status = data[i].status; - let totalPlayed = data[i].totalPlayed; - this.listData.push(new Player(id, name, level, status, totalPlayed)); - } - console.log("Loaded " + this.listData.length + " players."); - this.render(); - } - generate() { - console.log("Generating guest data."); - let maxPlayerCount = 12; - for (let i = 0; i < maxPlayerCount; i++) { - let level = i < 3 ? 1 : ( i < 6 ? 3 : 7); - let p = new Player(i, "Player " + i, level, false, 0); - this.listData.push(p); - } - console.log("Generated data for " + this.listData.length + " guest"); - this.store(); - this.render(); - } - active(factor) { - factor = typeof factor !== "undefined" ? factor : 1; - let data = super.active(); - console.log("Normalize skill by a factor of " + factor + "."); - let players = data.map(function (p) { - p.skill = Math.ceil(p.skill / factor); - return p; - }); - return players; - } -} \ No newline at end of file diff --git a/icon.png b/icon.png deleted file mode 100644 index 655915f..0000000 Binary files a/icon.png and /dev/null differ diff --git a/icon.svg b/icon.svg deleted file mode 100644 index 278a070..0000000 --- a/icon.svg +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/index.css b/index.css deleted file mode 100644 index 8e3b713..0000000 --- a/index.css +++ /dev/null @@ -1,12 +0,0 @@ -.button-grid { - display: grid; - grid-template-columns: repeat(4, 1fr); - grid-gap: 15px; -} -#timer-display { - text-align: center; - width: fit-content; -} -table { - font-size: 1.5em; -} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 9494abb..0000000 --- a/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import { GameManager } from "./game.mjs"; - -// Court and player handling -let g = new GameManager(); - -// Game handling -document.getElementById("propose").addEventListener("click", () => { - g.propose(); -}); -document.getElementById("confirm").addEventListener("click", () => { - g.confirm(); -}); -document.getElementById("reset").addEventListener("click", () => { - g.reset(); -}); diff --git a/main.html b/main.html deleted file mode 100644 index b3f2f0a..0000000 --- a/main.html +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - Match Up! - - - - - - -
- -
-
- - - - - - - - - - -
CourtTeam 1Team 2
-
-
-
- -
- -
- - -
-
-
-

Courts

-
-
-
-

Regulars

-
-
-
-

Guests

-
-
-
-

Player Update

-
- -
-
-
-
- - - - - - \ No newline at end of file diff --git a/player.mjs b/player.mjs deleted file mode 100644 index 594bb7b..0000000 --- a/player.mjs +++ /dev/null @@ -1,150 +0,0 @@ -import { GuestManager } from "./guest.mjs"; -import { shuffle, Manager } from "./utils.mjs"; - -class Player { - constructor(id, name, level, status, totalPlayed) { - this.id = id; - this.status = typeof status !== "undefined" ? status : false; - this.name = name; - this.level = typeof level !== "undefined" ? level : 1; - this.totalPlayed = typeof totalPlayed !== "undefined" ? status : 0; - } - toggle() { - this.status = !this.status; - this.print(); - } - print() { - let status = this.status ? "active" : "inactive"; - console.log(this.name + " is currently " + status); - } - render() { - let color = this.status ? "is-success" : "is-danger"; - let type = `class="button is-medium ${color}"`; - return ``; - } -} - -function randomLevel() { - const max_level = 10; - return Math.floor(Math.random() * max_level + 1); -} - -function randomStatus() { - return Math.random() < 0.5; -} - -function parseLineToPlayer(data) { - var info = data.split(","); - var id = Number(info[0].trim()); - var name = info[1].trim() + " " + info[2].trim(); - var level = Number(info[3].trim()); - return new Player(id, name, level, true, 0); -} - -export class PlayerManager extends Manager { - g = new GuestManager(); - - constructor() { - super("regular", []); - console.log("Loading player data."); - let data = JSON.parse(localStorage.getItem(this.description)); - if (data === null || data.length === 0) { - console.log("Player data unavailable: " + data); - this.generate(); - return; - } - for (let i = 0; i < data.length; i++) { - let id = Number(data[i].id); - let name = data[i].name; - let level = data[i].level; - let status = data[i].status; - let totalPlayed = data[i].totalPlayed; - this.listData.push(new Player(id, name, level, status, totalPlayed)); - } - console.log("Loaded " + this.listData.length + " players."); - this.render(); - this.addBehaviour(); - addLoadBehaviour(this); - } - generate() { - console.log("Generating player data."); - let maxPlayerCount = 71; - for (let i = 0; i < maxPlayerCount; i++) { - let p = new Player(i, "Player " + i, randomLevel(), randomStatus(), 0); - this.listData.push(p); - } - console.log("Generated data for " + this.listData.length + " players"); - this.store(); - this.render(); - } - import(data) { - var lines = data.split("\n"); - var players = []; - for (var i = 1; i < lines.length; i++) { - if (lines[i] == undefined || lines[i].trim() == "") { - continue; - } - players.push(parseLineToPlayer(lines[i])); - } - console.log("Loaded " + players.length + " Players"); - for (var i = 0; i < players.length; i++) { - players[i].print(); - } - this.listData = players; - this.store(); - this.render(); - } - active(factor) { - factor = typeof factor !== "undefined" ? factor : 1; - let data = super.active(); - console.log("Normalize skill by a factor of " + factor + "."); - let players = data.map(function (p) { - p.skill = Math.ceil(p.skill / factor); - return p; - }); - return players; - } - propose(count) { - console.log("Required players are " + count); - let factor = Number(document.getElementById("skill").value); - console.log("Skill normalized by a factor of " + factor + "."); - const activePlayers = this.active(factor); - console.log("Active players are:"); - console.log( - activePlayers - .map((i) => { - return i.name; - }) - .join(",") - ); - const shuffledPlayers = shuffle(activePlayers); - shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed); - const selectedPlayers = shuffledPlayers.slice(0, count); - selectedPlayers.sort((a, b) => a.level - b.level); - console.log("Selected players are:"); - console.log( - selectedPlayers - .map((i) => { - return i.name; - }) - .join(",") - ); - return selectedPlayers; - } -} - -// TODO Add load behaviour to constructor -export function addLoadBehaviour(p) { - const f = document.querySelector("#player-load input[type=file]"); - f.addEventListener("change", () => { - const file = f.files[0]; - let importData; - console.log("Loading data from " + file.name); - const reader = new FileReader(); - reader.onload = function (e) { - importData = reader.result; - p.import(importData); - }; - reader.readAsText(file); - }); -} diff --git a/timer.js b/timer.js deleted file mode 100644 index 09189c0..0000000 --- a/timer.js +++ /dev/null @@ -1,88 +0,0 @@ -let minsPerRound = Number(sessionStorage.getItem("minsPerRound")) || 12; -let timerRunningFlag = Number(sessionStorage.getItem("timerRunningFlag")) || 0; -let deadline = - Number(sessionStorage.getItem("deadline")) || new Date().getTime(); -let clock = 0; - -function setTimer(m, s) { - let timer = document.getElementById("timer-display"); - m = m < 10 ? "0" + m : m; - s = s < 10 ? "0" + s : s; - timer.value = `${m}:${s}`; -} - -function setSessionData() { - sessionStorage.setItem("deadline", deadline); - sessionStorage.setItem("minsPerRound", minsPerRound); - sessionStorage.setItem("timerRunningFlag", timerRunningFlag); -} - -function resetTimer() { - clearInterval(clock); - let mins = Math.floor(minsPerRound); - let secs = (minsPerRound - mins) * 60; - setTimer(mins, secs); - timerRunningFlag = 0; - setSessionData(); -} - -function updateTimer(milliseconds) { - const m = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60)); - const s = Math.floor((milliseconds % (1000 * 60)) / 1000); - setTimer(m, s); -} - -function refreshTimer() { - const now = new Date().getTime(); - const millisecondsToDeadline = deadline - now; - if (millisecondsToDeadline > 0) { - updateTimer(millisecondsToDeadline); - return; - } - resetTimer(); - const notification = new Notyf({ - duration: 0, - position: { x: "center", y: "top" }, - dismissible: true, - }); - notification.error("Round completed"); -} - -function startTimer(fresh) { - if (fresh) { - let now = new Date().getTime(); - const millisecondsToDeadline = minsPerRound * 60 * 1000; - deadline = now + millisecondsToDeadline; - } - timerRunningFlag = 1; - setSessionData(); - clock = setInterval(refreshTimer, 1000); -} - -window.onload = function () { - if (timerRunningFlag) startTimer(0); - else resetTimer(); - - document.getElementById("timer-start").addEventListener("click", () => { - if (timerRunningFlag != 0) return; - startTimer(1); - }); - - document.getElementById("timer-stop").addEventListener("click", () => { - resetTimer(); - }); - - document.getElementById("timer-inc").addEventListener("click", () => { - if (timerRunningFlag == 0) { - minsPerRound += 0.5; - resetTimer(); - } - }); - - document.getElementById("timer-dec").addEventListener("click", () => { - if (timerRunningFlag == 0 && minsPerRound != 0) { - minsPerRound -= 0.5; - resetTimer(); - } - }); -}; diff --git a/utils.mjs b/utils.mjs deleted file mode 100644 index 06a2519..0000000 --- a/utils.mjs +++ /dev/null @@ -1,51 +0,0 @@ -export class Manager { - constructor(description, listData) { - this.description = description; - this.listData = listData; - this.count = listData.length; - } - store() { - let stringData = JSON.stringify(this.listData); - localStorage.setItem(this.description, stringData); - } - render() { - let renderedHTML = this.listData - .map((i) => { - return i.render(); - }) - .join(""); - let elementId = this.description + "_list"; - document.getElementById(elementId).innerHTML = renderedHTML; - this.addBehaviour(); - } - addBehaviour() { - for (let idx = 0; idx < this.listData.length; ++idx) { - const elementId = this.description + "_" + this.listData[idx].id; - const p = document.getElementById(elementId); - p.addEventListener("click", () => { - this.listData[idx].toggle(); - this.store(); - p.classList.toggle("is-success"); - p.classList.toggle("is-danger"); - }); - } - } - active() { - return this.listData.filter(function (c) { - return c.status; - }); - } - inactive() { - return this.listData.filter(function (c) { - return !c.status; - }); - } -} - -export function shuffle(array) { - for (let i = array.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [array[i], array[j]] = [array[j], array[i]]; - } - return array; -} -- cgit v1.3.1