@terrafirmagreg-team/recipe 0.0.0-stage → 0.1.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 +62 -3
- package/src/components/button-copy.tsx +42 -0
- package/src/components/cards/card/index.tsx +212 -0
- package/src/components/cards/card/model.ts +64 -0
- package/src/components/cards/card/scene.tsx +105 -0
- package/src/components/cards/card/strip.tsx +196 -0
- package/src/components/cards/card/text.tsx +45 -0
- package/src/components/cards/card/tips.tsx +62 -0
- package/src/components/cards/default-item.tsx +43 -0
- package/src/components/cards/fit-card.tsx +26 -0
- package/src/components/cards/glare-filter.tsx +28 -0
- package/src/components/cards/paged-card.tsx +221 -0
- package/src/components/cards/slot-hitbox.tsx +211 -0
- package/src/components/cards/strip-card/buttons.tsx +101 -0
- package/src/components/cards/strip-card/index.tsx +212 -0
- package/src/components/cards/strip-card/member-cell.tsx +165 -0
- package/src/components/cards/strip-card/sprite.tsx +35 -0
- package/src/components/mdx/recipe.tsx +111 -0
- package/src/components/tool-list.tsx +48 -0
- package/src/components/views/alloy/index.tsx +105 -0
- package/src/components/views/alloy/list.tsx +84 -0
- package/src/components/views/alloy/mix/index.tsx +34 -0
- package/src/components/views/alloy/mix/ratio.tsx +93 -0
- package/src/components/views/alloy/mix/rows.tsx +146 -0
- package/src/components/views/alloy/mix/status.tsx +121 -0
- package/src/components/views/alloy/mix/total.tsx +131 -0
- package/src/components/views/alloy/range-bar.tsx +64 -0
- package/src/components/views/alloy/stack-bar.tsx +86 -0
- package/src/components/views/browser/axis-switcher.tsx +53 -0
- package/src/components/views/browser/card-grid.tsx +274 -0
- package/src/components/views/browser/favorite-button.tsx +45 -0
- package/src/components/views/browser/frame.tsx +111 -0
- package/src/components/views/browser/index.tsx +96 -0
- package/src/components/views/browser/item-panel/index.tsx +227 -0
- package/src/components/views/browser/item-panel/skeleton.tsx +25 -0
- package/src/components/views/browser/item-panel-grid/cell.tsx +176 -0
- package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +127 -0
- package/src/components/views/browser/item-panel-grid/index.tsx +103 -0
- package/src/components/views/browser/item-view/index.tsx +191 -0
- package/src/components/views/browser/item-view/tags.tsx +83 -0
- package/src/components/views/browser/item-view-header.tsx +130 -0
- package/src/components/views/browser/pane-tabs.tsx +60 -0
- package/src/components/views/browser/place-header.tsx +71 -0
- package/src/components/views/browser/query-controls.tsx +103 -0
- package/src/components/views/browser/recipe-item-header.tsx +59 -0
- package/src/components/views/browser/settings.tsx +51 -0
- package/src/components/views/browser/toolbar.tsx +53 -0
- package/src/components/views/browser/type-tabs.tsx +69 -0
- package/src/components/views/browser/type-view.tsx +189 -0
- package/src/components/views/browser/workstation-rail.tsx +42 -0
- package/src/components/views/calc/calculator/actions.tsx +57 -0
- package/src/components/views/calc/calculator/help.tsx +148 -0
- package/src/components/views/calc/calculator/index.tsx +220 -0
- package/src/components/views/calc/dot-overlay.tsx +79 -0
- package/src/components/views/calc/edge.tsx +50 -0
- package/src/components/views/calc/flow/index.tsx +267 -0
- package/src/components/views/calc/flow/picker-dialogs.tsx +68 -0
- package/src/components/views/calc/flow/toolbar.tsx +72 -0
- package/src/components/views/calc/flow/view-menu.tsx +221 -0
- package/src/components/views/calc/member-picker.tsx +118 -0
- package/src/components/views/calc/node-card/actions.tsx +168 -0
- package/src/components/views/calc/node-card/badges.tsx +77 -0
- package/src/components/views/calc/node-card/chips.tsx +219 -0
- package/src/components/views/calc/node-card/far.tsx +175 -0
- package/src/components/views/calc/node-card/full.tsx +282 -0
- package/src/components/views/calc/node-card/index.tsx +26 -0
- package/src/components/views/calc/node-card/menu.tsx +211 -0
- package/src/components/views/calc/recipe-picker/body.tsx +204 -0
- package/src/components/views/calc/recipe-picker/footer.tsx +129 -0
- package/src/components/views/calc/recipe-picker/index.tsx +47 -0
- package/src/components/views/calc/sidebar.tsx +162 -0
- package/src/components/views/calc/target.tsx +271 -0
- package/src/components/views/calc/trees/icon-picker.tsx +96 -0
- package/src/components/views/calc/trees/index.tsx +133 -0
- package/src/components/views/calc/trees/label.tsx +65 -0
- package/src/components/views/calc/trees/rows.tsx +139 -0
- package/src/components/views/forge/gui.tsx +130 -0
- package/src/components/views/forge/index.tsx +105 -0
- package/src/components/views/forge/list.tsx +112 -0
- package/src/components/views/forge/workbench/controls.tsx +96 -0
- package/src/components/views/forge/workbench/index.tsx +84 -0
- package/src/components/views/forge/workbench/panel.tsx +227 -0
- package/src/components/views/forge/workbench/ruler.tsx +132 -0
- package/src/components/views/forge/workbench/status.tsx +54 -0
- package/src/components/views/forge/workbench/tape.tsx +69 -0
- package/src/hooks/alloy/use-fluid-colors.ts +122 -0
- package/src/hooks/alloy/use-mix-state.ts +239 -0
- package/src/hooks/calc/flow/engage.ts +89 -0
- package/src/hooks/calc/flow/handlers.ts +115 -0
- package/src/hooks/calc/flow/layout.ts +149 -0
- package/src/hooks/calc/flow/mount.ts +96 -0
- package/src/hooks/calc/flow/nodes.ts +251 -0
- package/src/hooks/calc/flow/pickers.ts +50 -0
- package/src/hooks/calc/flow/props.ts +40 -0
- package/src/hooks/calc/flow/viewport.ts +154 -0
- package/src/hooks/calc/flow/window.ts +86 -0
- package/src/hooks/calc/use-actions.ts +376 -0
- package/src/hooks/calc/use-amounts.ts +101 -0
- package/src/hooks/calc/use-calc-fill.ts +91 -0
- package/src/hooks/calc/use-data.ts +289 -0
- package/src/hooks/calc/use-defaults.ts +38 -0
- package/src/hooks/calc/use-density.ts +28 -0
- package/src/hooks/calc/use-derived.ts +258 -0
- package/src/hooks/calc/use-direction.ts +23 -0
- package/src/hooks/calc/use-edge-style.ts +40 -0
- package/src/hooks/calc/use-far-mode.ts +36 -0
- package/src/hooks/calc/use-fill.ts +213 -0
- package/src/hooks/calc/use-focus.ts +30 -0
- package/src/hooks/calc/use-maps.ts +75 -0
- package/src/hooks/calc/use-reset.ts +14 -0
- package/src/hooks/calc/use-resolver.ts +234 -0
- package/src/hooks/calc/use-session.ts +12 -0
- package/src/hooks/calc/use-share.ts +61 -0
- package/src/hooks/calc/use-storage.ts +125 -0
- package/src/hooks/calc/use-tier.ts +12 -0
- package/src/hooks/calc/use-view-mode.ts +23 -0
- package/src/hooks/calc/use-worker.ts +269 -0
- package/src/hooks/forge/use-anvil-gui.ts +14 -0
- package/src/hooks/forge/use-forge-state.ts +134 -0
- package/src/hooks/forge/use-ruler.ts +99 -0
- package/src/hooks/use-add-to-calc.ts +47 -0
- package/src/hooks/use-favorite-hotkey.ts +38 -0
- package/src/hooks/use-favorites.ts +134 -0
- package/src/hooks/use-group-outlines.ts +64 -0
- package/src/hooks/use-hide-unused.ts +11 -0
- package/src/hooks/use-index.ts +68 -0
- package/src/hooks/use-item-feeds.ts +44 -0
- package/src/hooks/use-item-pane.ts +104 -0
- package/src/hooks/use-item-press.ts +85 -0
- package/src/hooks/use-item-tag-groups.ts +52 -0
- package/src/hooks/use-item-tooltips.ts +16 -0
- package/src/hooks/use-left-sidebar-tree.ts +26 -0
- package/src/hooks/use-mod-names.ts +15 -0
- package/src/hooks/use-mount-limit.ts +21 -0
- package/src/hooks/use-panel-cells.ts +115 -0
- package/src/hooks/use-panel-page.ts +51 -0
- package/src/hooks/use-panel-tabs.ts +42 -0
- package/src/hooks/use-query.ts +184 -0
- package/src/hooks/use-session.ts +84 -0
- package/src/hooks/use-sidebar-group.ts +20 -0
- package/src/hooks/use-tag-members.ts +14 -0
- package/src/hooks/use-tool-recipes.ts +25 -0
- package/src/hooks/use-type-filter.ts +72 -0
- package/src/lib/alloy/alloy.test.ts +186 -0
- package/src/lib/alloy/mix.ts +209 -0
- package/src/lib/alloy/parse.ts +36 -0
- package/src/lib/calc/defaults.ts +45 -0
- package/src/lib/calc/flow.ts +279 -0
- package/src/lib/calc/focus.ts +14 -0
- package/src/lib/calc/meta.ts +15 -0
- package/src/lib/calc/pack.ts +184 -0
- package/src/lib/calc/resolve.ts +230 -0
- package/src/lib/calc/route/buckets.ts +48 -0
- package/src/lib/calc/route/geometry.ts +62 -0
- package/src/lib/calc/route/index.ts +2 -0
- package/src/lib/calc/route/polyline.ts +103 -0
- package/src/lib/calc/route/router.ts +270 -0
- package/src/lib/calc/storage/entry.ts +89 -0
- package/src/lib/calc/storage/index.ts +18 -0
- package/src/lib/calc/storage/keys.ts +42 -0
- package/src/lib/calc/storage/store.ts +223 -0
- package/src/lib/calc/tree/build.ts +196 -0
- package/src/lib/calc/tree/context.ts +42 -0
- package/src/lib/calc/tree/goal.ts +64 -0
- package/src/lib/calc/tree/ideal.ts +36 -0
- package/src/lib/calc/tree/index.ts +18 -0
- package/src/lib/calc/tree/materials.ts +28 -0
- package/src/lib/calc/tree/pick.ts +68 -0
- package/src/lib/calc/tree/recipe.ts +103 -0
- package/src/lib/calc/tree/share.ts +198 -0
- package/src/lib/calc/tree/tree.test.ts +169 -0
- package/src/lib/calc/worker/api.ts +33 -0
- package/src/lib/calc/worker/fetch.ts +65 -0
- package/src/lib/calc/worker/fill.ts +123 -0
- package/src/lib/calc/worker/flush.ts +52 -0
- package/src/lib/calc/worker/index.ts +8 -0
- package/src/lib/calc/worker/protocol.ts +32 -0
- package/src/lib/calc/worker/resolve.ts +101 -0
- package/src/lib/calc/worker/state.ts +49 -0
- package/src/lib/client/recipe-categories.ts +96 -0
- package/src/lib/client/recipe.ts +83 -0
- package/src/lib/client-index/cache.ts +13 -0
- package/src/lib/client-index/catalog.ts +85 -0
- package/src/lib/client-index/chrome.ts +180 -0
- package/src/lib/client-index/index.ts +19 -0
- package/src/lib/client-index/registry.ts +110 -0
- package/src/lib/client-index/rows.ts +254 -0
- package/src/lib/client-index/tooltips.ts +80 -0
- package/src/lib/config.ts +17 -0
- package/src/lib/data/category/dto.ts +24 -0
- package/src/lib/data/category/load.ts +46 -0
- package/src/lib/data/category/parse.ts +70 -0
- package/src/lib/data/dto.ts +151 -0
- package/src/lib/data/grid.ts +39 -0
- package/src/lib/data/parse/entry.ts +84 -0
- package/src/lib/data/parse/index.ts +2 -0
- package/src/lib/data/parse/layout.ts +135 -0
- package/src/lib/data/parse/slots.ts +84 -0
- package/src/lib/data/parse/widgets.ts +80 -0
- package/src/lib/data/scene.ts +103 -0
- package/src/lib/data/slot-io.ts +43 -0
- package/src/lib/dump.ts +5 -0
- package/src/lib/favorite-hover.ts +12 -0
- package/src/lib/fluid-outputs.ts +72 -0
- package/src/lib/forge/actions.ts +58 -0
- package/src/lib/forge/data.ts +50 -0
- package/src/lib/forge/forge.test.ts +123 -0
- package/src/lib/forge/solve.ts +79 -0
- package/src/lib/group.ts +22 -0
- package/src/lib/index-store.ts +64 -0
- package/src/lib/links.ts +125 -0
- package/src/lib/lookup.ts +117 -0
- package/src/lib/panel-outline.ts +85 -0
- package/src/lib/panel.ts +104 -0
- package/src/lib/preview.ts +28 -0
- package/src/lib/recipe-slots.ts +7 -0
- package/src/lib/search.ts +138 -0
- package/src/lib/sidebar.ts +46 -0
- package/src/lib/tree.ts +90 -0
- package/src/lib/used-items.ts +24 -0
- package/src/locales/en_us.json +228 -0
- package/src/locales/ru_ru.json +228 -0
- package/src/locales.ts +5 -0
- package/src/types/alloy.ts +19 -0
- package/src/types/calc.ts +95 -0
- package/src/types/forge.ts +20 -0
- package/src/types/index.ts +134 -0
- package/styles/calc.css +47 -0
- package/styles/strip.css +7 -0
- package/styles.css +2 -0
- package/README.md +0 -3
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
4
|
+
import { Input } from '@terrafirmagreg-team/ui/components/ui/input';
|
|
5
|
+
import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
6
|
+
import {
|
|
7
|
+
ToggleGroup,
|
|
8
|
+
ToggleGroupItem,
|
|
9
|
+
} from '@terrafirmagreg-team/ui/components/ui/toggle-group';
|
|
10
|
+
import {
|
|
11
|
+
Tooltip,
|
|
12
|
+
TooltipContent,
|
|
13
|
+
TooltipTrigger,
|
|
14
|
+
} from '@terrafirmagreg-team/ui/components/ui/tooltip';
|
|
15
|
+
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
16
|
+
import { INGOT_MB, suggestAmounts } from '@terrafirmagreg-team/recipe/lib/alloy/mix';
|
|
17
|
+
import { Percent } from 'lucide-react';
|
|
18
|
+
import type { AlloyComponent } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
19
|
+
import type { MixState } from '@terrafirmagreg-team/recipe/hooks/alloy/use-mix-state';
|
|
20
|
+
|
|
21
|
+
export function MixTotal({
|
|
22
|
+
state,
|
|
23
|
+
components,
|
|
24
|
+
}: {
|
|
25
|
+
state: MixState;
|
|
26
|
+
components: readonly AlloyComponent[];
|
|
27
|
+
}) {
|
|
28
|
+
const t = useTranslations();
|
|
29
|
+
const {
|
|
30
|
+
unit,
|
|
31
|
+
total,
|
|
32
|
+
totalNumber,
|
|
33
|
+
totalInvalid,
|
|
34
|
+
presets,
|
|
35
|
+
ratioMix,
|
|
36
|
+
format,
|
|
37
|
+
unitLabel,
|
|
38
|
+
applyTotal,
|
|
39
|
+
switchUnit,
|
|
40
|
+
fill,
|
|
41
|
+
} = state;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<div className="flex flex-wrap items-end gap-2">
|
|
46
|
+
<label className="flex w-44 flex-col gap-1 text-xs text-muted-foreground">
|
|
47
|
+
<span className="flex items-baseline justify-between gap-2">
|
|
48
|
+
{t('recipe.alloy.total')}
|
|
49
|
+
{unit === 'ingot' ? (
|
|
50
|
+
<span className="tabular-nums text-muted-foreground/70">
|
|
51
|
+
{Number.isFinite(totalNumber)
|
|
52
|
+
? `= ${format(totalNumber * INGOT_MB)} ${t('recipe.alloy.unit.mb')}`
|
|
53
|
+
: `×${INGOT_MB} ${t('recipe.alloy.unit.mb')}`}
|
|
54
|
+
</span>
|
|
55
|
+
) : null}
|
|
56
|
+
</span>
|
|
57
|
+
<Tooltip>
|
|
58
|
+
<TooltipTrigger
|
|
59
|
+
render={
|
|
60
|
+
<Input
|
|
61
|
+
inputMode="decimal"
|
|
62
|
+
name="alloy-total"
|
|
63
|
+
autoComplete="off"
|
|
64
|
+
value={total}
|
|
65
|
+
onChange={(event) => applyTotal(event.target.value)}
|
|
66
|
+
placeholder={
|
|
67
|
+
unit === 'ingot' ? String(ratioMix?.total ?? 10) : '144'
|
|
68
|
+
}
|
|
69
|
+
/>
|
|
70
|
+
}
|
|
71
|
+
/>
|
|
72
|
+
<TooltipContent>{t('recipe.alloy.hint.scale')}</TooltipContent>
|
|
73
|
+
</Tooltip>
|
|
74
|
+
{totalInvalid ? (
|
|
75
|
+
<span className="text-[11px] text-destructive">
|
|
76
|
+
{t('recipe.alloy.invalid_total')}
|
|
77
|
+
</span>
|
|
78
|
+
) : null}
|
|
79
|
+
</label>
|
|
80
|
+
<ToggleGroup
|
|
81
|
+
value={[unit]}
|
|
82
|
+
onValueChange={(next) => {
|
|
83
|
+
const value = next[0];
|
|
84
|
+
if (value === 'mb' || value === 'ingot') switchUnit(value);
|
|
85
|
+
}}
|
|
86
|
+
variant="outline"
|
|
87
|
+
size="sm"
|
|
88
|
+
spacing={0}
|
|
89
|
+
aria-label={t('recipe.alloy.units')}
|
|
90
|
+
>
|
|
91
|
+
<Tooltip>
|
|
92
|
+
<TooltipTrigger render={<ToggleGroupItem value="mb" />}>
|
|
93
|
+
{t('recipe.alloy.unit.mb')}
|
|
94
|
+
</TooltipTrigger>
|
|
95
|
+
<TooltipContent>{t('recipe.alloy.hint.mb')}</TooltipContent>
|
|
96
|
+
</Tooltip>
|
|
97
|
+
<Tooltip>
|
|
98
|
+
<TooltipTrigger render={<ToggleGroupItem value="ingot" />}>
|
|
99
|
+
{t('recipe.alloy.unit.ingot')}
|
|
100
|
+
</TooltipTrigger>
|
|
101
|
+
<TooltipContent>{t('recipe.alloy.hint.ingot')}</TooltipContent>
|
|
102
|
+
</Tooltip>
|
|
103
|
+
</ToggleGroup>
|
|
104
|
+
<IconButton
|
|
105
|
+
label={`${t('recipe.alloy.fill')} — ${t('recipe.alloy.hint.fill')}`}
|
|
106
|
+
disabled={!suggestAmounts(components, totalNumber)}
|
|
107
|
+
onClick={() => fill(totalNumber)}
|
|
108
|
+
>
|
|
109
|
+
<Percent className="size-3.5" />
|
|
110
|
+
</IconButton>
|
|
111
|
+
</div>
|
|
112
|
+
<div
|
|
113
|
+
role="group"
|
|
114
|
+
aria-label={t('recipe.alloy.presets')}
|
|
115
|
+
className="flex flex-wrap gap-1.5"
|
|
116
|
+
>
|
|
117
|
+
{presets.map((value) => (
|
|
118
|
+
<Button
|
|
119
|
+
key={value}
|
|
120
|
+
variant="outline"
|
|
121
|
+
size="xs"
|
|
122
|
+
className="tabular-nums"
|
|
123
|
+
onClick={() => applyTotal(String(value))}
|
|
124
|
+
>
|
|
125
|
+
{format(value)} {unitLabel}
|
|
126
|
+
</Button>
|
|
127
|
+
))}
|
|
128
|
+
</div>
|
|
129
|
+
</>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Tooltip,
|
|
5
|
+
TooltipContent,
|
|
6
|
+
TooltipTrigger,
|
|
7
|
+
} from '@terrafirmagreg-team/ui/components/ui/tooltip';
|
|
8
|
+
import { cn } from 'cn';
|
|
9
|
+
|
|
10
|
+
export function AlloyRangeBar({
|
|
11
|
+
min,
|
|
12
|
+
max,
|
|
13
|
+
value,
|
|
14
|
+
color,
|
|
15
|
+
label,
|
|
16
|
+
}: {
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
value: number;
|
|
20
|
+
color?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
}) {
|
|
23
|
+
const valid = value >= min - 1e-8 && value <= max + 1e-8;
|
|
24
|
+
const bar = (
|
|
25
|
+
<div className="relative h-2.5 w-full min-w-24 rounded bg-secondary">
|
|
26
|
+
<div
|
|
27
|
+
className={cn(
|
|
28
|
+
'absolute inset-y-0 rounded transition-[background-color]',
|
|
29
|
+
!color &&
|
|
30
|
+
(valid
|
|
31
|
+
? 'bg-green-600/30 dark:bg-green-400/30'
|
|
32
|
+
: 'bg-muted-foreground/25'),
|
|
33
|
+
)}
|
|
34
|
+
style={{
|
|
35
|
+
left: `${min}%`,
|
|
36
|
+
width: `${max - min}%`,
|
|
37
|
+
...(color ? { backgroundColor: color, opacity: 0.28 } : {}),
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
<div
|
|
41
|
+
className={cn(
|
|
42
|
+
'absolute -inset-y-0.5 w-0.5 rounded transition-[left,background-color]',
|
|
43
|
+
!color && (valid ? 'bg-green-700 dark:bg-green-300' : 'bg-destructive'),
|
|
44
|
+
color && !valid && 'bg-destructive',
|
|
45
|
+
)}
|
|
46
|
+
style={{
|
|
47
|
+
left: `${Math.min(100, Math.max(0, value))}%`,
|
|
48
|
+
...(color && valid ? { backgroundColor: color } : {}),
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
if (!label) return bar;
|
|
54
|
+
return (
|
|
55
|
+
<Tooltip>
|
|
56
|
+
<TooltipTrigger
|
|
57
|
+
render={<div className="w-full" tabIndex={0} aria-label={label} />}
|
|
58
|
+
>
|
|
59
|
+
{bar}
|
|
60
|
+
</TooltipTrigger>
|
|
61
|
+
<TooltipContent>{label}</TooltipContent>
|
|
62
|
+
</Tooltip>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { cn } from 'cn';
|
|
5
|
+
import { useFluidColors } from '@terrafirmagreg-team/recipe/hooks/alloy/use-fluid-colors';
|
|
6
|
+
import type { AlloyComponent, AlloyMixRow } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
7
|
+
|
|
8
|
+
const PALETTE = [
|
|
9
|
+
'bg-amber-500',
|
|
10
|
+
'bg-sky-500',
|
|
11
|
+
'bg-emerald-500',
|
|
12
|
+
'bg-lime-500',
|
|
13
|
+
'bg-violet-500',
|
|
14
|
+
'bg-orange-500',
|
|
15
|
+
'bg-teal-500',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function AlloyStackBar({
|
|
19
|
+
rows,
|
|
20
|
+
colors,
|
|
21
|
+
className,
|
|
22
|
+
label,
|
|
23
|
+
}: {
|
|
24
|
+
rows: readonly Pick<AlloyMixRow, 'percent' | 'valid'>[];
|
|
25
|
+
colors?: readonly (string | undefined)[];
|
|
26
|
+
className?: string;
|
|
27
|
+
|
|
28
|
+
label?: string;
|
|
29
|
+
}) {
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
className={cn(
|
|
33
|
+
'flex h-3 w-full overflow-hidden rounded bg-secondary',
|
|
34
|
+
className,
|
|
35
|
+
)}
|
|
36
|
+
role={label ? 'img' : undefined}
|
|
37
|
+
aria-label={label}
|
|
38
|
+
aria-hidden={label ? undefined : true}
|
|
39
|
+
>
|
|
40
|
+
{rows.map((row, i) => {
|
|
41
|
+
const color = colors?.[i];
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
key={i}
|
|
45
|
+
className={cn(
|
|
46
|
+
'h-full transition-[width,background-color]',
|
|
47
|
+
!color && PALETTE[i % PALETTE.length],
|
|
48
|
+
!row.valid && 'opacity-40',
|
|
49
|
+
)}
|
|
50
|
+
style={{
|
|
51
|
+
width: `${Math.max(0, Math.min(100, row.percent))}%`,
|
|
52
|
+
...(color ? { backgroundColor: color } : {}),
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function AlloyMiniBar({
|
|
62
|
+
dataset,
|
|
63
|
+
components,
|
|
64
|
+
className,
|
|
65
|
+
}: {
|
|
66
|
+
dataset: string;
|
|
67
|
+
components: readonly AlloyComponent[];
|
|
68
|
+
className?: string;
|
|
69
|
+
}) {
|
|
70
|
+
const slots = useMemo(() => components.map(({ slot }) => slot), [components]);
|
|
71
|
+
const colors = useFluidColors(dataset, slots);
|
|
72
|
+
const sum = components.reduce(
|
|
73
|
+
(total, { slot }) => total + (slot.amount || 0),
|
|
74
|
+
0,
|
|
75
|
+
);
|
|
76
|
+
return (
|
|
77
|
+
<AlloyStackBar
|
|
78
|
+
className={className}
|
|
79
|
+
colors={colors}
|
|
80
|
+
rows={components.map(({ slot }) => ({
|
|
81
|
+
percent: sum > 0 ? (slot.amount / sum) * 100 : 0,
|
|
82
|
+
valid: true,
|
|
83
|
+
}))}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
import { Anvil, Calculator, FlaskConical, Shapes } from 'lucide-react';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
|
|
7
|
+
import { useLocationSearch } from '@terrafirmagreg-team/ui/hooks/page/use-location-search';
|
|
8
|
+
import { recipePlaceFromParams } from '@terrafirmagreg-team/recipe/lib/links';
|
|
9
|
+
import { recipeCalcHref, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
10
|
+
import { parseSectionLocation } from '@terrafirmagreg-team/kit/lib/location';
|
|
11
|
+
import { Switcher } from '@terrafirmagreg-team/ui/components/blocks/nav/switcher';
|
|
12
|
+
|
|
13
|
+
export function RecipeAxisSwitcher() {
|
|
14
|
+
const t = useTranslations();
|
|
15
|
+
const { dataset } = parseSectionLocation(usePathname());
|
|
16
|
+
const lang = useResolvedLang();
|
|
17
|
+
const axis = recipePlaceFromParams(
|
|
18
|
+
new URLSearchParams(useLocationSearch()),
|
|
19
|
+
).kind;
|
|
20
|
+
if (!dataset) return null;
|
|
21
|
+
return (
|
|
22
|
+
<Switcher
|
|
23
|
+
options={[
|
|
24
|
+
{
|
|
25
|
+
value: 'type',
|
|
26
|
+
title: t('recipe.axis_type'),
|
|
27
|
+
icon: <Shapes className="size-4" />,
|
|
28
|
+
url: recipeHref(dataset, lang),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
value: 'calc',
|
|
32
|
+
title: t('recipe.calculator'),
|
|
33
|
+
icon: <Calculator className="size-4" />,
|
|
34
|
+
url: recipeCalcHref(dataset, lang),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
value: 'forge',
|
|
38
|
+
title: t('recipe.forge.title'),
|
|
39
|
+
icon: <Anvil className="size-4" />,
|
|
40
|
+
url: recipeHref(dataset, lang, { tool: 'forge' }),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: 'alloy',
|
|
44
|
+
title: t('recipe.alloy.title'),
|
|
45
|
+
icon: <FlaskConical className="size-4" />,
|
|
46
|
+
url: recipeHref(dataset, lang, { tool: 'alloy' }),
|
|
47
|
+
},
|
|
48
|
+
]}
|
|
49
|
+
selected={axis ?? 'type'}
|
|
50
|
+
placeholder={t('recipe.axis_type')}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, type ReactNode, type RefObject } from 'react';
|
|
4
|
+
import { useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
|
|
7
|
+
import { RecipeDefaultMenuItem } from '@terrafirmagreg-team/recipe/components/cards/default-item';
|
|
8
|
+
import { CopyIdMenu } from '@terrafirmagreg-team/game/components/entry/copy-id-menu';
|
|
9
|
+
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
10
|
+
import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
|
|
11
|
+
import {
|
|
12
|
+
recipeCardImageUrl,
|
|
13
|
+
recipeHref,
|
|
14
|
+
recipeImageUrl,
|
|
15
|
+
} from '@terrafirmagreg-team/recipe/lib/links';
|
|
16
|
+
import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
17
|
+
import { loadClientRecipe } from '@terrafirmagreg-team/recipe/lib/client/recipe';
|
|
18
|
+
import { pushUrlState } from '@terrafirmagreg-team/ui/lib/utils/history';
|
|
19
|
+
import { useSwipe } from '@terrafirmagreg-team/ui/hooks/use-swipe';
|
|
20
|
+
import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
|
|
21
|
+
import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
|
|
22
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
23
|
+
import type { FitDim } from '@terrafirmagreg-team/ui/hooks/page/use-fit-pages';
|
|
24
|
+
import type {
|
|
25
|
+
RecipeCategory,
|
|
26
|
+
RecipeCompactIndex,
|
|
27
|
+
RecipeCompactRow,
|
|
28
|
+
RecipeSession,
|
|
29
|
+
} from '@terrafirmagreg-team/recipe/types';
|
|
30
|
+
|
|
31
|
+
const FALLBACK_DIM: FitDim = { w: 320, h: 80 };
|
|
32
|
+
|
|
33
|
+
export function recipeCardDim(
|
|
34
|
+
index: RecipeCompactIndex | null,
|
|
35
|
+
categoriesById: Map<string, RecipeCategory>,
|
|
36
|
+
row: RecipeCompactRow,
|
|
37
|
+
): FitDim {
|
|
38
|
+
if (row.d) return { w: row.d.w, h: row.d.h };
|
|
39
|
+
const typeId = index?.types[row.type];
|
|
40
|
+
const layout = typeId ? categoriesById.get(typeId)?.layout : undefined;
|
|
41
|
+
if (!layout) return FALLBACK_DIM;
|
|
42
|
+
const scale = layout.scale ?? 2;
|
|
43
|
+
const margin = layout.margin ?? 0;
|
|
44
|
+
return {
|
|
45
|
+
w: (layout.w + margin * 2) * scale,
|
|
46
|
+
h: (layout.h + margin * 2) * scale,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function RecipeGridCard({
|
|
51
|
+
row,
|
|
52
|
+
session,
|
|
53
|
+
focused,
|
|
54
|
+
maxH,
|
|
55
|
+
maxW,
|
|
56
|
+
onPick,
|
|
57
|
+
menuExtra,
|
|
58
|
+
defaultMaterial,
|
|
59
|
+
}: {
|
|
60
|
+
row: RecipeCompactRow;
|
|
61
|
+
session: RecipeSession;
|
|
62
|
+
focused: boolean;
|
|
63
|
+
maxH?: number;
|
|
64
|
+
maxW?: number;
|
|
65
|
+
onPick?: (recipeId: string) => void;
|
|
66
|
+
menuExtra?: (row: RecipeCompactRow) => ReactNode;
|
|
67
|
+
defaultMaterial?: string;
|
|
68
|
+
}) {
|
|
69
|
+
const t = useTranslations();
|
|
70
|
+
const { dataset, lang, langMap, names, nav, index } = session;
|
|
71
|
+
const recipe = useAsyncValue(
|
|
72
|
+
() => loadClientRecipe(dataset, row.id, row.bucket),
|
|
73
|
+
[dataset, row.id, row.bucket],
|
|
74
|
+
);
|
|
75
|
+
const [failed, setFailed] = useState(false);
|
|
76
|
+
|
|
77
|
+
const title = recipe
|
|
78
|
+
? recipeTitle(recipe, langMap)
|
|
79
|
+
: recipeItemName(names, lang, row.out[0] ?? row.id);
|
|
80
|
+
const src =
|
|
81
|
+
(recipe ? recipeImageUrl(dataset, recipe) : undefined) ??
|
|
82
|
+
(row.image
|
|
83
|
+
? recipeImageUrl(dataset, {
|
|
84
|
+
modId: row.id.split(':', 1)[0],
|
|
85
|
+
image: row.image,
|
|
86
|
+
})
|
|
87
|
+
: undefined) ??
|
|
88
|
+
recipeCardImageUrl(dataset, row.id);
|
|
89
|
+
|
|
90
|
+
const focus = () =>
|
|
91
|
+
pushUrlState(
|
|
92
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: undefined }),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const isolate = () =>
|
|
96
|
+
pushUrlState(
|
|
97
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: '1' }),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const openNewTab = () =>
|
|
101
|
+
window.open(
|
|
102
|
+
recipeHref(dataset, lang, { ...nav, id: row.id, solo: '1' }),
|
|
103
|
+
'_blank',
|
|
104
|
+
'noopener',
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const recipeType = index?.types[row.type];
|
|
108
|
+
const cardW = recipe?.w ?? row.d?.w ?? 0;
|
|
109
|
+
const fit = maxW && cardW > maxW ? maxW / cardW : 1;
|
|
110
|
+
return (
|
|
111
|
+
<CopyIdMenu
|
|
112
|
+
id={row.id}
|
|
113
|
+
label="recipe.copy_recipe_id"
|
|
114
|
+
extra={
|
|
115
|
+
<>
|
|
116
|
+
<RecipeDefaultMenuItem
|
|
117
|
+
dataset={dataset}
|
|
118
|
+
materialId={defaultMaterial ?? row.out[0]}
|
|
119
|
+
recipeId={row.id}
|
|
120
|
+
/>
|
|
121
|
+
{menuExtra?.(row)}
|
|
122
|
+
</>
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
<div
|
|
126
|
+
onClick={(event) => {
|
|
127
|
+
if ((event.target as HTMLElement).closest('a,button')) return;
|
|
128
|
+
if (onPick) onPick(row.id);
|
|
129
|
+
else focus();
|
|
130
|
+
}}
|
|
131
|
+
onDoubleClick={(event) => {
|
|
132
|
+
if ((event.target as HTMLElement).closest('a,button')) return;
|
|
133
|
+
if (onPick) openNewTab();
|
|
134
|
+
else isolate();
|
|
135
|
+
}}
|
|
136
|
+
onMouseEnter={() => {
|
|
137
|
+
favoriteHover.base = recipeType
|
|
138
|
+
? {
|
|
139
|
+
kind: 'recipe',
|
|
140
|
+
id: row.id,
|
|
141
|
+
type: recipeType,
|
|
142
|
+
...(row.out[0] ?? row.in[0]
|
|
143
|
+
? { icon: (row.out[0] ?? row.in[0])! }
|
|
144
|
+
: {}),
|
|
145
|
+
}
|
|
146
|
+
: undefined;
|
|
147
|
+
}}
|
|
148
|
+
onMouseLeave={() => {
|
|
149
|
+
favoriteHover.base = undefined;
|
|
150
|
+
favoriteHover.slot = undefined;
|
|
151
|
+
}}
|
|
152
|
+
aria-current={focused || undefined}
|
|
153
|
+
className={cn(
|
|
154
|
+
'relative w-fit flex-none rounded-md',
|
|
155
|
+
focused && 'ring-2 ring-primary ring-offset-1',
|
|
156
|
+
)}
|
|
157
|
+
style={fit < 1 ? { zoom: fit } : undefined}
|
|
158
|
+
>
|
|
159
|
+
{recipe ? (
|
|
160
|
+
src && !failed ? (
|
|
161
|
+
<PagedCard
|
|
162
|
+
recipe={recipe}
|
|
163
|
+
dataset={dataset}
|
|
164
|
+
lang={lang}
|
|
165
|
+
langMap={langMap}
|
|
166
|
+
nav={nav}
|
|
167
|
+
title={title}
|
|
168
|
+
src={src}
|
|
169
|
+
naturalW={row.d?.w}
|
|
170
|
+
naturalH={row.d?.h}
|
|
171
|
+
maxH={maxH}
|
|
172
|
+
interactive={focused}
|
|
173
|
+
onFail={() => setFailed(true)}
|
|
174
|
+
/>
|
|
175
|
+
) : (
|
|
176
|
+
<EmptyState variant="empty">{t('recipe.no_image')}</EmptyState>
|
|
177
|
+
)
|
|
178
|
+
) : src && !failed ? (
|
|
179
|
+
// eslint-disable-next-line @next/next/no-img-element -- dump asset
|
|
180
|
+
<img
|
|
181
|
+
src={src}
|
|
182
|
+
alt={title}
|
|
183
|
+
width={row.d?.w}
|
|
184
|
+
height={row.d?.h}
|
|
185
|
+
loading="lazy"
|
|
186
|
+
decoding="async"
|
|
187
|
+
onError={() => setFailed(true)}
|
|
188
|
+
className="block rounded-sm"
|
|
189
|
+
/>
|
|
190
|
+
) : (
|
|
191
|
+
<Skeleton
|
|
192
|
+
className="rounded-sm"
|
|
193
|
+
style={{
|
|
194
|
+
width: row.d?.w ?? FALLBACK_DIM.w,
|
|
195
|
+
height: row.d?.h ?? FALLBACK_DIM.h,
|
|
196
|
+
maxWidth: '100%',
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
</CopyIdMenu>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function RecipeCardGrid({
|
|
206
|
+
session,
|
|
207
|
+
rows,
|
|
208
|
+
boxRef,
|
|
209
|
+
maxH,
|
|
210
|
+
maxW,
|
|
211
|
+
loading,
|
|
212
|
+
empty,
|
|
213
|
+
onSwipe,
|
|
214
|
+
onPick,
|
|
215
|
+
cardMenuExtra,
|
|
216
|
+
defaultMaterial,
|
|
217
|
+
}: {
|
|
218
|
+
session: RecipeSession;
|
|
219
|
+
rows: RecipeCompactRow[];
|
|
220
|
+
boxRef: RefObject<HTMLDivElement | null>;
|
|
221
|
+
maxH?: number;
|
|
222
|
+
maxW?: number;
|
|
223
|
+
loading?: boolean;
|
|
224
|
+
empty?: string;
|
|
225
|
+
onSwipe?: (dir: -1 | 1) => void;
|
|
226
|
+
onPick?: (recipeId: string) => void;
|
|
227
|
+
cardMenuExtra?: (row: RecipeCompactRow) => ReactNode;
|
|
228
|
+
defaultMaterial?: string;
|
|
229
|
+
}) {
|
|
230
|
+
const { recipeId } = session;
|
|
231
|
+
const swipe = useSwipe((dir) => onSwipe?.(dir));
|
|
232
|
+
const { dataset } = session;
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
for (const row of rows) void loadClientRecipe(dataset, row.id, row.bucket);
|
|
236
|
+
}, [dataset, rows]);
|
|
237
|
+
|
|
238
|
+
let body;
|
|
239
|
+
if (loading) {
|
|
240
|
+
body = Array.from({ length: 6 }, (_, i) => (
|
|
241
|
+
<Skeleton
|
|
242
|
+
key={i}
|
|
243
|
+
className="h-24 rounded-md"
|
|
244
|
+
style={{ width: 220 + (i % 3) * 60 }}
|
|
245
|
+
/>
|
|
246
|
+
));
|
|
247
|
+
} else if (!rows.length) {
|
|
248
|
+
body = empty ? <EmptyState variant="empty">{empty}</EmptyState> : null;
|
|
249
|
+
} else {
|
|
250
|
+
body = rows.map((row) => (
|
|
251
|
+
<RecipeGridCard
|
|
252
|
+
key={`${row.bucket ?? ''}#${row.id}`}
|
|
253
|
+
row={row}
|
|
254
|
+
session={session}
|
|
255
|
+
focused={row.id === recipeId}
|
|
256
|
+
maxH={maxH}
|
|
257
|
+
maxW={maxW}
|
|
258
|
+
onPick={onPick}
|
|
259
|
+
defaultMaterial={defaultMaterial}
|
|
260
|
+
menuExtra={cardMenuExtra}
|
|
261
|
+
/>
|
|
262
|
+
));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div
|
|
267
|
+
ref={boxRef}
|
|
268
|
+
{...swipe}
|
|
269
|
+
className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 overflow-x-hidden"
|
|
270
|
+
>
|
|
271
|
+
{body}
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Star } from 'lucide-react';
|
|
4
|
+
import { Toggle } from '@terrafirmagreg-team/ui/components/ui/toggle';
|
|
5
|
+
import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
|
|
6
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
7
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
8
|
+
|
|
9
|
+
export function FavoriteButton({
|
|
10
|
+
active,
|
|
11
|
+
onToggle,
|
|
12
|
+
label,
|
|
13
|
+
variant = 'ghost',
|
|
14
|
+
className,
|
|
15
|
+
}: {
|
|
16
|
+
active: boolean;
|
|
17
|
+
onToggle: () => void;
|
|
18
|
+
label?: string;
|
|
19
|
+
variant?: 'ghost' | 'outline' | 'overlay';
|
|
20
|
+
className?: string;
|
|
21
|
+
}) {
|
|
22
|
+
const t = useTranslations();
|
|
23
|
+
const text =
|
|
24
|
+
label ??
|
|
25
|
+
(active ? t('recipe.remove_favorite') : t('recipe.add_favorite'));
|
|
26
|
+
return (
|
|
27
|
+
<Hint label={text}>
|
|
28
|
+
<Toggle
|
|
29
|
+
variant={variant === 'outline' ? 'outline' : 'default'}
|
|
30
|
+
pressed={active}
|
|
31
|
+
onPressedChange={onToggle}
|
|
32
|
+
aria-label={text}
|
|
33
|
+
className={cn(
|
|
34
|
+
'size-7 rounded-lg p-0 data-pressed:bg-transparent [&_svg]:size-3.5',
|
|
35
|
+
variant === 'overlay' &&
|
|
36
|
+
'absolute bottom-1 right-1 z-10 size-6 rounded-sm bg-background/80',
|
|
37
|
+
active && 'text-amber-500',
|
|
38
|
+
className,
|
|
39
|
+
)}
|
|
40
|
+
>
|
|
41
|
+
<Star className={cn(active && 'fill-current')} />
|
|
42
|
+
</Toggle>
|
|
43
|
+
</Hint>
|
|
44
|
+
);
|
|
45
|
+
}
|