Added agente class

vinayak
anulax1225 ago%!(EXTRA string=1 year)
parent dcec328025
commit 35c007aa8d
  1. BIN
      assets/contracts/procurement.png
  2. BIN
      assets/contracts/shuttle.png
  3. BIN
      assets/contracts/transportation.png
  4. BIN
      assets/fonts/m42.TTF
  5. BIN
      assets/logo/Offre.png
  6. BIN
      assets/logo/logoblanc.png
  7. BIN
      assets/logo/logoblancnotext.png
  8. BIN
      assets/logo/logonoir.png
  9. BIN
      assets/planets/planetproto.png
  10. BIN
      assets/ressources/ANTIMATTER.png
  11. BIN
      assets/ressources/medkit.png
  12. BIN
      assets/spaceships/spaceship.png
  13. BIN
      assets/spaceships/spaceshiporbits.png
  14. 105
      js/api/agent/agent.js
  15. 3
      js/api/config.js
  16. 0
      js/auth/login.js
  17. 0
      js/auth/register.js
  18. 9
      js/index.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

@ -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);
}
}
}

@ -0,0 +1,3 @@
export const SpaceTraders = {
host: "https://api.spacetraders.io/v2/"
}

@ -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");

Loading…
Cancel
Save