@shipload/item-renderer 1.0.0-next.3 → 1.0.0-next.30
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 +2 -2
- package/src/index.ts +22 -8
- package/src/links.ts +11 -8
- package/src/meta.ts +1 -1
- package/src/payload/codec.ts +24 -2
- package/src/primitives/module-slot.ts +4 -4
- package/src/primitives/quantity-badge.ts +15 -5
- package/src/primitives/resource-icon.ts +242 -0
- package/src/primitives/span-paragraph.ts +1 -1
- package/src/primitives/stat-bar.ts +17 -1
- package/src/primitives/stat-stars.ts +36 -0
- package/src/primitives/text.ts +27 -1
- package/src/render.ts +12 -7
- package/src/templates/_shared.ts +113 -2
- package/src/templates/component.ts +41 -61
- package/src/templates/index.ts +2 -1
- package/src/templates/item-cell.ts +86 -38
- package/src/templates/module.ts +59 -145
- package/src/templates/packed-entity.ts +25 -5
- package/src/templates/resource.ts +40 -68
- package/src/templates/ship-panel.ts +80 -85
- package/src/tokens/colors.ts +4 -10
- package/test/fixtures/cargo-items.ts +3 -3
- package/src/primitives/category-icon.ts +0 -110
- package/src/primitives/compact-row.ts +0 -38
package/src/tokens/colors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {tierColors} from '@shipload/sdk'
|
|
1
|
+
import {categoryColors, tierColors} from '@shipload/sdk'
|
|
2
2
|
|
|
3
3
|
export const colors = {
|
|
4
4
|
surface: {
|
|
@@ -10,7 +10,7 @@ export const colors = {
|
|
|
10
10
|
text: {
|
|
11
11
|
primary: '#e6e8ec',
|
|
12
12
|
secondary: '#8f98a8',
|
|
13
|
-
muted: '#
|
|
13
|
+
muted: '#7c8698',
|
|
14
14
|
accent: '#f4c96b',
|
|
15
15
|
},
|
|
16
16
|
brand: {
|
|
@@ -18,16 +18,10 @@ export const colors = {
|
|
|
18
18
|
teal: '#2fd6d1',
|
|
19
19
|
cyan: '#6cb9ff',
|
|
20
20
|
},
|
|
21
|
-
category:
|
|
22
|
-
ore: '#C26D3F',
|
|
23
|
-
crystal: '#4ADBFF',
|
|
24
|
-
gas: '#B8E4A0',
|
|
25
|
-
regolith: '#C4A57B',
|
|
26
|
-
biomass: '#5A8B3E',
|
|
27
|
-
},
|
|
21
|
+
category: categoryColors,
|
|
28
22
|
tier: tierColors,
|
|
29
23
|
accent: {
|
|
30
|
-
component: '#
|
|
24
|
+
component: '#7E93C4',
|
|
31
25
|
},
|
|
32
26
|
capability: {
|
|
33
27
|
engine: '#4a8abf',
|
|
@@ -49,7 +49,7 @@ export function cargoShipT1Packed(opts?: {
|
|
|
49
49
|
})
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export const
|
|
52
|
+
export const ITEM_PLATE = 10001
|
|
53
53
|
|
|
54
54
|
export const FIXTURES = {
|
|
55
55
|
oreT1: cargoOreT1('0x123456789ABCDEF'),
|
|
@@ -61,8 +61,8 @@ export const FIXTURES = {
|
|
|
61
61
|
stats: '0xDEADBEEF1234',
|
|
62
62
|
modules: [],
|
|
63
63
|
}),
|
|
64
|
-
|
|
65
|
-
item_id:
|
|
64
|
+
plate: ServerContract.Types.cargo_item.from({
|
|
65
|
+
item_id: ITEM_PLATE,
|
|
66
66
|
quantity: 1,
|
|
67
67
|
stats: '0x7FFF',
|
|
68
68
|
modules: [],
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type {CategoryIconShape} from '@shipload/sdk'
|
|
2
|
-
import {el} from './svg.ts'
|
|
3
|
-
|
|
4
|
-
export interface CategoryIconPathOpts {
|
|
5
|
-
shape: CategoryIconShape
|
|
6
|
-
cx: number
|
|
7
|
-
cy: number
|
|
8
|
-
size: number
|
|
9
|
-
color: string
|
|
10
|
-
strokeWidth?: number
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface CategoryIconSvgOpts {
|
|
14
|
-
size?: number
|
|
15
|
-
color?: string
|
|
16
|
-
strokeWidth?: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function hexPoints(cx: number, cy: number, r: number): string {
|
|
20
|
-
const pts: string[] = []
|
|
21
|
-
for (let i = 0; i < 6; i++) {
|
|
22
|
-
const angle = (Math.PI / 3) * i - Math.PI / 2
|
|
23
|
-
pts.push(
|
|
24
|
-
`${(cx + r * Math.cos(angle)).toFixed(2)},${(cy + r * Math.sin(angle)).toFixed(2)}`
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
return pts.join(' ')
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function diamondPoints(cx: number, cy: number, r: number): string {
|
|
31
|
-
return [
|
|
32
|
-
`${cx.toFixed(2)},${(cy - r).toFixed(2)}`,
|
|
33
|
-
`${(cx + r).toFixed(2)},${cy.toFixed(2)}`,
|
|
34
|
-
`${cx.toFixed(2)},${(cy + r).toFixed(2)}`,
|
|
35
|
-
`${(cx - r).toFixed(2)},${cy.toFixed(2)}`,
|
|
36
|
-
].join(' ')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function starPoints(cx: number, cy: number, r: number): string {
|
|
40
|
-
const inner = r * 0.45
|
|
41
|
-
const pts: string[] = []
|
|
42
|
-
for (let i = 0; i < 10; i++) {
|
|
43
|
-
const angle = (Math.PI / 5) * i - Math.PI / 2
|
|
44
|
-
const radius = i % 2 === 0 ? r : inner
|
|
45
|
-
pts.push(
|
|
46
|
-
`${(cx + radius * Math.cos(angle)).toFixed(2)},${(cy + radius * Math.sin(angle)).toFixed(2)}`
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
return pts.join(' ')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function categoryIconPath({
|
|
53
|
-
shape,
|
|
54
|
-
cx,
|
|
55
|
-
cy,
|
|
56
|
-
size,
|
|
57
|
-
color,
|
|
58
|
-
strokeWidth,
|
|
59
|
-
}: CategoryIconPathOpts): string {
|
|
60
|
-
const r = size / 2
|
|
61
|
-
const stroked = strokeWidth && strokeWidth > 0
|
|
62
|
-
const shapeAttrs = stroked
|
|
63
|
-
? {
|
|
64
|
-
fill: 'none',
|
|
65
|
-
stroke: color,
|
|
66
|
-
'stroke-width': strokeWidth,
|
|
67
|
-
'stroke-linejoin': 'round' as const,
|
|
68
|
-
}
|
|
69
|
-
: {fill: color}
|
|
70
|
-
switch (shape) {
|
|
71
|
-
case 'hex':
|
|
72
|
-
return el('polygon', {points: hexPoints(cx, cy, r), ...shapeAttrs})
|
|
73
|
-
case 'diamond':
|
|
74
|
-
return el('polygon', {points: diamondPoints(cx, cy, r), ...shapeAttrs})
|
|
75
|
-
case 'star':
|
|
76
|
-
return el('polygon', {points: starPoints(cx, cy, r), ...shapeAttrs})
|
|
77
|
-
case 'circle':
|
|
78
|
-
return el('circle', {cx, cy, r, ...shapeAttrs})
|
|
79
|
-
case 'square':
|
|
80
|
-
return el('rect', {x: cx - r, y: cy - r, width: size, height: size, ...shapeAttrs})
|
|
81
|
-
}
|
|
82
|
-
const _exhaustive: never = shape
|
|
83
|
-
throw new Error(`Unknown CategoryIconShape: ${String(_exhaustive)}`)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function categoryIconSvg(shape: CategoryIconShape, opts: CategoryIconSvgOpts = {}): string {
|
|
87
|
-
const size = opts.size ?? 16
|
|
88
|
-
const color = opts.color ?? '#ffffff'
|
|
89
|
-
const cx = size / 2
|
|
90
|
-
const cy = size / 2
|
|
91
|
-
const iconSize = size * 0.85
|
|
92
|
-
const inner = categoryIconPath({
|
|
93
|
-
shape,
|
|
94
|
-
cx,
|
|
95
|
-
cy,
|
|
96
|
-
size: iconSize,
|
|
97
|
-
color,
|
|
98
|
-
strokeWidth: opts.strokeWidth,
|
|
99
|
-
})
|
|
100
|
-
return el(
|
|
101
|
-
'svg',
|
|
102
|
-
{
|
|
103
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
104
|
-
width: size,
|
|
105
|
-
height: size,
|
|
106
|
-
viewBox: `0 0 ${size} ${size}`,
|
|
107
|
-
},
|
|
108
|
-
inner
|
|
109
|
-
)
|
|
110
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import {text} from './text.ts'
|
|
2
|
-
import {tokens} from '../tokens/index.ts'
|
|
3
|
-
|
|
4
|
-
export interface CompactRowProps {
|
|
5
|
-
x: number
|
|
6
|
-
y: number
|
|
7
|
-
width: number
|
|
8
|
-
label: string
|
|
9
|
-
value: string
|
|
10
|
-
labelColor?: string
|
|
11
|
-
valueColor?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function compactRow(p: CompactRowProps): string {
|
|
15
|
-
const labelColor = p.labelColor ?? tokens.colors.text.secondary
|
|
16
|
-
const valueColor = p.valueColor ?? tokens.colors.text.primary
|
|
17
|
-
return (
|
|
18
|
-
text({
|
|
19
|
-
x: p.x,
|
|
20
|
-
y: p.y,
|
|
21
|
-
value: p.label,
|
|
22
|
-
size: 11,
|
|
23
|
-
weight: 500,
|
|
24
|
-
family: tokens.typography.sans,
|
|
25
|
-
color: labelColor,
|
|
26
|
-
}) +
|
|
27
|
-
text({
|
|
28
|
-
x: p.x + p.width,
|
|
29
|
-
y: p.y,
|
|
30
|
-
value: p.value,
|
|
31
|
-
size: 11,
|
|
32
|
-
weight: 700,
|
|
33
|
-
family: tokens.typography.sans,
|
|
34
|
-
color: valueColor,
|
|
35
|
-
anchor: 'end',
|
|
36
|
-
})
|
|
37
|
-
)
|
|
38
|
-
}
|