diff --git a/assets/contracts/procurement.png b/assets/contracts/procurement.png new file mode 100644 index 0000000..f7cac9b Binary files /dev/null and b/assets/contracts/procurement.png differ diff --git a/assets/contracts/shuttle.png b/assets/contracts/shuttle.png new file mode 100644 index 0000000..92dab5d Binary files /dev/null and b/assets/contracts/shuttle.png differ diff --git a/assets/contracts/transportation.png b/assets/contracts/transportation.png new file mode 100644 index 0000000..7c197ce Binary files /dev/null and b/assets/contracts/transportation.png differ diff --git a/assets/fonts/m42.TTF b/assets/fonts/m42.TTF new file mode 100644 index 0000000..3609477 Binary files /dev/null and b/assets/fonts/m42.TTF differ diff --git a/assets/logo/Offre.png b/assets/logo/Offre.png new file mode 100644 index 0000000..70230f5 Binary files /dev/null and b/assets/logo/Offre.png differ diff --git a/assets/logo/logoblanc.png b/assets/logo/logoblanc.png new file mode 100644 index 0000000..ee79f5a Binary files /dev/null and b/assets/logo/logoblanc.png differ diff --git a/assets/logo/logoblancnotext.png b/assets/logo/logoblancnotext.png new file mode 100644 index 0000000..a48c638 Binary files /dev/null and b/assets/logo/logoblancnotext.png differ diff --git a/assets/logo/logonoir.png b/assets/logo/logonoir.png new file mode 100644 index 0000000..7d4783c Binary files /dev/null and b/assets/logo/logonoir.png differ diff --git a/assets/planets/planetproto.png b/assets/planets/planetproto.png new file mode 100644 index 0000000..3d500b4 Binary files /dev/null and b/assets/planets/planetproto.png differ diff --git a/assets/ressources/ANTIMATTER.png b/assets/ressources/ANTIMATTER.png new file mode 100644 index 0000000..bd8dffe Binary files /dev/null and b/assets/ressources/ANTIMATTER.png differ diff --git a/assets/ressources/medkit.png b/assets/ressources/medkit.png new file mode 100644 index 0000000..4491d9b Binary files /dev/null and b/assets/ressources/medkit.png differ diff --git a/assets/spaceships/spaceship.png b/assets/spaceships/spaceship.png new file mode 100644 index 0000000..acc67df Binary files /dev/null and b/assets/spaceships/spaceship.png differ diff --git a/assets/spaceships/spaceshiporbits.png b/assets/spaceships/spaceshiporbits.png new file mode 100644 index 0000000..344a342 Binary files /dev/null and b/assets/spaceships/spaceshiporbits.png differ diff --git a/js/api/agent/agent.js b/js/api/agent/agent.js index e69de29..c837c96 100644 --- a/js/api/agent/agent.js +++ b/js/api/agent/agent.js @@ -0,0 +1,105 @@ +'use strict'; +import { SpaceTraders } from "../config.js" + +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.shipsCpt = agent.shipCount; + } + + get_agent_system() { + let metaSystem = this.hq.split("-"); + return metaSystem[0] + "-" + metaSystem[1]; + } +} + +export class AgentBuilder { + static async create(symbol, faction, callback, email = "") { + const url = `${SpaceTraders.host}register`; + await $.ajax({ + url: url, + method: "POST", + headers: { "Content-Type": "application/json" }, + processData: false, + data: `{\n "faction": "${faction}",\n "symbol": "${symbol}",\n "email": "${email}"\n}`, + success: (reponse) => { + let agent = new Agent(reponse.data.agent, reponse.data.token) + callback(agent); + }, + }); + } + + static async get(token, callback){ + const url = `${SpaceTraders.host}my/agent`; + await $.ajax({ + url: url, + method: "GET", + headers: { + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + success: (reponse) => { + let agent = new Agent(reponse.data, token); + callback(agent); + }, + }); + } + + static async getPublic(symbol, callback) { + const url = `${SpaceTraders.host}agents/${symbol}`; + const headers = { Accept: "application/json" }; + await $.ajax({ + url: url, + method: "GET", + headers: headers, + success: (reponse) => { + let agent = new Agent(reponse.data); + callback(agent); + }, + }); + } + + static async list(limit, page, callback, agents = []) { + const url = `${SpaceTraders.host}agents`; + const headers = { Accept: "application/json" }; + const data = { limit, page }; + await $.ajax({ + url: url, + method: "GET", + headers: headers, + data: data, + success: (reponse) => { + reponse.data.forEach(agent => { + agents.push(agent); + }); + callback(agents, reponse.meta); + }, + }); + } + + static async listAll(callback) { + await this.list(1,1, (agents, meta) => { + let maxPage = meta.total / 20; + this.r_listing(1, maxPage, [], callback); + }); + } + + static async r_listing(page, maxPage, agents, callback) { + if (page < maxPage) { + this.list(20, page++,() => { + setTimeout(() => { + this.r_listing(page++, maxPage, agents, callback); + }, 1000); + }, agents); + } else { + callback(agents); + } + } +} + + + diff --git a/js/api/config.js b/js/api/config.js new file mode 100644 index 0000000..7108252 --- /dev/null +++ b/js/api/config.js @@ -0,0 +1,3 @@ +export const SpaceTraders = { + host: "https://api.spacetraders.io/v2/" +} \ No newline at end of file diff --git a/js/auth/login.js b/js/auth/login.js new file mode 100644 index 0000000..e69de29 diff --git a/js/auth/register.js b/js/auth/register.js new file mode 100644 index 0000000..e69de29 diff --git a/js/index.js b/js/index.js index fea19dc..32177ea 100644 --- a/js/index.js +++ b/js/index.js @@ -1,4 +1,13 @@ import {UIRenderer} from "./ui/templeting_engine.js"; +import { Agent, AgentBuilder } from "./api/agent/agent.js"; + +AgentBuilder.listAll((agents) => { + console.log(agents); +}); + +AgentBuilder.create("ZEUslkdjlka", "COSMIC", (agent) => { + console.log(agent); +}); let UI = new UIRenderer("html");