@terrafirmagreg-team/recipe 1.2.22 → 1.2.24

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.
@@ -11,6 +11,7 @@ import { useCycleIndex } from '@terrafirmagreg-team/ui/hooks/use-cycle-index';
11
11
  import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
12
12
  import { entryHref } from '@terrafirmagreg-team/game/lib/entry/href';
13
13
  import { loadStackDisplay } from '@terrafirmagreg-team/game/lib/entry/tooltip';
14
+ import { texturePublicUrl } from '@terrafirmagreg-team/dump/lib/dump/assets/urls';
14
15
  import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/browser/favorite-hover';
15
16
  import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
16
17
  import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
@@ -114,6 +115,11 @@ export function SlotHitbox({
114
115
  ? widget.tagKind
115
116
  : undefined
116
117
  : widgetRefKind(widget);
118
+ const chanceUrl =
119
+ dataset && (alternatives?.length ?? 0) > 1
120
+ ? texturePublicUrl(dataset, 'emi:textures/gui/widgets.png')
121
+ : undefined;
122
+ const chance = widget.w >= 26 ? { u: 19, v: 27 } : { u: 1, v: 19 };
117
123
  const icon = (
118
124
  <span className="pointer-events-none flex size-full items-center justify-center">
119
125
  {alternatives && alternatives.length > 1 ? (
@@ -121,7 +127,19 @@ export function SlotHitbox({
121
127
  aria-hidden
122
128
  className="absolute bg-mc-inset"
123
129
  style={{ inset: scale }}
124
- />
130
+ >
131
+ {chanceUrl ? (
132
+ <span
133
+ className="absolute inset-0 block"
134
+ style={{
135
+ backgroundImage: `url(${chanceUrl})`,
136
+ backgroundSize: `${256 * scale}px ${256 * scale}px`,
137
+ backgroundPosition: `-${chance.u * scale}px -${chance.v * scale}px`,
138
+ imageRendering: 'pixelated',
139
+ }}
140
+ />
141
+ ) : null}
142
+ </span>
125
143
  ) : null}
126
144
  <EntryIcon
127
145
  id={iconId}
@@ -4,71 +4,23 @@ import { useState } from 'react';
4
4
  import { Check, Copy } from 'lucide-react';
5
5
  import { useCopyButton } from '@terrafirmagreg-team/ui/hooks/use-copy-button';
6
6
  import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
7
+ import { CardPager } from '@terrafirmagreg-team/recipe/components/cards/controls/card-pager';
8
+ import { texturePublicUrl } from '@terrafirmagreg-team/dump/lib/dump/assets/urls';
9
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
7
10
 
8
- export function StripCardTagPager({
9
- left,
10
- top,
11
- dir,
12
- scale,
13
- disabled,
14
- onClick,
15
- }: {
11
+ const BUTTONS_TEX = 'emi:textures/gui/buttons.png';
12
+
13
+ export function StripCardTagPager(props: {
16
14
  left: number;
17
15
  top: number;
18
16
  dir: -1 | 1;
19
17
  scale: number;
20
18
  disabled: boolean;
21
19
  onClick: () => void;
20
+ dataset: DatasetRef;
22
21
  }) {
23
- const t = useTranslations();
24
- const [hover, setHover] = useState(false);
25
- const arrow = `${3.5 * scale}px solid ${disabled ? 'var(--color-mc-inset)' : hover ? 'var(--color-mc-arrow-dark)' : 'var(--color-mc-arrow)'}`;
26
- return (
27
- <button
28
- type="button"
29
- aria-label={
30
- dir < 0
31
- ? t('Previous Page', { note: 'ui.prev_page' })
32
- : t('Next Page', { note: 'ui.next_page' })
33
- }
34
- disabled={disabled}
35
- onClick={onClick}
36
- onMouseEnter={() => setHover(true)}
37
- onMouseLeave={() => setHover(false)}
38
- onFocus={() => setHover(true)}
39
- onBlur={() => setHover(false)}
40
- className="absolute flex cursor-pointer items-center justify-center border-0 bg-transparent p-0 outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-default"
41
- style={{
42
- left: left - 4 * scale,
43
- top: top - 4 * scale,
44
- width: 20 * scale,
45
- height: 20 * scale,
46
- }}
47
- >
48
- <span
49
- aria-hidden
50
- className="flex items-center justify-center"
51
- style={{
52
- width: 12 * scale,
53
- height: 12 * scale,
54
- background: disabled ? 'var(--color-mc-dim)' : hover ? 'var(--color-mc-bright)' : 'var(--color-mc-panel)',
55
- boxShadow: `inset ${scale}px ${scale}px 0 rgba(255,255,255,0.65), inset -${scale}px -${scale}px 0 rgba(0,0,0,0.45)`,
56
- }}
57
- >
58
- <span
59
- aria-hidden
60
- className="block"
61
- style={{
62
- width: 0,
63
- height: 0,
64
- borderTop: `${2.5 * scale}px solid transparent`,
65
- borderBottom: `${2.5 * scale}px solid transparent`,
66
- ...(dir < 0 ? { borderRight: arrow } : { borderLeft: arrow }),
67
- }}
68
- />
69
- </span>
70
- </button>
71
- );
22
+ const { dataset, ...rest } = props;
23
+ return <CardPager {...rest} tex={texturePublicUrl(dataset, BUTTONS_TEX)} />;
72
24
  }
73
25
 
74
26
  export function StripCardTagCopy({
@@ -189,6 +189,7 @@ export function StripCard({
189
189
  scale={scale}
190
190
  disabled={clamped <= 0}
191
191
  onClick={() => setPage(clamped - 1)}
192
+ dataset={dataset}
192
193
  />
193
194
  <StripCardTagPager
194
195
  left={(margin + guiW - 14) * scale}
@@ -197,6 +198,7 @@ export function StripCard({
197
198
  scale={scale}
198
199
  disabled={clamped + 1 >= pages}
199
200
  onClick={() => setPage(clamped + 1)}
201
+ dataset={dataset}
200
202
  />
201
203
  </>
202
204
  )}
@@ -3,6 +3,7 @@ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
3
 
4
4
  import Link from 'next/link';
5
5
  import { EntryIcon } from '@terrafirmagreg-team/game/components/entry/icon';
6
+ import { McText } from '@terrafirmagreg-team/game/components/entry/mc-text';
6
7
  import {
7
8
  EntryTooltip,
8
9
  type EntryTooltipLevel,
@@ -31,6 +32,8 @@ export function StripCardMember({
31
32
  x,
32
33
  y,
33
34
  pitch,
35
+ hideIcon,
36
+ tooltipLines,
34
37
  interactive = true,
35
38
  tooltipLevel,
36
39
  }: {
@@ -42,12 +45,17 @@ export function StripCardMember({
42
45
  x: number;
43
46
  y: number;
44
47
  pitch: number;
48
+ hideIcon?: boolean;
49
+ tooltipLines?: string[];
45
50
  interactive?: boolean;
46
51
  tooltipLevel?: EntryTooltipLevel;
47
52
  }) {
48
53
  const kind = MEMBER_KIND[member.kind ?? 'item'] ?? 'item';
49
54
  const name = stackDisplayName(langMap, member.id);
50
- const checkKind = kind === 'item' || kind === 'fluid' ? kind : undefined;
55
+ const checkKind =
56
+ kind === 'item' || kind === 'fluid' || kind === 'block' || kind === 'entity'
57
+ ? kind
58
+ : undefined;
51
59
  const stackPeek =
52
60
  dataset && checkKind
53
61
  ? loadStackDisplay.peek(dataset, member.id, checkKind)
@@ -77,15 +85,20 @@ export function StripCardMember({
77
85
  }
78
86
  const inner = (
79
87
  <>
80
- <span className="pointer-events-none flex size-full items-center justify-center">
81
- <EntryIcon
82
- id={member.id}
83
- kind={kind}
84
- dataset={dataset}
85
- size={Math.max(8, pitch - 4)}
86
- missing="placeholder"
87
- />
88
- </span>
88
+ {hideIcon ? null : (
89
+ <span
90
+ className="pointer-events-none absolute flex justify-center"
91
+ style={{ inset: 0, alignItems: 'center' }}
92
+ >
93
+ <EntryIcon
94
+ id={member.id}
95
+ kind={kind}
96
+ dataset={dataset}
97
+ size={Math.max(8, pitch - 4)}
98
+ missing="placeholder"
99
+ />
100
+ </span>
101
+ )}
89
102
  {badges.length > 0 && (
90
103
  <span
91
104
  className="font-mc pointer-events-none absolute right-0 bottom-0 leading-none text-white [text-shadow:1px_1px_0_var(--color-mc-arrow)]"
@@ -96,6 +109,15 @@ export function StripCardMember({
96
109
  )}
97
110
  </>
98
111
  );
112
+ const footer = tooltipLines?.length ? (
113
+ <>
114
+ {tooltipLines.map((line, index) => (
115
+ <p key={`${index}:${line}`} className="text-muted-foreground">
116
+ <McText text={line} surface="inverted" />
117
+ </p>
118
+ ))}
119
+ </>
120
+ ) : undefined;
99
121
  const faceStyle = { left: x, top: y, width: pitch, height: pitch };
100
122
  const hover = {
101
123
  onMouseEnter: () => {
@@ -118,10 +140,11 @@ export function StripCardMember({
118
140
  dataset={dataset}
119
141
  id={member.id}
120
142
  name={name}
121
- kind={kind === 'fluid' ? 'fluid' : kind === 'entity' ? 'entity' : 'item'}
143
+ kind={kind}
122
144
  lang={lang}
123
145
  langMap={langMap}
124
146
  level={tooltipLevel}
147
+ footer={footer}
125
148
  >
126
149
  <span
127
150
  {...hover}
@@ -139,10 +162,11 @@ export function StripCardMember({
139
162
  dataset={dataset}
140
163
  id={member.id}
141
164
  name={name}
142
- kind={kind === 'fluid' ? 'fluid' : kind === 'entity' ? 'entity' : 'item'}
165
+ kind={kind}
143
166
  lang={lang}
144
167
  langMap={langMap}
145
168
  level={tooltipLevel}
169
+ footer={footer}
146
170
  >
147
171
  <span
148
172
  {...hover}
@@ -268,7 +268,7 @@ export function RecipeCardGrid({
268
268
  <div
269
269
  ref={boxRef}
270
270
  {...swipe}
271
- className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 overflow-x-auto"
271
+ className="flex min-h-0 flex-1 flex-col items-center justify-start gap-2 overflow-x-auto overflow-y-clip"
272
272
  >
273
273
  {body}
274
274
  </div>
@@ -1,14 +1,10 @@
1
- import { Layout } from '@terrafirmagreg-team/kit/components/layouts/layout';
2
- import type { SectionLayoutViewProps } from '@terrafirmagreg-team/kit/components/views/routes';
3
- import { RecipeAxisSwitcher } from '@terrafirmagreg-team/recipe/components/views/browser/axis-switcher';
1
+ 'use client';
2
+ import { useEffect } from 'react';
3
+ import type { TreeFeatureProps } from '@terrafirmagreg-team/kit/types';
4
4
  import { useRecipeLeftSidebarTree } from '@terrafirmagreg-team/recipe/hooks/use-left-sidebar-tree';
5
5
 
6
- export function RecipeLayout(props: SectionLayoutViewProps) {
7
- return (
8
- <Layout
9
- {...props}
10
- useTree={useRecipeLeftSidebarTree}
11
- sidebar={{ feature: RecipeAxisSwitcher }}
12
- />
13
- );
6
+ export function RecipeTreeFeature({ input, dataset, onTree }: TreeFeatureProps) {
7
+ const tree = useRecipeLeftSidebarTree(input, dataset);
8
+ useEffect(() => onTree({ input, tree }), [input, tree, onTree]);
9
+ return null;
14
10
  }
@@ -30,6 +30,7 @@ export function useRecipeIndex(dataset: DatasetRef | undefined, lang: string) {
30
30
  const [loaded, setLoaded] = useState<LoadedIndex | null>(null);
31
31
  const [complete, setComplete] = useState<string | null>(null);
32
32
  const [lastFull, setLastFull] = useState<RecipeCompactIndex | null>(null);
33
+ const [warmKey, setWarmKey] = useState<string | null>(null);
33
34
  const nonce = useDumpRetryNonce();
34
35
  const { locales: items } = useLang();
35
36
  const locales = useMemo(
@@ -53,29 +54,37 @@ export function useRecipeIndex(dataset: DatasetRef | undefined, lang: string) {
53
54
  setLastFull(index);
54
55
  });
55
56
  publishRecipeIndex(dataset, lang, index);
56
- const entityNames = await loadRecipeEntityNames(dataset, chrome, lang);
57
+ const entityNames = await loadRecipeEntityNames(
58
+ dataset,
59
+ chrome,
60
+ lang,
61
+ ).catch(() => null);
57
62
  if (isCancelled()) return;
58
- publishRecipeIndex(dataset, lang, {
59
- ...index,
60
- names: {
61
- ...index.names,
62
- [lang]: { ...entityNames, ...index.names[lang] },
63
- },
64
- });
65
- }, [dataset, lang, nonce]);
63
+ if (entityNames) {
64
+ publishRecipeIndex(dataset, lang, {
65
+ ...index,
66
+ names: {
67
+ ...index.names,
68
+ [lang]: { ...entityNames, ...index.names[lang] },
69
+ },
70
+ });
71
+ }
72
+ setWarmKey(key);
73
+ }, [dataset, lang, nonce, key]);
66
74
 
67
75
  useAsyncEffect(async (isCancelled) => {
68
- if (!dataset) return;
69
- const others = locales.filter((entry) => entry !== lang);
70
- for (const entry of others) {
71
- if (isCancelled()) return;
76
+ if (!dataset || warmKey !== key) return;
77
+ for (const entry of locales.filter((item) => item !== lang)) {
72
78
  await idle();
73
79
  if (isCancelled()) return;
74
- const chrome = await loadRecipeChromeClient(dataset, entry);
80
+ const other = await loadRecipeChromeClient(dataset, entry).catch(
81
+ () => null,
82
+ );
75
83
  if (isCancelled()) return;
76
- await loadRecipeCompactIndex(dataset, chrome);
84
+ if (!other) continue;
85
+ await loadRecipeCompactIndex(dataset, other).catch(() => null);
77
86
  }
78
- }, [dataset, lang, locales]);
87
+ }, [dataset, lang, locales, warmKey, key]);
79
88
 
80
89
  const active = loaded?.key === key ? loaded.index : null;
81
90
  const index = active?.items.length ? active : (lastFull ?? active);
@@ -1,34 +1,24 @@
1
1
  'use client';
2
- import { usePathname } from 'next/navigation';
3
- import { useMemo } from 'react';
4
2
  import type * as PageTree from 'fumadocs-core/page-tree';
5
- import { useLocationSearchParams } from '@terrafirmagreg-team/ui/hooks/page/use-location-search';
3
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
6
4
  import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
7
5
  import { useLastValue } from '@terrafirmagreg-team/ui/hooks/use-last-value';
8
6
  import { skeletonTree } from '@terrafirmagreg-team/ui/lib/tree';
9
7
  import { useRecipeModNames } from '@terrafirmagreg-team/recipe/hooks/use-mod-names';
10
8
  import { useSidebarGroup } from '@terrafirmagreg-team/recipe/hooks/use-sidebar-group';
11
9
  import { groupRecipeSidebarByMod } from '@terrafirmagreg-team/recipe/lib/browser/sidebar';
12
- import { parseSectionLocation } from '@terrafirmagreg-team/sites/location';
13
- import { useVersionPreference } from '@terrafirmagreg-team/kit/hooks/use-version-pref';
14
10
 
15
- export function useRecipeLeftSidebarTree(tree: PageTree.Root): PageTree.Root {
16
- const { dataset: datasetId } = parseSectionLocation(usePathname());
11
+ export function useRecipeLeftSidebarTree(
12
+ tree: PageTree.Root,
13
+ dataset?: DatasetRef,
14
+ ): PageTree.Root {
17
15
  const lang = useResolvedLang();
18
16
  const { sidebarGroup } = useSidebarGroup();
19
- const scopeKey = datasetId ?? '';
20
- const versionParam = useLocationSearchParams().get('version') ?? undefined;
21
- const preferred = useVersionPreference(datasetId);
22
- const version = versionParam ?? preferred;
23
- const dataset = useMemo(
24
- () => (datasetId ? { id: datasetId, version } : undefined),
25
- [datasetId, version],
26
- );
27
17
  const result = useRecipeModNames(
28
18
  sidebarGroup === 'mod' ? dataset : undefined,
29
19
  lang,
30
20
  );
31
- const modNames = useLastValue(result.value, scopeKey);
21
+ const modNames = useLastValue(result.value, dataset?.id ?? '');
32
22
  if (sidebarGroup === 'mod' && !modNames && result.pending)
33
23
  return skeletonTree('recipe:skeleton');
34
24
  return sidebarGroup === 'mod' && modNames
@@ -4,26 +4,25 @@ import type {
4
4
  RecipeChrome,
5
5
  RecipeStackGroup,
6
6
  } from '@terrafirmagreg-team/recipe/types';
7
- import { clientDumpLang, loadClientManifest } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
7
+ import {
8
+ clientDumpLang,
9
+ clientDumpNames,
10
+ loadClientManifest,
11
+ } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
8
12
  import {
9
13
  creativeTabName,
10
14
  dumpTextString,
11
15
  } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
12
- import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
13
- import {
14
- loadClientRegistry,
15
- loadClientRegistryOrder,
16
- resolveClientStackDisplay,
17
- } from '@terrafirmagreg-team/dump/lib/dump/client/registry';
16
+ import { loadClientRegistryOrder } from '@terrafirmagreg-team/dump/lib/dump/client/registry';
18
17
  import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
19
18
  import { loadClientTabs } from '@terrafirmagreg-team/dump/lib/dump/client/tabs';
20
19
  import { loadDatasetRecipeCategories } from '@terrafirmagreg-team/recipe/lib/data/category/load';
21
20
  import { loadClientRegistryGroups } from '@terrafirmagreg-team/dump/lib/dump/client/groups';
22
21
  import { loadClientModNames } from '@terrafirmagreg-team/dump/lib/dump/client/mods';
23
- import { loadClientModAtlases } from '@terrafirmagreg-team/dump/lib/dump/client/atlases';
24
- import { lookupSpriteInBundle } from '@terrafirmagreg-team/dump/lib/dump/assets/atlas/lookup';
25
- import { stackIdBase, stackIdFromRef } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
26
- import type { AtlasBundle } from '@terrafirmagreg-team/dump/lib/dump/assets/atlas/dto';
22
+ import {
23
+ stackIdBase,
24
+ stackIdFromRef,
25
+ } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
27
26
  import { createDatasetCache } from '@terrafirmagreg-team/dump/lib/dump/reader';
28
27
 
29
28
  async function clientEntityNames(
@@ -31,49 +30,15 @@ async function clientEntityNames(
31
30
  lang: string,
32
31
  ids: Iterable<string>,
33
32
  ): Promise<Record<string, string>> {
34
- const [map, items, fluids] = await Promise.all([
35
- clientDumpLang(dataset, lang),
36
- loadClientRegistry(dataset, 'items'),
37
- loadClientRegistry(dataset, 'fluids'),
38
- ]);
39
- const all = [...new Set([...items.keys(), ...fluids.keys(), ...ids])];
40
- const info = new Map<string, { baseId: string; langKey?: string }>();
41
- const mods = new Set<string>();
42
- for (const id of all) {
43
- const baseId = stackIdBase(id);
44
- const langKey = resolveClientStackDisplay(id, items, fluids)?.name;
45
- info.set(id, { baseId, ...(langKey ? { langKey } : {}) });
46
- if (!langKey && baseId.includes(':') && !baseId.startsWith('#')) {
47
- const mod = baseId.split(':', 2)[0];
48
- if (mod) mods.add(mod);
33
+ const table = await clientDumpNames(dataset, lang);
34
+ for (const id of ids) {
35
+ if (table[id] === undefined && table[stackIdBase(id)] === undefined) {
36
+ throw new Error(
37
+ `dump names missing id "${id}" for ${dataset.id} lang=${lang}`,
38
+ );
49
39
  }
50
40
  }
51
- const atlases = new Map<string, AtlasBundle>();
52
- await Promise.all(
53
- [...mods].map(async (mod) => {
54
- atlases.set(mod, await loadClientModAtlases(dataset, mod));
55
- }),
56
- );
57
- const names: Record<string, string> = { ...map };
58
- let processed = 0;
59
- for (const [id, entry] of info) {
60
- if (++processed % 2000 === 0) {
61
- await new Promise((resolve) => setTimeout(resolve));
62
- }
63
- const langKey =
64
- entry.langKey ??
65
- lookupSpriteInBundle(
66
- atlases.get(entry.baseId.split(':', 2)[0] ?? ''),
67
- entry.baseId,
68
- )?.sprite.langKey;
69
- const kind = entry.baseId.startsWith('#')
70
- ? undefined
71
- : fluids.has(entry.baseId)
72
- ? 'fluid'
73
- : 'item';
74
- names[id] = stackDisplayName(map, id, kind, langKey);
75
- }
76
- return names;
41
+ return { ...table };
77
42
  }
78
43
 
79
44
  async function clientNamedCategories(
@@ -56,12 +56,13 @@ const typeRowsCache = createDatasetCache(
56
56
  });
57
57
  }),
58
58
  );
59
- return buckets
59
+ const rows = buckets
60
60
  .flat()
61
61
  .sort(
62
62
  (a, b) =>
63
63
  (a.o ?? Number.MAX_SAFE_INTEGER) - (b.o ?? Number.MAX_SAFE_INTEGER),
64
64
  );
65
+ return rows;
65
66
  },
66
67
  (dataset, _index, typeId) => `${dataset.id}/${dataset.version ?? ''} ${typeId}`,
67
68
  );