@terrafirmagreg-team/recipe 1.2.13 → 1.2.15
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 +8 -8
- package/src/components/tree.tsx +4 -1
- package/src/components/views/alloy/index.tsx +1 -1
- package/src/components/views/browser/workstation-rail.tsx +1 -1
- package/src/components/views/calc/calculator/index.tsx +1 -1
- package/src/components/views/calc/trees/icon-picker.tsx +1 -1
- package/src/components/views/forge/index.tsx +1 -1
- package/src/lib/og.ts +127 -0
- package/src/lib/tool-names.ts +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/recipe",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Recipe viewer and calculator",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"./styles.css": "./styles.css"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@terrafirmagreg-team/data": "^1.2.
|
|
27
|
-
"@terrafirmagreg-team/dump": "^1.2.
|
|
26
|
+
"@terrafirmagreg-team/data": "^1.2.4",
|
|
27
|
+
"@terrafirmagreg-team/dump": "^1.2.12",
|
|
28
28
|
"@terrafirmagreg-team/game": "^1.2.6",
|
|
29
|
-
"@terrafirmagreg-team/kit": "^1.2.
|
|
30
|
-
"@terrafirmagreg-team/mdx": "^1.2.
|
|
31
|
-
"@terrafirmagreg-team/preview": "^1.2.
|
|
32
|
-
"@terrafirmagreg-team/sites": "^1.2.
|
|
29
|
+
"@terrafirmagreg-team/kit": "^1.2.16",
|
|
30
|
+
"@terrafirmagreg-team/mdx": "^1.2.8",
|
|
31
|
+
"@terrafirmagreg-team/preview": "^1.2.4",
|
|
32
|
+
"@terrafirmagreg-team/sites": "^1.2.3",
|
|
33
33
|
"@terrafirmagreg-team/translate": "^1.2.8",
|
|
34
|
-
"@terrafirmagreg-team/ui": "^1.2.
|
|
34
|
+
"@terrafirmagreg-team/ui": "^1.2.11",
|
|
35
35
|
"@types/pathfinding": "^0.1.0",
|
|
36
36
|
"comlink": "^4.4.2",
|
|
37
37
|
"fflate": "0.8.3",
|
package/src/components/tree.tsx
CHANGED
|
@@ -22,7 +22,10 @@ function categoryIcon(
|
|
|
22
22
|
if (!category.icon) return undefined;
|
|
23
23
|
return createElement(
|
|
24
24
|
'span',
|
|
25
|
-
{
|
|
25
|
+
{
|
|
26
|
+
key: 'icon',
|
|
27
|
+
className: 'inline-flex size-4 shrink-0 items-center justify-center',
|
|
28
|
+
},
|
|
26
29
|
createElement(Entry, {
|
|
27
30
|
dataset,
|
|
28
31
|
reference: category.icon,
|
|
@@ -71,7 +71,7 @@ export function AlloyCalculator({ session }: { session: RecipeSession }) {
|
|
|
71
71
|
)
|
|
72
72
|
}
|
|
73
73
|
>
|
|
74
|
-
<div className="
|
|
74
|
+
<div className="flex-1 space-y-5 overflow-y-auto p-2 sm:p-4">
|
|
75
75
|
{loading ? (
|
|
76
76
|
<EmptyState variant="loading" />
|
|
77
77
|
) : value === undefined ? (
|
|
@@ -17,7 +17,7 @@ export function WorkstationRail({
|
|
|
17
17
|
if (!workstations?.length) return null;
|
|
18
18
|
const { lang, names, nav } = session;
|
|
19
19
|
return (
|
|
20
|
-
<div className="
|
|
20
|
+
<div className="flex max-h-full flex-col items-center gap-1 self-start overflow-y-auto overflow-x-hidden rounded-lg border border-border bg-muted/60 p-1">
|
|
21
21
|
<Factory
|
|
22
22
|
className="m-1 size-3.5 shrink-0 text-muted-foreground"
|
|
23
23
|
aria-hidden
|
|
@@ -155,7 +155,7 @@ export function Calculator({ session }: { session: RecipeSession }) {
|
|
|
155
155
|
focusNodeId={focusNodeId}
|
|
156
156
|
onFocusedNode={() => setFocusNodeId(null)}
|
|
157
157
|
empty={
|
|
158
|
-
<div className="
|
|
158
|
+
<div className="absolute inset-0 z-10 grid place-items-center overflow-auto p-4">
|
|
159
159
|
<div className="flex flex-col items-center gap-4">
|
|
160
160
|
<EmptyState variant="empty">
|
|
161
161
|
{t('Click an item in the catalog to add a card.', { note: 'recipe.calc.empty' })}
|
|
@@ -66,7 +66,7 @@ export function IconPicker({
|
|
|
66
66
|
placeholder={t('Search items', { note: 'recipe.search' })}
|
|
67
67
|
className="h-7 px-2 text-xs"
|
|
68
68
|
/>
|
|
69
|
-
<div className="
|
|
69
|
+
<div className="mt-2 grid max-h-60 grid-cols-6 gap-1 overflow-y-auto">
|
|
70
70
|
{results.map((item) => (
|
|
71
71
|
<button
|
|
72
72
|
key={`${item.kind}:${item.id}`}
|
|
@@ -71,7 +71,7 @@ export function ForgeCalculator({ session }: { session: RecipeSession }) {
|
|
|
71
71
|
)
|
|
72
72
|
}
|
|
73
73
|
>
|
|
74
|
-
<div className="
|
|
74
|
+
<div className="flex-1 space-y-5 overflow-y-auto p-2 sm:p-4">
|
|
75
75
|
{loading ? (
|
|
76
76
|
<EmptyState variant="loading" />
|
|
77
77
|
) : value === undefined ? (
|
package/src/lib/og.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
|
|
2
|
+
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
3
|
+
import { clientDumpLang } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
|
|
4
|
+
import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
|
|
5
|
+
import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
6
|
+
import { stripMcFormat } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
7
|
+
import {
|
|
8
|
+
ogLocalized,
|
|
9
|
+
ogRefSprite,
|
|
10
|
+
ogStackName,
|
|
11
|
+
} from '@terrafirmagreg-team/dump/lib/dump/assets/og';
|
|
12
|
+
import {
|
|
13
|
+
ogName,
|
|
14
|
+
registerOgResolver,
|
|
15
|
+
type OgContext,
|
|
16
|
+
} from '@terrafirmagreg-team/preview/lib';
|
|
17
|
+
import { loadDatasetRecipeCategories } from './data/category/load';
|
|
18
|
+
import { loadClientRecipe } from './client/recipe';
|
|
19
|
+
import { recipeToolName } from './tool-names';
|
|
20
|
+
|
|
21
|
+
async function recipeOgContext(
|
|
22
|
+
dataset: DatasetRef,
|
|
23
|
+
search: URLSearchParams,
|
|
24
|
+
lang: Lang,
|
|
25
|
+
): Promise<OgContext> {
|
|
26
|
+
const tool = search.get('tool');
|
|
27
|
+
if (tool) {
|
|
28
|
+
return {
|
|
29
|
+
entity: { kind: 'tool', name: recipeToolName(tool, lang) },
|
|
30
|
+
imageQuery: `tool=${encodeURIComponent(tool)}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const item = search.get('item');
|
|
34
|
+
const fluid = search.get('fluid');
|
|
35
|
+
if (item || fluid) {
|
|
36
|
+
const kind = fluid ? 'fluid' : 'item';
|
|
37
|
+
const id = (item ?? fluid)!;
|
|
38
|
+
return {
|
|
39
|
+
entity: {
|
|
40
|
+
kind,
|
|
41
|
+
name: await ogStackName(dataset, id, kind, lang),
|
|
42
|
+
id,
|
|
43
|
+
},
|
|
44
|
+
icon: await ogRefSprite(dataset, { kind, id }),
|
|
45
|
+
description: id,
|
|
46
|
+
imageQuery: `${kind}=${encodeURIComponent(id)}`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const type = search.get('type');
|
|
50
|
+
const id = search.get('id');
|
|
51
|
+
if (type === 'emi:tag' && id) {
|
|
52
|
+
const [, tagKind = 'item', ns = '', ...rest] = id.split('/');
|
|
53
|
+
const path = rest.join('/');
|
|
54
|
+
const tagPath = path.startsWith(`${tagKind}s/`)
|
|
55
|
+
? path.slice(tagKind.length + 2)
|
|
56
|
+
: path;
|
|
57
|
+
const tagId = rest.length ? `${ns}:${tagPath}` : ns;
|
|
58
|
+
const members = await loadClientTagMembers(dataset, tagKind);
|
|
59
|
+
const list = tagId ? members?.[`#${tagId}`] : undefined;
|
|
60
|
+
const first = list?.[0];
|
|
61
|
+
return {
|
|
62
|
+
entity: { kind: 'tag', name: `#${tagId || id}`, id },
|
|
63
|
+
icon: first
|
|
64
|
+
? await ogRefSprite(dataset, {
|
|
65
|
+
kind: tagKind as ReferenceKind,
|
|
66
|
+
id: first,
|
|
67
|
+
})
|
|
68
|
+
: undefined,
|
|
69
|
+
description:
|
|
70
|
+
list != null
|
|
71
|
+
? `${list.length} member${list.length === 1 ? '' : 's'}`
|
|
72
|
+
: `${tagKind} tag`,
|
|
73
|
+
imageQuery: `type=emi:tag&id=${encodeURIComponent(id)}`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (id) {
|
|
77
|
+
const recipe = await loadClientRecipe(dataset, id);
|
|
78
|
+
if (!recipe) return {};
|
|
79
|
+
const out = recipe.outputs[0];
|
|
80
|
+
const [categories, map] = await Promise.all([
|
|
81
|
+
loadDatasetRecipeCategories(dataset),
|
|
82
|
+
clientDumpLang(dataset, lang),
|
|
83
|
+
]);
|
|
84
|
+
const category = categories.find((row) => row.id === recipe.type);
|
|
85
|
+
const catName = category
|
|
86
|
+
? stripMcFormat(
|
|
87
|
+
ogLocalized(map, category.display?.name) ?? category.id,
|
|
88
|
+
).trim()
|
|
89
|
+
: undefined;
|
|
90
|
+
const name = out
|
|
91
|
+
? await ogStackName(
|
|
92
|
+
dataset,
|
|
93
|
+
out.id,
|
|
94
|
+
out.kind === 'fluid' ? 'fluid' : 'item',
|
|
95
|
+
lang,
|
|
96
|
+
).catch(() => recipe.id)
|
|
97
|
+
: recipe.id;
|
|
98
|
+
return {
|
|
99
|
+
entity: { kind: 'recipe', name, id: recipe.id },
|
|
100
|
+
icon: out
|
|
101
|
+
? await ogRefSprite(dataset, {
|
|
102
|
+
kind: out.kind === 'tag' ? 'itemTag' : out.kind,
|
|
103
|
+
id: out.id,
|
|
104
|
+
})
|
|
105
|
+
: undefined,
|
|
106
|
+
description: catName ?? recipe.id,
|
|
107
|
+
imageQuery: `id=${encodeURIComponent(id)}`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (!type || type === 'all') return {};
|
|
111
|
+
const [categories, map] = await Promise.all([
|
|
112
|
+
loadDatasetRecipeCategories(dataset),
|
|
113
|
+
clientDumpLang(dataset, lang),
|
|
114
|
+
]);
|
|
115
|
+
const category = categories.find((row) => row.id === type);
|
|
116
|
+
if (!category) return {};
|
|
117
|
+
const localized =
|
|
118
|
+
ogLocalized(map, category.display?.name) ?? category.id;
|
|
119
|
+
return {
|
|
120
|
+
entity: { kind: 'category', ...ogName(localized), id: category.id },
|
|
121
|
+
icon: await ogRefSprite(dataset, category.icon),
|
|
122
|
+
description: category.id,
|
|
123
|
+
imageQuery: `type=${encodeURIComponent(type)}`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
registerOgResolver('recipe', recipeOgContext);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { humanizeKey } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
2
|
+
import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
|
|
3
|
+
import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
|
|
4
|
+
|
|
5
|
+
const TOOL_KEYS: Record<string, [string, string]> = {
|
|
6
|
+
calc: ['Calculator', 'recipe.calculator'],
|
|
7
|
+
forge: ['Forging', 'recipe.forge.title'],
|
|
8
|
+
alloy: ['Alloys', 'recipe.alloy.title'],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function recipeToolName(tool: string, lang: Lang): string {
|
|
12
|
+
const [source, note] = TOOL_KEYS[tool] ?? [];
|
|
13
|
+
if (!source || !note) return humanizeKey(tool);
|
|
14
|
+
const registry = loadLocaleRegistry();
|
|
15
|
+
const messages =
|
|
16
|
+
registry.messages[lang] ??
|
|
17
|
+
registry.messages[registry.defaultLanguage] ??
|
|
18
|
+
{};
|
|
19
|
+
return messages[`${source}(${note})`] ?? source;
|
|
20
|
+
}
|