@shipload/sdk 1.0.0-next.5 → 1.0.0-next.51

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.
Files changed (145) hide show
  1. package/lib/scan.d.ts +52 -0
  2. package/lib/scan.js +162 -0
  3. package/lib/scan.js.map +1 -0
  4. package/lib/scan.m.js +152 -0
  5. package/lib/scan.m.js.map +1 -0
  6. package/lib/shipload.d.ts +3167 -1353
  7. package/lib/shipload.js +13319 -5640
  8. package/lib/shipload.js.map +1 -1
  9. package/lib/shipload.m.js +13091 -5589
  10. package/lib/shipload.m.js.map +1 -1
  11. package/lib/testing.d.ts +1037 -0
  12. package/lib/testing.js +4363 -0
  13. package/lib/testing.js.map +1 -0
  14. package/lib/testing.m.js +4357 -0
  15. package/lib/testing.m.js.map +1 -0
  16. package/package.json +20 -2
  17. package/src/capabilities/craftable.ts +51 -0
  18. package/src/capabilities/crafting.test.ts +7 -0
  19. package/src/capabilities/crafting.ts +6 -7
  20. package/src/capabilities/gathering.test.ts +29 -0
  21. package/src/capabilities/gathering.ts +37 -19
  22. package/src/capabilities/index.ts +0 -1
  23. package/src/capabilities/modules.ts +22 -0
  24. package/src/capabilities/storage.ts +16 -1
  25. package/src/contracts/platform.ts +231 -3
  26. package/src/contracts/server.ts +1178 -511
  27. package/src/coordinates/address.ts +88 -0
  28. package/src/coordinates/constants.test.ts +15 -0
  29. package/src/coordinates/constants.ts +23 -0
  30. package/src/coordinates/index.ts +15 -0
  31. package/src/coordinates/memo.test.ts +47 -0
  32. package/src/coordinates/memo.ts +20 -0
  33. package/src/coordinates/permutation.ts +77 -0
  34. package/src/coordinates/regions.ts +48 -0
  35. package/src/coordinates/sectors.ts +115 -0
  36. package/src/data/capabilities.ts +31 -16
  37. package/src/data/capability-formulas.ts +21 -14
  38. package/src/data/catalog.ts +0 -5
  39. package/src/data/colors.ts +13 -47
  40. package/src/data/entities.json +154 -10
  41. package/src/data/item-ids.ts +31 -12
  42. package/src/data/items.json +192 -74
  43. package/src/data/kind-registry.json +131 -0
  44. package/src/data/kind-registry.ts +172 -0
  45. package/src/data/metadata.ts +166 -48
  46. package/src/data/recipes-runtime.ts +5 -23
  47. package/src/data/recipes.json +1003 -163
  48. package/src/derivation/build-methods.test.ts +13 -0
  49. package/src/derivation/build-methods.ts +48 -0
  50. package/src/derivation/capabilities.test.ts +151 -0
  51. package/src/derivation/capabilities.ts +527 -0
  52. package/src/derivation/capability-mappings.ts +58 -16
  53. package/src/derivation/crafting.ts +36 -33
  54. package/src/derivation/index.ts +28 -2
  55. package/src/derivation/recipe-usage.test.ts +81 -0
  56. package/src/derivation/recipe-usage.ts +141 -0
  57. package/src/derivation/reserve-regen.ts +34 -0
  58. package/src/derivation/resources.ts +98 -19
  59. package/src/derivation/rollups.test.ts +55 -0
  60. package/src/derivation/rollups.ts +56 -0
  61. package/src/derivation/stars.test.ts +67 -0
  62. package/src/derivation/stars.ts +25 -0
  63. package/src/derivation/stats.ts +6 -6
  64. package/src/derivation/stratum.ts +26 -22
  65. package/src/derivation/tiers.ts +40 -7
  66. package/src/derivation/upgrades.ts +14 -0
  67. package/src/derivation/wormhole.ts +141 -0
  68. package/src/entities/entity.ts +98 -0
  69. package/src/entities/gamestate.ts +3 -28
  70. package/src/entities/makers.ts +131 -134
  71. package/src/entities/slot-multiplier.ts +43 -0
  72. package/src/errors.ts +12 -16
  73. package/src/format.ts +26 -4
  74. package/src/index-module.ts +294 -34
  75. package/src/managers/actions.ts +616 -105
  76. package/src/managers/base.ts +6 -2
  77. package/src/managers/cluster.test.ts +39 -0
  78. package/src/managers/cluster.ts +53 -0
  79. package/src/managers/construction-types.ts +80 -0
  80. package/src/managers/construction.ts +412 -0
  81. package/src/managers/context.ts +29 -1
  82. package/src/managers/coordinates.ts +14 -0
  83. package/src/managers/entities.ts +27 -66
  84. package/src/managers/epochs.ts +40 -0
  85. package/src/managers/flatten-gather-plan.test.ts +80 -0
  86. package/src/managers/index.ts +20 -1
  87. package/src/managers/locations.ts +25 -29
  88. package/src/managers/nft.test.ts +14 -0
  89. package/src/managers/nft.ts +70 -0
  90. package/src/managers/players.ts +25 -0
  91. package/src/managers/plot.ts +122 -0
  92. package/src/nft/atomicassets.abi.json +1342 -0
  93. package/src/nft/atomicassets.ts +237 -0
  94. package/src/nft/atomicdata.ts +130 -0
  95. package/src/nft/buildImmutableData.ts +336 -0
  96. package/src/nft/description.ts +104 -36
  97. package/src/nft/index.ts +3 -0
  98. package/src/planner/index.ts +242 -0
  99. package/src/planner/planner.test.ts +325 -0
  100. package/src/resolution/describe-module.ts +43 -25
  101. package/src/resolution/display-name.ts +38 -10
  102. package/src/resolution/resolve-item.test.ts +48 -0
  103. package/src/resolution/resolve-item.ts +74 -47
  104. package/src/scan/index.ts +244 -0
  105. package/src/scan/scan-wasm.base64.ts +2 -0
  106. package/src/scheduling/accessor.ts +65 -23
  107. package/src/scheduling/availability.ts +108 -0
  108. package/src/scheduling/cancel.test.ts +348 -0
  109. package/src/scheduling/cancel.ts +209 -0
  110. package/src/scheduling/energy.ts +47 -0
  111. package/src/scheduling/idle-resolve.ts +45 -0
  112. package/src/scheduling/lane-core.ts +128 -0
  113. package/src/scheduling/lanes.test.ts +249 -0
  114. package/src/scheduling/lanes.ts +198 -0
  115. package/src/scheduling/projection.ts +210 -107
  116. package/src/scheduling/schedule.ts +240 -117
  117. package/src/scheduling/task-cargo.ts +46 -0
  118. package/src/scheduling/unwrap.test.ts +86 -0
  119. package/src/scheduling/unwrap.ts +190 -0
  120. package/src/shipload.ts +26 -1
  121. package/src/subscriptions/manager.cluster.test.ts +51 -0
  122. package/src/subscriptions/manager.ts +245 -172
  123. package/src/subscriptions/mappers.ts +5 -8
  124. package/src/subscriptions/types.ts +28 -3
  125. package/src/testing/catalog-hash.ts +19 -0
  126. package/src/testing/index.ts +2 -0
  127. package/src/testing/projection-parity.ts +167 -0
  128. package/src/travel/reach.ts +23 -0
  129. package/src/travel/route-planner.ts +277 -0
  130. package/src/travel/route-simulator.ts +174 -0
  131. package/src/travel/travel.ts +175 -118
  132. package/src/types/capabilities.ts +29 -6
  133. package/src/types/entity.ts +3 -3
  134. package/src/types/index.ts +0 -1
  135. package/src/types.ts +39 -14
  136. package/src/utils/cargo.test.ts +14 -0
  137. package/src/utils/cargo.ts +29 -0
  138. package/src/utils/display-name.ts +70 -0
  139. package/src/utils/system.ts +36 -24
  140. package/src/capabilities/loading.ts +0 -8
  141. package/src/entities/container.ts +0 -123
  142. package/src/entities/ship-deploy.ts +0 -295
  143. package/src/entities/ship.ts +0 -221
  144. package/src/entities/warehouse.ts +0 -127
  145. package/src/types/entity-traits.ts +0 -69
@@ -1,221 +0,0 @@
1
- import {type UInt16, type UInt16Type, UInt32, UInt64, type UInt64Type} from '@wharfkit/antelope'
2
- import {ServerContract} from '../contracts'
3
- import {Coordinates, type CoordinatesType} from '../types'
4
- import {
5
- type FloatPosition,
6
- getDestinationLocation,
7
- getInterpolatedPosition,
8
- getPositionAt,
9
- getFlightOrigin as travelGetFlightOrigin,
10
- } from '../travel/travel'
11
- import {
12
- type ProjectedEntity,
13
- projectFromCurrentState as sharedProjectFromCurrentState,
14
- projectFromCurrentStateAt as sharedProjectFromCurrentStateAt,
15
- } from '../scheduling/projection'
16
- import {Location} from './location'
17
- import {ScheduleAccessor} from '../scheduling/accessor'
18
- import {InventoryAccessor} from './inventory-accessor'
19
- import type {EntityInventory} from './entity-inventory'
20
- import {
21
- energyPercent as calcEnergyPercent,
22
- needsRecharge as calcNeedsRecharge,
23
- hasEnergyForDistance,
24
- maxTravelDistance,
25
- } from '../capabilities/movement'
26
- import * as schedule from '../scheduling/schedule'
27
-
28
- export interface PackedModuleInput {
29
- itemId: UInt16Type
30
- stats: UInt64Type
31
- }
32
-
33
- export interface ShipStateInput {
34
- id: UInt64Type
35
- owner: string
36
- name: string
37
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
38
- hullmass?: number
39
- capacity?: number
40
- energy?: number
41
- modules?: PackedModuleInput[]
42
- schedule?: ServerContract.Types.schedule
43
- cargo?: ServerContract.Types.cargo_item[]
44
- }
45
-
46
- type MovementEntity = {
47
- engines: ServerContract.Types.movement_stats
48
- generator: ServerContract.Types.energy_stats
49
- energy: UInt16
50
- }
51
-
52
- export class Ship extends ServerContract.Types.entity_info {
53
- private _sched?: ScheduleAccessor
54
- private _inv?: InventoryAccessor
55
-
56
- get name(): string {
57
- return this.entity_name
58
- }
59
-
60
- get entityClass(): 'mobile' {
61
- return 'mobile'
62
- }
63
-
64
- get canUndeploy(): boolean {
65
- return true
66
- }
67
-
68
- get inv(): InventoryAccessor {
69
- this._inv ??= new InventoryAccessor(this)
70
- return this._inv
71
- }
72
-
73
- get inventory(): EntityInventory[] {
74
- return this.inv.items
75
- }
76
-
77
- get sched(): ScheduleAccessor {
78
- this._sched ??= new ScheduleAccessor(this)
79
- return this._sched
80
- }
81
-
82
- get maxDistance(): UInt32 {
83
- if (!this.generator || !this.engines) return UInt32.from(0)
84
- return maxTravelDistance(this as MovementEntity)
85
- }
86
-
87
- get isIdle(): boolean {
88
- return this.is_idle
89
- }
90
-
91
- getFlightOrigin(flightTaskIndex: number): Coordinates {
92
- return Coordinates.from(travelGetFlightOrigin(this, flightTaskIndex))
93
- }
94
-
95
- destinationLocation(): Coordinates | undefined {
96
- const dest = getDestinationLocation(this)
97
- return dest ? Coordinates.from(dest) : undefined
98
- }
99
-
100
- /** Chain-tile coordinates at `now`. For smooth visual position use interpolatedPositionAt. */
101
- positionAt(now: Date): Coordinates {
102
- const taskIndex = this.sched.currentTaskIndex(now)
103
- const progress = this.sched.currentTaskProgress(now)
104
- return Coordinates.from(getPositionAt(this, taskIndex, progress))
105
- }
106
-
107
- interpolatedPositionAt(now: Date): FloatPosition {
108
- const taskIndex = this.sched.currentTaskIndex(now)
109
- const progress = this.sched.currentTaskProgressFloat(now)
110
- return getInterpolatedPosition(this, taskIndex, progress)
111
- }
112
-
113
- isInFlight(now: Date): boolean {
114
- return schedule.isInFlight(this, now)
115
- }
116
-
117
- isRecharging(now: Date): boolean {
118
- return schedule.isRecharging(this, now)
119
- }
120
-
121
- isLoading(now: Date): boolean {
122
- return schedule.isLoading(this, now)
123
- }
124
-
125
- isUnloading(now: Date): boolean {
126
- return schedule.isUnloading(this, now)
127
- }
128
-
129
- isGathering(now: Date): boolean {
130
- return schedule.isGathering(this, now)
131
- }
132
-
133
- get hasEngines(): boolean {
134
- return this.engines !== undefined
135
- }
136
-
137
- get hasGenerator(): boolean {
138
- return this.generator !== undefined
139
- }
140
-
141
- get hasGatherer(): boolean {
142
- return this.gatherer !== undefined
143
- }
144
-
145
- get hasWarp(): boolean {
146
- return this.warp !== undefined
147
- }
148
-
149
- project(): ProjectedEntity {
150
- return sharedProjectFromCurrentState(this)
151
- }
152
-
153
- projectAt(now: Date): ProjectedEntity {
154
- return sharedProjectFromCurrentStateAt(this, now)
155
- }
156
-
157
- get location(): Location {
158
- return Location.from(this.coordinates)
159
- }
160
-
161
- get totalCargoMass(): UInt64 {
162
- return this.inv.totalMass
163
- }
164
-
165
- get totalMass(): UInt64 {
166
- let mass = UInt64.from(this.hullmass ?? 0).adding(this.totalCargoMass)
167
- if (this.loaders) {
168
- mass = mass.adding(UInt64.from(this.loaders.mass).multiplying(this.loaders.quantity))
169
- }
170
- return mass
171
- }
172
-
173
- get maxCapacity(): UInt64 {
174
- return UInt64.from(this.capacity)
175
- }
176
-
177
- hasSpace(goodMass: UInt64, quantity: number): boolean {
178
- return this.totalMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
179
- }
180
-
181
- get availableCapacity(): UInt64 {
182
- return this.totalMass.gte(this.maxCapacity)
183
- ? UInt64.from(0)
184
- : this.maxCapacity.subtracting(this.totalMass)
185
- }
186
-
187
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
188
- return this.inv.forItem(goodId)
189
- }
190
-
191
- get sellableCargo(): EntityInventory[] {
192
- return this.inv.sellable
193
- }
194
-
195
- get hasSellableCargo(): boolean {
196
- return this.inv.hasSellable
197
- }
198
-
199
- get sellableGoodsCount(): number {
200
- return this.inv.sellableCount
201
- }
202
-
203
- get isFull(): boolean {
204
- return this.totalMass.gte(this.maxCapacity)
205
- }
206
-
207
- get energyPercent(): number {
208
- if (!this.generator || this.energy === undefined) return 0
209
- return calcEnergyPercent(this as MovementEntity)
210
- }
211
-
212
- get needsRecharge(): boolean {
213
- if (!this.generator || this.energy === undefined) return false
214
- return calcNeedsRecharge(this as MovementEntity)
215
- }
216
-
217
- hasEnergyFor(distance: UInt64): boolean {
218
- if (!this.engines || !this.generator || this.energy === undefined) return false
219
- return hasEnergyForDistance(this as MovementEntity, distance)
220
- }
221
- }
@@ -1,127 +0,0 @@
1
- import {UInt64, type UInt64Type} from '@wharfkit/antelope'
2
- import {ServerContract} from '../contracts'
3
- import type {CoordinatesType} from '../types'
4
- import {Location} from './location'
5
- import {ScheduleAccessor} from '../scheduling/accessor'
6
- import {InventoryAccessor} from './inventory-accessor'
7
- import type {EntityInventory} from './entity-inventory'
8
- import * as schedule from '../scheduling/schedule'
9
- import type {PackedModuleInput} from './ship'
10
- import {decodeCraftedItemStats} from '../derivation/crafting'
11
- import {getModuleCapabilityType, MODULE_LOADER} from '../capabilities/modules'
12
- import {computeLoaderCapabilities} from './ship-deploy'
13
-
14
- export interface WarehouseStateInput {
15
- id: UInt64Type
16
- owner: string
17
- name: string
18
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
19
- hullmass?: number
20
- capacity: number
21
- modules?: PackedModuleInput[]
22
- schedule?: ServerContract.Types.schedule
23
- cargo?: ServerContract.Types.cargo_item[]
24
- }
25
-
26
- export class Warehouse extends ServerContract.Types.entity_info {
27
- private _sched?: ScheduleAccessor
28
- private _inv?: InventoryAccessor
29
-
30
- get name(): string {
31
- return this.entity_name
32
- }
33
-
34
- get entityClass(): 'building' {
35
- return 'building'
36
- }
37
-
38
- get canDemolish(): boolean {
39
- return true
40
- }
41
-
42
- get inv(): InventoryAccessor {
43
- this._inv ??= new InventoryAccessor(this)
44
- return this._inv
45
- }
46
-
47
- get inventory(): EntityInventory[] {
48
- return this.inv.items
49
- }
50
-
51
- get sched(): ScheduleAccessor {
52
- this._sched ??= new ScheduleAccessor(this)
53
- return this._sched
54
- }
55
-
56
- get isIdle(): boolean {
57
- return this.is_idle
58
- }
59
-
60
- isLoading(now: Date): boolean {
61
- return schedule.isLoading(this, now)
62
- }
63
-
64
- isUnloading(now: Date): boolean {
65
- return schedule.isUnloading(this, now)
66
- }
67
-
68
- get location(): Location {
69
- return Location.from(this.coordinates)
70
- }
71
-
72
- get totalCargoMass(): UInt64 {
73
- return this.inv.totalMass
74
- }
75
-
76
- get maxCapacity(): UInt64 {
77
- return UInt64.from(this.capacity)
78
- }
79
-
80
- get availableCapacity(): UInt64 {
81
- const cargo = this.totalCargoMass
82
- return cargo.gte(this.maxCapacity) ? UInt64.from(0) : this.maxCapacity.subtracting(cargo)
83
- }
84
-
85
- hasSpace(goodMass: UInt64, quantity: number): boolean {
86
- return this.totalCargoMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
87
- }
88
-
89
- get isFull(): boolean {
90
- return this.totalCargoMass.gte(this.maxCapacity)
91
- }
92
-
93
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
94
- return this.inv.forItem(goodId)
95
- }
96
-
97
- get orbitalAltitude(): number {
98
- return this.coordinates.z?.toNumber() || 0
99
- }
100
-
101
- get totalMass(): UInt64 {
102
- const hull = this.hullmass ? UInt64.from(this.hullmass) : UInt64.from(0)
103
- return hull.adding(this.totalCargoMass)
104
- }
105
- }
106
-
107
- export function computeWarehouseCapabilities(modules: {itemId: number; stats: bigint}[]): {
108
- loaders?: {mass: number; thrust: number; quantity: number}
109
- } {
110
- const warehouse: {loaders?: {mass: number; thrust: number; quantity: number}} = {}
111
-
112
- const loaderModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_LOADER)
113
- if (loaderModules.length > 0) {
114
- let totalMass = 0
115
- let totalThrust = 0
116
- let totalQuantity = 0
117
- for (const m of loaderModules) {
118
- const caps = computeLoaderCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
119
- totalMass += caps.mass
120
- totalThrust += caps.thrust
121
- totalQuantity += caps.quantity
122
- }
123
- warehouse.loaders = {mass: totalMass, thrust: totalThrust, quantity: totalQuantity}
124
- }
125
-
126
- return warehouse
127
- }
@@ -1,69 +0,0 @@
1
- import {Name} from '@wharfkit/antelope'
2
-
3
- export const ENTITY_SHIP = Name.from('ship')
4
- export const ENTITY_WAREHOUSE = Name.from('warehouse')
5
- export const ENTITY_CONTAINER = Name.from('container')
6
-
7
- export type EntityTypeName = 'ship' | 'warehouse' | 'container'
8
-
9
- export interface EntityTraits {
10
- typeName: Name
11
- isMovable: boolean
12
- hasEnergy: boolean
13
- hasLoaders: boolean
14
- notFoundError: string
15
- }
16
-
17
- export const shipTraits: EntityTraits = {
18
- typeName: ENTITY_SHIP,
19
- isMovable: true,
20
- hasEnergy: true,
21
- hasLoaders: true,
22
-
23
- notFoundError: 'ship not found',
24
- }
25
-
26
- export const warehouseTraits: EntityTraits = {
27
- typeName: ENTITY_WAREHOUSE,
28
- isMovable: false,
29
- hasEnergy: false,
30
- hasLoaders: true,
31
-
32
- notFoundError: 'warehouse not found',
33
- }
34
-
35
- export const containerTraits: EntityTraits = {
36
- typeName: ENTITY_CONTAINER,
37
- isMovable: true,
38
- hasEnergy: false,
39
- hasLoaders: false,
40
-
41
- notFoundError: 'container not found',
42
- }
43
-
44
- export function getEntityTraits(entityType: Name | EntityTypeName): EntityTraits {
45
- const typeName = typeof entityType === 'string' ? entityType : entityType.toString()
46
-
47
- switch (typeName) {
48
- case 'ship':
49
- return shipTraits
50
- case 'warehouse':
51
- return warehouseTraits
52
- case 'container':
53
- return containerTraits
54
- default:
55
- throw new Error(`Unknown entity type: ${typeName}`)
56
- }
57
- }
58
-
59
- export function isShip(entity: {type?: Name}): boolean {
60
- return entity.type?.equals(ENTITY_SHIP) ?? false
61
- }
62
-
63
- export function isWarehouse(entity: {type?: Name}): boolean {
64
- return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
65
- }
66
-
67
- export function isContainer(entity: {type?: Name}): boolean {
68
- return entity.type?.equals(ENTITY_CONTAINER) ?? false
69
- }