diff options
| author | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-11-14 15:58:36 +0100 |
|---|---|---|
| committer | Karan Jayachandra <karan.jayachandra@nxp.com> | 2025-11-14 15:58:36 +0100 |
| commit | e4b599e57e076bef7caa8f5825bbca17540b571d (patch) | |
| tree | 6c86ebeec49161bd459b7a79f7278e7e817bfc53 /src/data.js | |
| parent | 51cf65e4d3e928a37b542acfb3de439c42907a9f (diff) | |
Unified the data classes
Diffstat (limited to 'src/data.js')
| -rw-r--r-- | src/data.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/data.js b/src/data.js new file mode 100644 index 0000000..4358ee6 --- /dev/null +++ b/src/data.js @@ -0,0 +1,98 @@ +class Switch { + constructor(id, description, status) { + this.id = id; + this.status = typeof status !== "undefined" ? status : false; + this.description = description; + this.name = description + " " + (id + 1); + } + toggle() { + this.status = !this.status; + this.print(); + } + print() { + let status = this.status ? "active" : "inactive"; + console.log(this.name + " is currently " + status); + } + render() { + let color = this.status ? "is-success" : "is-danger"; + let type = `class="button is-medium ${color}"`; + let id = this.description + "_" + this.id; + return `<button id=${id} ${type}>${this.name}</button>`; + } +} + +export class Court extends Switch { + constructor(id, status) { + super(id, "Court", status); + } +} + +export class Player extends Switch { + constructor(id, status, level, games, name) { + super(id, "Regular", status); + this.level = typeof level !== "undefined" ? level : 1; + this.games = typeof games !== "undefined" ? games : 0; + if (typeof name !== "undefined") { + this.name = name; + } + } +} + +const guestCategories = { + 0: { description: "Beginner", level: 1 }, + 1: { description: "Novice", level: 3 }, + 2: { description: "Intermediate", level: 6 }, +}; + +export class Guest extends Switch { + maxCount = 4; + categoryCount = 3; + + constructor(id, status, games) { + super(id, "Guest", status); + const categoryId = Math.floor(id / this.maxCount) || 0; + this.level = guestCategories[categoryId].level; + this.games = typeof games !== "undefined" ? games : 0; + const guestNumber = (id % this.maxCount) + 1; + this.name = guestCategories[categoryId].description + " " + guestNumber; + } +} + +export class Team { + constructor(playerOne, playerTwo) { + this.playerOne = playerOne; + this.playerTwo = playerTwo; + } + print() { + console.log("Team consists of:"); + this.playerOne.print(); + this.playerTwo.print(); + } + render() { + let p1 = `<td style="width: 23%; text-align: right;">${this.playerOne}</td>`; + let p2 = `<td style="width: 23%; text-align: left;">${this.playerTwo}</td>`; + return p1 + p2; + } +} + +export class Game extends Switch { + constructor(id, status, teamOne, teamTwo) { + super(id, "Game", status); + this.teamOne = teamOne; + 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); + } + render() { + let blockedState = this.teamOne.playerOne === "RESERVED"; + let type = blockedState ? `class="is-danger is-dark"` : ``; + let court = `<td style="width: 8%; text-align: center;">${ + this.id + 1 + }</td>`; + return `<tr ${type}>${court}${this.teamOne.render()}${this.teamTwo.render()}</tr>`; + } +} |
