@shipload/sdk 1.0.0-next.10 → 1.0.0-next.12

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 (39) hide show
  1. package/lib/shipload.d.ts +759 -868
  2. package/lib/shipload.js +2463 -2588
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +2432 -2557
  5. package/lib/shipload.m.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/data/entities.json +13 -0
  8. package/src/data/item-ids.ts +1 -0
  9. package/src/data/items.json +6 -0
  10. package/src/data/kind-registry.json +78 -0
  11. package/src/data/kind-registry.ts +133 -0
  12. package/src/data/metadata.ts +6 -0
  13. package/src/data/recipes.json +57 -0
  14. package/src/derivation/capabilities.ts +397 -0
  15. package/src/derivation/crafting.ts +1 -1
  16. package/src/entities/entity.ts +98 -0
  17. package/src/entities/makers.ts +76 -170
  18. package/src/errors.ts +10 -13
  19. package/src/index-module.ts +39 -22
  20. package/src/managers/entities.ts +18 -80
  21. package/src/managers/index.ts +1 -1
  22. package/src/nft/atomicdata.ts +5 -0
  23. package/src/nft/description.ts +1 -1
  24. package/src/resolution/resolve-item.ts +3 -2
  25. package/src/scheduling/projection.ts +2 -2
  26. package/src/subscriptions/manager.ts +3 -5
  27. package/src/subscriptions/mappers.ts +3 -8
  28. package/src/subscriptions/types.ts +2 -2
  29. package/src/testing/catalog-hash.ts +19 -0
  30. package/src/testing/index.ts +2 -0
  31. package/src/testing/projection-parity.ts +143 -0
  32. package/src/types/index.ts +0 -1
  33. package/src/types.ts +0 -9
  34. package/src/entities/container.ts +0 -123
  35. package/src/entities/extractor.ts +0 -144
  36. package/src/entities/ship-deploy.ts +0 -316
  37. package/src/entities/ship.ts +0 -221
  38. package/src/entities/warehouse.ts +0 -136
  39. package/src/types/entity-traits.ts +0 -132
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "1.0.0-next.10",
4
+ "version": "1.0.0-next.12",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -66,6 +66,19 @@
66
66
  }
67
67
  ]
68
68
  },
69
+ {
70
+ "entityItemId": 10204,
71
+ "slots": [
72
+ {
73
+ "type": "generator",
74
+ "outputPct": 100
75
+ },
76
+ {
77
+ "type": "crafter",
78
+ "outputPct": 100
79
+ }
80
+ ]
81
+ },
69
82
  {
70
83
  "entityItemId": 20200,
71
84
  "slots": []
@@ -72,6 +72,7 @@ export const ITEM_CONTAINER_T1_PACKED = 10200
72
72
  export const ITEM_SHIP_T1_PACKED = 10201
73
73
  export const ITEM_WAREHOUSE_T1_PACKED = 10202
74
74
  export const ITEM_EXTRACTOR_T1_PACKED = 10203
75
+ export const ITEM_FACTORY_T1_PACKED = 10204
75
76
  export const ITEM_HULL_PLATES_T2 = 20001
76
77
  export const ITEM_CARGO_LINING_T2 = 20002
77
78
  export const ITEM_CONTAINER_T2_PACKED = 20200
@@ -489,6 +489,12 @@
489
489
  "type": "entity",
490
490
  "tier": 1
491
491
  },
492
+ {
493
+ "id": 10204,
494
+ "mass": 800000,
495
+ "type": "entity",
496
+ "tier": 1
497
+ },
492
498
  {
493
499
  "id": 20001,
494
500
  "mass": 50000,
@@ -0,0 +1,78 @@
1
+ {
2
+ "kinds": [
3
+ {
4
+ "kind": "ship",
5
+ "classification": "OrbitalVessel",
6
+ "capabilityFlags": 19,
7
+ "zCoord": 800,
8
+ "defaultLabel": "Ship"
9
+ },
10
+ {
11
+ "kind": "warehouse",
12
+ "classification": "PlanetaryStructure",
13
+ "capabilityFlags": 20,
14
+ "zCoord": 0,
15
+ "defaultLabel": "Warehouse"
16
+ },
17
+ {
18
+ "kind": "extractor",
19
+ "classification": "PlanetaryStructure",
20
+ "capabilityFlags": 20,
21
+ "zCoord": 0,
22
+ "defaultLabel": "Extractor"
23
+ },
24
+ {
25
+ "kind": "factory",
26
+ "classification": "PlanetaryStructure",
27
+ "capabilityFlags": 20,
28
+ "zCoord": 0,
29
+ "defaultLabel": "Factory"
30
+ },
31
+ {
32
+ "kind": "container",
33
+ "classification": "OrbitalVessel",
34
+ "capabilityFlags": 3,
35
+ "zCoord": 300,
36
+ "defaultLabel": "Container"
37
+ },
38
+ {
39
+ "kind": "nexus",
40
+ "classification": "OrbitalVessel",
41
+ "capabilityFlags": 0,
42
+ "zCoord": 800,
43
+ "defaultLabel": "Nexus"
44
+ }
45
+ ],
46
+ "templates": [
47
+ {
48
+ "itemId": 10201,
49
+ "kind": "ship",
50
+ "displayLabel": ""
51
+ },
52
+ {
53
+ "itemId": 10202,
54
+ "kind": "warehouse",
55
+ "displayLabel": ""
56
+ },
57
+ {
58
+ "itemId": 10203,
59
+ "kind": "extractor",
60
+ "displayLabel": ""
61
+ },
62
+ {
63
+ "itemId": 10204,
64
+ "kind": "factory",
65
+ "displayLabel": ""
66
+ },
67
+ {
68
+ "itemId": 10200,
69
+ "kind": "container",
70
+ "displayLabel": ""
71
+ },
72
+ {
73
+ "itemId": 20200,
74
+ "kind": "container",
75
+ "displayLabel": ""
76
+ }
77
+ ]
78
+ }
@@ -0,0 +1,133 @@
1
+ import {Name, type NameType} from '@wharfkit/antelope'
2
+ import kindRegistryJson from './kind-registry.json'
3
+
4
+ export const CAP_WRAP = 0x01
5
+ export const CAP_UNDEPLOY = 0x02
6
+ export const CAP_DEMOLISH = 0x04
7
+ export const CAP_MODULES = 0x10
8
+
9
+ export enum EntityClass {
10
+ OrbitalVessel = 0,
11
+ PlanetaryStructure = 1,
12
+ }
13
+
14
+ const CLASSIFICATION_BY_NAME: Record<string, EntityClass> = {
15
+ OrbitalVessel: EntityClass.OrbitalVessel,
16
+ PlanetaryStructure: EntityClass.PlanetaryStructure,
17
+ }
18
+
19
+ export type EntityTypeName = 'ship' | 'warehouse' | 'extractor' | 'factory' | 'container' | 'nexus'
20
+
21
+ export interface KindMeta {
22
+ kind: Name
23
+ classification: EntityClass
24
+ capabilityFlags: number
25
+ zCoord: number
26
+ defaultLabel: string
27
+ }
28
+
29
+ export interface TemplateMeta {
30
+ itemId: number
31
+ kind: Name
32
+ displayLabel: string
33
+ }
34
+
35
+ interface RawKindEntry {
36
+ kind: string
37
+ classification: string
38
+ capabilityFlags: number
39
+ zCoord: number
40
+ defaultLabel: string
41
+ }
42
+
43
+ interface RawTemplateEntry {
44
+ itemId: number
45
+ kind: string
46
+ displayLabel: string
47
+ }
48
+
49
+ const KIND_META: Map<string, KindMeta> = (() => {
50
+ const m = new Map<string, KindMeta>()
51
+ for (const r of kindRegistryJson.kinds as RawKindEntry[]) {
52
+ const cls = CLASSIFICATION_BY_NAME[r.classification]
53
+ if (cls === undefined) {
54
+ throw new Error(
55
+ `kind-registry: unknown classification "${r.classification}" for kind ${r.kind}`
56
+ )
57
+ }
58
+ m.set(r.kind, {
59
+ kind: Name.from(r.kind),
60
+ classification: cls,
61
+ capabilityFlags: r.capabilityFlags,
62
+ zCoord: r.zCoord,
63
+ defaultLabel: r.defaultLabel,
64
+ })
65
+ }
66
+ return m
67
+ })()
68
+
69
+ const TEMPLATE_BY_ITEM_ID: Map<number, TemplateMeta> = (() => {
70
+ const m = new Map<number, TemplateMeta>()
71
+ for (const r of kindRegistryJson.templates as RawTemplateEntry[]) {
72
+ m.set(r.itemId, {
73
+ itemId: r.itemId,
74
+ kind: Name.from(r.kind),
75
+ displayLabel: r.displayLabel,
76
+ })
77
+ }
78
+ return m
79
+ })()
80
+
81
+ function nameKey(kind: NameType | EntityTypeName): string {
82
+ if (typeof kind === 'string') return kind
83
+ return Name.from(kind).toString()
84
+ }
85
+
86
+ export function getKindMeta(kind: NameType | EntityTypeName): KindMeta | undefined {
87
+ return KIND_META.get(nameKey(kind))
88
+ }
89
+
90
+ export function getTemplateMeta(itemId: number): TemplateMeta | undefined {
91
+ return TEMPLATE_BY_ITEM_ID.get(itemId)
92
+ }
93
+
94
+ export function getPackedEntityType(itemId: number): Name | null {
95
+ return TEMPLATE_BY_ITEM_ID.get(itemId)?.kind ?? null
96
+ }
97
+
98
+ export function kindCan(kind: NameType | EntityTypeName, cap: number): boolean {
99
+ const m = KIND_META.get(nameKey(kind))
100
+ return m !== undefined && (m.capabilityFlags & cap) !== 0
101
+ }
102
+
103
+ export function getEntityClass(kind: NameType | EntityTypeName): EntityClass {
104
+ const m = KIND_META.get(nameKey(kind))
105
+ if (!m) throw new Error(`Entity type has no class: ${nameKey(kind)}`)
106
+ return m.classification
107
+ }
108
+
109
+ export const ENTITY_SHIP = Name.from('ship')
110
+ export const ENTITY_WAREHOUSE = Name.from('warehouse')
111
+ export const ENTITY_EXTRACTOR = Name.from('extractor')
112
+ export const ENTITY_FACTORY = Name.from('factory')
113
+ export const ENTITY_CONTAINER = Name.from('container')
114
+ export const ENTITY_NEXUS = Name.from('nexus')
115
+
116
+ export function isShip(entity: {type?: Name}): boolean {
117
+ return entity.type?.equals(ENTITY_SHIP) ?? false
118
+ }
119
+ export function isWarehouse(entity: {type?: Name}): boolean {
120
+ return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
121
+ }
122
+ export function isExtractor(entity: {type?: Name}): boolean {
123
+ return entity.type?.equals(ENTITY_EXTRACTOR) ?? false
124
+ }
125
+ export function isFactory(entity: {type?: Name}): boolean {
126
+ return entity.type?.equals(ENTITY_FACTORY) ?? false
127
+ }
128
+ export function isContainer(entity: {type?: Name}): boolean {
129
+ return entity.type?.equals(ENTITY_CONTAINER) ?? false
130
+ }
131
+ export function isNexus(entity: {type?: Name}): boolean {
132
+ return entity.type?.equals(ENTITY_NEXUS) ?? false
133
+ }
@@ -229,6 +229,11 @@ export const itemMetadata: Record<number, ItemMetadata> = {
229
229
  'Planetary resource extraction facility with generator and gatherer module slots.',
230
230
  color: '#D4726F',
231
231
  },
232
+ 10204: {
233
+ name: 'Factory',
234
+ description: 'Planetary fabrication facility with generator and crafter module slots.',
235
+ color: '#7BA7D4',
236
+ },
232
237
 
233
238
  // === Components (T2) ===
234
239
  20001: {
@@ -255,6 +260,7 @@ export const entityMetadata: Record<number, EntityMetadata> = {
255
260
  10201: {moduleSlotLabels: ['Engine', 'Generator', 'Gatherer', 'Loader', 'Storage']},
256
261
  10202: {moduleSlotLabels: ['Loader', 'Storage', 'Storage', 'Storage', 'Storage']},
257
262
  10203: {moduleSlotLabels: ['Generator', 'Gatherer']},
263
+ 10204: {moduleSlotLabels: ['Generator', 'Crafter']},
258
264
  }
259
265
 
260
266
  for (const item of items as Array<{id: number}>) {
@@ -801,6 +801,63 @@
801
801
  ],
802
802
  "blendWeights": []
803
803
  },
804
+ {
805
+ "outputItemId": 10204,
806
+ "outputMass": 800000,
807
+ "inputs": [
808
+ {
809
+ "itemId": 10001,
810
+ "quantity": 15
811
+ },
812
+ {
813
+ "itemId": 10002,
814
+ "quantity": 6
815
+ },
816
+ {
817
+ "itemId": 10008,
818
+ "quantity": 4
819
+ },
820
+ {
821
+ "itemId": 10009,
822
+ "quantity": 4
823
+ }
824
+ ],
825
+ "statSlots": [
826
+ {
827
+ "sources": [
828
+ {
829
+ "inputIndex": 0,
830
+ "statIndex": 0
831
+ }
832
+ ]
833
+ },
834
+ {
835
+ "sources": [
836
+ {
837
+ "inputIndex": 0,
838
+ "statIndex": 1
839
+ }
840
+ ]
841
+ },
842
+ {
843
+ "sources": [
844
+ {
845
+ "inputIndex": 1,
846
+ "statIndex": 0
847
+ }
848
+ ]
849
+ },
850
+ {
851
+ "sources": [
852
+ {
853
+ "inputIndex": 1,
854
+ "statIndex": 1
855
+ }
856
+ ]
857
+ }
858
+ ],
859
+ "blendWeights": []
860
+ },
804
861
  {
805
862
  "outputItemId": 20001,
806
863
  "outputMass": 50000,