@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,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
5
|
+
import { ItemRow } from '@terrafirmagreg-team/ui/components/blocks/list/row';
|
|
6
|
+
import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
|
|
7
|
+
import { RecipeItemHeader } from '@terrafirmagreg-team/recipe/components/views/browser/recipe-item-header';
|
|
8
|
+
import { RecipeFrame } from '@terrafirmagreg-team/recipe/components/views/browser/frame';
|
|
9
|
+
import { useToolRecipes } from '@terrafirmagreg-team/recipe/hooks/use-tool-recipes';
|
|
10
|
+
import { toAlloyRecipe } from '@terrafirmagreg-team/recipe/lib/alloy/parse';
|
|
11
|
+
import { RecipeCard } from '@terrafirmagreg-team/recipe/components/cards/card';
|
|
12
|
+
import { FitCard } from '@terrafirmagreg-team/recipe/components/cards/fit-card';
|
|
13
|
+
import {
|
|
14
|
+
recipeCardImageUrl,
|
|
15
|
+
recipeImageUrl,
|
|
16
|
+
} from '@terrafirmagreg-team/recipe/lib/links';
|
|
17
|
+
import { AlloyList } from './list';
|
|
18
|
+
import { AlloyMix } from './mix';
|
|
19
|
+
import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
20
|
+
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
21
|
+
|
|
22
|
+
function AlloyRecipeCard({
|
|
23
|
+
recipe,
|
|
24
|
+
session,
|
|
25
|
+
}: {
|
|
26
|
+
recipe: Recipe;
|
|
27
|
+
session: RecipeSession;
|
|
28
|
+
}) {
|
|
29
|
+
const [failed, setFailed] = useState(false);
|
|
30
|
+
const src =
|
|
31
|
+
recipeImageUrl(session.dataset, recipe) ??
|
|
32
|
+
recipeCardImageUrl(session.dataset, recipe.id);
|
|
33
|
+
if (!src || failed) return null;
|
|
34
|
+
return (
|
|
35
|
+
<RecipeCard
|
|
36
|
+
recipe={recipe}
|
|
37
|
+
dataset={session.dataset}
|
|
38
|
+
lang={session.lang}
|
|
39
|
+
langMap={session.langMap}
|
|
40
|
+
title={recipe.id}
|
|
41
|
+
src={src}
|
|
42
|
+
onFail={() => setFailed(true)}
|
|
43
|
+
interactive
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function AlloyCalculator({ session }: { session: RecipeSession }) {
|
|
49
|
+
const t = useTranslations();
|
|
50
|
+
const { value, pending } = useToolRecipes(
|
|
51
|
+
session,
|
|
52
|
+
'tfc:alloying',
|
|
53
|
+
toAlloyRecipe,
|
|
54
|
+
);
|
|
55
|
+
const activeId = session.recipeId;
|
|
56
|
+
const active =
|
|
57
|
+
value?.find(({ recipe }) => recipe.id === activeId) ??
|
|
58
|
+
(!activeId ? value?.[0] : undefined);
|
|
59
|
+
const loading = session.indexLoading || pending;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<AlloyList session={session} />
|
|
64
|
+
<RecipeFrame
|
|
65
|
+
session={session}
|
|
66
|
+
header={
|
|
67
|
+
active ? (
|
|
68
|
+
<RecipeItemHeader recipe={active.recipe} session={session} />
|
|
69
|
+
) : (
|
|
70
|
+
<ItemRow layout="header" title={t('recipe.alloy.title')} />
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<div className="flex-1 space-y-5 overflow-y-auto p-2 sm:p-4">
|
|
75
|
+
{loading ? (
|
|
76
|
+
<EmptyState variant="loading" />
|
|
77
|
+
) : value === undefined ? (
|
|
78
|
+
<EmptyState variant="missing">
|
|
79
|
+
{t('recipe.alloy.load_error')}
|
|
80
|
+
</EmptyState>
|
|
81
|
+
) : active ? (
|
|
82
|
+
<>
|
|
83
|
+
<AlloyMix
|
|
84
|
+
key={active.recipe.id}
|
|
85
|
+
recipe={active}
|
|
86
|
+
session={session}
|
|
87
|
+
/>
|
|
88
|
+
<FitCard w={active.recipe.w ?? 0}>
|
|
89
|
+
<AlloyRecipeCard
|
|
90
|
+
key={active.recipe.id}
|
|
91
|
+
recipe={active.recipe}
|
|
92
|
+
session={session}
|
|
93
|
+
/>
|
|
94
|
+
</FitCard>
|
|
95
|
+
</>
|
|
96
|
+
) : (
|
|
97
|
+
<EmptyState>
|
|
98
|
+
{t(activeId ? 'recipe.alloy.missing' : 'recipe.alloy.empty')}
|
|
99
|
+
</EmptyState>
|
|
100
|
+
)}
|
|
101
|
+
</div>
|
|
102
|
+
</RecipeFrame>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useDeferredValue, useMemo, useState } from 'react';
|
|
4
|
+
import type * as PageTree from 'fumadocs-core/page-tree';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
7
|
+
import { ToolList } from '@terrafirmagreg-team/recipe/components/tool-list';
|
|
8
|
+
import { useToolRecipes } from '@terrafirmagreg-team/recipe/hooks/use-tool-recipes';
|
|
9
|
+
import { recipeItemName } from '@terrafirmagreg-team/recipe/lib/client-index';
|
|
10
|
+
import { toAlloyRecipe } from '@terrafirmagreg-team/recipe/lib/alloy/parse';
|
|
11
|
+
import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
|
|
12
|
+
import { AlloyMiniBar } from './stack-bar';
|
|
13
|
+
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
14
|
+
|
|
15
|
+
export function AlloyList({ session }: { session: RecipeSession }) {
|
|
16
|
+
const t = useTranslations();
|
|
17
|
+
const { value } = useToolRecipes(session, 'tfc:alloying', toAlloyRecipe);
|
|
18
|
+
const [query, setQuery] = useState('');
|
|
19
|
+
const search = useDeferredValue(query.trim().toLowerCase());
|
|
20
|
+
const name = (id: string) => recipeItemName(session.names, session.lang, id);
|
|
21
|
+
|
|
22
|
+
const tree = useMemo((): PageTree.Root => {
|
|
23
|
+
const rows = !search
|
|
24
|
+
? (value ?? [])
|
|
25
|
+
: (value ?? []).filter(({ recipe, components }) =>
|
|
26
|
+
[
|
|
27
|
+
recipe.id,
|
|
28
|
+
`${recipe.outputs[0]?.id ?? ''} ${name(
|
|
29
|
+
recipe.outputs[0]?.id ?? '',
|
|
30
|
+
)}`,
|
|
31
|
+
...components.map(({ slot }) => `${slot.id} ${name(slot.id)}`),
|
|
32
|
+
].some((id) => id.toLowerCase().includes(search)),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const children: PageTree.Item[] = rows.map(({ recipe, components }) => {
|
|
36
|
+
return {
|
|
37
|
+
type: 'page',
|
|
38
|
+
$id: recipe.id,
|
|
39
|
+
url: recipeHref(session.dataset, session.lang, {
|
|
40
|
+
tool: 'alloy',
|
|
41
|
+
id: recipe.id,
|
|
42
|
+
unit: session.alloyUnit,
|
|
43
|
+
tab: session.tab,
|
|
44
|
+
}),
|
|
45
|
+
name: (
|
|
46
|
+
<>
|
|
47
|
+
<Entry
|
|
48
|
+
id={recipe.outputs[0]?.id ?? recipe.id}
|
|
49
|
+
kind={recipe.outputs[0]?.kind === 'fluid' ? 'fluid' : 'item'}
|
|
50
|
+
size="sm"
|
|
51
|
+
labeled
|
|
52
|
+
href={false}
|
|
53
|
+
tooltip={false}
|
|
54
|
+
className="min-w-0 flex-1 justify-start truncate"
|
|
55
|
+
/>
|
|
56
|
+
<AlloyMiniBar
|
|
57
|
+
dataset={session.dataset}
|
|
58
|
+
components={components}
|
|
59
|
+
className="ms-auto h-1.5 w-10 shrink-0"
|
|
60
|
+
/>
|
|
61
|
+
</>
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
name: 'alloy',
|
|
68
|
+
$id: `alloy:${session.lang}:${search}:${rows.length}`,
|
|
69
|
+
children,
|
|
70
|
+
} as PageTree.Root;
|
|
71
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
+
}, [value, search, session.lang, session.dataset, session.tab]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<ToolList
|
|
76
|
+
tree={tree}
|
|
77
|
+
loaded={value !== undefined}
|
|
78
|
+
query={query}
|
|
79
|
+
onQuery={setQuery}
|
|
80
|
+
searchLabel={t('recipe.alloy.search')}
|
|
81
|
+
emptyLabel={t('recipe.alloy.empty')}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { AlloyStackBar } from '@terrafirmagreg-team/recipe/components/views/alloy/stack-bar';
|
|
4
|
+
import { useMixState } from '@terrafirmagreg-team/recipe/hooks/alloy/use-mix-state';
|
|
5
|
+
import { MixTotal } from './total';
|
|
6
|
+
import { RatioPanel } from './ratio';
|
|
7
|
+
import { MixRows } from './rows';
|
|
8
|
+
import { MixStatus } from './status';
|
|
9
|
+
import type { AlloyRecipe } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
10
|
+
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
11
|
+
|
|
12
|
+
export function AlloyMix({
|
|
13
|
+
recipe,
|
|
14
|
+
session,
|
|
15
|
+
}: {
|
|
16
|
+
recipe: AlloyRecipe;
|
|
17
|
+
session: RecipeSession;
|
|
18
|
+
}) {
|
|
19
|
+
const state = useMixState(recipe, session);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="space-y-4">
|
|
23
|
+
<MixTotal state={state} components={recipe.components} />
|
|
24
|
+
<RatioPanel state={state} components={recipe.components} />
|
|
25
|
+
<AlloyStackBar
|
|
26
|
+
rows={state.mix.rows}
|
|
27
|
+
colors={state.colors}
|
|
28
|
+
label={state.mixLabel}
|
|
29
|
+
/>
|
|
30
|
+
<MixRows state={state} components={recipe.components} />
|
|
31
|
+
<MixStatus state={state} />
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
4
|
+
import { Button } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
5
|
+
import {
|
|
6
|
+
Tooltip,
|
|
7
|
+
TooltipContent,
|
|
8
|
+
TooltipTrigger,
|
|
9
|
+
} from '@terrafirmagreg-team/ui/components/ui/tooltip';
|
|
10
|
+
import { INGOT_MB } from '@terrafirmagreg-team/recipe/lib/alloy/mix';
|
|
11
|
+
import type { AlloyComponent } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
12
|
+
import type { MixState } from '@terrafirmagreg-team/recipe/hooks/alloy/use-mix-state';
|
|
13
|
+
|
|
14
|
+
export function RatioPanel({
|
|
15
|
+
state,
|
|
16
|
+
components,
|
|
17
|
+
}: {
|
|
18
|
+
state: MixState;
|
|
19
|
+
components: readonly AlloyComponent[];
|
|
20
|
+
}) {
|
|
21
|
+
const t = useTranslations();
|
|
22
|
+
const { ratioMix, colors, name, applyRatioMix } = state;
|
|
23
|
+
|
|
24
|
+
if (!ratioMix) return null;
|
|
25
|
+
return (
|
|
26
|
+
<div className="space-y-1.5 rounded-md border border-dashed px-3 py-2 text-sm">
|
|
27
|
+
<div className="flex items-center gap-2">
|
|
28
|
+
<span className="text-xs text-muted-foreground">
|
|
29
|
+
{t('recipe.alloy.ratio_ingots')}
|
|
30
|
+
</span>
|
|
31
|
+
<span className="ms-auto flex shrink-0 items-center gap-1.5">
|
|
32
|
+
{[2, 4, 8].map((mult) => {
|
|
33
|
+
const text = components
|
|
34
|
+
.map(({ slot }, i) => `${ratioMix.counts[i] * mult}×${name(slot.id)}`)
|
|
35
|
+
.join(' + ');
|
|
36
|
+
return (
|
|
37
|
+
<Tooltip key={mult}>
|
|
38
|
+
<TooltipTrigger
|
|
39
|
+
render={
|
|
40
|
+
<Button
|
|
41
|
+
variant="outline"
|
|
42
|
+
size="xs"
|
|
43
|
+
aria-label={`${t('recipe.alloy.hint.mult')}: ${text}`}
|
|
44
|
+
onClick={() => applyRatioMix(mult)}
|
|
45
|
+
/>
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
×{mult}
|
|
49
|
+
</TooltipTrigger>
|
|
50
|
+
<TooltipContent>{text}</TooltipContent>
|
|
51
|
+
</Tooltip>
|
|
52
|
+
);
|
|
53
|
+
})}
|
|
54
|
+
<Tooltip>
|
|
55
|
+
<TooltipTrigger
|
|
56
|
+
render={
|
|
57
|
+
<Button
|
|
58
|
+
variant="outline"
|
|
59
|
+
size="sm"
|
|
60
|
+
onClick={() => applyRatioMix()}
|
|
61
|
+
/>
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
{t('recipe.alloy.apply')}
|
|
65
|
+
</TooltipTrigger>
|
|
66
|
+
<TooltipContent>{t('recipe.alloy.hint.apply')}</TooltipContent>
|
|
67
|
+
</Tooltip>
|
|
68
|
+
</span>
|
|
69
|
+
</div>
|
|
70
|
+
<div className="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5">
|
|
71
|
+
{components.map(({ slot }, i) => (
|
|
72
|
+
<span
|
|
73
|
+
key={slot.id}
|
|
74
|
+
className="inline-flex min-w-0 items-center gap-1 tabular-nums"
|
|
75
|
+
>
|
|
76
|
+
{i > 0 ? <span className="text-muted-foreground">+</span> : null}
|
|
77
|
+
<span
|
|
78
|
+
className="size-2 shrink-0 rounded-full"
|
|
79
|
+
style={{ backgroundColor: colors[i] }}
|
|
80
|
+
/>
|
|
81
|
+
<span className="max-w-40 truncate" title={name(slot.id)}>
|
|
82
|
+
{ratioMix.counts[i]}×{name(slot.id)}
|
|
83
|
+
</span>
|
|
84
|
+
</span>
|
|
85
|
+
))}
|
|
86
|
+
<span className="tabular-nums text-muted-foreground">
|
|
87
|
+
→ {ratioMix.total.toLocaleString()} {t('recipe.alloy.unit.ingot')} (
|
|
88
|
+
{(ratioMix.total * INGOT_MB).toLocaleString()} {t('recipe.alloy.unit.mb')})
|
|
89
|
+
</span>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
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 { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
7
|
+
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
8
|
+
import { minShareMix } from '@terrafirmagreg-team/recipe/lib/alloy/mix';
|
|
9
|
+
import { AlloyRangeBar } from '@terrafirmagreg-team/recipe/components/views/alloy/range-bar';
|
|
10
|
+
import { Check, Minus, Plus, TrendingDown, X } from 'lucide-react';
|
|
11
|
+
import { cn } from 'cn';
|
|
12
|
+
import type { AlloyComponent } from '@terrafirmagreg-team/recipe/types/alloy';
|
|
13
|
+
import type { MixState } from '@terrafirmagreg-team/recipe/hooks/alloy/use-mix-state';
|
|
14
|
+
|
|
15
|
+
export function MixRows({
|
|
16
|
+
state,
|
|
17
|
+
components,
|
|
18
|
+
}: {
|
|
19
|
+
state: MixState;
|
|
20
|
+
components: readonly AlloyComponent[];
|
|
21
|
+
}) {
|
|
22
|
+
const t = useTranslations();
|
|
23
|
+
const {
|
|
24
|
+
mix,
|
|
25
|
+
fix,
|
|
26
|
+
econTotal,
|
|
27
|
+
colors,
|
|
28
|
+
inputs,
|
|
29
|
+
unitLabel,
|
|
30
|
+
name,
|
|
31
|
+
format,
|
|
32
|
+
formatPercent,
|
|
33
|
+
trim,
|
|
34
|
+
setInputs,
|
|
35
|
+
stepInput,
|
|
36
|
+
} = state;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ul className="space-y-3">
|
|
40
|
+
{components.map(({ slot, range }, i) => {
|
|
41
|
+
const row = mix.rows[i];
|
|
42
|
+
const missing = fix?.[i];
|
|
43
|
+
const econ = range ? minShareMix(components, i, econTotal) : null;
|
|
44
|
+
return (
|
|
45
|
+
<li
|
|
46
|
+
key={slot.id}
|
|
47
|
+
className={cn(
|
|
48
|
+
'grid grid-cols-[1fr_auto] items-center gap-x-4 gap-y-1 rounded-md px-2 py-1.5 transition-colors lg:grid-cols-[minmax(0,12rem)_1fr_auto_minmax(3.5rem,auto)]',
|
|
49
|
+
row?.valid === false && 'bg-destructive/5',
|
|
50
|
+
)}
|
|
51
|
+
>
|
|
52
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
53
|
+
<span
|
|
54
|
+
className="size-2.5 shrink-0 rounded-full"
|
|
55
|
+
style={{ backgroundColor: colors[i] }}
|
|
56
|
+
/>
|
|
57
|
+
<Entry reference={slot.ref} labeled className="min-w-0" />
|
|
58
|
+
{row?.valid === false ? (
|
|
59
|
+
<X className="size-3.5 shrink-0 text-destructive" />
|
|
60
|
+
) : row?.valid ? (
|
|
61
|
+
<Check className="size-3.5 shrink-0 text-green-600 dark:text-green-400" />
|
|
62
|
+
) : (
|
|
63
|
+
<span className="size-3.5 shrink-0" aria-hidden />
|
|
64
|
+
)}
|
|
65
|
+
</span>
|
|
66
|
+
<span className="flex w-16 flex-col items-end justify-self-end text-right text-sm tabular-nums text-muted-foreground lg:order-last lg:w-20">
|
|
67
|
+
<span>{formatPercent(row?.percent ?? 0)}%</span>
|
|
68
|
+
{missing !== undefined && missing > 0 ? (
|
|
69
|
+
<span className="text-[11px] leading-tight text-destructive">
|
|
70
|
+
+{format(missing)}
|
|
71
|
+
</span>
|
|
72
|
+
) : null}
|
|
73
|
+
</span>
|
|
74
|
+
<span className="col-span-2 lg:col-span-1">
|
|
75
|
+
{range ? (
|
|
76
|
+
<AlloyRangeBar
|
|
77
|
+
min={range.min}
|
|
78
|
+
max={range.max}
|
|
79
|
+
value={row?.percent ?? 0}
|
|
80
|
+
color={colors[i]}
|
|
81
|
+
label={`${t('recipe.alloy.range_allowed')}: ${formatPercent(
|
|
82
|
+
range.min,
|
|
83
|
+
)}–${formatPercent(range.max)}%`}
|
|
84
|
+
/>
|
|
85
|
+
) : (
|
|
86
|
+
<span className="text-xs text-muted-foreground">—</span>
|
|
87
|
+
)}
|
|
88
|
+
</span>
|
|
89
|
+
<span className="col-span-2 flex items-center justify-end gap-1 lg:col-span-1">
|
|
90
|
+
<Button
|
|
91
|
+
variant="outline"
|
|
92
|
+
size="icon-xs"
|
|
93
|
+
aria-label={`${t('recipe.alloy.step.down')} ${name(slot.id)}`}
|
|
94
|
+
onClick={() => stepInput(i, -1)}
|
|
95
|
+
>
|
|
96
|
+
<Minus />
|
|
97
|
+
</Button>
|
|
98
|
+
<Input
|
|
99
|
+
inputMode="decimal"
|
|
100
|
+
name={`alloy-${slot.id}`}
|
|
101
|
+
autoComplete="off"
|
|
102
|
+
className="w-16 justify-self-end"
|
|
103
|
+
value={inputs[i] ?? ''}
|
|
104
|
+
onChange={(event) =>
|
|
105
|
+
setInputs((prev) =>
|
|
106
|
+
prev.map((value, j) =>
|
|
107
|
+
j === i ? event.target.value : value,
|
|
108
|
+
),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
aria-label={name(slot.id)}
|
|
112
|
+
/>
|
|
113
|
+
<Button
|
|
114
|
+
variant="outline"
|
|
115
|
+
size="icon-xs"
|
|
116
|
+
aria-label={`${t('recipe.alloy.step.up')} ${name(slot.id)}`}
|
|
117
|
+
onClick={() => stepInput(i, 1)}
|
|
118
|
+
>
|
|
119
|
+
<Plus />
|
|
120
|
+
</Button>
|
|
121
|
+
<span className="w-8 text-xs text-muted-foreground">
|
|
122
|
+
{unitLabel}
|
|
123
|
+
</span>
|
|
124
|
+
{range ? (
|
|
125
|
+
<IconButton
|
|
126
|
+
label={`${t('recipe.alloy.economize')} ${name(slot.id)} — ${t(
|
|
127
|
+
'recipe.alloy.hint.economize',
|
|
128
|
+
)}`}
|
|
129
|
+
size="icon-xs"
|
|
130
|
+
disabled={!econ}
|
|
131
|
+
onClick={() =>
|
|
132
|
+
econ && setInputs(econ.map((value) => trim(value)))
|
|
133
|
+
}
|
|
134
|
+
>
|
|
135
|
+
<TrendingDown />
|
|
136
|
+
</IconButton>
|
|
137
|
+
) : (
|
|
138
|
+
<span className="size-6 shrink-0" aria-hidden />
|
|
139
|
+
)}
|
|
140
|
+
</span>
|
|
141
|
+
</li>
|
|
142
|
+
);
|
|
143
|
+
})}
|
|
144
|
+
</ul>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
4
|
+
import { useCopyButton } from '@terrafirmagreg-team/ui/hooks/use-copy-button';
|
|
5
|
+
import { Badge } from '@terrafirmagreg-team/ui/components/ui/badge';
|
|
6
|
+
import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
|
|
7
|
+
import { IconButton } from '@terrafirmagreg-team/ui/components/blocks/button/icon-button';
|
|
8
|
+
import {
|
|
9
|
+
ArrowUpToLine,
|
|
10
|
+
Check,
|
|
11
|
+
Copy,
|
|
12
|
+
Magnet,
|
|
13
|
+
RotateCcw,
|
|
14
|
+
} from 'lucide-react';
|
|
15
|
+
import type { MixState } from '@terrafirmagreg-team/recipe/hooks/alloy/use-mix-state';
|
|
16
|
+
|
|
17
|
+
export function MixStatus({ state }: { state: MixState }) {
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
const {
|
|
20
|
+
mix,
|
|
21
|
+
fix,
|
|
22
|
+
needsSnap,
|
|
23
|
+
snapped,
|
|
24
|
+
factor,
|
|
25
|
+
totalNumber,
|
|
26
|
+
unit,
|
|
27
|
+
ratioMix,
|
|
28
|
+
output,
|
|
29
|
+
unitLabel,
|
|
30
|
+
format,
|
|
31
|
+
copyText,
|
|
32
|
+
trim,
|
|
33
|
+
setInputs,
|
|
34
|
+
fill,
|
|
35
|
+
} = state;
|
|
36
|
+
const { checked: copied, onClick: onCopy } = useCopyButton(() =>
|
|
37
|
+
navigator.clipboard.writeText(copyText),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
aria-live="polite"
|
|
43
|
+
className="flex flex-wrap items-center gap-3 rounded-md border bg-muted/40 px-3 py-2"
|
|
44
|
+
>
|
|
45
|
+
<Badge variant={mix.valid ? 'default' : 'destructive'}>
|
|
46
|
+
{mix.valid ? t('recipe.alloy.valid') : t('recipe.alloy.invalid')}
|
|
47
|
+
</Badge>
|
|
48
|
+
<span className="flex flex-wrap items-baseline gap-x-3">
|
|
49
|
+
<span className="text-sm text-muted-foreground tabular-nums">
|
|
50
|
+
{t('recipe.alloy.total_in')}: {format(mix.total)} {unitLabel}
|
|
51
|
+
</span>
|
|
52
|
+
<span className="flex items-center gap-1.5 text-sm tabular-nums font-medium">
|
|
53
|
+
<span className="text-muted-foreground">→</span>
|
|
54
|
+
{output ? (
|
|
55
|
+
<Entry
|
|
56
|
+
id={output.id}
|
|
57
|
+
kind={output.kind === 'fluid' ? 'fluid' : 'item'}
|
|
58
|
+
size="sm"
|
|
59
|
+
labeled
|
|
60
|
+
href={false}
|
|
61
|
+
tooltip={false}
|
|
62
|
+
/>
|
|
63
|
+
) : (
|
|
64
|
+
t('recipe.alloy.result')
|
|
65
|
+
)}
|
|
66
|
+
<span className="font-normal text-muted-foreground">
|
|
67
|
+
{format(mix.output)} {unitLabel}
|
|
68
|
+
</span>
|
|
69
|
+
</span>
|
|
70
|
+
</span>
|
|
71
|
+
<span className="ms-auto flex flex-wrap items-center gap-2">
|
|
72
|
+
<IconButton
|
|
73
|
+
label={`${t('recipe.alloy.fix')} — ${t('recipe.alloy.hint.fix')}`}
|
|
74
|
+
disabled={!fix || mix.valid}
|
|
75
|
+
onClick={() =>
|
|
76
|
+
fix &&
|
|
77
|
+
setInputs((prev) =>
|
|
78
|
+
prev.map((value, i) => trim((Number(value) || 0) + fix[i])),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
<ArrowUpToLine className="size-3.5" />
|
|
83
|
+
</IconButton>
|
|
84
|
+
{needsSnap ? (
|
|
85
|
+
<IconButton
|
|
86
|
+
label={`${t('recipe.alloy.snap_ingots')} — ${t('recipe.alloy.hint.snap')}`}
|
|
87
|
+
disabled={!snapped}
|
|
88
|
+
onClick={() =>
|
|
89
|
+
snapped && setInputs(snapped.map((value) => trim(value / factor)))
|
|
90
|
+
}
|
|
91
|
+
>
|
|
92
|
+
<Magnet className="size-3.5" />
|
|
93
|
+
</IconButton>
|
|
94
|
+
) : (
|
|
95
|
+
<span className="size-7 shrink-0" aria-hidden />
|
|
96
|
+
)}
|
|
97
|
+
<IconButton
|
|
98
|
+
label={`${t('recipe.alloy.reset')} — ${t('recipe.alloy.hint.reset')}`}
|
|
99
|
+
onClick={() =>
|
|
100
|
+
fill(
|
|
101
|
+
Number.isFinite(totalNumber)
|
|
102
|
+
? totalNumber
|
|
103
|
+
: unit === 'ingot'
|
|
104
|
+
? (ratioMix?.total ?? 10)
|
|
105
|
+
: 144,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
>
|
|
109
|
+
<RotateCcw className="size-3.5" />
|
|
110
|
+
</IconButton>
|
|
111
|
+
<IconButton label={t('recipe.alloy.copy_mix')} onClick={onCopy}>
|
|
112
|
+
{copied ? (
|
|
113
|
+
<Check className="size-3.5 text-green-600 dark:text-green-400" />
|
|
114
|
+
) : (
|
|
115
|
+
<Copy className="size-3.5" />
|
|
116
|
+
)}
|
|
117
|
+
</IconButton>
|
|
118
|
+
</span>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|