blob: c5093a616e0717e1534b0e3f0ec552ee485c56f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import { Cargo, CargoManifest } from '../model/cargo.ts';
export type CategorizedCargo = {
wanted: CargoManifest;
goods: CargoManifest;
};
// cargo is a ship.cargo object, want is an optional symbol
export function categorizeCargo(cargo: Cargo, want?: string): CategorizedCargo {
const wanted = cargo.inventory.filter(i => i.symbol === want || i.symbol === 'ANTIMATTER');
const goods = cargo.inventory.filter(i => i.symbol !== want && i.symbol !== 'ANTIMATTER');
const wobj = wanted.reduce(function(acc: CargoManifest, e) {
acc[e.symbol] = e.units;
return acc;
}, {});
const gobj = goods.reduce(function(acc: CargoManifest, e) {
acc[e.symbol] = e.units;
return acc;
}, {});
return {wanted: wobj, goods: gobj};
}
export function systemFromWaypoint(waypoint: string): string {
return waypoint.split('-').slice(0,2).join('-');
}
|