@terrafirmagreg-team/recipe 0.1.0 → 1.2.0
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 +16 -16
- package/src/components/button-copy.tsx +1 -0
- package/src/components/cards/card/index.tsx +5 -3
- package/src/components/cards/card/scene.tsx +4 -2
- package/src/components/cards/card/strip.tsx +4 -2
- package/src/components/cards/card/text.tsx +2 -1
- package/src/components/cards/card/tips.tsx +1 -0
- package/src/components/cards/default-item.tsx +6 -2
- package/src/components/cards/glare-filter.tsx +1 -0
- package/src/components/cards/paged-card.tsx +1 -0
- package/src/components/cards/slot-hitbox.tsx +4 -2
- package/src/components/cards/strip-card/buttons.tsx +7 -2
- package/src/components/cards/strip-card/index.tsx +3 -1
- package/src/components/cards/strip-card/member-cell.tsx +4 -2
- package/src/components/cards/strip-card/sprite.tsx +1 -0
- package/src/components/embed-card.tsx +44 -0
- package/src/components/mdx/recipe.tsx +34 -16
- package/src/components/tool-list.tsx +1 -0
- package/src/{lib/tree.ts → components/tree.tsx} +20 -12
- package/src/components/views/alloy/index.tsx +14 -7
- package/src/components/views/alloy/list.tsx +3 -2
- package/src/components/views/alloy/mix/index.tsx +1 -0
- package/src/components/views/alloy/mix/ratio.tsx +7 -6
- package/src/components/views/alloy/mix/rows.tsx +6 -7
- package/src/components/views/alloy/mix/status.tsx +8 -7
- package/src/components/views/alloy/mix/total.tsx +13 -12
- package/src/components/views/alloy/range-bar.tsx +2 -1
- package/src/components/views/alloy/stack-bar.tsx +4 -2
- package/src/components/views/browser/axis-switcher.tsx +13 -12
- package/src/components/views/browser/card-grid.tsx +2 -1
- package/src/components/views/browser/favorite-button.tsx +2 -1
- package/src/components/views/browser/frame.tsx +3 -2
- package/src/components/views/browser/index.tsx +20 -2
- package/src/components/views/browser/item-panel/index.tsx +11 -9
- package/src/components/views/browser/item-panel/skeleton.tsx +1 -0
- package/src/components/views/browser/item-panel-grid/cell.tsx +5 -3
- package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +4 -2
- package/src/components/views/browser/item-panel-grid/index.tsx +4 -2
- package/src/components/views/browser/item-view/index.tsx +7 -12
- package/src/components/views/browser/item-view/tags.tsx +7 -5
- package/src/components/views/browser/item-view-header.tsx +10 -9
- package/src/components/views/browser/pane-tabs.tsx +1 -0
- package/src/components/views/browser/place-header.tsx +4 -3
- package/src/components/views/browser/query-controls.tsx +3 -1
- package/src/components/views/browser/recipe-item-header.tsx +5 -4
- package/src/components/views/browser/settings.tsx +4 -3
- package/src/components/views/browser/toolbar.tsx +3 -2
- package/src/components/views/browser/type-tabs.tsx +5 -3
- package/src/components/views/browser/type-view.tsx +7 -12
- package/src/components/views/browser/workstation-rail.tsx +4 -3
- package/src/components/views/calc/calculator/actions.tsx +4 -14
- package/src/components/views/calc/calculator/help.tsx +69 -28
- package/src/components/views/calc/calculator/index.tsx +34 -82
- package/src/components/views/calc/dot-overlay.tsx +1 -0
- package/src/components/views/calc/edge.tsx +134 -32
- package/src/components/views/calc/flow/index.tsx +92 -54
- package/src/components/views/calc/flow/picker-dialogs.tsx +84 -6
- package/src/components/views/calc/flow/toolbar.tsx +9 -21
- package/src/components/views/calc/flow/view-menu.tsx +16 -120
- package/src/components/views/calc/member-picker.tsx +8 -6
- package/src/components/views/calc/node-card/actions.tsx +28 -106
- package/src/components/views/calc/node-card/badges.tsx +10 -28
- package/src/components/views/calc/node-card/chips.tsx +8 -40
- package/src/components/views/calc/node-card/far.tsx +13 -65
- package/src/components/views/calc/node-card/full.tsx +133 -83
- package/src/components/views/calc/node-card/index.tsx +1 -0
- package/src/components/views/calc/node-card/menu.tsx +93 -22
- package/src/components/views/calc/node-card/port-cells.tsx +186 -0
- package/src/components/views/calc/node-card/port-rails.tsx +251 -0
- package/src/components/views/calc/node-card/ports.tsx +86 -0
- package/src/components/views/calc/recipe-picker/body.tsx +17 -14
- package/src/components/views/calc/recipe-picker/footer.tsx +5 -3
- package/src/components/views/calc/recipe-picker/index.tsx +5 -0
- package/src/components/views/calc/sidebar.tsx +19 -10
- package/src/components/views/calc/trees/icon-picker.tsx +3 -2
- package/src/components/views/calc/trees/index.tsx +5 -4
- package/src/components/views/calc/trees/label.tsx +6 -4
- package/src/components/views/calc/trees/rows.tsx +6 -5
- package/src/components/views/forge/gui.tsx +2 -1
- package/src/components/views/forge/index.tsx +14 -7
- package/src/components/views/forge/list.tsx +3 -2
- package/src/components/views/forge/workbench/controls.tsx +13 -6
- package/src/components/views/forge/workbench/index.tsx +3 -2
- package/src/components/views/forge/workbench/panel.tsx +1 -0
- package/src/components/views/forge/workbench/ruler.tsx +5 -4
- package/src/components/views/forge/workbench/status.tsx +6 -5
- package/src/components/views/forge/workbench/tape.tsx +5 -4
- package/src/hooks/alloy/use-fluid-colors.ts +12 -9
- package/src/hooks/alloy/use-mix-state.ts +3 -2
- package/src/hooks/calc/flow/use-engage.ts +129 -0
- package/src/hooks/calc/flow/use-handlers.ts +192 -0
- package/src/hooks/calc/flow/use-layout.ts +105 -0
- package/src/hooks/calc/flow/{mount.ts → use-mount.ts} +1 -0
- package/src/hooks/calc/flow/{nodes.ts → use-nodes.ts} +46 -37
- package/src/hooks/calc/flow/use-pickers.ts +57 -0
- package/src/hooks/calc/flow/{viewport.ts → use-viewport.ts} +13 -26
- package/src/hooks/calc/flow/{window.ts → use-window.ts} +1 -0
- package/src/hooks/calc/use-actions.ts +208 -229
- package/src/hooks/calc/use-amounts.ts +23 -60
- package/src/hooks/calc/use-data.ts +106 -192
- package/src/hooks/calc/use-defaults.ts +4 -2
- package/src/hooks/calc/use-far-mode.ts +1 -0
- package/src/hooks/calc/use-focus.ts +8 -7
- package/src/hooks/calc/use-maps.ts +1 -0
- package/src/hooks/calc/use-reset.ts +1 -0
- package/src/hooks/calc/use-resolver.ts +32 -196
- package/src/hooks/calc/use-session.ts +1 -0
- package/src/hooks/calc/use-share.ts +5 -2
- package/src/hooks/calc/use-storage.ts +5 -4
- package/src/hooks/calc/use-tier.ts +1 -0
- package/src/hooks/calc/use-view-mode.ts +1 -0
- package/src/hooks/calc/use-worker.ts +56 -121
- package/src/hooks/forge/use-anvil-gui.ts +4 -2
- package/src/hooks/forge/use-forge-state.ts +1 -0
- package/src/hooks/forge/use-ruler.ts +1 -0
- package/src/hooks/use-add-to-calc.ts +23 -19
- package/src/hooks/use-categories-by-id.ts +18 -0
- package/src/hooks/use-favorite-hotkey.ts +1 -0
- package/src/hooks/use-favorites.ts +1 -0
- package/src/hooks/use-group-outlines.ts +1 -0
- package/src/hooks/use-hide-unused.ts +2 -1
- package/src/hooks/use-index.ts +6 -2
- package/src/hooks/use-item-feeds.ts +3 -1
- package/src/hooks/use-item-pane.ts +6 -4
- package/src/hooks/use-item-press.ts +27 -23
- package/src/hooks/use-item-tag-groups.ts +4 -2
- package/src/hooks/use-item-tooltips.ts +3 -1
- package/src/hooks/use-left-sidebar-tree.ts +11 -3
- package/src/hooks/use-mod-names.ts +4 -2
- package/src/hooks/use-mount-limit.ts +1 -0
- package/src/hooks/use-panel-cells.ts +3 -1
- package/src/hooks/use-panel-page.ts +9 -6
- package/src/hooks/use-panel-tabs.ts +2 -1
- package/src/hooks/use-query.ts +8 -6
- package/src/hooks/use-session.ts +6 -2
- package/src/hooks/use-sidebar-group.ts +3 -7
- package/src/hooks/use-tag-members.ts +3 -1
- package/src/hooks/use-tool-recipes.ts +1 -0
- package/src/hooks/use-type-filter.ts +1 -0
- package/src/lib/alloy/mix.ts +1 -0
- package/src/lib/alloy/parse.ts +1 -0
- package/src/lib/calc/defaults.ts +6 -4
- package/src/lib/calc/flow.ts +143 -107
- package/src/lib/calc/focus.ts +1 -0
- package/src/lib/calc/meta.ts +3 -1
- package/src/lib/calc/pack.ts +47 -154
- package/src/lib/calc/ports.ts +43 -0
- package/src/lib/calc/resolve.ts +6 -38
- package/src/lib/calc/route/buckets.ts +1 -0
- package/src/lib/calc/route/geometry.ts +13 -24
- package/src/lib/calc/route/index.ts +1 -0
- package/src/lib/calc/route/polyline.ts +3 -3
- package/src/lib/calc/route/router.ts +181 -57
- package/src/lib/calc/scheme.ts +226 -0
- package/src/lib/calc/storage/entry.ts +27 -19
- package/src/lib/calc/storage/index.ts +2 -0
- package/src/lib/calc/storage/keys.ts +4 -8
- package/src/lib/calc/storage/store.ts +11 -36
- package/src/lib/calc/tree/index.ts +2 -16
- package/src/lib/calc/tree/materials.ts +1 -0
- package/src/lib/calc/tree/recipe.ts +1 -0
- package/src/lib/calc/tree/share.ts +86 -149
- package/src/lib/calc/worker/api.ts +3 -11
- package/src/lib/calc/worker/fetch.ts +1 -0
- package/src/lib/calc/worker/flush.ts +7 -20
- package/src/lib/calc/worker/index.ts +1 -1
- package/src/lib/calc/worker/protocol.ts +16 -13
- package/src/lib/calc/worker/resolve.ts +32 -84
- package/src/lib/calc/worker/state.ts +5 -6
- package/src/{components/cards/card/model.ts → lib/card-model.ts} +1 -0
- package/src/lib/client/recipe-categories.ts +11 -93
- package/src/lib/client/recipe.ts +13 -11
- package/src/lib/client-index/catalog.ts +33 -27
- package/src/lib/client-index/chrome.ts +30 -30
- package/src/lib/client-index/index.ts +1 -0
- package/src/lib/client-index/registry.ts +70 -59
- package/src/lib/client-index/rows.ts +63 -57
- package/src/lib/client-index/tooltips.ts +28 -34
- package/src/lib/config.ts +2 -1
- package/src/lib/data/category/dto.ts +4 -3
- package/src/lib/data/category/load.ts +9 -8
- package/src/lib/data/category/parse.ts +4 -3
- package/src/lib/data/dto.ts +4 -3
- package/src/lib/data/grid.ts +2 -1
- package/src/lib/data/parse/entry.ts +3 -2
- package/src/lib/data/parse/index.ts +1 -0
- package/src/lib/data/parse/layout.ts +5 -2
- package/src/lib/data/parse/slots.ts +3 -2
- package/src/lib/data/parse/widgets.ts +3 -2
- package/src/lib/data/scene.ts +1 -1
- package/src/lib/data/slot-io.ts +1 -0
- package/src/lib/dump.ts +4 -3
- package/src/lib/embed.ts +22 -0
- package/src/lib/favorite-hover.ts +1 -0
- package/src/lib/fluid-outputs.ts +10 -12
- package/src/lib/forge/actions.ts +2 -1
- package/src/lib/forge/data.ts +2 -1
- package/src/lib/forge/solve.ts +1 -0
- package/src/lib/group.ts +1 -0
- package/src/lib/index-store.ts +15 -9
- package/src/lib/links.ts +15 -9
- package/src/lib/lookup.ts +10 -8
- package/src/lib/panel-outline.ts +1 -0
- package/src/lib/panel.ts +3 -2
- package/src/lib/preview.ts +12 -8
- package/src/lib/recipe-slots.ts +1 -0
- package/src/lib/search.ts +1 -0
- package/src/lib/sidebar.ts +1 -0
- package/src/lib/used-items.ts +1 -0
- package/src/locales/en_us.json +170 -226
- package/src/locales/ru_ru.json +170 -226
- package/src/locales.ts +1 -0
- package/src/types/alloy.ts +1 -0
- package/src/{hooks/calc/flow/props.ts → types/calc-flow-props.ts} +18 -14
- package/src/types/calc.ts +41 -44
- package/src/types/forge.ts +1 -0
- package/src/types/index.ts +4 -2
- package/styles/calc.css +308 -47
- package/src/components/cards/fit-card.tsx +0 -26
- package/src/components/views/calc/target.tsx +0 -271
- package/src/hooks/calc/flow/engage.ts +0 -89
- package/src/hooks/calc/flow/handlers.ts +0 -115
- package/src/hooks/calc/flow/layout.ts +0 -149
- package/src/hooks/calc/flow/pickers.ts +0 -50
- package/src/hooks/calc/use-calc-fill.ts +0 -91
- package/src/hooks/calc/use-density.ts +0 -28
- package/src/hooks/calc/use-derived.ts +0 -258
- package/src/hooks/calc/use-direction.ts +0 -23
- package/src/hooks/calc/use-edge-style.ts +0 -40
- package/src/hooks/calc/use-fill.ts +0 -213
- package/src/lib/alloy/alloy.test.ts +0 -186
- package/src/lib/calc/tree/build.ts +0 -196
- package/src/lib/calc/tree/context.ts +0 -42
- package/src/lib/calc/tree/goal.ts +0 -64
- package/src/lib/calc/tree/ideal.ts +0 -36
- package/src/lib/calc/tree/pick.ts +0 -68
- package/src/lib/calc/tree/tree.test.ts +0 -169
- package/src/lib/calc/worker/fill.ts +0 -123
- package/src/lib/client-index/cache.ts +0 -13
- package/src/lib/forge/forge.test.ts +0 -123
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
useCallback,
|
|
@@ -10,24 +11,16 @@ import {
|
|
|
10
11
|
import { useReactFlow } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
|
|
11
12
|
import type {
|
|
12
13
|
AnyCalcFlowNode,
|
|
13
|
-
CalcDensity,
|
|
14
14
|
CalcFlowNode,
|
|
15
15
|
CalcViewMode,
|
|
16
16
|
} from '@terrafirmagreg-team/recipe/lib/calc/flow';
|
|
17
|
-
import type { CalcDirection } from '@terrafirmagreg-team/recipe/lib/calc/flow';
|
|
18
|
-
import type { CalcGoal } from '@terrafirmagreg-team/recipe/lib/calc/tree';
|
|
19
17
|
|
|
20
18
|
export function useFlowViewport({
|
|
21
|
-
goals,
|
|
22
19
|
mergedNodes,
|
|
23
20
|
dataset,
|
|
24
|
-
direction,
|
|
25
21
|
resetGen,
|
|
26
22
|
treeReady,
|
|
27
|
-
layoutKey,
|
|
28
|
-
layout,
|
|
29
23
|
mode,
|
|
30
|
-
density,
|
|
31
24
|
applyFocus,
|
|
32
25
|
focusSeqRef,
|
|
33
26
|
focusRef,
|
|
@@ -35,16 +28,11 @@ export function useFlowViewport({
|
|
|
35
28
|
onFocusedNode,
|
|
36
29
|
focusId,
|
|
37
30
|
}: {
|
|
38
|
-
goals: CalcGoal[];
|
|
39
31
|
mergedNodes: AnyCalcFlowNode[];
|
|
40
|
-
dataset:
|
|
41
|
-
direction: CalcDirection;
|
|
32
|
+
dataset: DatasetRef;
|
|
42
33
|
resetGen: number;
|
|
43
34
|
treeReady: boolean;
|
|
44
|
-
layoutKey: string;
|
|
45
|
-
layout: { key: string } | null;
|
|
46
35
|
mode: CalcViewMode;
|
|
47
|
-
density: CalcDensity;
|
|
48
36
|
applyFocus: (id: string | null) => void;
|
|
49
37
|
focusSeqRef: RefObject<{ id: string; index: number } | null>;
|
|
50
38
|
focusRef?: RefObject<((materialId: string) => void) | null>;
|
|
@@ -54,10 +42,9 @@ export function useFlowViewport({
|
|
|
54
42
|
}) {
|
|
55
43
|
const { setCenter, getZoom } = useReactFlow();
|
|
56
44
|
const userMovedRef = useRef(false);
|
|
57
|
-
const storageKey = `calc:${dataset}`;
|
|
45
|
+
const storageKey = `calc:${dataset.id}/${dataset.version ?? ''}`;
|
|
58
46
|
|
|
59
|
-
const
|
|
60
|
-
const ready = treeReady && layoutReady;
|
|
47
|
+
const ready = treeReady;
|
|
61
48
|
|
|
62
49
|
const centerOnNode = useCallback(
|
|
63
50
|
(node: AnyCalcFlowNode) => {
|
|
@@ -106,16 +93,15 @@ export function useFlowViewport({
|
|
|
106
93
|
}, [mergedNodes, focusNodeId, applyFocus, centerOnNode, onFocusedNode]);
|
|
107
94
|
|
|
108
95
|
const recenterRef = useRef(false);
|
|
109
|
-
const viewSigRef = useRef(
|
|
96
|
+
const viewSigRef = useRef(mode);
|
|
110
97
|
useEffect(() => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
viewSigRef.current = sig;
|
|
98
|
+
if (viewSigRef.current === mode) return;
|
|
99
|
+
viewSigRef.current = mode;
|
|
114
100
|
recenterRef.current = true;
|
|
115
|
-
}, [mode
|
|
101
|
+
}, [mode]);
|
|
116
102
|
useEffect(() => {
|
|
117
103
|
if (!ready || !recenterRef.current) return;
|
|
118
|
-
const root = mergedNodes
|
|
104
|
+
const root = mergedNodes[0];
|
|
119
105
|
if (root) centerOnNode(root as AnyCalcFlowNode);
|
|
120
106
|
recenterRef.current = false;
|
|
121
107
|
}, [ready, mergedNodes, centerOnNode]);
|
|
@@ -127,16 +113,16 @@ export function useFlowViewport({
|
|
|
127
113
|
const viewportConfig = useMemo(
|
|
128
114
|
() => ({
|
|
129
115
|
storageKey,
|
|
130
|
-
resetKey: `${storageKey}:${
|
|
116
|
+
resetKey: `${storageKey}:${resetGen}`,
|
|
131
117
|
selectedId: focusId,
|
|
132
118
|
userMovedRef,
|
|
133
|
-
initFocusId:
|
|
119
|
+
initFocusId: null,
|
|
134
120
|
focusZoom: 1,
|
|
135
121
|
minZoom: 0.02,
|
|
136
122
|
restoreViewport: false,
|
|
137
123
|
ready,
|
|
138
124
|
}),
|
|
139
|
-
[storageKey,
|
|
125
|
+
[storageKey, resetGen, focusId, ready],
|
|
140
126
|
);
|
|
141
127
|
const shellProps = useMemo(
|
|
142
128
|
() => ({ 'data-ready': ready ? ('true' as const) : ('false' as const) }),
|
|
@@ -152,3 +138,4 @@ export function useFlowViewport({
|
|
|
152
138
|
shellProps,
|
|
153
139
|
};
|
|
154
140
|
}
|
|
141
|
+
|
|
@@ -7,33 +7,29 @@ import {
|
|
|
7
7
|
type SetStateAction,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import { useCopyButton } from '@terrafirmagreg-team/ui/hooks/use-copy-button';
|
|
10
|
-
import type {
|
|
10
|
+
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
11
11
|
import { recipeCalcHref, recipeStackHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
12
12
|
import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
13
13
|
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
14
14
|
import type {
|
|
15
|
+
CalcCard,
|
|
15
16
|
CalcKind,
|
|
16
|
-
CalcMaterial,
|
|
17
17
|
CalcNode,
|
|
18
18
|
CalculatorState,
|
|
19
|
-
|
|
19
|
+
CalcWire,
|
|
20
20
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
21
21
|
import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
23
|
+
let cardSeq = 0;
|
|
24
|
+
const newCardId = () =>
|
|
25
|
+
`c${Date.now().toString(36)}${(cardSeq += 1).toString(36)}`;
|
|
27
26
|
|
|
28
27
|
export function useCalcActions({
|
|
29
28
|
dataset,
|
|
30
29
|
lang,
|
|
31
|
-
|
|
30
|
+
cards,
|
|
31
|
+
wires,
|
|
32
32
|
tagSelections,
|
|
33
|
-
collapsed,
|
|
34
|
-
auto,
|
|
35
|
-
goal,
|
|
36
|
-
ideal,
|
|
37
33
|
persist,
|
|
38
34
|
recipeDefaults,
|
|
39
35
|
setRecipeDefault,
|
|
@@ -41,33 +37,28 @@ export function useCalcActions({
|
|
|
41
37
|
encodeShare,
|
|
42
38
|
flushAmounts,
|
|
43
39
|
setFocusNodeId,
|
|
44
|
-
|
|
40
|
+
nodes,
|
|
45
41
|
}: {
|
|
46
|
-
dataset:
|
|
42
|
+
dataset: DatasetRef;
|
|
47
43
|
lang: Lang;
|
|
48
|
-
|
|
44
|
+
cards: CalcCard[];
|
|
45
|
+
wires: CalcWire[];
|
|
49
46
|
tagSelections: Record<string, string>;
|
|
50
|
-
collapsed: string[];
|
|
51
|
-
auto: string[];
|
|
52
|
-
goal: CalcGoal | null;
|
|
53
|
-
ideal: number;
|
|
54
47
|
persist: (next: CalculatorState) => void;
|
|
55
48
|
recipeDefaults: Record<string, string>;
|
|
56
49
|
setRecipeDefault: (materialId: string, recipeId: string | null) => void;
|
|
57
50
|
recipeBody: (recipeId: string) => Recipe | undefined;
|
|
58
51
|
encodeShare: () => string;
|
|
59
|
-
flushAmounts: () =>
|
|
60
|
-
target: CalculatorTarget | null;
|
|
61
|
-
inventory: CalcMaterial[];
|
|
62
|
-
};
|
|
52
|
+
flushAmounts: () => CalcCard[];
|
|
63
53
|
setFocusNodeId: Dispatch<SetStateAction<string | null>>;
|
|
64
|
-
|
|
54
|
+
nodes: CalcNode[];
|
|
65
55
|
}) {
|
|
66
56
|
const { checked: shared, onClick: onShare } = useCopyButton(async () => {
|
|
67
57
|
const tree = encodeShare();
|
|
58
|
+
const { id: datasetId, version } = dataset;
|
|
68
59
|
try {
|
|
69
60
|
const res = (await fetch(
|
|
70
|
-
`/api/share/recipe/${encodeURIComponent(
|
|
61
|
+
`/api/share/recipe/${encodeURIComponent(datasetId)}${version ? `?version=${encodeURIComponent(version)}` : ''}`,
|
|
71
62
|
{
|
|
72
63
|
method: 'POST',
|
|
73
64
|
headers: { 'content-type': 'application/json' },
|
|
@@ -75,215 +66,110 @@ export function useCalcActions({
|
|
|
75
66
|
},
|
|
76
67
|
).then((r) => (r.ok ? r.json() : null))) as {
|
|
77
68
|
id?: string;
|
|
69
|
+
dataset?: DatasetRef;
|
|
78
70
|
} | null;
|
|
79
71
|
if (res?.id) {
|
|
80
72
|
await navigator.clipboard.writeText(
|
|
81
|
-
`${window.location.origin}${recipeCalcHref(dataset, undefined, `s${res.id}`)}`,
|
|
73
|
+
`${window.location.origin}${recipeCalcHref(res.dataset ?? dataset, undefined, `s${res.id}`)}`,
|
|
82
74
|
);
|
|
83
75
|
return;
|
|
84
76
|
}
|
|
85
77
|
} catch {
|
|
86
|
-
|
|
87
78
|
}
|
|
88
79
|
await navigator.clipboard.writeText(
|
|
89
80
|
`${window.location.origin}${recipeCalcHref(dataset, undefined, tree)}`,
|
|
90
81
|
);
|
|
91
82
|
});
|
|
92
83
|
|
|
93
|
-
const
|
|
94
|
-
(
|
|
95
|
-
const next = { ...selections };
|
|
96
|
-
const changed = selections[key] !== recipeId;
|
|
97
|
-
if (recipeId) next[key] = recipeId;
|
|
98
|
-
else delete next[key];
|
|
99
|
-
const descendant = changed && /^g\d/.test(key);
|
|
100
|
-
if (descendant) {
|
|
101
|
-
for (const path of Object.keys(next)) {
|
|
102
|
-
if (path.startsWith(`${key}/`)) delete next[path];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
84
|
+
const write = useCallback(
|
|
85
|
+
(next: Partial<Pick<CalculatorState, 'cards' | 'wires' | 'tagSelections'>>) => {
|
|
105
86
|
persist({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
tagSelections,
|
|
109
|
-
collapsed: collapsed.filter(
|
|
110
|
-
(path) =>
|
|
111
|
-
path !== key && !(descendant && path.startsWith(`${key}/`)),
|
|
112
|
-
),
|
|
113
|
-
auto: descendant
|
|
114
|
-
? auto.filter((path) => !path.startsWith(`${key}/`))
|
|
115
|
-
: auto,
|
|
87
|
+
cards: next.cards ?? flushAmounts(),
|
|
88
|
+
wires: next.wires ?? wires,
|
|
89
|
+
tagSelections: next.tagSelections ?? tagSelections,
|
|
116
90
|
});
|
|
117
91
|
},
|
|
118
|
-
[
|
|
119
|
-
selections,
|
|
120
|
-
persist,
|
|
121
|
-
tagSelections,
|
|
122
|
-
collapsed,
|
|
123
|
-
auto,
|
|
124
|
-
flushAmounts,
|
|
125
|
-
],
|
|
92
|
+
[flushAmounts, persist, wires, tagSelections],
|
|
126
93
|
);
|
|
127
94
|
|
|
128
|
-
const
|
|
129
|
-
(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
tagSelections,
|
|
139
|
-
collapsed: collapsed.includes(path)
|
|
140
|
-
? collapsed
|
|
141
|
-
: [...collapsed, path],
|
|
142
|
-
auto,
|
|
143
|
-
});
|
|
95
|
+
const onSelectRecipe = useCallback(
|
|
96
|
+
(cardId: string, recipeId: string | null) => {
|
|
97
|
+
if (!cards.some((row) => row.id === cardId)) return;
|
|
98
|
+
const nextCards = cards.map((row) =>
|
|
99
|
+
row.id === cardId ? { ...row, recipeId } : row,
|
|
100
|
+
);
|
|
101
|
+
const nextWires = recipeId
|
|
102
|
+
? wires
|
|
103
|
+
: wires.filter((wire) => wire.to !== cardId);
|
|
104
|
+
write({ cards: nextCards, wires: nextWires });
|
|
144
105
|
},
|
|
145
|
-
[
|
|
106
|
+
[cards, wires, write],
|
|
146
107
|
);
|
|
147
108
|
|
|
148
109
|
const onSelectTagMember = useCallback(
|
|
149
110
|
(tagId: string, memberId: string) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const paths: string[] = [];
|
|
153
|
-
const walk = (n: CalcNode) => {
|
|
154
|
-
if (n.tagId === tagId && n.path) paths.push(n.path);
|
|
155
|
-
n.children.forEach(walk);
|
|
156
|
-
};
|
|
157
|
-
if (goal) walk(goal.node);
|
|
158
|
-
const hitsSelf = (key: string) =>
|
|
159
|
-
paths.some((p) => key === p || key.startsWith(`${p}/`));
|
|
160
|
-
const hitsDescendant = (key: string) =>
|
|
161
|
-
paths.some((p) => key.startsWith(`${p}/`));
|
|
162
|
-
persist({
|
|
163
|
-
...flushAmounts(),
|
|
164
|
-
selections: paths.length
|
|
165
|
-
? Object.fromEntries(
|
|
166
|
-
Object.entries(selections).filter(
|
|
167
|
-
([key]) => !hitsSelf(key),
|
|
168
|
-
),
|
|
169
|
-
)
|
|
170
|
-
: selections,
|
|
171
|
-
tagSelections: next,
|
|
172
|
-
collapsed: paths.length
|
|
173
|
-
? collapsed.filter((path) => !hitsDescendant(path))
|
|
174
|
-
: collapsed,
|
|
175
|
-
auto: paths.length
|
|
176
|
-
? auto.filter((path) => !hitsDescendant(path))
|
|
177
|
-
: auto,
|
|
178
|
-
});
|
|
111
|
+
write({ tagSelections: { ...tagSelections, [tagId]: memberId } });
|
|
179
112
|
},
|
|
180
|
-
[
|
|
181
|
-
tagSelections,
|
|
182
|
-
persist,
|
|
183
|
-
selections,
|
|
184
|
-
collapsed,
|
|
185
|
-
auto,
|
|
186
|
-
flushAmounts,
|
|
187
|
-
goal,
|
|
188
|
-
],
|
|
113
|
+
[tagSelections, write],
|
|
189
114
|
);
|
|
190
115
|
|
|
191
|
-
const
|
|
192
|
-
(materialId: string, kind: CalcKind) => {
|
|
193
|
-
const
|
|
194
|
-
setFocusNodeId('g0');
|
|
195
|
-
if (cur.target?.id === materialId && cur.target.kind === kind) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
116
|
+
const onAddCard = useCallback(
|
|
117
|
+
(materialId: string, kind: CalcKind, pos?: { x: number; y: number }) => {
|
|
118
|
+
const id = newCardId();
|
|
198
119
|
persist({
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
120
|
+
cards: [
|
|
121
|
+
...flushAmounts(),
|
|
122
|
+
{ id, materialId, kind, recipeId: null, crafts: 1, pos },
|
|
123
|
+
],
|
|
124
|
+
wires,
|
|
202
125
|
tagSelections,
|
|
203
|
-
collapsed: [],
|
|
204
|
-
auto: [],
|
|
205
126
|
});
|
|
127
|
+
setFocusNodeId(id);
|
|
128
|
+
return id;
|
|
206
129
|
},
|
|
207
|
-
[persist,
|
|
130
|
+
[flushAmounts, persist, wires, tagSelections, setFocusNodeId],
|
|
208
131
|
);
|
|
209
132
|
|
|
210
|
-
const
|
|
211
|
-
(
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
);
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
auto,
|
|
229
|
-
});
|
|
230
|
-
},
|
|
231
|
-
[
|
|
232
|
-
persist,
|
|
233
|
-
selections,
|
|
234
|
-
tagSelections,
|
|
235
|
-
collapsed,
|
|
236
|
-
auto,
|
|
237
|
-
flushAmounts,
|
|
238
|
-
],
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
const onRemoveStock = useCallback(
|
|
242
|
-
(index: number) => {
|
|
243
|
-
const cur = flushAmounts();
|
|
133
|
+
const onSupplyInput = useCallback(
|
|
134
|
+
(cardId: string, inputIndex: number, recipeId: string | null, outputAmount?: number) => {
|
|
135
|
+
const consumerNode = nodes.find((n) => n.id === cardId);
|
|
136
|
+
const consumerCard = cards.find((row) => row.id === cardId);
|
|
137
|
+
const input = consumerNode?.inputs[inputIndex];
|
|
138
|
+
if (!consumerNode || !consumerCard || !input?.id) return null;
|
|
139
|
+
const need = Math.max(1, input.amount - input.covered);
|
|
140
|
+
const crafts = recipeId && outputAmount
|
|
141
|
+
? Math.max(1, Math.ceil(need / outputAmount))
|
|
142
|
+
: need;
|
|
143
|
+
const base = consumerCard.pos;
|
|
144
|
+
const id = newCardId();
|
|
145
|
+
const nextWires = [
|
|
146
|
+
...wires.filter(
|
|
147
|
+
(wire) => !(wire.to === cardId && wire.input === inputIndex),
|
|
148
|
+
),
|
|
149
|
+
{ from: id, to: cardId, input: inputIndex },
|
|
150
|
+
];
|
|
244
151
|
persist({
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
152
|
+
cards: [
|
|
153
|
+
...flushAmounts(),
|
|
154
|
+
{
|
|
155
|
+
id,
|
|
156
|
+
materialId: input.id,
|
|
157
|
+
kind: input.kind,
|
|
158
|
+
recipeId,
|
|
159
|
+
crafts,
|
|
160
|
+
pos: base
|
|
161
|
+
? { x: base.x - 40, y: base.y + 140 + inputIndex * 24 }
|
|
162
|
+
: undefined,
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
wires: nextWires,
|
|
248
166
|
tagSelections,
|
|
249
|
-
collapsed,
|
|
250
|
-
auto,
|
|
251
167
|
});
|
|
168
|
+
return id;
|
|
252
169
|
},
|
|
253
|
-
[
|
|
254
|
-
persist,
|
|
255
|
-
selections,
|
|
256
|
-
tagSelections,
|
|
257
|
-
collapsed,
|
|
258
|
-
auto,
|
|
259
|
-
flushAmounts,
|
|
260
|
-
],
|
|
170
|
+
[nodes, cards, wires, flushAmounts, persist, tagSelections],
|
|
261
171
|
);
|
|
262
172
|
|
|
263
|
-
const onApplyIdeal = useCallback(() => {
|
|
264
|
-
const cur = flushAmounts();
|
|
265
|
-
if (!cur.target || !Number.isFinite(ideal) || ideal <= 1) return;
|
|
266
|
-
persist({
|
|
267
|
-
target: {
|
|
268
|
-
...cur.target,
|
|
269
|
-
amount: Math.ceil(cur.target.amount * ideal),
|
|
270
|
-
},
|
|
271
|
-
inventory: cur.inventory,
|
|
272
|
-
selections,
|
|
273
|
-
tagSelections,
|
|
274
|
-
collapsed,
|
|
275
|
-
auto,
|
|
276
|
-
});
|
|
277
|
-
}, [
|
|
278
|
-
persist,
|
|
279
|
-
selections,
|
|
280
|
-
tagSelections,
|
|
281
|
-
collapsed,
|
|
282
|
-
auto,
|
|
283
|
-
flushAmounts,
|
|
284
|
-
ideal,
|
|
285
|
-
]);
|
|
286
|
-
|
|
287
173
|
const onOpenItem = useCallback(
|
|
288
174
|
(materialId: string, kind: CalcKind) => {
|
|
289
175
|
window.open(
|
|
@@ -295,32 +181,115 @@ export function useCalcActions({
|
|
|
295
181
|
[dataset, lang],
|
|
296
182
|
);
|
|
297
183
|
|
|
298
|
-
const
|
|
299
|
-
(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
184
|
+
const onRemoveCard = useCallback(
|
|
185
|
+
(cardId: string) => {
|
|
186
|
+
write({
|
|
187
|
+
cards: flushAmounts().filter((row) => row.id !== cardId),
|
|
188
|
+
wires: wires.filter(
|
|
189
|
+
(wire) => wire.from !== cardId && wire.to !== cardId,
|
|
190
|
+
),
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
[flushAmounts, write, wires],
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const onMoveCard = useCallback(
|
|
197
|
+
(cardId: string, pos: { x: number; y: number }) => {
|
|
198
|
+
write({
|
|
199
|
+
cards: flushAmounts().map((row) =>
|
|
200
|
+
row.id === cardId ? { ...row, pos } : row,
|
|
201
|
+
),
|
|
308
202
|
});
|
|
309
203
|
},
|
|
310
|
-
[
|
|
204
|
+
[flushAmounts, write],
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const onMoveCards = useCallback(
|
|
208
|
+
(positions: Map<string, { x: number; y: number }>) => {
|
|
209
|
+
write({
|
|
210
|
+
cards: flushAmounts().map((row) => {
|
|
211
|
+
const pos = positions.get(row.id);
|
|
212
|
+
return pos ? { ...row, pos } : row;
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
[flushAmounts, write],
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const onWire = useCallback(
|
|
220
|
+
(from: string, to: string, input: number, out?: number) => {
|
|
221
|
+
if (from === to) return;
|
|
222
|
+
write({
|
|
223
|
+
wires: [
|
|
224
|
+
...wires.filter(
|
|
225
|
+
(wire) => !(wire.to === to && wire.input === input),
|
|
226
|
+
),
|
|
227
|
+
{ from, to, input, out: out || undefined },
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
[wires, write],
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const onUnwire = useCallback(
|
|
235
|
+
(from: string, to: string, input: number, out?: number) => {
|
|
236
|
+
write({
|
|
237
|
+
wires: wires.filter(
|
|
238
|
+
(wire) =>
|
|
239
|
+
!(
|
|
240
|
+
wire.from === from &&
|
|
241
|
+
wire.to === to &&
|
|
242
|
+
wire.input === input &&
|
|
243
|
+
(wire.out ?? 0) === (out ?? 0)
|
|
244
|
+
),
|
|
245
|
+
),
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
[wires, write],
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const onRewire = useCallback(
|
|
252
|
+
(
|
|
253
|
+
from: string,
|
|
254
|
+
to: string,
|
|
255
|
+
input: number,
|
|
256
|
+
next: { from: string; to: string; input: number; out?: number },
|
|
257
|
+
) => {
|
|
258
|
+
if (next.from === next.to) return;
|
|
259
|
+
write({
|
|
260
|
+
wires: [
|
|
261
|
+
...wires.filter(
|
|
262
|
+
(wire) =>
|
|
263
|
+
!(wire.from === from && wire.to === to && wire.input === input) &&
|
|
264
|
+
!(wire.to === next.to && wire.input === next.input),
|
|
265
|
+
),
|
|
266
|
+
next,
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
[wires, write],
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const onWireAmount = useCallback(
|
|
274
|
+
(from: string, to: string, input: number, amount: number | null) => {
|
|
275
|
+
write({
|
|
276
|
+
wires: wires.map((wire) =>
|
|
277
|
+
wire.from === from && wire.to === to && wire.input === input
|
|
278
|
+
? { ...wire, amount: amount ?? undefined }
|
|
279
|
+
: wire,
|
|
280
|
+
),
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
[wires, write],
|
|
311
284
|
);
|
|
312
285
|
|
|
313
286
|
const onClear = useCallback(() => {
|
|
314
|
-
const cur = flushAmounts();
|
|
315
287
|
persist({
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
selections: {},
|
|
288
|
+
cards: [],
|
|
289
|
+
wires: [],
|
|
319
290
|
tagSelections: {},
|
|
320
|
-
collapsed: [],
|
|
321
|
-
auto: [],
|
|
322
291
|
});
|
|
323
|
-
}, [
|
|
292
|
+
}, [persist]);
|
|
324
293
|
|
|
325
294
|
const flowData = useMemo<
|
|
326
295
|
Omit<
|
|
@@ -330,6 +299,10 @@ export function useCalcActions({
|
|
|
330
299
|
| 'direction'
|
|
331
300
|
| 'onRequestPicker'
|
|
332
301
|
| 'onRequestMemberPicker'
|
|
302
|
+
| 'onRequestSupply'
|
|
303
|
+
| 'onCrafts'
|
|
304
|
+
| 'getRecipesForItem'
|
|
305
|
+
| 'ensureMaterial'
|
|
333
306
|
>
|
|
334
307
|
>(
|
|
335
308
|
() => ({
|
|
@@ -337,28 +310,34 @@ export function useCalcActions({
|
|
|
337
310
|
recipeBody,
|
|
338
311
|
onSelectRecipe,
|
|
339
312
|
onSelectTagMember,
|
|
340
|
-
|
|
341
|
-
|
|
313
|
+
onSupplyInput,
|
|
314
|
+
onAddCard,
|
|
342
315
|
onOpenItem,
|
|
316
|
+
onRemoveCard,
|
|
317
|
+
onMoveCard,
|
|
318
|
+
onWire,
|
|
319
|
+
onUnwire,
|
|
320
|
+
onRewire,
|
|
321
|
+
onWireAmount,
|
|
343
322
|
recipeDefaults,
|
|
344
323
|
onSetRecipeDefault: setRecipeDefault,
|
|
345
|
-
onFillNode,
|
|
346
|
-
onCollapseNode,
|
|
347
|
-
onRemoveTarget,
|
|
348
324
|
}),
|
|
349
325
|
[
|
|
350
326
|
dataset,
|
|
351
327
|
recipeBody,
|
|
352
328
|
onSelectRecipe,
|
|
353
329
|
onSelectTagMember,
|
|
354
|
-
|
|
355
|
-
|
|
330
|
+
onSupplyInput,
|
|
331
|
+
onAddCard,
|
|
356
332
|
onOpenItem,
|
|
333
|
+
onRemoveCard,
|
|
334
|
+
onMoveCard,
|
|
335
|
+
onWire,
|
|
336
|
+
onUnwire,
|
|
337
|
+
onRewire,
|
|
338
|
+
onWireAmount,
|
|
357
339
|
recipeDefaults,
|
|
358
340
|
setRecipeDefault,
|
|
359
|
-
onFillNode,
|
|
360
|
-
onCollapseNode,
|
|
361
|
-
onRemoveTarget,
|
|
362
341
|
],
|
|
363
342
|
);
|
|
364
343
|
|
|
@@ -366,11 +345,11 @@ export function useCalcActions({
|
|
|
366
345
|
shared,
|
|
367
346
|
onShare,
|
|
368
347
|
flowData,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
onRemoveTarget,
|
|
348
|
+
onAddCard,
|
|
349
|
+
onRemoveCard,
|
|
350
|
+
onMoveCards,
|
|
351
|
+
onSupplyInput,
|
|
374
352
|
onClear,
|
|
375
353
|
};
|
|
376
354
|
}
|
|
355
|
+
|