@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,152 @@
1
+ import type { TaggedReference } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
2
+ import type { DumpText } from '@terrafirmagreg-team/dump/lib/dump/contract/text';
3
+ import type { RecipeEntry, RecipeSlot } from '@terrafirmagreg-team/dump/lib/dump/gen';
4
+
5
+ export const RECIPE_SLOT_TYPES = [
6
+ 'input',
7
+ 'output',
8
+ 'catalyst',
9
+ 'tank',
10
+ 'renderOnly',
11
+ ] as const;
12
+
13
+ export type RecipeSlotType = (typeof RECIPE_SLOT_TYPES)[number];
14
+
15
+ export type IngredientKind = 'item' | 'fluid' | 'tag';
16
+
17
+ export type RecipeIngredient = {
18
+ kind: IngredientKind;
19
+ id: string;
20
+ count?: number;
21
+ chance?: number;
22
+ x?: number;
23
+ y?: number;
24
+ };
25
+
26
+ export type RecipeSlotFill = Omit<
27
+ RecipeSlot,
28
+ 'amount' | 'ref' | 'type' | 'alternatives'
29
+ > & {
30
+ type: RecipeSlotType;
31
+ ref: TaggedReference;
32
+ amount: number;
33
+ kind: IngredientKind;
34
+ id: string;
35
+ count?: number;
36
+ alternatives?: TaggedReference[];
37
+ };
38
+
39
+ export type RecipeSlotWidget = {
40
+ type: 'slot';
41
+ x: number;
42
+ y: number;
43
+ w: number;
44
+ h: number;
45
+ role: string;
46
+ kind: IngredientKind;
47
+
48
+ tagKind?: string;
49
+ id: string;
50
+
51
+ count?: number;
52
+
53
+ chance?: number;
54
+
55
+ alternatives?: string[];
56
+ };
57
+
58
+ export type RecipeTextWidget = {
59
+ type: 'text';
60
+ x: number;
61
+ y: number;
62
+ w: number;
63
+ h: number;
64
+ text: string;
65
+
66
+ component?: DumpText;
67
+
68
+ color?: number;
69
+
70
+ shadow?: boolean;
71
+ tooltip?: string[];
72
+ };
73
+
74
+ export type RecipeGrid = {
75
+
76
+ y: number;
77
+
78
+ row: number;
79
+
80
+ tail: number;
81
+ cols: number;
82
+
83
+ rows: number;
84
+ };
85
+
86
+ export type RecipeGridMember = {
87
+ id: string;
88
+ kind?: string;
89
+ amount?: number;
90
+ chance?: number;
91
+ };
92
+
93
+ export type RecipeTextureWidget = {
94
+ type: 'texture' | 'animated';
95
+ x: number;
96
+ y: number;
97
+ w: number;
98
+ h: number;
99
+ texture: string;
100
+ u?: number;
101
+ v?: number;
102
+ regionW?: number;
103
+ regionH?: number;
104
+ time?: number;
105
+ horizontal?: boolean;
106
+ endToStart?: boolean;
107
+ fullToEmpty?: boolean;
108
+ textureW?: number;
109
+ textureH?: number;
110
+ tooltip?: string[];
111
+ };
112
+
113
+ export type RecipeDecorWidget = {
114
+ type: 'widget';
115
+ x: number;
116
+ y: number;
117
+ w: number;
118
+ h: number;
119
+ tooltip?: string[];
120
+ };
121
+
122
+ export type RecipeWidget =
123
+ | RecipeSlotWidget
124
+ | RecipeTextWidget
125
+ | RecipeTextureWidget
126
+ | RecipeDecorWidget;
127
+
128
+ export type Recipe = Omit<
129
+ RecipeEntry,
130
+ 'image' | 'w' | 'h' | 'properties' | 'slots'
131
+ > & {
132
+ id: string;
133
+ type: string;
134
+ modId: string;
135
+ slots: Record<string, RecipeSlotFill>;
136
+ properties: Record<string, unknown>;
137
+ inputs: RecipeIngredient[];
138
+ outputs: RecipeIngredient[];
139
+ pattern?: string[];
140
+ width?: number;
141
+ height?: number;
142
+ scale?: number;
143
+ margin?: number;
144
+ widgets: RecipeWidget[];
145
+ bodyUrl: string;
146
+
147
+ image?: string;
148
+ w?: number;
149
+ h?: number;
150
+ extra: Record<string, unknown>;
151
+ };
152
+
@@ -0,0 +1,40 @@
1
+ import {
2
+ asNumber,
3
+ asRecord,
4
+ asString,
5
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
6
+ import type { RecipeGrid, RecipeGridMember } from '@terrafirmagreg-team/recipe/lib/data/dto';
7
+
8
+ export function recipeGrid(
9
+ properties: Record<string, unknown> | undefined,
10
+ ): { grid: RecipeGrid; members: RecipeGridMember[] } | undefined {
11
+ const raw = asRecord(properties?.grid);
12
+ if (!raw) return undefined;
13
+ const y = asNumber(raw.y);
14
+ const row = asNumber(raw.row);
15
+ const cols = asNumber(raw.cols);
16
+ const rows = asNumber(raw.rows);
17
+ if (y === undefined || !row || !cols || !rows) return undefined;
18
+ const members = Array.isArray(properties?.members)
19
+ ? properties.members.flatMap((item) => {
20
+ const record = asRecord(item);
21
+ const id = asString(record?.id ?? item);
22
+ if (!id) return [];
23
+ const kind = asString(record?.kind);
24
+ const amount = asNumber(record?.amount);
25
+ const chance = asNumber(record?.chance);
26
+ return [
27
+ {
28
+ id,
29
+ ...(kind ? { kind } : {}),
30
+ ...(amount !== undefined ? { amount } : {}),
31
+ ...(chance !== undefined ? { chance } : {}),
32
+ },
33
+ ];
34
+ })
35
+ : [];
36
+ if (!members.length) return undefined;
37
+ const tail = asNumber(raw.tail) ?? 0;
38
+ return { grid: { y, row, tail, cols, rows }, members };
39
+ }
40
+
@@ -0,0 +1,85 @@
1
+ import { stackDisplayName } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
2
+ import { asNumber, asRecord, asString } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
3
+ import type { DumpRecipeLayout } from '@terrafirmagreg-team/recipe/lib/data/category/dto';
4
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
5
+ import { hydrateRecipe } from './layout';
6
+ import { parseSlots } from './slots';
7
+ import { parseDecorWidgets } from './widgets';
8
+
9
+ function parseProperties(value: unknown): Record<string, unknown> {
10
+ const row = asRecord(value);
11
+ return row ? { ...row } : {};
12
+ }
13
+
14
+ function recipeModId(id: string): string {
15
+ const colon = id.indexOf(':');
16
+ return colon > 0 ? id.slice(0, colon) : id;
17
+ }
18
+
19
+ export function parseRecipe(
20
+ raw: unknown,
21
+ ctx: {
22
+ modId?: string;
23
+ bodyUrl: string;
24
+ id?: string;
25
+ layout?: DumpRecipeLayout;
26
+ },
27
+ ): Recipe | undefined {
28
+ const row = asRecord(raw);
29
+ if (!row) return undefined;
30
+ const id = ctx.id ?? asString(row.id);
31
+ if (!id) return undefined;
32
+ const category = asString(row.category);
33
+ if (!category) return undefined;
34
+ const slots = parseSlots(row.slots);
35
+ const decorWidgets = parseDecorWidgets(row.widgets);
36
+ const properties = parseProperties(row.properties);
37
+ const image = asString(row.image);
38
+ const w = asNumber(row.w);
39
+ const h = asNumber(row.h);
40
+ const extra: Record<string, unknown> = {};
41
+ for (const [key, value] of Object.entries(row)) {
42
+ if (
43
+ key === 'category' ||
44
+ key === 'slots' ||
45
+ key === 'widgets' ||
46
+ key === 'properties' ||
47
+ key === 'image' ||
48
+ key === 'w' ||
49
+ key === 'h'
50
+ ) {
51
+ continue;
52
+ }
53
+ extra[key] = value;
54
+ }
55
+ const recipe: Recipe = {
56
+ id,
57
+ type: category,
58
+ modId: ctx.modId ?? recipeModId(id),
59
+ category,
60
+ slots,
61
+ properties,
62
+ inputs: [],
63
+ outputs: [],
64
+ widgets: decorWidgets,
65
+ bodyUrl: ctx.bodyUrl,
66
+ ...(image ? { image } : {}),
67
+ ...(w !== undefined ? { w } : {}),
68
+ ...(h !== undefined ? { h } : {}),
69
+ extra,
70
+ };
71
+ return hydrateRecipe(recipe, ctx.layout);
72
+ }
73
+
74
+ export function recipeTitle(
75
+ recipe: Pick<Recipe, 'id' | 'outputs'>,
76
+ map: Record<string, string>,
77
+ ): string {
78
+ const main = recipe.outputs[0];
79
+ if (main) {
80
+ const name = stackDisplayName(map, main.id);
81
+ if (name !== main.id) return name;
82
+ }
83
+ return recipe.id;
84
+ }
85
+
@@ -0,0 +1,3 @@
1
+ export { parseRecipe, recipeTitle } from './entry';
2
+ export { hydrateRecipe } from './layout';
3
+
@@ -0,0 +1,138 @@
1
+ import { stackIdFromRef } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
2
+ import type { DumpRecipeLayout } from '@terrafirmagreg-team/recipe/lib/data/category/dto';
3
+ import type {
4
+ Recipe,
5
+ RecipeIngredient,
6
+ RecipeWidget,
7
+ } from '@terrafirmagreg-team/recipe/lib/data/dto';
8
+ import {
9
+ outputBoundary,
10
+ slotIoRole,
11
+ } from '@terrafirmagreg-team/recipe/lib/data/slot-io';
12
+ import { tagKindFromRef } from './slots';
13
+
14
+ function recipeIo(
15
+ recipe: Pick<Recipe, 'slots'>,
16
+ layout?: DumpRecipeLayout,
17
+ ): {
18
+ inputs: RecipeIngredient[];
19
+ outputs: RecipeIngredient[];
20
+ catalysts: RecipeIngredient[];
21
+ } {
22
+ const byId = new Map((layout?.slots ?? []).map((slot) => [slot.id, slot]));
23
+ const boundary = outputBoundary(recipe.slots, layout);
24
+ const inputs: RecipeIngredient[] = [];
25
+ const outputs: RecipeIngredient[] = [];
26
+ const catalysts: RecipeIngredient[] = [];
27
+ for (const [slotId, fill] of Object.entries(recipe.slots)) {
28
+ if (fill.type === 'renderOnly') continue;
29
+ const laid = byId.get(slotId);
30
+ const x = fill.x ?? laid?.x;
31
+ const role = slotIoRole(fill.type, x, boundary);
32
+ const y = fill.y ?? laid?.y;
33
+ const ingredient: RecipeIngredient = {
34
+ kind: fill.kind,
35
+ id: fill.id,
36
+ ...(fill.count !== undefined ? { count: fill.count } : {}),
37
+ ...(fill.chance !== undefined ? { chance: fill.chance } : {}),
38
+ ...(x !== undefined ? { x } : {}),
39
+ ...(y !== undefined ? { y } : {}),
40
+ };
41
+ if (role === 'output') outputs.push(ingredient);
42
+ else if (role === 'catalyst') catalysts.push(ingredient);
43
+ else inputs.push(ingredient);
44
+ }
45
+ return { inputs, outputs, catalysts };
46
+ }
47
+
48
+ function positionedWidgets(
49
+ recipe: Pick<Recipe, 'slots'>,
50
+ covered: Set<string>,
51
+ ): RecipeWidget[] {
52
+ const out: RecipeWidget[] = [];
53
+ for (const [slotId, fill] of Object.entries(recipe.slots)) {
54
+ if (covered.has(slotId)) continue;
55
+ if (fill.x === undefined || fill.y === undefined) continue;
56
+ const tagKind = fill.kind === 'tag' ? tagKindFromRef(fill.ref) : undefined;
57
+ out.push({
58
+ type: 'slot',
59
+ x: fill.x,
60
+ y: fill.y,
61
+ w: fill.w ?? 16,
62
+ h: fill.h ?? 16,
63
+ role: fill.type,
64
+ kind: fill.kind,
65
+ ...(tagKind && tagKind !== 'item' ? { tagKind } : {}),
66
+ id: fill.id,
67
+ ...(fill.count !== undefined && fill.count !== 1
68
+ ? { count: fill.count }
69
+ : {}),
70
+ ...(fill.chance !== undefined ? { chance: fill.chance } : {}),
71
+ ...(fill.alternatives?.length
72
+ ? { alternatives: fill.alternatives.map(stackIdFromRef) }
73
+ : {}),
74
+ });
75
+ }
76
+ return out;
77
+ }
78
+
79
+ function widgetsFromLayout(
80
+ recipe: Pick<Recipe, 'slots'>,
81
+ layout: DumpRecipeLayout,
82
+ ): RecipeWidget[] {
83
+ const out: RecipeWidget[] = [];
84
+ for (const slot of layout.slots) {
85
+ const fill = recipe.slots[slot.id];
86
+ if (!fill || fill.type === 'renderOnly') continue;
87
+ const tagKind = fill.kind === 'tag' ? tagKindFromRef(fill.ref) : undefined;
88
+ const pos =
89
+ fill.x !== undefined && fill.y !== undefined
90
+ ? { x: fill.x, y: fill.y, w: fill.w ?? 16, h: fill.h ?? 16 }
91
+ : { x: slot.x, y: slot.y, w: slot.w, h: slot.h };
92
+ out.push({
93
+ type: 'slot',
94
+ ...pos,
95
+ role: fill.type,
96
+ kind: fill.kind,
97
+ ...(tagKind && tagKind !== 'item' ? { tagKind } : {}),
98
+ id: fill.id,
99
+ ...(fill.count !== undefined && fill.count !== 1
100
+ ? { count: fill.count }
101
+ : {}),
102
+ ...(fill.chance !== undefined ? { chance: fill.chance } : {}),
103
+ ...(fill.alternatives?.length
104
+ ? { alternatives: fill.alternatives.map(stackIdFromRef) }
105
+ : {}),
106
+ });
107
+ }
108
+ return out;
109
+ }
110
+
111
+ export function hydrateRecipe(recipe: Recipe, layout?: DumpRecipeLayout): Recipe {
112
+ const io = recipeIo(recipe, layout);
113
+ return {
114
+ ...recipe,
115
+ type: recipe.category,
116
+ inputs: io.inputs,
117
+ outputs: io.outputs,
118
+ widgets: [
119
+ ...(layout ? widgetsFromLayout(recipe, layout) : []),
120
+ ...positionedWidgets(
121
+ recipe,
122
+ new Set((layout?.slots ?? []).map((slot) => slot.id)),
123
+ ),
124
+ ...(recipe.widgets as RecipeWidget[]).filter(
125
+ (widget) => widget.type !== 'slot',
126
+ ),
127
+ ],
128
+ ...(layout
129
+ ? {
130
+ width: layout.w,
131
+ height: layout.h,
132
+ ...(layout.scale !== undefined ? { scale: layout.scale } : {}),
133
+ ...(layout.margin !== undefined ? { margin: layout.margin } : {}),
134
+ }
135
+ : {}),
136
+ };
137
+ }
138
+
@@ -0,0 +1,85 @@
1
+ import {
2
+ asTaggedReference,
3
+ stackIdFromRef,
4
+ type TaggedReference,
5
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
6
+ import { asNumber, asRecord } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
7
+ import type {
8
+ IngredientKind,
9
+ RecipeSlotFill,
10
+ RecipeSlotType,
11
+ } from '@terrafirmagreg-team/recipe/lib/data/dto';
12
+ import { RECIPE_SLOT_TYPES } from '@terrafirmagreg-team/recipe/lib/data/dto';
13
+
14
+ function asSlotType(value: unknown): RecipeSlotType | undefined {
15
+ return typeof value === 'string' &&
16
+ (RECIPE_SLOT_TYPES as readonly string[]).includes(value)
17
+ ? (value as RecipeSlotType)
18
+ : undefined;
19
+ }
20
+
21
+ export function kindFromRef(ref: TaggedReference): IngredientKind {
22
+ switch (ref.kind) {
23
+ case 'fluid':
24
+ return 'fluid';
25
+ case 'itemTag':
26
+ case 'blockTag':
27
+ case 'fluidTag':
28
+ case 'entityTag':
29
+ return 'tag';
30
+ default:
31
+ return 'item';
32
+ }
33
+ }
34
+
35
+ export function tagKindFromRef(ref: TaggedReference): string | undefined {
36
+ return ref.kind.endsWith('Tag')
37
+ ? ref.kind.slice(0, -'Tag'.length)
38
+ : undefined;
39
+ }
40
+
41
+ function parseSlotFill(value: unknown): RecipeSlotFill | undefined {
42
+ const row = asRecord(value);
43
+ if (!row) return undefined;
44
+ const type = asSlotType(row.type);
45
+ const ref = asTaggedReference(row.ref);
46
+ const amount = asNumber(row.amount);
47
+ if (!type || !ref || amount === undefined) return undefined;
48
+ const chance = asNumber(row.chance);
49
+ const x = asNumber(row.x);
50
+ const y = asNumber(row.y);
51
+ const w = asNumber(row.w);
52
+ const h = asNumber(row.h);
53
+ const alternatives = Array.isArray(row.alternatives)
54
+ ? row.alternatives.flatMap((item) => {
55
+ const tagged = asTaggedReference(item);
56
+ return tagged ? [tagged] : [];
57
+ })
58
+ : undefined;
59
+ return {
60
+ type,
61
+ ref,
62
+ amount,
63
+ ...(chance !== undefined ? { chance } : {}),
64
+ kind: kindFromRef(ref),
65
+ id: stackIdFromRef(ref),
66
+ count: amount,
67
+ ...(x !== undefined ? { x } : {}),
68
+ ...(y !== undefined ? { y } : {}),
69
+ ...(w !== undefined ? { w } : {}),
70
+ ...(h !== undefined ? { h } : {}),
71
+ ...(alternatives?.length ? { alternatives } : {}),
72
+ };
73
+ }
74
+
75
+ export function parseSlots(value: unknown): Record<string, RecipeSlotFill> {
76
+ const row = asRecord(value);
77
+ if (!row) return {};
78
+ const out: Record<string, RecipeSlotFill> = {};
79
+ for (const [slotId, fill] of Object.entries(row)) {
80
+ const parsed = parseSlotFill(fill);
81
+ if (parsed) out[slotId] = parsed;
82
+ }
83
+ return out;
84
+ }
85
+
@@ -0,0 +1,81 @@
1
+ import { asNumber, asRecord, asString } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
2
+ import { asDumpText } from '@terrafirmagreg-team/dump/lib/dump/contract/text';
3
+ import type { RecipeWidget } from '@terrafirmagreg-team/recipe/lib/data/dto';
4
+
5
+ function parseDecorWidget(value: unknown): RecipeWidget | undefined {
6
+ const row = asRecord(value);
7
+ if (!row) return undefined;
8
+ const type = asString(row.type);
9
+ const x = asNumber(row.x);
10
+ const y = asNumber(row.y);
11
+ const w = asNumber(row.w);
12
+ const h = asNumber(row.h);
13
+ if (!type || x === undefined || y === undefined) return undefined;
14
+ const tooltip = Array.isArray(row.tooltip)
15
+ ? row.tooltip.flatMap((line) => {
16
+ const text = asString(line);
17
+ return text ? [text] : [];
18
+ })
19
+ : undefined;
20
+ const box = { x, y, w: w ?? 0, h: h ?? 0 };
21
+ const tip = tooltip?.length ? { tooltip } : {};
22
+ if (type === 'text') {
23
+ const component = asDumpText(row.component);
24
+ const text = asString(row.text) ?? (component ? '' : undefined);
25
+ if (text === undefined) return undefined;
26
+ const color = asNumber(row.color);
27
+ const shadow = typeof row.shadow === 'boolean' ? row.shadow : undefined;
28
+ return {
29
+ type,
30
+ ...box,
31
+ text,
32
+ ...(component ? { component } : {}),
33
+ ...(color !== undefined ? { color } : {}),
34
+ ...(shadow !== undefined ? { shadow } : {}),
35
+ ...tip,
36
+ };
37
+ }
38
+ if (type === 'texture' || type === 'animated') {
39
+ const texture = asString(row.texture);
40
+ if (!texture) return undefined;
41
+ const u = asNumber(row.u);
42
+ const v = asNumber(row.v);
43
+ const regionW = asNumber(row.regionW);
44
+ const regionH = asNumber(row.regionH);
45
+ const time = asNumber(row.time);
46
+ const horizontal =
47
+ typeof row.horizontal === 'boolean' ? row.horizontal : undefined;
48
+ return {
49
+ type,
50
+ ...box,
51
+ texture,
52
+ ...(u !== undefined ? { u } : {}),
53
+ ...(v !== undefined ? { v } : {}),
54
+ ...(regionW !== undefined ? { regionW } : {}),
55
+ ...(regionH !== undefined ? { regionH } : {}),
56
+ ...(time !== undefined ? { time } : {}),
57
+ ...(horizontal !== undefined ? { horizontal } : {}),
58
+ ...(typeof row.endToStart === 'boolean' ? { endToStart: row.endToStart } : {}),
59
+ ...(typeof row.fullToEmpty === 'boolean'
60
+ ? { fullToEmpty: row.fullToEmpty }
61
+ : {}),
62
+ ...(asNumber(row.textureW) !== undefined
63
+ ? { textureW: asNumber(row.textureW) }
64
+ : {}),
65
+ ...(asNumber(row.textureH) !== undefined
66
+ ? { textureH: asNumber(row.textureH) }
67
+ : {}),
68
+ ...tip,
69
+ };
70
+ }
71
+ return { type: 'widget', ...box, ...tip };
72
+ }
73
+
74
+ export function parseDecorWidgets(value: unknown): RecipeWidget[] {
75
+ if (!Array.isArray(value)) return [];
76
+ return value.flatMap((item) => {
77
+ const widget = parseDecorWidget(item);
78
+ return widget ? [widget] : [];
79
+ });
80
+ }
81
+
@@ -0,0 +1,103 @@
1
+ import {
2
+ asNumber,
3
+ asRecord,
4
+ asString,
5
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/read';
6
+
7
+ export type RecipeSceneRect = {
8
+ x: number;
9
+ y: number;
10
+ w: number;
11
+ h: number;
12
+ };
13
+
14
+ export type RecipeMultiblockPart = {
15
+ item: string;
16
+ x: number;
17
+ y: number;
18
+ };
19
+
20
+ export type RecipeMultiblockScene = {
21
+ glb?: string;
22
+ minY?: number;
23
+ maxY?: number;
24
+ bounds?: RecipeSceneRect;
25
+ parts: RecipeMultiblockPart[];
26
+ };
27
+
28
+ function asRect(value: unknown): RecipeSceneRect | undefined {
29
+ const row = asRecord(value);
30
+ const x = asNumber(row?.x);
31
+ const y = asNumber(row?.y);
32
+ const w = asNumber(row?.w);
33
+ const h = asNumber(row?.h);
34
+ return x !== undefined && y !== undefined && w && h
35
+ ? { x, y, w, h }
36
+ : undefined;
37
+ }
38
+
39
+ export type RecipeSceneEntity = {
40
+ id: string;
41
+ x: number;
42
+ y: number;
43
+ w: number;
44
+ h: number;
45
+ clip?: RecipeSceneRect;
46
+ baked?: boolean;
47
+ };
48
+
49
+ export function recipeSceneEntities(
50
+ properties: Record<string, unknown>,
51
+ ): RecipeSceneEntity[] {
52
+ const row = asRecord(properties.scene);
53
+ const entities = Array.isArray(row?.entities) ? row.entities : [];
54
+ return entities.flatMap((value): RecipeSceneEntity[] => {
55
+ const entity = asRecord(value);
56
+ const id = asString(entity?.id);
57
+ const x = asNumber(entity?.x);
58
+ const y = asNumber(entity?.y);
59
+ const w = asNumber(entity?.w);
60
+ const h = asNumber(entity?.h);
61
+ return id && x !== undefined && y !== undefined
62
+ ? [
63
+ {
64
+ id,
65
+ x,
66
+ y,
67
+ w: w ?? 0,
68
+ h: h ?? 0,
69
+ ...(asRect(entity?.clip) ? { clip: asRect(entity?.clip) } : {}),
70
+ ...(entity?.baked === true ? { baked: true } : {}),
71
+ },
72
+ ]
73
+ : [];
74
+ });
75
+ }
76
+
77
+ export function recipeMultiblock(
78
+ properties: Record<string, unknown>,
79
+ ): RecipeMultiblockScene | undefined {
80
+ const row = asRecord(properties.multiblock);
81
+ if (!row) return undefined;
82
+ const parts = (Array.isArray(row.parts) ? row.parts : []).flatMap(
83
+ (value): RecipeMultiblockPart[] => {
84
+ const part = asRecord(value);
85
+ const item = asString(part?.item);
86
+ const x = asNumber(part?.x);
87
+ const y = asNumber(part?.y);
88
+ return item && x !== undefined && y !== undefined
89
+ ? [{ item, x, y }]
90
+ : [];
91
+ },
92
+ );
93
+ const glb = asString(row.glb);
94
+ if (!glb && !parts.length) return undefined;
95
+ return {
96
+ ...(glb ? { glb } : {}),
97
+ ...(asNumber(row.minY) !== undefined ? { minY: asNumber(row.minY) } : {}),
98
+ ...(asNumber(row.maxY) !== undefined ? { maxY: asNumber(row.maxY) } : {}),
99
+ ...(asRect(row.bounds) ? { bounds: asRect(row.bounds) } : {}),
100
+ parts,
101
+ };
102
+ }
103
+