clean: respect es11

This commit is contained in:
2024-02-20 09:22:11 +01:00
parent 54ef19a340
commit c143d96443
36 changed files with 163 additions and 163 deletions

View File

@ -1,11 +1,11 @@
import { reloadView } from '../index.js'
import { reloadView } from '../index.js';
export default class LanguageManager {
constructor() {
this.availableLanguages = ['en', 'fr', 'tp', 'cr'];
this.dict = null;
this.currentLang = 'en'
this.currentLang = 'en';
this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang;
if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) {
this.loading = this.translatePage();
@ -28,7 +28,7 @@ export default class LanguageManager {
document.querySelectorAll('[data-i18n]').forEach(el => {
let key = el.getAttribute('data-i18n');
el.innerHTML = this.dict[key];
})
});
await reloadView();
return 0;

View File

@ -9,7 +9,7 @@ class MyProfile extends Profile
*/
constructor (client)
{
super(client, "../me")
super(client, "../me");
}
/**
@ -20,11 +20,11 @@ class MyProfile extends Profile
async change_avatar(form_data)
{
let response = await this.client._patch_file(`/api/profiles/settings`, form_data);
let response_data = await response.json()
let response_data = await response.json();
return response_data;
}
}
export {MyProfile}
export {MyProfile};

View File

@ -86,4 +86,4 @@ class Account
}
}
export { Account }
export { Account };

View File

@ -1,4 +1,4 @@
import {Message} from "./message.js"
import {Message} from "./message.js";
class Channel {
constructor(client, channel_id, members_id, messages, reload) {
@ -18,7 +18,7 @@ class Channel {
this.chatSocket = new WebSocket(url);
this.chatSocket.onmessage = (event) =>{
let data = JSON.parse(event.data)
let data = JSON.parse(event.data);
this.messages.push(new Message(
this.channel_id,
@ -41,12 +41,12 @@ class Channel {
let new_messages = [];
messages.forEach((message) => {
message = message["fields"];
message = message.fields;
new_messages.push(new Message(
message["channel_id"],
message["author_id"],
message["content"],
message["time"],
message.channel_id,
message.author_id,
message.content,
message.time,
));
});
@ -80,4 +80,4 @@ class Channel {
}
export {Channel}
export {Channel};

View File

@ -1,4 +1,4 @@
import {Channel} from "./channel.js"
import {Channel} from "./channel.js";
class Channels {
constructor(client) {
@ -17,7 +17,7 @@ class Channels {
let data = await response.json();
let messages = undefined;
let messages;
if (response.status == 200)
messages = data.messages;
@ -31,10 +31,9 @@ class Channels {
});
let data = await response.json();
console.log(response.status)
return data;
}
}
export {Channels}
export {Channels};

View File

@ -7,4 +7,4 @@ class Message {
}
}
export {Message}
export {Message};

View File

@ -30,11 +30,11 @@ class Notice {
console.log("receive_" + send.type + ": Function not found");
}
}
};
this.chatSocket.onopen = (event) => {
this.getOnlineUser();
this.ask_friend();
}
};
}
async disconnect() {
@ -60,8 +60,8 @@ class Notice {
async receive_accept_invite(send) {
this.data["invited"] = send.invites;
let id_game = send["id_game"];
this.data.invited = send.invites;
let id_game = send.id_game;
navigateTo("/game/" + id_game);
}
@ -77,7 +77,7 @@ class Notice {
}
async receive_refuse_invite(send) {
this.data["invited"] = send.invites;
this.data.invited = send.invites;
if (send.author_id == this.client.me.id) {
if (this.rewrite_invite !== undefined)
@ -123,10 +123,10 @@ class Notice {
// Regarder qu'il est bien invité par l'auteur
// Et qu'il n'est pas déjà invité
if (!content.includes(send.author_id) ||
this.data["invited"].includes(send.author_id))
this.data.invited.includes(send.author_id))
return;
this.data["invited"] = content;
this.data.invited = content;
let sender = await this.client.profiles.getProfileId(send.author_id);
create_popup("Invitation received by " + sender.username);
@ -152,24 +152,24 @@ class Notice {
let content = send.online;
if (content !== undefined) {
if (this.data["online"].length > 0) {
if (this.data.online.length > 0) {
// get all disconnect user
//let disconnects = this.data["online"].filter(id => !Object.keys(content).includes(id));
let disconnects = [];
for (const [key, value] of Object.entries(this.data["online"])) {
for (const [key, value] of Object.entries(this.data.online)) {
if (content[key] == "red" && value == "green")
disconnects.push(key);
}
// delete invite
this.data["invited"] = this.data["invited"].filter(id => !disconnects.includes(id));
this.data.invited = this.data.invited.filter(id => !disconnects.includes(id));
//console.log(this.data["invited"]);
}
this.data["online"] = content;
this.data.online = content;
if (this.rewrite_usernames !== undefined)
this.rewrite_usernames();
@ -202,12 +202,12 @@ class Notice {
//this.data["asker"].includes(send.author_id))
//return;
this.data["asked"] = send.asked;
this.data["asker"] = send.asker;
this.data.asked = send.asked;
this.data.asker = send.asker;
if (send.author_id != my_id) {
let sender = await this.client.profiles.getProfileId(send.author_id);
if (this.data["asker"].includes(send.author_id))
if (this.data.asker.includes(send.author_id))
create_popup(sender.username + " ask you as friend");
if (this.rewrite_profile !== undefined)
await this.rewrite_profile();
@ -248,8 +248,8 @@ class Notice {
}
async receive_accept_friend(send) {
this.data["asked"] = send.asked;
this.data["asker"] = send.asker;
this.data.asked = send.asked;
this.data.asker = send.asker;
let sender = await this.client.profiles.getProfileId(send.author_id);
if (send.author_id == this.client.me.id) {
@ -279,8 +279,8 @@ class Notice {
}
async receive_refuse_friend(send) {
this.data["asked"] = send.asked;
this.data["asker"] = send.asker;
this.data.asked = send.asked;
this.data.asker = send.asker;
let sender = await this.client.profiles.getProfileId(send.author_id);
if (send.author_id == this.client.me.id) {
@ -304,4 +304,4 @@ class Notice {
}
}
export {Notice}
export {Notice};

View File

@ -3,11 +3,11 @@ import { MatchMaking } from "./matchmaking.js";
import { Profiles } from "./profiles.js";
import { Channels } from './chat/channels.js';
import { MyProfile } from "./MyProfile.js";
import { navigateTo } from "../index.js"
import { navigateTo } from "../index.js";
import { Tourmanents } from "./tournament/tournaments.js";
import {Notice} from "./chat/notice.js"
import {Notice} from "./chat/notice.js";
import { Channel } from "./chat/channel.js";
import LanguageManager from './LanguageManager.js'
import LanguageManager from './LanguageManager.js';
function getCookie(name)
{
@ -15,7 +15,7 @@ function getCookie(name)
document.cookie.split(';').forEach(function(el) {
let split = el.split('=');
cookie[split[0].trim()] = split.slice(1).join("=");
})
});
return cookie[name];
}
@ -72,7 +72,7 @@ class Client
*/
this.notice = new Notice(this);
this.lang = new LanguageManager;
this.lang = new LanguageManager();
}
@ -218,7 +218,7 @@ class Client
*/
async login(username, password)
{
let response = await this._post("/api/accounts/login", {username: username, password: password})
let response = await this._post("/api/accounts/login", {username: username, password: password});
if (response.status == 200)
await this._update_logged(true);
@ -244,8 +244,8 @@ class Client
let response = await this._get("/api/accounts/logged");
await this._update_logged(response.status === 200);
return response.status === 200
return response.status === 200;
}
}
export {Client}
export {Client};

View File

@ -55,7 +55,7 @@ class Ball
*/
render(ctx)
{
let distance = this.speed * (this.game.time.deltaTime() / 1000)
let distance = this.speed * (this.game.time.deltaTime() / 1000);
this.position.x = this.position.x + distance * Math.cos(this.angle);
this.position.y = this.position.y - distance * Math.sin(this.angle);
@ -70,8 +70,8 @@ class Ball
this.angle = data.angle;
this.speed = data.speed;
return this
return this;
}
}
export { Ball }
export { Ball };

View File

@ -1,6 +1,6 @@
import { sleep } from "../../utils/sleep.js";
import { Ball } from "./Ball.js";
import { GameConfig } from "./GameConfig.js"
import { GameConfig } from "./GameConfig.js";
import { Player } from "./Player.js";
import { Time } from "./Time.js";
import { Wall } from "./Wall.js";
@ -150,7 +150,7 @@ class Game
if (data.detail === "update_paddle")
this._receive_update_paddle(data);
else if (data.detail === "update_ball")
this._receive_ball(data)
this._receive_ball(data);
else if (data.detail === "init_game")
this._init_game(data);
}
@ -160,7 +160,7 @@ class Game
/**
* @type {Ball}
*/
this.ball = (new Ball(this)).from_json(data.ball)
this.ball = (new Ball(this)).from_json(data.ball);
/**
* @type {[Wall]}
@ -174,7 +174,7 @@ class Game
/**
* @type {[Player]}
*/
this.players = []
this.players = [];
const players_data = data.players;
players_data.forEach((player_data) => {
this.players.push(new Player(this).from_json(player_data));
@ -216,4 +216,4 @@ class Game
}
}
export { Game }
export { Game };

View File

@ -1,5 +1,5 @@
import { Player } from "./Player.js";
import { Client } from "../client.js"
import { Client } from "../client.js";
import { Game } from "./Game.js";
import { Segment } from "./Segment.js";
@ -66,4 +66,4 @@ class MyPlayer extends Player
}
}
export { MyPlayer }
export { MyPlayer };

View File

@ -115,8 +115,8 @@ class Player
*/
this.rail = this.rail.from_json(data.rail);
return this
return this;
}
}
export { Player }
export { Player };

View File

@ -20,11 +20,11 @@ class Point
from_json(data)
{
this.x = data.x
this.y = data.y
this.x = data.x;
this.y = data.y;
return this
return this;
}
}
export { Point }
export { Point };

View File

@ -1,4 +1,4 @@
import { Point } from "./Point.js"
import { Point } from "./Point.js";
class Segment
{
@ -54,4 +54,4 @@ class Segment
}
}
export { Segment }
export { Segment };

View File

@ -39,4 +39,4 @@ class Time
}
}
export { Time }
export { Time };

View File

@ -20,10 +20,10 @@ class Wall
from_json(data)
{
this.rail = this.rail.from_json(data.rail)
this.rail = this.rail.from_json(data.rail);
return this
return this;
}
}
export { Wall }
export { Wall };

View File

@ -10,7 +10,7 @@ class MatchMaking
/**
* @type {Client}
*/
this.client = client
this.client = client;
this.searching = false;
}
@ -56,10 +56,10 @@ class MatchMaking
async stop()
{
if (this._socket)
this._socket.close()
this._socket = undefined
this._socket.close();
this._socket = undefined;
this.searching = false;
}
}
export {MatchMaking}
export {MatchMaking};

View File

@ -63,16 +63,16 @@ class Profile
let block_response = await this.client._get("/api/profiles/block");
if (block_response.status != 200)
return
return;
let block_data = await block_response.json();
let block_list = JSON.parse(block_data["blockeds"]);
let client_id = block_data["user_id"];
let block_list = JSON.parse(block_data.blockeds);
let client_id = block_data.user_id;
block_list.forEach(block => {
let blocker = block.fields.blocker;
let blocked = block.fields.blocked;
if (blocker == client_id && blocked == this.id)
return this.isBlocked = true;
return (this.isBlocked = true);
});
}
@ -84,8 +84,8 @@ class Profile
return this.isFriend;
let friend_data = await friend_response.json();
let friends_list = friend_data["friends"];
let client_id = friend_data["user_id"];
let friends_list = friend_data.friends;
let client_id = friend_data.user_id;
friends_list.forEach(friend => {
if (friend == this.id) {
this.isFriend = true;
@ -97,4 +97,4 @@ class Profile
}
export {Profile}
export {Profile};

View File

@ -10,7 +10,7 @@ class Profiles
/**
* @type {Client} client
*/
this.client = client
this.client = client;
}
/**
@ -22,9 +22,9 @@ class Profiles
let response = await this.client._get("/api/profiles/");
let response_data = await response.json();
let profiles = []
let profiles = [];
response_data.forEach((profile) => {
profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar))
profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar));
});
return profiles;
}
@ -85,4 +85,4 @@ class Profiles
}
}
export {Profiles}
export {Profiles};

View File

@ -65,7 +65,7 @@ class Tourmanent
/**
* @type {Number}
*/
this.id = id
this.id = id;
/**
* @type {Boolean} if a websocket connection is enabled
@ -99,16 +99,16 @@ class Tourmanent
leave(event)
{
if (this.connected == false)
return
return;
this.connected = false;
this._socket.close()
this._socket.close();
this.disconnect_func(event);
}
toggle_participation()
{
if (!this.connected)
return
return;
this._socket.send(JSON.stringify({participate: ""}));
}
@ -143,4 +143,4 @@ class Tourmanent
}
export { Tourmanent }
export { Tourmanent };

View File

@ -11,7 +11,7 @@ class Tourmanents
/**
* @type {Client}
*/
this.client = client
this.client = client;
}
/**
@ -52,7 +52,7 @@ class Tourmanents
async search(state)
{
let response = await this.client._get(`/api/tournaments/search/${state}`);
let response_data = await response.json()
let response_data = await response.json();
if (response.status === 403)
{
@ -88,4 +88,4 @@ class Tourmanents
}
export { Tourmanents }
export { Tourmanents };