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 --- .gitlab-ci.yml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .gitlab-ci.yml (limited to '.gitlab-ci.yml') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e0d0142..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,12 +0,0 @@ -image: ruby:latest - -deploy: - stage: deploy - environment: - name: production - url: https://match-up-demo-73950c31ba18.herokuapp.com - script: - - gem install dpl - - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_PRODUCTION_KEY - rules: - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH -- cgit v1.3.1 From b5cbc5700ad9dc4298d2d41d3f9361cfb033214a Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sun, 9 Nov 2025 16:36:59 +0100 Subject: Added a simple deploy --- .gitlab-ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .gitlab-ci.yml (limited to '.gitlab-ci.yml') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..31bc86e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,15 @@ +# The Docker image that will be used to build your app +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: + - cp index.html index.css icon.svg *.js *.mjs public/ -- 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 '.gitlab-ci.yml') 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 05d2f2f943921d6b5c921686c5edce6eb39d23b8 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Thu, 13 Nov 2025 11:58:42 +0100 Subject: Cleaned up the code quite a bit --- .gitlab-ci.yml | 2 +- assets/icon.ipe | 461 -------------------------------------------------------- game.mjs | 188 ++++++++++++----------- icon.png | Bin 0 -> 1453 bytes icon.svg | 41 ++++- index.html | 23 +-- index.js | 10 +- player.mjs | 37 ++++- timer.js | 8 +- utils.mjs | 32 ++-- 10 files changed, 207 insertions(+), 595 deletions(-) delete mode 100644 assets/icon.ipe create mode 100644 icon.png (limited to '.gitlab-ci.yml') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 96fb3e5..3926782 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,4 @@ create-pages: before_script: - mkdir public script: - - cp index.html index.css icon.svg *.js *.mjs public/ + - cp index.html index.css icon.png *.js *.mjs public/ diff --git a/assets/icon.ipe b/assets/icon.ipe deleted file mode 100644 index d23d37f..0000000 --- a/assets/icon.ipe +++ /dev/null @@ -1,461 +0,0 @@ - - - - - - - -0 0 m --1 0.333 l --1 -0.333 l -h - - - - -0 0 m --1 0.333 l --1 -0.333 l -h - - - - -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h - - - - -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h - - - - -0.6 0 0 0.6 0 0 e -0.4 0 0 0.4 0 0 e - - - - -0.6 0 0 0.6 0 0 e - - - - - -0.5 0 0 0.5 0 0 e - - -0.6 0 0 0.6 0 0 e -0.4 0 0 0.4 0 0 e - - - - - --0.6 -0.6 m -0.6 -0.6 l -0.6 0.6 l --0.6 0.6 l -h --0.4 -0.4 m -0.4 -0.4 l -0.4 0.4 l --0.4 0.4 l -h - - - - --0.6 -0.6 m -0.6 -0.6 l -0.6 0.6 l --0.6 0.6 l -h - - - - - --0.5 -0.5 m -0.5 -0.5 l -0.5 0.5 l --0.5 0.5 l -h - - --0.6 -0.6 m -0.6 -0.6 l -0.6 0.6 l --0.6 0.6 l -h --0.4 -0.4 m -0.4 -0.4 l -0.4 0.4 l --0.4 0.4 l -h - - - - - - --0.43 -0.57 m -0.57 0.43 l -0.43 0.57 l --0.57 -0.43 l -h - - --0.43 0.57 m -0.57 -0.43 l -0.43 -0.57 l --0.57 0.43 l -h - - - - - -0 0 m --1 0.333 l --1 -0.333 l -h - - - - -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h - - - - -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h - - - - --1 0.333 m -0 0 l --1 -0.333 l - - - - -0 0 m --1 0.333 l --1 -0.333 l -h --1 0 m --2 0.333 l --2 -0.333 l -h - - - - -0 0 m --1 0.333 l --1 -0.333 l -h --1 0 m --2 0.333 l --2 -0.333 l -h - - - - -0.5 0 m --0.5 0.333 l --0.5 -0.333 l -h - - - - -0.5 0 m --0.5 0.333 l --0.5 -0.333 l -h - - - - -0.5 0 m --0.5 0.333 l --0.3 0 l --0.5 -0.333 l -h - - - - -0.5 0 m --0.5 0.333 l --0.3 0 l --0.5 -0.333 l -h - - - - -1 0 m -0 0.333 l -0 -0.333 l -h -0 0 m --1 0.333 l --1 -0.333 l -h - - - - -1 0 m -0 0.333 l -0 -0.333 l -h -0 0 m --1 0.333 l --1 -0.333 l -h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -92 620 m -4 0 0 -4 96 620 100 620 a -100 616 l -92 616 l -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h - - -92 620 m -4 0 0 -4 96 620 100 620 a -100 616 l -92 616 l -h - - - diff --git a/game.mjs b/game.mjs index 45efb81..926d0eb 100644 --- a/game.mjs +++ b/game.mjs @@ -1,5 +1,6 @@ +import { Manager } from "./utils.mjs"; import { CourtManager } from "./court.mjs"; -import { getMatchCount, shuffle, Manager } from "./utils.mjs"; +import { PlayerManager, addLoadBehaviour } from "./player.mjs"; class Team { constructor(playerOne, playerTwo) { @@ -10,27 +11,30 @@ class Team { console.log(this.playerOne + " and " + this.playerTwo); } render() { - return `${this.playerOne}${this.playerTwo}`; + let p1 = `${this.playerOne}`; + let p2 = `${this.playerTwo}`; + return p1 + p2; } } class Game { - constructor(courtId, team_1, team_2) { - this.courtId = courtId; - this.team_1 = team_1; - this.team_2 = team_2; + constructor(id, teamOne, teamTwo, status) { + this.id = id; + this.teamOne = teamOne; + this.teamTwo = teamTwo; + this.status = typeof status !== "undefined" ? status : false; } print() { - let team_1 = this.team_1.playerOne + " and " + this.team_1.playerTwo; - let team_2 = this.team_2.playerOne + " and " + this.team_2.playerTwo; - console.log(team_1 + " is playing against " + team_2); + 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 type = - this.team_1.playerOne === "RESERVED" ? `class="is-danger is-dark"` : ``; + this.teamOne.playerOne === "RESERVED" ? `class="is-danger is-dark"` : ``; return `${ - this.courtId + 1 - }${this.team_1.render()}${this.team_2.render()}`; + this.id + 1 + }${this.teamOne.render()}${this.teamTwo.render()}`; } } @@ -45,10 +49,13 @@ function generateDummyGames(courts, description) { } export class GameManager extends Manager { + courts = new CourtManager(); + players = new PlayerManager(); + constructor() { super("game", []); this.round = Number(localStorage.getItem("round")) || 0; - this.courts = new CourtManager(); + addLoadBehaviour(this.players); console.log("Loading game data."); let data = JSON.parse(localStorage.getItem(this.description)); if (data === null || data.length === 0) { @@ -57,117 +64,130 @@ export class GameManager extends Manager { return; } for (let i = 0; i < data.length; i++) { - let courtId = Number(data[i].courtId); + let id = Number(data[i].id); let teamOne = new Team( - data[i].team_1.playerOne, - data[i].team_1.playerTwo + data[i].teamOne.playerOne, + data[i].teamOne.playerTwo ); let teamTwo = new Team( - data[i].team_2.playerOne, - data[i].team_2.playerTwo + data[i].teamTwo.playerOne, + data[i].teamTwo.playerTwo ); - this.listData.push(new Game(courtId, teamOne, teamTwo)); + let status = Boolean(data[i].status); + this.listData.push(new Game(id, teamOne, teamTwo, status)); } console.log("Loaded " + this.listData.length + " games."); this.render(); this.addDescription(); } + 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(); this.addDescription(); } addDescription() { - let description = this.proposed ? "Proposal" : "Round " + this.round; + let description = this.isConfirmed() ? "Round " + this.round : "Proposal"; document.getElementById("game_description").innerHTML = description; } - propose(players) { - console.log("Proposing new games!"); - let possibleMatches = getMatchCount(players, this.courts.listData); - let requiredPlayers = possibleMatches * 4; - console.log("Required players are " + requiredPlayers); - const activeCourts = this.courts.listData.filter(function (c) { - return c.status; - }); - const inactiveCourts = this.courts.listData.filter(function (c) { - return !c.status; - }); - const activePlayers = players.filter(function (p) { - return p.status; - }); + getBlockedGames() { + const inactiveCourts = this.courts.inactive(); console.log("Total reserved courts are " + inactiveCourts.length + "."); - console.log("Total possible matches are " + possibleMatches + "."); - 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, requiredPlayers); - selectedPlayers.sort((a, b) => a.level - b.level); - console.log("Selected players are:"); - console.log( - selectedPlayers - .map((i) => { - return i.name; - }) - .join(",") - ); - console.log("The matches are:"); - this.listData = generateDummyGames( - activeCourts.slice(possibleMatches + 1), - "---" - ); - this.listData = this.listData.concat( - generateDummyGames(inactiveCourts, "RESERVED") - ); - for (let index = 0; index < possibleMatches; index++) { + 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 = selectedPlayers.slice(startIndex, endIndex); + 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(activeCourts[index].id, team_1, team_2); + const game = new Game(courts[index].id, team_1, team_2); game.print(); - this.listData.push(game); + games.push(game); } - this.listData.sort((a, b) => a.courtId - b.courtId); - this.proposed = true; + 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(); this.addDescription(); } confirm() { - this.proposed = false; + 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.addDescription(); 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, - }, - ], - }); + const notification = new Notyf(); notification.success("Round confirmed!"); } reset() { - localStorage.clear("round"); - localStorage.clear("round"); + 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(regulars, courts) { + const activeCourts = courts.filter(function (c) { + return c.status; + }); + console.log( + "There are a total of " + activeCourts.length + " courts available." + ); + console.log(regulars); + const activePlayers = regulars.filter(function (p) { + return p.status; + }); + console.log( + "There are a total of " + activePlayers.length + " players available." + ); + var possibleMatches = Math.floor(activePlayers.length / 4); + possibleMatches = + possibleMatches > activeCourts.length + ? activeCourts.length + : possibleMatches; + return possibleMatches; +} diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..655915f Binary files /dev/null and b/icon.png differ diff --git a/icon.svg b/icon.svg index d2700a4..278a070 100644 --- a/icon.svg +++ b/icon.svg @@ -1,5 +1,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -12,4 +40,15 @@ + + + + + + + + + + + diff --git a/index.html b/index.html index 35d1b15..b3f2f0a 100644 --- a/index.html +++ b/index.html @@ -13,9 +13,12 @@
-
-
-

- Match Up made with ❤️ by Karan. The source code is licensed CC BY-SA 4.0. -

-
-
+ \ No newline at end of file diff --git a/index.js b/index.js index 9f13cd8..9494abb 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,15 @@ import { GameManager } from "./game.mjs"; -import { PlayerManager, addLoadBehaviour } from "./player.mjs"; // Court and player handling let g = new GameManager(); -let p = new PlayerManager(); -addLoadBehaviour(p); // Game handling document.getElementById("propose").addEventListener("click", () => { - let factor = Number(document.getElementById("skill").value); - let players = p.normalize(factor); - console.log(players); - g.propose(players); + g.propose(); }); document.getElementById("confirm").addEventListener("click", () => { - console.log("Confirm the proposal for round " + g.round + "."); g.confirm(); }); document.getElementById("reset").addEventListener("click", () => { - console.log("Resetting the session!"); g.reset(); }); diff --git a/player.mjs b/player.mjs index d97ff42..4413d16 100644 --- a/player.mjs +++ b/player.mjs @@ -1,11 +1,11 @@ -import { Manager } from "./utils.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.status = typeof status !== "undefined" ? status : false; this.totalPlayed = typeof totalPlayed !== "undefined" ? status : 0; } toggle() { @@ -99,14 +99,43 @@ export class PlayerManager extends Manager { this.render(); this.addToggleBehaviour(); } - normalize(factor) { + active(factor) { + factor = typeof factor !== "undefined" ? factor : 1; + let data = super.active(); console.log("Normalize skill by a factor of " + factor + "."); - let players = this.listData.map(function (p) { + 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; + } } // Try to add this functionality inside the class to call after constructor diff --git a/timer.js b/timer.js index 207fb66..09189c0 100644 --- a/timer.js +++ b/timer.js @@ -19,7 +19,9 @@ function setSessionData() { function resetTimer() { clearInterval(clock); - setTimer(minsPerRound, 0); + let mins = Math.floor(minsPerRound); + let secs = (minsPerRound - mins) * 60; + setTimer(mins, secs); timerRunningFlag = 0; setSessionData(); } @@ -72,14 +74,14 @@ window.onload = function () { document.getElementById("timer-inc").addEventListener("click", () => { if (timerRunningFlag == 0) { - minsPerRound += 1; + minsPerRound += 0.5; resetTimer(); } }); document.getElementById("timer-dec").addEventListener("click", () => { if (timerRunningFlag == 0 && minsPerRound != 0) { - minsPerRound -= 1; + minsPerRound -= 0.5; resetTimer(); } }); diff --git a/utils.mjs b/utils.mjs index b8e5222..62569e4 100644 --- a/utils.mjs +++ b/utils.mjs @@ -29,28 +29,16 @@ export class Manager { }); } } -} - -export function getMatchCount(regulars, courts) { - const activeCourts = courts.filter(function (c) { - return c.status; - }); - console.log( - "There are a total of " + activeCourts.length + " courts available." - ); - console.log(regulars); - const activePlayers = regulars.filter(function (p) { - return p.status; - }); - console.log( - "There are a total of " + activePlayers.length + " players available." - ); - var possibleMatches = Math.floor(activePlayers.length / 4); - possibleMatches = - possibleMatches > activeCourts.length - ? activeCourts.length - : possibleMatches; - return possibleMatches; + active() { + return this.listData.filter(function (c) { + return c.status; + }); + } + inactive() { + return this.listData.filter(function (c) { + return !c.status; + }); + } } export function shuffle(array) { -- cgit v1.3.1 From 33c3c6d7dc89187c08ec0775bbad8aaccb85d086 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Thu, 13 Nov 2025 16:57:32 +0100 Subject: Only guests need to be implemented to merge to main --- .gitlab-ci.yml | 2 +- court.mjs | 9 ++++----- game.mjs | 44 ++++++++++++++++++-------------------------- player.mjs | 24 +++++++++--------------- utils.mjs | 3 ++- 5 files changed, 34 insertions(+), 48 deletions(-) (limited to '.gitlab-ci.yml') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3926782..4b220ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,4 @@ create-pages: before_script: - mkdir public script: - - cp index.html index.css icon.png *.js *.mjs public/ + - cp index.html index.css favicon.ico icon.png *.js *.mjs public/ diff --git a/court.mjs b/court.mjs index aa5bf29..713c488 100644 --- a/court.mjs +++ b/court.mjs @@ -15,9 +15,8 @@ class Court { console.log(this.name + " is currently " + status); } render() { - let type = this.status - ? `class="button is-medium is-success"` - : 'class="button is-medium is-danger"'; + let color = this.status ? "is-success" : "is-danger"; + let type = `class="button is-medium ${color}"`; return ``; } } @@ -39,7 +38,7 @@ export class CourtManager extends Manager { } console.log("Loaded " + this.listData.length + " courts."); this.render(); - this.addToggleBehaviour(); + this.addBehaviour(); } generate() { console.log("Generating court data."); @@ -49,6 +48,6 @@ export class CourtManager extends Manager { console.log("Generated data for " + this.listData.length + " courts"); this.store(); this.render(); - this.addToggleBehaviour(); + this.addBehaviour(); } } diff --git a/game.mjs b/game.mjs index 926d0eb..c67041f 100644 --- a/game.mjs +++ b/game.mjs @@ -1,6 +1,6 @@ import { Manager } from "./utils.mjs"; import { CourtManager } from "./court.mjs"; -import { PlayerManager, addLoadBehaviour } from "./player.mjs"; +import { PlayerManager } from "./player.mjs"; class Team { constructor(playerOne, playerTwo) { @@ -30,8 +30,8 @@ class Game { console.log(teamOne + " is playing against " + teamTwo); } render() { - let type = - this.teamOne.playerOne === "RESERVED" ? `class="is-danger is-dark"` : ``; + let blockedState = this.teamOne.playerOne === "RESERVED"; + let type = blockedState ? `class="is-danger is-dark"` : ``; return `${ this.id + 1 }${this.teamOne.render()}${this.teamTwo.render()}`; @@ -51,11 +51,10 @@ function generateDummyGames(courts, description) { export class GameManager extends Manager { courts = new CourtManager(); players = new PlayerManager(); - + constructor() { super("game", []); this.round = Number(localStorage.getItem("round")) || 0; - addLoadBehaviour(this.players); console.log("Loading game data."); let data = JSON.parse(localStorage.getItem(this.description)); if (data === null || data.length === 0) { @@ -78,7 +77,6 @@ export class GameManager extends Manager { } console.log("Loaded " + this.listData.length + " games."); this.render(); - this.addDescription(); } isConfirmed() { return this.listData[0].status; @@ -93,9 +91,8 @@ export class GameManager extends Manager { console.log(this.listData); this.store(); this.render(); - this.addDescription(); } - addDescription() { + addBehaviour() { let description = this.isConfirmed() ? "Round " + this.round : "Proposal"; document.getElementById("game_description").innerHTML = description; } @@ -123,7 +120,10 @@ export class GameManager extends Manager { } propose() { console.log("Proposing new games!"); - let possibleMatches = getMatchCount(this.players.listData, this.courts.listData); + 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(); @@ -138,7 +138,6 @@ export class GameManager extends Manager { ); this.listData.sort((a, b) => a.id - b.id); this.render(); - this.addDescription(); } confirm() { if (this.isConfirmed()) { @@ -154,7 +153,7 @@ export class GameManager extends Manager { } // Need to update the number of games played here this.store(); - this.addDescription(); + this.render(); document.getElementById("timer-start").click(); const notification = new Notyf(); notification.success("Round confirmed!"); @@ -170,24 +169,17 @@ export class GameManager extends Manager { } } -function getMatchCount(regulars, courts) { - const activeCourts = courts.filter(function (c) { +function getMatchCount(players, courts) { + courts = courts.filter(function (c) { return c.status; }); - console.log( - "There are a total of " + activeCourts.length + " courts available." - ); - console.log(regulars); - const activePlayers = regulars.filter(function (p) { + 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 " + activePlayers.length + " players available." - ); - var possibleMatches = Math.floor(activePlayers.length / 4); - possibleMatches = - possibleMatches > activeCourts.length - ? activeCourts.length - : possibleMatches; + 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/player.mjs b/player.mjs index 4413d16..a8d4cb7 100644 --- a/player.mjs +++ b/player.mjs @@ -14,18 +14,11 @@ class Player { } print() { let status = this.status ? "active" : "inactive"; - console.log( - this.name + - " has a level of " + - this.level + - " and is currently " + - status - ); + console.log(this.name + " is currently " + status); } render() { - let type = this.status - ? `class="button is-medium is-success"` - : 'class="button is-medium is-danger"'; + let color = this.status ? "is-success" : "is-danger"; + let type = `class="button is-medium ${color}"`; return ``; } } @@ -67,7 +60,8 @@ export class PlayerManager extends Manager { } console.log("Loaded " + this.listData.length + " players."); this.render(); - this.addToggleBehaviour(); + this.addBehaviour(); + addLoadBehaviour(this); } generate() { console.log("Generating player data."); @@ -79,7 +73,7 @@ export class PlayerManager extends Manager { console.log("Generated data for " + this.listData.length + " players"); this.store(); this.render(); - this.addToggleBehaviour(); + this.addBehaviour(); } import(data) { var lines = data.split("\n"); @@ -97,7 +91,7 @@ export class PlayerManager extends Manager { this.listData = players; this.store(); this.render(); - this.addToggleBehaviour(); + this.addBehaviour(); } active(factor) { factor = typeof factor !== "undefined" ? factor : 1; @@ -112,7 +106,7 @@ export class PlayerManager extends Manager { propose(count) { console.log("Required players are " + count); let factor = Number(document.getElementById("skill").value); - console.log("Skill normalized by a factor of " + factor + "."); + console.log("Skill normalized by a factor of " + factor + "."); const activePlayers = this.active(factor); console.log("Active players are:"); console.log( @@ -138,7 +132,7 @@ export class PlayerManager extends Manager { } } -// Try to add this functionality inside the class to call after constructor +// TODO Add load behaviour to constructor export function addLoadBehaviour(p) { const f = document.querySelector("#player-load input[type=file]"); f.addEventListener("change", () => { diff --git a/utils.mjs b/utils.mjs index 62569e4..06a2519 100644 --- a/utils.mjs +++ b/utils.mjs @@ -16,8 +16,9 @@ export class Manager { .join(""); let elementId = this.description + "_list"; document.getElementById(elementId).innerHTML = renderedHTML; + this.addBehaviour(); } - addToggleBehaviour() { + addBehaviour() { for (let idx = 0; idx < this.listData.length; ++idx) { const elementId = this.description + "_" + this.listData[idx].id; const p = document.getElementById(elementId); -- cgit v1.3.1 From 8a05236fea86f0a9214798193c652b1b09674565 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Thu, 13 Nov 2025 22:04:06 +0100 Subject: Updated the CI to match npm --- .gitlab-ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to '.gitlab-ci.yml') diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4b220ca..eded231 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,7 @@ -# The Docker image that will be used to build your app image: node:lts create-pages: pages: - publish: public - before_script: - - mkdir public + publish: dist script: - - cp index.html index.css favicon.ico icon.png *.js *.mjs public/ + - npm install + - npm run build \ No newline at end of file -- cgit v1.3.1