Skip to content

Commit

Permalink
build: 0dca7e6
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 11, 2024
1 parent d40894d commit ca25e01
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Scripts/Control.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"use strict";
/**
* If more functionality is needed, combine them in one function as static function of this class.
*/
class Control {
static createTournament() {
// new tournament
Expand Down
5 changes: 5 additions & 0 deletions Scripts/FileManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"use strict";
/**
* In charge of saving and loading Tournaments as JSON files.
* Saving on the Tournament page, Loading on the Homepage.
*/
class FileManager {
static loadJSON() {
// to decide which one to use
Expand All @@ -10,6 +14,7 @@ class FileManager {
// load tournament in given moment
}
static exportLogJSON() {
// in fact, export snapshot of the tournament alongside with the logs - for faster loading and ease of use
}
static exportSnapshotJSON() {
}
Expand Down
9 changes: 5 additions & 4 deletions Scripts/HistoryManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"use strict";
/**
* In charge of history saved to Local storage.
* Apart of saving the history can also EXECUTE ON CHANGING HISTORY,
* when needed for undo/redo functionality.
*/
class HistoryManager {
static getCurrentSerialNumber() {
}
Expand All @@ -18,8 +23,4 @@ class HistoryManager {
// do what is in the log
// if save, than add it to history
}
static saveToSessionStorage(key, sth) {
}
static getFromSessionStorage(key) {
}
}
16 changes: 16 additions & 0 deletions Scripts/Log.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
"use strict";
/**
* Encapsulate info about ONE change in the tournament, such as renaming team, passed match, change of settings...
* Has its serial number, which determines its order in the chain of changes - must be set just before adding to the chain, default -1.
*/
class Log {
/**
* Each Log has it serial number, which determines its order in the chain of changes.
* @param idOfObject ID of object on which the event happened.
* @param type Type of event.
* @param previous Previous state of the tournament.
* @param after State of the tournament after the change.
*/
constructor(idOfObject, type, previous, after) {
this.serialNumber = -1;
this.idOfObject = idOfObject;
this.type = type;
this.previous = previous;
this.after = after;
}
/**
* ONLY for History manager to use, NOWHERE ELSE SHOULD IT BE USED!
* Set just before adding to the chain of Logs, to avoid conflicts.
* @param num Number greater than the precent number by one.
*/
setSerialNumber(num) {
if (this.serialNumber != -1) {
this.serialNumber = num;
Expand Down
4 changes: 4 additions & 0 deletions Scripts/LogEvent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"use strict";
/**
* List every change of the state of the Tournament we might want to save to Log.
* For forgotting heads, please put a comment of the format of the previous/after data.
*/
var LogEvent;
(function (LogEvent) {
LogEvent[LogEvent["SAVE_MATCH"] = 0] = "SAVE_MATCH";
Expand Down
3 changes: 3 additions & 0 deletions Scripts/Main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"use strict";
/**
* Main shouldn't have had a lot to do.
*/
window.onload = function () {
UI.buildHomePage();
};
10 changes: 7 additions & 3 deletions Scripts/Match.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
/**
* Represents one Match, has a lot of info and few useful functions.
* Has unique id for IDs of both Teams lower than 13.378 - doesn't tested further.
* Has unique id created from IDs of both Teams (order doesn't matter).
* Guranteed unique id for Teams IDs lower than 13.378 - doesn't tested further.
*
* It's functions completely comprehend the Match page, given that it is created with correct functions on buttons etc. (job of UI)
* Save function intended to only be called once the match ended, otherwise redundant logs in history - but will work just fine.
*/
class Match {
/**
Expand Down Expand Up @@ -221,14 +225,14 @@ class Match {
timeOfStart: this.timeOfStart,
timeOfEnd: this.timeOfEnd
};
HistoryManager.saveToSessionStorage("previousInfo", previousInfo);
BrowserStorage.saveToSessionStorage("previousInfo", previousInfo);
}
save(askToLeave = true) {
this.setTimeOfEnd();
if (this.shouldMatchEnd()) {
this.finished = true;
}
const previousInfo = HistoryManager.getFromSessionStorage("previousInfo");
const previousInfo = BrowserStorage.getFromSessionStorage("previousInfo");
// save previous info - only what was changed // if this doesnt work, edit to just save everything
const matchAsDict = JSON.parse(JSON.stringify(this));
let previous = [];
Expand Down
3 changes: 3 additions & 0 deletions Scripts/OrderMethod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"use strict";
/**
* List each method of ordering the Tournament is capable of.
*/
var OrderMethod;
(function (OrderMethod) {
OrderMethod[OrderMethod["ROUND_ROBIN"] = 0] = "ROUND_ROBIN";
Expand Down
14 changes: 14 additions & 0 deletions Scripts/StorageManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
/**
* In charge of all Local and Session storage of the browser.
* For every access to any storage please use this class.
* It has all info about how is the storage used, which names used etc.
*/
class BrowserStorage {
static saveToSessionStorage(key, sth) {
// maybe save the key to some storage, so we know it is there?
// but maybe only for local storage, not session
}
static getFromSessionStorage(key) {
}
}
2 changes: 2 additions & 0 deletions Scripts/Team.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
/**
* Encapsulate team id and name.
* Can get/set name, get id (immutable).
* ID should be unique, here not responsible.
*/
class Team {
/**
Expand Down
19 changes: 18 additions & 1 deletion Scripts/Tournament.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"use strict";
/**
* Completely comprehend Tournament page, given it is created correctely (job of UI).
* Stores info about tournament, its teams, order of matches (can be changed on the fly).
*/
class Tournament {
constructor() {
this.teams = [];
Expand All @@ -9,7 +13,20 @@ class Tournament {
this.pointsToSet = 15;
this.setsToWin = 2;
}
addTeam(team) {
addTeam(teamName, team = new Team(this.teams.length + 1, teamName)) {
const teamID = team.getId();
// if equal, it was created automaticaly and definitely is in no conflict
if (teamID != this.teams.length) {
// check if not duplicate
for (let i = 0; i < this.teams.length; i++) {
if (teamID == this.teams[i].getId()) {
console.log("Cannot add two teams with the same ID.");
return;
}
}
}
// add team
this.teams.push(team);
}
removeTeam(team) {
}
Expand Down
5 changes: 5 additions & 0 deletions Scripts/UI.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"use strict";
/**
* In charge of all UI, building home/tournament/match(/end?) pages,
* create popups, update visuals,...
*/
class UI {
static buildHomePage() {
// append all buttons and whatever
Expand Down Expand Up @@ -34,6 +38,7 @@ class UI {
// basically when change of order method happen, so the ui reflects it
}
static afterSavingMatch() {
// popup: don't U wanna leave the match for tournament and next match?
}
/**
* Win effects for the end of match. Not intrusive, maybe missclick? Sth like confetti.
Expand Down

0 comments on commit ca25e01

Please sign in to comment.