game: add: docstring

This commit is contained in:
2024-01-22 13:21:51 +01:00
parent ab73826c11
commit 6fd11d0028
10 changed files with 231 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import { MyProfile } from "./MyProfile.js";
import { navigateTo } from "../index.js"
import { Tourmanents } from "./tournament/tournaments.js";
import {Notice} from "./chat/notice.js"
import { Channel } from "./chat/channel.js";
function getCookie(name)
{
@ -19,21 +20,62 @@ function getCookie(name)
class Client
{
/**
*
* @param {String} url
*/
constructor(url)
{
/**
* @type {String}
*/
this._url = url;
/**
* @type {Account}
*/
this.account = new Account(this);
/**
* @type {Profiles}
*/
this.profiles = new Profiles(this);
/**
* @type {MatchMaking}
*/
this.matchmaking = new MatchMaking(this);
/**
* @type {Tourmanents}
*/
this.tournaments = new Tourmanents(this);
/**
* @type {Boolean} A private var represent if the is is log NEVER USE IT use await isAuthentificated()
*/
this._logged = undefined;
/**
* @type {Channels}
*/
this.channels = new Channels(this);
/**
* @type {Channel}
*/
this.channel = undefined;
/**
* @type {Notice}
*/
this.notice = new Notice(this);
}
/**
* The only right way to determine is the user is logged
* @returns {Boolean}
*/
async isAuthentificate()
{
if (this._logged == undefined)
@ -41,6 +83,12 @@ class Client
return this._logged;
}
/**
* Send a GET request to %uri%
* @param {String} uri
* @param {*} data
* @returns {Response}
*/
async _get(uri, data)
{
let response = await fetch(this._url + uri, {
@ -50,6 +98,12 @@ class Client
return response;
}
/**
* Send a POST request
* @param {String} uri
* @param {*} data
* @returns {Response}
*/
async _post(uri, data)
{
let response = await fetch(this._url + uri, {
@ -63,6 +117,12 @@ class Client
return response;
}
/**
* Send a DELETE request
* @param {String} uri
* @param {String} data
* @returns {Response}
*/
async _delete(uri, data)
{
let response = await fetch(this._url + uri, {
@ -76,6 +136,12 @@ class Client
return response;
}
/**
* Send a PATCH request with json
* @param {String} uri
* @param {*} data
* @returns {Response}
*/
async _patch_json(uri, data)
{
let response = await fetch(this._url + uri, {
@ -89,6 +155,12 @@ class Client
return response;
}
/**
* Send a PATCH request with file
* @param {String} uri
* @param {*} file
* @returns {Response}
*/
async _patch_file(uri, file)
{
let response = await fetch(this._url + uri, {
@ -101,6 +173,11 @@ class Client
return response;
}
/**
* Change logged state. Use It if you recv an 403 error
* @param {Boolean} state
* @returns
*/
async _update_logged(state)
{
if (this._logged == state)
@ -126,6 +203,12 @@ class Client
this._logged = state;
}
/**
* Loggin the user
* @param {String} username
* @param {String} password
* @returns
*/
async login(username, password)
{
let response = await this._post("/api/accounts/login", {username: username, password: password})
@ -135,12 +218,19 @@ class Client
return response;
}
/**
* Logout the user
*/
async logout()
{
await this._get("/api/accounts/logout");
await this._update_logged(false);
}
/**
* Determine if the user is logged. NEVER USE IT, USE isAuthentificated()
* @returns {Boolean}
*/
async _test_logged()
{
let response = await this._get("/api/accounts/logged");