From fb75594636bf135f9847a4cc97ef3821f241dc3f Mon Sep 17 00:00:00 2001 From: Natalie Rose Date: Fri, 28 Aug 2026 13:36:23 +1000 Subject: [PATCH] Add get_buildings_resources --- lib/endpoints/body.test.ts | 14 +++ lib/endpoints/body.ts | 4 + lib/types/body.ts | 44 +++++++++ lib/types/schema.ts | 177 ++++++++++++++++++++++++++++++++++++- package-lock.json | 14 +-- package.json | 2 +- 6 files changed, 246 insertions(+), 9 deletions(-) diff --git a/lib/endpoints/body.test.ts b/lib/endpoints/body.test.ts index 557fb34..730afc1 100644 --- a/lib/endpoints/body.test.ts +++ b/lib/endpoints/body.test.ts @@ -23,6 +23,20 @@ test('getBuildings', async () => { ]); }); +test('getBuildingsResources', async () => { + const { result } = await lacuna.body.getBuildingsResources({ + body_id: empire.home_planet_id, + }); + expect(result?.buildings).toBeDefined(); + + const building = Object.values(result!.buildings)[0]; + expect(building.resources).toBeDefined(); + expect(typeof building.resources.food_hour).toBe('number'); + expect(typeof building.resources.happiness_hour).toBe('number'); + + expectMatchesApiSchema('body', 'get_buildings_resources', result); +}); + test('rearrangeBuildings', async () => { console.warn = jest.fn(); diff --git a/lib/endpoints/body.ts b/lib/endpoints/body.ts index 283eca1..be36f07 100644 --- a/lib/endpoints/body.ts +++ b/lib/endpoints/body.ts @@ -16,6 +16,10 @@ class Body extends Endpoint { return this.callWithSession('get_buildings', params); } + getBuildingsResources(params: B.GetBuildingsResourcesParams) { + return this.callWithSession('get_buildings_resources', params); + } + getStatus(params: B.GetStatusParams) { return this.callWithSession('get_status', params); } diff --git a/lib/types/body.ts b/lib/types/body.ts index 7cff0b1..492904c 100644 --- a/lib/types/body.ts +++ b/lib/types/body.ts @@ -24,6 +24,50 @@ export interface GetBuildingsResponse { }; } +export interface BuildingResources { + food_hour: number; + food_capacity: number; + water_hour: number; + water_capacity: number; + waste_hour: number; + waste_capacity: number; + energy_hour: number; + energy_capacity: number; + happiness_hour: number; + // ore_hour / ore_capacity / ore are all omitted for the Mining Ministry + // (its ore output is driven by deployed mining platforms, not the building). + ore_hour?: number; + ore_capacity?: number; + // Present only when the building produces that resource. + food?: { [type: string]: number }; + ore?: { [type: string]: number }; +} + +export interface BuildingResourcesSummary extends BuildingSummary { + resources: BuildingResources; + pending_build?: { seconds_remaining: number; start: string; end: string }; + work?: { seconds_remaining: number; start: string; end: string }; + repair_costs?: { food: number; water: number; energy: number; ore: number }; +} + +export interface GetBuildingsResourcesParams { + body_id: number; +} + +export interface GetBuildingsResourcesResponse { + body: { + surface_image: string; + }; + buildings: { + [index: string]: BuildingResourcesSummary; + }; + status: { + server: components['schemas']['server_status']; + empire?: components['schemas']['empire_status']; + body?: components['schemas']['body_status']; + }; +} + export interface GetStatusParams { body_id: number; } diff --git a/lib/types/schema.ts b/lib/types/schema.ts index c756f55..3ef4374 100644 --- a/lib/types/schema.ts +++ b/lib/types/schema.ts @@ -6269,7 +6269,7 @@ export interface paths { }; }; responses: { - /** @description Returns information about the current state of the empire. */ + /** @description Returns information about the current state of this body. Must be owned or a sitter of the current empire. */ 200: { headers: { [name: string]: unknown; @@ -6303,6 +6303,67 @@ export interface paths { patch?: never; trace?: never; }; + '/v2/body/get_body_status': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: { + content: { + 'application/json': { + body_id: string; + }; + }; + }; + responses: { + /** @description Usd in the Star Map. Returns public information about the given body. */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + id?: number; + jsonrpc?: string; + result?: { + body: components['schemas']['body_status']; + status?: { + server: components['schemas']['server_status']; + empire?: components['schemas']['empire_status']; + body?: components['schemas']['body_status']; + }; + }; + }; + }; + }; + /** @description RPC Error */ + 500: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['rpc_error']; + }; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/v2/body/get_buildings': { parameters: { query?: never; @@ -6367,6 +6428,70 @@ export interface paths { patch?: never; trace?: never; }; + '/v2/body/get_buildings_resources': { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get?: never; + put?: never; + post: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: { + content: { + 'application/json': { + body_id: string; + }; + }; + }; + responses: { + /** @description Like get_buildings, but every building entry additionally carries a `resources` object: hourly production/consumption and storage capacity for food/ore/water/waste/energy plus happiness_hour, and per-food-type / per-ore-type production breakdowns (each omitted when the building produces none of that resource). */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': { + id?: number; + jsonrpc?: string; + result?: { + buildings: components['schemas']['buildings_resources_list']; + body: { + surface_image: string; + }; + status: { + server: components['schemas']['server_status']; + empire?: components['schemas']['empire_status']; + body?: components['schemas']['body_status']; + }; + }; + }; + }; + }; + /** @description RPC Error */ + 500: { + headers: { + [name: string]: unknown; + }; + content: { + 'application/json': components['schemas']['rpc_error']; + }; + }; + }; + }; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; '/v2/body/repair_list': { parameters: { query?: never; @@ -81014,6 +81139,56 @@ export interface components { waste_capacity: number; happiness_hour: number; }; + building_resources: { + food_hour: number; + food_capacity: number; + energy_hour: number; + energy_capacity: number; + water_hour: number; + water_capacity: number; + waste_hour: number; + waste_capacity: number; + happiness_hour: number; + ore_hour?: number; + ore_capacity?: number; + /** @description Hourly production keyed by food type. */ + food?: { + [key: string]: number; + }; + /** @description Hourly production keyed by ore type. */ + ore?: { + [key: string]: number; + }; + }; + /** @description Keyed by building id. */ + buildings_resources_list: { + [key: string]: { + name: string; + x: number; + y: number; + url: string; + level: number; + image: string; + efficiency: number; + resources: components['schemas']['building_resources']; + pending_build?: { + seconds_remaining: number; + start: string; + end: string; + }; + work?: { + seconds_remaining: number; + start: string; + end: string; + }; + repair_costs?: { + food: number; + water: number; + energy: number; + ore: number; + }; + }; + }; building: { id: string; name: string; diff --git a/package-lock.json b/package-lock.json index 4df9d03..5cae66c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "proper-url-join": "^2.1.2" }, "devDependencies": { - "@tlecommunity/api-spec": "^1.2.2", + "@tlecommunity/api-spec": "^1.3.1", "@types/jest": "^30.0.0", "@types/proper-url-join": "^2.1.5", "ajv": "^8.20.0", @@ -1541,9 +1541,9 @@ } }, "node_modules/@tlecommunity/api-spec": { - "version": "1.2.2", - "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.2/api-spec-1.2.2.tgz", - "integrity": "sha512-7gFjtbKOrvzjz2vfvRgzJZPlMy3KrhtHRHWlFki/46RPjOrC0wO6ncp625ehCSml/0m01CVSadTnEkfE5BXinw==", + "version": "1.3.1", + "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.3.1/api-spec-1.3.1.tgz", + "integrity": "sha512-K19S0aIywQRhib1lUkXmkpO9hAMIQeHfC9g+Ko6YWN+iC0C6xRz4UFiycyIDqpwSqGoOdhzsQdNgkTq/QosNbA==", "dev": true, "license": "MIT" }, @@ -7169,9 +7169,9 @@ } }, "@tlecommunity/api-spec": { - "version": "1.2.2", - "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.2/api-spec-1.2.2.tgz", - "integrity": "sha512-7gFjtbKOrvzjz2vfvRgzJZPlMy3KrhtHRHWlFki/46RPjOrC0wO6ncp625ehCSml/0m01CVSadTnEkfE5BXinw==", + "version": "1.3.1", + "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.3.1/api-spec-1.3.1.tgz", + "integrity": "sha512-K19S0aIywQRhib1lUkXmkpO9hAMIQeHfC9g+Ko6YWN+iC0C6xRz4UFiycyIDqpwSqGoOdhzsQdNgkTq/QosNbA==", "dev": true }, "@tybys/wasm-util": { diff --git a/package.json b/package.json index e5c0a1b..bc9ffc7 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "author": "Natalie Rose ", "license": "MIT", "devDependencies": { - "@tlecommunity/api-spec": "^1.2.2", + "@tlecommunity/api-spec": "^1.3.1", "@types/jest": "^30.0.0", "@types/proper-url-join": "^2.1.5", "ajv": "^8.20.0", -- 2.51.2