@terrafirmagreg-team/recipe 1.2.11 → 1.2.13
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 +3 -3
- package/src/components/views/browser/axis-switcher.tsx +11 -3
- package/src/components/views/browser/index.tsx +6 -2
- package/src/components/views/browser/item-panel/index.tsx +5 -2
- package/src/components/views/browser/item-panel-grid/index.tsx +7 -1
- package/src/components/views/browser/toolbar.tsx +5 -2
- package/src/components/views/calc/calculator/index.tsx +3 -0
- package/src/components/views/calc/flow/index.tsx +10 -2
- package/src/components/views/calc/flow/picker-dialogs.tsx +122 -5
- package/src/components/views/calc/node-card/full.tsx +0 -1
- package/src/components/views/calc/node-card/menu.tsx +17 -1
- package/src/components/views/calc/node-card/port-cells.tsx +23 -6
- package/src/components/views/calc/node-card/port-rails.tsx +1 -3
- package/src/hooks/calc/flow/use-handlers.ts +14 -6
- package/src/hooks/calc/flow/use-layout.ts +5 -0
- package/src/hooks/calc/flow/use-pickers.ts +15 -0
- package/src/hooks/calc/flow/use-viewport.ts +1 -1
- package/src/hooks/calc/use-actions.ts +144 -4
- package/src/hooks/calc/use-defaults.ts +4 -0
- package/src/hooks/calc/use-resolver.ts +1 -0
- package/src/hooks/calc/use-storage.ts +6 -1
- package/src/hooks/use-index.ts +10 -0
- package/src/hooks/use-left-sidebar-tree.ts +4 -1
- package/src/lib/calc/defaults.ts +43 -5
- package/src/lib/calc/flow.ts +32 -14
- package/src/lib/calc/scheme.ts +24 -16
- package/src/lib/calc/storage/index.ts +1 -0
- package/src/lib/calc/storage/keys.ts +1 -1
- package/src/lib/calc/storage/store.ts +62 -0
- package/src/lib/calc/tree/recipe.ts +1 -0
- package/src/lib/calc/wire.ts +39 -0
- package/src/lib/calc/worker/resolve.ts +7 -0
- package/src/lib/client-index/chrome.ts +56 -38
- package/src/lib/client-index/index.ts +1 -1
- package/src/lib/links.ts +2 -1
- package/src/types/calc-flow-props.ts +1 -0
- package/src/types/calc.ts +2 -1
- package/styles/calc.css +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/recipe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Recipe viewer and calculator",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@terrafirmagreg-team/data": "^1.2.3",
|
|
27
|
-
"@terrafirmagreg-team/dump": "^1.2.
|
|
27
|
+
"@terrafirmagreg-team/dump": "^1.2.9",
|
|
28
28
|
"@terrafirmagreg-team/game": "^1.2.6",
|
|
29
|
-
"@terrafirmagreg-team/kit": "^1.2.
|
|
29
|
+
"@terrafirmagreg-team/kit": "^1.2.14",
|
|
30
30
|
"@terrafirmagreg-team/mdx": "^1.2.7",
|
|
31
31
|
"@terrafirmagreg-team/preview": "^1.2.3",
|
|
32
32
|
"@terrafirmagreg-team/sites": "^1.2.2",
|
|
@@ -9,7 +9,11 @@ import { recipePlaceFromParams } from '@terrafirmagreg-team/recipe/lib/links';
|
|
|
9
9
|
import { recipeCalcHref, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
10
10
|
import { parseSectionLocation } from '@terrafirmagreg-team/sites/location';
|
|
11
11
|
import { Switcher } from '@terrafirmagreg-team/ui/components/blocks/nav/switcher';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
isDatasetFailed,
|
|
14
|
+
useFailedDatasets,
|
|
15
|
+
} from '@terrafirmagreg-team/kit/hooks/use-dump-status';
|
|
16
|
+
import { useVersionPreference } from '@terrafirmagreg-team/kit/hooks/use-version-pref';
|
|
13
17
|
|
|
14
18
|
export function RecipeAxisSwitcher() {
|
|
15
19
|
const t = useTranslations();
|
|
@@ -18,8 +22,12 @@ export function RecipeAxisSwitcher() {
|
|
|
18
22
|
const params = useLocationSearchParams();
|
|
19
23
|
const axis = recipePlaceFromParams(params).kind;
|
|
20
24
|
const failed = useFailedDatasets();
|
|
21
|
-
const
|
|
22
|
-
|
|
25
|
+
const preferred = useVersionPreference(datasetId);
|
|
26
|
+
const dataset = {
|
|
27
|
+
id: datasetId ?? '',
|
|
28
|
+
version: params.get('version') ?? preferred,
|
|
29
|
+
};
|
|
30
|
+
if (!datasetId || isDatasetFailed(failed, dataset)) return null;
|
|
23
31
|
return (
|
|
24
32
|
<Switcher
|
|
25
33
|
options={[
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { useDocumentTitle } from '@terrafirmagreg-team/ui/hooks/use-document-title';
|
|
4
4
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
isDatasetFailed,
|
|
7
|
+
useFailedDatasets,
|
|
8
|
+
} from '@terrafirmagreg-team/kit/hooks/use-dump-status';
|
|
6
9
|
import {
|
|
7
10
|
DumpUnavailable,
|
|
8
11
|
DumpUnavailableOverlay,
|
|
@@ -75,7 +78,8 @@ export function RecipeBrowser({
|
|
|
75
78
|
const { dataset, item, fluid, names } = session;
|
|
76
79
|
const focusId = item ?? fluid;
|
|
77
80
|
const failed =
|
|
78
|
-
useFailedDatasets()
|
|
81
|
+
isDatasetFailed(useFailedDatasets(), dataset) &&
|
|
82
|
+
!session.index?.items.length;
|
|
79
83
|
|
|
80
84
|
const focusTitle = focusId
|
|
81
85
|
? recipeItemName(names, lang, focusId)
|
|
@@ -35,7 +35,10 @@ import {
|
|
|
35
35
|
RecipePanelSkeleton,
|
|
36
36
|
RecipeTabsSkeleton,
|
|
37
37
|
} from '@terrafirmagreg-team/recipe/components/views/browser/item-panel/skeleton';
|
|
38
|
-
import {
|
|
38
|
+
import {
|
|
39
|
+
isDatasetFailed,
|
|
40
|
+
useFailedDatasets,
|
|
41
|
+
} from '@terrafirmagreg-team/kit/hooks/use-dump-status';
|
|
39
42
|
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
40
43
|
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
41
44
|
import type {
|
|
@@ -137,7 +140,7 @@ export const ItemPanel = memo(function ItemPanel({
|
|
|
137
140
|
|
|
138
141
|
const tabOptions = usePanelTabs(dIndex, dNames, dLang);
|
|
139
142
|
|
|
140
|
-
const failed = useFailedDatasets()
|
|
143
|
+
const failed = isDatasetFailed(useFailedDatasets(), dataset);
|
|
141
144
|
|
|
142
145
|
let body;
|
|
143
146
|
const indexEmpty = !index?.items.length;
|
|
@@ -60,7 +60,13 @@ export const ItemPanelGrid = memo(function ItemPanelGrid({
|
|
|
60
60
|
>
|
|
61
61
|
{shown.map((cell) => (
|
|
62
62
|
<PanelCell
|
|
63
|
-
key={
|
|
63
|
+
key={
|
|
64
|
+
cell.kind === 'recipe'
|
|
65
|
+
? `R:${cell.fav.id}`
|
|
66
|
+
: cell.kind === 'group'
|
|
67
|
+
? `G:${cell.id}`
|
|
68
|
+
: cell.id
|
|
69
|
+
}
|
|
64
70
|
cell={cell}
|
|
65
71
|
dataset={dataset}
|
|
66
72
|
lang={lang}
|
|
@@ -11,13 +11,16 @@ import {
|
|
|
11
11
|
SheetTitle,
|
|
12
12
|
} from '@terrafirmagreg-team/ui/components/ui/sheet';
|
|
13
13
|
import { ItemPanel } from '@terrafirmagreg-team/recipe/components/views/browser/item-panel';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
isDatasetFailed,
|
|
16
|
+
useFailedDatasets,
|
|
17
|
+
} from '@terrafirmagreg-team/kit/hooks/use-dump-status';
|
|
15
18
|
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
16
19
|
|
|
17
20
|
export function RecipeToolbar({ session }: { session: RecipeSession }) {
|
|
18
21
|
const t = useTranslations();
|
|
19
22
|
const [itemsOpen, setItemsOpen] = useState(false);
|
|
20
|
-
const failed = useFailedDatasets()
|
|
23
|
+
const failed = isDatasetFailed(useFailedDatasets(), session.dataset);
|
|
21
24
|
if ((session.indexLoading || failed) && !session.index?.items.length)
|
|
22
25
|
return null;
|
|
23
26
|
|
|
@@ -40,6 +40,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
40
40
|
setRecipeDefault,
|
|
41
41
|
getRecipesForItem,
|
|
42
42
|
ensureMaterial,
|
|
43
|
+
tagMembers,
|
|
43
44
|
nodes,
|
|
44
45
|
flows,
|
|
45
46
|
summary,
|
|
@@ -80,6 +81,8 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
80
81
|
flushAmounts,
|
|
81
82
|
setFocusNodeId,
|
|
82
83
|
nodes: deferredNodes,
|
|
84
|
+
tagMembers,
|
|
85
|
+
ensureMaterial,
|
|
83
86
|
});
|
|
84
87
|
|
|
85
88
|
const iconItems = useMemo(
|
|
@@ -97,14 +97,17 @@ function CalcFlowInner({
|
|
|
97
97
|
setMemberNode,
|
|
98
98
|
supply,
|
|
99
99
|
setSupply,
|
|
100
|
+
demand,
|
|
101
|
+
setDemand,
|
|
100
102
|
onRequestPicker,
|
|
101
103
|
onRequestMemberPicker,
|
|
102
104
|
onRequestSupply,
|
|
105
|
+
onRequestDemand,
|
|
103
106
|
} = useFlowPickers(schemeNodes);
|
|
104
107
|
|
|
105
108
|
const flowData = useMemo(
|
|
106
|
-
() => ({ ...data, onRequestSupply }),
|
|
107
|
-
[data, onRequestSupply],
|
|
109
|
+
() => ({ ...data, onRequestSupply, onRequestDemand }),
|
|
110
|
+
[data, onRequestSupply, onRequestDemand],
|
|
108
111
|
);
|
|
109
112
|
|
|
110
113
|
const tier = useStore((s) =>
|
|
@@ -124,6 +127,7 @@ function CalcFlowInner({
|
|
|
124
127
|
onRequestPicker,
|
|
125
128
|
onRequestMemberPicker,
|
|
126
129
|
onRequestSupply,
|
|
130
|
+
onRequestDemand,
|
|
127
131
|
});
|
|
128
132
|
const focusIdRef = useRef<string | null>(null);
|
|
129
133
|
const [focusId, setFocusId] = useState<string | null>(null);
|
|
@@ -179,6 +183,7 @@ function CalcFlowInner({
|
|
|
179
183
|
setPickerNode(null);
|
|
180
184
|
setMemberNode(null);
|
|
181
185
|
setSupply(null);
|
|
186
|
+
setDemand(null);
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
const {
|
|
@@ -204,6 +209,7 @@ function CalcFlowInner({
|
|
|
204
209
|
const closePicker = useCallback(() => setPickerNode(null), [setPickerNode]);
|
|
205
210
|
const closeMember = useCallback(() => setMemberNode(null), [setMemberNode]);
|
|
206
211
|
const closeSupply = useCallback(() => setSupply(null), [setSupply]);
|
|
212
|
+
const closeDemand = useCallback(() => setDemand(null), [setDemand]);
|
|
207
213
|
const runRelayout = useCallback(() => {
|
|
208
214
|
onRelayout?.(relayout());
|
|
209
215
|
}, [onRelayout, relayout]);
|
|
@@ -282,12 +288,14 @@ function CalcFlowInner({
|
|
|
282
288
|
pickerNode={pickerNode}
|
|
283
289
|
memberNode={memberNode}
|
|
284
290
|
supply={supply}
|
|
291
|
+
demand={demand}
|
|
285
292
|
session={session}
|
|
286
293
|
dataset={dataset}
|
|
287
294
|
data={data}
|
|
288
295
|
onClosePicker={closePicker}
|
|
289
296
|
onCloseMember={closeMember}
|
|
290
297
|
onCloseSupply={closeSupply}
|
|
298
|
+
onCloseDemand={closeDemand}
|
|
291
299
|
/>
|
|
292
300
|
</CalcTierProvider>
|
|
293
301
|
</CalcFarProvider>
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
3
3
|
|
|
4
|
-
import { Mountain } from 'lucide-react';
|
|
4
|
+
import { Mountain, SquareArrowOutUpRight } from 'lucide-react';
|
|
5
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
6
|
import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
7
|
+
import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
7
8
|
import { CalcRecipePicker } from '@terrafirmagreg-team/recipe/components/views/calc/recipe-picker';
|
|
8
9
|
import { CalcMemberPicker } from '@terrafirmagreg-team/recipe/components/views/calc/member-picker';
|
|
10
|
+
import { usesForInput } from '@terrafirmagreg-team/recipe/lib/browser/lookup';
|
|
9
11
|
import type { CalcFlowData } from '@terrafirmagreg-team/recipe/lib/calc/flow';
|
|
10
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
DemandRequest,
|
|
14
|
+
SupplyRequest,
|
|
15
|
+
} from '@terrafirmagreg-team/recipe/hooks/calc/flow/use-pickers';
|
|
11
16
|
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
12
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
CalcNode,
|
|
19
|
+
CalcRecipeSummary,
|
|
20
|
+
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
13
21
|
|
|
14
22
|
function SupplyPicker({
|
|
15
23
|
supply,
|
|
@@ -21,7 +29,12 @@ function SupplyPicker({
|
|
|
21
29
|
session: RecipeSession;
|
|
22
30
|
data: Omit<
|
|
23
31
|
CalcFlowData,
|
|
24
|
-
|
|
32
|
+
| 'node'
|
|
33
|
+
| 'mode'
|
|
34
|
+
| 'onRequestPicker'
|
|
35
|
+
| 'onRequestMemberPicker'
|
|
36
|
+
| 'onRequestSupply'
|
|
37
|
+
| 'onRequestDemand'
|
|
25
38
|
>;
|
|
26
39
|
onClose: () => void;
|
|
27
40
|
}) {
|
|
@@ -74,29 +87,125 @@ function SupplyPicker({
|
|
|
74
87
|
);
|
|
75
88
|
}
|
|
76
89
|
|
|
90
|
+
function DemandPicker({
|
|
91
|
+
demand,
|
|
92
|
+
session,
|
|
93
|
+
data,
|
|
94
|
+
onClose,
|
|
95
|
+
}: {
|
|
96
|
+
demand: DemandRequest;
|
|
97
|
+
session: RecipeSession;
|
|
98
|
+
data: Omit<
|
|
99
|
+
CalcFlowData,
|
|
100
|
+
| 'node'
|
|
101
|
+
| 'mode'
|
|
102
|
+
| 'onRequestPicker'
|
|
103
|
+
| 'onRequestMemberPicker'
|
|
104
|
+
| 'onRequestSupply'
|
|
105
|
+
| 'onRequestDemand'
|
|
106
|
+
>;
|
|
107
|
+
onClose: () => void;
|
|
108
|
+
}) {
|
|
109
|
+
const t = useTranslations();
|
|
110
|
+
const { node, output } = demand;
|
|
111
|
+
const slot = node.outputs[output];
|
|
112
|
+
const materialId = slot?.id ?? '';
|
|
113
|
+
const kind = slot?.kind ?? 'item';
|
|
114
|
+
const uses = useAsyncResult(
|
|
115
|
+
session.index && materialId
|
|
116
|
+
? () => usesForInput(session.dataset, session.index!, materialId, kind)
|
|
117
|
+
: false,
|
|
118
|
+
[session.dataset, session.index, materialId, kind],
|
|
119
|
+
);
|
|
120
|
+
if (!slot?.id) return null;
|
|
121
|
+
const seen = new Set<string>();
|
|
122
|
+
const recipes: CalcRecipeSummary[] = (uses.value ?? []).flatMap((row) => {
|
|
123
|
+
if (seen.has(row.id)) return [];
|
|
124
|
+
seen.add(row.id);
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
recipeId: row.id,
|
|
128
|
+
category: session.index?.types[row.type] ?? row.cat ?? row.id,
|
|
129
|
+
outputAmount: 1,
|
|
130
|
+
row,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
});
|
|
134
|
+
const demandNode: CalcNode = {
|
|
135
|
+
...node,
|
|
136
|
+
materialId,
|
|
137
|
+
kind,
|
|
138
|
+
recipe: null,
|
|
139
|
+
availableRecipes: recipes,
|
|
140
|
+
tagId: undefined,
|
|
141
|
+
members: undefined,
|
|
142
|
+
inputs: [],
|
|
143
|
+
};
|
|
144
|
+
return (
|
|
145
|
+
<CalcRecipePicker
|
|
146
|
+
open
|
|
147
|
+
onOpenChange={(open) => {
|
|
148
|
+
if (!open) onClose();
|
|
149
|
+
}}
|
|
150
|
+
node={demandNode}
|
|
151
|
+
session={session}
|
|
152
|
+
onSelectRecipe={(_cardId, recipeId) => {
|
|
153
|
+
if (recipeId) data.onDemandOutput(node.id, output, recipeId);
|
|
154
|
+
onClose();
|
|
155
|
+
}}
|
|
156
|
+
onSelectTagMember={data.onSelectTagMember}
|
|
157
|
+
recipeDefaults={data.recipeDefaults}
|
|
158
|
+
onSetRecipeDefault={data.onSetRecipeDefault}
|
|
159
|
+
actions={
|
|
160
|
+
<Button
|
|
161
|
+
size="xs"
|
|
162
|
+
variant="outline"
|
|
163
|
+
className="ms-auto shrink-0"
|
|
164
|
+
onClick={() => {
|
|
165
|
+
data.onOpenItem(materialId, kind, 'uses');
|
|
166
|
+
onClose();
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
<SquareArrowOutUpRight className="size-3.5" />
|
|
170
|
+
{t('Open uses page', { note: 'recipe.calc.demand.uses' })}
|
|
171
|
+
</Button>
|
|
172
|
+
}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
77
177
|
export function CalcPickers({
|
|
78
178
|
pickerNode,
|
|
79
179
|
memberNode,
|
|
80
180
|
supply,
|
|
181
|
+
demand,
|
|
81
182
|
session,
|
|
82
183
|
dataset,
|
|
83
184
|
data,
|
|
84
185
|
onClosePicker,
|
|
85
186
|
onCloseMember,
|
|
86
187
|
onCloseSupply,
|
|
188
|
+
onCloseDemand,
|
|
87
189
|
}: {
|
|
88
190
|
pickerNode: CalcNode | null;
|
|
89
191
|
memberNode: CalcNode | null;
|
|
90
192
|
supply: SupplyRequest | null;
|
|
193
|
+
demand: DemandRequest | null;
|
|
91
194
|
session: RecipeSession;
|
|
92
195
|
dataset: DatasetRef;
|
|
93
196
|
data: Omit<
|
|
94
197
|
CalcFlowData,
|
|
95
|
-
|
|
198
|
+
| 'node'
|
|
199
|
+
| 'mode'
|
|
200
|
+
| 'onRequestPicker'
|
|
201
|
+
| 'onRequestMemberPicker'
|
|
202
|
+
| 'onRequestSupply'
|
|
203
|
+
| 'onRequestDemand'
|
|
96
204
|
>;
|
|
97
205
|
onClosePicker: () => void;
|
|
98
206
|
onCloseMember: () => void;
|
|
99
207
|
onCloseSupply: () => void;
|
|
208
|
+
onCloseDemand: () => void;
|
|
100
209
|
}) {
|
|
101
210
|
return (
|
|
102
211
|
<>
|
|
@@ -140,6 +249,14 @@ export function CalcPickers({
|
|
|
140
249
|
onClose={onCloseSupply}
|
|
141
250
|
/>
|
|
142
251
|
) : null}
|
|
252
|
+
{demand ? (
|
|
253
|
+
<DemandPicker
|
|
254
|
+
demand={demand}
|
|
255
|
+
session={session}
|
|
256
|
+
data={data}
|
|
257
|
+
onClose={onCloseDemand}
|
|
258
|
+
/>
|
|
259
|
+
) : null}
|
|
143
260
|
</>
|
|
144
261
|
);
|
|
145
262
|
}
|
|
@@ -301,7 +301,6 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
|
301
301
|
langMap={langMap}
|
|
302
302
|
names={names}
|
|
303
303
|
connectable={interactive}
|
|
304
|
-
onOpen={() => onRequestPicker(node)}
|
|
305
304
|
/>
|
|
306
305
|
{interactive ? <NodeActions data={data} nodeId={id} /> : null}
|
|
307
306
|
<NodeBadges node={node} />
|
|
@@ -4,6 +4,7 @@ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
|
4
4
|
import {
|
|
5
5
|
ExternalLink,
|
|
6
6
|
ListFilter,
|
|
7
|
+
MoveRight,
|
|
7
8
|
Pin,
|
|
8
9
|
PinOff,
|
|
9
10
|
Plus,
|
|
@@ -159,7 +160,13 @@ export function PortContextMenu({
|
|
|
159
160
|
lang: string;
|
|
160
161
|
langMap?: Record<string, string>;
|
|
161
162
|
}) {
|
|
162
|
-
const {
|
|
163
|
+
const {
|
|
164
|
+
onAddCard,
|
|
165
|
+
onOpenItem,
|
|
166
|
+
onRequestPicker,
|
|
167
|
+
onRequestSupply,
|
|
168
|
+
onRequestDemand,
|
|
169
|
+
} = data;
|
|
163
170
|
const t = useTranslations();
|
|
164
171
|
return (
|
|
165
172
|
<ContextMenuContent>
|
|
@@ -188,6 +195,15 @@ export function PortContextMenu({
|
|
|
188
195
|
{t('Keep as external source', { note: 'recipe.calc.supply.source' })}
|
|
189
196
|
</ContextMenuItem>
|
|
190
197
|
) : null}
|
|
198
|
+
{out != null ? (
|
|
199
|
+
<ContextMenuItem
|
|
200
|
+
className="whitespace-nowrap"
|
|
201
|
+
onClick={() => onRequestDemand(node, out)}
|
|
202
|
+
>
|
|
203
|
+
<MoveRight />
|
|
204
|
+
{t('Use in downstream recipe', { note: 'recipe.calc.demand' })}
|
|
205
|
+
</ContextMenuItem>
|
|
206
|
+
) : null}
|
|
191
207
|
{out === 0 && !node.recipe && node.availableRecipes.length > 0 ? (
|
|
192
208
|
<ContextMenuItem
|
|
193
209
|
className="whitespace-nowrap"
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Position,
|
|
7
7
|
} from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
|
|
8
8
|
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
9
|
+
import { tagHashId } from '@terrafirmagreg-team/dump/lib/dump/paths';
|
|
9
10
|
import {
|
|
10
11
|
ContextMenu,
|
|
11
12
|
ContextMenuTrigger,
|
|
@@ -43,10 +44,8 @@ export function OutputCell({
|
|
|
43
44
|
langMap,
|
|
44
45
|
names,
|
|
45
46
|
connectable,
|
|
46
|
-
onOpen,
|
|
47
47
|
}: CellProps & {
|
|
48
48
|
out: CalcOutput;
|
|
49
|
-
onOpen?: () => void;
|
|
50
49
|
}) {
|
|
51
50
|
const name = recipeItemName(names, lang, out.id);
|
|
52
51
|
const count = out.remaining;
|
|
@@ -68,13 +67,19 @@ export function OutputCell({
|
|
|
68
67
|
)}
|
|
69
68
|
onClick={(e) => {
|
|
70
69
|
e.stopPropagation();
|
|
71
|
-
|
|
70
|
+
data.onRequestDemand(node, index);
|
|
72
71
|
}}
|
|
73
72
|
>
|
|
74
73
|
<span className="calc-port-inner">
|
|
75
74
|
<Entry
|
|
76
75
|
id={out.id}
|
|
77
|
-
kind={
|
|
76
|
+
kind={
|
|
77
|
+
out.tagId
|
|
78
|
+
? out.kind === 'fluid'
|
|
79
|
+
? 'fluidTag'
|
|
80
|
+
: 'itemTag'
|
|
81
|
+
: out.kind
|
|
82
|
+
}
|
|
78
83
|
dataset={dataset}
|
|
79
84
|
lang={lang}
|
|
80
85
|
langMap={langMap}
|
|
@@ -160,6 +165,18 @@ export function InputCell({
|
|
|
160
165
|
href={false}
|
|
161
166
|
tooltip="adaptive"
|
|
162
167
|
/>
|
|
168
|
+
) : inp.tagId ? (
|
|
169
|
+
<Entry
|
|
170
|
+
id={tagHashId(inp.tagId)}
|
|
171
|
+
kind={inp.kind === 'fluid' ? 'fluidTag' : 'itemTag'}
|
|
172
|
+
dataset={dataset}
|
|
173
|
+
lang={lang}
|
|
174
|
+
langMap={langMap}
|
|
175
|
+
name={`${name} ×${qty}`}
|
|
176
|
+
size="sm"
|
|
177
|
+
href={false}
|
|
178
|
+
tooltip="adaptive"
|
|
179
|
+
/>
|
|
163
180
|
) : (
|
|
164
181
|
<span className="text-[9px]">?</span>
|
|
165
182
|
)}
|
|
@@ -168,12 +185,12 @@ export function InputCell({
|
|
|
168
185
|
</Handle>
|
|
169
186
|
}
|
|
170
187
|
/>
|
|
171
|
-
{id ? (
|
|
188
|
+
{id || inp.tagId ? (
|
|
172
189
|
<PortContextMenu
|
|
173
190
|
data={data}
|
|
174
191
|
node={node}
|
|
175
192
|
input={index}
|
|
176
|
-
id={id}
|
|
193
|
+
id={id ?? tagHashId(inp.tagId!)}
|
|
177
194
|
kind={inp.kind}
|
|
178
195
|
dataset={dataset}
|
|
179
196
|
lang={lang}
|
|
@@ -171,8 +171,7 @@ export function PortRailOut({
|
|
|
171
171
|
langMap,
|
|
172
172
|
names,
|
|
173
173
|
connectable = true,
|
|
174
|
-
|
|
175
|
-
}: RailProps & { onOpen?: () => void }) {
|
|
174
|
+
}: RailProps) {
|
|
176
175
|
const {
|
|
177
176
|
ref,
|
|
178
177
|
start,
|
|
@@ -222,7 +221,6 @@ export function PortRailOut({
|
|
|
222
221
|
langMap={langMap}
|
|
223
222
|
names={names}
|
|
224
223
|
connectable={connectable}
|
|
225
|
-
onOpen={onOpen}
|
|
226
224
|
/>
|
|
227
225
|
))}
|
|
228
226
|
{below > 0 ? (
|
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
import type {
|
|
18
18
|
CalcKind,
|
|
19
19
|
CalcNode,
|
|
20
|
+
CalcNodeInput,
|
|
21
|
+
CalcOutput,
|
|
20
22
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
21
23
|
|
|
22
24
|
export function useFlowHandlers({
|
|
@@ -36,6 +38,14 @@ export function useFlowHandlers({
|
|
|
36
38
|
setPickerNode: (node: CalcNode | null) => void;
|
|
37
39
|
}) {
|
|
38
40
|
const { screenToFlowPosition, getNode } = useReactFlow();
|
|
41
|
+
const slotAccepts = useCallback(
|
|
42
|
+
(slot: CalcNodeInput | undefined, srcOut: CalcOutput | undefined) => {
|
|
43
|
+
if (!slot || !srcOut?.id || slot.kind !== srcOut.kind) return false;
|
|
44
|
+
if (slot.id === srcOut.id) return true;
|
|
45
|
+
return !!slot.tagId && !!slot.members?.includes(srcOut.id);
|
|
46
|
+
},
|
|
47
|
+
[],
|
|
48
|
+
);
|
|
39
49
|
|
|
40
50
|
const handleNodeEnter = useCallback(
|
|
41
51
|
(_event: MouseEvent, node: AnyCalcFlowNode) => applyEngaged(node.id),
|
|
@@ -117,11 +127,10 @@ export function useFlowHandlers({
|
|
|
117
127
|
const tNode = (getNode(target)?.data as CalcFlowData | undefined)?.node;
|
|
118
128
|
const slot = tNode?.inputs[input];
|
|
119
129
|
const srcOut = sNode?.outputs[out];
|
|
120
|
-
if (!sNode || !tNode || !slot
|
|
121
|
-
if (slot.id !== srcOut.id || slot.kind !== srcOut.kind) return;
|
|
130
|
+
if (!sNode || !tNode || !slotAccepts(slot, srcOut)) return;
|
|
122
131
|
data.onWire(source, target, input, out);
|
|
123
132
|
},
|
|
124
|
-
[data, getNode],
|
|
133
|
+
[data, getNode, slotAccepts],
|
|
125
134
|
);
|
|
126
135
|
|
|
127
136
|
const handleReconnect = useCallback(
|
|
@@ -139,8 +148,7 @@ export function useFlowHandlers({
|
|
|
139
148
|
const tNode = (getNode(conn.target)?.data as CalcFlowData | undefined)?.node;
|
|
140
149
|
const slot = tNode?.inputs[input];
|
|
141
150
|
const srcOut = sNode?.outputs[out];
|
|
142
|
-
if (!sNode || !tNode || !slot
|
|
143
|
-
if (slot.id !== srcOut.id || slot.kind !== srcOut.kind) return;
|
|
151
|
+
if (!sNode || !tNode || !slotAccepts(slot, srcOut)) return;
|
|
144
152
|
data.onRewire(wire.from, wire.to, wire.input, {
|
|
145
153
|
from: conn.source,
|
|
146
154
|
to: conn.target,
|
|
@@ -148,7 +156,7 @@ export function useFlowHandlers({
|
|
|
148
156
|
out,
|
|
149
157
|
});
|
|
150
158
|
},
|
|
151
|
-
[data, getNode],
|
|
159
|
+
[data, getNode, slotAccepts],
|
|
152
160
|
);
|
|
153
161
|
|
|
154
162
|
const handleEdgesDelete = useCallback(
|
|
@@ -26,6 +26,7 @@ export function useFlowLayout({
|
|
|
26
26
|
onRequestPicker,
|
|
27
27
|
onRequestMemberPicker,
|
|
28
28
|
onRequestSupply,
|
|
29
|
+
onRequestDemand,
|
|
29
30
|
}: {
|
|
30
31
|
nodes: CalcNode[];
|
|
31
32
|
wires: CalcWire[];
|
|
@@ -38,12 +39,14 @@ export function useFlowLayout({
|
|
|
38
39
|
| 'onRequestPicker'
|
|
39
40
|
| 'onRequestMemberPicker'
|
|
40
41
|
| 'onRequestSupply'
|
|
42
|
+
| 'onRequestDemand'
|
|
41
43
|
| 'onCrafts'
|
|
42
44
|
>;
|
|
43
45
|
mode: CalcViewMode;
|
|
44
46
|
onRequestPicker: (node: CalcNode) => void;
|
|
45
47
|
onRequestMemberPicker: (node: CalcNode) => void;
|
|
46
48
|
onRequestSupply: (node: CalcNode, input: number) => void;
|
|
49
|
+
onRequestDemand: (node: CalcNode, output: number) => void;
|
|
47
50
|
}) {
|
|
48
51
|
const flowData = useMemo(
|
|
49
52
|
() =>
|
|
@@ -53,6 +56,7 @@ export function useFlowLayout({
|
|
|
53
56
|
onRequestPicker,
|
|
54
57
|
onRequestMemberPicker,
|
|
55
58
|
onRequestSupply,
|
|
59
|
+
onRequestDemand,
|
|
56
60
|
}) as Omit<CalcFlowData, 'node'>,
|
|
57
61
|
[
|
|
58
62
|
data,
|
|
@@ -60,6 +64,7 @@ export function useFlowLayout({
|
|
|
60
64
|
onRequestPicker,
|
|
61
65
|
onRequestMemberPicker,
|
|
62
66
|
onRequestSupply,
|
|
67
|
+
onRequestDemand,
|
|
63
68
|
],
|
|
64
69
|
);
|
|
65
70
|
const rawFlow = useMemo(
|
|
@@ -4,11 +4,13 @@ import { useCallback, useState } from 'react';
|
|
|
4
4
|
import type { CalcNode } from '@terrafirmagreg-team/recipe/types/calc';
|
|
5
5
|
|
|
6
6
|
export type SupplyRequest = { node: CalcNode; input: number };
|
|
7
|
+
export type DemandRequest = { node: CalcNode; output: number };
|
|
7
8
|
|
|
8
9
|
export function useFlowPickers(nodes: CalcNode[]) {
|
|
9
10
|
const [pickerNode, setPickerNode] = useState<CalcNode | null>(null);
|
|
10
11
|
const [memberNode, setMemberNode] = useState<CalcNode | null>(null);
|
|
11
12
|
const [supply, setSupply] = useState<SupplyRequest | null>(null);
|
|
13
|
+
const [demand, setDemand] = useState<DemandRequest | null>(null);
|
|
12
14
|
const onRequestPicker = useCallback(
|
|
13
15
|
(node: CalcNode) => setPickerNode(node),
|
|
14
16
|
[],
|
|
@@ -21,6 +23,10 @@ export function useFlowPickers(nodes: CalcNode[]) {
|
|
|
21
23
|
(node: CalcNode, input: number) => setSupply({ node, input }),
|
|
22
24
|
[],
|
|
23
25
|
);
|
|
26
|
+
const onRequestDemand = useCallback(
|
|
27
|
+
(node: CalcNode, output: number) => setDemand({ node, output }),
|
|
28
|
+
[],
|
|
29
|
+
);
|
|
24
30
|
|
|
25
31
|
const [prevNodes, setPrevNodes] = useState(nodes);
|
|
26
32
|
if (prevNodes !== nodes) {
|
|
@@ -40,6 +46,12 @@ export function useFlowPickers(nodes: CalcNode[]) {
|
|
|
40
46
|
else if (live !== supply.node)
|
|
41
47
|
setSupply({ node: live, input: supply.input });
|
|
42
48
|
}
|
|
49
|
+
if (demand) {
|
|
50
|
+
const live = nodes.find((n) => n.id === demand.node.id);
|
|
51
|
+
if (!live) setDemand(null);
|
|
52
|
+
else if (live !== demand.node)
|
|
53
|
+
setDemand({ node: live, output: demand.output });
|
|
54
|
+
}
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
return {
|
|
@@ -49,9 +61,12 @@ export function useFlowPickers(nodes: CalcNode[]) {
|
|
|
49
61
|
setMemberNode,
|
|
50
62
|
supply,
|
|
51
63
|
setSupply,
|
|
64
|
+
demand,
|
|
65
|
+
setDemand,
|
|
52
66
|
onRequestPicker,
|
|
53
67
|
onRequestMemberPicker,
|
|
54
68
|
onRequestSupply,
|
|
69
|
+
onRequestDemand,
|
|
55
70
|
};
|
|
56
71
|
}
|
|
57
72
|
|
|
@@ -42,7 +42,7 @@ export function useFlowViewport({
|
|
|
42
42
|
}) {
|
|
43
43
|
const { setCenter, getZoom } = useReactFlow();
|
|
44
44
|
const userMovedRef = useRef(false);
|
|
45
|
-
const storageKey = `calc:${dataset.id}
|
|
45
|
+
const storageKey = `calc:${dataset.id}`;
|
|
46
46
|
|
|
47
47
|
const ready = treeReady;
|
|
48
48
|
|