@terrafirmagreg-team/recipe 1.2.38 → 1.2.39
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/cards/card/text.tsx +3 -2
- package/src/components/cards/scroll-card/index.tsx +16 -3
- package/src/components/cards/slot-hitbox.tsx +7 -4
- package/src/components/cards/strip-card/member-cell.tsx +4 -2
- package/src/components/views/browser/frame.tsx +73 -33
- package/src/components/views/browser/item-view/index.tsx +12 -9
- package/src/components/views/browser/item-view/tags.tsx +3 -3
- package/src/components/views/browser/query-controls.tsx +1 -1
- package/src/components/views/browser/type-view.tsx +40 -1
- package/src/components/views/calc/calculator/actions.tsx +7 -3
- package/src/components/views/calc/calculator/index.tsx +18 -8
- package/src/components/views/calc/edge.tsx +3 -1
- package/src/components/views/calc/node-card/badges.tsx +11 -2
- package/src/components/views/calc/node-card/full.tsx +63 -10
- package/src/components/views/calc/node-card/port-cells.tsx +13 -8
- package/src/components/views/calc/node-card/ports.tsx +39 -13
- package/src/components/views/calc/recipe-picker/body.tsx +34 -1
- package/src/components/views/calc/sidebar.tsx +8 -2
- package/src/hooks/calc/use-actions.ts +2 -0
- package/src/hooks/calc/use-amounts.ts +22 -3
- package/src/hooks/calc/use-storage.ts +2 -1
- package/src/lib/calc/flow.ts +2 -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.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Recipe viewer and calculator",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@terrafirmagreg-team/data": "^1.2.14",
|
|
27
27
|
"@terrafirmagreg-team/dump": "^1.2.25",
|
|
28
|
-
"@terrafirmagreg-team/game": "^1.2.
|
|
28
|
+
"@terrafirmagreg-team/game": "^1.2.16",
|
|
29
29
|
"@terrafirmagreg-team/kit": "^1.2.36",
|
|
30
30
|
"@terrafirmagreg-team/mdx": "^1.2.14",
|
|
31
31
|
"@terrafirmagreg-team/preview": "^1.2.12",
|
|
32
32
|
"@terrafirmagreg-team/sites": "^1.2.5",
|
|
33
33
|
"@terrafirmagreg-team/translate": "^1.2.14",
|
|
34
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
34
|
+
"@terrafirmagreg-team/ui": "^1.2.29",
|
|
35
35
|
"@types/pathfinding": "^0.1.0",
|
|
36
36
|
"comlink": "^4.4.2",
|
|
37
37
|
"fflate": "0.8.3",
|
|
@@ -45,15 +45,16 @@ export function CardText({
|
|
|
45
45
|
...(wrap ? { width: widget.w * scale } : {}),
|
|
46
46
|
}),
|
|
47
47
|
fontSize: size ?? 8 * scale,
|
|
48
|
+
fontWeight: 700,
|
|
48
49
|
color: `#${rgb.toString(16).padStart(6, '0')}`,
|
|
49
50
|
...(widget.shadow === true
|
|
50
51
|
? {
|
|
51
|
-
textShadow: `${scale}px ${scale}px 0 #${shadowRgb.toString(16).padStart(6, '0')}`,
|
|
52
|
+
textShadow: `${scale / 2}px ${scale / 2}px 0 #${shadowRgb.toString(16).padStart(6, '0')}`,
|
|
52
53
|
}
|
|
53
54
|
: {}),
|
|
54
55
|
}}
|
|
55
56
|
>
|
|
56
|
-
<McText text={content} surface="
|
|
57
|
+
<McText text={content} surface="normal" />
|
|
57
58
|
</span>
|
|
58
59
|
);
|
|
59
60
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useId,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ComponentProps,
|
|
9
|
+
type CSSProperties,
|
|
10
|
+
} from 'react';
|
|
4
11
|
import { RecipeCard } from '@terrafirmagreg-team/recipe/components/cards/card';
|
|
5
12
|
import { StripCardMember } from '@terrafirmagreg-team/recipe/components/cards/strip-card/member-cell';
|
|
6
13
|
import { CardScrollbar } from '@terrafirmagreg-team/recipe/components/cards/controls/card-scrollbar';
|
|
@@ -315,6 +322,7 @@ export function ScrollCard(props: Props) {
|
|
|
315
322
|
|
|
316
323
|
const renderText = (el: ScrollElement, index: number, moving: boolean) => {
|
|
317
324
|
const rgb = (el.color ?? 0xffffff) & 0xffffff;
|
|
325
|
+
const shadowRgb = ((rgb & 0xfcfcfc) >> 2) & 0xffffff;
|
|
318
326
|
const x = (el.x - viewport.x) * scale;
|
|
319
327
|
const y = (el.y - viewport.y) * scale;
|
|
320
328
|
const shifted = (horizontal ? x : y) - (moving ? offset * scale : 0);
|
|
@@ -326,7 +334,9 @@ export function ScrollCard(props: Props) {
|
|
|
326
334
|
left: horizontal ? shifted : x,
|
|
327
335
|
top: horizontal ? y : shifted,
|
|
328
336
|
fontSize: 8 * scale,
|
|
337
|
+
fontWeight: 700,
|
|
329
338
|
color: `#${rgb.toString(16).padStart(6, '0')}`,
|
|
339
|
+
textShadow: `${scale / 2}px ${scale / 2}px 0 #${shadowRgb.toString(16).padStart(6, '0')}`,
|
|
330
340
|
}}
|
|
331
341
|
>
|
|
332
342
|
<McText text={el.text ?? ''} surface="dark" />
|
|
@@ -412,8 +422,11 @@ export function ScrollCard(props: Props) {
|
|
|
412
422
|
) : null}
|
|
413
423
|
{el.label ? (
|
|
414
424
|
<span
|
|
415
|
-
className="font-mc pointer-events-none absolute right-0 bottom-0 leading-none
|
|
416
|
-
style={{
|
|
425
|
+
className="font-mc mc-count pointer-events-none absolute right-0 bottom-0 leading-none"
|
|
426
|
+
style={{
|
|
427
|
+
fontSize: (el.w / 16) * 7 * scale,
|
|
428
|
+
'--mc-count-shift': `${scale}px`,
|
|
429
|
+
} as CSSProperties}
|
|
417
430
|
>
|
|
418
431
|
{el.label}
|
|
419
432
|
</span>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import type { CSSProperties } from 'react';
|
|
2
3
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
3
4
|
|
|
4
5
|
import Link from 'next/link';
|
|
@@ -142,11 +143,12 @@ export function SlotHitbox({
|
|
|
142
143
|
{widget.kind === 'tag' ? (
|
|
143
144
|
<span
|
|
144
145
|
aria-hidden
|
|
145
|
-
className="font-mc pointer-events-none absolute top-0 left-0 leading-none
|
|
146
|
+
className="font-mc mc-count pointer-events-none absolute top-0 left-0 leading-none"
|
|
146
147
|
style={{
|
|
147
148
|
paddingLeft: scale / 2,
|
|
148
149
|
fontSize: (Math.min(widget.w, widget.h) / 16) * 7 * scale,
|
|
149
|
-
|
|
150
|
+
'--mc-count-shift': `${scale}px`,
|
|
151
|
+
} as CSSProperties}
|
|
150
152
|
>
|
|
151
153
|
#
|
|
152
154
|
</span>
|
|
@@ -163,7 +165,7 @@ export function SlotHitbox({
|
|
|
163
165
|
widget.count !== undefined && widget.count > 1 ? (
|
|
164
166
|
<span
|
|
165
167
|
aria-hidden
|
|
166
|
-
className="font-mc pointer-events-none absolute right-0 bottom-0 leading-none
|
|
168
|
+
className="font-mc mc-count pointer-events-none absolute right-0 bottom-0 leading-none"
|
|
167
169
|
style={{
|
|
168
170
|
paddingRight: scale,
|
|
169
171
|
paddingBottom: scale,
|
|
@@ -171,7 +173,8 @@ export function SlotHitbox({
|
|
|
171
173
|
(Math.min(widget.w, widget.h) / 16) *
|
|
172
174
|
(widget.kind === 'fluid' ? 4 : 7) *
|
|
173
175
|
scale,
|
|
174
|
-
|
|
176
|
+
'--mc-count-shift': `${scale}px`,
|
|
177
|
+
} as CSSProperties}
|
|
175
178
|
>
|
|
176
179
|
{widget.kind === 'fluid'
|
|
177
180
|
? formatFluidAmount(widget.count)
|
|
@@ -109,8 +109,10 @@ export function StripCardMember({
|
|
|
109
109
|
)}
|
|
110
110
|
{badges.length > 0 && (
|
|
111
111
|
<span
|
|
112
|
-
className="font-mc pointer-events-none absolute right-0 bottom-0 leading-none
|
|
113
|
-
style={{
|
|
112
|
+
className="font-mc mc-count pointer-events-none absolute right-0 bottom-0 leading-none"
|
|
113
|
+
style={{
|
|
114
|
+
fontSize: (pitch / 16) * (kind === 'fluid' ? 4 : 7),
|
|
115
|
+
}}
|
|
114
116
|
>
|
|
115
117
|
{badges.join(' ')}
|
|
116
118
|
</span>
|
|
@@ -9,6 +9,7 @@ import { Pager } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
|
9
9
|
import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
|
|
10
10
|
import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
11
11
|
import { replaceUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
|
|
12
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
12
13
|
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
13
14
|
|
|
14
15
|
type FeedList = {
|
|
@@ -26,6 +27,9 @@ export function RecipeFrame({
|
|
|
26
27
|
strip,
|
|
27
28
|
rail,
|
|
28
29
|
back,
|
|
30
|
+
navPrev,
|
|
31
|
+
navNext,
|
|
32
|
+
onNavWheel,
|
|
29
33
|
onPageChange,
|
|
30
34
|
children,
|
|
31
35
|
}: {
|
|
@@ -35,6 +39,9 @@ export function RecipeFrame({
|
|
|
35
39
|
strip?: ReactNode;
|
|
36
40
|
rail?: ReactNode;
|
|
37
41
|
back?: { href: string; label: string };
|
|
42
|
+
navPrev?: ReactNode;
|
|
43
|
+
navNext?: ReactNode;
|
|
44
|
+
onNavWheel?: (dir: -1 | 1) => void;
|
|
38
45
|
onPageChange?: (page: number) => void;
|
|
39
46
|
children: ReactNode;
|
|
40
47
|
}) {
|
|
@@ -62,45 +69,78 @@ export function RecipeFrame({
|
|
|
62
69
|
<div className="min-w-0 flex-1">{strip}</div>
|
|
63
70
|
</div>
|
|
64
71
|
) : null}
|
|
65
|
-
<div
|
|
66
|
-
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
<div
|
|
73
|
+
className={cn(
|
|
74
|
+
'grid items-center gap-x-3 border-b border-border pb-2 pt-2',
|
|
75
|
+
navPrev || navNext
|
|
76
|
+
? 'grid-cols-[minmax(0,1fr)_minmax(0,360px)_minmax(0,1fr)]'
|
|
77
|
+
: 'grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)]',
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
<div className="flex min-w-0 justify-start">
|
|
81
|
+
{back ? (
|
|
82
|
+
<Link
|
|
83
|
+
href={back.href}
|
|
84
|
+
className="shrink-0 text-xs text-muted-foreground hover:text-foreground"
|
|
85
|
+
>
|
|
86
|
+
← {back.label}
|
|
87
|
+
</Link>
|
|
88
|
+
) : null}
|
|
89
|
+
</div>
|
|
90
|
+
{navPrev || navNext ? (
|
|
91
|
+
<div
|
|
92
|
+
onWheel={
|
|
93
|
+
onNavWheel
|
|
94
|
+
? (event) => onNavWheel(event.deltaY > 0 ? 1 : -1)
|
|
95
|
+
: undefined
|
|
96
|
+
}
|
|
97
|
+
className="flex w-full max-w-90 min-w-0 items-center gap-2"
|
|
70
98
|
>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
{navPrev}
|
|
100
|
+
<div className="min-w-0 flex-1">{header}</div>
|
|
101
|
+
{navNext}
|
|
102
|
+
</div>
|
|
103
|
+
) : (
|
|
104
|
+
<div className="min-w-0 max-w-full">{header}</div>
|
|
105
|
+
)}
|
|
106
|
+
<div className="flex min-w-0 items-center justify-self-end">
|
|
76
107
|
<RecipeToolbar session={session} />
|
|
77
108
|
</div>
|
|
78
109
|
</div>
|
|
79
110
|
{list ? (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
<div
|
|
112
|
+
onWheel={(event) => goPage(event.deltaY > 0 ? 1 : -1)}
|
|
113
|
+
className="mx-auto w-full max-w-90"
|
|
114
|
+
>
|
|
115
|
+
{onPageChange ? (
|
|
116
|
+
<Pager
|
|
117
|
+
layout="spread"
|
|
118
|
+
page={list.page}
|
|
119
|
+
pages={list.pages}
|
|
120
|
+
to={list.to}
|
|
121
|
+
total={list.total}
|
|
122
|
+
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
123
|
+
className="pt-2"
|
|
124
|
+
onPage={onPageChange}
|
|
125
|
+
/>
|
|
126
|
+
) : (
|
|
127
|
+
<QueryPager
|
|
128
|
+
dataset={session.dataset}
|
|
129
|
+
params={{ ...session.nav, id: undefined }}
|
|
130
|
+
query={session.query}
|
|
131
|
+
list={list}
|
|
132
|
+
label={t('{page}/{pages}', { note: 'recipe.page_of' })}
|
|
133
|
+
className="pt-2"
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
101
137
|
) : null}
|
|
102
|
-
<div className="flex min-h-0 flex-1
|
|
103
|
-
{rail
|
|
138
|
+
<div className="relative flex min-h-0 flex-1 overflow-hidden pt-2">
|
|
139
|
+
{rail ? (
|
|
140
|
+
<div className="absolute start-0 top-2 bottom-0 z-10 flex flex-col">
|
|
141
|
+
{rail}
|
|
142
|
+
</div>
|
|
143
|
+
) : null}
|
|
104
144
|
<div
|
|
105
145
|
onWheel={(event) => goPage(event.deltaY > 0 ? 1 : -1)}
|
|
106
146
|
className="flex min-w-0 flex-1 flex-col"
|
|
@@ -138,19 +138,22 @@ export function ItemView({ session }: { session: RecipeSession }) {
|
|
|
138
138
|
}
|
|
139
139
|
header={
|
|
140
140
|
<div className="flex flex-col gap-1.5">
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
141
|
+
<div className="mx-auto w-full max-w-90">
|
|
142
|
+
<ItemViewHeader
|
|
143
|
+
item={item}
|
|
144
|
+
kind={kind}
|
|
145
|
+
name={name}
|
|
146
|
+
parsed={parsed}
|
|
147
|
+
favorite={favorites.isFavorite(item)}
|
|
148
|
+
onToggleFavorite={() => favorites.toggleItem(item)}
|
|
149
|
+
onAddToCalc={() => addToCalc(item, kind)}
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
150
152
|
<PaneTabs
|
|
151
153
|
value={pane.pane}
|
|
152
154
|
options={pane.options}
|
|
153
155
|
onChange={pane.select}
|
|
156
|
+
className="mx-auto w-fit"
|
|
154
157
|
/>
|
|
155
158
|
</div>
|
|
156
159
|
}
|
|
@@ -27,9 +27,9 @@ export function ItemTagGroups({
|
|
|
27
27
|
return <EmptyState variant="empty">{t('No tags for this item.', { note: 'recipe.empty_tags' })}</EmptyState>;
|
|
28
28
|
}
|
|
29
29
|
return (
|
|
30
|
-
<div className="flex flex-col gap-3 pt-1">
|
|
30
|
+
<div className="flex flex-col items-center gap-3 pt-1">
|
|
31
31
|
{groups.map(([tagKind, ids]) => (
|
|
32
|
-
<div key={tagKind} className="flex flex-col gap-1.5">
|
|
32
|
+
<div key={tagKind} className="flex flex-col items-center gap-1.5">
|
|
33
33
|
{groups.length > 1 && (
|
|
34
34
|
<p className="text-xs font-medium text-muted-foreground">
|
|
35
35
|
{tagKind === 'block'
|
|
@@ -37,7 +37,7 @@ export function ItemTagGroups({
|
|
|
37
37
|
: t('Items', { note: 'recipe.tags_item' })}
|
|
38
38
|
</p>
|
|
39
39
|
)}
|
|
40
|
-
<div className="flex flex-wrap gap-1">
|
|
40
|
+
<div className="flex flex-wrap justify-center gap-1">
|
|
41
41
|
{ids.map((id) => {
|
|
42
42
|
const bare = id.replace(/^#+/, '');
|
|
43
43
|
return (
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
4
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
6
|
import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
|
|
6
7
|
import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
@@ -105,6 +106,22 @@ export function TypeView({ session }: { session: RecipeSession }) {
|
|
|
105
106
|
true,
|
|
106
107
|
);
|
|
107
108
|
|
|
109
|
+
const goCategory = (dir: -1 | 1) => {
|
|
110
|
+
const cur = nonEmptyIds.indexOf(shown ?? '');
|
|
111
|
+
const next =
|
|
112
|
+
nonEmptyIds[(cur + dir + nonEmptyIds.length) % nonEmptyIds.length];
|
|
113
|
+
if (!next || next === shown) return;
|
|
114
|
+
replaceUrlState(
|
|
115
|
+
recipeHref(dataset, resolved, {
|
|
116
|
+
...nav,
|
|
117
|
+
type: next,
|
|
118
|
+
id: undefined,
|
|
119
|
+
solo: undefined,
|
|
120
|
+
rpage: undefined,
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
108
125
|
const onSwipe = (dir: -1 | 1) => {
|
|
109
126
|
if (recipeId) {
|
|
110
127
|
const next = focusIndex + dir;
|
|
@@ -167,8 +184,30 @@ export function TypeView({ session }: { session: RecipeSession }) {
|
|
|
167
184
|
}}
|
|
168
185
|
/>
|
|
169
186
|
}
|
|
187
|
+
navPrev={
|
|
188
|
+
<PagerArrow
|
|
189
|
+
dir={-1}
|
|
190
|
+
label={t('Previous category', { note: 'recipe.axis.prev' })}
|
|
191
|
+
disabled={nonEmptyIds.length < 2}
|
|
192
|
+
onClick={() => goCategory(-1)}
|
|
193
|
+
/>
|
|
194
|
+
}
|
|
195
|
+
navNext={
|
|
196
|
+
<PagerArrow
|
|
197
|
+
dir={1}
|
|
198
|
+
label={t('Next category', { note: 'recipe.axis.next' })}
|
|
199
|
+
disabled={nonEmptyIds.length < 2}
|
|
200
|
+
onClick={() => goCategory(1)}
|
|
201
|
+
/>
|
|
202
|
+
}
|
|
203
|
+
onNavWheel={goCategory}
|
|
170
204
|
header={
|
|
171
|
-
<
|
|
205
|
+
<div className="flex min-w-0 justify-center">
|
|
206
|
+
<PlaceHeader
|
|
207
|
+
session={session}
|
|
208
|
+
overline={t('Categories', { note: 'recipe.axis_type' })}
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
172
211
|
}
|
|
173
212
|
rail={
|
|
174
213
|
<WorkstationRail
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { Check, CircleAlert, Share2, Trash2 } from 'lucide-react';
|
|
3
|
+
import { Check, CircleAlert, LoaderCircle, Share2, Trash2 } from 'lucide-react';
|
|
4
4
|
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
5
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
6
|
import { RecipeToolbar } from '@terrafirmagreg-team/recipe/components/views/browser/toolbar';
|
|
@@ -11,6 +11,7 @@ import { useFeatureFlags } from '@terrafirmagreg-team/kit/hooks/use-features';
|
|
|
11
11
|
export function CalcActions({
|
|
12
12
|
session,
|
|
13
13
|
shared,
|
|
14
|
+
sharing,
|
|
14
15
|
shareError,
|
|
15
16
|
shareFailed,
|
|
16
17
|
onShare,
|
|
@@ -19,6 +20,7 @@ export function CalcActions({
|
|
|
19
20
|
}: {
|
|
20
21
|
session: RecipeSession;
|
|
21
22
|
shared: boolean;
|
|
23
|
+
sharing?: boolean;
|
|
22
24
|
shareError?: boolean;
|
|
23
25
|
shareFailed?: boolean;
|
|
24
26
|
onShare: () => void;
|
|
@@ -41,7 +43,7 @@ export function CalcActions({
|
|
|
41
43
|
) : null}
|
|
42
44
|
<IconButton
|
|
43
45
|
overlay
|
|
44
|
-
disabled={flags?.share === false}
|
|
46
|
+
disabled={flags?.share === false || sharing}
|
|
45
47
|
className={shareError ? 'text-red-500' : undefined}
|
|
46
48
|
label={
|
|
47
49
|
shared
|
|
@@ -52,7 +54,9 @@ export function CalcActions({
|
|
|
52
54
|
}
|
|
53
55
|
onClick={onShare}
|
|
54
56
|
>
|
|
55
|
-
{
|
|
57
|
+
{sharing ? (
|
|
58
|
+
<LoaderCircle className="size-3.5 animate-spin" />
|
|
59
|
+
) : shared ? (
|
|
56
60
|
<Check className="size-3.5" />
|
|
57
61
|
) : shareError ? (
|
|
58
62
|
<CircleAlert className="size-3.5" />
|
|
@@ -56,14 +56,17 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
56
56
|
const { focusNodeRef, onFocusNode, focusNodeId, setFocusNodeId } =
|
|
57
57
|
useCalcFocus(cards);
|
|
58
58
|
const { resetGen } = useCalcReset(activeTabId);
|
|
59
|
-
const { displayCards, flushAmounts, onCrafts } =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const { displayCards, pendingCrafts, flushAmounts, onCrafts } =
|
|
60
|
+
useCalcAmounts({
|
|
61
|
+
cards,
|
|
62
|
+
wires,
|
|
63
|
+
tagSelections,
|
|
64
|
+
resolved: deferredNodes,
|
|
65
|
+
persist,
|
|
66
|
+
});
|
|
65
67
|
const {
|
|
66
68
|
shared,
|
|
69
|
+
sharing,
|
|
67
70
|
shareError,
|
|
68
71
|
onShare,
|
|
69
72
|
flowData,
|
|
@@ -101,8 +104,14 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
101
104
|
);
|
|
102
105
|
|
|
103
106
|
const data = useMemo(
|
|
104
|
-
() => ({
|
|
105
|
-
|
|
107
|
+
() => ({
|
|
108
|
+
...flowData,
|
|
109
|
+
onCrafts,
|
|
110
|
+
pendingCrafts,
|
|
111
|
+
getRecipesForItem,
|
|
112
|
+
ensureMaterial,
|
|
113
|
+
}),
|
|
114
|
+
[flowData, onCrafts, pendingCrafts, getRecipesForItem, ensureMaterial],
|
|
106
115
|
);
|
|
107
116
|
|
|
108
117
|
return (
|
|
@@ -150,6 +159,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
150
159
|
<CalcActions
|
|
151
160
|
session={session}
|
|
152
161
|
shared={shared}
|
|
162
|
+
sharing={sharing}
|
|
153
163
|
shareError={shareError}
|
|
154
164
|
shareFailed={shareFailed}
|
|
155
165
|
onShare={onShare}
|
|
@@ -73,7 +73,9 @@ function EdgeAmountLabel({ ctx }: { ctx: ChevronEdgePathContext }) {
|
|
|
73
73
|
? recipeItemName(session.names, session.lang, matId)
|
|
74
74
|
: matId;
|
|
75
75
|
const fmt =
|
|
76
|
-
matKind === 'fluid'
|
|
76
|
+
matKind === 'fluid'
|
|
77
|
+
? formatFluidAmount
|
|
78
|
+
: (n: number) => formatCount(n, 1_000);
|
|
77
79
|
return (
|
|
78
80
|
<button
|
|
79
81
|
type="button"
|
|
@@ -42,14 +42,23 @@ export function NodeBadges({
|
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
if (node.remaining < 0) {
|
|
45
|
+
const fmtAmount =
|
|
46
|
+
node.kind === 'fluid'
|
|
47
|
+
? formatFluidAmount
|
|
48
|
+
: (n: number) => formatCount(n, 1_000);
|
|
49
|
+
const overTip = t('Shortage: {wired} wired, only {produced} produced', {
|
|
50
|
+
note: 'recipe.calc.overdrawn',
|
|
51
|
+
})
|
|
52
|
+
.replaceAll('{wired}', fmtAmount(node.allocated))
|
|
53
|
+
.replaceAll('{produced}', fmtAmount(node.produced));
|
|
45
54
|
chips.push(
|
|
46
|
-
<Hint key="over" label={
|
|
55
|
+
<Hint key="over" label={overTip} side="top">
|
|
47
56
|
<span
|
|
48
57
|
className={cn(CORNER_CHIP, 'border-red-500/40 text-red-500')}
|
|
49
58
|
>
|
|
50
59
|
{node.kind === 'fluid'
|
|
51
60
|
? formatFluidAmount(node.remaining)
|
|
52
|
-
: formatCount(node.remaining)}
|
|
61
|
+
: formatCount(node.remaining, 1_000)}
|
|
53
62
|
</span>
|
|
54
63
|
</Hint>,
|
|
55
64
|
);
|
|
@@ -43,6 +43,17 @@ import { NodeActions } from './actions';
|
|
|
43
43
|
import { PortRailIn, PortRailOut } from './port-rails';
|
|
44
44
|
import { NodeContextMenu, NodeHoverContent } from './menu';
|
|
45
45
|
|
|
46
|
+
const CRAFTS_SUFFIX: Record<string, number> = { k: 1e3, m: 1e6, b: 1e9 };
|
|
47
|
+
|
|
48
|
+
function parseCraftsInput(raw: string): number | null {
|
|
49
|
+
const match = /^(\d+(?:\.\d+)?)\s*([kmb])?$/i.exec(raw.trim());
|
|
50
|
+
if (!match) return null;
|
|
51
|
+
const value = Math.round(
|
|
52
|
+
Number(match[1]) * (CRAFTS_SUFFIX[match[2]?.toLowerCase() ?? ''] ?? 1),
|
|
53
|
+
);
|
|
54
|
+
return Number.isFinite(value) ? Math.max(1, value) : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
46
57
|
export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
47
58
|
data,
|
|
48
59
|
id,
|
|
@@ -117,9 +128,12 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
|
117
128
|
[id],
|
|
118
129
|
);
|
|
119
130
|
|
|
131
|
+
const crafts = data.pendingCrafts?.get(id) ?? node.crafts;
|
|
120
132
|
const fmtAmount =
|
|
121
|
-
node.kind === 'fluid'
|
|
122
|
-
|
|
133
|
+
node.kind === 'fluid'
|
|
134
|
+
? formatFluidAmount
|
|
135
|
+
: (n: number) => formatCount(n, 1_000);
|
|
136
|
+
const producedTip = t('Surplus: {produced} produced, {allocated} wired, {remaining} left', {
|
|
123
137
|
note: 'recipe.calc.hint.produced',
|
|
124
138
|
})
|
|
125
139
|
.replaceAll('{produced}', fmtAmount(node.produced))
|
|
@@ -232,6 +246,24 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
|
232
246
|
<div className="mx-1 flex min-w-0 items-center gap-1">
|
|
233
247
|
{interactive ? (
|
|
234
248
|
<span className="nodrag ml-auto flex shrink-0 items-center gap-0.5">
|
|
249
|
+
{[2, 4].map((div) => (
|
|
250
|
+
<button
|
|
251
|
+
key={div}
|
|
252
|
+
type="button"
|
|
253
|
+
aria-label={
|
|
254
|
+
div === 2
|
|
255
|
+
? t('Halve crafts', { note: 'recipe.calc.crafts.d2' })
|
|
256
|
+
: t('Quarter crafts', { note: 'recipe.calc.crafts.d4' })
|
|
257
|
+
}
|
|
258
|
+
className="grid h-4 min-w-4 place-items-center rounded border border-border bg-background px-px text-[8px] font-medium leading-none text-muted-foreground hover:text-foreground"
|
|
259
|
+
onClick={(e) => {
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
onCrafts(id, (crafts) => Math.max(1, Math.round(crafts / div)));
|
|
262
|
+
}}
|
|
263
|
+
>
|
|
264
|
+
÷{div}
|
|
265
|
+
</button>
|
|
266
|
+
))}
|
|
235
267
|
<button
|
|
236
268
|
type="button"
|
|
237
269
|
aria-label={t('Fewer crafts', { note: 'recipe.calc.crafts.down' })}
|
|
@@ -244,22 +276,25 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
|
244
276
|
<Minus className="size-2.5" />
|
|
245
277
|
</button>
|
|
246
278
|
<input
|
|
247
|
-
key={
|
|
279
|
+
key={crafts}
|
|
248
280
|
type="text"
|
|
249
281
|
inputMode="numeric"
|
|
250
|
-
defaultValue={
|
|
251
|
-
|
|
282
|
+
defaultValue={crafts}
|
|
283
|
+
size={Math.min(9, Math.max(3, String(crafts).length))}
|
|
284
|
+
title={`${t('Crafts', { note: 'recipe.calc.crafts.title' })}: ${String(crafts)}`}
|
|
252
285
|
aria-label={t('Crafts', { note: 'recipe.calc.crafts.title' })}
|
|
253
|
-
className="w-9 rounded border border-
|
|
286
|
+
className="w-auto min-w-9 rounded border border-border bg-transparent text-center tabular-nums focus:outline-none"
|
|
254
287
|
onClick={(e) => e.stopPropagation()}
|
|
255
288
|
onKeyDown={(e) => {
|
|
256
289
|
if (e.key === 'Enter') e.currentTarget.blur();
|
|
257
290
|
}}
|
|
258
291
|
onBlur={(e) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
292
|
+
const value = parseCraftsInput(e.target.value);
|
|
293
|
+
if (value == null) {
|
|
294
|
+
e.target.value = String(crafts);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
onCrafts(id, value);
|
|
263
298
|
}}
|
|
264
299
|
/>
|
|
265
300
|
<button
|
|
@@ -273,6 +308,24 @@ export const CalcNodeCardFull = memo(function CalcNodeCardFull({
|
|
|
273
308
|
>
|
|
274
309
|
<Plus className="size-2.5" />
|
|
275
310
|
</button>
|
|
311
|
+
{[2, 4].map((mult) => (
|
|
312
|
+
<button
|
|
313
|
+
key={mult}
|
|
314
|
+
type="button"
|
|
315
|
+
aria-label={
|
|
316
|
+
mult === 2
|
|
317
|
+
? t('Double crafts', { note: 'recipe.calc.crafts.x2' })
|
|
318
|
+
: t('Quadruple crafts', { note: 'recipe.calc.crafts.x4' })
|
|
319
|
+
}
|
|
320
|
+
className="grid h-4 min-w-4 place-items-center rounded border border-border bg-background px-px text-[8px] font-medium leading-none text-muted-foreground hover:text-foreground"
|
|
321
|
+
onClick={(e) => {
|
|
322
|
+
e.stopPropagation();
|
|
323
|
+
onCrafts(id, (crafts) => crafts * mult);
|
|
324
|
+
}}
|
|
325
|
+
>
|
|
326
|
+
×{mult}
|
|
327
|
+
</button>
|
|
328
|
+
))}
|
|
276
329
|
</span>
|
|
277
330
|
) : null}
|
|
278
331
|
</div>
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
22
22
|
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
23
23
|
import { PortContextMenu } from './menu';
|
|
24
|
-
import {
|
|
24
|
+
import { PortCount, portAmountLine } from './ports';
|
|
25
25
|
|
|
26
26
|
interface CellProps {
|
|
27
27
|
index: number;
|
|
@@ -49,7 +49,6 @@ export function OutputCell({
|
|
|
49
49
|
}) {
|
|
50
50
|
const name = recipeItemName(names, lang, out.id);
|
|
51
51
|
const count = out.remaining;
|
|
52
|
-
const qty = formatPortCount(count, out.kind);
|
|
53
52
|
return (
|
|
54
53
|
<ContextMenu>
|
|
55
54
|
<ContextMenuTrigger
|
|
@@ -83,12 +82,13 @@ export function OutputCell({
|
|
|
83
82
|
dataset={dataset}
|
|
84
83
|
lang={lang}
|
|
85
84
|
langMap={langMap}
|
|
86
|
-
name={
|
|
85
|
+
name={name}
|
|
86
|
+
subheader={portAmountLine(count, out.kind)}
|
|
87
87
|
size="sm"
|
|
88
88
|
href={false}
|
|
89
89
|
tooltip="adaptive"
|
|
90
90
|
/>
|
|
91
|
-
<PortCount value={count} kind={out.kind} />
|
|
91
|
+
<PortCount value={count} kind={out.kind} name={name} />
|
|
92
92
|
</span>
|
|
93
93
|
</Handle>
|
|
94
94
|
}
|
|
@@ -123,7 +123,6 @@ export function InputCell({
|
|
|
123
123
|
const id = inp.id;
|
|
124
124
|
const name = id ? recipeItemName(names, lang, id) : (inp.tagId ?? '?');
|
|
125
125
|
const uncovered = Math.max(0, inp.amount - inp.covered);
|
|
126
|
-
const qty = formatPortCount(uncovered, inp.kind);
|
|
127
126
|
const state = inp.wired
|
|
128
127
|
? uncovered <= 0
|
|
129
128
|
? 'full'
|
|
@@ -160,7 +159,8 @@ export function InputCell({
|
|
|
160
159
|
dataset={dataset}
|
|
161
160
|
lang={lang}
|
|
162
161
|
langMap={langMap}
|
|
163
|
-
name={
|
|
162
|
+
name={name}
|
|
163
|
+
subheader={portAmountLine(uncovered, inp.kind)}
|
|
164
164
|
size="sm"
|
|
165
165
|
href={false}
|
|
166
166
|
tooltip="adaptive"
|
|
@@ -172,7 +172,8 @@ export function InputCell({
|
|
|
172
172
|
dataset={dataset}
|
|
173
173
|
lang={lang}
|
|
174
174
|
langMap={langMap}
|
|
175
|
-
name={
|
|
175
|
+
name={name}
|
|
176
|
+
subheader={portAmountLine(uncovered, inp.kind)}
|
|
176
177
|
size="sm"
|
|
177
178
|
href={false}
|
|
178
179
|
tooltip="adaptive"
|
|
@@ -180,7 +181,11 @@ export function InputCell({
|
|
|
180
181
|
) : (
|
|
181
182
|
<span className="text-[9px]">?</span>
|
|
182
183
|
)}
|
|
183
|
-
<PortCount
|
|
184
|
+
<PortCount
|
|
185
|
+
value={uncovered}
|
|
186
|
+
kind={inp.kind}
|
|
187
|
+
name={id || inp.tagId ? name : undefined}
|
|
188
|
+
/>
|
|
184
189
|
</span>
|
|
185
190
|
</Handle>
|
|
186
191
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
3
4
|
import { Handle, Position } from '@terrafirmagreg-team/ui/lib/canvas/xyflow';
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
formatCount,
|
|
7
|
+
formatFluidAmount,
|
|
8
|
+
} from '@terrafirmagreg-team/ui/lib/utils/format';
|
|
9
|
+
import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
|
|
5
10
|
import { PORT_OUT } from '@terrafirmagreg-team/recipe/lib/calc/ports';
|
|
6
11
|
import type {
|
|
7
12
|
CalcKind,
|
|
@@ -9,24 +14,45 @@ import type {
|
|
|
9
14
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
10
15
|
|
|
11
16
|
export function formatPortCount(value: number, kind: CalcKind): string {
|
|
12
|
-
if (kind === 'fluid')
|
|
13
|
-
if (Math.abs(value) >= 1_000)
|
|
14
|
-
return `${Math.round((value / 1000) * 100) / 100}`;
|
|
15
|
-
return `${Math.round(value)}`;
|
|
16
|
-
}
|
|
17
|
+
if (kind === 'fluid') return formatFluidAmount(value);
|
|
17
18
|
return formatCount(value, 1_000);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function
|
|
21
|
+
export function portAmountLine(value: number, kind: CalcKind): ReactNode {
|
|
22
|
+
return (
|
|
23
|
+
<p className="text-muted-foreground">
|
|
24
|
+
{value.toLocaleString('en-US')}
|
|
25
|
+
{kind === 'fluid' ? ' mB' : ''}
|
|
26
|
+
</p>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function PortCount({
|
|
31
|
+
value,
|
|
32
|
+
kind,
|
|
33
|
+
name,
|
|
34
|
+
}: {
|
|
35
|
+
value: number;
|
|
36
|
+
kind: CalcKind;
|
|
37
|
+
name?: string;
|
|
38
|
+
}) {
|
|
21
39
|
const text = formatPortCount(value, kind);
|
|
22
40
|
return (
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
<Hint
|
|
42
|
+
label={
|
|
43
|
+
<>
|
|
44
|
+
<p>{name}</p>
|
|
45
|
+
{portAmountLine(value, kind)}
|
|
46
|
+
</>
|
|
47
|
+
}
|
|
27
48
|
>
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
<span
|
|
50
|
+
className="calc-port-count"
|
|
51
|
+
data-len={text.length >= 5 ? 'xl' : text.length >= 4 ? 'l' : undefined}
|
|
52
|
+
>
|
|
53
|
+
{text}
|
|
54
|
+
</span>
|
|
55
|
+
</Hint>
|
|
30
56
|
);
|
|
31
57
|
}
|
|
32
58
|
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
DialogTitle,
|
|
11
11
|
} from '@terrafirmagreg-team/ui/components/ui/dialog';
|
|
12
12
|
import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
13
|
+
import { PagerArrow } from '@terrafirmagreg-team/ui/components/blocks/page/pager';
|
|
13
14
|
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
14
15
|
import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
|
|
15
16
|
import {
|
|
@@ -101,6 +102,14 @@ export function PickerBody({
|
|
|
101
102
|
setPinned(false);
|
|
102
103
|
setPage(next);
|
|
103
104
|
};
|
|
105
|
+
const goCategory = (dir: -1 | 1) => {
|
|
106
|
+
const cur = categories.indexOf(active ?? '');
|
|
107
|
+
const next =
|
|
108
|
+
categories[(cur + dir + categories.length) % categories.length];
|
|
109
|
+
if (!next || next === active) return;
|
|
110
|
+
setTab(next);
|
|
111
|
+
goPage(0);
|
|
112
|
+
};
|
|
104
113
|
const custom =
|
|
105
114
|
!!node.recipe &&
|
|
106
115
|
node.recipe.recipeId !== (defaultRecipeId ?? recipes[0]?.recipeId);
|
|
@@ -163,7 +172,31 @@ export function PickerBody({
|
|
|
163
172
|
}}
|
|
164
173
|
/>
|
|
165
174
|
}
|
|
166
|
-
|
|
175
|
+
navPrev={
|
|
176
|
+
<PagerArrow
|
|
177
|
+
dir={-1}
|
|
178
|
+
label={t('Previous category', { note: 'recipe.axis.prev' })}
|
|
179
|
+
disabled={categories.length < 2}
|
|
180
|
+
onClick={() => goCategory(-1)}
|
|
181
|
+
/>
|
|
182
|
+
}
|
|
183
|
+
navNext={
|
|
184
|
+
<PagerArrow
|
|
185
|
+
dir={1}
|
|
186
|
+
label={t('Next category', { note: 'recipe.axis.next' })}
|
|
187
|
+
disabled={categories.length < 2}
|
|
188
|
+
onClick={() => goCategory(1)}
|
|
189
|
+
/>
|
|
190
|
+
}
|
|
191
|
+
onNavWheel={goCategory}
|
|
192
|
+
header={
|
|
193
|
+
<div className="flex min-w-0 justify-center">
|
|
194
|
+
<PlaceHeader
|
|
195
|
+
session={frameSession}
|
|
196
|
+
overline={t('Categories', { note: 'recipe.axis_type' })}
|
|
197
|
+
/>
|
|
198
|
+
</div>
|
|
199
|
+
}
|
|
167
200
|
rail={
|
|
168
201
|
<WorkstationRail
|
|
169
202
|
session={session}
|
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
LeftSidebarTree,
|
|
12
12
|
} from '@terrafirmagreg-team/ui/components/layouts/left-sidebar';
|
|
13
13
|
import { recipeStackHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
formatCount,
|
|
16
|
+
formatFluidAmount,
|
|
17
|
+
} from '@terrafirmagreg-team/ui/lib/utils/format';
|
|
15
18
|
import { CalcTrees } from '@terrafirmagreg-team/recipe/components/views/calc/trees';
|
|
16
19
|
import type { CalcMaterial } from '@terrafirmagreg-team/recipe/types/calc';
|
|
17
20
|
import type { CalcTreeEntry } from '@terrafirmagreg-team/recipe/lib/calc/storage';
|
|
@@ -109,7 +112,10 @@ export function CalcSidebar({
|
|
|
109
112
|
className="ms-auto shrink-0 tabular-nums text-xs text-muted-foreground"
|
|
110
113
|
title={row.amount.toLocaleString()}
|
|
111
114
|
>
|
|
112
|
-
×
|
|
115
|
+
×
|
|
116
|
+
{row.kind === 'fluid'
|
|
117
|
+
? formatFluidAmount(row.amount)
|
|
118
|
+
: formatCount(row.amount, 1_000)}
|
|
113
119
|
</span>
|
|
114
120
|
</>
|
|
115
121
|
),
|
|
@@ -86,6 +86,7 @@ export function useCalcActions({
|
|
|
86
86
|
}) {
|
|
87
87
|
const {
|
|
88
88
|
checked: shared,
|
|
89
|
+
isLoading: sharing,
|
|
89
90
|
error: shareError,
|
|
90
91
|
onClick: onShare,
|
|
91
92
|
} = useCopyButton(async () => {
|
|
@@ -513,6 +514,7 @@ export function useCalcActions({
|
|
|
513
514
|
|
|
514
515
|
return {
|
|
515
516
|
shared,
|
|
517
|
+
sharing,
|
|
516
518
|
shareError,
|
|
517
519
|
onShare,
|
|
518
520
|
flowData,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import type {
|
|
5
5
|
CalcCard,
|
|
6
|
+
CalcNode,
|
|
6
7
|
CalcWire,
|
|
7
8
|
CalculatorState,
|
|
8
9
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
@@ -11,11 +12,13 @@ export function useCalcAmounts({
|
|
|
11
12
|
cards,
|
|
12
13
|
wires,
|
|
13
14
|
tagSelections,
|
|
15
|
+
resolved,
|
|
14
16
|
persist,
|
|
15
17
|
}: {
|
|
16
18
|
cards: CalcCard[];
|
|
17
19
|
wires: CalcWire[];
|
|
18
20
|
tagSelections: Record<string, string>;
|
|
21
|
+
resolved: CalcNode[];
|
|
19
22
|
persist: (next: CalculatorState) => void;
|
|
20
23
|
}) {
|
|
21
24
|
const [pending, setPending] = useState<CalcCard[] | null>(null);
|
|
@@ -28,13 +31,21 @@ export function useCalcAmounts({
|
|
|
28
31
|
[],
|
|
29
32
|
);
|
|
30
33
|
|
|
34
|
+
if (pending) {
|
|
35
|
+
const settled = pending.every(
|
|
36
|
+
(card) =>
|
|
37
|
+
(resolved.find((node) => node.id === card.id)?.crafts ??
|
|
38
|
+
card.crafts) === card.crafts,
|
|
39
|
+
);
|
|
40
|
+
if (settled) setPending(null);
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
const flushAmounts = useCallback((): CalcCard[] => {
|
|
32
44
|
if (amountTimer.current) {
|
|
33
45
|
clearTimeout(amountTimer.current);
|
|
34
46
|
amountTimer.current = undefined;
|
|
35
47
|
}
|
|
36
48
|
if (!pending) return cards;
|
|
37
|
-
setPending(null);
|
|
38
49
|
return pending;
|
|
39
50
|
}, [pending, cards]);
|
|
40
51
|
|
|
@@ -56,15 +67,23 @@ export function useCalcAmounts({
|
|
|
56
67
|
if (amountTimer.current) clearTimeout(amountTimer.current);
|
|
57
68
|
amountTimer.current = setTimeout(() => {
|
|
58
69
|
amountTimer.current = undefined;
|
|
59
|
-
setPending(null);
|
|
60
70
|
persist({ cards: next, wires, tagSelections });
|
|
61
71
|
}, 300);
|
|
62
72
|
},
|
|
63
73
|
[pending, cards, persist, wires, tagSelections],
|
|
64
74
|
);
|
|
65
75
|
|
|
76
|
+
const pendingCrafts = useMemo(
|
|
77
|
+
() =>
|
|
78
|
+
pending
|
|
79
|
+
? new Map(pending.map((card) => [card.id, card.crafts]))
|
|
80
|
+
: null,
|
|
81
|
+
[pending],
|
|
82
|
+
);
|
|
83
|
+
|
|
66
84
|
return {
|
|
67
85
|
displayCards: pending ?? cards,
|
|
86
|
+
pendingCrafts,
|
|
68
87
|
flushAmounts,
|
|
69
88
|
onCrafts,
|
|
70
89
|
};
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type CalcTreeEntry,
|
|
19
19
|
} from '@terrafirmagreg-team/recipe/lib/calc/storage';
|
|
20
20
|
import type { CalculatorState } from '@terrafirmagreg-team/recipe/types/calc';
|
|
21
|
+
import { stripMcFormat } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
21
22
|
|
|
22
23
|
const EMPTY_TABS: CalcTreeEntry[] = [];
|
|
23
24
|
const EMPTY_CALC: CalculatorState = {
|
|
@@ -97,7 +98,7 @@ export function useCalcStorage(storageKey: string) {
|
|
|
97
98
|
(id: string, name: string) => {
|
|
98
99
|
updateCalcTab(storageKey, id, (tab) => ({
|
|
99
100
|
...tab,
|
|
100
|
-
name: name.trim() || undefined,
|
|
101
|
+
name: stripMcFormat(name).trim() || undefined,
|
|
101
102
|
}));
|
|
102
103
|
},
|
|
103
104
|
[storageKey],
|
package/src/lib/calc/flow.ts
CHANGED
|
@@ -71,6 +71,7 @@ export type CalcFlowData = {
|
|
|
71
71
|
cardId: string,
|
|
72
72
|
crafts: number | ((current: number) => number),
|
|
73
73
|
) => void;
|
|
74
|
+
pendingCrafts?: Map<string, number> | null;
|
|
74
75
|
onWire: (from: string, to: string, input: number, out?: number) => void;
|
|
75
76
|
onUnwire: (
|
|
76
77
|
from: string,
|
|
@@ -240,6 +241,7 @@ function sameFlowData(a: CalcFlowData, b: CalcFlowData): boolean {
|
|
|
240
241
|
a.onRemoveCard === b.onRemoveCard &&
|
|
241
242
|
a.onMoveCard === b.onMoveCard &&
|
|
242
243
|
a.onCrafts === b.onCrafts &&
|
|
244
|
+
a.pendingCrafts === b.pendingCrafts &&
|
|
243
245
|
a.onWire === b.onWire &&
|
|
244
246
|
a.onUnwire === b.onUnwire &&
|
|
245
247
|
a.onRewire === b.onRewire &&
|