@terrafirmagreg-team/recipe 1.2.37 → 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/card-grid.tsx +2 -1
- 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 +34 -5
- package/src/components/views/calc/calculator/index.tsx +22 -8
- package/src/components/views/calc/edge.tsx +11 -4
- package/src/components/views/calc/node-card/badges.tsx +17 -3
- package/src/components/views/calc/node-card/full.tsx +117 -37
- package/src/components/views/calc/node-card/menu.tsx +12 -1
- 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/components/views/calc/trees/label.tsx +9 -5
- package/src/hooks/calc/use-actions.ts +26 -3
- package/src/hooks/calc/use-amounts.ts +32 -5
- package/src/hooks/calc/use-data.ts +2 -1
- package/src/hooks/calc/use-share.ts +15 -8
- package/src/hooks/calc/use-storage.ts +2 -1
- package/src/lib/calc/flow.ts +6 -1
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>
|
|
@@ -155,7 +155,8 @@ function RecipeGridCard({
|
|
|
155
155
|
}}
|
|
156
156
|
aria-current={focused || undefined}
|
|
157
157
|
className={cn(
|
|
158
|
-
'relative w-fit flex-none rounded-md',
|
|
158
|
+
'relative w-fit flex-none cursor-pointer rounded-md transition-shadow',
|
|
159
|
+
'hover:ring-1 hover:ring-foreground/50',
|
|
159
160
|
focused && 'ring-2 ring-primary ring-offset-1',
|
|
160
161
|
)}
|
|
161
162
|
style={fit < 1 ? { zoom: fit } : undefined}
|
|
@@ -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 { 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,12 +11,18 @@ import { useFeatureFlags } from '@terrafirmagreg-team/kit/hooks/use-features';
|
|
|
11
11
|
export function CalcActions({
|
|
12
12
|
session,
|
|
13
13
|
shared,
|
|
14
|
+
sharing,
|
|
15
|
+
shareError,
|
|
16
|
+
shareFailed,
|
|
14
17
|
onShare,
|
|
15
18
|
hasTargets,
|
|
16
19
|
onClear,
|
|
17
20
|
}: {
|
|
18
21
|
session: RecipeSession;
|
|
19
22
|
shared: boolean;
|
|
23
|
+
sharing?: boolean;
|
|
24
|
+
shareError?: boolean;
|
|
25
|
+
shareFailed?: boolean;
|
|
20
26
|
onShare: () => void;
|
|
21
27
|
hasTargets: boolean;
|
|
22
28
|
onClear: () => void;
|
|
@@ -26,13 +32,37 @@ export function CalcActions({
|
|
|
26
32
|
return (
|
|
27
33
|
<>
|
|
28
34
|
<RecipeToolbar session={session} />
|
|
35
|
+
{shareFailed ? (
|
|
36
|
+
<IconButton
|
|
37
|
+
overlay
|
|
38
|
+
className="text-red-500"
|
|
39
|
+
label={t('Shared scheme failed to load', { note: 'recipe.calc.share_failed' })}
|
|
40
|
+
>
|
|
41
|
+
<CircleAlert className="size-3.5" />
|
|
42
|
+
</IconButton>
|
|
43
|
+
) : null}
|
|
29
44
|
<IconButton
|
|
30
45
|
overlay
|
|
31
|
-
disabled={flags?.share === false}
|
|
32
|
-
|
|
46
|
+
disabled={flags?.share === false || sharing}
|
|
47
|
+
className={shareError ? 'text-red-500' : undefined}
|
|
48
|
+
label={
|
|
49
|
+
shared
|
|
50
|
+
? t('Copied', { note: 'recipe.copied' })
|
|
51
|
+
: shareError
|
|
52
|
+
? t('Copy failed', { note: 'recipe.calc.copy_failed' })
|
|
53
|
+
: t('Share', { note: 'recipe.calc.share' })
|
|
54
|
+
}
|
|
33
55
|
onClick={onShare}
|
|
34
56
|
>
|
|
35
|
-
|
|
57
|
+
{sharing ? (
|
|
58
|
+
<LoaderCircle className="size-3.5 animate-spin" />
|
|
59
|
+
) : shared ? (
|
|
60
|
+
<Check className="size-3.5" />
|
|
61
|
+
) : shareError ? (
|
|
62
|
+
<CircleAlert className="size-3.5" />
|
|
63
|
+
) : (
|
|
64
|
+
<Share2 className="size-3.5" />
|
|
65
|
+
)}
|
|
36
66
|
</IconButton>
|
|
37
67
|
<CalcHelp />
|
|
38
68
|
{hasTargets ? (
|
|
@@ -47,4 +77,3 @@ export function CalcActions({
|
|
|
47
77
|
</>
|
|
48
78
|
);
|
|
49
79
|
}
|
|
50
|
-
|
|
@@ -48,6 +48,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
48
48
|
encodeShare,
|
|
49
49
|
recipeBody,
|
|
50
50
|
settled,
|
|
51
|
+
shareFailed,
|
|
51
52
|
} = useCalcData(session);
|
|
52
53
|
const deferredNodes = useDeferredValue(nodes);
|
|
53
54
|
const deferredFlows = useDeferredValue(flows);
|
|
@@ -55,14 +56,18 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
55
56
|
const { focusNodeRef, onFocusNode, focusNodeId, setFocusNodeId } =
|
|
56
57
|
useCalcFocus(cards);
|
|
57
58
|
const { resetGen } = useCalcReset(activeTabId);
|
|
58
|
-
const { displayCards, flushAmounts, onCrafts } =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const { displayCards, pendingCrafts, flushAmounts, onCrafts } =
|
|
60
|
+
useCalcAmounts({
|
|
61
|
+
cards,
|
|
62
|
+
wires,
|
|
63
|
+
tagSelections,
|
|
64
|
+
resolved: deferredNodes,
|
|
65
|
+
persist,
|
|
66
|
+
});
|
|
64
67
|
const {
|
|
65
68
|
shared,
|
|
69
|
+
sharing,
|
|
70
|
+
shareError,
|
|
66
71
|
onShare,
|
|
67
72
|
flowData,
|
|
68
73
|
onMoveCards,
|
|
@@ -99,8 +104,14 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
99
104
|
);
|
|
100
105
|
|
|
101
106
|
const data = useMemo(
|
|
102
|
-
() => ({
|
|
103
|
-
|
|
107
|
+
() => ({
|
|
108
|
+
...flowData,
|
|
109
|
+
onCrafts,
|
|
110
|
+
pendingCrafts,
|
|
111
|
+
getRecipesForItem,
|
|
112
|
+
ensureMaterial,
|
|
113
|
+
}),
|
|
114
|
+
[flowData, onCrafts, pendingCrafts, getRecipesForItem, ensureMaterial],
|
|
104
115
|
);
|
|
105
116
|
|
|
106
117
|
return (
|
|
@@ -148,6 +159,9 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
148
159
|
<CalcActions
|
|
149
160
|
session={session}
|
|
150
161
|
shared={shared}
|
|
162
|
+
sharing={sharing}
|
|
163
|
+
shareError={shareError}
|
|
164
|
+
shareFailed={shareFailed}
|
|
151
165
|
onShare={onShare}
|
|
152
166
|
hasTargets={displayCards.length > 0}
|
|
153
167
|
onClear={onClear}
|
|
@@ -14,7 +14,10 @@ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
|
14
14
|
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
15
15
|
import { useCalcSession } from '@terrafirmagreg-team/recipe/hooks/calc/use-calc-session';
|
|
16
16
|
import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
formatCount,
|
|
19
|
+
formatFluidAmount,
|
|
20
|
+
} from '@terrafirmagreg-team/ui/lib/utils/format';
|
|
18
21
|
import type { FlowPoint } from '@terrafirmagreg-team/ui/types/canvas';
|
|
19
22
|
import type { CalcWire } from '@terrafirmagreg-team/recipe/types/calc';
|
|
20
23
|
|
|
@@ -69,11 +72,15 @@ function EdgeAmountLabel({ ctx }: { ctx: ChevronEdgePathContext }) {
|
|
|
69
72
|
matId && session?.names
|
|
70
73
|
? recipeItemName(session.names, session.lang, matId)
|
|
71
74
|
: matId;
|
|
75
|
+
const fmt =
|
|
76
|
+
matKind === 'fluid'
|
|
77
|
+
? formatFluidAmount
|
|
78
|
+
: (n: number) => formatCount(n, 1_000);
|
|
72
79
|
return (
|
|
73
80
|
<button
|
|
74
81
|
type="button"
|
|
75
82
|
className="calc-edge-label"
|
|
76
|
-
title={`${matName ?? ''} ${flow}${cap != null ? ` / ${cap}` : ''}`}
|
|
83
|
+
title={`${matName ?? ''} ${fmt(flow)}${cap != null ? ` / ${fmt(cap)}` : ''}`}
|
|
77
84
|
onClick={(e) => {
|
|
78
85
|
e.stopPropagation();
|
|
79
86
|
if (e.shiftKey) {
|
|
@@ -97,8 +104,8 @@ function EdgeAmountLabel({ ctx }: { ctx: ChevronEdgePathContext }) {
|
|
|
97
104
|
<span className="calc-edge-label__name">{matName}</span>
|
|
98
105
|
) : null}
|
|
99
106
|
<span className="calc-edge-label__amount">
|
|
100
|
-
×{
|
|
101
|
-
{cap != null ? `/${
|
|
107
|
+
×{fmt(flow)}
|
|
108
|
+
{cap != null ? `/${fmt(cap)}` : ''}
|
|
102
109
|
</span>
|
|
103
110
|
<span className="calc-edge-label__cut" aria-hidden>
|
|
104
111
|
×
|
|
@@ -5,7 +5,10 @@ import { Mountain, Repeat } from 'lucide-react';
|
|
|
5
5
|
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
6
|
import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
|
|
7
7
|
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
formatCount,
|
|
10
|
+
formatFluidAmount,
|
|
11
|
+
} from '@terrafirmagreg-team/ui/lib/utils/format';
|
|
9
12
|
import type { CalcFlowNode } from '@terrafirmagreg-team/recipe/lib/calc/flow';
|
|
10
13
|
|
|
11
14
|
const CORNER_CHIP =
|
|
@@ -39,12 +42,23 @@ export function NodeBadges({
|
|
|
39
42
|
);
|
|
40
43
|
}
|
|
41
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));
|
|
42
54
|
chips.push(
|
|
43
|
-
<Hint key="over" label={
|
|
55
|
+
<Hint key="over" label={overTip} side="top">
|
|
44
56
|
<span
|
|
45
57
|
className={cn(CORNER_CHIP, 'border-red-500/40 text-red-500')}
|
|
46
58
|
>
|
|
47
|
-
{
|
|
59
|
+
{node.kind === 'fluid'
|
|
60
|
+
? formatFluidAmount(node.remaining)
|
|
61
|
+
: formatCount(node.remaining, 1_000)}
|
|
48
62
|
</span>
|
|
49
63
|
</Hint>,
|
|
50
64
|
);
|