aboutsummaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorKaran Jayachandra <me@karanj.com>2025-11-16 16:18:48 +0100
committerKaran Jayachandra <me@karanj.com>2025-11-16 16:18:48 +0100
commit34ad81f7aeaa44437ea6f42ac9159d6a8612ad6c (patch)
treefcfc212a79e3e34b0e0bdfcc4cca7fb05f65123e /src/main.js
parent63c405504466bdadb64dfb3017bbfa942d7330f3 (diff)
parent2e323bf7c20cc59a8d2017517b14d615344c5863 (diff)
Merge branch 'develop' into 'main'
Develop See merge request KaranJayachandra/match_up!23
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/main.js b/src/main.js
index ec33b18..59f66d0 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,19 +1,8 @@
-import "notyf/notyf.min.css";
-import "bulma/css/bulma.css";
-import "@fortawesome/fontawesome-free/css/all.css";
-import "./style.css";
-import { Notyf } from "notyf";
+import "./style.css"
import { Timer } from "./timer";
-import { Team, Game } from "./data";
+import { Team, Game, Regular } from "./data";
import { Manager, CourtManager, RegularManager, GuestManager } from "./manage";
-export function getNotifier(seconds) {
- return new Notyf({
- duration: seconds * milliSecond,
- position: { x: "center", y: "top" },
- dismissible: true,
- });
-}
export class GameManager extends Manager {
timer = new Timer();
@@ -27,12 +16,17 @@ export class GameManager extends Manager {
this.render();
addGameBehaviour(this);
}
- createItem(i, description) {
+ createItem(i, description, status) {
if (typeof description === "undefined") {
description = "---";
}
- let team = new Team(description, description);
- return new Game(i, true, team, team);
+ if (typeof status === "undefined") {
+ status = true;
+ }
+ let player = new Regular(null, null, null, null, description, "");
+ console.log(player);
+ let team = new Team(player, player);
+ return new Game(i, status, team, team);
}
loadItem(data) {
let id = Number(data.id);
@@ -44,20 +38,20 @@ export class GameManager extends Manager {
addBehaviour() {
let confirmedStatus = this.data[0].status;
let description = confirmedStatus ? "Round " + this.round : "Proposal";
- document.getElementById("Game_description").innerHTML = description;
+ document.getElementById("Game-description").innerHTML = description;
}
addBlockedGames() {
const inactiveCourts = this.courts.inactive();
console.log("Total reserved courts are " + inactiveCourts.length + ".");
for (let court of inactiveCourts) {
- this.data.push(this.createItem(court.id, "RESERVED"));
+ this.data.push(this.createItem(court.id, "RESERVED", false));
}
}
addInactiveGames(possibleMatches) {
const activeCourts = this.courts.active();
const unusedCourts = activeCourts.slice(possibleMatches + 1);
for (let court of unusedCourts) {
- this.data.push(this.createItem(court.id));
+ this.data.push(this.createItem(court.id, "---", false));
}
}
addActiveGames(possibleMatches) {
@@ -69,8 +63,8 @@ export class GameManager extends Manager {
const startIndex = 4 * index;
const endIndex = startIndex + 4;
const courtPlayers = selectedPlayers.slice(startIndex, endIndex);
- const teamOne = new Team(courtPlayers[0].name, courtPlayers[3].name);
- const teamTwo = new Team(courtPlayers[1].name, courtPlayers[2].name);
+ const teamOne = new Team(courtPlayers[0], courtPlayers[3]);
+ const teamTwo = new Team(courtPlayers[1], courtPlayers[2]);
const game = new Game(usedCourts[index].id, false, teamOne, teamTwo);
this.data.push(game);
}
@@ -98,7 +92,7 @@ export class GameManager extends Manager {
p.print();
});
const shuffledPlayers = shuffle(activePlayers);
- shuffledPlayers.sort((a, b) => a.totalPlayed - b.totalPlayed);
+ shuffledPlayers.sort((a, b) => a.games - b.games);
const selectedPlayers = shuffledPlayers.slice(0, count);
selectedPlayers.sort((a, b) => a.level - b.level);
console.log("Selected players are:");
@@ -125,7 +119,6 @@ export class GameManager extends Manager {
confirm() {
let confirmedStatus = this.data[0].status;
if (confirmedStatus) {
- getNotifier().error("Create a proposal first!");
return;
}
console.log("Confirm the proposal for round " + this.round + ".");
@@ -134,7 +127,18 @@ export class GameManager extends Manager {
for (let i = 0; i < this.data.length; i++) {
this.data[i].status = true;
}
- // Increment the number of games played
+ let selectedPlayers = [];
+ for (let game of this.data) {
+ console.log(game);
+ if ( game.teamOne.playerOne.name !== "RESERVED" ){
+ selectedPlayers.push(game.teamOne.playerOne.name);
+ selectedPlayers.push(game.teamOne.playerTwo.name);
+ selectedPlayers.push(game.teamTwo.playerOne.name);
+ selectedPlayers.push(game.teamTwo.playerTwo.name);
+ }
+ }
+ this.regulars.incrementGames(selectedPlayers);
+ this.guests.incrementGames(selectedPlayers);
this.store();
this.render();
document.getElementById("timer-start").click();
@@ -144,7 +148,7 @@ export class GameManager extends Manager {
localStorage.removeItem(this.description);
localStorage.removeItem(this.courts.description);
localStorage.removeItem(this.guests.description);
- // Clear the number of games played
+ this.regulars.reset();
document.getElementById("timer-stop").click();
window.location.reload();
}
@@ -164,12 +168,11 @@ function addGameBehaviour(g) {
});
document.getElementById("confirm").addEventListener("click", () => {
g.confirm();
- getNotifier().success("Round confirmed!");
});
document.getElementById("reset").addEventListener("click", () => {
g.reset();
- getNotifier().error("Session has been reset!");
});
}
const g = new GameManager();
+