1
0
Fork 0

Use waypoints function where relevant

This commit is contained in:
Julien Dessaux 2023-06-07 00:22:52 +02:00
parent 458d08626f
commit 4d5384aa43
Signed by: adyxax
GPG key ID: F92E51B86E07177E

View file

@ -29,20 +29,21 @@ export async function system(ctx) {
// Retrieves a list of waypoints that have a specific ctx.trait like a SHIPYARD or a MARKETPLACE in the system ctx.symbol // Retrieves a list of waypoints that have a specific ctx.trait like a SHIPYARD or a MARKETPLACE in the system ctx.symbol
export async function trait(ctx) { export async function trait(ctx) {
const s = await system(ctx); const w = await waypoints(ctx);
return s.waypoints.filter(s => s.traits.some(t => t.symbol === ctx.trait)); return w.filter(s => s.traits.some(t => t.symbol === ctx.trait));
} }
// Retrieves a list of waypoints that have a specific ctx.type like ASTEROID_FIELD in the system ctx.symbol // Retrieves a list of waypoints that have a specific ctx.type like ASTEROID_FIELD in the system ctx.symbol
export async function type(ctx, response) { export async function type(ctx, response) {
const s = await system(ctx); const w = await waypoints(ctx);
return s.waypoints.filter(s => s.type === ctx.type); return w.filter(s => s.type === ctx.type);
} }
// Retrieves the system's information for ctx.symbol and caches it in the database // Retrieves the system's information for ctx.symbol and caches it in the database
export async function waypoints(ctx) { export async function waypoints(ctx) {
await system(ctx); await system(ctx);
let updated = db.getSystemUpdated(ctx.symbol); let updated = db.getSystemUpdated(ctx.symbol);
// TODO handle uncharted systems
if (updated === null) { if (updated === null) {
let waypoints = []; let waypoints = [];
for (let page=1; true; ++page) { for (let page=1; true; ++page) {