From 9c944ac71a1e5b8d657a60a1e24d143a13573645 Mon Sep 17 00:00:00 2001 From: anulax1225 Date: Thu, 18 Jan 2024 10:34:02 +0100 Subject: [PATCH] deleted skama_code --- js/skama_code/api/agent.js | 129 ------------------- js/skama_code/api/config.js | 7 - js/skama_code/api/planet.js | 71 ----------- js/skama_code/api/system.js | 155 ----------------------- js/skama_code/auth/auth.js | 89 ------------- js/skama_code/commun/my.js | 5 - js/skama_code/commun/position.js | 18 --- js/skama_code/commun/strategie.js | 51 -------- js/skama_code/commun/timer.js | 59 --------- js/skama_code/rendering/canvas_render.js | 0 js/skama_code/ui/menu.js | 0 js/skama_code/ui/modal.js | 39 ------ js/skama_code/ui/templeting_engine.js | 47 ------- 13 files changed, 670 deletions(-) delete mode 100644 js/skama_code/api/agent.js delete mode 100644 js/skama_code/api/config.js delete mode 100644 js/skama_code/api/planet.js delete mode 100644 js/skama_code/api/system.js delete mode 100644 js/skama_code/auth/auth.js delete mode 100644 js/skama_code/commun/my.js delete mode 100644 js/skama_code/commun/position.js delete mode 100644 js/skama_code/commun/strategie.js delete mode 100644 js/skama_code/commun/timer.js delete mode 100644 js/skama_code/rendering/canvas_render.js delete mode 100644 js/skama_code/ui/menu.js delete mode 100644 js/skama_code/ui/modal.js delete mode 100644 js/skama_code/ui/templeting_engine.js diff --git a/js/skama_code/api/agent.js b/js/skama_code/api/agent.js deleted file mode 100644 index 67cf836..0000000 --- a/js/skama_code/api/agent.js +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; -import { SpaceTraders } from "./config.js" - -export class My { - static agent = null; - static temp_engine = null; - static canvas_renderer = null; -} - -export class Agent { - constructor(agent, token = "") { - this.token = token; - this.name = agent.symbol; - this.credits = agent.credits; - this.faction = agent.startingFaction; - this.hq = agent.headquarters; - this.ships_cpt = agent.shipCount; - } - - get_agent_system() { - let metaSystem = this.hq.split("-"); - return metaSystem[0] + "-" + metaSystem[1]; - } -} - -export class AgentBuilder { - constructor(end = false) { - this.stopped = false; - this.end = end; - } - - static create(symbol, faction, callback, error_handler) { - const url = `${SpaceTraders.host}/register`; - $.ajax({ - url: url, - method: "POST", - headers: { "Content-Type": "application/json" }, - processData: false, - data: `{\n "faction": "${faction}",\n "symbol": "${symbol}"}`, - success: (reponse) => { - let agent = new Agent(reponse.data.agent, reponse.data.token) - callback(agent); - }, - error: (err) => { - error_handler(["Name already took."]) - } - }); - } - - static get(token, callback, error_handler){ - const url = `${SpaceTraders.host}/my/agent`; - $.ajax({ - url: url, - method: "GET", - headers: { - Accept: "application/json", - Authorization: `Bearer ${token}`, - }, - success: (reponse) => { - let agent = new Agent(reponse.data, token); - callback(agent); - }, - error: (err) => { - error_handler(["Token invalide."]); - } - }); - } - - static get_public(symbol, callback) { - const url = `${SpaceTraders.host}/agents/${symbol}`; - $.ajax({ - url: url, - method: "GET", - headers: { - Accept: "application/json" - }, - success: (reponse) => { - let agent = new Agent(reponse.data); - callback(agent); - }, - }); - } - - static list(limit, page, callback, agents = []) { - const url = `${SpaceTraders.host}/agents`; - const data = { limit, page }; - $.ajax({ - url: url, - method: "GET", - headers: { - Accept: "application/json" - }, - data: data, - success: (reponse) => { - reponse.data.forEach(agent => { - agents.push(new Agent(agent)); - }); - callback(agents, reponse.meta); - }, - }); - } - - static list_all(callback) { - this.list(20, 1, (agents, meta) => { - let maxPage = meta.total / 20; - this.#r_listing(2, maxPage, agents, callback); - }); - } - - static #r_listing(page, maxPage, agents, callback) { - if (page < maxPage) { - this.list(20, page++,() => { - setTimeout(() => { - if (!this.end) { - callback(agents); - agents = []; - } - if (!this.stopped) this.#r_listing(page++, maxPage, agents, callback, end); - }, 1000); - }, agents); - } else { - callback(agents); - } - } -} - - - diff --git a/js/skama_code/api/config.js b/js/skama_code/api/config.js deleted file mode 100644 index 322ae37..0000000 --- a/js/skama_code/api/config.js +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export const SpaceTraders = { - host: "https://api.spacetraders.io/v2", - timing: 1000, -} \ No newline at end of file diff --git a/js/skama_code/api/planet.js b/js/skama_code/api/planet.js deleted file mode 100644 index c4c085a..0000000 --- a/js/skama_code/api/planet.js +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -import { SpaceTraders } from "./config.js"; -import { Position } from "../commun/position.js"; - -class Market { - constructor(market) { - this.symbol = market.symbol; - this.exports = market.exports; - this.imports = market.imports; - this.exchange = market.exchange; - this.transctions = market.transctions; - this.trade_goods = market.tradeGoods; - } - - has_export(market_export) { - - } - - list_exports(callback) { - - } - - has_import(market_import) { - - } - - list_import(callback) { - - } -} - -export class Planet { - constructor(waypoint) { - this.name = waypoint.symbol; - this.type = waypoint.type; - this.system = waypoint.systemSymbol; - this.position = new Position(waypoint.x, waypoint.y); - this.moons = waypoint.orbitals; - this.orbits = waypoint.orbits; - this.faction = waypoint.faction; - this.traits = waypoint.traits; - this.dangers = waypoint.modifiers; - this.discovery = waypoint.char; - this.is_under_construction = waypoint.isUnderConstruction; - } - - get_market(callback, error_handler) { - const url = `${SpaceTraders.host}/systems/${this.system}/waypoints/${this.name}/market`; - $.ajax({ - url: url, - method: "GET", - success: (reponse) => { - let market = new Market(reponse.data); - callback(market); - }, - error: (err) => { - error_handler("Market not found"); - } - }); - } - - is_type(type) { - return this.type === type ? true : false; - } - - is_discovered() { - return this.discovery.length > 0 ? true : false; - } -} \ No newline at end of file diff --git a/js/skama_code/api/system.js b/js/skama_code/api/system.js deleted file mode 100644 index 14053af..0000000 --- a/js/skama_code/api/system.js +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -import { SpaceTraders } from "./config.js"; -import { Position } from "../commun/position.js"; -import { Planet } from "./planet.js"; - -export class System { - constructor(data) { - this.name = data.symbol; - this.sector = data.sectorSymbol; - this.type = data.type; - this.position = new Position(data.x, data.y); - this.factions = data.factions; - this.stopped = false; - this.end = false; - } - - when_end() { - this.end = true; - } - - get_planet(name, callback, error_handler) { - const url = `${SpaceTraders.host}/systems/${this.name}/waypoints/${name}`; - $.ajax({ - url: url, - method: "GET", - success: (reponse) => { - let planet = new Planet(reponse.data); - callback(planet); - }, - error: (err) => { - error_handler("Planet not found"); - } - }); - } - - list_planets(limit, page, callback, planets = []) { - const url = `${SpaceTraders.host}/systems/${this.name}/waypoints` - $.ajax({ - url: url, - method: "GET", - data: { - limit: limit, - page: page - }, - success: (reponse) => { - reponse.data.forEach(planet => { - planets.push(new Planet(planet)); - }); - callback(planets, reponse.meta); - } - }); - } - - stop() { - this.stopped = true; - } - - list_all_planets(callback, end = false) { - this.list_planets(20, 1, (planets, meta) => { - let maxPage = meta.total / 20; - this.#r_listing(2, maxPage, planets, callback, end); - }); - } - - #r_listing(page, maxPage, planets, callback) { - if (page < maxPage) { - this.list_planets(20, page++, () => { - setTimeout(() => { - if (!end) { - callback(planets); - planets = []; - } - if (!this.stopped) this.#r_listing(page++, maxPage, planets, callback, end); - }, SpaceTraders.timing); - }, planets); - } else { - callback(planets); - } - } -} - -export class SystemBuilder { - constructor(end = false) { - this.stopped = false; - this.end = end; - this.page = 1; - - } - - static parse_system_name(name) { - return name.split("-").slice(-1, 2).join("-"); - } - - static get(name, callback, error_handler) { - const url = `${SpaceTraders.host}/systems/${name}/`; - $.ajax({ - url: url, - method: "GET", - success: (reponse) => { - let system = new System(reponse.data); - callback(system); - }, - error: (err) => { - error_handler("System not found"); - } - }); - } - - static list(limit, page, callback, systems = []) { - const url = `${SpaceTraders.host}/systems/` - $.ajax({ - url: url, - method: "GET", - data: { - limit: limit, - page: page - }, - success: (reponse) => { - reponse.data.forEach(system => { - systems.push(new System(system)); - }); - callback(systems, reponse.meta); - } - }); - } - - stop() { - this.stopped = true; - } - - list_all(callback) { - SystemBuilder.list(20, this.page, (systems, meta) => { - this.max_page = meta.total / 20; - this.#r_listing(systems, callback); - }); - } - - #r_listing(systems, callback) { - if (page < maxPage) { - SystemBuilder.list(20, this.page++, () => { - setTimeout(() => { - if (!this.end) { - callback(systems); - systems = []; - } - if (!this.stopped) this.#r_listing(page++, maxPage, systems, callback); - }, SpaceTraders.timing); - }, systems); - } else { - callback(systems); - } - } -} \ No newline at end of file diff --git a/js/skama_code/auth/auth.js b/js/skama_code/auth/auth.js deleted file mode 100644 index 4ce4f41..0000000 --- a/js/skama_code/auth/auth.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; -import { AgentBuilder } from '../api/agent.js' -import Strategie from '../commun/strategie.js'; - -let strategies = { - register: [ - { - name: "name", - validations: [ - "required", - "max_length|14" - ] - }, - { - name: "faction", - validations: [ - "required" - ] - } - ], - login: [ - { - name: "token", - validations: [ - "required" - ] - } - ] -} - -export class Auth { - constructor(store = false) { - this.store = store; - this.validated = () => {}; - this.error_handler = () => {}; - this.strategies = strategies; - } - - done(validated) { - this.validated = validated; - return this; - } - - fail(error_handler) { - this.error_handler = error_handler; - return this; - } - - login(token) { - let validateur = new Strategie(this.strategies.login); - validateur.validate("token", token); - if (validateur.errors.length > 0) this.error_handler(validateur.errors); - else { - if (this.store) localStorage.setItem("token", token); - AgentBuilder.get(token, this.validated, this.error_handler); - } - } - - relog() { - if(this.#is_login()) { - AgentBuilder.get(localStorage.getItem("token"), this.validated, this.error_handler); - return true; - } - return false; - } - - register(new_agent) { - let validateur = new Strategie(this.strategies.register); - validateur.validate("name", new_agent.name); - validateur.validate("faction", new_agent.faction); - if (validateur.errors.length > 0) this.error_handler(validateur.errors); - else { - AgentBuilder.create(new_agent.name, new_agent.faction, (agent) => { - if (this.store) localStorage.setItem("token", agent.token); - this.validated(agent); - }, this.error_handler); - } - } - - unload_token() { - if(this.#is_login()) localStorage.removeItem("token"); - } - - #is_login() { - if (localStorage.getItem("token")) return true - return false - } -} \ No newline at end of file diff --git a/js/skama_code/commun/my.js b/js/skama_code/commun/my.js deleted file mode 100644 index 00770e2..0000000 --- a/js/skama_code/commun/my.js +++ /dev/null @@ -1,5 +0,0 @@ -export class My { - static agent = null; - static temp_engine = null; - static canvas_renderer = null; -} \ No newline at end of file diff --git a/js/skama_code/commun/position.js b/js/skama_code/commun/position.js deleted file mode 100644 index b8c5275..0000000 --- a/js/skama_code/commun/position.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export class Position { - constructor(x, y) { - this.x = x; - this.y = y; - } - - get_canvas_pos(w, h) { - return new Position(x - w/2, y - h/2) - } - - move(position) { - this.x += position.x; - this.y += position.y; - } -} \ No newline at end of file diff --git a/js/skama_code/commun/strategie.js b/js/skama_code/commun/strategie.js deleted file mode 100644 index 79966c3..0000000 --- a/js/skama_code/commun/strategie.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export default class Strategie { - constructor(strategie) { - this.strategie = strategie; - this.errors = []; - } - - validate(name, input) { - this.strategie.forEach(input_strat => { - if(input_strat.name === name) input_strat.validations.forEach((validation) => { - let args = validation.split("|"); - switch (args[0]) { - case "required": - this.#test(Strategie.#required(input), `${name} is required.`); - break; - case "max_length": - this.#test(Strategie.#max_length(input, parseInt(args[1])), `${name} must have a max lenght of ${args[1]}.`); - break; - case "min_length": - this.#test(Strategie.#min_length(input, parseInt(args[1])), `${name} must have a min lenght of ${args[1]}`); - break; - } - }); - }); - } - - #test(test, error) { - if(!test) this.errors.push(error); - } - - static #valide_email(input) { - - } - - static #min_length(input, length) { - if(input.length < length) return false; - return true; - } - - static #max_length(input, length) { - if(input.length > length) return false; - return true; - } - - static #required(input) { - if (input === undefined || input === null || input === "") return false; - return true; - } -} \ No newline at end of file diff --git a/js/skama_code/commun/timer.js b/js/skama_code/commun/timer.js deleted file mode 100644 index 1891f15..0000000 --- a/js/skama_code/commun/timer.js +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export class Timer { - constructor(time, step, unit = "s") { - this.passed_time = 0; - this.time = time; - this.step = step; - this.continue = true; - switch (unit) { - case "ms": - this.unit = 1; - break; - case "s": - this.unit = 1000; - break; - case "m": - this.unit = 60000; - break; - case "h": - this.unit = 3600000; - break; - default: - this.unit = 1; - break; - } - } - on(action, callback) { - switch(action) { - case "end": - this.end_callback = callback; - break; - case "step": - this.step_callback = callback; - break; - } - } - start() { - this.continue = true; - this.#time_step(); - } - - stop() { - this.continue = false; - this.passed_time = 0; - } - - #time_step() { - if (this.passed_time < this.time && this.continue) { - if (this.step_callback) this.step_callback(this.passed_time); - this.passed_time += this.step; - setTimeout(() => { - this.#time_step() - }, this.step*this.unit); - } else { - if (this.end_callback) this.end_callback(this.time); - } - } -} \ No newline at end of file diff --git a/js/skama_code/rendering/canvas_render.js b/js/skama_code/rendering/canvas_render.js deleted file mode 100644 index e69de29..0000000 diff --git a/js/skama_code/ui/menu.js b/js/skama_code/ui/menu.js deleted file mode 100644 index e69de29..0000000 diff --git a/js/skama_code/ui/modal.js b/js/skama_code/ui/modal.js deleted file mode 100644 index 98890a3..0000000 --- a/js/skama_code/ui/modal.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; - -export class Modal { - constructor(name, template_engine, tag = "#block-content") { - this.name = name; - this.template_engine = template_engine; - this.tag = tag; - this.modal_class = ""; - } - - load(template) { - this.template_engine.get_template((reponse) => { - $(this.tag).prepend(` - - ${reponse} - - `); - }, template); - } - - on_close(callback) { - document.querySelector(`#${this.name}`).addEventListener("close", callback); - } - - add_class(modal_class) { - let modal; - if(modal = $(`#${this.name}`)) modal.addClass(modal_class); - this.modal_class = `${this.modal_class} ${modal_class}`; - } - - show() { - document.querySelector(`#${this.name}`).showModal(); - } - - close() { - document.querySelector(`#${this.name}`).close(); - } -} \ No newline at end of file diff --git a/js/skama_code/ui/templeting_engine.js b/js/skama_code/ui/templeting_engine.js deleted file mode 100644 index 8d6f89c..0000000 --- a/js/skama_code/ui/templeting_engine.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2023 Entreprise SkamKraft -'use strict'; -export class TemplateEngine { - constructor(path) { - this.templatePath = path; - } - - render(template) { - this.get_template((reponse) => { - $('body').html(reponse); - this.get_template((reponse) => { - $("#block-content").html(reponse); - if (this.after_render_callback) this.#flush_events().after_render_callback(this); - }, template) - }); - } - - frag_load(tag, template) { - this.get_template((reponse) => { - $(tag).html(reponse); - }, template); - } - - get_template(callback, template = "") { - let url = template === "" ? `${this.templatePath}/template.html`: `${this.templatePath}/${template}`; - $.ajax(url,{ - method: "GET", - success: callback, - error: (err) => { - console.log(err); - } - }); - } - - add_event(tag, action, callback) { - $("body").on(action, tag, callback); - } - - #flush_events() { - $("body").unbind(); - return this; - } - - after_render(callback) { - this.after_render_callback = callback; - } -}