@terrafirmagreg-team/recipe 1.2.41 → 1.2.43

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 (47) hide show
  1. package/package.json +4 -4
  2. package/src/components/cards/calc-add-item.tsx +55 -0
  3. package/src/components/cards/card/index.tsx +2 -0
  4. package/src/components/cards/card/text.tsx +20 -4
  5. package/src/components/views/browser/card-grid.tsx +11 -23
  6. package/src/components/views/browser/frame.tsx +8 -33
  7. package/src/components/views/browser/item-view/index.tsx +8 -10
  8. package/src/components/views/browser/settings.tsx +6 -0
  9. package/src/components/views/browser/type-tabs.tsx +5 -0
  10. package/src/components/views/browser/type-view.tsx +9 -47
  11. package/src/components/views/calc/calculator/index.tsx +4 -0
  12. package/src/components/views/calc/flow/index.tsx +42 -1
  13. package/src/components/views/calc/flow/picker-dialogs.tsx +15 -8
  14. package/src/components/views/calc/flow/toolbar.tsx +2 -0
  15. package/src/components/views/calc/flow/view-menu.tsx +13 -0
  16. package/src/components/views/calc/member-picker.tsx +7 -2
  17. package/src/components/views/calc/node-card/actions.tsx +1 -1
  18. package/src/components/views/calc/node-card/badges.tsx +1 -1
  19. package/src/components/views/calc/node-card/far.tsx +1 -1
  20. package/src/components/views/calc/node-card/full.tsx +34 -5
  21. package/src/components/views/calc/node-card/menu.tsx +32 -0
  22. package/src/components/views/calc/recipe-picker/body.tsx +10 -36
  23. package/src/hooks/calc/flow/use-layout.ts +1 -1
  24. package/src/hooks/calc/flow/use-pickers.ts +14 -10
  25. package/src/hooks/calc/use-actions.ts +54 -31
  26. package/src/hooks/calc/use-recipe-ids.ts +33 -0
  27. package/src/hooks/use-card-grid.ts +14 -0
  28. package/src/lib/alloy/parse.ts +6 -3
  29. package/src/lib/browser/card-dim.test.ts +39 -0
  30. package/src/lib/browser/card-dim.ts +38 -0
  31. package/src/lib/browser/lookup.ts +3 -2
  32. package/src/lib/browser/row-match.test.ts +34 -0
  33. package/src/lib/browser/row-match.ts +8 -0
  34. package/src/lib/calc/flow.ts +3 -1
  35. package/src/lib/calc/member.test.ts +178 -0
  36. package/src/lib/calc/member.ts +90 -0
  37. package/src/lib/calc/scheme.test.ts +213 -0
  38. package/src/lib/calc/scheme.ts +8 -3
  39. package/src/lib/calc/tree/index.ts +5 -1
  40. package/src/lib/calc/tree/recipe.test.ts +88 -0
  41. package/src/lib/calc/tree/recipe.ts +19 -3
  42. package/src/lib/calc/wire.test.ts +70 -0
  43. package/src/lib/calc/wire.ts +6 -2
  44. package/src/lib/cards/model.test.ts +61 -1
  45. package/src/lib/cards/model.ts +9 -2
  46. package/src/types/calc-flow-props.ts +2 -0
  47. package/styles/calc.css +4 -0
@@ -9,6 +9,10 @@ import { CalcRecipePicker } from '@terrafirmagreg-team/recipe/components/views/c
9
9
  import { CalcMemberPicker } from '@terrafirmagreg-team/recipe/components/views/calc/member-picker';
10
10
  import { usesForInput } from '@terrafirmagreg-team/recipe/lib/browser/lookup';
11
11
  import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
12
+ import {
13
+ memberTarget,
14
+ type MemberRequest,
15
+ } from '@terrafirmagreg-team/recipe/lib/calc/member';
12
16
  import type {
13
17
  DemandRequest,
14
18
  SupplyRequest,
@@ -50,8 +54,8 @@ function SupplyPicker({
50
54
  kind: slot.kind,
51
55
  recipe: null,
52
56
  availableRecipes: recipes,
53
- tagId: undefined,
54
- members: undefined,
57
+ tagId: slot.tagId,
58
+ members: slot.members,
55
59
  inputs: [],
56
60
  };
57
61
  return (
@@ -188,7 +192,7 @@ export function CalcPickers({
188
192
  onCloseDemand,
189
193
  }: {
190
194
  pickerNode: CalcNode | null;
191
- memberNode: CalcNode | null;
195
+ memberNode: MemberRequest | null;
192
196
  supply: SupplyRequest | null;
193
197
  demand: DemandRequest | null;
194
198
  session: RecipeSession;
@@ -207,6 +211,9 @@ export function CalcPickers({
207
211
  onCloseSupply: () => void;
208
212
  onCloseDemand: () => void;
209
213
  }) {
214
+ const member = memberNode
215
+ ? memberTarget(memberNode, data.tagSelections)
216
+ : undefined;
210
217
  return (
211
218
  <>
212
219
  {pickerNode ? (
@@ -225,16 +232,16 @@ export function CalcPickers({
225
232
  onSetRecipeDefault={data.onSetRecipeDefault}
226
233
  />
227
234
  ) : null}
228
- {memberNode?.tagId && memberNode.members ? (
235
+ {member ? (
229
236
  <CalcMemberPicker
230
237
  open
231
238
  onOpenChange={(open) => {
232
239
  if (!open) onCloseMember();
233
240
  }}
234
- tagId={memberNode.tagId}
235
- members={memberNode.members}
236
- selected={memberNode.materialId}
237
- memberKind={memberNode.kind}
241
+ tagId={member.tagId}
242
+ members={member.members}
243
+ selected={member.selected}
244
+ memberKind={member.kind}
238
245
  dataset={dataset}
239
246
  lang={session.lang}
240
247
  langMap={session.langMap}
@@ -31,6 +31,8 @@ export function CalcToolbar({
31
31
  onModeChange: (mode: CalcViewMode) => void;
32
32
  farCards: CalcFarMode;
33
33
  onFarCardsChange: (mode: CalcFarMode) => void;
34
+ recipeIds: boolean;
35
+ onRecipeIdsChange: (show: boolean) => void;
34
36
  }) {
35
37
  const t = useTranslations();
36
38
  return (
@@ -10,6 +10,7 @@ import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-transl
10
10
  import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
11
11
  import {
12
12
  DropdownMenu,
13
+ DropdownMenuCheckboxItem,
13
14
  DropdownMenuContent,
14
15
  DropdownMenuLabel,
15
16
  DropdownMenuRadioGroup,
@@ -35,11 +36,15 @@ export function CalcViewMenu({
35
36
  onModeChange,
36
37
  farCards,
37
38
  onFarCardsChange,
39
+ recipeIds,
40
+ onRecipeIdsChange,
38
41
  }: {
39
42
  mode: CalcViewMode;
40
43
  onModeChange: (mode: CalcViewMode) => void;
41
44
  farCards: CalcFarMode;
42
45
  onFarCardsChange: (mode: CalcFarMode) => void;
46
+ recipeIds: boolean;
47
+ onRecipeIdsChange: (show: boolean) => void;
43
48
  }) {
44
49
  const t = useTranslations();
45
50
  const modeLabels: Record<CalcViewMode, string> = {
@@ -110,6 +115,14 @@ export function CalcViewMenu({
110
115
  </DropdownMenuRadioGroup>
111
116
  </>
112
117
  ) : null}
118
+ <DropdownMenuSeparator />
119
+ <DropdownMenuCheckboxItem
120
+ className="whitespace-nowrap"
121
+ checked={recipeIds}
122
+ onCheckedChange={(checked) => onRecipeIdsChange(checked === true)}
123
+ >
124
+ {t('Show recipe IDs', { note: 'recipe.calc.ids' })}
125
+ </DropdownMenuCheckboxItem>
113
126
  </DropdownMenuContent>
114
127
  </DropdownMenu>
115
128
  );
@@ -13,7 +13,10 @@ import {
13
13
  } from '@terrafirmagreg-team/ui/components/ui/command';
14
14
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
15
15
  import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
16
- import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
16
+ import {
17
+ stackIdBase,
18
+ type ReferenceKind,
19
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
17
20
 
18
21
  export function CalcMemberList({
19
22
  tagId,
@@ -46,7 +49,9 @@ export function CalcMemberList({
46
49
  key={id}
47
50
  value={id}
48
51
  keywords={[stackDisplayName(langMap, id), id]}
49
- data-checked={id === selected}
52
+ data-checked={
53
+ selected != null && stackIdBase(id) === stackIdBase(selected)
54
+ }
50
55
  onSelect={() => onSelect(tagId, id)}
51
56
  >
52
57
  <Entry
@@ -29,7 +29,7 @@ export function NodeActions({
29
29
  const canPick = node.recipe != null || node.availableRecipes.length > 0;
30
30
 
31
31
  return (
32
- <span className="pointer-events-auto absolute -top-2 right-3 z-30 flex gap-0.5">
32
+ <span className="pointer-events-auto absolute -top-2.5 right-3 z-30 flex gap-0.5">
33
33
  {canPick ? (
34
34
  <Hint label={t('Pick a recipe', { note: 'recipe.calc.pick.title' })} side="top">
35
35
  <button
@@ -65,7 +65,7 @@ export function NodeBadges({
65
65
  }
66
66
  if (!chips.length) return null;
67
67
  return (
68
- <span className="pointer-events-auto absolute right-3 -bottom-1.5 z-30 flex flex-col-reverse items-end gap-0.5">
68
+ <span className="pointer-events-auto absolute right-3 -bottom-2 z-30 flex flex-col-reverse items-end gap-0.5">
69
69
  {chips}
70
70
  </span>
71
71
  );
@@ -91,7 +91,7 @@ export function CalcFarCard({ data, selected }: NodeProps<CalcFlowNode>) {
91
91
  event.stopPropagation();
92
92
  onRequestPicker(node);
93
93
  }}
94
- className={cn(CORNER_BUTTON, 'absolute -top-2 right-1')}
94
+ className={cn(CORNER_BUTTON, 'absolute -top-2.5 right-1')}
95
95
  >
96
96
  <ListFilter className="size-2.5" />
97
97
  </button>
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { memo, useEffect, useState } from 'react';
4
- import { Minus, Plus } from 'lucide-react';
3
+ import { memo, useEffect, useMemo, useState } from 'react';
4
+ import { Check, Copy, Minus, Plus } from 'lucide-react';
5
5
  import {
6
6
  useUpdateNodeInternals,
7
7
  type NodeProps,
@@ -18,14 +18,17 @@ import {
18
18
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
19
19
  import { StackCount } from '@terrafirmagreg-team/game/components/entry/stack-count';
20
20
  import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
21
+ import { ButtonCopy } from '@terrafirmagreg-team/recipe/components/button-copy';
21
22
  import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
22
23
  import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
24
+ import { Marquee } from '@terrafirmagreg-team/ui/components/blocks/text/marquee';
23
25
  import {
24
26
  formatCount,
25
27
  formatFluidAmount,
26
28
  } from '@terrafirmagreg-team/ui/lib/utils/format';
27
29
  import { useCalcSession } from '@terrafirmagreg-team/recipe/hooks/calc/use-calc-session';
28
30
  import { useCalcFar } from '@terrafirmagreg-team/recipe/hooks/calc/use-far-mode';
31
+ import { useCalcRecipeIds } from '@terrafirmagreg-team/recipe/hooks/calc/use-recipe-ids';
29
32
  import { useCalcTier } from '@terrafirmagreg-team/recipe/hooks/calc/use-tier';
30
33
  import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
31
34
  import {
@@ -35,6 +38,7 @@ import {
35
38
  import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
36
39
  import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
37
40
  import { CALC_NODE_W } from '@terrafirmagreg-team/recipe/lib/calc/flow';
41
+ import { pinnedRecipe } from '@terrafirmagreg-team/recipe/lib/calc/member';
38
42
  import { railSpans } from '@terrafirmagreg-team/recipe/lib/calc/ports';
39
43
  import type { CalcFlowNode } from '@terrafirmagreg-team/recipe/lib/calc/flow';
40
44
  import { NodeBadges } from './badges';
@@ -64,6 +68,7 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
64
68
  dataset,
65
69
  mode,
66
70
  recipeBody,
71
+ tagSelections,
67
72
  onRequestPicker,
68
73
  onRequestMemberPicker,
69
74
  onCrafts,
@@ -71,6 +76,7 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
71
76
  const t = useTranslations();
72
77
  const session = useCalcSession();
73
78
  const farCards = useCalcFar();
79
+ const showIds = useCalcRecipeIds();
74
80
  const lang = session?.lang ?? 'en_us';
75
81
  const names = session?.names ?? {};
76
82
  const langMap = session?.langMap;
@@ -79,7 +85,13 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
79
85
  const [imgFail, setImgFail] = useState(false);
80
86
  const name = recipeItemName(names, lang, node.materialId);
81
87
  const recipes = node.availableRecipes;
82
- const body = node.recipe ? recipeBody(node.recipe.recipeId) : undefined;
88
+ const rawBody = node.recipe
89
+ ? recipeBody(node.recipe.recipeId)
90
+ : undefined;
91
+ const body = useMemo(
92
+ () => (rawBody ? pinnedRecipe(rawBody, node, tagSelections) : rawBody),
93
+ [rawBody, node, tagSelections],
94
+ );
83
95
  const src = body
84
96
  ? (recipeImageUrl(dataset, body) ??
85
97
  recipeCardImageUrl(dataset, body.id))
@@ -194,9 +206,9 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
194
206
  {producedBadge}
195
207
  </span>
196
208
  </span>
197
- <span className="w-full truncate px-0.5 text-center text-[9px] leading-tight text-muted-foreground">
209
+ <Marquee className="w-full px-0.5 text-center text-[9px] leading-tight text-muted-foreground">
198
210
  {name}
199
- </span>
211
+ </Marquee>
200
212
  <NodeChips
201
213
  node={node}
202
214
  mini
@@ -398,6 +410,23 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
398
410
  connectable={interactive}
399
411
  />
400
412
  {interactive ? <NodeActions data={data} nodeId={id} /> : null}
413
+ {showIds && body ? (
414
+ <span className="nodrag absolute -bottom-2.5 left-3 z-30 flex">
415
+ <span className="inline-flex max-w-full items-center gap-0.5 rounded-sm border border-border bg-background px-1 py-px shadow-sm">
416
+ <code className="truncate text-[8px] leading-tight text-muted-foreground">
417
+ {body.id}
418
+ </code>
419
+ <ButtonCopy
420
+ value={body.id}
421
+ title={t('Copy recipe id', { note: 'recipe.copy_recipe_id' })}
422
+ aria-label={t('Copy recipe id', { note: 'recipe.copy_recipe_id' })}
423
+ copy={<Copy className="size-2.5" />}
424
+ copied={<Check className="size-2.5" />}
425
+ className="size-3.5 p-0"
426
+ />
427
+ </span>
428
+ </span>
429
+ ) : null}
401
430
  <NodeBadges node={node} />
402
431
  </div>
403
432
  );
@@ -2,6 +2,8 @@
2
2
  import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
3
 
4
4
  import {
5
+ Check,
6
+ Copy,
5
7
  ExternalLink,
6
8
  ListFilter,
7
9
  Mountain,
@@ -22,8 +24,10 @@ import {
22
24
  } from '@terrafirmagreg-team/ui/components/ui/context-menu';
23
25
  import { HoverCardContent } from '@terrafirmagreg-team/ui/components/ui/hover-card';
24
26
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
27
+ import { useCalcRecipeIds } from '@terrafirmagreg-team/recipe/hooks/calc/use-recipe-ids';
25
28
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
26
29
  import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
30
+ import { ButtonCopy } from '@terrafirmagreg-team/recipe/components/button-copy';
27
31
  import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
28
32
  import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
29
33
  import type { CalcKind } from '@terrafirmagreg-team/recipe/types/calc';
@@ -168,7 +172,9 @@ export function PortContextMenu({
168
172
  onRequestSupply,
169
173
  onRequestDemand,
170
174
  onSupplyInput,
175
+ onRequestMemberPicker,
171
176
  } = data;
177
+ const slot = input != null ? node.inputs[input] : undefined;
172
178
  const t = useTranslations();
173
179
  return (
174
180
  <ContextMenuContent>
@@ -206,6 +212,15 @@ export function PortContextMenu({
206
212
  {t('Supply via recipe…', { note: 'recipe.calc.supply.recipe' })}
207
213
  </ContextMenuItem>
208
214
  ) : null}
215
+ {slot?.tagId && slot.members && slot.members.length > 1 ? (
216
+ <ContextMenuItem
217
+ className="whitespace-nowrap"
218
+ onClick={() => onRequestMemberPicker(node, input)}
219
+ >
220
+ <ListFilter />
221
+ {t('Choose tag member', { note: 'recipe.calc.member.title' })}
222
+ </ContextMenuItem>
223
+ ) : null}
209
224
  {out != null ? (
210
225
  <ContextMenuItem
211
226
  className="whitespace-nowrap"
@@ -262,6 +277,8 @@ export function NodeHoverContent({
262
277
  onFail: () => void;
263
278
  }) {
264
279
  const { node, dataset } = data;
280
+ const t = useTranslations();
281
+ const showIds = useCalcRecipeIds();
265
282
  return (
266
283
  <HoverCardContent
267
284
  side="right"
@@ -287,6 +304,21 @@ export function NodeHoverContent({
287
304
  <span className="truncate">
288
305
  {body ? recipeTitle(body, langMap ?? {}) : name}
289
306
  </span>
307
+ {showIds && body ? (
308
+ <span className="ml-auto inline-flex max-w-[60%] shrink-0 items-center gap-0.5 rounded-sm border border-border bg-background px-1 py-px pl-2">
309
+ <code className="truncate text-[9px] leading-tight text-muted-foreground/70">
310
+ {body.id}
311
+ </code>
312
+ <ButtonCopy
313
+ value={body.id}
314
+ title={t('Copy recipe id', { note: 'recipe.copy_recipe_id' })}
315
+ aria-label={t('Copy recipe id', { note: 'recipe.copy_recipe_id' })}
316
+ copy={<Copy className="size-2.5" />}
317
+ copied={<Check className="size-2.5" />}
318
+ className="size-3.5 p-0"
319
+ />
320
+ </span>
321
+ ) : null}
290
322
  </div>
291
323
  {body && src ? (
292
324
  <PagedCard
@@ -3,6 +3,7 @@
3
3
  import { useMemo, useRef, useState, type ReactNode } from 'react';
4
4
  import { Sparkles } from 'lucide-react';
5
5
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
6
+ import { useCardGrid } from '@terrafirmagreg-team/recipe/hooks/use-card-grid';
6
7
  import { useCategoriesById } from '@terrafirmagreg-team/recipe/hooks/use-categories-by-id';
7
8
  import { useFitPages } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
8
9
  import {
@@ -10,13 +11,10 @@ import {
10
11
  DialogTitle,
11
12
  } from '@terrafirmagreg-team/ui/components/ui/dialog';
12
13
  import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
13
- import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
14
14
  import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
15
15
  import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
16
- import {
17
- RecipeCardGrid,
18
- recipeCardDim,
19
- } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
16
+ import { RecipeCardGrid } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
17
+ import { recipeCardFitDim } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
20
18
  import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
21
19
  import { PlaceHeader } from '@terrafirmagreg-team/recipe/components/views/browser/place-header';
22
20
  import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
@@ -86,30 +84,21 @@ export function PickerBody({
86
84
  const focusIndex = rows.findIndex(
87
85
  (row) => row.id === node.recipe?.recipeId,
88
86
  );
87
+ const { grid } = useCardGrid();
89
88
  const list = useFitPages(
90
89
  boxRef,
91
90
  rows,
92
- (row, box) => {
93
- const d = recipeCardDim(index ?? null, categoriesById, row);
94
- return d.h > box.h ? { w: d.w, h: box.h } : d;
95
- },
91
+ (row, box) =>
92
+ recipeCardFitDim(index ?? null, categoriesById, row, box),
96
93
  page,
97
94
  8,
98
95
  pinned && focusIndex >= 0 ? focusIndex : undefined,
99
- true,
96
+ !grid,
100
97
  );
101
98
  const goPage = (next: number) => {
102
99
  setPinned(false);
103
100
  setPage(next);
104
101
  };
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
- };
113
102
  const custom =
114
103
  !!node.recipe &&
115
104
  node.recipe.recipeId !== (defaultRecipeId ?? recipes[0]?.recipeId);
@@ -172,25 +161,8 @@ export function PickerBody({
172
161
  }}
173
162
  />
174
163
  }
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
164
  header={
193
- <div className="flex min-w-0 justify-center">
165
+ <div className="mx-auto w-full max-w-90">
194
166
  <PlaceHeader
195
167
  session={frameSession}
196
168
  overline={t('Categories', { note: 'recipe.axis_type' })}
@@ -213,6 +185,8 @@ export function PickerBody({
213
185
  boxRef={boxRef}
214
186
  maxH={list.box.h}
215
187
  maxW={list.box.w}
188
+ vertical={!grid}
189
+ loading={!list.measured}
216
190
  empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
217
191
  onSwipe={(dir) =>
218
192
  goPage((list.page + dir + list.pages) % Math.max(list.pages, 1))
@@ -44,7 +44,7 @@ export function useFlowLayout({
44
44
  >;
45
45
  mode: CalcViewMode;
46
46
  onRequestPicker: (node: CalcNode) => void;
47
- onRequestMemberPicker: (node: CalcNode) => void;
47
+ onRequestMemberPicker: (node: CalcNode, input?: number) => void;
48
48
  onRequestSupply: (node: CalcNode, input: number) => void;
49
49
  onRequestDemand: (node: CalcNode, output: number) => void;
50
50
  }) {
@@ -3,12 +3,14 @@
3
3
  import { useCallback, useState } from 'react';
4
4
  import type { CalcNode } from '@terrafirmagreg-team/recipe/types/calc';
5
5
 
6
+ import type { MemberRequest } from '@terrafirmagreg-team/recipe/lib/calc/member';
7
+
6
8
  export type SupplyRequest = { node: CalcNode; input: number };
7
9
  export type DemandRequest = { node: CalcNode; output: number };
8
10
 
9
11
  export function useFlowPickers(nodes: CalcNode[]) {
10
12
  const [pickerNode, setPickerNode] = useState<CalcNode | null>(null);
11
- const [memberNode, setMemberNode] = useState<CalcNode | null>(null);
13
+ const [memberNode, setMemberNode] = useState<MemberRequest | null>(null);
12
14
  const [supply, setSupply] = useState<SupplyRequest | null>(null);
13
15
  const [demand, setDemand] = useState<DemandRequest | null>(null);
14
16
  const onRequestPicker = useCallback(
@@ -16,7 +18,7 @@ export function useFlowPickers(nodes: CalcNode[]) {
16
18
  [],
17
19
  );
18
20
  const onRequestMemberPicker = useCallback(
19
- (node: CalcNode) => setMemberNode(node),
21
+ (node: CalcNode, input?: number) => setMemberNode({ node, input }),
20
22
  [],
21
23
  );
22
24
  const onRequestSupply = useCallback(
@@ -31,14 +33,16 @@ export function useFlowPickers(nodes: CalcNode[]) {
31
33
  const [prevNodes, setPrevNodes] = useState(nodes);
32
34
  if (prevNodes !== nodes) {
33
35
  setPrevNodes(nodes);
34
- for (const [node, set] of [
35
- [pickerNode, setPickerNode],
36
- [memberNode, setMemberNode],
37
- ] as const) {
38
- if (!node) continue;
39
- const live = nodes.find((n) => n.id === node.id);
40
- if (live && live !== node) set(live);
41
- else if (!live) set(null);
36
+ if (pickerNode) {
37
+ const live = nodes.find((n) => n.id === pickerNode.id);
38
+ if (!live) setPickerNode(null);
39
+ else if (live !== pickerNode) setPickerNode(live);
40
+ }
41
+ if (memberNode) {
42
+ const live = nodes.find((n) => n.id === memberNode.node.id);
43
+ if (!live) setMemberNode(null);
44
+ else if (live !== memberNode.node)
45
+ setMemberNode({ node: live, input: memberNode.input });
42
46
  }
43
47
  if (supply) {
44
48
  const live = nodes.find((n) => n.id === supply.node.id);
@@ -13,7 +13,7 @@ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
13
13
  import { loadClientRecipe } from '@terrafirmagreg-team/recipe/lib/client/recipe';
14
14
  import { resolveClientTag } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
15
15
  import {
16
- recipeDivisor,
16
+ resolveRecipeAmount,
17
17
  toCalcRecipe,
18
18
  } from '@terrafirmagreg-team/recipe/lib/calc/tree';
19
19
  import { CALC_NODE_W } from '@terrafirmagreg-team/recipe/lib/calc/flow';
@@ -33,6 +33,17 @@ let cardSeq = 0;
33
33
  const newCardId = () =>
34
34
  `c${Date.now().toString(36)}${(cardSeq += 1).toString(36)}`;
35
35
 
36
+ function selectTagMember(
37
+ prev: Record<string, string>,
38
+ tagId: string,
39
+ memberId: string,
40
+ ): Record<string, string> {
41
+ const base = tagId.replace(/^#+/, '');
42
+ const next = { ...prev, [base]: memberId };
43
+ delete next[`#${base}`];
44
+ return next;
45
+ }
46
+
36
47
  async function copyText(text: string) {
37
48
  try {
38
49
  await navigator.clipboard.writeText(text);
@@ -144,7 +155,7 @@ export function useCalcActions({
144
155
 
145
156
  const onSelectTagMember = useCallback(
146
157
  (tagId: string, memberId: string) => {
147
- write({ tagSelections: { ...tagSelections, [tagId]: memberId } });
158
+ write({ tagSelections: selectTagMember(tagSelections, tagId, memberId) });
148
159
  },
149
160
  [tagSelections, write],
150
161
  );
@@ -172,15 +183,9 @@ export function useCalcActions({
172
183
  const consumerCard = cards.find((row) => row.id === cardId);
173
184
  const input = consumerNode?.inputs[inputIndex];
174
185
  if (!consumerNode || !consumerCard || !input?.id) return null;
186
+ const materialId = input.id;
187
+ const kind = input.kind;
175
188
  const need = Math.max(1, input.amount - input.covered);
176
- const per = outputAmount ?? (() => {
177
- const body = recipeId ? recipeBody(recipeId) : undefined;
178
- const calc = body ? toCalcRecipe(body) : undefined;
179
- return calc ? recipeDivisor(calc, input.id!, input.kind) : 0;
180
- })();
181
- const crafts = recipeId && per > 0
182
- ? Math.max(1, Math.ceil(need / per))
183
- : need;
184
189
  const base = consumerCard.pos;
185
190
  const id = newCardId();
186
191
  const nextWires = [
@@ -189,26 +194,42 @@ export function useCalcActions({
189
194
  ),
190
195
  { from: id, to: cardId, input: inputIndex },
191
196
  ];
192
- persist({
193
- cards: [
194
- ...flushAmounts(),
195
- {
196
- id,
197
- materialId: input.id,
198
- kind: input.kind,
199
- recipeId,
200
- crafts,
201
- pos: base
202
- ? { x: base.x - 40, y: base.y + 140 + inputIndex * 24 }
203
- : undefined,
204
- },
205
- ],
206
- wires: nextWires,
207
- tagSelections,
208
- });
197
+ void (async () => {
198
+ const per = recipeId
199
+ ? await resolveRecipeAmount(
200
+ recipeId,
201
+ materialId,
202
+ kind,
203
+ async (id) =>
204
+ recipeBody(id) ??
205
+ (await loadClientRecipe(dataset, id).catch(() => undefined)),
206
+ outputAmount ?? 0,
207
+ )
208
+ : 0;
209
+ const crafts = recipeId && per > 0
210
+ ? Math.max(1, Math.ceil(need / per))
211
+ : need;
212
+ persist({
213
+ cards: [
214
+ ...flushAmounts(),
215
+ {
216
+ id,
217
+ materialId,
218
+ kind,
219
+ recipeId,
220
+ crafts,
221
+ pos: base
222
+ ? { x: base.x - 40, y: base.y + 140 + inputIndex * 24 }
223
+ : undefined,
224
+ },
225
+ ],
226
+ wires: nextWires,
227
+ tagSelections,
228
+ });
229
+ })();
209
230
  return id;
210
231
  },
211
- [nodes, cards, wires, flushAmounts, persist, tagSelections, recipeBody],
232
+ [nodes, cards, wires, flushAmounts, persist, tagSelections, recipeBody, dataset],
212
233
  );
213
234
 
214
235
  const onDemandOutput = useCallback(
@@ -285,7 +306,7 @@ export function useCalcActions({
285
306
  ]
286
307
  : wires,
287
308
  tagSelections: pickedTag
288
- ? { ...tagSelections, [pickedTag]: out.id }
309
+ ? selectTagMember(tagSelections, pickedTag, out.id)
289
310
  : tagSelections,
290
311
  });
291
312
  ensureMaterial?.(materialId);
@@ -384,7 +405,7 @@ export function useCalcActions({
384
405
  ],
385
406
  tagSelections:
386
407
  pinTag && srcOut?.id
387
- ? { ...tagSelections, [pinTag]: srcOut.id }
408
+ ? selectTagMember(tagSelections, pinTag, srcOut.id)
388
409
  : tagSelections,
389
410
  });
390
411
  },
@@ -431,7 +452,7 @@ export function useCalcActions({
431
452
  ],
432
453
  tagSelections:
433
454
  pinTag && srcOut?.id
434
- ? { ...tagSelections, [pinTag]: srcOut.id }
455
+ ? selectTagMember(tagSelections, pinTag, srcOut.id)
435
456
  : tagSelections,
436
457
  });
437
458
  },
@@ -491,12 +512,14 @@ export function useCalcActions({
491
512
  onWireAmount,
492
513
  recipeDefaults,
493
514
  onSetRecipeDefault: setRecipeDefault,
515
+ tagSelections,
494
516
  }),
495
517
  [
496
518
  dataset,
497
519
  recipeBody,
498
520
  onSelectRecipe,
499
521
  onSelectTagMember,
522
+ tagSelections,
500
523
  onSupplyInput,
501
524
  onDemandOutput,
502
525
  onAddCard,