parent
7dfe56b4a2
commit
5174ee36a8
13 changed files with 306 additions and 79 deletions
@ -1,5 +1,5 @@ |
||||
'use strict'; |
||||
export const SpaceTraders = { |
||||
host: "https://api.spacetraders.io/v2/", |
||||
host: "https://api.spacetraders.io/v2", |
||||
limit_max: 20, |
||||
} |
@ -1,30 +1,103 @@ |
||||
class Position { |
||||
constructor(x, y) { |
||||
this.x = x; |
||||
this.y = y; |
||||
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) { |
||||
|
||||
} |
||||
|
||||
get_canvas_pos(w, h) { |
||||
return new Position(x - w/2, y - h/2) |
||||
list_import(callback) { |
||||
|
||||
} |
||||
} |
||||
|
||||
export class Planet { |
||||
constructor(waypoint) { |
||||
this.symbol = waypoint.symbol; |
||||
this.type = waypoint.type; |
||||
this.system = waypoint.systemSymbol; |
||||
this.position = new Position(x, 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; |
||||
} |
||||
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() { |
||||
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("Planet not found"); |
||||
} |
||||
});
|
||||
} |
||||
|
||||
is_type(type) { |
||||
return this.type === type ? true : false; |
||||
} |
||||
|
||||
is_discovered() { |
||||
return this.discovery.length > 0 ? true : false; |
||||
}
|
||||
} |
||||
|
||||
export class PlanetBuilder { |
||||
|
||||
static get(system, name, callback, error_handler) { |
||||
const url = `${SpaceTraders.host}/systems/${system}/waypoints/${name}`; |
||||
$.ajax({ |
||||
url: url, |
||||
method: "GET", |
||||
success: (reponse) => { |
||||
let planet = new Planet(reponse.data); |
||||
callback(planet); |
||||
}, |
||||
error: (err) => { |
||||
error_handler("Planet not found"); |
||||
} |
||||
}); |
||||
}
|
||||
|
||||
static list(system, limit, page, planets = []) { |
||||
const url = `${SpaceTraders.host}/systems/${system}/waypoints` |
||||
$.ajax({ |
||||
url: url, |
||||
method: "GET", |
||||
|
||||
}); |
||||
} |
||||
|
||||
static list_all(system, callback, error_handler) { |
||||
const url = `${SpaceTraders.host}/systems/${system}/waypoints`; |
||||
|
||||
} |
||||
|
||||
static #r_listing() { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
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) |
||||
} |
||||
} |
@ -1,38 +1,3 @@ |
||||
// Copyright © 2023 Entreprise SkamKraft
|
||||
'use strict'; |
||||
import { UIRenderer } from "./ui/templeting_engine.js"; |
||||
import { Initialzer } from "./commun/commun.js"; |
||||
import { AgentBuilder } from "./api/agent.js"; |
||||
import { Auth } from "./auth/auth.js"; |
||||
let store; |
||||
let token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiSEFSRElDSyIsInZlcnNpb24iOiJ2Mi4xLjQiLCJyZXNldF9kYXRlIjoiMjAyMy0xMi0wMiIsImlhdCI6MTcwMjY2Mjc2Mywic3ViIjoiYWdlbnQtdG9rZW4ifQ.PrvaOz3W79acq6RoxryMW53PRRz824_AM0VGLwfXCOsGCOCAIY-rn6-bZTOnLAtp4xPSDqEk4c38oWYAWW59p0iMDDLpur6ONnjT0RjjsQS9zr5BByfBpP36CT23IZSSzk3XxGrFolHJAyU3K1liYfNbsPuNTXlkHGNHq6yMqH4ZQUPFsXEsCkg9cUynkdLw3C39SvWhtJ89oblj_8tQp2k8dxhZemepuXtiI51eFMpv8A0WRAi7pVYo_ajJujY9QDLYn_m5hDZWTlQMIstjPaDl99p2IMweIMO2Q2G-0lKiWQ4sl6VW5tuVrz1HLYU6kyMjFQWNn6kFDE7LWMTrfw"; |
||||
let UI = new UIRenderer("html"); |
||||
let initer = new Initialzer(UI); |
||||
import tests from "./test/tests.js"; |
||||
|
||||
UI.render("templates/home.html"); |
||||
UI.frag_load("#test", "templates/login.html"); |
||||
|
||||
let auth = new Auth(store = true); |
||||
auth.done((agent) => { |
||||
console.log(agent); |
||||
}).fail((errs) => { |
||||
errs.forEach(err => { |
||||
console.log(err); |
||||
}); |
||||
}); |
||||
auth.login(token); |
||||
auth.relog(); |
||||
|
||||
//await auth.register({
|
||||
// symbol: "lkdsjfsjdlfjlk",
|
||||
// faction: "COSMIC"
|
||||
//});
|
||||
|
||||
$(document).ready(() => { |
||||
initer.init_menu_link("#contracts-link", "contracts.html"); |
||||
initer.init_menu_link("#ships-link", "ships.html"); |
||||
initer.init_menu_link("#systems-link", "systems.html"); |
||||
initer.init_menu_link("#signup-link", "register.html"); |
||||
initer.init_menu_link("#signin-link", "login.html"); |
||||
initer.init_menu_link(".nav-brand", "home.html"); |
||||
}); |
||||
tests.modal(); |
@ -0,0 +1,93 @@ |
||||
import { Timer } from "../ui/timer.js"; |
||||
import { Modal } from "../ui/modal.js"; |
||||
import { TemplateEngine } from "../ui/templeting_engine.js"; |
||||
import { Initialzer } from "../commun/commun.js"; |
||||
import { AgentBuilder } from "../api/agent.js"; |
||||
import { Auth } from "../auth/auth.js"; |
||||
import { PlanetBuilder } from "../api/planet.js"; |
||||
|
||||
let temp_path = "html"; |
||||
let token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiSEFSRElDSyIsInZlcnNpb24iOiJ2Mi4xLjQiLCJyZXNldF9kYXRlIjoiMjAyMy0xMi0wMiIsImlhdCI6MTcwMjY2Mjc2Mywic3ViIjoiYWdlbnQtdG9rZW4ifQ.PrvaOz3W79acq6RoxryMW53PRRz824_AM0VGLwfXCOsGCOCAIY-rn6-bZTOnLAtp4xPSDqEk4c38oWYAWW59p0iMDDLpur6ONnjT0RjjsQS9zr5BByfBpP36CT23IZSSzk3XxGrFolHJAyU3K1liYfNbsPuNTXlkHGNHq6yMqH4ZQUPFsXEsCkg9cUynkdLw3C39SvWhtJ89oblj_8tQp2k8dxhZemepuXtiI51eFMpv8A0WRAi7pVYo_ajJujY9QDLYn_m5hDZWTlQMIstjPaDl99p2IMweIMO2Q2G-0lKiWQ4sl6VW5tuVrz1HLYU6kyMjFQWNn6kFDE7LWMTrfw"; |
||||
|
||||
let tests = { |
||||
timer: function() { |
||||
let timer = new Timer(1, 0.1666, "m"); |
||||
timer.on("step", (time) => { |
||||
console.log(time); |
||||
}) |
||||
timer.on("end", () => { |
||||
console.log("pattes fini"); |
||||
}); |
||||
timer.start(); |
||||
}, |
||||
render_template: function() { |
||||
let UI = new TemplateEngine(temp_path); |
||||
let initer = new Initialzer(UI); |
||||
|
||||
UI.render("templates/home.html"); |
||||
UI.frag_load("#test", "templates/login.html"); |
||||
|
||||
$(document).ready(() => { |
||||
initer.init_menu_link("#contracts-link", "contracts.html"); |
||||
initer.init_menu_link("#ships-link", "ships.html"); |
||||
initer.init_menu_link("#systems-link", "systems.html"); |
||||
initer.init_menu_link("#signup-link", "register.html"); |
||||
initer.init_menu_link("#signin-link", "login.html"); |
||||
initer.init_menu_link(".nav-brand", "home.html"); |
||||
}); |
||||
}, |
||||
authentication: function() { |
||||
let auth = new Auth(true); |
||||
auth.done((agent) => { |
||||
console.log(agent); |
||||
}).fail((errs) => { |
||||
errs.forEach(err => { |
||||
console.log(err); |
||||
}); |
||||
}); |
||||
auth.login(token); |
||||
auth.relog(); |
||||
|
||||
//auth.register({
|
||||
// symbol: "lkdsjfsjdlfjlk",
|
||||
// faction: "COSMIC"
|
||||
//});
|
||||
}, |
||||
modal: function() { |
||||
let template_engine = new TemplateEngine(temp_path); |
||||
|
||||
let timer = new Timer(60, 1, "s"); |
||||
timer.on("step", (time) => { |
||||
$("#timer").html(` |
||||
<p>${time}</p> |
||||
`);
|
||||
}); |
||||
|
||||
template_engine.render("templates/login.html"); |
||||
|
||||
let modal = new Modal("test-modal",template_engine); |
||||
modal.enable = false; |
||||
|
||||
modal.render("templates/test_modal.html"); |
||||
|
||||
template_engine.add_event("#valid", "click", () => { |
||||
modal.show(); |
||||
timer.start(); |
||||
}); |
||||
|
||||
template_engine.add_event("#ok", "click", () => { |
||||
modal.close(); |
||||
timer.stop(); |
||||
}); |
||||
}, |
||||
get_planet: function() { |
||||
PlanetBuilder.get("X1-TT23", "X1-TT23-FF1E", (planet) => { |
||||
console.log(planet); |
||||
}, (err) => { |
||||
console.log(err); |
||||
}); |
||||
}, |
||||
|
||||
} |
||||
|
||||
export default tests; |
@ -0,0 +1,30 @@ |
||||
export class Modal { |
||||
constructor(name, template_engine, tag = "#block-content") { |
||||
this.name = name; |
||||
this.template_engine = template_engine; |
||||
this.tag = tag; |
||||
this.modal_class = ""; |
||||
} |
||||
|
||||
render(template) { |
||||
this.template_engine.get_template((reponse) => { |
||||
$(this.tag).html(` |
||||
<dialog id="${this.name}" class="${this.modal_class} modal-disable"> |
||||
${reponse} |
||||
</dialog> |
||||
`);
|
||||
}, template); |
||||
} |
||||
|
||||
add_class(modal_class) { |
||||
this.modal_class = `${this.modal_class} ${modal_class}`; |
||||
} |
||||
|
||||
show() { |
||||
document.querySelector(`#${this.name}`).showModal();
|
||||
} |
||||
|
||||
close() { |
||||
document.querySelector(`#${this.name}`).close(); |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in New Issue