@terrafirmagreg-team/recipe 0.0.0-stage → 1.2.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.
Files changed (221) hide show
  1. package/package.json +62 -3
  2. package/src/components/button-copy.tsx +43 -0
  3. package/src/components/cards/card/index.tsx +214 -0
  4. package/src/components/cards/card/scene.tsx +107 -0
  5. package/src/components/cards/card/strip.tsx +198 -0
  6. package/src/components/cards/card/text.tsx +46 -0
  7. package/src/components/cards/card/tips.tsx +63 -0
  8. package/src/components/cards/default-item.tsx +47 -0
  9. package/src/components/cards/glare-filter.tsx +29 -0
  10. package/src/components/cards/paged-card.tsx +222 -0
  11. package/src/components/cards/slot-hitbox.tsx +213 -0
  12. package/src/components/cards/strip-card/buttons.tsx +106 -0
  13. package/src/components/cards/strip-card/index.tsx +214 -0
  14. package/src/components/cards/strip-card/member-cell.tsx +167 -0
  15. package/src/components/cards/strip-card/sprite.tsx +36 -0
  16. package/src/components/embed-card.tsx +44 -0
  17. package/src/components/mdx/recipe.tsx +129 -0
  18. package/src/components/tool-list.tsx +49 -0
  19. package/src/components/tree.tsx +98 -0
  20. package/src/components/views/alloy/index.tsx +112 -0
  21. package/src/components/views/alloy/list.tsx +85 -0
  22. package/src/components/views/alloy/mix/index.tsx +35 -0
  23. package/src/components/views/alloy/mix/ratio.tsx +94 -0
  24. package/src/components/views/alloy/mix/rows.tsx +145 -0
  25. package/src/components/views/alloy/mix/status.tsx +122 -0
  26. package/src/components/views/alloy/mix/total.tsx +132 -0
  27. package/src/components/views/alloy/range-bar.tsx +65 -0
  28. package/src/components/views/alloy/stack-bar.tsx +88 -0
  29. package/src/components/views/browser/axis-switcher.tsx +54 -0
  30. package/src/components/views/browser/card-grid.tsx +275 -0
  31. package/src/components/views/browser/favorite-button.tsx +46 -0
  32. package/src/components/views/browser/frame.tsx +112 -0
  33. package/src/components/views/browser/index.tsx +114 -0
  34. package/src/components/views/browser/item-panel/index.tsx +229 -0
  35. package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
  36. package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
  37. package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
  38. package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
  39. package/src/components/views/browser/item-view/index.tsx +186 -0
  40. package/src/components/views/browser/item-view/tags.tsx +85 -0
  41. package/src/components/views/browser/item-view-header.tsx +131 -0
  42. package/src/components/views/browser/pane-tabs.tsx +61 -0
  43. package/src/components/views/browser/place-header.tsx +72 -0
  44. package/src/components/views/browser/query-controls.tsx +105 -0
  45. package/src/components/views/browser/recipe-item-header.tsx +60 -0
  46. package/src/components/views/browser/settings.tsx +52 -0
  47. package/src/components/views/browser/toolbar.tsx +54 -0
  48. package/src/components/views/browser/type-tabs.tsx +71 -0
  49. package/src/components/views/browser/type-view.tsx +184 -0
  50. package/src/components/views/browser/workstation-rail.tsx +43 -0
  51. package/src/components/views/calc/calculator/actions.tsx +47 -0
  52. package/src/components/views/calc/calculator/help.tsx +189 -0
  53. package/src/components/views/calc/calculator/index.tsx +172 -0
  54. package/src/components/views/calc/dot-overlay.tsx +80 -0
  55. package/src/components/views/calc/edge.tsx +152 -0
  56. package/src/components/views/calc/flow/index.tsx +305 -0
  57. package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
  58. package/src/components/views/calc/flow/toolbar.tsx +60 -0
  59. package/src/components/views/calc/flow/view-menu.tsx +117 -0
  60. package/src/components/views/calc/member-picker.tsx +120 -0
  61. package/src/components/views/calc/node-card/actions.tsx +90 -0
  62. package/src/components/views/calc/node-card/badges.tsx +59 -0
  63. package/src/components/views/calc/node-card/chips.tsx +187 -0
  64. package/src/components/views/calc/node-card/far.tsx +123 -0
  65. package/src/components/views/calc/node-card/full.tsx +332 -0
  66. package/src/components/views/calc/node-card/index.tsx +27 -0
  67. package/src/components/views/calc/node-card/menu.tsx +282 -0
  68. package/src/components/views/calc/node-card/port-cells.tsx +186 -0
  69. package/src/components/views/calc/node-card/port-rails.tsx +251 -0
  70. package/src/components/views/calc/node-card/ports.tsx +86 -0
  71. package/src/components/views/calc/recipe-picker/body.tsx +207 -0
  72. package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
  73. package/src/components/views/calc/recipe-picker/index.tsx +52 -0
  74. package/src/components/views/calc/sidebar.tsx +171 -0
  75. package/src/components/views/calc/trees/icon-picker.tsx +97 -0
  76. package/src/components/views/calc/trees/index.tsx +134 -0
  77. package/src/components/views/calc/trees/label.tsx +67 -0
  78. package/src/components/views/calc/trees/rows.tsx +140 -0
  79. package/src/components/views/forge/gui.tsx +131 -0
  80. package/src/components/views/forge/index.tsx +112 -0
  81. package/src/components/views/forge/list.tsx +113 -0
  82. package/src/components/views/forge/workbench/controls.tsx +103 -0
  83. package/src/components/views/forge/workbench/index.tsx +85 -0
  84. package/src/components/views/forge/workbench/panel.tsx +228 -0
  85. package/src/components/views/forge/workbench/ruler.tsx +133 -0
  86. package/src/components/views/forge/workbench/status.tsx +55 -0
  87. package/src/components/views/forge/workbench/tape.tsx +70 -0
  88. package/src/hooks/alloy/use-fluid-colors.ts +125 -0
  89. package/src/hooks/alloy/use-mix-state.ts +240 -0
  90. package/src/hooks/calc/flow/use-engage.ts +129 -0
  91. package/src/hooks/calc/flow/use-handlers.ts +192 -0
  92. package/src/hooks/calc/flow/use-layout.ts +105 -0
  93. package/src/hooks/calc/flow/use-mount.ts +97 -0
  94. package/src/hooks/calc/flow/use-nodes.ts +260 -0
  95. package/src/hooks/calc/flow/use-pickers.ts +57 -0
  96. package/src/hooks/calc/flow/use-viewport.ts +141 -0
  97. package/src/hooks/calc/flow/use-window.ts +87 -0
  98. package/src/hooks/calc/use-actions.ts +355 -0
  99. package/src/hooks/calc/use-amounts.ts +64 -0
  100. package/src/hooks/calc/use-data.ts +203 -0
  101. package/src/hooks/calc/use-defaults.ts +40 -0
  102. package/src/hooks/calc/use-far-mode.ts +37 -0
  103. package/src/hooks/calc/use-focus.ts +31 -0
  104. package/src/hooks/calc/use-maps.ts +76 -0
  105. package/src/hooks/calc/use-reset.ts +15 -0
  106. package/src/hooks/calc/use-resolver.ts +70 -0
  107. package/src/hooks/calc/use-session.ts +13 -0
  108. package/src/hooks/calc/use-share.ts +64 -0
  109. package/src/hooks/calc/use-storage.ts +126 -0
  110. package/src/hooks/calc/use-tier.ts +13 -0
  111. package/src/hooks/calc/use-view-mode.ts +24 -0
  112. package/src/hooks/calc/use-worker.ts +204 -0
  113. package/src/hooks/forge/use-anvil-gui.ts +16 -0
  114. package/src/hooks/forge/use-forge-state.ts +135 -0
  115. package/src/hooks/forge/use-ruler.ts +100 -0
  116. package/src/hooks/use-add-to-calc.ts +51 -0
  117. package/src/hooks/use-categories-by-id.ts +18 -0
  118. package/src/hooks/use-favorite-hotkey.ts +39 -0
  119. package/src/hooks/use-favorites.ts +135 -0
  120. package/src/hooks/use-group-outlines.ts +65 -0
  121. package/src/hooks/use-hide-unused.ts +12 -0
  122. package/src/hooks/use-index.ts +72 -0
  123. package/src/hooks/use-item-feeds.ts +46 -0
  124. package/src/hooks/use-item-pane.ts +106 -0
  125. package/src/hooks/use-item-press.ts +89 -0
  126. package/src/hooks/use-item-tag-groups.ts +54 -0
  127. package/src/hooks/use-item-tooltips.ts +18 -0
  128. package/src/hooks/use-left-sidebar-tree.ts +34 -0
  129. package/src/hooks/use-mod-names.ts +17 -0
  130. package/src/hooks/use-mount-limit.ts +22 -0
  131. package/src/hooks/use-panel-cells.ts +117 -0
  132. package/src/hooks/use-panel-page.ts +54 -0
  133. package/src/hooks/use-panel-tabs.ts +43 -0
  134. package/src/hooks/use-query.ts +186 -0
  135. package/src/hooks/use-session.ts +88 -0
  136. package/src/hooks/use-sidebar-group.ts +16 -0
  137. package/src/hooks/use-tag-members.ts +16 -0
  138. package/src/hooks/use-tool-recipes.ts +26 -0
  139. package/src/hooks/use-type-filter.ts +73 -0
  140. package/src/lib/alloy/mix.ts +210 -0
  141. package/src/lib/alloy/parse.ts +37 -0
  142. package/src/lib/calc/defaults.ts +47 -0
  143. package/src/lib/calc/flow.ts +315 -0
  144. package/src/lib/calc/focus.ts +15 -0
  145. package/src/lib/calc/meta.ts +17 -0
  146. package/src/lib/calc/pack.ts +77 -0
  147. package/src/lib/calc/ports.ts +43 -0
  148. package/src/lib/calc/resolve.ts +198 -0
  149. package/src/lib/calc/route/buckets.ts +49 -0
  150. package/src/lib/calc/route/geometry.ts +51 -0
  151. package/src/lib/calc/route/index.ts +3 -0
  152. package/src/lib/calc/route/polyline.ts +103 -0
  153. package/src/lib/calc/route/router.ts +394 -0
  154. package/src/lib/calc/scheme.ts +226 -0
  155. package/src/lib/calc/storage/entry.ts +97 -0
  156. package/src/lib/calc/storage/index.ts +20 -0
  157. package/src/lib/calc/storage/keys.ts +38 -0
  158. package/src/lib/calc/storage/store.ts +198 -0
  159. package/src/lib/calc/tree/index.ts +4 -0
  160. package/src/lib/calc/tree/materials.ts +29 -0
  161. package/src/lib/calc/tree/recipe.ts +104 -0
  162. package/src/lib/calc/tree/share.ts +135 -0
  163. package/src/lib/calc/worker/api.ts +25 -0
  164. package/src/lib/calc/worker/fetch.ts +66 -0
  165. package/src/lib/calc/worker/flush.ts +39 -0
  166. package/src/lib/calc/worker/index.ts +8 -0
  167. package/src/lib/calc/worker/protocol.ts +35 -0
  168. package/src/lib/calc/worker/resolve.ts +49 -0
  169. package/src/lib/calc/worker/state.ts +48 -0
  170. package/src/lib/card-model.ts +65 -0
  171. package/src/lib/client/recipe-categories.ts +14 -0
  172. package/src/lib/client/recipe.ts +85 -0
  173. package/src/lib/client-index/catalog.ts +91 -0
  174. package/src/lib/client-index/chrome.ts +180 -0
  175. package/src/lib/client-index/index.ts +20 -0
  176. package/src/lib/client-index/registry.ts +121 -0
  177. package/src/lib/client-index/rows.ts +260 -0
  178. package/src/lib/client-index/tooltips.ts +74 -0
  179. package/src/lib/config.ts +18 -0
  180. package/src/lib/data/category/dto.ts +25 -0
  181. package/src/lib/data/category/load.ts +47 -0
  182. package/src/lib/data/category/parse.ts +71 -0
  183. package/src/lib/data/dto.ts +152 -0
  184. package/src/lib/data/grid.ts +40 -0
  185. package/src/lib/data/parse/entry.ts +85 -0
  186. package/src/lib/data/parse/index.ts +3 -0
  187. package/src/lib/data/parse/layout.ts +138 -0
  188. package/src/lib/data/parse/slots.ts +85 -0
  189. package/src/lib/data/parse/widgets.ts +81 -0
  190. package/src/lib/data/scene.ts +103 -0
  191. package/src/lib/data/slot-io.ts +44 -0
  192. package/src/lib/dump.ts +6 -0
  193. package/src/lib/embed.ts +22 -0
  194. package/src/lib/favorite-hover.ts +13 -0
  195. package/src/lib/fluid-outputs.ts +70 -0
  196. package/src/lib/forge/actions.ts +59 -0
  197. package/src/lib/forge/data.ts +51 -0
  198. package/src/lib/forge/solve.ts +80 -0
  199. package/src/lib/group.ts +23 -0
  200. package/src/lib/index-store.ts +70 -0
  201. package/src/lib/links.ts +131 -0
  202. package/src/lib/lookup.ts +119 -0
  203. package/src/lib/panel-outline.ts +86 -0
  204. package/src/lib/panel.ts +105 -0
  205. package/src/lib/preview.ts +32 -0
  206. package/src/lib/recipe-slots.ts +8 -0
  207. package/src/lib/search.ts +139 -0
  208. package/src/lib/sidebar.ts +47 -0
  209. package/src/lib/used-items.ts +25 -0
  210. package/src/locales/en_us.json +172 -0
  211. package/src/locales/ru_ru.json +172 -0
  212. package/src/locales.ts +6 -0
  213. package/src/types/alloy.ts +20 -0
  214. package/src/types/calc-flow-props.ts +44 -0
  215. package/src/types/calc.ts +92 -0
  216. package/src/types/forge.ts +21 -0
  217. package/src/types/index.ts +136 -0
  218. package/styles/calc.css +308 -0
  219. package/styles/strip.css +7 -0
  220. package/styles.css +2 -0
  221. package/README.md +0 -3
@@ -0,0 +1,98 @@
1
+ import 'server-only';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+ import { createElement } from 'react';
4
+ import type * as PageTree from 'fumadocs-core/page-tree';
5
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
6
+ import { loadMergedLangMap, creativeTabName } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/load';
7
+ import { loadClientManifest } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
8
+ import { DUMP_POINTER_TTL } from '@terrafirmagreg-team/dump/lib/dump/json-reader';
9
+ import { createAsyncCache } from '@terrafirmagreg-team/data/lib/async-cache';
10
+ import { loadDatasetRecipeCategories } from '@terrafirmagreg-team/recipe/lib/data/category/load';
11
+ import { keyTreeNode } from '@terrafirmagreg-team/translate/server';
12
+ import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
13
+ import { encodeQueryValue } from '@terrafirmagreg-team/translate/lib/url';
14
+ import { recipeBasePath } from '@terrafirmagreg-team/recipe/lib/links';
15
+ import { sectionDatasets } from '@terrafirmagreg-team/kit/lib/datasets';
16
+ import type { DumpRecipeCategory } from '@terrafirmagreg-team/recipe/lib/data/category/dto';
17
+ import type { SectionTrees } from '@terrafirmagreg-team/kit/types';
18
+
19
+ function categoryIcon(
20
+ dataset: DatasetRef,
21
+ category: DumpRecipeCategory,
22
+ ): React.ReactNode {
23
+ if (!category.icon) return undefined;
24
+ return createElement(
25
+ 'span',
26
+ { className: 'inline-flex size-4 shrink-0 items-center justify-center' },
27
+ createElement(Entry, {
28
+ dataset,
29
+ reference: category.icon,
30
+ name: category.id,
31
+ size: 'sm',
32
+ href: false,
33
+ tooltip: false,
34
+ missing: 'hide',
35
+ }),
36
+ );
37
+ }
38
+
39
+ function categoryLeaf(
40
+ dataset: DatasetRef,
41
+ category: DumpRecipeCategory,
42
+ map: Record<string, string>,
43
+ ): PageTree.Item {
44
+ return keyTreeNode({
45
+ type: 'page',
46
+ name: creativeTabName(map, category.display?.name),
47
+ url: `${recipeBasePath(dataset)}?type=${encodeQueryValue(category.id)}`,
48
+ icon: categoryIcon(dataset, category),
49
+ $id: `${dataset.id}/${dataset.version ?? ''}/type/${category.id}`,
50
+ }) as PageTree.Item;
51
+ }
52
+
53
+ const recipeTreesCache = createAsyncCache(
54
+ async (): Promise<SectionTrees> => buildRecipeTrees(),
55
+ () => 'recipe-trees',
56
+ DUMP_POINTER_TTL,
57
+ );
58
+
59
+ export function recipeTrees(): Promise<SectionTrees> {
60
+ return recipeTreesCache();
61
+ }
62
+
63
+ async function buildRecipeTrees(): Promise<SectionTrees> {
64
+ const { defaultLanguage } = loadLocaleRegistry();
65
+ const datasets = await sectionDatasets('recipe');
66
+ const trees: SectionTrees = {};
67
+ for (const { id, title: datasetTitle, languages } of datasets) {
68
+ for (const lang of languages ?? [defaultLanguage]) {
69
+ const ref = { id };
70
+ const map = await loadMergedLangMap(ref, lang);
71
+ const categories = await loadDatasetRecipeCategories(ref);
72
+ const types = (await loadClientManifest(ref))?.indexes.recipes.types;
73
+ const nonEmpty = types
74
+ ? new Set(
75
+ types
76
+ .filter((row) => (row.count ?? 0) > 0)
77
+ .map((row) => row.id),
78
+ )
79
+ : undefined;
80
+ const leaves = [...categories]
81
+ .filter((category) => !nonEmpty || nonEmpty.has(category.id))
82
+ .sort(
83
+ (a, b) =>
84
+ creativeTabName(map, a.display?.name).localeCompare(
85
+ creativeTabName(map, b.display?.name),
86
+ ) || a.id.localeCompare(b.id),
87
+ )
88
+ .map((category) => categoryLeaf(ref, category, map));
89
+ (trees[lang] ??= {})[id] = {
90
+ name: datasetTitle ?? id,
91
+ children: leaves,
92
+ $id: `recipe/${id}/${lang}`,
93
+ } satisfies PageTree.Root;
94
+ }
95
+ }
96
+ return trees;
97
+ }
98
+
@@ -0,0 +1,112 @@
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 { FitBox } from '@terrafirmagreg-team/ui/components/blocks/fit-box';
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('Alloys', { note: 'recipe.alloy.title' })} />
71
+ )
72
+ }
73
+ >
74
+ <div className="scrollbar-thin 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('Could not load recipes. Reload the page to retry.', { note: 'recipe.alloy.load_error' })}
80
+ </EmptyState>
81
+ ) : active ? (
82
+ <>
83
+ <AlloyMix
84
+ key={active.recipe.id}
85
+ recipe={active}
86
+ session={session}
87
+ />
88
+ <FitBox w={active.recipe.w ?? 0}>
89
+ <AlloyRecipeCard
90
+ key={active.recipe.id}
91
+ recipe={active.recipe}
92
+ session={session}
93
+ />
94
+ </FitBox>
95
+ </>
96
+ ) : (
97
+ <EmptyState>
98
+ {activeId
99
+ ? t('Recipe not found in this dump. Select another alloy.', {
100
+ note: 'recipe.alloy.missing',
101
+ })
102
+ : t('No matching recipes in this dump.', {
103
+ note: 'recipe.alloy.empty',
104
+ })}
105
+ </EmptyState>
106
+ )}
107
+ </div>
108
+ </RecipeFrame>
109
+ </>
110
+ );
111
+ }
112
+
@@ -0,0 +1,85 @@
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('Search alloys', { note: 'recipe.alloy.search' })}
81
+ emptyLabel={t('No matching recipes in this dump.', { note: 'recipe.alloy.empty' })}
82
+ />
83
+ );
84
+ }
85
+
@@ -0,0 +1,35 @@
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
+ }
35
+
@@ -0,0 +1,94 @@
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 ratio in ingots', { note: '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('Apply the recipe ratio multiplied', { note: '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('Apply', { note: 'recipe.alloy.apply' })}
65
+ </TooltipTrigger>
66
+ <TooltipContent>{t('Fill fields with the recipe ratio in whole ingots', { note: '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('ing.', { note: 'recipe.alloy.unit.ingot' })} (
88
+ {(ratioMix.total * INGOT_MB).toLocaleString()} {t('mB', { note: 'recipe.alloy.unit.mb' })})
89
+ </span>
90
+ </div>
91
+ </div>
92
+ );
93
+ }
94
+
@@ -0,0 +1,145 @@
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 '@terrafirmagreg-team/ui/lib/utils/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('Allowed window', { note: '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('Remove 1', { note: '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('Add 1', { note: '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('Minimize', { note: 'recipe.alloy.economize' })} ${name(slot.id)}: ${t('Set this metal to the lower bound of its range; others keep the recipe ratio', { note: 'recipe.alloy.hint.economize' })}`}
127
+ size="icon-xs"
128
+ disabled={!econ}
129
+ onClick={() =>
130
+ econ && setInputs(econ.map((value) => trim(value)))
131
+ }
132
+ >
133
+ <TrendingDown />
134
+ </IconButton>
135
+ ) : (
136
+ <span className="size-6 shrink-0" aria-hidden />
137
+ )}
138
+ </span>
139
+ </li>
140
+ );
141
+ })}
142
+ </ul>
143
+ );
144
+ }
145
+