@shipload/sdk 2.0.0-rc15 → 2.0.0-rc16

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-rc15",
4
+ "version": "2.0.0-rc16",
5
5
  "homepage": "https://github.com/shipload/sdk",
6
6
  "license": "MIT",
7
7
  "main": "lib/shipload.js",
@@ -18,7 +18,7 @@ export class EntityInventory extends ServerContract.Types.cargo_item {
18
18
  }
19
19
 
20
20
  get name(): string {
21
- return this.item.name
21
+ return this.item.displayName
22
22
  }
23
23
 
24
24
  get unitMass(): UInt32 {
@@ -1,36 +1,18 @@
1
1
  import type {ResolvedItem} from './resolve-item'
2
- import type {ResourceCategory} from '../types'
2
+ import type {ResourceCategory, ResourceTier} from '../types'
3
+ import {CATEGORY_LABELS, TIER_ADJECTIVES, tierNumber} from '../types'
3
4
  import {formatMass as defaultFormatMass} from '../format'
4
5
 
5
- const TIER_ADJECTIVES: Record<number, string> = {
6
- 1: 'Crude',
7
- 2: 'Dense',
8
- 3: 'Pure',
9
- 4: 'Prime',
10
- 5: 'Pristine',
11
- 6: 'Radiant',
12
- 7: 'Exotic',
13
- 8: 'Mythic',
14
- 9: 'Cosmic',
15
- 10: 'Ascendant',
6
+ export interface DisplayNameInput {
7
+ itemType: 'resource' | 'component' | 'module' | 'entity' | string
8
+ tier: ResourceTier | string
9
+ category?: ResourceCategory
10
+ name: string
16
11
  }
17
12
 
18
- const CATEGORY_LABELS: Record<ResourceCategory, string> = {
19
- ore: 'Ore',
20
- crystal: 'Crystal',
21
- gas: 'Gas',
22
- regolith: 'Regolith',
23
- biomass: 'Biomass',
24
- }
25
-
26
- function tierNumber(tier: string): number {
27
- return Number(String(tier).replace(/^t/i, ''))
28
- }
29
-
30
- export function displayName(resolved: ResolvedItem): string {
13
+ export function displayName(resolved: DisplayNameInput): string {
31
14
  if (resolved.itemType === 'resource') {
32
- const tierNum = tierNumber(resolved.tier)
33
- const adj = TIER_ADJECTIVES[tierNum] ?? 'Unknown'
15
+ const adj = TIER_ADJECTIVES[tierNumber(resolved.tier)] ?? 'Unknown'
34
16
  const cat = resolved.category ? CATEGORY_LABELS[resolved.category] : 'Resource'
35
17
  return `${adj} ${cat}`
36
18
  }
@@ -100,7 +100,7 @@ function resolveResource(id: number, stats?: UInt64Type): ResolvedItem {
100
100
  }
101
101
  return {
102
102
  itemId: id,
103
- name: String(item.name),
103
+ name: item.displayName,
104
104
  icon: categoryIcons[cat] ?? '⬡',
105
105
  abbreviation: null,
106
106
  category: cat,
package/src/types.ts CHANGED
@@ -116,6 +116,31 @@ export interface Distance {
116
116
  export type ResourceCategory = 'ore' | 'crystal' | 'gas' | 'regolith' | 'biomass'
117
117
  export type ResourceTier = 't1' | 't2' | 't3' | 't4' | 't5'
118
118
 
119
+ export const TIER_ADJECTIVES: Record<number, string> = {
120
+ 1: 'Crude',
121
+ 2: 'Dense',
122
+ 3: 'Pure',
123
+ 4: 'Prime',
124
+ 5: 'Pristine',
125
+ 6: 'Radiant',
126
+ 7: 'Exotic',
127
+ 8: 'Mythic',
128
+ 9: 'Cosmic',
129
+ 10: 'Ascendant',
130
+ }
131
+
132
+ export const CATEGORY_LABELS: Record<ResourceCategory, string> = {
133
+ ore: 'Ore',
134
+ crystal: 'Crystal',
135
+ gas: 'Gas',
136
+ regolith: 'Regolith',
137
+ biomass: 'Biomass',
138
+ }
139
+
140
+ export function tierNumber(tier: string): number {
141
+ return Number(String(tier).replace(/^t/i, ''))
142
+ }
143
+
119
144
  @Struct.type('item')
120
145
  export class Item extends Struct {
121
146
  @Struct.field(UInt16)
@@ -132,4 +157,11 @@ export class Item extends Struct {
132
157
  tier!: ResourceTier
133
158
  @Struct.field('string')
134
159
  color!: string
160
+
161
+ get displayName(): string {
162
+ if (this.name && this.name.length > 0) return this.name
163
+ const adj = TIER_ADJECTIVES[tierNumber(this.tier)] ?? 'Unknown'
164
+ const cat = CATEGORY_LABELS[this.category] ?? 'Resource'
165
+ return `${adj} ${cat}`
166
+ }
135
167
  }