@shipload/sdk 1.0.0-next.14 → 1.0.0-next.16

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.
@@ -66,6 +66,10 @@ const KIND_META: Map<string, KindMeta> = (() => {
66
66
  return m
67
67
  })()
68
68
 
69
+ export const ALL_ENTITY_TYPES: readonly EntityTypeName[] = Object.freeze([
70
+ ...KIND_META.keys(),
71
+ ] as EntityTypeName[])
72
+
69
73
  const TEMPLATE_BY_ITEM_ID: Map<number, TemplateMeta> = (() => {
70
74
  const m = new Map<number, TemplateMeta>()
71
75
  for (const r of kindRegistryJson.templates as RawTemplateEntry[]) {
@@ -200,6 +200,7 @@ export {
200
200
  getKindMeta,
201
201
  getTemplateMeta,
202
202
  kindCan,
203
+ ALL_ENTITY_TYPES,
203
204
  CAP_WRAP,
204
205
  CAP_UNDEPLOY,
205
206
  CAP_DEMOLISH,
@@ -379,7 +380,7 @@ export {
379
380
 
380
381
  export {formatMass, formatMassDelta, formatMassScaled, formatLocation} from './format'
381
382
 
382
- export {displayName, displayNameWithTier, describeItem} from './resolution/display-name'
383
+ export {displayName, describeItem} from './resolution/display-name'
383
384
  export type {DescribeOptions} from './resolution/display-name'
384
385
 
385
386
  export * from './subscriptions'
@@ -187,13 +187,15 @@ export class ActionsManager extends BaseManager {
187
187
  owner: NameType,
188
188
  entityId: UInt64Type,
189
189
  nexusId: UInt64Type,
190
- items: ServerContract.ActionParams.Type.cargo_item[]
190
+ cargoId: UInt64Type,
191
+ quantity: UInt64Type
191
192
  ): Action {
192
193
  return this.server.action('wrap', {
193
194
  owner: Name.from(owner),
194
195
  entity_id: UInt64.from(entityId),
195
196
  nexus_id: UInt64.from(nexusId),
196
- items,
197
+ cargo_id: UInt64.from(cargoId),
198
+ quantity: UInt64.from(quantity),
197
199
  })
198
200
  }
199
201
 
@@ -211,6 +213,24 @@ export class ActionsManager extends BaseManager {
211
213
  })
212
214
  }
213
215
 
216
+ deploynft(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action {
217
+ const params: ServerContract.ActionParams.deploynft = {
218
+ owner: Name.from(owner),
219
+ asset_id: UInt64.from(assetId),
220
+ target_nexus_id: UInt64.from(targetNexusId),
221
+ }
222
+ return this.server.action('deploynft', params)
223
+ }
224
+
225
+ unwrapnft(owner: NameType, assetId: UInt64Type, hostId: UInt64Type): Action {
226
+ const params: ServerContract.ActionParams.unwrapnft = {
227
+ owner: Name.from(owner),
228
+ asset_id: UInt64.from(assetId),
229
+ host_id: UInt64.from(hostId),
230
+ }
231
+ return this.server.action('unwrapnft', params)
232
+ }
233
+
214
234
  demolish(entityId: UInt64Type): Action {
215
235
  return this.server.action('demolish', {
216
236
  entity_id: UInt64.from(entityId),
@@ -1,26 +1,44 @@
1
1
  import type {ResolvedItem} from './resolve-item'
2
2
  import type {ResourceCategory} from '../types'
3
- import {CATEGORY_LABELS, TIER_ADJECTIVES} from '../types'
3
+ import {
4
+ CATEGORY_LABELS,
5
+ RESOURCE_TIER_ADJECTIVES,
6
+ COMPONENT_TIER_PREFIXES,
7
+ MODULE_TIER_PREFIXES,
8
+ } from '../types'
4
9
  import {formatMass as defaultFormatMass} from '../format'
5
10
 
6
- export interface DisplayNameInput {
7
- itemType: 'resource' | 'component' | 'module' | 'entity' | string
11
+ interface DisplayNameInputCommon {
8
12
  tier: number
9
13
  category?: ResourceCategory
10
14
  name: string
11
15
  }
12
16
 
13
- export function displayName(resolved: DisplayNameInput): string {
14
- if (resolved.itemType === 'resource') {
15
- const adj = TIER_ADJECTIVES[resolved.tier] ?? 'Unknown'
16
- const cat = resolved.category ? CATEGORY_LABELS[resolved.category] : 'Resource'
17
- return `${adj} ${cat}`
18
- }
19
- return resolved.name
17
+ export type DisplayNameInput =
18
+ | (DisplayNameInputCommon & {itemType: 'resource' | 'component' | 'module' | 'entity' | string})
19
+ | (DisplayNameInputCommon & {type: string})
20
+
21
+ function itemTypeOf(item: DisplayNameInput): string {
22
+ return 'itemType' in item ? item.itemType : item.type
23
+ }
24
+
25
+ function tierPrefix(item: DisplayNameInput): string | null {
26
+ const t = itemTypeOf(item)
27
+ if (t === 'resource') return RESOURCE_TIER_ADJECTIVES[item.tier] ?? null
28
+ if (t === 'component') return COMPONENT_TIER_PREFIXES[item.tier] ?? null
29
+ if (t === 'module') return MODULE_TIER_PREFIXES[item.tier] ?? null
30
+ return null
31
+ }
32
+
33
+ function baseName(item: DisplayNameInput): string {
34
+ if (itemTypeOf(item) !== 'resource') return item.name
35
+ return item.category ? CATEGORY_LABELS[item.category] : 'Resource'
20
36
  }
21
37
 
22
- export function displayNameWithTier(resolved: DisplayNameInput): string {
23
- return `${displayName(resolved)} (T${resolved.tier})`
38
+ export function displayName(item: DisplayNameInput): string {
39
+ const prefix = tierPrefix(item)
40
+ const head = prefix ? `${prefix} ${baseName(item)}` : baseName(item)
41
+ return `${head} (T${item.tier})`
24
42
  }
25
43
 
26
44
  export interface DescribeOptions {
@@ -255,7 +255,6 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
255
255
  applyAddCargoTask(projected, task)
256
256
  break
257
257
  case TaskType.UNLOAD:
258
- case TaskType.WRAP:
259
258
  applyRemoveCargoTask(projected, task)
260
259
  break
261
260
  case TaskType.GATHER:
@@ -268,7 +267,6 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
268
267
  applyDeployTask(projected, task)
269
268
  break
270
269
  case TaskType.UNDEPLOY:
271
- case TaskType.WRAP_ENTITY:
272
270
  case TaskType.DEMOLISH:
273
271
  break
274
272
  }
@@ -440,7 +438,6 @@ export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity
440
438
  if (taskComplete) applyAddCargoTask(projected, task)
441
439
  break
442
440
  case TaskType.UNLOAD:
443
- case TaskType.WRAP:
444
441
  if (taskComplete) applyRemoveCargoTask(projected, task)
445
442
  break
446
443
  case TaskType.GATHER:
@@ -453,7 +450,6 @@ export function projectEntityAt(entity: Projectable, now: Date): ProjectedEntity
453
450
  if (taskComplete) applyDeployTask(projected, task)
454
451
  break
455
452
  case TaskType.UNDEPLOY:
456
- case TaskType.WRAP_ENTITY:
457
453
  case TaskType.DEMOLISH:
458
454
  break
459
455
  }
@@ -34,7 +34,6 @@ export function taskCargoChanges(task: ServerContract.Types.task): TaskCargoChan
34
34
  case TaskType.GATHER:
35
35
  return task.entitytarget ? [] : items.map((i) => toChange(i, 'in'))
36
36
  case TaskType.UNLOAD:
37
- case TaskType.WRAP:
38
37
  return items.map((i) => toChange(i, 'out'))
39
38
  case TaskType.CRAFT:
40
39
  return [
package/src/types.ts CHANGED
@@ -50,10 +50,8 @@ export enum TaskType {
50
50
  WARP = 6,
51
51
  CRAFT = 7,
52
52
  DEPLOY = 8,
53
- WRAP = 9,
54
53
  UNWRAP = 10,
55
54
  UNDEPLOY = 11,
56
- WRAP_ENTITY = 12,
57
55
  DEMOLISH = 13,
58
56
  }
59
57
 
@@ -120,7 +118,7 @@ export type ModuleType =
120
118
  | 'storage'
121
119
  | 'hauler'
122
120
 
123
- export const TIER_ADJECTIVES: Record<number, string> = {
121
+ export const RESOURCE_TIER_ADJECTIVES: Record<number, string> = {
124
122
  1: 'Crude',
125
123
  2: 'Dense',
126
124
  3: 'Pure',
@@ -133,6 +131,9 @@ export const TIER_ADJECTIVES: Record<number, string> = {
133
131
  10: 'Ascendant',
134
132
  }
135
133
 
134
+ export const COMPONENT_TIER_PREFIXES: Record<number, string> = {}
135
+ export const MODULE_TIER_PREFIXES: Record<number, string> = {}
136
+
136
137
  export const CATEGORY_LABELS: Record<ResourceCategory, string> = {
137
138
  ore: 'Ore',
138
139
  crystal: 'Crystal',
@@ -158,5 +159,5 @@ export function formatTier(tier: number): string {
158
159
  }
159
160
 
160
161
  export function tierAdjective(tier: number): string {
161
- return TIER_ADJECTIVES[tier] ?? `T${tier}`
162
+ return RESOURCE_TIER_ADJECTIVES[tier] ?? `T${tier}`
162
163
  }