@shipload/sdk 2.0.0-rc24 → 2.0.0-rc25

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-rc24",
4
+ "version": "2.0.0-rc25",
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 {UInt16, UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
2
2
  import {ServerContract} from '../contracts'
3
3
  import {StorageCapability} from '../types/capabilities'
4
- import {getItem} from '../market/items'
4
+ import {getItem} from '../data/catalog'
5
5
  import {INSUFFICIENT_ITEM_QUANTITY} from '../errors'
6
6
 
7
7
  export interface HasCargo {
@@ -0,0 +1,129 @@
1
+ import {UInt16, UInt16Type} from '@wharfkit/antelope'
2
+ import items from './items.json'
3
+ import {tierLabels} from './colors'
4
+ import {itemMetadata} from './metadata'
5
+ import {CATEGORY_LABELS, Item, ItemType, ModuleType, ResourceCategory} from '../types'
6
+
7
+ const itemsById = new Map<number, Item>()
8
+
9
+ for (const raw of items as any[]) {
10
+ const meta = itemMetadata[raw.id]
11
+ if (!meta) {
12
+ throw new Error(`Missing metadata for item ${raw.id}. Add an entry to metadata.ts.`)
13
+ }
14
+ itemsById.set(raw.id, {
15
+ id: raw.id,
16
+ name: meta.name,
17
+ description: meta.description,
18
+ color: meta.color,
19
+ mass: raw.mass,
20
+ type: raw.type,
21
+ tier: raw.tier,
22
+ category: raw.category,
23
+ moduleType: raw.type === 'module' ? raw.subtype : undefined,
24
+ })
25
+ }
26
+
27
+ export const itemIds = Array.from(itemsById.keys())
28
+
29
+ export function getItem(itemId: UInt16Type): Item {
30
+ const id = UInt16.from(itemId).toNumber()
31
+ const item = itemsById.get(id)
32
+ if (!item) throw new Error(`Unknown item id: ${id}`)
33
+ return item
34
+ }
35
+
36
+ export function getItems(): Item[] {
37
+ return Array.from(itemsById.values())
38
+ }
39
+
40
+ export function getResources(opts?: {category?: ResourceCategory; tier?: number}): Item[] {
41
+ const out: Item[] = []
42
+ for (const item of itemsById.values()) {
43
+ if (item.type !== 'resource') continue
44
+ if (opts?.category !== undefined && item.category !== opts.category) continue
45
+ if (opts?.tier !== undefined && item.tier !== opts.tier) continue
46
+ out.push(item)
47
+ }
48
+ return out
49
+ }
50
+
51
+ export function getComponents(opts?: {tier?: number}): Item[] {
52
+ const out: Item[] = []
53
+ for (const item of itemsById.values()) {
54
+ if (item.type !== 'component') continue
55
+ if (opts?.tier !== undefined && item.tier !== opts.tier) continue
56
+ out.push(item)
57
+ }
58
+ return out
59
+ }
60
+
61
+ export function getModules(opts?: {moduleType?: ModuleType; tier?: number}): Item[] {
62
+ const out: Item[] = []
63
+ for (const item of itemsById.values()) {
64
+ if (item.type !== 'module') continue
65
+ if (opts?.moduleType !== undefined && item.moduleType !== opts.moduleType) continue
66
+ if (opts?.tier !== undefined && item.tier !== opts.tier) continue
67
+ out.push(item)
68
+ }
69
+ return out
70
+ }
71
+
72
+ export function getEntityItems(opts?: {tier?: number}): Item[] {
73
+ const out: Item[] = []
74
+ for (const item of itemsById.values()) {
75
+ if (item.type !== 'entity') continue
76
+ if (opts?.tier !== undefined && item.tier !== opts.tier) continue
77
+ out.push(item)
78
+ }
79
+ return out
80
+ }
81
+
82
+ export function __registerItemInternal(item: Item): void {
83
+ itemsById.set(item.id, item)
84
+ }
85
+
86
+ export function resolveItemCategory(id: number): ResourceCategory | undefined {
87
+ const item = itemsById.get(id)
88
+ return item?.category
89
+ }
90
+
91
+ const TYPE_LABEL_BY_STRING: Record<ItemType, string> = {
92
+ resource: 'Resource',
93
+ component: 'Component',
94
+ module: 'Module',
95
+ entity: 'Entity',
96
+ }
97
+
98
+ const TYPE_BY_INDEX: ItemType[] = ['resource', 'component', 'module', 'entity']
99
+
100
+ export function typeLabel(type: ItemType | number): string {
101
+ if (typeof type === 'number') {
102
+ const t = TYPE_BY_INDEX[type]
103
+ return t ? TYPE_LABEL_BY_STRING[t] : `type ${type}`
104
+ }
105
+ return TYPE_LABEL_BY_STRING[type] ?? `type ${type}`
106
+ }
107
+
108
+ export function categoryLabel(cat: ResourceCategory): string {
109
+ return CATEGORY_LABELS[cat]
110
+ }
111
+
112
+ export function tierLabel(tier: number): string {
113
+ return tierLabels[tier] ?? `T${tier}`
114
+ }
115
+
116
+ // Chain rescat enum order from server::getrescats.
117
+ // IMPORTANT: gas=1, crystal=4 — does NOT match the player-facing T-prefix
118
+ // order (ore=100, crystal=200, gas=300, regolith=400, biomass=500).
119
+ // Do not "fix" this ordering — it must stay aligned with the contract enum.
120
+ const CATEGORY_BY_INDEX: ResourceCategory[] = ['ore', 'gas', 'regolith', 'biomass', 'crystal']
121
+
122
+ export function categoryFromIndex(i: number): ResourceCategory | undefined {
123
+ return CATEGORY_BY_INDEX[i]
124
+ }
125
+
126
+ export function categoryLabelFromIndex(i: number): string {
127
+ const cat = categoryFromIndex(i)
128
+ return cat ? CATEGORY_LABELS[cat] : `category ${i}`
129
+ }
@@ -1,4 +1,4 @@
1
- import type {ResourceCategory, ResourceTier} from '../types'
1
+ import type {ResourceCategory} from '../types'
2
2
 
3
3
  export const categoryColors: Record<ResourceCategory, string> = {
4
4
  ore: '#C26D3F',
@@ -8,20 +8,33 @@ export const categoryColors: Record<ResourceCategory, string> = {
8
8
  biomass: '#5A8B3E',
9
9
  }
10
10
 
11
- export const tierColors: Record<ResourceTier, string> = {
12
- t1: '#8b8b8b',
13
- t2: '#4ade80',
14
- t3: '#818cf8',
15
- t4: '#c084fc',
16
- t5: '#fbbf24',
11
+ export const tierColors: Record<number, string> = {
12
+ 1: '#8b8b8b',
13
+ 2: '#4ade80',
14
+ 3: '#818cf8',
15
+ 4: '#c084fc',
16
+ 5: '#fbbf24',
17
+ 6: '#f97316',
18
+ 7: '#ef4444',
19
+ 8: '#ec4899',
20
+ 9: '#06b6d4',
21
+ 10: '#ffffff',
17
22
  }
18
23
 
19
- export const tierLabels: Record<ResourceTier, string> = {
20
- t1: 'Common',
21
- t2: 'Uncommon',
22
- t3: 'Rare',
23
- t4: 'Epic',
24
- t5: 'Legendary',
24
+ // Rarity-tier names (badge labels). Kept disjoint from TIER_ADJECTIVES in
25
+ // types.ts (resource descriptors like "Pristine Ore") so the two vocabularies
26
+ // never collide at any tier.
27
+ export const tierLabels: Record<number, string> = {
28
+ 1: 'Common',
29
+ 2: 'Uncommon',
30
+ 3: 'Rare',
31
+ 4: 'Epic',
32
+ 5: 'Legendary',
33
+ 6: 'Mythic',
34
+ 7: 'Divine',
35
+ 8: 'Celestial',
36
+ 9: 'Eternal',
37
+ 10: 'Transcendent',
25
38
  }
26
39
 
27
40
  export const categoryIcons: Record<ResourceCategory, string> = {
@@ -2,7 +2,7 @@ import items from './items.json'
2
2
  import recipes from './recipes.json'
3
3
  import entities from './entities.json'
4
4
 
5
- import {getItem} from '../market/items'
5
+ import {getItem} from './catalog'
6
6
  import {Item, ModuleType, ResourceCategory} from '../types'
7
7
 
8
8
  export interface RecipeInputItemId {
@@ -1,7 +1,7 @@
1
1
  import {UInt64} from '@wharfkit/antelope'
2
2
  import type {ResourceCategory} from '../types'
3
3
  import {findItemByCategoryAndTier, getRecipe, Recipe} from '../data/recipes-runtime'
4
- import {getItem} from '../market/items'
4
+ import {getItem} from '../data/catalog'
5
5
  import {getStatDefinitions} from './stats'
6
6
  import {deriveResourceStats} from './stratum'
7
7
 
@@ -1,4 +1,4 @@
1
- import {getItem} from '../market/items'
1
+ import {getItem} from '../data/catalog'
2
2
 
3
3
  export const DEPTH_THRESHOLD_T1 = 0
4
4
  export const DEPTH_THRESHOLD_T2 = 2000
@@ -1,6 +1,6 @@
1
1
  import {UInt32, UInt64} from '@wharfkit/antelope'
2
2
  import {ServerContract} from '../contracts'
3
- import {getItem} from '../market/items'
3
+ import {getItem} from '../data/catalog'
4
4
  import {Item} from '../types'
5
5
 
6
6
  export class EntityInventory extends ServerContract.Types.cargo_item {
@@ -6,7 +6,7 @@ import {Container, ContainerStateInput} from './container'
6
6
  import {ITEM_SHIP_T1_PACKED, ITEM_WAREHOUSE_T1_PACKED} from '../data/item-ids'
7
7
  import {getEntityLayout} from '../data/recipes-runtime'
8
8
  import {itemMetadata} from '../data/metadata'
9
- import {getItem} from '../market/items'
9
+ import {getItem} from '../data/catalog'
10
10
  import {
11
11
  getModuleCapabilityType,
12
12
  MODULE_STORAGE,
@@ -45,7 +45,21 @@ export {
45
45
  export type {EntityType, LocationStratum} from './managers'
46
46
  export type {EntityRefInput} from './managers/actions'
47
47
 
48
- export {getItem, getItems, itemIds} from './market/items'
48
+ export {
49
+ getItem,
50
+ getItems,
51
+ itemIds,
52
+ getResources,
53
+ getComponents,
54
+ getModules,
55
+ getEntityItems,
56
+ resolveItemCategory,
57
+ typeLabel,
58
+ categoryLabel,
59
+ categoryFromIndex,
60
+ categoryLabelFromIndex,
61
+ tierLabel,
62
+ } from './data/catalog'
49
63
  export {getCurrentEpoch, getEpochInfo} from './scheduling/epoch'
50
64
  export type {EpochInfo} from './scheduling/epoch'
51
65
  export {
@@ -1,22 +1,18 @@
1
1
  import type {ResolvedItem} from './resolve-item'
2
2
  import type {ResourceCategory} from '../types'
3
- import {CATEGORY_LABELS, TIER_ADJECTIVES, tierNumber} from '../types'
3
+ import {CATEGORY_LABELS, TIER_ADJECTIVES} from '../types'
4
4
  import {formatMass as defaultFormatMass} from '../format'
5
5
 
6
6
  export interface DisplayNameInput {
7
7
  itemType: 'resource' | 'component' | 'module' | 'entity' | string
8
- tier: number | string
8
+ tier: number
9
9
  category?: ResourceCategory
10
10
  name: string
11
11
  }
12
12
 
13
- function asTierNumber(tier: number | string): number {
14
- return typeof tier === 'number' ? tier : tierNumber(tier)
15
- }
16
-
17
13
  export function displayName(resolved: DisplayNameInput): string {
18
14
  if (resolved.itemType === 'resource') {
19
- const adj = TIER_ADJECTIVES[asTierNumber(resolved.tier)] ?? 'Unknown'
15
+ const adj = TIER_ADJECTIVES[resolved.tier] ?? 'Unknown'
20
16
  const cat = resolved.category ? CATEGORY_LABELS[resolved.category] : 'Resource'
21
17
  return `${adj} ${cat}`
22
18
  }
@@ -32,7 +28,7 @@ export interface DescribeOptions {
32
28
  export function describeItem(resolved: ResolvedItem, opts?: DescribeOptions): string {
33
29
  const massFmt = opts?.formatMass ?? defaultFormatMass
34
30
  const mass = massFmt(resolved.mass)
35
- const tier = `T${asTierNumber(resolved.tier)}`
31
+ const tier = `T${resolved.tier}`
36
32
  if (resolved.itemType === 'resource') {
37
33
  const cat = resolved.category ? CATEGORY_LABELS[resolved.category] : 'Resource'
38
34
  const header = `${tier} ${cat}`
@@ -1,7 +1,7 @@
1
1
  import {UInt16, UInt64} from '@wharfkit/antelope'
2
2
  import type {UInt16Type, UInt64Type} from '@wharfkit/antelope'
3
3
  import type {ResourceCategory} from '../types'
4
- import {getItem} from '../market/items'
4
+ import {getItem} from '../data/catalog'
5
5
  import {getEntityLayout} from '../data/recipes-runtime'
6
6
  import {entityMetadata, itemMetadata} from '../data/metadata'
7
7
  import {
@@ -17,7 +17,7 @@ import {
17
17
  SHIP_CARGO_NOT_LOADED,
18
18
  } from '../errors'
19
19
  import {getRecipe, RecipeInput} from '../data/recipes-runtime'
20
- import {getItem} from '../market/items'
20
+ import {getItem} from '../data/catalog'
21
21
  import {distanceBetweenCoordinates, lerp} from '../travel/travel'
22
22
  import {
23
23
  calcStacksMass,
@@ -32,7 +32,7 @@ import {
32
32
  ShipLike,
33
33
  TaskType,
34
34
  } from '../types'
35
- import {getItem} from '../market/items'
35
+ import {getItem} from '../data/catalog'
36
36
  import {hasSystem} from '../utils/system'
37
37
 
38
38
  export function calc_orbital_altitude(mass: number): number {
package/src/types.ts CHANGED
@@ -103,7 +103,6 @@ export interface Distance {
103
103
 
104
104
  export type ItemType = 'resource' | 'component' | 'module' | 'entity'
105
105
  export type ResourceCategory = 'ore' | 'crystal' | 'gas' | 'regolith' | 'biomass'
106
- export type ResourceTier = 't1' | 't2' | 't3' | 't4' | 't5'
107
106
  export type ModuleType =
108
107
  | 'any'
109
108
  | 'engine'
@@ -137,10 +136,6 @@ export const CATEGORY_LABELS: Record<ResourceCategory, string> = {
137
136
  biomass: 'Biomass',
138
137
  }
139
138
 
140
- export function tierNumber(tier: string): number {
141
- return Number(String(tier).replace(/^t/i, ''))
142
- }
143
-
144
139
  export interface Item {
145
140
  id: number
146
141
  name: string
@@ -1,41 +0,0 @@
1
- import {UInt16, UInt16Type} from '@wharfkit/antelope'
2
- import items from '../data/items.json'
3
- import {itemMetadata} from '../data/metadata'
4
- import {Item} from '../types'
5
-
6
- const itemsById = new Map<number, Item>()
7
-
8
- for (const raw of items as any[]) {
9
- const meta = itemMetadata[raw.id]
10
- if (!meta) {
11
- throw new Error(`Missing metadata for item ${raw.id}. Add an entry to metadata.ts.`)
12
- }
13
- itemsById.set(raw.id, {
14
- id: raw.id,
15
- name: meta.name,
16
- description: meta.description,
17
- color: meta.color,
18
- mass: raw.mass,
19
- type: raw.type,
20
- tier: raw.tier,
21
- category: raw.category,
22
- moduleType: raw.type === 'module' ? raw.subtype : undefined,
23
- })
24
- }
25
-
26
- export const itemIds = Array.from(itemsById.keys())
27
-
28
- export function getItem(itemId: UInt16Type): Item {
29
- const id = UInt16.from(itemId).toNumber()
30
- const item = itemsById.get(id)
31
- if (!item) throw new Error(`Unknown item id: ${id}`)
32
- return item
33
- }
34
-
35
- export function getItems(): Item[] {
36
- return Array.from(itemsById.values())
37
- }
38
-
39
- export function __registerItemInternal(item: Item): void {
40
- itemsById.set(item.id, item)
41
- }