@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/lib/shipload.d.ts +12 -2
- package/lib/shipload.js +35 -26
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +33 -27
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/entities/entity-inventory.ts +1 -1
- package/src/resolution/display-name.ts +9 -27
- package/src/resolution/resolve-item.ts +1 -1
- package/src/types.ts +32 -0
package/package.json
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
|
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
|
}
|
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
|
}
|