@terrafirmagreg-team/recipe 1.2.38 → 1.2.40

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.
Files changed (32) hide show
  1. package/package.json +5 -5
  2. package/src/components/cards/card/index.tsx +1 -3
  3. package/src/components/cards/card/text.tsx +5 -3
  4. package/src/components/cards/paged-card.tsx +0 -3
  5. package/src/components/cards/scroll-card/index.tsx +42 -7
  6. package/src/components/cards/slot-hitbox.tsx +7 -4
  7. package/src/components/cards/strip-card/index.tsx +1 -2
  8. package/src/components/cards/strip-card/member-cell.tsx +4 -2
  9. package/src/components/views/browser/frame.tsx +73 -33
  10. package/src/components/views/browser/index.tsx +0 -2
  11. package/src/components/views/browser/item-view/index.tsx +12 -9
  12. package/src/components/views/browser/item-view/tags.tsx +3 -3
  13. package/src/components/views/browser/query-controls.tsx +1 -1
  14. package/src/components/views/browser/type-view.tsx +40 -1
  15. package/src/components/views/calc/calculator/actions.tsx +7 -3
  16. package/src/components/views/calc/calculator/index.tsx +18 -8
  17. package/src/components/views/calc/edge.tsx +3 -1
  18. package/src/components/views/calc/node-card/badges.tsx +11 -2
  19. package/src/components/views/calc/node-card/full.tsx +63 -10
  20. package/src/components/views/calc/node-card/port-cells.tsx +13 -8
  21. package/src/components/views/calc/node-card/ports.tsx +39 -13
  22. package/src/components/views/calc/recipe-picker/body.tsx +34 -1
  23. package/src/components/views/calc/sidebar.tsx +8 -2
  24. package/src/hooks/calc/use-actions.ts +2 -0
  25. package/src/hooks/calc/use-amounts.ts +22 -3
  26. package/src/hooks/calc/use-storage.ts +2 -1
  27. package/src/lib/calc/flow.ts +2 -0
  28. package/src/lib/cards/model.test.ts +21 -0
  29. package/src/lib/cards/model.ts +7 -0
  30. package/src/lib/data/parse/widgets.test.ts +51 -0
  31. package/src/lib/data/scroll.ts +9 -0
  32. package/src/components/cards/glare-filter.tsx +0 -29
@@ -73,7 +73,9 @@ function EdgeAmountLabel({ ctx }: { ctx: ChevronEdgePathContext }) {
73
73
  ? recipeItemName(session.names, session.lang, matId)
74
74
  : matId;
75
75
  const fmt =
76
- matKind === 'fluid' ? formatFluidAmount : (n: number) => formatCount(n);
76
+ matKind === 'fluid'
77
+ ? formatFluidAmount
78
+ : (n: number) => formatCount(n, 1_000);
77
79
  return (
78
80
  <button
79
81
  type="button"
@@ -42,14 +42,23 @@ export function NodeBadges({
42
42
  );
43
43
  }
44
44
  if (node.remaining < 0) {
45
+ const fmtAmount =
46
+ node.kind === 'fluid'
47
+ ? formatFluidAmount
48
+ : (n: number) => formatCount(n, 1_000);
49
+ const overTip = t('Shortage: {wired} wired, only {produced} produced', {
50
+ note: 'recipe.calc.overdrawn',
51
+ })
52
+ .replaceAll('{wired}', fmtAmount(node.allocated))
53
+ .replaceAll('{produced}', fmtAmount(node.produced));
45
54
  chips.push(
46
- <Hint key="over" label={t('Overdrawn: more is wired out than produced', { note: 'recipe.calc.overdrawn' })} side="top">
55
+ <Hint key="over" label={overTip} side="top">
47
56
  <span
48
57
  className={cn(CORNER_CHIP, 'border-red-500/40 text-red-500')}
49
58
  >
50
59
  {node.kind === 'fluid'
51
60
  ? formatFluidAmount(node.remaining)
52
- : formatCount(node.remaining)}
61
+ : formatCount(node.remaining, 1_000)}
53
62
  </span>
54
63
  </Hint>,
55
64
  );
@@ -43,6 +43,17 @@ import { NodeActions } from './actions';
43
43
  import { PortRailIn, PortRailOut } from './port-rails';
44
44
  import { NodeContextMenu, NodeHoverContent } from './menu';
45
45
 
46
+ const CRAFTS_SUFFIX: Record<string, number> = { k: 1e3, m: 1e6, b: 1e9 };
47
+
48
+ function parseCraftsInput(raw: string): number | null {
49
+ const match = /^(\d+(?:\.\d+)?)\s*([kmb])?$/i.exec(raw.trim());
50
+ if (!match) return null;
51
+ const value = Math.round(
52
+ Number(match[1]) * (CRAFTS_SUFFIX[match[2]?.toLowerCase() ?? ''] ?? 1),
53
+ );
54
+ return Number.isFinite(value) ? Math.max(1, value) : null;
55
+ }
56
+
46
57
  export const CalcNodeCardFull = memo(function CalcNodeCardFull({
47
58
  data,
48
59
  id,
@@ -117,9 +128,12 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
117
128
  [id],
118
129
  );
119
130
 
131
+ const crafts = data.pendingCrafts?.get(id) ?? node.crafts;
120
132
  const fmtAmount =
121
- node.kind === 'fluid' ? formatFluidAmount : (n: number) => formatCount(n);
122
- const producedTip = t('Produced {produced} → wired {allocated} → surplus {remaining}', {
133
+ node.kind === 'fluid'
134
+ ? formatFluidAmount
135
+ : (n: number) => formatCount(n, 1_000);
136
+ const producedTip = t('Surplus: {produced} produced, {allocated} wired, {remaining} left', {
123
137
  note: 'recipe.calc.hint.produced',
124
138
  })
125
139
  .replaceAll('{produced}', fmtAmount(node.produced))
@@ -232,6 +246,24 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
232
246
  <div className="mx-1 flex min-w-0 items-center gap-1">
233
247
  {interactive ? (
234
248
  <span className="nodrag ml-auto flex shrink-0 items-center gap-0.5">
249
+ {[2, 4].map((div) => (
250
+ <button
251
+ key={div}
252
+ type="button"
253
+ aria-label={
254
+ div === 2
255
+ ? t('Halve crafts', { note: 'recipe.calc.crafts.d2' })
256
+ : t('Quarter crafts', { note: 'recipe.calc.crafts.d4' })
257
+ }
258
+ className="grid h-4 min-w-4 place-items-center rounded border border-border bg-background px-px text-[8px] font-medium leading-none text-muted-foreground hover:text-foreground"
259
+ onClick={(e) => {
260
+ e.stopPropagation();
261
+ onCrafts(id, (crafts) => Math.max(1, Math.round(crafts / div)));
262
+ }}
263
+ >
264
+ ÷{div}
265
+ </button>
266
+ ))}
235
267
  <button
236
268
  type="button"
237
269
  aria-label={t('Fewer crafts', { note: 'recipe.calc.crafts.down' })}
@@ -244,22 +276,25 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
244
276
  <Minus className="size-2.5" />
245
277
  </button>
246
278
  <input
247
- key={node.crafts}
279
+ key={crafts}
248
280
  type="text"
249
281
  inputMode="numeric"
250
- defaultValue={node.crafts}
251
- title={t('Crafts', { note: 'recipe.calc.crafts.title' })}
282
+ defaultValue={crafts}
283
+ size={Math.min(9, Math.max(3, String(crafts).length))}
284
+ title={`${t('Crafts', { note: 'recipe.calc.crafts.title' })}: ${String(crafts)}`}
252
285
  aria-label={t('Crafts', { note: 'recipe.calc.crafts.title' })}
253
- className="w-9 rounded border border-transparent bg-transparent text-center tabular-nums hover:border-border focus:border-border focus:outline-none"
286
+ className="w-auto min-w-9 rounded border border-border bg-transparent text-center tabular-nums focus:outline-none"
254
287
  onClick={(e) => e.stopPropagation()}
255
288
  onKeyDown={(e) => {
256
289
  if (e.key === 'Enter') e.currentTarget.blur();
257
290
  }}
258
291
  onBlur={(e) => {
259
- onCrafts(
260
- id,
261
- Math.max(1, Math.round(Number(e.target.value) || 1)),
262
- );
292
+ const value = parseCraftsInput(e.target.value);
293
+ if (value == null) {
294
+ e.target.value = String(crafts);
295
+ return;
296
+ }
297
+ onCrafts(id, value);
263
298
  }}
264
299
  />
265
300
  <button
@@ -273,6 +308,24 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
273
308
  >
274
309
  <Plus className="size-2.5" />
275
310
  </button>
311
+ {[2, 4].map((mult) => (
312
+ <button
313
+ key={mult}
314
+ type="button"
315
+ aria-label={
316
+ mult === 2
317
+ ? t('Double crafts', { note: 'recipe.calc.crafts.x2' })
318
+ : t('Quadruple crafts', { note: 'recipe.calc.crafts.x4' })
319
+ }
320
+ className="grid h-4 min-w-4 place-items-center rounded border border-border bg-background px-px text-[8px] font-medium leading-none text-muted-foreground hover:text-foreground"
321
+ onClick={(e) => {
322
+ e.stopPropagation();
323
+ onCrafts(id, (crafts) => crafts * mult);
324
+ }}
325
+ >
326
+ ×{mult}
327
+ </button>
328
+ ))}
276
329
  </span>
277
330
  ) : null}
278
331
  </div>
@@ -21,7 +21,7 @@ import type {
21
21
  } from '@terrafirmagreg-team/recipe/types/calc';
22
22
  import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
23
23
  import { PortContextMenu } from './menu';
24
- import { formatPortCount, PortCount } from './ports';
24
+ import { PortCount, portAmountLine } from './ports';
25
25
 
26
26
  interface CellProps {
27
27
  index: number;
@@ -49,7 +49,6 @@ export function OutputCell({
49
49
  }) {
50
50
  const name = recipeItemName(names, lang, out.id);
51
51
  const count = out.remaining;
52
- const qty = formatPortCount(count, out.kind);
53
52
  return (
54
53
  <ContextMenu>
55
54
  <ContextMenuTrigger
@@ -83,12 +82,13 @@ export function OutputCell({
83
82
  dataset={dataset}
84
83
  lang={lang}
85
84
  langMap={langMap}
86
- name={`${name} ×${qty}`}
85
+ name={name}
86
+ subheader={portAmountLine(count, out.kind)}
87
87
  size="sm"
88
88
  href={false}
89
89
  tooltip="adaptive"
90
90
  />
91
- <PortCount value={count} kind={out.kind} />
91
+ <PortCount value={count} kind={out.kind} name={name} />
92
92
  </span>
93
93
  </Handle>
94
94
  }
@@ -123,7 +123,6 @@ export function InputCell({
123
123
  const id = inp.id;
124
124
  const name = id ? recipeItemName(names, lang, id) : (inp.tagId ?? '?');
125
125
  const uncovered = Math.max(0, inp.amount - inp.covered);
126
- const qty = formatPortCount(uncovered, inp.kind);
127
126
  const state = inp.wired
128
127
  ? uncovered <= 0
129
128
  ? 'full'
@@ -160,7 +159,8 @@ export function InputCell({
160
159
  dataset={dataset}
161
160
  lang={lang}
162
161
  langMap={langMap}
163
- name={`${name} ×${qty}`}
162
+ name={name}
163
+ subheader={portAmountLine(uncovered, inp.kind)}
164
164
  size="sm"
165
165
  href={false}
166
166
  tooltip="adaptive"
@@ -172,7 +172,8 @@ export function InputCell({
172
172
  dataset={dataset}
173
173
  lang={lang}
174
174
  langMap={langMap}
175
- name={`${name} ×${qty}`}
175
+ name={name}
176
+ subheader={portAmountLine(uncovered, inp.kind)}
176
177
  size="sm"
177
178
  href={false}
178
179
  tooltip="adaptive"
@@ -180,7 +181,11 @@ export function InputCell({
180
181
  ) : (
181
182
  <span className="text-[9px]">?</span>
182
183
  )}
183
- <PortCount value={uncovered} kind={inp.kind} />
184
+ <PortCount
185
+ value={uncovered}
186
+ kind={inp.kind}
187
+ name={id || inp.tagId ? name : undefined}
188
+ />
184
189
  </span>
185
190
  </Handle>
186
191
  }
@@ -1,7 +1,12 @@
1
1
  'use client';
2
2
 
3
+ import type { ReactNode } from 'react';
3
4
  import { Handle, Position } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
4
- import { formatCount } from '@terrafirmagreg-team/ui/lib/utils/format';
5
+ import {
6
+ formatCount,
7
+ formatFluidAmount,
8
+ } from '@terrafirmagreg-team/ui/lib/utils/format';
9
+ import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
5
10
  import { PORT_OUT } from '@terrafirmagreg-team/recipe/lib/calc/ports';
6
11
  import type {
7
12
  CalcKind,
@@ -9,24 +14,45 @@ import type {
9
14
  } from '@terrafirmagreg-team/recipe/types/calc';
10
15
 
11
16
  export function formatPortCount(value: number, kind: CalcKind): string {
12
- if (kind === 'fluid') {
13
- if (Math.abs(value) >= 1_000)
14
- return `${Math.round((value / 1000) * 100) / 100}`;
15
- return `${Math.round(value)}`;
16
- }
17
+ if (kind === 'fluid') return formatFluidAmount(value);
17
18
  return formatCount(value, 1_000);
18
19
  }
19
20
 
20
- export function PortCount({ value, kind }: { value: number; kind: CalcKind }) {
21
+ export function portAmountLine(value: number, kind: CalcKind): ReactNode {
22
+ return (
23
+ <p className="text-muted-foreground">
24
+ {value.toLocaleString('en-US')}
25
+ {kind === 'fluid' ? ' mB' : ''}
26
+ </p>
27
+ );
28
+ }
29
+
30
+ export function PortCount({
31
+ value,
32
+ kind,
33
+ name,
34
+ }: {
35
+ value: number;
36
+ kind: CalcKind;
37
+ name?: string;
38
+ }) {
21
39
  const text = formatPortCount(value, kind);
22
40
  return (
23
- <span
24
- className="calc-port-count"
25
- data-len={text.length >= 5 ? 'xl' : text.length >= 4 ? 'l' : undefined}
26
- title={String(value)}
41
+ <Hint
42
+ label={
43
+ <>
44
+ <p>{name}</p>
45
+ {portAmountLine(value, kind)}
46
+ </>
47
+ }
27
48
  >
28
- {text}
29
- </span>
49
+ <span
50
+ className="calc-port-count"
51
+ data-len={text.length >= 5 ? 'xl' : text.length >= 4 ? 'l' : undefined}
52
+ >
53
+ {text}
54
+ </span>
55
+ </Hint>
30
56
  );
31
57
  }
32
58
 
@@ -10,6 +10,7 @@ import {
10
10
  DialogTitle,
11
11
  } from '@terrafirmagreg-team/ui/components/ui/dialog';
12
12
  import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
13
+ import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
13
14
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
14
15
  import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
15
16
  import {
@@ -101,6 +102,14 @@ export function PickerBody({
101
102
  setPinned(false);
102
103
  setPage(next);
103
104
  };
105
+ const goCategory = (dir: -1 | 1) => {
106
+ const cur = categories.indexOf(active ?? '');
107
+ const next =
108
+ categories[(cur + dir + categories.length) % categories.length];
109
+ if (!next || next === active) return;
110
+ setTab(next);
111
+ goPage(0);
112
+ };
104
113
  const custom =
105
114
  !!node.recipe &&
106
115
  node.recipe.recipeId !== (defaultRecipeId ?? recipes[0]?.recipeId);
@@ -163,7 +172,31 @@ export function PickerBody({
163
172
  }}
164
173
  />
165
174
  }
166
- header={<PlaceHeader session={frameSession} />}
175
+ navPrev={
176
+ <PagerArrow
177
+ dir={-1}
178
+ label={t('Previous category', { note: 'recipe.axis.prev' })}
179
+ disabled={categories.length < 2}
180
+ onClick={() => goCategory(-1)}
181
+ />
182
+ }
183
+ navNext={
184
+ <PagerArrow
185
+ dir={1}
186
+ label={t('Next category', { note: 'recipe.axis.next' })}
187
+ disabled={categories.length < 2}
188
+ onClick={() => goCategory(1)}
189
+ />
190
+ }
191
+ onNavWheel={goCategory}
192
+ header={
193
+ <div className="flex min-w-0 justify-center">
194
+ <PlaceHeader
195
+ session={frameSession}
196
+ overline={t('Categories', { note: 'recipe.axis_type' })}
197
+ />
198
+ </div>
199
+ }
167
200
  rail={
168
201
  <WorkstationRail
169
202
  session={session}
@@ -11,7 +11,10 @@ import {
11
11
  LeftSidebarTree,
12
12
  } from '@terrafirmagreg-team/ui/components/layouts/left-sidebar';
13
13
  import { recipeStackHref } from '@terrafirmagreg-team/recipe/lib/links';
14
- import { formatCount } from '@terrafirmagreg-team/ui/lib/utils/format';
14
+ import {
15
+ formatCount,
16
+ formatFluidAmount,
17
+ } from '@terrafirmagreg-team/ui/lib/utils/format';
15
18
  import { CalcTrees } from '@terrafirmagreg-team/recipe/components/views/calc/trees';
16
19
  import type { CalcMaterial } from '@terrafirmagreg-team/recipe/types/calc';
17
20
  import type { CalcTreeEntry } from '@terrafirmagreg-team/recipe/lib/calc/storage';
@@ -109,7 +112,10 @@ export function CalcSidebar({
109
112
  className="ms-auto shrink-0 tabular-nums text-xs text-muted-foreground"
110
113
  title={row.amount.toLocaleString()}
111
114
  >
112
- ×{formatCount(row.amount)}
115
+ ×
116
+ {row.kind === 'fluid'
117
+ ? formatFluidAmount(row.amount)
118
+ : formatCount(row.amount, 1_000)}
113
119
  </span>
114
120
  </>
115
121
  ),
@@ -86,6 +86,7 @@ export function useCalcActions({
86
86
  }) {
87
87
  const {
88
88
  checked: shared,
89
+ isLoading: sharing,
89
90
  error: shareError,
90
91
  onClick: onShare,
91
92
  } = useCopyButton(async () => {
@@ -513,6 +514,7 @@ export function useCalcActions({
513
514
 
514
515
  return {
515
516
  shared,
517
+ sharing,
516
518
  shareError,
517
519
  onShare,
518
520
  flowData,
@@ -1,8 +1,9 @@
1
1
  'use client';
2
2
 
3
- import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import type {
5
5
  CalcCard,
6
+ CalcNode,
6
7
  CalcWire,
7
8
  CalculatorState,
8
9
  } from '@terrafirmagreg-team/recipe/types/calc';
@@ -11,11 +12,13 @@ export function useCalcAmounts({
11
12
  cards,
12
13
  wires,
13
14
  tagSelections,
15
+ resolved,
14
16
  persist,
15
17
  }: {
16
18
  cards: CalcCard[];
17
19
  wires: CalcWire[];
18
20
  tagSelections: Record<string, string>;
21
+ resolved: CalcNode[];
19
22
  persist: (next: CalculatorState) => void;
20
23
  }) {
21
24
  const [pending, setPending] = useState<CalcCard[] | null>(null);
@@ -28,13 +31,21 @@ export function useCalcAmounts({
28
31
  [],
29
32
  );
30
33
 
34
+ if (pending) {
35
+ const settled = pending.every(
36
+ (card) =>
37
+ (resolved.find((node) => node.id === card.id)?.crafts ??
38
+ card.crafts) === card.crafts,
39
+ );
40
+ if (settled) setPending(null);
41
+ }
42
+
31
43
  const flushAmounts = useCallback((): CalcCard[] => {
32
44
  if (amountTimer.current) {
33
45
  clearTimeout(amountTimer.current);
34
46
  amountTimer.current = undefined;
35
47
  }
36
48
  if (!pending) return cards;
37
- setPending(null);
38
49
  return pending;
39
50
  }, [pending, cards]);
40
51
 
@@ -56,15 +67,23 @@ export function useCalcAmounts({
56
67
  if (amountTimer.current) clearTimeout(amountTimer.current);
57
68
  amountTimer.current = setTimeout(() => {
58
69
  amountTimer.current = undefined;
59
- setPending(null);
60
70
  persist({ cards: next, wires, tagSelections });
61
71
  }, 300);
62
72
  },
63
73
  [pending, cards, persist, wires, tagSelections],
64
74
  );
65
75
 
76
+ const pendingCrafts = useMemo(
77
+ () =>
78
+ pending
79
+ ? new Map(pending.map((card) => [card.id, card.crafts]))
80
+ : null,
81
+ [pending],
82
+ );
83
+
66
84
  return {
67
85
  displayCards: pending ?? cards,
86
+ pendingCrafts,
68
87
  flushAmounts,
69
88
  onCrafts,
70
89
  };
@@ -18,6 +18,7 @@ import {
18
18
  type CalcTreeEntry,
19
19
  } from '@terrafirmagreg-team/recipe/lib/calc/storage';
20
20
  import type { CalculatorState } from '@terrafirmagreg-team/recipe/types/calc';
21
+ import { stripMcFormat } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
21
22
 
22
23
  const EMPTY_TABS: CalcTreeEntry[] = [];
23
24
  const EMPTY_CALC: CalculatorState = {
@@ -97,7 +98,7 @@ export function useCalcStorage(storageKey: string) {
97
98
  (id: string, name: string) => {
98
99
  updateCalcTab(storageKey, id, (tab) => ({
99
100
  ...tab,
100
- name: name.trim() || undefined,
101
+ name: stripMcFormat(name).trim() || undefined,
101
102
  }));
102
103
  },
103
104
  [storageKey],
@@ -71,6 +71,7 @@ export type CalcFlowData = {
71
71
  cardId: string,
72
72
  crafts: number | ((current: number) => number),
73
73
  ) => void;
74
+ pendingCrafts?: Map<string, number> | null;
74
75
  onWire: (from: string, to: string, input: number, out?: number) => void;
75
76
  onUnwire: (
76
77
  from: string,
@@ -240,6 +241,7 @@ function sameFlowData(a: CalcFlowData, b: CalcFlowData): boolean {
240
241
  a.onRemoveCard === b.onRemoveCard &&
241
242
  a.onMoveCard === b.onMoveCard &&
242
243
  a.onCrafts === b.onCrafts &&
244
+ a.pendingCrafts === b.pendingCrafts &&
243
245
  a.onWire === b.onWire &&
244
246
  a.onUnwire === b.onUnwire &&
245
247
  a.onRewire === b.onRewire &&
@@ -0,0 +1,21 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { widgetTextColor } from '@terrafirmagreg-team/recipe/lib/cards/model';
4
+
5
+ test('widgetTextColor defaults uncolored shadowed text to white', () => {
6
+ assert.equal(widgetTextColor(undefined, true), 0xffffff);
7
+ });
8
+
9
+ test('widgetTextColor defaults uncolored unshadowed text to black', () => {
10
+ assert.equal(widgetTextColor(undefined, false), 0x000000);
11
+ });
12
+
13
+ test('widgetTextColor keeps explicit colors', () => {
14
+ assert.equal(widgetTextColor(0xffffff, false), 0xffffff);
15
+ assert.equal(widgetTextColor(0xff0000, true), 0xff0000);
16
+ assert.equal(widgetTextColor(0, false), 0);
17
+ });
18
+
19
+ test('widgetTextColor masks color to 24 bits', () => {
20
+ assert.equal(widgetTextColor(0x1ff0000, true), 0xff0000);
21
+ });
@@ -3,6 +3,13 @@ import type {
3
3
  RecipeTextWidget,
4
4
  } from '@terrafirmagreg-team/recipe/lib/data/dto';
5
5
 
6
+ export function widgetTextColor(
7
+ color: number | undefined,
8
+ shadow: boolean,
9
+ ): number {
10
+ return (color ?? (shadow ? 0xffffff : 0)) & 0xffffff;
11
+ }
12
+
6
13
  export type CardStripGeo = {
7
14
  slots: RecipeSlotWidget[];
8
15
  top: number;
@@ -0,0 +1,51 @@
1
+ import assert from 'node:assert/strict';
2
+ import { test } from 'node:test';
3
+ import { dumpTextLines } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
4
+ import { parseDecorWidgets } from '@terrafirmagreg-team/recipe/lib/data/parse/widgets';
5
+
6
+ const LANG = {
7
+ 'tfg.emi.fluid_veins.biomes': 'Биомы:',
8
+ 'tfg.emi.fluid_veins.yield_range': 'Выход: %s-%s',
9
+ };
10
+
11
+ test('parseDecorWidgets keeps tooltipComponents next to plain tooltip', () => {
12
+ const [widget] = parseDecorWidgets([
13
+ {
14
+ type: 'text',
15
+ x: 8,
16
+ y: 126,
17
+ w: 22,
18
+ h: 9,
19
+ text: '··· +8',
20
+ tooltip: ['Coastal Dunes, Shore'],
21
+ tooltipComponents: [
22
+ { translate: 'tfg.emi.fluid_veins.biomes' },
23
+ { text: '§7Coastal Dunes' },
24
+ ],
25
+ },
26
+ ]);
27
+ assert.equal(widget?.type, 'text');
28
+ if (widget?.type !== 'text') return;
29
+ assert.equal(widget.tooltip?.[0], 'Coastal Dunes, Shore');
30
+ assert.equal(widget?.tooltipComponents?.length, 2);
31
+ assert.equal(
32
+ widget?.tooltipComponents?.[0]?.translate,
33
+ 'tfg.emi.fluid_veins.biomes',
34
+ );
35
+ });
36
+
37
+ test('dumpTextLines resolves translate keys from lang map', () => {
38
+ const lines = dumpTextLines(LANG, [
39
+ { translate: 'tfg.emi.fluid_veins.biomes' },
40
+ {
41
+ translate: 'tfg.emi.fluid_veins.yield_range',
42
+ with: [{ text: '100' }, { text: '200' }],
43
+ },
44
+ { text: '§7plain' },
45
+ ]);
46
+ assert.deepEqual(lines, ['Биомы:', 'Выход: 100-200', '§7plain']);
47
+ });
48
+
49
+ test('dumpTextLines leaves untranslated keys empty like the card fallback', () => {
50
+ assert.deepEqual(dumpTextLines({}, [{ translate: 'missing.key' }]), ['']);
51
+ });
@@ -8,6 +8,11 @@ import {
8
8
  asTaggedReference,
9
9
  type TaggedReference,
10
10
  } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
11
+ import {
12
+ asDumpText,
13
+ asDumpTextList,
14
+ type DumpText,
15
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/text';
11
16
 
12
17
  export type ScrollRect = { x: number; y: number; w: number; h: number };
13
18
 
@@ -42,8 +47,10 @@ export type ScrollElement = {
42
47
  base?: TaggedReference;
43
48
  mark?: boolean;
44
49
  tooltip?: string[];
50
+ tooltipComponents?: DumpText[];
45
51
  label?: string;
46
52
  text?: string;
53
+ component?: DumpText;
47
54
  color?: number;
48
55
  pin?: boolean;
49
56
  u?: number;
@@ -140,8 +147,10 @@ function scrollElement(value: unknown): ScrollElement | undefined {
140
147
  .map(asString)
141
148
  .filter((line): line is string => line !== undefined && line.length > 0)
142
149
  : undefined,
150
+ tooltipComponents: asDumpTextList(raw.tooltipComponents),
143
151
  label: asString(raw.label),
144
152
  text: asString(raw.text),
153
+ component: asDumpText(raw.component),
145
154
  color: asNumber(raw.color),
146
155
  pin: asBool(raw.pin) === true || undefined,
147
156
  u: asNumber(raw.u),
@@ -1,29 +0,0 @@
1
- import type { CSSProperties } from 'react';
2
-
3
- export const RECIPE_GLARE_FILTER_ID = 'recipe-glare-cut';
4
-
5
- export const recipeGlareFilter: CSSProperties = {
6
- filter: `url(#${RECIPE_GLARE_FILTER_ID})`,
7
- };
8
-
9
- export function RecipeGlareFilter() {
10
- return (
11
- <svg aria-hidden className="absolute size-0 overflow-hidden">
12
- <defs>
13
- <filter
14
- id={RECIPE_GLARE_FILTER_ID}
15
- colorInterpolationFilters="sRGB"
16
- >
17
- <feColorMatrix
18
- type="matrix"
19
- values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 -2.946 -9.912 -1.001 13.44 0"
20
- />
21
- <feComponentTransfer>
22
- <feFuncA type="table" tableValues="0.03 1" />
23
- </feComponentTransfer>
24
- </filter>
25
- </defs>
26
- </svg>
27
- );
28
- }
29
-