From de0251bc22d554e2ace4d2d3d061dc1054656bcd Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 13 May 2024 23:45:45 +0200 Subject: [node] Big Contracts lib refactoring --- nodejs/automation/contracting.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'nodejs/automation/contracting.ts') diff --git a/nodejs/automation/contracting.ts b/nodejs/automation/contracting.ts index 9ac5d2f..4648b0d 100644 --- a/nodejs/automation/contracting.ts +++ b/nodejs/automation/contracting.ts @@ -1,10 +1,8 @@ import { debugLog } from '../lib/api.ts'; import { Ship } from '../lib/ships.ts'; -import { Contract } from '../lib/types.ts'; import * as mining from './mining.js'; import * as selling from './selling.js'; -import * as dbContracts from '../database/contracts.ts'; -import * as libContracts from '../lib/contracts.ts'; +import { Contract, getContracts } from '../lib/contracts.ts'; import * as libSystems from '../lib/systems.ts'; import * as systems from '../lib/systems.ts'; import { @@ -12,7 +10,7 @@ import { } from '../lib/utils.ts'; export async function run(ship: Ship): Promise { - const contracts = await libContracts.getContracts(); + const contracts = await getContracts(); const active = contracts.filter(function(c) { if (c.fulfilled) return false; const deadline = new Date(c.terms.deadline).getTime(); @@ -29,7 +27,7 @@ export async function run(ship: Ship): Promise { async function runOne(contract: Contract, ship: Ship): Promise { debugLog(contract); - await libContracts.accept(contract); + await contract.accept(); switch(contract.type) { case 'PROCUREMENT': //if (contract.terms.deliver[0].tradeSymbol.match(/_ORE$/)) { @@ -58,7 +56,7 @@ async function runOreProcurement(contract: Contract, ship: Ship): Promise break; case deliveryPoint.symbol: if (goodCargo !== undefined) { // we could be here if a client restart happens right after selling before we navigate away - contract = await libContracts.deliver(contract, ship); + await contract.deliver(ship); if (contract.fulfilled) return; } await ship.navigate(asteroid); @@ -117,7 +115,7 @@ async function runTradeProcurement(contract: Contract, ship: Ship): Promise