@shipload/item-renderer 1.0.0-next.27 → 1.0.0-next.28
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipload/item-renderer",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.28",
|
|
4
4
|
"description": "Deterministic SVG rendering for Shipload items",
|
|
5
5
|
"homepage": "https://github.com/shipload/toolkit/tree/master/packages/item-renderer",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"fonts:copy": "bun run scripts/copy-fonts.ts"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@shipload/sdk": "^1.0.0-next.
|
|
48
|
+
"@shipload/sdk": "^1.0.0-next.28",
|
|
49
49
|
"@wharfkit/antelope": "1.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {el} from './svg.ts'
|
|
2
2
|
import {text} from './text.ts'
|
|
3
3
|
import {tokens} from '../tokens/index.ts'
|
|
4
|
+
import {statStars, STAR_BLOCK_WIDTH} from './stat-stars.ts'
|
|
4
5
|
|
|
5
6
|
export interface StatBarProps {
|
|
6
7
|
x: number
|
|
@@ -11,6 +12,7 @@ export interface StatBarProps {
|
|
|
11
12
|
value: number | null // 0..1023, or null for ranges mode (no value text, no fill)
|
|
12
13
|
color: string
|
|
13
14
|
inverted?: boolean
|
|
15
|
+
stars?: number // 0..3 per-stat rating; only drawn in values mode
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export function statBar({
|
|
@@ -22,6 +24,7 @@ export function statBar({
|
|
|
22
24
|
value,
|
|
23
25
|
color,
|
|
24
26
|
inverted,
|
|
27
|
+
stars,
|
|
25
28
|
}: StatBarProps): string {
|
|
26
29
|
const h = tokens.spacing.statBarHeight
|
|
27
30
|
|
|
@@ -59,6 +62,8 @@ export function statBar({
|
|
|
59
62
|
const displayFraction = inverted ? 1 - clamped / 1023 : clamped / 1023
|
|
60
63
|
const filled = Math.floor(width * displayFraction)
|
|
61
64
|
|
|
65
|
+
const VALUE_COL_W = 34 // room for up to 4 mono digits at size 14, anchored end
|
|
66
|
+
|
|
62
67
|
// value text = primary; identity color = bar + code + chrome
|
|
63
68
|
labelOut += text({
|
|
64
69
|
x: x + width,
|
|
@@ -71,6 +76,15 @@ export function statBar({
|
|
|
71
76
|
anchor: 'end',
|
|
72
77
|
})
|
|
73
78
|
|
|
79
|
+
// stars sit immediately left of the reserved value column
|
|
80
|
+
if (stars !== undefined) {
|
|
81
|
+
labelOut += statStars({
|
|
82
|
+
x: x + width - VALUE_COL_W - STAR_BLOCK_WIDTH,
|
|
83
|
+
y: y - 6,
|
|
84
|
+
n: stars,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
74
88
|
const bar = el('rect', {
|
|
75
89
|
x,
|
|
76
90
|
y,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {el} from './svg.ts'
|
|
2
|
+
|
|
3
|
+
// 24×24 path, identical to the webapp ItemStatRow star.
|
|
4
|
+
const STAR_PATH =
|
|
5
|
+
'M12 2.2l2.95 5.98 6.6.96-4.77 4.65 1.13 6.57L12 17.23 6.09 20.36l1.13-6.57L2.45 9.14l6.6-.96z'
|
|
6
|
+
|
|
7
|
+
export const STAR_SIZE = 9
|
|
8
|
+
export const STAR_GAP = 1
|
|
9
|
+
export const MAX_STARS = 3
|
|
10
|
+
export const STAR_BLOCK_WIDTH = MAX_STARS * STAR_SIZE + (MAX_STARS - 1) * STAR_GAP
|
|
11
|
+
|
|
12
|
+
const ON_COLOR = '#ffce5c'
|
|
13
|
+
const EMPTY_COLOR = 'rgba(255,255,255,0.16)'
|
|
14
|
+
const SCALE = STAR_SIZE / 24
|
|
15
|
+
|
|
16
|
+
export interface StatStarsProps {
|
|
17
|
+
x: number // left edge of the star block
|
|
18
|
+
y: number // vertical center the stars should sit on (text baseline)
|
|
19
|
+
n: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Draws MAX_STARS glyphs left-to-right starting at x; the first `n` are filled.
|
|
23
|
+
export function statStars({x, y, n}: StatStarsProps): string {
|
|
24
|
+
const filled = Math.max(0, Math.min(MAX_STARS, Math.floor(n)))
|
|
25
|
+
const top = y - STAR_SIZE + 1 // center the glyph on the text baseline
|
|
26
|
+
let out = ''
|
|
27
|
+
for (let i = 0; i < MAX_STARS; i++) {
|
|
28
|
+
const gx = x + i * (STAR_SIZE + STAR_GAP)
|
|
29
|
+
out += el('path', {
|
|
30
|
+
d: STAR_PATH,
|
|
31
|
+
transform: `translate(${gx} ${top}) scale(${SCALE})`,
|
|
32
|
+
fill: i < filled ? ON_COLOR : EMPTY_COLOR,
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
return out
|
|
36
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {ResolvedItem} from '@shipload/sdk'
|
|
2
|
-
import {getStatDefinitions, categoryColors, formatLocation} from '@shipload/sdk'
|
|
2
|
+
import {getStatDefinitions, categoryColors, formatLocation, starsForStat} from '@shipload/sdk'
|
|
3
3
|
import type {CargoItem} from '../payload/codec.ts'
|
|
4
4
|
import {panel} from '../primitives/panel.ts'
|
|
5
5
|
import {resourceIcon} from '../primitives/resource-icon.ts'
|
|
@@ -112,6 +112,7 @@ export function renderResource(
|
|
|
112
112
|
value: row.value,
|
|
113
113
|
color: row.color,
|
|
114
114
|
inverted: row.inverted,
|
|
115
|
+
stars: row.value !== null ? starsForStat(row.value) : undefined,
|
|
115
116
|
})
|
|
116
117
|
)
|
|
117
118
|
.join('')
|