@terrafirmagreg-team/guide 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/package.json +58 -3
  2. package/src/components/book-switcher.tsx +46 -0
  3. package/src/components/views/browser.tsx +124 -0
  4. package/src/components/views/entry/pages.tsx +186 -0
  5. package/src/components/views/entry/view.tsx +60 -0
  6. package/src/components/views/kind/links.tsx +111 -0
  7. package/src/components/views/kind/media.tsx +167 -0
  8. package/src/components/views/kind/recipe.tsx +134 -0
  9. package/src/components/views/kind/table.tsx +138 -0
  10. package/src/components/views/kind/unknown.tsx +23 -0
  11. package/src/components/views/page/category-body.tsx +56 -0
  12. package/src/components/views/page/entry-body.tsx +79 -0
  13. package/src/components/views/page/overview-body.tsx +97 -0
  14. package/src/components/views/page/text.tsx +57 -0
  15. package/src/components/views/page/view.tsx +279 -0
  16. package/src/components/views/text.tsx +130 -0
  17. package/src/hooks/use-left-sidebar-tree.ts +19 -0
  18. package/src/hooks/use-tree.ts +33 -0
  19. package/src/lib/book/convert.ts +74 -0
  20. package/src/lib/book/index-rows.ts +134 -0
  21. package/src/lib/book/index.ts +2 -0
  22. package/src/lib/book/localize.ts +76 -0
  23. package/src/lib/book/raw.ts +80 -0
  24. package/src/lib/books.ts +29 -0
  25. package/src/lib/breadcrumb.ts +54 -0
  26. package/src/lib/client/guides.ts +189 -0
  27. package/src/lib/client-payload/extras.ts +101 -0
  28. package/src/lib/client-payload/index.ts +112 -0
  29. package/src/lib/client-payload/links.ts +101 -0
  30. package/src/lib/config.ts +46 -0
  31. package/src/lib/data/dto.ts +77 -0
  32. package/src/lib/data/parse.ts +93 -0
  33. package/src/lib/dump.ts +5 -0
  34. package/src/lib/format.ts +231 -0
  35. package/src/lib/links.ts +2 -0
  36. package/src/lib/markdown/book.ts +73 -0
  37. package/src/lib/markdown/ctx.ts +26 -0
  38. package/src/lib/markdown/index.ts +8 -0
  39. package/src/lib/markdown/page.ts +154 -0
  40. package/src/lib/markdown/table.ts +35 -0
  41. package/src/lib/markdown/text.ts +39 -0
  42. package/src/lib/markdown-page.ts +72 -0
  43. package/src/lib/messages.ts +13 -0
  44. package/src/lib/meta.ts +9 -0
  45. package/src/lib/multiblock/index.ts +8 -0
  46. package/src/lib/multiblock/url.ts +61 -0
  47. package/src/lib/names.ts +35 -0
  48. package/src/lib/page-kind.ts +117 -0
  49. package/src/lib/paths.ts +52 -0
  50. package/src/lib/preview.ts +33 -0
  51. package/src/lib/query.ts +28 -0
  52. package/src/lib/recipe.ts +30 -0
  53. package/src/lib/reference/index.ts +40 -0
  54. package/src/lib/reference/resolver.ts +88 -0
  55. package/src/lib/search/filter.ts +17 -0
  56. package/src/lib/search/index.ts +156 -0
  57. package/src/lib/sprites.ts +17 -0
  58. package/src/lib/table.ts +10 -0
  59. package/src/lib/toc.ts +137 -0
  60. package/src/lib/tree/children.ts +70 -0
  61. package/src/lib/tree/index.ts +117 -0
  62. package/src/locales/en_us.json +22 -0
  63. package/src/locales/ru_ru.json +22 -0
  64. package/src/locales.ts +5 -0
  65. package/src/types/index.ts +215 -0
  66. package/README.md +0 -3
@@ -0,0 +1,117 @@
1
+ import 'server-only';
2
+ import { createElement } from 'react';
3
+ import type * as PageTree from 'fumadocs-core/page-tree';
4
+ import { Entry } from '@terrafirmagreg-team/game/components/entry/entry';
5
+ import { loadMergedLangMap } from '@terrafirmagreg-team/game/lib/dump/assets/lang/load';
6
+ import { asRecord, asString } from '@terrafirmagreg-team/game/lib/dump/contract/read';
7
+ import { loadDatasetDump } from '@terrafirmagreg-team/game/lib/dump/mods/load';
8
+ import { clientDumpJson } from '@terrafirmagreg-team/game/lib/dump/client/dump';
9
+ import { keyTreeNode } from '@terrafirmagreg-team/translate/server';
10
+ import { loadLocaleRegistry } from '@terrafirmagreg-team/translate/server';
11
+ import { encodeQueryValue } from '@terrafirmagreg-team/translate/lib/url';
12
+ import { sectionUrl } from '@terrafirmagreg-team/kit/lib/location';
13
+ import { bookOptionId } from '@terrafirmagreg-team/guide/lib/paths';
14
+ import { bookSlug, toBook } from '@terrafirmagreg-team/guide/lib/book';
15
+ import { sectionDatasets } from '@terrafirmagreg-team/kit/lib/datasets';
16
+ import type { GuideBookJson, GuideBookRef } from '@terrafirmagreg-team/guide/lib/data/dto';
17
+ import type { SectionTrees } from '@terrafirmagreg-team/kit/types';
18
+
19
+ function bookIcon(
20
+ dataset: string,
21
+ raw: GuideBookJson | undefined,
22
+ ): React.ReactNode {
23
+ const cover = asRecord(raw?.cover);
24
+ const coverId = asString(cover?.id) ?? undefined;
25
+ if (!coverId) return undefined;
26
+ return createElement(
27
+ 'span',
28
+ {
29
+ 'data-icon': true,
30
+ className:
31
+ 'inline-flex size-3.5 shrink-0 items-center justify-center overflow-hidden',
32
+ },
33
+ createElement(Entry, {
34
+ dataset,
35
+ id: coverId,
36
+ kind: 'item',
37
+ size: 14,
38
+ href: false,
39
+ tooltip: false,
40
+ missing: 'hide',
41
+ }),
42
+ );
43
+ }
44
+
45
+ function bookLeaf(
46
+ dataset: string,
47
+ ref: GuideBookRef,
48
+ slug: string,
49
+ raw: GuideBookJson | undefined,
50
+ map: Record<string, string>,
51
+ ): PageTree.Item {
52
+ const book = toBook(raw, ref, slug, map);
53
+ const bookId = bookOptionId(ref.modId, ref.bookPath);
54
+ return keyTreeNode({
55
+ type: 'page',
56
+ name: book.name,
57
+ url: `${sectionUrl('guide', dataset)}?book=${encodeQueryValue(bookId)}`,
58
+ icon: bookIcon(dataset, raw),
59
+ $id: `${dataset}/book/${bookId}`,
60
+ }) as PageTree.Item;
61
+ }
62
+
63
+ async function datasetBookLeaves(
64
+ dataset: string,
65
+ langMap: Record<string, string>,
66
+ ): Promise<PageTree.Node[]> {
67
+ const dump = await loadDatasetDump(dataset);
68
+ if (!dump) return [];
69
+ const taken = new Set<string>();
70
+ const leaves: PageTree.Node[] = [];
71
+ for (const mod of dump.mods) {
72
+ const raws = await Promise.all(
73
+ mod.books.map((ref) =>
74
+ clientDumpJson(dataset, `${ref.dir}/book.json`).then(
75
+ (raw) => asRecord(raw) as GuideBookJson | undefined,
76
+ ),
77
+ ),
78
+ );
79
+ for (const [i, ref] of mod.books.entries()) {
80
+ const raw = raws[i];
81
+ if (!raw) continue;
82
+ let slug = bookSlug(raw, ref);
83
+ if (taken.has(slug)) {
84
+ let n = 2;
85
+ while (taken.has(`${slug}-${n}`)) n += 1;
86
+ slug = `${slug}-${n}`;
87
+ }
88
+ taken.add(slug);
89
+ leaves.push(bookLeaf(dataset, ref, slug, raw, langMap));
90
+ }
91
+ }
92
+ return leaves;
93
+ }
94
+
95
+ let cached: Promise<SectionTrees> | undefined;
96
+
97
+ export function guideTrees(): Promise<SectionTrees> {
98
+ cached ??= buildGuideTrees();
99
+ return cached;
100
+ }
101
+
102
+ async function buildGuideTrees(): Promise<SectionTrees> {
103
+ const { defaultLanguage } = loadLocaleRegistry();
104
+ const datasets = await sectionDatasets('guide');
105
+ const trees: SectionTrees = {};
106
+ for (const { id, title: datasetTitle, languages } of datasets) {
107
+ for (const lang of languages ?? [defaultLanguage]) {
108
+ const map = await loadMergedLangMap(id, lang);
109
+ (trees[lang] ??= {})[id] = {
110
+ name: datasetTitle ?? id,
111
+ children: await datasetBookLeaves(id, map),
112
+ $id: `guide/${id}/${lang}`,
113
+ } satisfies PageTree.Root;
114
+ }
115
+ }
116
+ return trees;
117
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "guide": {
3
+ "entry_count": "{count} entries",
4
+ "page_count": "{count} pages",
5
+ "entry_missing": "Entry not found",
6
+ "entity_unavailable": "Entity preview unavailable",
7
+ "link": "Open",
8
+ "objective": "Objective",
9
+ "quest": "Quest",
10
+ "recipe_empty": "No recipes",
11
+ "related": "Related"
12
+ },
13
+ "ui": {
14
+ "select_book": "Select book"
15
+ },
16
+ "sections": {
17
+ "guide": "Guide",
18
+ "desc": {
19
+ "guide": "Gameplay guide"
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "guide": {
3
+ "entry_count": "Записей: {count}",
4
+ "page_count": "Страниц: {count}",
5
+ "entry_missing": "Запись не найдена",
6
+ "entity_unavailable": "Превью сущности недоступно",
7
+ "link": "Открыть",
8
+ "objective": "Задача",
9
+ "quest": "Квест",
10
+ "recipe_empty": "Нет рецептов",
11
+ "related": "Связанное"
12
+ },
13
+ "ui": {
14
+ "select_book": "Выберите книгу"
15
+ },
16
+ "sections": {
17
+ "guide": "Гайды",
18
+ "desc": {
19
+ "guide": "Игровой гайд"
20
+ }
21
+ }
22
+ }
package/src/locales.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { createLocaleCatalog } from '@terrafirmagreg-team/translate/lib/locales';
2
+
3
+ export const locales = createLocaleCatalog(
4
+ import.meta.glob('./locales/*.json', { eager: true, import: 'default' }),
5
+ );
@@ -0,0 +1,215 @@
1
+ import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
2
+ import type { DatasetLanding } from '@terrafirmagreg-team/kit/types';
3
+ import type { DumpText } from '@terrafirmagreg-team/game/lib/dump/contract/text';
4
+ import type {
5
+ ReferenceKind,
6
+ TaggedReference,
7
+ } from '@terrafirmagreg-team/game/lib/dump/contract/ref';
8
+ import type { GuidePage } from '@terrafirmagreg-team/guide/lib/data/dto';
9
+ import type { AtlasBundle } from '@terrafirmagreg-team/game/lib/dump/assets/atlas/dto';
10
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
11
+ import type { DumpEntityEntry } from '@terrafirmagreg-team/game/lib/dump/data/registry/dto';
12
+ import type { PagePreviewData } from '@terrafirmagreg-team/ui/types/preview';
13
+
14
+ export type {
15
+ GuideMultiblock,
16
+ GuidePage,
17
+ GuideTableCell,
18
+ GuideTableLegend,
19
+ } from '@terrafirmagreg-team/guide/lib/data/dto';
20
+
21
+ export type GuideEntry = {
22
+ id: string;
23
+ name?: string;
24
+ category?: string;
25
+ icon?: TaggedReference;
26
+ pages?: GuidePage[];
27
+ order?: number;
28
+ contentLanguage?: Lang;
29
+
30
+ translation?: 'untranslated' | 'partial';
31
+ };
32
+
33
+ export type GuideEntryRef = {
34
+ id: string;
35
+ name: string;
36
+ icon?: TaggedReference;
37
+ pageCount?: number;
38
+ order?: number;
39
+ translation?: 'untranslated' | 'partial';
40
+ };
41
+
42
+ export type GuideCategory = {
43
+ id: string;
44
+ name: string;
45
+ description?: string;
46
+ icon?: TaggedReference;
47
+ entries: GuideEntryRef[];
48
+ order?: number;
49
+ translation?: 'untranslated' | 'partial';
50
+ };
51
+
52
+ export type GuideBook = {
53
+ id?: string;
54
+ slug: string;
55
+ name: string;
56
+ description?: string;
57
+ landing: DumpText[];
58
+ landingText?: string;
59
+ cover: TaggedReference | null;
60
+ macros?: Record<string, string>;
61
+ translation?: 'untranslated' | 'partial';
62
+ };
63
+
64
+ export type GuideIndex = {
65
+ status: 'missing' | 'ready';
66
+ root: string;
67
+ modId: string;
68
+ bookId?: string;
69
+ bookPath?: string;
70
+ bookSlug?: string;
71
+ book: GuideBook | null;
72
+ categories: GuideCategory[];
73
+ entries: GuideEntry[];
74
+ language: Lang;
75
+ isFallback: boolean;
76
+ };
77
+
78
+ type GuideMultiblockDef = {
79
+ id: string;
80
+ pattern?: string[][];
81
+ mapping?: Record<string, unknown>;
82
+ glb?: string;
83
+ error?: string | null;
84
+ };
85
+
86
+ type GuideEntityRender = {
87
+ path?: string;
88
+ scale?: number;
89
+ offset?: number;
90
+ width?: number;
91
+ height?: number;
92
+ };
93
+
94
+ export type GuideBookMeta = {
95
+ bookId?: string;
96
+ name?: string;
97
+ multiblockDefs?: GuideMultiblockDef[];
98
+ entityRenders?: Record<string, GuideEntityRender>;
99
+ };
100
+
101
+ export type GuideFormatNode =
102
+ | {
103
+ type: 'text';
104
+ value: string;
105
+ styles: string[];
106
+ color?: string;
107
+ link?: string;
108
+ tooltip?: string;
109
+ }
110
+ | { type: 'break' }
111
+ | { type: 'keybind'; value: string }
112
+ | { type: 'command'; value: string; label?: string };
113
+
114
+ export type GuideFormatOptions = {
115
+ dataset?: string;
116
+ lang?: Lang;
117
+ modId?: string;
118
+ bookPath?: string;
119
+ categoryByEntry?: Map<string, string>;
120
+ macros?: Record<string, string>;
121
+ langMap?: Record<string, string>;
122
+ keybinds?: Record<string, string>;
123
+ questLinks?: Record<string, { filename: string; questId: string }>;
124
+ previews?: Record<string, PagePreviewData>;
125
+ };
126
+
127
+ export type GuideCategoryRef = {
128
+ id: string;
129
+ };
130
+
131
+ type GuideReferenceKind = 'guide' | 'recipe' | 'quest';
132
+
133
+ export type GuideReference = {
134
+ kind: GuideReferenceKind;
135
+ id: string;
136
+ anchor?: string;
137
+ };
138
+
139
+ export type ResolvedGuideReference = GuideReference & {
140
+ href?: string;
141
+ available: boolean;
142
+ };
143
+
144
+ export type GuideReferenceContext = {
145
+ dataset: string;
146
+ lang: Lang;
147
+ modId: string;
148
+ bookPath: string;
149
+ categoryByEntry: Map<string, string>;
150
+ questLinks?: Record<string, { filename: string; questId: string }>;
151
+ targets?: Partial<
152
+ Record<'recipe' | 'quest', (id: string) => string | undefined>
153
+ >;
154
+ };
155
+
156
+ export type GuideTocLabels = {
157
+ related?: string;
158
+ objective?: string;
159
+ };
160
+
161
+ export type GuidePageKind = 'pack' | 'overview' | 'category' | 'entry';
162
+
163
+ export type GuidePageData = DatasetLanding;
164
+
165
+ export type PageRendererProps = {
166
+ dataset: string;
167
+ lang: Lang;
168
+ bookPath: string;
169
+ page: GuidePage;
170
+ atlases?: Record<string, AtlasBundle>;
171
+ meta: GuideBookMeta;
172
+ bookModId: string;
173
+ categoryByEntry: Map<string, string>;
174
+ langMap: Record<string, string>;
175
+ entryRefs: Map<string, GuideEntryRef>;
176
+ keybinds?: Record<string, string>;
177
+ book?: GuideBook | null;
178
+ extras?: GuideEntryExtras;
179
+ questLinks?: Record<string, { filename: string; questId: string }>;
180
+ previews?: Record<string, PagePreviewData>;
181
+ messages: GuideMessages;
182
+ };
183
+
184
+ export type GuideMessages = Record<string, string>;
185
+
186
+ export type GuideEntryExtras = {
187
+ atlases: Record<string, AtlasBundle>;
188
+ keybinds: Record<string, string>;
189
+ recipes: Record<string, Recipe>;
190
+ entities: Record<string, DumpEntityEntry>;
191
+ entityNames: Record<string, string>;
192
+ glbs: Record<string, string>;
193
+ };
194
+
195
+ export type GuidePagePayload = {
196
+ kind: GuidePageKind;
197
+ dataset: string;
198
+ lang: Lang;
199
+ title: string;
200
+ modId?: string;
201
+ bookPath?: string;
202
+ description?: string;
203
+ previewIcon?: string;
204
+ previewKind?: ReferenceKind;
205
+ categoryId?: string;
206
+ bookModId?: string;
207
+ book?: GuideBook | null;
208
+ categories?: GuideCategory[];
209
+ entries?: GuideEntry[];
210
+ entry?: GuideEntry;
211
+ extras?: GuideEntryExtras;
212
+ questLinks?: Record<string, { filename: string; questId: string }>;
213
+ previews?: Record<string, PagePreviewData>;
214
+ messages: GuideMessages;
215
+ };
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.