@shipload/sdk 2.0.0-rc7 → 2.0.0-rc8

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "2.0.0-rc7",
4
+ "version": "2.0.0-rc8",
5
5
  "homepage": "https://github.com/shipload/sdk",
6
6
  "license": "MIT",
7
7
  "main": "lib/shipload.js",
@@ -1,7 +1,7 @@
1
1
  import type {ResourceCategory, ResourceTier} from '../types'
2
2
 
3
3
  export const categoryColors: Record<ResourceCategory, string> = {
4
- metal: '#7B8D9E',
4
+ metal: '#5B9BD5',
5
5
  precious: '#D4A843',
6
6
  gas: '#7EC8E3',
7
7
  mineral: '#B8A9C9',
@@ -26,3 +26,22 @@ export const categoryIcons: Record<ResourceCategory, string> = {
26
26
 
27
27
  export const componentIcon = '▣'
28
28
  export const moduleIcon = '⬢'
29
+
30
+ export const itemIcons: Record<number, string> = {
31
+ 10001: 'HP',
32
+ 10002: 'CL',
33
+ 10003: 'CT',
34
+ 10004: 'TC',
35
+ 10005: 'PC',
36
+ 10006: 'EN',
37
+ 10007: 'GN',
38
+ 10008: 'SH',
39
+ 10009: 'DS',
40
+ 10010: 'EP',
41
+ 10011: 'CA',
42
+ 10012: 'TB',
43
+ 10013: 'RC',
44
+ 10014: 'EX',
45
+ 10015: 'LD',
46
+ 10016: 'MF',
47
+ }
@@ -1,4 +1,4 @@
1
- import {MODULE_ENGINE, MODULE_GENERATOR, MODULE_EXTRACTOR, MODULE_LOADER, MODULE_CRAFTER, ITEM_ENGINE_T1, ITEM_GENERATOR_T1, ITEM_EXTRACTOR_T1, ITEM_LOADER_T1, ITEM_MANUFACTURING_T1} from '../capabilities/modules'
1
+ import {MODULE_ANY, MODULE_ENGINE, MODULE_GENERATOR, MODULE_EXTRACTOR, MODULE_LOADER, MODULE_CRAFTER, ITEM_ENGINE_T1, ITEM_GENERATOR_T1, ITEM_EXTRACTOR_T1, ITEM_LOADER_T1, ITEM_MANUFACTURING_T1} from '../capabilities/modules'
2
2
  import type {ResourceCategory} from '../types'
3
3
 
4
4
  export {ITEM_ENGINE_T1, ITEM_GENERATOR_T1, ITEM_EXTRACTOR_T1, ITEM_LOADER_T1, ITEM_MANUFACTURING_T1}
@@ -38,6 +38,10 @@ export interface ComponentDefinition {
38
38
  usedIn: {type: 'entity' | 'module'; name: string}[]
39
39
  }
40
40
 
41
+ export interface ModuleSlot {
42
+ type: number
43
+ }
44
+
41
45
  export interface EntityRecipe {
42
46
  id: string
43
47
  name: string
@@ -46,6 +50,7 @@ export interface EntityRecipe {
46
50
  packedItemId: number
47
51
  recipe: RecipeInput[]
48
52
  stats: {key: string; sourceComponentId: number; sourceStatKey: string}[]
53
+ moduleSlots?: ModuleSlot[]
49
54
  }
50
55
 
51
56
  export interface CraftableItem {
@@ -98,7 +103,7 @@ export const components: ComponentDefinition[] = [
98
103
  {key: 'thermal', source: 'gas'},
99
104
  ],
100
105
  recipe: [{category: 'gas' as ResourceCategory, quantity: 32}],
101
- usedIn: [{type: 'module', name: 'Engine Module T1'}],
106
+ usedIn: [{type: 'module', name: 'Engine'}],
102
107
  },
103
108
  {
104
109
  id: ITEM_POWER_CELL,
@@ -111,7 +116,7 @@ export const components: ComponentDefinition[] = [
111
116
  {key: 'clarity', source: 'mineral'},
112
117
  ],
113
118
  recipe: [{category: 'mineral' as ResourceCategory, quantity: 20}],
114
- usedIn: [{type: 'module', name: 'Generator Module T1'}],
119
+ usedIn: [{type: 'module', name: 'Generator'}],
115
120
  },
116
121
  {
117
122
  id: ITEM_DRILL_SHAFT,
@@ -124,7 +129,7 @@ export const components: ComponentDefinition[] = [
124
129
  {key: 'tolerance', source: 'metal'},
125
130
  ],
126
131
  recipe: [{category: 'metal' as ResourceCategory, quantity: 15}],
127
- usedIn: [{type: 'module', name: 'Extractor Module T1'}],
132
+ usedIn: [{type: 'module', name: 'Extractor'}],
128
133
  },
129
134
  {
130
135
  id: ITEM_EXTRACTION_PROBE,
@@ -137,7 +142,7 @@ export const components: ComponentDefinition[] = [
137
142
  {key: 'reflectivity', source: 'precious'},
138
143
  ],
139
144
  recipe: [{category: 'precious' as ResourceCategory, quantity: 10}],
140
- usedIn: [{type: 'module', name: 'Extractor Module T1'}],
145
+ usedIn: [{type: 'module', name: 'Extractor'}],
141
146
  },
142
147
  {
143
148
  id: ITEM_CARGO_ARM,
@@ -150,7 +155,7 @@ export const components: ComponentDefinition[] = [
150
155
  {key: 'insulation', source: 'organic'},
151
156
  ],
152
157
  recipe: [{category: 'organic' as ResourceCategory, quantity: 32}],
153
- usedIn: [{type: 'module', name: 'Loader Module T1'}],
158
+ usedIn: [{type: 'module', name: 'Loader'}],
154
159
  },
155
160
  {
156
161
  id: ITEM_TOOL_BIT,
@@ -163,7 +168,7 @@ export const components: ComponentDefinition[] = [
163
168
  {key: 'clarity', source: 'mineral'},
164
169
  ],
165
170
  recipe: [{category: 'mineral' as ResourceCategory, quantity: 20}],
166
- usedIn: [{type: 'module', name: 'Manufacturing Module T1'}],
171
+ usedIn: [{type: 'module', name: 'Manufacturing'}],
167
172
  },
168
173
  {
169
174
  id: ITEM_REACTION_CHAMBER,
@@ -176,7 +181,7 @@ export const components: ComponentDefinition[] = [
176
181
  {key: 'thermal', source: 'gas'},
177
182
  ],
178
183
  recipe: [{category: 'gas' as ResourceCategory, quantity: 32}],
179
- usedIn: [{type: 'module', name: 'Manufacturing Module T1'}],
184
+ usedIn: [{type: 'module', name: 'Manufacturing'}],
180
185
  },
181
186
  ]
182
187
 
@@ -214,6 +219,13 @@ export const entityRecipes: EntityRecipe[] = [
214
219
  {key: 'ductility', sourceComponentId: ITEM_CARGO_LINING, sourceStatKey: 'ductility'},
215
220
  {key: 'purity', sourceComponentId: ITEM_CARGO_LINING, sourceStatKey: 'purity'},
216
221
  ],
222
+ moduleSlots: [
223
+ {type: MODULE_ANY},
224
+ {type: MODULE_ANY},
225
+ {type: MODULE_ANY},
226
+ {type: MODULE_ANY},
227
+ {type: MODULE_ANY},
228
+ ],
217
229
  },
218
230
  ]
219
231
 
@@ -231,7 +243,7 @@ export interface ModuleRecipe {
231
243
  export const moduleRecipes: ModuleRecipe[] = [
232
244
  {
233
245
  id: 'engine-t1',
234
- name: 'Engine Module T1',
246
+ name: 'Engine',
235
247
  description: 'Basic propulsion system. Converts volatile gases into thrust.',
236
248
  color: '#E86344',
237
249
  itemId: ITEM_ENGINE_T1,
@@ -244,7 +256,7 @@ export const moduleRecipes: ModuleRecipe[] = [
244
256
  },
245
257
  {
246
258
  id: 'generator-t1',
247
- name: 'Generator Module T1',
259
+ name: 'Generator',
248
260
  description: 'Basic energy system. Stores and recharges energy from resonant minerals.',
249
261
  color: '#7B5AE8',
250
262
  itemId: ITEM_GENERATOR_T1,
@@ -257,7 +269,7 @@ export const moduleRecipes: ModuleRecipe[] = [
257
269
  },
258
270
  {
259
271
  id: 'extractor-t1',
260
- name: 'Extractor Module T1',
272
+ name: 'Extractor',
261
273
  description: 'Basic extraction system. Drills and probes for raw resources.',
262
274
  color: '#7B8D9E',
263
275
  itemId: ITEM_EXTRACTOR_T1,
@@ -276,7 +288,7 @@ export const moduleRecipes: ModuleRecipe[] = [
276
288
  },
277
289
  {
278
290
  id: 'loader-t1',
279
- name: 'Loader Module T1',
291
+ name: 'Loader',
280
292
  description: 'Basic cargo handling system. Loads and unloads cargo with articulated arms.',
281
293
  color: '#6B8E5A',
282
294
  itemId: ITEM_LOADER_T1,
@@ -292,7 +304,7 @@ export const moduleRecipes: ModuleRecipe[] = [
292
304
  },
293
305
  {
294
306
  id: 'manufacturing-t1',
295
- name: 'Manufacturing Module T1',
307
+ name: 'Manufacturing',
296
308
  description: 'Basic crafting system. Processes materials using reaction chambers and cutting tools.',
297
309
  color: '#7EC8E3',
298
310
  itemId: ITEM_MANUFACTURING_T1,
@@ -141,7 +141,7 @@ export * from './types/capabilities'
141
141
  export * from './types/entity'
142
142
  export * from './capabilities'
143
143
 
144
- export {categoryColors, tierColors, categoryIcons, componentIcon, moduleIcon} from './data/colors'
144
+ export {categoryColors, tierColors, categoryIcons, componentIcon, moduleIcon, itemIcons} from './data/colors'
145
145
 
146
146
  export {
147
147
  components,
@@ -178,6 +178,7 @@ export type {
178
178
  RecipeInput,
179
179
  EntityRecipe,
180
180
  ModuleRecipe,
181
+ ModuleSlot,
181
182
  CraftableItem,
182
183
  } from './data/recipes'
183
184
 
@@ -205,4 +206,4 @@ export {
205
206
  } from './entities/ship-deploy'
206
207
 
207
208
  export {resolveItem} from './resolution/resolve-item'
208
- export type {ResolvedItem, ResolvedItemStat, ResolvedAttributeGroup, ResolvedItemType} from './resolution/resolve-item'
209
+ export type {ResolvedItem, ResolvedItemStat, ResolvedAttributeGroup, ResolvedModuleSlot, ResolvedItemType} from './resolution/resolve-item'
@@ -9,7 +9,7 @@ import {deriveResourceStats} from '../derivation/stratum'
9
9
  import {getStatDefinitions} from '../derivation/stats'
10
10
  import {computeShipHullCapabilities, computeEngineCapabilities, computeGeneratorCapabilities, computeExtractorCapabilities, computeLoaderCapabilities, computeManufacturingCapabilities} from '../entities/ship-deploy'
11
11
  import {computeContainerCapabilities} from '../entities/container'
12
- import {categoryColors, categoryIcons, componentIcon, moduleIcon} from '../data/colors'
12
+ import {categoryColors, categoryIcons, componentIcon, moduleIcon, itemIcons} from '../data/colors'
13
13
  import {ServerContract} from '../contracts'
14
14
 
15
15
  export interface ResolvedItemStat {
@@ -29,6 +29,12 @@ export interface ResolvedAttributeGroup {
29
29
 
30
30
  export type ResolvedItemType = 'resource' | 'component' | 'module' | 'entity'
31
31
 
32
+ export interface ResolvedModuleSlot {
33
+ name?: string
34
+ installed: boolean
35
+ attributes?: {label: string; value: number}[]
36
+ }
37
+
32
38
  export interface ResolvedItem {
33
39
  itemId: number
34
40
  name: string
@@ -39,6 +45,7 @@ export interface ResolvedItem {
39
45
  itemType: ResolvedItemType
40
46
  stats?: ResolvedItemStat[]
41
47
  attributes?: ResolvedAttributeGroup[]
48
+ moduleSlots?: ResolvedModuleSlot[]
42
49
  }
43
50
 
44
51
  function toNum(v: UInt16Type): number {
@@ -107,7 +114,7 @@ function resolveComponent(id: number, seed?: UInt64Type): ResolvedItem {
107
114
  return {
108
115
  itemId: id,
109
116
  name: comp.name,
110
- icon: componentIcon,
117
+ icon: itemIcons[id] ?? componentIcon,
111
118
  tier: 't1' as ResourceTier,
112
119
  mass: comp.mass,
113
120
  itemType: 'component',
@@ -172,7 +179,7 @@ function resolveModule(id: number, seed?: UInt64Type): ResolvedItem {
172
179
  return {
173
180
  itemId: id,
174
181
  name: recipe.name,
175
- icon: moduleIcon,
182
+ icon: itemIcons[id] ?? moduleIcon,
176
183
  tier: 't1' as ResourceTier,
177
184
  mass: 0,
178
185
  itemType: 'module',
@@ -183,6 +190,8 @@ function resolveModule(id: number, seed?: UInt64Type): ResolvedItem {
183
190
  function resolveEntity(id: number, seed?: UInt64Type, modules?: ServerContract.Types.module_entry[]): ResolvedItem {
184
191
  const recipe = getEntityRecipeByItemId(id)!
185
192
  let attributes: ResolvedAttributeGroup[] | undefined
193
+ let moduleSlots: ResolvedModuleSlot[] | undefined
194
+
186
195
  if (seed !== undefined) {
187
196
  const stats = decodeCraftedItemStats(id, toBigSeed(seed))
188
197
  attributes = []
@@ -201,27 +210,37 @@ function resolveEntity(id: number, seed?: UInt64Type, modules?: ServerContract.T
201
210
  {label: 'Capacity', value: containerCaps.capacity},
202
211
  ]})
203
212
  }
213
+ }
204
214
 
205
- if (modules) {
206
- for (const mod of modules) {
207
- if (!mod.installed) continue
215
+ if (recipe.moduleSlots) {
216
+ moduleSlots = recipe.moduleSlots.map((slot, i) => {
217
+ const mod = modules?.[i]
218
+ if (mod?.installed) {
208
219
  const modItemId = Number(mod.installed.item_id.value.toString())
209
220
  const modSeed = BigInt(mod.installed.seed.toString())
210
221
  const modStats = decodeCraftedItemStats(modItemId, modSeed)
211
222
  const modType = getModuleCapabilityType(modItemId)
212
223
  const group = computeCapabilityGroup(modType, modStats)
213
- if (group) attributes.push(group)
224
+ const modRecipe = getModuleRecipeByItemId(modItemId)
225
+ return {
226
+ name: modRecipe?.name ?? 'Module',
227
+ installed: true,
228
+ attributes: group?.attributes,
229
+ }
214
230
  }
215
- }
231
+ return {installed: false}
232
+ })
216
233
  }
234
+
217
235
  return {
218
236
  itemId: id,
219
237
  name: recipe.name,
220
- icon: componentIcon,
238
+ icon: itemIcons[id] ?? componentIcon,
221
239
  tier: 't1' as ResourceTier,
222
240
  mass: 0,
223
241
  itemType: 'entity',
224
242
  attributes,
243
+ moduleSlots,
225
244
  }
226
245
  }
227
246