diff options
author | Julien Dessaux | 2024-05-17 22:01:29 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-05-17 22:01:29 +0200 |
commit | ccbfd9deb947c776782b80229be4513485321a88 (patch) | |
tree | 7f7f5e7816cabe4a88ed9c66ca9b29762fccb1e5 /nodejs/lib | |
parent | [node] Added agent class, and fixed contract updates (diff) | |
download | spacetraders-ccbfd9deb947c776782b80229be4513485321a88.tar.gz spacetraders-ccbfd9deb947c776782b80229be4513485321a88.tar.bz2 spacetraders-ccbfd9deb947c776782b80229be4513485321a88.zip |
[node] fixed and optimized contracting
Diffstat (limited to '')
-rw-r--r-- | nodejs/lib/contracts.ts | 8 | ||||
-rw-r--r-- | nodejs/lib/ships.ts | 24 |
2 files changed, 19 insertions, 13 deletions
diff --git a/nodejs/lib/contracts.ts b/nodejs/lib/contracts.ts index 009c853..f9ba212 100644 --- a/nodejs/lib/contracts.ts +++ b/nodejs/lib/contracts.ts @@ -53,8 +53,8 @@ export class Contract { debugLog(response); throw response; } - this.accepted = contract.accepted; - this.terms = contract.terms; + this.accepted = response.data.contract.accepted; + this.terms = response.data.contract.terms; setAgent(response.data.agent); } async deliver(ship: Ship): Promise<void> { @@ -84,7 +84,7 @@ export class Contract { throw response; } } - this.terms = contract.terms; + this.terms = response.data.contract.terms; ship.cargo = response.data.cargo; if(response.data.contract.terms.deliver[0].unitsRequired <= response.data.contract.terms.deliver[0].unitsFulfilled) { return await this.fulfill(); @@ -100,6 +100,6 @@ export class Contract { } setAgent(response.data.agent); this.fulfilled = true; - this.terms = contract.terms; + this.terms = response.data.contract.terms; } }; diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts index 920cc21..e4875f8 100644 --- a/nodejs/lib/ships.ts +++ b/nodejs/lib/ships.ts @@ -25,15 +25,6 @@ import { shortestPath, } from './utils.ts'; -export async function getShips(): Promise<Array<Ship>> { - const response = await send<Array<Ship>>({endpoint: `/my/ships`, page: 1}); - if (response.error) { - debugLog(response); - throw response; - } - return response.data.map(ship => new Ship(ship)); -} - export class Ship { cargo: Cargo; cooldown: Cooldown; @@ -228,3 +219,18 @@ export class Ship { return this.cargo; } } + +let myShips: Array<Ship> = []; + +export function getShips(): Array<Ship> { + return myShips; +} + +export async function initShips(): Promise<void> { + const response = await send<Array<Ship>>({endpoint: `/my/ships`, page: 1}); + if (response.error) { + debugLog(response); + throw response; + } + myShips = response.data.map(ship => new Ship(ship)); +} |