parent
							
								
									b73672f469
								
							
						
					
					
						commit
						9c944ac71a
					
				
				 13 changed files with 0 additions and 670 deletions
			
			
		| @ -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); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| @ -1,7 +0,0 @@ | |||||||
| // Copyright © 2023 Entreprise SkamKraft
 |  | ||||||
| 'use strict'; |  | ||||||
| 
 |  | ||||||
| export const SpaceTraders = { |  | ||||||
|         host: "https://api.spacetraders.io/v2", |  | ||||||
|         timing: 1000, |  | ||||||
| } |  | ||||||
| @ -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; |  | ||||||
|     }    
 |  | ||||||
| } |  | ||||||
| @ -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); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -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 |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,5 +0,0 @@ | |||||||
| export class My { |  | ||||||
|     static agent = null; |  | ||||||
|     static temp_engine = null; |  | ||||||
|     static canvas_renderer = 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; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -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; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -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); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -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(` |  | ||||||
|                 <dialog id="${this.name}" class="${this.modal_class} modal-disable"> |  | ||||||
|                     ${reponse} |  | ||||||
|                 </dialog> |  | ||||||
|             `);
 |  | ||||||
|         }, 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(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -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; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
					Loading…
					
					
				
		Reference in New Issue