summaryrefslogtreecommitdiff
path: root/nodejs/lib/agent.ts
diff options
context:
space:
mode:
authorJulien Dessaux2024-05-15 23:49:33 +0200
committerJulien Dessaux2024-05-15 23:49:33 +0200
commit6504e44ffa97965e47e893b55621d2d04003d519 (patch)
tree18b416bdd03988b5e2215e8e4c1771b06e7f4084 /nodejs/lib/agent.ts
parent[node] updated dependencies (diff)
downloadspacetraders-6504e44ffa97965e47e893b55621d2d04003d519.tar.gz
spacetraders-6504e44ffa97965e47e893b55621d2d04003d519.tar.bz2
spacetraders-6504e44ffa97965e47e893b55621d2d04003d519.zip
[node] Added agent class, and fixed contract updates
Diffstat (limited to 'nodejs/lib/agent.ts')
-rw-r--r--nodejs/lib/agent.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/nodejs/lib/agent.ts b/nodejs/lib/agent.ts
new file mode 100644
index 0000000..ee7200c
--- /dev/null
+++ b/nodejs/lib/agent.ts
@@ -0,0 +1,45 @@
+import { debugLog, send } from './api.ts';
+
+export class Agent {
+ accountId: string;
+ credits: number;
+ headquarters: string;
+ shipCount: number;
+ startingFaction: string;
+ symbol: string;
+ constructor() {
+ this.accountId = "";
+ this.credits = 0;
+ this.headquarters = "";
+ this.shipCount = 0;
+ this.startingFaction = "";
+ this.symbol = "";
+ }
+ set(agent: Agent) {
+ this.accountId = agent.accountId;
+ this.credits = agent.credits;
+ this.headquarters = agent.headquarters;
+ this.shipCount = agent.shipCount;
+ this.startingFaction = agent.startingFaction;
+ this.symbol = agent.symbol;
+ }
+};
+
+let myAgent : Agent = new Agent();
+
+export function getAgent(): Agent {
+ return myAgent;
+}
+
+export async function initAgent(): Promise<void> {
+ const response = await send<Agent>({endpoint: `/my/agent`, page: 1});
+ if (response.error) {
+ debugLog(response);
+ throw response;
+ }
+ myAgent.set(response.data);
+}
+
+export function setAgent(agent: Agent): void {
+ myAgent.set(agent);
+}