@terrafirmagreg-team/recipe 1.2.40 → 1.2.42
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/components/cards/calc-add-item.tsx +55 -0
- package/src/components/cards/card/index.tsx +2 -0
- package/src/components/cards/card/text.tsx +20 -4
- package/src/components/views/browser/card-grid.tsx +11 -23
- package/src/components/views/browser/frame.tsx +7 -10
- package/src/components/views/browser/item-view/index.tsx +8 -10
- package/src/components/views/browser/settings.tsx +6 -0
- package/src/components/views/browser/toolbar.tsx +7 -7
- package/src/components/views/browser/type-view.tsx +10 -10
- package/src/components/views/calc/calculator/index.tsx +4 -0
- package/src/components/views/calc/flow/index.tsx +42 -1
- package/src/components/views/calc/flow/picker-dialogs.tsx +15 -8
- package/src/components/views/calc/flow/toolbar.tsx +2 -0
- package/src/components/views/calc/flow/view-menu.tsx +13 -0
- package/src/components/views/calc/member-picker.tsx +7 -2
- package/src/components/views/calc/node-card/full.tsx +34 -5
- package/src/components/views/calc/node-card/menu.tsx +32 -0
- package/src/components/views/calc/recipe-picker/body.tsx +9 -9
- package/src/hooks/calc/flow/use-layout.ts +1 -1
- package/src/hooks/calc/flow/use-pickers.ts +14 -10
- package/src/hooks/calc/use-actions.ts +54 -31
- package/src/hooks/calc/use-recipe-ids.ts +33 -0
- package/src/hooks/use-card-grid.ts +14 -0
- package/src/lib/alloy/parse.ts +6 -3
- package/src/lib/browser/card-dim.test.ts +39 -0
- package/src/lib/browser/card-dim.ts +38 -0
- package/src/lib/browser/lookup.ts +3 -2
- package/src/lib/browser/row-match.test.ts +34 -0
- package/src/lib/browser/row-match.ts +8 -0
- package/src/lib/calc/flow.ts +3 -1
- package/src/lib/calc/member.test.ts +178 -0
- package/src/lib/calc/member.ts +90 -0
- package/src/lib/calc/scheme.test.ts +213 -0
- package/src/lib/calc/scheme.ts +8 -3
- package/src/lib/calc/tree/index.ts +5 -1
- package/src/lib/calc/tree/recipe.test.ts +88 -0
- package/src/lib/calc/tree/recipe.ts +19 -3
- package/src/lib/calc/wire.test.ts +70 -0
- package/src/lib/calc/wire.ts +6 -2
- package/src/lib/cards/model.test.ts +61 -1
- package/src/lib/cards/model.ts +9 -2
- package/src/types/calc-flow-props.ts +2 -0
- package/styles/calc.css +4 -0
|
@@ -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
|
|
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={
|
|
52
|
+
data-checked={
|
|
53
|
+
selected != null && stackIdBase(id) === stackIdBase(selected)
|
|
54
|
+
}
|
|
50
55
|
onSelect={() => onSelect(tagId, id)}
|
|
51
56
|
>
|
|
52
57
|
<Entry
|
|
@@ -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
|
|
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
|
-
<
|
|
209
|
+
<Marquee className="w-full px-0.5 text-center text-[9px] leading-tight text-muted-foreground">
|
|
198
210
|
{name}
|
|
199
|
-
</
|
|
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 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 {
|
|
@@ -13,10 +14,8 @@ import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
|
13
14
|
import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
14
15
|
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
15
16
|
import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
recipeCardDim,
|
|
19
|
-
} from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
|
|
17
|
+
import { RecipeCardGrid } from '@terrafirmagreg-team/recipe/components/views/browser/card-grid';
|
|
18
|
+
import { recipeCardFitDim } from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
|
|
20
19
|
import { RecipeTypeTabs } from '@terrafirmagreg-team/recipe/components/views/browser/type-tabs';
|
|
21
20
|
import { PlaceHeader } from '@terrafirmagreg-team/recipe/components/views/browser/place-header';
|
|
22
21
|
import { WorkstationRail } from '@terrafirmagreg-team/recipe/components/views/browser/workstation-rail';
|
|
@@ -86,17 +85,16 @@ export function PickerBody({
|
|
|
86
85
|
const focusIndex = rows.findIndex(
|
|
87
86
|
(row) => row.id === node.recipe?.recipeId,
|
|
88
87
|
);
|
|
88
|
+
const { grid } = useCardGrid();
|
|
89
89
|
const list = useFitPages(
|
|
90
90
|
boxRef,
|
|
91
91
|
rows,
|
|
92
|
-
(row, box) =>
|
|
93
|
-
|
|
94
|
-
return d.h > box.h ? { w: d.w, h: box.h } : d;
|
|
95
|
-
},
|
|
92
|
+
(row, box) =>
|
|
93
|
+
recipeCardFitDim(index ?? null, categoriesById, row, box),
|
|
96
94
|
page,
|
|
97
95
|
8,
|
|
98
96
|
pinned && focusIndex >= 0 ? focusIndex : undefined,
|
|
99
|
-
|
|
97
|
+
!grid,
|
|
100
98
|
);
|
|
101
99
|
const goPage = (next: number) => {
|
|
102
100
|
setPinned(false);
|
|
@@ -213,6 +211,8 @@ export function PickerBody({
|
|
|
213
211
|
boxRef={boxRef}
|
|
214
212
|
maxH={list.box.h}
|
|
215
213
|
maxW={list.box.w}
|
|
214
|
+
vertical={!grid}
|
|
215
|
+
loading={!list.measured}
|
|
216
216
|
empty={t('No recipes of this type.', { note: 'recipe.empty_type' })}
|
|
217
217
|
onSwipe={(dir) =>
|
|
218
218
|
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<
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
?
|
|
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
|
-
?
|
|
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
|
-
?
|
|
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,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
startTransition,
|
|
6
|
+
useCallback,
|
|
7
|
+
useContext,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import {
|
|
10
|
+
boolCodec,
|
|
11
|
+
createStoredValue,
|
|
12
|
+
} from '@terrafirmagreg-team/ui/lib/utils/stored-value';
|
|
13
|
+
|
|
14
|
+
const useStoredRecipeIds = createStoredValue(
|
|
15
|
+
'calc:recipeIds',
|
|
16
|
+
boolCodec(false),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const CalcRecipeIdsContext = createContext(false);
|
|
20
|
+
|
|
21
|
+
export const CalcRecipeIdsProvider = CalcRecipeIdsContext.Provider;
|
|
22
|
+
|
|
23
|
+
export function useCalcRecipeIds(): boolean {
|
|
24
|
+
return useContext(CalcRecipeIdsContext);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useCalcRecipeIdsMode() {
|
|
28
|
+
const [show, setStored] = useStoredRecipeIds();
|
|
29
|
+
const setShow = useCallback((next: boolean) => {
|
|
30
|
+
startTransition(() => setStored(next));
|
|
31
|
+
}, [setStored]);
|
|
32
|
+
return [show, setShow] as const;
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
boolCodec,
|
|
3
|
+
createStoredValue,
|
|
4
|
+
} from '@terrafirmagreg-team/ui/lib/utils/stored-value';
|
|
5
|
+
|
|
6
|
+
const useStoredCardGrid = createStoredValue(
|
|
7
|
+
'wiki.recipe.cardGrid',
|
|
8
|
+
boolCodec(false),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export function useCardGrid() {
|
|
12
|
+
const [grid, setGrid] = useStoredCardGrid();
|
|
13
|
+
return { grid, setGrid };
|
|
14
|
+
}
|
package/src/lib/alloy/parse.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
1
|
+
import type { Recipe, RecipeTextWidget } from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
2
2
|
import type { AlloyComponent, AlloyRecipe } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
3
3
|
import { cleanForgeText } from '@terrafirmagreg-team/recipe/lib/forge/actions';
|
|
4
|
+
import { widgetText } from '@terrafirmagreg-team/recipe/lib/cards/model';
|
|
4
5
|
|
|
5
6
|
export function parseAlloyPercent(
|
|
6
7
|
text: string,
|
|
@@ -20,11 +21,13 @@ export function toAlloyRecipe(recipe: Recipe): AlloyRecipe {
|
|
|
20
21
|
.sort(([a], [b]) => a.localeCompare(b, undefined, { numeric: true }))
|
|
21
22
|
.map(([, slot]) => slot);
|
|
22
23
|
const ranges = recipe.widgets
|
|
23
|
-
.filter(
|
|
24
|
+
.filter(
|
|
25
|
+
(widget): widget is RecipeTextWidget => widget.type === 'text',
|
|
26
|
+
)
|
|
24
27
|
.map((widget) => ({
|
|
25
28
|
x: widget.x,
|
|
26
29
|
y: widget.y,
|
|
27
|
-
range: parseAlloyPercent(widget
|
|
30
|
+
range: parseAlloyPercent(widgetText(widget)),
|
|
28
31
|
}))
|
|
29
32
|
.filter((widget) => widget.range !== undefined)
|
|
30
33
|
.sort((a, b) => a.y - b.y || a.x - b.x);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import {
|
|
4
|
+
recipeCardDim,
|
|
5
|
+
recipeCardFitDim,
|
|
6
|
+
} from '@terrafirmagreg-team/recipe/lib/browser/card-dim';
|
|
7
|
+
|
|
8
|
+
const ROW = { d: { w: 320, h: 170 }, type: 0, id: 'a:b', out: [], in: [] };
|
|
9
|
+
|
|
10
|
+
test('recipeCardDim returns declared dims', () => {
|
|
11
|
+
assert.deepEqual(recipeCardDim(null, new Map(), ROW as never), {
|
|
12
|
+
w: 320,
|
|
13
|
+
h: 170,
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('recipeCardFitDim keeps dims when the card fits the box', () => {
|
|
18
|
+
const d = recipeCardFitDim(null, new Map(), ROW as never, {
|
|
19
|
+
w: 800,
|
|
20
|
+
h: 600,
|
|
21
|
+
});
|
|
22
|
+
assert.deepEqual(d, { w: 320, h: 170 });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('recipeCardFitDim scales uniformly when wider than the box', () => {
|
|
26
|
+
const d = recipeCardFitDim(null, new Map(), ROW as never, {
|
|
27
|
+
w: 160,
|
|
28
|
+
h: 600,
|
|
29
|
+
});
|
|
30
|
+
assert.deepEqual(d, { w: 160, h: 85 });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('recipeCardFitDim caps height to the box', () => {
|
|
34
|
+
const d = recipeCardFitDim(null, new Map(), ROW as never, {
|
|
35
|
+
w: 800,
|
|
36
|
+
h: 100,
|
|
37
|
+
});
|
|
38
|
+
assert.deepEqual(d, { w: 320, h: 100 });
|
|
39
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FitDim } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
|
|
2
|
+
import type {
|
|
3
|
+
RecipeCategory,
|
|
4
|
+
RecipeCompactIndex,
|
|
5
|
+
RecipeCompactRow,
|
|
6
|
+
} from '@terrafirmagreg-team/recipe/types';
|
|
7
|
+
|
|
8
|
+
export const FALLBACK_DIM: FitDim = { w: 320, h: 80 };
|
|
9
|
+
|
|
10
|
+
export function recipeCardDim(
|
|
11
|
+
index: RecipeCompactIndex | null,
|
|
12
|
+
categoriesById: Map<string, RecipeCategory>,
|
|
13
|
+
row: RecipeCompactRow,
|
|
14
|
+
): FitDim {
|
|
15
|
+
if (row.d) return { w: row.d.w, h: row.d.h };
|
|
16
|
+
const typeId = index?.types[row.type];
|
|
17
|
+
const layout = typeId ? categoriesById.get(typeId)?.layout : undefined;
|
|
18
|
+
if (!layout) return FALLBACK_DIM;
|
|
19
|
+
const scale = layout.scale ?? 2;
|
|
20
|
+
const margin = layout.margin ?? 0;
|
|
21
|
+
return {
|
|
22
|
+
w: (layout.w + margin * 2) * scale,
|
|
23
|
+
h: (layout.h + margin * 2) * scale,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function recipeCardFitDim(
|
|
28
|
+
index: RecipeCompactIndex | null,
|
|
29
|
+
categoriesById: Map<string, RecipeCategory>,
|
|
30
|
+
row: RecipeCompactRow,
|
|
31
|
+
box: FitDim,
|
|
32
|
+
): FitDim {
|
|
33
|
+
const d = recipeCardDim(index, categoriesById, row);
|
|
34
|
+
const fit = box.w > 0 && d.w > box.w ? box.w / d.w : 1;
|
|
35
|
+
const w = d.w * fit;
|
|
36
|
+
const h = d.h * fit;
|
|
37
|
+
return h > box.h ? { w, h: box.h } : { w, h };
|
|
38
|
+
}
|