From cabac66d56e8912941cef976d69a4fd3ec9ad928 Mon Sep 17 00:00:00 2001 From: Karan Jayachandra Date: Sat, 15 Nov 2025 14:30:38 +0100 Subject: Working on improving tables --- src/data.js | 9 ++++---- src/main.js | 73 ++++++++++++++++++++++++++--------------------------------- src/manage.js | 4 ++-- src/style.css | 7 +++++- 4 files changed, 45 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/data.js b/src/data.js index 4358ee6..589b5a3 100644 --- a/src/data.js +++ b/src/data.js @@ -45,7 +45,7 @@ const guestCategories = { }; export class Guest extends Switch { - maxCount = 4; + maxCount = 6; categoryCount = 3; constructor(id, status, games) { @@ -82,14 +82,15 @@ export class Game extends Switch { this.teamTwo = teamTwo; } print() { - super.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); + console.log( + "Game " + this.id + ": " + teamOne + " is playing against " + teamTwo + ); } render() { let blockedState = this.teamOne.playerOne === "RESERVED"; - let type = blockedState ? `class="is-danger is-dark"` : ``; + let type = blockedState ? `class="is-dark"` : ``; let court = `${ this.id + 1 }`; diff --git a/src/main.js b/src/main.js index cb7ec8e..ec33b18 100644 --- a/src/main.js +++ b/src/main.js @@ -5,7 +5,7 @@ import "./style.css"; import { Notyf } from "notyf"; import { Timer } from "./timer"; import { Team, Game } from "./data"; -import { Manager, CourtManager, PlayerManager, GuestManager } from "./manage"; +import { Manager, CourtManager, RegularManager, GuestManager } from "./manage"; export function getNotifier(seconds) { return new Notyf({ @@ -18,7 +18,7 @@ export function getNotifier(seconds) { export class GameManager extends Manager { timer = new Timer(); courts = new CourtManager(); - players = new PlayerManager(); + regulars = new RegularManager(); guests = new GuestManager(); constructor() { @@ -53,34 +53,35 @@ export class GameManager extends Manager { this.data.push(this.createItem(court.id, "RESERVED")); } } - addInactiveGames(courts) { - for (let court of courts) { + 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)); } } - addActiveGames(courts, players) { - for (let index = 0; index < courts.length; index++) { + addActiveGames(possibleMatches) { + const activeCourts = this.courts.active(); + const usedCourts = activeCourts.slice(0, possibleMatches); + let requiredPlayerCount = possibleMatches * 4; + const selectedPlayers = this.selectPlayers(requiredPlayerCount); + for (let index = 0; index < usedCourts.length; index++) { const startIndex = 4 * index; const endIndex = startIndex + 4; - const courtPlayers = players.slice(startIndex, endIndex); + 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 game = new Game(courts[index].id, false, teamOne, teamTwo); - game.print(); + const game = new Game(usedCourts[index].id, false, teamOne, teamTwo); this.data.push(game); } } getPossibleGameCount() { - let activeRegularCount = this.players.active().length; + let activeRegularCount = this.regulars.active().length; let activeGuestCount = this.guests.active().length; let activePlayerCount = activeRegularCount + activeGuestCount; - console.log( - "There are a total of " + activePlayerCount + " players available." - ); + console.log("Total players available: " + activePlayerCount); let activeCourtCount = this.courts.active().length; - console.log( - "There are a total of " + activeCourtCount + " courts available." - ); + console.log("There courts available: " + activeCourtCount); let possibleMatches = Math.min( Math.floor(activePlayerCount / 4), activeCourtCount @@ -89,46 +90,36 @@ export class GameManager extends Manager { } selectPlayers(count) { console.log("Required players are " + count); - let activePlayers = this.players.active(); + let activePlayers = this.regulars.active(); const activeGuests = this.guests.active(); activePlayers = activePlayers.concat(activeGuests); console.log("Active players are:"); - console.log( - activePlayers - .map((i) => { - return i.name; - }) - .join(",") - ); + activePlayers.map((p) => { + p.print(); + }); 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(",") - ); + selectedPlayers.map((p) => { + p.print(); + }); return selectedPlayers; } propose() { console.log("Proposing new games!"); - let possibleMatches = this.getPossibleGameCount(); - console.log("Total possible matches are " + possibleMatches + "."); this.data = []; this.addBlockedGames(); - const activeCourts = this.courts.active(); - const unusedCourts = activeCourts.slice(possibleMatches + 1); - this.addInactiveGames(unusedCourts); - const usedCourts = activeCourts.slice(0, possibleMatches); - let requiredPlayerCount = possibleMatches * 4; - const selectedPlayers = this.selectPlayers(requiredPlayerCount); + let possibleMatches = this.getPossibleGameCount(); + console.log("Total possible matches are " + possibleMatches + "."); + this.addInactiveGames(possibleMatches); + this.addActiveGames(possibleMatches); console.log("The matches are:"); - this.addActiveGames(usedCourts, selectedPlayers); this.data.sort((a, b) => a.id - b.id); + this.data.map((g) => { + g.print(); + }) this.render(); } confirm() { @@ -152,8 +143,8 @@ export class GameManager extends Manager { localStorage.removeItem("round"); localStorage.removeItem(this.description); localStorage.removeItem(this.courts.description); - // Clear the number of games played localStorage.removeItem(this.guests.description); + // Clear the number of games played document.getElementById("timer-stop").click(); window.location.reload(); } diff --git a/src/manage.js b/src/manage.js index 952c72f..7449866 100644 --- a/src/manage.js +++ b/src/manage.js @@ -95,7 +95,7 @@ function normalize(data) { export class GuestManager extends Manager { constructor() { - super("Guest", 12); + super("Guest", 18); } createItem(i) { return new Guest(i, randomStatus()); @@ -116,7 +116,7 @@ export function randomLevel() { return Math.floor(Math.random() * maxLevel + 1); } -export class PlayerManager extends Manager { +export class RegularManager extends Manager { constructor() { super("Regular", 71); addLoadBehaviour(this); diff --git a/src/style.css b/src/style.css index 1bd8901..73550ca 100644 --- a/src/style.css +++ b/src/style.css @@ -1,6 +1,6 @@ .button-grid { display: grid; - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(3, 1fr); grid-gap: 15px; } #timer-display { @@ -10,3 +10,8 @@ table { font-size: 1.5em; } +@media (max-width: 900px) { + .button-grid { + grid-template-columns: repeat(1, 1fr); + } +} \ No newline at end of file -- cgit v1.3.1