diff options
| -rw-r--r-- | index.html | 36 | ||||
| -rw-r--r-- | src/data.js | 9 | ||||
| -rw-r--r-- | src/main.js | 73 | ||||
| -rw-r--r-- | src/manage.js | 4 | ||||
| -rw-r--r-- | src/style.css | 7 |
5 files changed, 66 insertions, 63 deletions
@@ -24,9 +24,9 @@ </nav> <div class="container"> <section class="section"> + <h1 class="title" id="Game_description"></h1> <table class="table is-fullwidth"> <thead> - <tr><th colspan="5"><div id="Game_description"></div></th></tr> <tr> <th>Court</th> <th colspan='2' style="text-align: center;">Team 1</th> @@ -48,7 +48,6 @@ </select> </div> <button class="button is-medium is-dark" id="confirm">Confirm</button> - <button class="button is-medium is-danger" id="reset">Reset</button> </div> </section> <section class="section"> @@ -64,20 +63,27 @@ <div id="Guest_list" class="button-grid"></div> </section> <section class="section"> - <h1 class="title">Player Update</h1> - <div id="player-load" class="file is-danger has-name is-boxed"> - <label class="file-label"> - <input class="file-input" type="file" name="players" accept=".csv"/> - <span class="file-cta"> - <span class="file-icon"> - <i class="fa-solid fa-upload"></i> - </span> - <span class="file-label"> Update players... </span> - </span> - <span class="file-name"> No file selected... </span> - </label> + <h1 class="title">Admin</h1> + <h1 class="subtitle">Changes here are permanent and cannot be reverted.</h1> + <div class="field is-grouped is-grouped-centered"> + <button class="button is-medium is-danger" id="reset"> + Reset Session + </button> </div> - </section> + <div class="field is-grouped is-grouped-centered"> + <div id="player-load" class="file is-danger is-boxed is-medium"> + <label class="file-label"> + <input class="file-input" type="file" name="players" accept=".csv" /> + <span class="file-cta"> + <span class="file-icon"> + <i class="fa-solid fa-upload"></i> + </span> + <span class="file-label">Update Regulars</span> + </span> + </label> + </div> + </div> + </section> </div> </section> <script src="src/main.js" type="module"></script> 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 = `<td style="width: 8%; text-align: center;">${ this.id + 1 }</td>`; 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 |
