diff options
| -rw-r--r-- | .gitlab-ci.yml | 2 | ||||
| -rw-r--r-- | assets/icon.ipe | 461 | ||||
| -rw-r--r-- | game.mjs | 188 | ||||
| -rw-r--r-- | icon.png | bin | 0 -> 1453 bytes | |||
| -rw-r--r-- | icon.svg | 41 | ||||
| -rw-r--r-- | index.html | 23 | ||||
| -rw-r--r-- | index.js | 10 | ||||
| -rw-r--r-- | player.mjs | 37 | ||||
| -rw-r--r-- | timer.js | 8 | ||||
| -rw-r--r-- | utils.mjs | 32 |
10 files changed, 207 insertions, 595 deletions
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 @@ -<?xml version="1.0"?> -<!DOCTYPE ipe SYSTEM "ipe.dtd"> -<ipe version="70218" creator="Ipe 7.2.29"> -<info created="D:20251109135743" modified="D:20251109135745"/> -<ipestyle name="basic"> -<symbol name="arrow/arc(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0 0 m --1 0.333 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/farc(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0 0 m --1 0.333 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/ptarc(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/fptarc(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="mark/circle(sx)" transformations="translations"> -<path fill="sym-stroke"> -0.6 0 0 0.6 0 0 e -0.4 0 0 0.4 0 0 e -</path> -</symbol> -<symbol name="mark/disk(sx)" transformations="translations"> -<path fill="sym-stroke"> -0.6 0 0 0.6 0 0 e -</path> -</symbol> -<symbol name="mark/fdisk(sfx)" transformations="translations"> -<group> -<path fill="sym-fill"> -0.5 0 0 0.5 0 0 e -</path> -<path fill="sym-stroke" fillrule="eofill"> -0.6 0 0 0.6 0 0 e -0.4 0 0 0.4 0 0 e -</path> -</group> -</symbol> -<symbol name="mark/box(sx)" transformations="translations"> -<path fill="sym-stroke" fillrule="eofill"> --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 -</path> -</symbol> -<symbol name="mark/square(sx)" transformations="translations"> -<path fill="sym-stroke"> --0.6 -0.6 m -0.6 -0.6 l -0.6 0.6 l --0.6 0.6 l -h -</path> -</symbol> -<symbol name="mark/fsquare(sfx)" transformations="translations"> -<group> -<path fill="sym-fill"> --0.5 -0.5 m -0.5 -0.5 l -0.5 0.5 l --0.5 0.5 l -h -</path> -<path fill="sym-stroke" fillrule="eofill"> --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 -</path> -</group> -</symbol> -<symbol name="mark/cross(sx)" transformations="translations"> -<group> -<path fill="sym-stroke"> --0.43 -0.57 m -0.57 0.43 l -0.43 0.57 l --0.57 -0.43 l -h -</path> -<path fill="sym-stroke"> --0.43 0.57 m -0.57 -0.43 l -0.43 -0.57 l --0.57 0.43 l -h -</path> -</group> -</symbol> -<symbol name="arrow/fnormal(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0 0 m --1 0.333 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/pointed(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/fpointed(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0 0 m --1 0.333 l --0.8 0 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/linear(spx)"> -<path stroke="sym-stroke" pen="sym-pen"> --1 0.333 m -0 0 l --1 -0.333 l -</path> -</symbol> -<symbol name="arrow/fdouble(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0 0 m --1 0.333 l --1 -0.333 l -h --1 0 m --2 0.333 l --2 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/double(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0 0 m --1 0.333 l --1 -0.333 l -h --1 0 m --2 0.333 l --2 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-normal(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0.5 0 m --0.5 0.333 l --0.5 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-fnormal(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0.5 0 m --0.5 0.333 l --0.5 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-pointed(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -0.5 0 m --0.5 0.333 l --0.3 0 l --0.5 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-fpointed(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -0.5 0 m --0.5 0.333 l --0.3 0 l --0.5 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-double(spx)"> -<path stroke="sym-stroke" fill="sym-stroke" pen="sym-pen"> -1 0 m -0 0.333 l -0 -0.333 l -h -0 0 m --1 0.333 l --1 -0.333 l -h -</path> -</symbol> -<symbol name="arrow/mid-fdouble(spx)"> -<path stroke="sym-stroke" fill="white" pen="sym-pen"> -1 0 m -0 0.333 l -0 -0.333 l -h -0 0 m --1 0.333 l --1 -0.333 l -h -</path> -</symbol> -<anglesize name="22.5 deg" value="22.5"/> -<anglesize name="30 deg" value="30"/> -<anglesize name="45 deg" value="45"/> -<anglesize name="60 deg" value="60"/> -<anglesize name="90 deg" value="90"/> -<arrowsize name="large" value="10"/> -<arrowsize name="small" value="5"/> -<arrowsize name="tiny" value="3"/> -<color name="blue" value="0 0 1"/> -<color name="brown" value="0.647 0.165 0.165"/> -<color name="darkblue" value="0 0 0.545"/> -<color name="darkcyan" value="0 0.545 0.545"/> -<color name="darkgray" value="0.663"/> -<color name="darkgreen" value="0 0.392 0"/> -<color name="darkmagenta" value="0.545 0 0.545"/> -<color name="darkorange" value="1 0.549 0"/> -<color name="darkred" value="0.545 0 0"/> -<color name="gold" value="1 0.843 0"/> -<color name="gray" value="0.745"/> -<color name="green" value="0 1 0"/> -<color name="lightblue" value="0.678 0.847 0.902"/> -<color name="lightcyan" value="0.878 1 1"/> -<color name="lightgray" value="0.827"/> -<color name="lightgreen" value="0.565 0.933 0.565"/> -<color name="lightyellow" value="1 1 0.878"/> -<color name="navy" value="0 0 0.502"/> -<color name="orange" value="1 0.647 0"/> -<color name="pink" value="1 0.753 0.796"/> -<color name="purple" value="0.627 0.125 0.941"/> -<color name="red" value="1 0 0"/> -<color name="seagreen" value="0.18 0.545 0.341"/> -<color name="turquoise" value="0.251 0.878 0.816"/> -<color name="violet" value="0.933 0.51 0.933"/> -<color name="yellow" value="1 1 0"/> -<dashstyle name="dash dot dotted" value="[4 2 1 2 1 2] 0"/> -<dashstyle name="dash dotted" value="[4 2 1 2] 0"/> -<dashstyle name="dashed" value="[4] 0"/> -<dashstyle name="dotted" value="[1 3] 0"/> -<gridsize name="10 pts (~3.5 mm)" value="10"/> -<gridsize name="14 pts (~5 mm)" value="14"/> -<gridsize name="16 pts (~6 mm)" value="16"/> -<gridsize name="20 pts (~7 mm)" value="20"/> -<gridsize name="28 pts (~10 mm)" value="28"/> -<gridsize name="32 pts (~12 mm)" value="32"/> -<gridsize name="4 pts" value="4"/> -<gridsize name="56 pts (~20 mm)" value="56"/> -<gridsize name="8 pts (~3 mm)" value="8"/> -<opacity name="10%" value="0.1"/> -<opacity name="30%" value="0.3"/> -<opacity name="50%" value="0.5"/> -<opacity name="75%" value="0.75"/> -<pen name="fat" value="1.2"/> -<pen name="heavier" value="0.8"/> -<pen name="ultrafat" value="2"/> -<symbolsize name="large" value="5"/> -<symbolsize name="small" value="2"/> -<symbolsize name="tiny" value="1.1"/> -<textsize name="Huge" value="\Huge"/> -<textsize name="LARGE" value="\LARGE"/> -<textsize name="Large" value="\Large"/> -<textsize name="footnote" value="\footnotesize"/> -<textsize name="huge" value="\huge"/> -<textsize name="large" value="\large"/> -<textsize name="script" value="\scriptsize"/> -<textsize name="small" value="\small"/> -<textsize name="tiny" value="\tiny"/> -<textstyle name="center" begin="\begin{center}" end="\end{center}"/> -<textstyle name="item" begin="\begin{itemize}\item{}" end="\end{itemize}"/> -<textstyle name="itemize" begin="\begin{itemize}" end="\end{itemize}"/> -<tiling name="falling" angle="-60" step="4" width="1"/> -<tiling name="rising" angle="30" step="4" width="1"/> -</ipestyle> -<page> -<layer name="alpha"/> -<view layers="alpha" active="alpha"/> -<path layer="alpha" matrix="1 0 -0.0833333 1 -8 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 0.25 1 -216 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 0.166667 1 -164 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 0 1 -60 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="0.999999 -0.00001629 0.0833496 1 -112.01 208.002" stroke="black" fill="white"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 0.0833333 1 -112 208" stroke="black" fill="white"> -92 620 m -4 0 0 -4 96 620 100 620 a -100 616 l -92 616 l -h -</path> -<path matrix="1 0 0.0833337 1 -100 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 -0.25 1 108 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 -0.00000003 1 -48 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 -0.166667 1 56 208" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 -0.00001629 -0.083317 1 3.9901 208.002" stroke="black" fill="1"> -96 624 m -92 612 -88 600 -92 588 -96 576 c -96 576 -100 588 -104 600 -100 612 -96 624 c -h -</path> -<path matrix="1 0 -0.0833333 1 4 208" stroke="black" fill="white"> -92 620 m -4 0 0 -4 96 620 100 620 a -100 616 l -92 616 l -h -</path> -</page> -</ipe> @@ -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 `<td style="width: 23%; text-align: right;">${this.playerOne}</td><td style="width: 23%; text-align: left;">${this.playerTwo}</td>`; + let p1 = `<td style="width: 23%; text-align: right;">${this.playerOne}</td>`; + let p2 = `<td style="width: 23%; text-align: right;">${this.playerTwo}</td>`; + 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 `<tr ${type}><td style="width: 8%; text-align: center;">${ - this.courtId + 1 - }</td>${this.team_1.render()}${this.team_2.render()}</tr>`; + this.id + 1 + }</td>${this.teamOne.render()}${this.teamTwo.render()}</tr>`; } } @@ -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 Binary files differnew file mode 100644 index 0000000..655915f --- /dev/null +++ b/icon.png @@ -1,5 +1,33 @@ <?xml version="1.0" encoding="UTF-8"?> -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="40" height="50" viewBox="0 0 40 50"> +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="187" height="50" viewBox="0 0 187 50"> +<defs> +<g> +<g id="glyph-0-0"> +<path d="M 5.171875 -16.53125 C 5.03125 -16.90625 5 -16.921875 4.484375 -16.921875 L 1.3125 -16.921875 L 1.3125 -16.28125 C 3.015625 -16.28125 3.296875 -16.28125 3.296875 -15.171875 L 3.296875 -2.421875 C 3.296875 -1.8125 3.296875 -0.640625 1.3125 -0.640625 L 1.3125 0 C 1.890625 -0.046875 2.921875 -0.046875 3.546875 -0.046875 C 4.15625 -0.046875 5.203125 -0.046875 5.78125 0 L 5.78125 -0.640625 C 3.796875 -0.640625 3.796875 -1.8125 3.796875 -2.421875 L 3.796875 -16.1875 L 3.8125 -16.1875 L 9.640625 -0.390625 C 9.734375 -0.15625 9.78125 0 9.984375 0 C 10.1875 0 10.234375 -0.15625 10.328125 -0.390625 L 16.203125 -16.3125 L 16.234375 -16.3125 L 16.234375 -1.765625 C 16.234375 -0.640625 15.953125 -0.640625 14.25 -0.640625 L 14.25 0 C 14.921875 -0.046875 16.25 -0.046875 16.96875 -0.046875 C 17.6875 -0.046875 19.0625 -0.046875 19.71875 0 L 19.71875 -0.640625 C 18.015625 -0.640625 17.75 -0.640625 17.75 -1.765625 L 17.75 -15.171875 C 17.75 -16.28125 18.015625 -16.28125 19.71875 -16.28125 L 19.71875 -16.921875 L 16.578125 -16.921875 C 16.0625 -16.921875 16.03125 -16.90625 15.890625 -16.53125 L 10.53125 -2 Z M 5.171875 -16.53125 "/> +</g> +<g id="glyph-0-1"> +<path d="M 9 -17.125 C 8.875 -17.453125 8.828125 -17.515625 8.578125 -17.515625 C 8.328125 -17.515625 8.28125 -17.453125 8.15625 -17.125 L 2.90625 -2.25 C 2.421875 -0.921875 1.4375 -0.640625 0.5625 -0.640625 L 0.5625 0 C 1.015625 -0.046875 2 -0.046875 2.484375 -0.046875 C 3.09375 -0.046875 4.09375 -0.046875 4.6875 0 L 4.6875 -0.640625 C 3.515625 -0.6875 3.34375 -1.484375 3.34375 -1.78125 C 3.34375 -2 3.390625 -2.125 3.4375 -2.28125 L 4.765625 -5.96875 L 11.25 -5.96875 L 12.734375 -1.765625 C 12.859375 -1.46875 12.859375 -1.40625 12.859375 -1.3125 C 12.859375 -0.640625 11.796875 -0.640625 11.328125 -0.640625 L 11.328125 0 C 12.046875 -0.046875 13.328125 -0.046875 14.09375 -0.046875 C 14.75 -0.046875 15.984375 -0.046875 16.578125 0 L 16.578125 -0.640625 C 15.265625 -0.640625 14.8125 -0.640625 14.5 -1.5625 Z M 8 -15.140625 L 11.03125 -6.609375 L 4.984375 -6.609375 Z M 8 -15.140625 "/> +</g> +<g id="glyph-0-2"> +<path d="M 15.40625 -16.84375 L 1.109375 -16.84375 L 0.6875 -11.375 L 1.140625 -11.375 C 1.46875 -15.484375 1.8125 -16.203125 5.625 -16.203125 C 6.078125 -16.203125 6.796875 -16.203125 6.984375 -16.1875 C 7.453125 -16.109375 7.453125 -15.8125 7.453125 -15.234375 L 7.453125 -1.8125 C 7.453125 -0.921875 7.390625 -0.640625 5.328125 -0.640625 L 4.640625 -0.640625 L 4.640625 0 C 5.828125 -0.03125 7.0625 -0.046875 8.28125 -0.046875 C 9.484375 -0.046875 10.734375 -0.03125 11.921875 0 L 11.921875 -0.640625 L 11.21875 -0.640625 C 9.171875 -0.640625 9.09375 -0.921875 9.09375 -1.8125 L 9.09375 -15.234375 C 9.09375 -15.78125 9.09375 -16.078125 9.546875 -16.1875 C 9.734375 -16.203125 10.453125 -16.203125 10.90625 -16.203125 C 14.6875 -16.203125 15.0625 -15.484375 15.390625 -11.375 L 15.828125 -11.375 Z M 15.40625 -16.84375 "/> +</g> +<g id="glyph-0-3"> +<path d="M 15.390625 -16.828125 C 15.390625 -17.265625 15.359375 -17.296875 15.21875 -17.296875 C 15.109375 -17.296875 15.09375 -17.265625 14.921875 -16.96875 L 13.828125 -14.890625 C 12.609375 -16.4375 11.125 -17.328125 9.21875 -17.328125 C 4.984375 -17.328125 1.140625 -13.578125 1.140625 -8.46875 C 1.140625 -3.328125 4.984375 0.390625 9.25 0.390625 C 13.03125 0.390625 15.390625 -2.953125 15.390625 -5.796875 C 15.390625 -6.046875 15.390625 -6.140625 15.171875 -6.140625 C 14.96875 -6.140625 14.96875 -6.078125 14.9375 -5.84375 C 14.75 -2.375 12.265625 -0.25 9.59375 -0.25 C 7.0625 -0.25 3.015625 -2.03125 3.015625 -8.46875 C 3.015625 -14.9375 7.140625 -16.671875 9.546875 -16.671875 C 12.34375 -16.671875 14.375 -14.25 14.84375 -10.796875 C 14.890625 -10.5 14.890625 -10.453125 15.109375 -10.453125 C 15.390625 -10.453125 15.390625 -10.5 15.390625 -10.953125 Z M 15.390625 -16.828125 "/> +</g> +<g id="glyph-0-4"> +<path d="M 13.90625 -15.171875 C 13.90625 -16.28125 14.171875 -16.28125 15.890625 -16.28125 L 15.890625 -16.921875 C 15.171875 -16.875 13.859375 -16.875 13.078125 -16.875 C 12.3125 -16.875 11 -16.875 10.28125 -16.921875 L 10.28125 -16.28125 C 12 -16.28125 12.265625 -16.28125 12.265625 -15.171875 L 12.265625 -9.125 L 4.875 -9.125 L 4.875 -15.171875 C 4.875 -16.28125 5.15625 -16.28125 6.859375 -16.28125 L 6.859375 -16.921875 C 6.140625 -16.875 4.828125 -16.875 4.0625 -16.875 C 3.296875 -16.875 1.984375 -16.875 1.265625 -16.921875 L 1.265625 -16.28125 C 2.96875 -16.28125 3.25 -16.28125 3.25 -15.171875 L 3.25 -1.765625 C 3.25 -0.640625 2.96875 -0.640625 1.265625 -0.640625 L 1.265625 0 C 1.984375 -0.046875 3.296875 -0.046875 4.0625 -0.046875 C 4.828125 -0.046875 6.140625 -0.046875 6.859375 0 L 6.859375 -0.640625 C 5.15625 -0.640625 4.875 -0.640625 4.875 -1.765625 L 4.875 -8.46875 L 12.265625 -8.46875 L 12.265625 -1.765625 C 12.265625 -0.640625 12 -0.640625 10.28125 -0.640625 L 10.28125 0 C 11 -0.046875 12.3125 -0.046875 13.078125 -0.046875 C 13.859375 -0.046875 15.171875 -0.046875 15.890625 0 L 15.890625 -0.640625 C 14.171875 -0.640625 13.90625 -0.640625 13.90625 -1.765625 Z M 13.90625 -15.171875 "/> +</g> +<g id="glyph-0-5"> +<path d="M 13.375 -5.671875 C 13.375 -2.359375 11.21875 -0.25 8.875 -0.25 C 7.609375 -0.25 6.46875 -0.921875 5.78125 -1.953125 C 4.984375 -3.140625 4.875 -4.6875 4.875 -5.546875 L 4.875 -15.171875 C 4.875 -16.28125 5.15625 -16.28125 6.859375 -16.28125 L 6.859375 -16.921875 C 6.140625 -16.875 4.828125 -16.875 4.0625 -16.875 C 3.296875 -16.875 1.984375 -16.875 1.265625 -16.921875 L 1.265625 -16.28125 C 2.96875 -16.28125 3.25 -16.28125 3.25 -15.171875 L 3.25 -5.671875 C 3.25 -2.109375 5.953125 0.390625 8.828125 0.390625 C 12.046875 0.390625 13.90625 -2.90625 13.90625 -5.328125 L 13.90625 -14.75 C 13.90625 -16.125 15.171875 -16.28125 15.890625 -16.28125 L 15.890625 -16.921875 C 15.3125 -16.875 14.28125 -16.875 13.65625 -16.875 C 13.03125 -16.875 11.96875 -16.875 11.40625 -16.921875 L 11.40625 -16.28125 C 13.375 -16.28125 13.375 -15.109375 13.375 -14.5 Z M 13.375 -5.671875 "/> +</g> +<g id="glyph-0-6"> +<path d="M 4.90625 -7.953125 L 8.875 -7.953125 C 12.0625 -7.953125 14.390625 -10.03125 14.390625 -12.390625 C 14.390625 -14.75 12.125 -16.921875 8.875 -16.921875 L 1.28125 -16.921875 L 1.28125 -16.28125 C 3 -16.28125 3.265625 -16.28125 3.265625 -15.171875 L 3.265625 -1.765625 C 3.265625 -0.640625 3 -0.640625 1.28125 -0.640625 L 1.28125 0 C 2 -0.046875 3.328125 -0.046875 4.09375 -0.046875 C 4.859375 -0.046875 6.171875 -0.046875 6.890625 0 L 6.890625 -0.640625 C 5.171875 -0.640625 4.90625 -0.640625 4.90625 -1.765625 Z M 4.859375 -8.46875 L 4.859375 -15.3125 C 4.859375 -16.15625 4.90625 -16.28125 5.890625 -16.28125 L 8.40625 -16.28125 C 11.59375 -16.28125 12.515625 -14.453125 12.515625 -12.390625 C 12.515625 -10.140625 11.421875 -8.46875 8.40625 -8.46875 Z M 4.859375 -8.46875 "/> +</g> +</g> +<clipPath id="clip-0"> +<path clip-rule="nonzero" d="M 59 16.535156 L 185 16.535156 L 185 33.46875 L 59 33.46875 Z M 59 16.535156 "/> +</clipPath> +</defs> <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 36 832 C 33 820 31.5 814 32 808 C 32.5 802 35 796 40 784 C 40 784 41.5 790 42.75 795 C 44 800 45 804 44.25 809 C 43.5 814 41 820 36 832 Z M 36 832 " transform="matrix(1, 0, 0, -1, -22, 833)"/> <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 36 832 C 29 820 25.5 814 24 808 C 22.5 802 23 796 24 784 C 24 784 27.5 790 30.417969 795 C 33.332031 800 35.667969 804 36.582031 809 C 37.5 814 37 820 36 832 Z M 36 832 " transform="matrix(1, 0, 0, -1, -22, 833)"/> <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 36 832 C 30 820 27 814 26 808 C 25 802 26 796 28 784 C 28 784 31 790 33.5 795 C 36 800 38 804 38.5 809 C 39 814 38 820 36 832 Z M 36 832 " transform="matrix(1, 0, 0, -1, -22, 833)"/> @@ -12,4 +40,15 @@ <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 48 832 C 46 820 45 814 46 808 C 47 802 50 796 56 784 C 56 784 57 790 57.832031 795 C 58.667969 800 59.332031 804 58.167969 809 C 57 814 54 820 48 832 Z M 48 832 " transform="matrix(1, 0, 0, -1, -22, 833)"/> <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 48 832 C 45 820 43.5 814 44 808 C 44.5 802 47 796 52 784 C 52 784 53.5 790 54.75 795 C 56 800 57 804 56.25 809 C 55.5 814 53 820 48 832 Z M 48 832 " transform="matrix(1, 0, 0, -1, -22, 833)"/> <path fill-rule="evenodd" fill="rgb(100%, 100%, 100%)" fill-opacity="1" stroke-width="0.4" stroke-linecap="butt" stroke-linejoin="round" stroke="rgb(0%, 0%, 0%)" stroke-opacity="1" stroke-miterlimit="10" d="M 44.332031 828 C 43.890625 833.332031 51.890625 833.332031 52.332031 828 L 52.667969 824 L 44.667969 824 Z M 44.332031 828 " transform="matrix(1, 0, 0, -1, -22, 833)"/> +<g clip-path="url(#clip-0)"> +<g fill="rgb(0%, 0%, 0%)" fill-opacity="1"> +<use xlink:href="#glyph-0-0" x="58.5835" y="33.467"/> +<use xlink:href="#glyph-0-1" x="79.652535" y="33.467"/> +<use xlink:href="#glyph-0-2" x="94.896602" y="33.467"/> +<use xlink:href="#glyph-0-3" x="111.429597" y="33.467"/> +<use xlink:href="#glyph-0-4" x="127.962593" y="33.467"/> +<use xlink:href="#glyph-0-5" x="152.625757" y="33.467"/> +<use xlink:href="#glyph-0-6" x="169.803218" y="33.467"/> +</g> +</g> </svg> @@ -13,9 +13,12 @@ <section class="section"> <nav class="navbar" role="navigation" aria-label="main navigation"> <div class="navbar-brand"> - <a class="navbar-item" href="https://bulma.io"> - <img src="icon.svg" style="height: 80%;"> Match Up - </a> + <div class="navbar-item"> + <img src="icon.png"> + </div> + <div class="navbar-item"> + Match Up + </div> </div> <div class="navbar-end"> <div class="field is-grouped is-grouped-right"> @@ -85,15 +88,15 @@ </section> </div> </section> - <footer class="footer"> - <div class="content has-text-centered"> - <p> - <strong>Match Up</strong> made with ❤️ by <a href="https://karanj.com">Karan</a>. The source code is licensed <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">CC BY-SA 4.0</a>. - </p> - </div> - </footer> <script src="index.js" type="module"></script> <script src="timer.js"></script> <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script> </body> + <footer class="footer"> + <div class="content has-text-centered"> + <p> + <strong>Match Up</strong> made with ❤️ by <a href="https://karanj.com">Karan</a>. The source code is licensed <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">CC BY-SA 4.0</a>. Logo from <a href="https://www.flaticon.com/free-icons/shuttle-cock" title="shuttle cock icons">Flaticon</a>. + </p> + </div> + </footer> </html>
\ No newline at end of file @@ -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(); }); @@ -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 @@ -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(); } }); @@ -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) { |
