@shipload/sdk 1.0.0-next.44 → 1.0.0-next.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/shipload.d.ts +235 -39
- package/lib/shipload.js +1401 -157
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +1387 -158
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +81 -15
- package/lib/testing.js +374 -41
- package/lib/testing.js.map +1 -1
- package/lib/testing.m.js +375 -42
- package/lib/testing.m.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/gathering.test.ts +14 -1
- package/src/capabilities/gathering.ts +6 -5
- package/src/capabilities/modules.ts +4 -0
- package/src/contracts/server.ts +242 -28
- package/src/data/entities.json +93 -19
- package/src/data/item-ids.ts +12 -0
- package/src/data/items.json +76 -2
- package/src/data/kind-registry.json +10 -0
- package/src/data/metadata.ts +68 -0
- package/src/data/recipes-runtime.ts +1 -0
- package/src/data/recipes.json +720 -0
- package/src/derivation/capabilities.test.ts +11 -11
- package/src/derivation/capabilities.ts +42 -27
- package/src/derivation/index.ts +2 -0
- package/src/derivation/recipe-usage.test.ts +11 -7
- package/src/derivation/stars.test.ts +16 -0
- package/src/derivation/stars.ts +10 -0
- package/src/derivation/stratum.ts +11 -4
- package/src/entities/makers.ts +8 -1
- package/src/index-module.ts +5 -1
- package/src/managers/actions.ts +10 -0
- package/src/nft/buildImmutableData.ts +1 -1
- package/src/nft/description.ts +20 -11
- package/src/resolution/describe-module.ts +21 -8
- package/src/resolution/resolve-item.test.ts +12 -1
- package/src/resolution/resolve-item.ts +33 -33
- package/src/scheduling/projection.ts +8 -1
- package/src/subscriptions/manager.cluster.test.ts +7 -2
- package/src/subscriptions/types.ts +1 -0
- package/src/utils/cargo.test.ts +14 -0
- package/src/utils/cargo.ts +2 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {UInt16, UInt64} from '@wharfkit/antelope'
|
|
2
2
|
import type {UInt16Type, UInt64Type} from '@wharfkit/antelope'
|
|
3
3
|
import type {ResourceCategory} from '../types'
|
|
4
|
-
import {getItem} from '../data/catalog'
|
|
4
|
+
import {getItem, getModules} from '../data/catalog'
|
|
5
5
|
import {getEntityLayout} from '../data/recipes-runtime'
|
|
6
6
|
import {entityMetadata, itemMetadata} from '../data/metadata'
|
|
7
7
|
import {
|
|
@@ -26,25 +26,13 @@ import {
|
|
|
26
26
|
computeGeneratorCapabilities,
|
|
27
27
|
computeHaulerCapabilities,
|
|
28
28
|
computeLoaderCapabilities,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
computeContainerCapabilities,
|
|
32
|
-
computeContainerT2Capabilities,
|
|
29
|
+
computeBaseCapacity,
|
|
30
|
+
computeBaseHullmass,
|
|
33
31
|
computeStorageCapabilities,
|
|
34
32
|
} from '../derivation/capabilities'
|
|
35
33
|
import {applySlotMultiplierUint32} from '../entities/slot-multiplier'
|
|
36
34
|
import {categoryColors, componentIcon, itemAbbreviations, moduleIcon} from '../data/colors'
|
|
37
35
|
import type {ServerContract} from '../contracts'
|
|
38
|
-
import {
|
|
39
|
-
ITEM_CONTAINER_T1_PACKED,
|
|
40
|
-
ITEM_CONTAINER_T2_PACKED,
|
|
41
|
-
ITEM_EXTRACTOR_T1_PACKED,
|
|
42
|
-
ITEM_FACTORY_T1_PACKED,
|
|
43
|
-
ITEM_MASS_CATCHER_T1_PACKED,
|
|
44
|
-
ITEM_MASS_DRIVER_T1_PACKED,
|
|
45
|
-
ITEM_SHIP_T1_PACKED,
|
|
46
|
-
ITEM_WAREHOUSE_T1_PACKED,
|
|
47
|
-
} from '../data/item-ids'
|
|
48
36
|
|
|
49
37
|
export interface ResolvedItemStat {
|
|
50
38
|
key: string
|
|
@@ -68,6 +56,10 @@ export interface ResolvedModuleSlot {
|
|
|
68
56
|
capability?: string
|
|
69
57
|
installed: boolean
|
|
70
58
|
attributes?: {label: string; value: number}[]
|
|
59
|
+
slotLabel?: string
|
|
60
|
+
slotType?: string
|
|
61
|
+
outputPct?: number
|
|
62
|
+
maxTier?: number
|
|
71
63
|
}
|
|
72
64
|
|
|
73
65
|
export interface ResolvedItem {
|
|
@@ -217,7 +209,7 @@ function computeCapabilityGroup(
|
|
|
217
209
|
}
|
|
218
210
|
}
|
|
219
211
|
case MODULE_HAULER: {
|
|
220
|
-
const caps = computeHaulerCapabilities(stats)
|
|
212
|
+
const caps = computeHaulerCapabilities(stats, tier)
|
|
221
213
|
return {
|
|
222
214
|
capability: 'Hauling',
|
|
223
215
|
attributes: [
|
|
@@ -256,11 +248,22 @@ function computeCapabilityGroup(
|
|
|
256
248
|
}
|
|
257
249
|
}
|
|
258
250
|
|
|
251
|
+
// Recipe-less higher-tier modules reuse the T1 stat layout of their module type.
|
|
252
|
+
function decodeModuleStats(id: number, big: bigint): Record<string, number> {
|
|
253
|
+
const decoded = decodeCraftedItemStats(id, big)
|
|
254
|
+
if (Object.keys(decoded).length > 0) return decoded
|
|
255
|
+
const moduleType = getItem(id).moduleType
|
|
256
|
+
if (!moduleType) return decoded
|
|
257
|
+
const t1 = getModules({moduleType, tier: 1})[0]
|
|
258
|
+
if (!t1) return decoded
|
|
259
|
+
return decodeCraftedItemStats(Number(t1.id), big)
|
|
260
|
+
}
|
|
261
|
+
|
|
259
262
|
function resolveModule(id: number, stats?: UInt64Type): ResolvedItem {
|
|
260
263
|
const item = getItem(id)
|
|
261
264
|
let attributes: ResolvedAttributeGroup[] | undefined
|
|
262
265
|
if (stats !== undefined) {
|
|
263
|
-
const decoded =
|
|
266
|
+
const decoded = decodeModuleStats(id, toBigStats(stats))
|
|
264
267
|
const modType = getModuleCapabilityType(id)
|
|
265
268
|
const group = computeCapabilityGroup(modType, decoded, item.tier)
|
|
266
269
|
if (group) attributes = [group]
|
|
@@ -284,21 +287,9 @@ function hullCapsForEntity(
|
|
|
284
287
|
hullmass: number
|
|
285
288
|
capacity: number
|
|
286
289
|
} {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
case ITEM_WAREHOUSE_T1_PACKED:
|
|
291
|
-
return computeWarehouseHullCapabilities(decoded)
|
|
292
|
-
case ITEM_EXTRACTOR_T1_PACKED:
|
|
293
|
-
case ITEM_FACTORY_T1_PACKED:
|
|
294
|
-
case ITEM_MASS_DRIVER_T1_PACKED:
|
|
295
|
-
case ITEM_MASS_CATCHER_T1_PACKED:
|
|
296
|
-
case ITEM_CONTAINER_T1_PACKED:
|
|
297
|
-
return computeContainerCapabilities(decoded)
|
|
298
|
-
case ITEM_CONTAINER_T2_PACKED:
|
|
299
|
-
return computeContainerT2Capabilities(decoded)
|
|
300
|
-
default:
|
|
301
|
-
throw new Error(`resolveItem: no capacity formula wired for entity item ${itemId}`)
|
|
290
|
+
return {
|
|
291
|
+
hullmass: computeBaseHullmass(decoded),
|
|
292
|
+
capacity: computeBaseCapacity(itemId, decoded),
|
|
302
293
|
}
|
|
303
294
|
}
|
|
304
295
|
|
|
@@ -316,6 +307,7 @@ function resolveEntity(
|
|
|
316
307
|
const bigStats = toBigStats(stats)
|
|
317
308
|
const decoded = decodeCraftedItemStats(id, bigStats)
|
|
318
309
|
if (decoded.strength === undefined) decoded.strength = decodeStat(bigStats, 0)
|
|
310
|
+
if (decoded.density === undefined) decoded.density = decodeStat(bigStats, 1)
|
|
319
311
|
if (decoded.hardness === undefined) decoded.hardness = decodeStat(bigStats, 2)
|
|
320
312
|
const hullCaps = hullCapsForEntity(id, decoded)
|
|
321
313
|
attributes = [
|
|
@@ -332,11 +324,17 @@ function resolveEntity(
|
|
|
332
324
|
if (layout && layout.slots.length > 0) {
|
|
333
325
|
const slotLabels = entityMetadata[id]?.moduleSlotLabels ?? []
|
|
334
326
|
moduleSlots = layout.slots.map((slot, i) => {
|
|
327
|
+
const slotInfo = {
|
|
328
|
+
slotLabel: slotLabels[i] ?? slot.type,
|
|
329
|
+
slotType: slot.type,
|
|
330
|
+
outputPct: slot.outputPct,
|
|
331
|
+
maxTier: slot.maxTier,
|
|
332
|
+
}
|
|
335
333
|
const mod = modules?.[i]
|
|
336
334
|
if (mod?.installed) {
|
|
337
335
|
const modItemId = Number(mod.installed.item_id.value.toString())
|
|
338
336
|
const modStats = BigInt(mod.installed.stats.toString())
|
|
339
|
-
const decodedStats =
|
|
337
|
+
const decodedStats = decodeModuleStats(modItemId, modStats)
|
|
340
338
|
const modType = getModuleCapabilityType(modItemId)
|
|
341
339
|
let modName = 'Module'
|
|
342
340
|
let modTier = 1
|
|
@@ -353,11 +351,13 @@ function resolveEntity(
|
|
|
353
351
|
capability: group?.capability,
|
|
354
352
|
installed: true,
|
|
355
353
|
attributes: group?.attributes,
|
|
354
|
+
...slotInfo,
|
|
356
355
|
}
|
|
357
356
|
}
|
|
358
357
|
return {
|
|
359
358
|
name: slotLabels[i] ?? slot.type,
|
|
360
359
|
installed: false,
|
|
360
|
+
...slotInfo,
|
|
361
361
|
}
|
|
362
362
|
})
|
|
363
363
|
}
|
|
@@ -167,7 +167,14 @@ function recomputeCaps(entity: Projectable): ProjectedCaps | undefined {
|
|
|
167
167
|
loaderLanes: (caps.loaderLanes ?? []).map(toLoaderLane),
|
|
168
168
|
gathererLanes: (caps.gathererLanes ?? []).map(toGathererLane),
|
|
169
169
|
crafterLanes: (caps.crafterLanes ?? []).map(toCrafterLane),
|
|
170
|
-
hauler: caps.hauler
|
|
170
|
+
hauler: caps.hauler
|
|
171
|
+
? ServerContract.Types.hauler_stats.from({
|
|
172
|
+
capacity: caps.hauler.capacity,
|
|
173
|
+
efficiency: caps.hauler.efficiency,
|
|
174
|
+
drain: caps.hauler.drain,
|
|
175
|
+
capacity_by_tier: caps.hauler.capacityByTier,
|
|
176
|
+
})
|
|
177
|
+
: undefined,
|
|
171
178
|
launcher: caps.launcher
|
|
172
179
|
? ServerContract.Types.launcher_stats.from({
|
|
173
180
|
charge_rate: caps.launcher.chargeRate,
|
|
@@ -29,10 +29,15 @@ describe('cluster delta routing', () => {
|
|
|
29
29
|
sub_id: handle.subId,
|
|
30
30
|
hub_id: 42,
|
|
31
31
|
seq: 7,
|
|
32
|
-
cells: [{gx: 0, gy: 1, entity: 99}],
|
|
32
|
+
cells: [{gx: 0, gy: 1, entity: 99, type: 'warehouse'}],
|
|
33
33
|
})
|
|
34
34
|
expect(received).toEqual([
|
|
35
|
-
{
|
|
35
|
+
{
|
|
36
|
+
hubId: 42,
|
|
37
|
+
seq: 7,
|
|
38
|
+
cells: [{gx: 0, gy: 1, entity: 99, type: 'warehouse'}],
|
|
39
|
+
erased: false,
|
|
40
|
+
},
|
|
36
41
|
])
|
|
37
42
|
})
|
|
38
43
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {describe, expect, test} from 'bun:test'
|
|
2
|
+
import {cargoRef} from './cargo'
|
|
3
|
+
|
|
4
|
+
describe('cargoRef', () => {
|
|
5
|
+
test('forwards entity_id when provided', () => {
|
|
6
|
+
const ref = cargoRef({item_id: 10201, stats: 196849n, modules: [], entity_id: 42n})
|
|
7
|
+
expect(ref.entity_id).toBe(42n)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('omits entity_id when absent', () => {
|
|
11
|
+
const ref = cargoRef({item_id: 10201, stats: 196849n})
|
|
12
|
+
expect(ref.entity_id).toBeUndefined()
|
|
13
|
+
})
|
|
14
|
+
})
|
package/src/utils/cargo.ts
CHANGED
|
@@ -4,11 +4,13 @@ export function cargoRef(src: {
|
|
|
4
4
|
item_id: number
|
|
5
5
|
stats: bigint | number
|
|
6
6
|
modules?: ServerContract.Types.module_entry[]
|
|
7
|
+
entity_id?: bigint | number
|
|
7
8
|
}): ServerContract.ActionParams.Type.cargo_ref {
|
|
8
9
|
return {
|
|
9
10
|
item_id: src.item_id,
|
|
10
11
|
stats: src.stats,
|
|
11
12
|
modules: src.modules ?? [],
|
|
13
|
+
entity_id: src.entity_id,
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|