skamkraft_proto
ambigipathyv ago%!(EXTRA string=1 year)
parent 81277ff164
commit ff3f7235f3
  1. 17
      js/skama_code/api/agent.js
  2. 2
      js/skama_code/api/config.js
  3. 56
      js/skama_code/api/system.js
  4. 5
      js/skama_code/commun/my.js

@ -4,6 +4,8 @@ import { SpaceTraders } from "./config.js"
export class My {
static agent = null;
static temp_engine = null;
static canvas_renderer = null;
}
export class Agent {
@ -23,6 +25,11 @@ export class Agent {
}
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({
@ -94,22 +101,22 @@ export class AgentBuilder {
});
}
static list_all(callback, end = false) {
static list_all(callback) {
this.list(20, 1, (agents, meta) => {
let maxPage = meta.total / 20;
this.#r_listing(2, maxPage, agents, callback, end);
this.#r_listing(2, maxPage, agents, callback);
});
}
static #r_listing(page, maxPage, agents, callback, end) {
static #r_listing(page, maxPage, agents, callback) {
if (page < maxPage) {
this.list(20, page++,() => {
setTimeout(() => {
if (!end) {
if (!this.end) {
callback(agents);
agents = [];
}
this.#r_listing(page++, maxPage, agents, callback, end);
if (!this.stopped) this.#r_listing(page++, maxPage, agents, callback, end);
}, 1000);
}, agents);
} else {

@ -3,5 +3,5 @@
export const SpaceTraders = {
host: "https://api.spacetraders.io/v2",
limit_max: 20,
timing: 1000,
}

@ -12,9 +12,15 @@ export class System {
this.type = data.type;
this.position = new Position(data.x, data.y);
this.factions = data.factions;
this.stopped = false;
this.end = false;
}
get(name, callback, error_handler) {
when_end() {
this.end = true;
}
get_planet(name, callback, error_handler) {
const url = `${SpaceTraders.host}/systems/${this.name}/waypoints/${name}`;
$.ajax({
url: url,
@ -29,7 +35,7 @@ export class System {
});
}
list(limit, page, callback, planets = []) {
list_planets(limit, page, callback, planets = []) {
const url = `${SpaceTraders.host}/systems/${this.name}/waypoints`
$.ajax({
url: url,
@ -47,23 +53,27 @@ export class System {
});
}
list_all(callback, end = false) {
this.list(20, 1, (planets, 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, end) {
#r_listing(page, maxPage, planets, callback) {
if (page < maxPage) {
this.list(20, page++, () => {
this.list_planets(20, page++, () => {
setTimeout(() => {
if (!end) {
callback(planets);
planets = [];
}
this.#r_listing(page++, maxPage, planets, callback, end);
}, 1000);
if (!this.stopped) this.#r_listing(page++, maxPage, planets, callback, end);
}, SpaceTraders.timing);
}, planets);
} else {
callback(planets);
@ -72,6 +82,13 @@ export class System {
}
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("-");
}
@ -109,24 +126,27 @@ export class SystemBuilder {
});
}
static list_all(callback, end = false) {
this.list(20, 1, (systems, meta) => {
let maxPage = meta.total / 20;
this.#r_listing(2, maxPage, systems, callback, end);
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);
});
}
static #r_listing(page, maxPage, systems, callback, end) {
#r_listing(systems, callback) {
if (page < maxPage) {
this.list(20, page++, () => {
SystemBuilder.list(20, this.page++, () => {
setTimeout(() => {
if (!end) {
console.log(systems);
if (!this.end) {
callback(systems);
systems = [];
}
this.#r_listing(page++, maxPage, systems, callback, end);
}, 1000);
if (!this.stopped) this.#r_listing(page++, maxPage, systems, callback);
}, SpaceTraders.timing);
}, systems);
} else {
callback(systems);

@ -0,0 +1,5 @@
export class My {
static agent = null;
static temp_engine = null;
static canvas_renderer = null;
}
Loading…
Cancel
Save