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