rpg-engine 0.8.0 → 0.9.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.
@@ -7,8 +7,8 @@ import { findPage, pageFileNamed, pageNamed as pageWithName, sectionTitles } fro
7
7
  import { bookTitles, findRules, hasAllWords, readRuleBook, shownRules } from "../rules/index.js";
8
8
  import { systemContentFolders } from "../systems/index.js";
9
9
  import { libraryAnswer, libraryLines, systemWordsNamed } from "./shared/library.js";
10
- import { disagreementAdvice, houseRules, precedentRule, systemRuleBook } from "./shared/rules.js";
11
- import { campaignSystem, campaignWorld, foreignLanguage } from "./shared/world.js";
10
+ import { disagreementAdvice, hasTranslatedRules, houseRules, precedentRule, systemRuleBook } from "./shared/rules.js";
11
+ import { campaignSystem, campaignSystemWords, campaignWorld, foreignLanguage } from "./shared/world.js";
12
12
  // About how many words an answer shows: a section of the system has about 80 words in the middle (D-178).
13
13
  const answerWords = 800;
14
14
  // What the rules add when the text is the name of a page, which holds the answer: a spell, an item (D-195).
@@ -34,13 +34,16 @@ export const rules = defineCommand({
34
34
  // Read one by one, as the system is (SYS-1): a mistake elsewhere in campaign.yaml does not stop the rules.
35
35
  const precedents = readListSetting(root, "precedents");
36
36
  const house = readRuleBook(join(root, houseRulesFolderName), houseRules);
37
- const book = system === undefined ? [] : systemRuleBook(system);
37
+ const campaignLanguage = readTextSetting(root, "language");
38
+ // In the campaign's language where the system has its rules in it (D-542).
39
+ const translated = system !== undefined && hasTranslatedRules(system, campaignLanguage);
40
+ const book = system === undefined ? [] : systemRuleBook(system, campaignLanguage);
38
41
  const text = input.text?.trim() ?? "";
39
42
  const common = {
40
43
  text,
41
44
  system: system?.name,
42
45
  missingSystem: named !== undefined && system === undefined ? named : undefined,
43
- language: system === undefined ? undefined : foreignLanguage(system.language, readTextSetting(root, "language")),
46
+ language: system === undefined || translated ? undefined : foreignLanguage(system.language, campaignLanguage),
44
47
  houseRules: bookTitles(house),
45
48
  chapters: chaptersOf(book),
46
49
  };
@@ -53,16 +56,16 @@ export const rules = defineCommand({
53
56
  // Or the sections of pages it names, as a class's features: Cleric › Domain Spells, or Domain Spells alone (RUL-6).
54
57
  const pageSections = page === undefined ? sectionsNamed(root, context, text) : [];
55
58
  const budget = page === undefined && pageSections.length === 0 ? answerWords : answerWordsBesidePage;
56
- // Searched in the campaign's language, the system is searched by its own names too, as its words in that language give them (RUL-8): afferrato, Grappled.
57
- const campaignLanguage = readTextSetting(root, "language");
58
- const ownNames = system === undefined || campaignLanguage === undefined || /[›>/]/.test(text) ? [] : systemWordsNamed(system, campaignLanguage, text, true).filter((one) => !hasAllWords(text, one.named));
59
+ // Searched in the campaign's language, the system is searched by its own names too, as its words in that language give them (RUL-8): afferrato, Grappled;
60
+ // its rules in that language, by the campaign's words for the system's: grappled, Afferrato (D-542).
61
+ const ownNames = system === undefined || campaignLanguage === undefined || /[›>/]/.test(text) ? [] : systemWordsNamed(system, campaignLanguage, text, !translated).filter((one) => !hasAllWords(text, one.named));
59
62
  const systemNames = ownNames.map((one) => one.named);
60
63
  // A name answers for the system only when its words are the whole search: tiro per colpire is no question about Archery, Tiro.
61
64
  const answering = ownNames.filter((one) => one.whole).map((one) => one.named);
62
65
  const found = findRules([...house, ...book], [text, ...systemNames].join(" "));
63
66
  const houseAnswer = answerOf(found.filter((finding) => finding.section.source === houseRules), budget);
64
67
  const systemAnswer = answerOf(found.filter((finding) => finding.section.source !== houseRules), budget - houseAnswer.used);
65
- const shownTitles = [...houseAnswer.shown, ...systemAnswer.shown].map((shown) => shown.path.at(-1) ?? "");
68
+ const shownTitles = withEnglishTitles([...houseAnswer.shown, ...systemAnswer.shown].map((shown) => shown.path.at(-1) ?? ""), translated ? campaignSystemWords(root, context) : undefined);
66
69
  // Then the player's books, fewer of them when the rules have answered: a section shown holds every word searched, or a name the system gave them (LIB-6, LIB-7).
67
70
  const answered = [...houseAnswer.shown, ...systemAnswer.shown].some((shown) => [text, ...answering].some((searched) => hasAllWords(`${shown.path.join(" ")} ${shown.text}`, searched)));
68
71
  const library = libraryAnswer(root, context, system, text, answered);
@@ -110,6 +113,11 @@ function isAboutAny(precedent, text, titles) {
110
113
  const rule = precedentRule(precedent);
111
114
  return rule !== undefined && (hasAllWords(text, rule) || titles.some((title) => comparableText(rule) === comparableText(title)));
112
115
  }
116
+ /** The titles of the sections shown with the system's names of those in the campaign's language, so that "Poisoned: …" goes with Avvelenato too (D-542). */
117
+ function withEnglishTitles(titles, words) {
118
+ const english = Object.entries(words ?? {}).filter(([, own]) => titles.some((title) => comparableText(title) === comparableText(own))).map(([name]) => name);
119
+ return [...titles, ...english];
120
+ }
113
121
  /**
114
122
  * The page of the campaign, or else of the game system, whose name or alias is the text: it holds rules too, such as a spell or how long a potion takes to drink.
115
123
  */
@@ -82,8 +82,8 @@ export function knowsPage(knowledge, page) {
82
82
  */
83
83
  export function knownText(world, knowledge, page) {
84
84
  const parts = [
85
- ...partsOf(page),
86
- ...inheritedByBase(world, page).flatMap((group) => group.parts.map((part) => ({ ...part, holder: group.base }))),
85
+ ...readableParts(page),
86
+ ...inheritedByBase(world, page).flatMap((group) => readableInherited(group).map((part) => ({ ...part, holder: group.base }))),
87
87
  ].filter((part) => isShown(knowledge, page, part));
88
88
  return inKnownWords(world, knowledge, withoutComments([knownIntroduction(world, knowledge, page), ...parts.map((part) => part.text)].filter((text) => text !== "").join("\n\n")));
89
89
  }
@@ -97,7 +97,8 @@ export function knownSecretsApart(world, knowledge, page) {
97
97
  }
98
98
  /** A page's introduction as the character knows it (VIEW-3): its own, else that of its nearest base it knows; without comments. */
99
99
  export function knownIntroduction(world, knowledge, page) {
100
- const introduction = introductionText(page.body) || (baseChain(world, page).filter((base) => knowsPage(knowledge, base)).map((base) => introductionText(base.body)).find((text) => text !== "") ?? "");
100
+ const introduction = introductionText(page.translated ?? page.body)
101
+ || (baseChain(world, page).filter((base) => knowsPage(knowledge, base)).map((base) => introductionText(base.translated ?? base.body)).find((text) => text !== "") ?? "");
101
102
  return inKnownWords(world, knowledge, withoutComments(introduction));
102
103
  }
103
104
  /**
@@ -199,6 +200,17 @@ function isShown(knowledge, page, part) {
199
200
  function partsOf(page) {
200
201
  return textParts(page.body).map((part) => ({ ...part, holder: page }));
201
202
  }
203
+ /** A page's sections as the player reads them: a system's page in the campaign's language where it has it (D-542). */
204
+ function readableParts(page) {
205
+ return textParts(page.translated ?? page.body).map((part) => ({ ...part, holder: page }));
206
+ }
207
+ /**
208
+ * The sections a page inherits from a base as the player reads them: in the campaign's language when the base has it and every section of it reaches the page
209
+ * (D-542), as the stat block of a wolf for a companion; else as the base writes them, since a section the page has of its own hides one by its English name.
210
+ */
211
+ function readableInherited(group) {
212
+ return group.base.translated !== undefined && group.parts.length === textParts(group.base.body).length ? textParts(group.base.translated) : group.parts;
213
+ }
202
214
  function isSecretText(text) {
203
215
  return /^[ \t]{0,3}>[ \t]*\[!secret\]/i.test(text);
204
216
  }
@@ -10,10 +10,18 @@ export interface TitledRule {
10
10
  text: string;
11
11
  precedents: string[];
12
12
  }
13
- /** The rule with this title: a house rule first, else the game system's; undefined when neither has a section so titled. */
13
+ /**
14
+ * The rule with this title: a house rule first, else the game system's, in the campaign's language where the system has its rules in it, by the title's word
15
+ * there, Prono for Prone (D-542); undefined when neither has a section so titled.
16
+ */
14
17
  export declare function ruleTitled(root: string, system: GameSystem, title: string): TitledRule | undefined;
15
- /** The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file. */
16
- export declare function systemRuleBook(system: GameSystem): RuleSection[];
18
+ /**
19
+ * The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file.
20
+ * In a language the system has its rules in, a chapter translated takes the place of its English one (D-542).
21
+ */
22
+ export declare function systemRuleBook(system: GameSystem, language?: string): RuleSection[];
23
+ /** Whether a game system has its rules in a language, in one of its folders (D-542). */
24
+ export declare function hasTranslatedRules(system: GameSystem, language: string | undefined): boolean;
17
25
  /** "Poisoned is a condition of the system 5e, by a house rule:" and the text, then the precedents on it, with what to do when they disagree with the book. */
18
26
  export declare function ruleBlock(rule: TitledRule): string;
19
27
  /** The rule a precedent is about: the name before its colon, as in "Poisoned: …" (D-179); undefined when it has none. */
@@ -1,29 +1,59 @@
1
1
  // A rule by its title, as rules finds it (D-179, DAT-3, DAT-6): a house rule of the campaign first, else the game system's, with the table's precedents on it.
2
2
  import { join } from "node:path";
3
- import { houseRulesFolderName, readListSetting } from "../../campaign/index.js";
3
+ import { houseRulesFolderName, readListSetting, readTextSetting } from "../../campaign/index.js";
4
+ import { translationFolder } from "../../core/files.js";
4
5
  import { comparableText } from "../../core/text.js";
5
6
  import { isTitled, readRuleBook } from "../../rules/index.js";
6
- import { systemContentFolders } from "../../systems/index.js";
7
+ import { layeredSystemWords, systemContentFolders } from "../../systems/index.js";
7
8
  /** The source of the campaign's own rules, in the campaign's rules folder. */
8
9
  export const houseRules = "house rules";
9
10
  /** What to do when a precedent and the book disagree (D-181). */
10
11
  export const disagreementAdvice = "When the text and a precedent disagree, tell the player and ask whether to keep the precedent: if so, write it again saying it is a house rule, against the book; if not, remove it. Both with config.";
11
- /** The rule with this title: a house rule first, else the game system's; undefined when neither has a section so titled. */
12
+ /**
13
+ * The rule with this title: a house rule first, else the game system's, in the campaign's language where the system has its rules in it, by the title's word
14
+ * there, Prono for Prone (D-542); undefined when neither has a section so titled.
15
+ */
12
16
  export function ruleTitled(root, system, title) {
13
17
  const titled = (section) => isTitled(section, title);
18
+ const language = readTextSetting(root, "language");
19
+ const own = ownWord(system, language, title);
14
20
  const house = readRuleBook(join(root, houseRulesFolderName), houseRules).find(titled);
15
- const section = house ?? systemRuleBook(system).find(titled);
21
+ const section = house ?? systemRuleBook(system, language).find((one) => titled(one) || (own !== undefined && isTitled(one, own))) ?? systemRuleBook(system).find(titled);
16
22
  if (section === undefined) {
17
23
  return undefined;
18
24
  }
19
25
  const precedents = readListSetting(root, "precedents").filter((precedent) => comparableText(precedentRule(precedent) ?? "") === comparableText(title));
20
26
  return { source: section.source, text: section.text, precedents };
21
27
  }
22
- /** The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file. */
23
- export function systemRuleBook(system) {
24
- const [own, version] = systemContentFolders(system).map((folder) => readRuleBook(join(folder, "rules"), system.name));
28
+ /**
29
+ * The rules of a game system, its own with those of the version of its rules (VER-3): a chapter of the version takes the place of a common one of its file.
30
+ * In a language the system has its rules in, a chapter translated takes the place of its English one (D-542).
31
+ */
32
+ export function systemRuleBook(system, language) {
33
+ const [own, version] = systemContentFolders(system).map((folder) => translatedBook(readRuleBook(join(folder, "rules"), system.name), translationFolder(folder, language), system.name));
25
34
  return version === undefined ? own : [...own.filter((section) => !version.some((other) => other.file === section.file)), ...version];
26
35
  }
36
+ /** Whether a game system has its rules in a language, in one of its folders (D-542). */
37
+ export function hasTranslatedRules(system, language) {
38
+ return systemContentFolders(system).some((folder) => {
39
+ const translations = translationFolder(folder, language);
40
+ return translations !== undefined && readRuleBook(join(translations, "rules"), system.name).length > 0;
41
+ });
42
+ }
43
+ /** A word of the system in a language, by its English, as Prono for Prone; none without it, or when its words do not read, which validate says. */
44
+ function ownWord(system, language, english) {
45
+ try {
46
+ return language === undefined ? undefined : layeredSystemWords(systemContentFolders(system), language)?.words[english];
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ }
52
+ function translatedBook(book, translations, system) {
53
+ const translated = translations === undefined ? [] : readRuleBook(join(translations, "rules"), system);
54
+ const files = new Set(translated.map((section) => section.file));
55
+ return files.size === 0 ? book : [...book.filter((section) => !files.has(section.file)), ...translated].sort((first, second) => (first.file < second.file ? -1 : first.file > second.file ? 1 : 0));
56
+ }
27
57
  /** "Poisoned is a condition of the system 5e, by a house rule:" and the text, then the precedents on it, with what to do when they disagree with the book. */
28
58
  export function ruleBlock(rule) {
29
59
  const precedents = rule.precedents.length === 0 ? "" : `\n\nPrecedents of the table: ${rule.precedents.join(" · ")}`;
@@ -8,6 +8,7 @@ export declare const show: import("../core/registry.ts").Command<z.ZodObject<{
8
8
  type?: undefined;
9
9
  path?: undefined;
10
10
  system?: undefined;
11
+ title?: undefined;
11
12
  hides?: undefined;
12
13
  namesakes?: undefined;
13
14
  section?: undefined;
@@ -41,6 +42,7 @@ export declare const show: import("../core/registry.ts").Command<z.ZodObject<{
41
42
  type?: undefined;
42
43
  path?: undefined;
43
44
  system?: undefined;
45
+ title?: undefined;
44
46
  hides?: undefined;
45
47
  namesakes?: undefined;
46
48
  section?: undefined;
@@ -72,6 +74,7 @@ export declare const show: import("../core/registry.ts").Command<z.ZodObject<{
72
74
  type: "place" | "quest" | "creature" | "item" | "character" | "faction" | "event" | "topic" | undefined;
73
75
  path: string;
74
76
  system: string | undefined;
77
+ title: string | undefined;
75
78
  hides: string | undefined;
76
79
  namesakes: string[];
77
80
  section: string | undefined;
@@ -77,6 +77,7 @@ export const show = defineCommand({
77
77
  type: page.type,
78
78
  path: page.path,
79
79
  system: page.system,
80
+ title: page.title,
80
81
  hides: page.system === undefined && !isCopy && systemPageNamed(world, page.name) !== undefined ? world.system?.name : undefined,
81
82
  // Acolyte (background) beside the creature Acolyte: the name alone leads here (SYS-2).
82
83
  namesakes: isCopy || reference.section !== undefined ? [] : namesakes(world, page).map((other) => `${other.name}, ${other.system === undefined ? withArticle(other.type ?? "page") : systemLabel(other)}`),
@@ -107,7 +108,8 @@ export const show = defineCommand({
107
108
  parts: group.parts.filter((piece) => piece.text.split("\n").slice(1).some((line) => line.trim() !== "")).map((piece) => piece.name),
108
109
  }))
109
110
  : [],
110
- text: group === undefined ? (part?.text ?? page.body) : "",
111
+ // A system's page in the campaign's language where it has it, whole (D-542); a section as the system writes it.
112
+ text: group === undefined ? (part?.text ?? page.translated ?? page.body) : "",
111
113
  linkedFrom: isCopy ? [] : backlinks(world, page).map((link) => ({ page: link.page.name, places: link.places })),
112
114
  problems: world.problems,
113
115
  loot: reference.section === undefined ? (lootNote(world, system, page, chain) ?? fallenCopiesNote(root, world, system, page)) : undefined,
@@ -135,6 +137,7 @@ export const show = defineCommand({
135
137
  }
136
138
  const header = [
137
139
  title,
140
+ result.title === undefined ? "" : `Named in the campaign's language: ${result.title}.`,
138
141
  result.hides === undefined ? "" : `This page hides the system ${result.hides}'s ${result.page}: links to that name lead here.`,
139
142
  result.namesakes.length === 0 ? "" : `There is also ${result.namesakes.join("; ")}: show it by that name.`,
140
143
  result.alsoCopy ? `${result.page} is also a copy in the open scene: change and write refuse both until the scene closes, which removes the copy, or the page is renamed.` : "",
@@ -242,7 +242,7 @@ export const view = defineCommand({
242
242
  kind: "overview",
243
243
  campaign: settings.name,
244
244
  ...(settings.language === undefined ? {} : { language: settings.language }),
245
- ...(words === undefined ? {} : { words }),
245
+ ...(words === undefined ? {} : { words: withPageTitles(words, world) }),
246
246
  ...(system === undefined || Object.keys(system.sheetVerbs).length === 0 ? {} : { verbs: system.sheetVerbs }),
247
247
  ...(system === undefined ? {} : { system: { name: system.name, title: system.title, ...(system.attribution === undefined ? {} : { attribution: system.attribution }) } }),
248
248
  ...(now === undefined ? {} : { now: formatGameDate(now) }),
@@ -349,6 +349,11 @@ function shownPage(root, context, world, knowledge, page, party) {
349
349
  ...(story === undefined ? {} : { story }),
350
350
  };
351
351
  }
352
+ /** The system's words for the page, with the names its translation gives its pages, as Palla di fuoco for Fireball, where its words do not name them (D-542). */
353
+ function withPageTitles(words, world) {
354
+ const titles = Object.fromEntries((world.system?.pages ?? []).flatMap((page) => (page.title === undefined ? [] : [[page.name, page.title]])));
355
+ return Object.keys(titles).length === 0 ? words : { ...words, words: { ...titles, ...words.words } };
356
+ }
352
357
  /** "Known to Bruna alone: Ettore plays as not knowing it, though all at the screen may read it.": who knows a page, and how the others are played (VIEW-12). */
353
358
  function whoKnowsText(who, unaware) {
354
359
  const others = unaware.length === 0 ? "" : `: ${unaware.join(" and ")} ${unaware.length === 1 ? "plays" : "play"} as not knowing it, though all at the screen may read it`;
@@ -4,6 +4,8 @@ export declare function foldersIn(folder: string): string[];
4
4
  export declare function filesIn(folder: string, keep: (name: string) => boolean): string[];
5
5
  /** The order of a folder's files, the same on every system: those nearer the folder first, then by path, as Windows lists them, case aside. */
6
6
  export declare function fileOrder(first: string, second: string): number;
7
+ /** Where a game system keeps its text in a language, translations/it, by the language's code or its base one (D-542); undefined when it has none. */
8
+ export declare function translationFolder(folder: string, language: string | undefined): string | undefined;
7
9
  /**
8
10
  * The folders of the packages in these folders of npm's, in their scopes' folders too (@rpgengine/weather), links to folders included, as npm links a package
9
11
  * installed from a folder (D-441); never followed further.
@@ -34,6 +34,12 @@ export function fileOrder(first, second) {
34
34
  const [one, other] = [first.toUpperCase(), second.toUpperCase()];
35
35
  return depth(first) - depth(second) || (one < other ? -1 : one > other ? 1 : first < second ? -1 : first > second ? 1 : 0);
36
36
  }
37
+ /** Where a game system keeps its text in a language, translations/it, by the language's code or its base one (D-542); undefined when it has none. */
38
+ export function translationFolder(folder, language) {
39
+ const code = language?.trim().toLowerCase();
40
+ const codes = code === undefined || code === "" ? [] : [...new Set([code, code.split("-")[0]])];
41
+ return codes.map((one) => join(folder, "translations", one)).find((path) => existsSync(path) && statSync(path).isDirectory());
42
+ }
37
43
  /**
38
44
  * The folders of the packages in these folders of npm's, in their scopes' folders too (@rpgengine/weather), links to folders included, as npm links a package
39
45
  * installed from a folder (D-441); never followed further.
@@ -1,5 +1,5 @@
1
1
  import { fieldLabel, phraseLabel } from "./labels.js";
2
- import { isolated, listText, systemWord, t } from "./text.js";
2
+ import { isolated, listText, systemWord, systemWordAnyCase, t } from "./text.js";
3
3
  /** A game date in the page's language: day 3, 06:00, or day 3; any other text as it is. */
4
4
  export function gameDateLabel(date) {
5
5
  const read = readDate(date);
@@ -80,9 +80,9 @@ export function effectLabel(effect) {
80
80
  export function burnsLabel(name, burns) {
81
81
  return burns.fuel === name ? t("{count} left", { count: burns.left }) : t("{fuel}: {count} left", { fuel: effectName(burns.fuel), count: burns.left });
82
82
  }
83
- /** An effect's name in the page's language: a condition of the system in its words, as Unconscious in Italian; any other as written. */
83
+ /** An effect's name in the page's language: a condition of the system in its words, as Unconscious in Italian, whatever its capitals; any other as written. */
84
84
  export function effectName(name) {
85
- return systemWord("words", name) ?? name;
85
+ return systemWordAnyCase("words", name) ?? name;
86
86
  }
87
87
  /** Where a place is from the party, in the page's language: 12 km north-east, Here; the length as `length` writes it in the player's units. */
88
88
  export function fromLabel(from, length) {
@@ -154,7 +154,7 @@ export function factLabel(fact) {
154
154
  case "effect":
155
155
  return t("{who}: {effect}", { who: subjectLabel(fact.who), effect: effectLabel(fact) });
156
156
  case "effect-ended":
157
- return t("{who}: {effect} ended", { who: subjectLabel(fact.who), effect: fact.effect });
157
+ return t("{who}: {effect} ended", { who: subjectLabel(fact.who), effect: effectName(fact.effect) });
158
158
  case "back":
159
159
  return t("Back to save {save}: what came after it is gone", { save: fact.save });
160
160
  case "quest":
@@ -118,7 +118,7 @@ function Group({ member, group, fields, version, onRoll, first }) {
118
118
  const line = (value) => ({ value, label: label(value.field), fields, tip: tip(value), tabIndex: stop(value.field), onRoll: throwOf, answers: answersOf(value) });
119
119
  // A card with the number the master asks stays open while it is asked.
120
120
  const lit = values.some((value) => answersOf(value) !== undefined);
121
- return (_jsxs(Card, { name: group.name, title: systemWord("groups", group.name), icon: group.icon ?? cardIcons.plain, layout: layout, preview: preview(group, label), onReach: explain, held: lit, first: first, children: [layout === "table" && values.length > 0 && (_jsx("div", { class: "rows", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Row, { ...line(value) }, value.field)) })), layout === "table" && _jsx(ItemsTable, { group: group, fields: fields }), layout === "tiles" && (_jsx("div", { class: "tiles", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Tile, { ...line(value) }, value.field)) })), layout === "rows" && (_jsx("div", { class: "rows", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Row, { ...line(value) }, value.field)) }))] }));
121
+ return (_jsxs(Card, { name: group.name, title: systemWord("groups", group.name) ?? systemWord("words", group.name), icon: group.icon ?? cardIcons.plain, layout: layout, preview: preview(group, label), onReach: explain, held: lit, first: first, children: [layout === "table" && values.length > 0 && (_jsx("div", { class: "rows", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Row, { ...line(value) }, value.field)) })), layout === "table" && _jsx(ItemsTable, { group: group, fields: fields }), layout === "tiles" && (_jsx("div", { class: "tiles", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Tile, { ...line(value) }, value.field)) })), layout === "rows" && (_jsx("div", { class: "rows", onKeyDown: onKeyDown, children: values.map((value) => _jsx(Row, { ...line(value) }, value.field)) }))] }));
122
122
  }
123
123
  /** A card of the sheet the player opens and closes (D-284): its icon and title on the left, what it holds while closed, the chevron on the right. */
124
124
  export function Card({ name, title, icon, layout, preview, onReach, held, first, children }) {
@@ -93,6 +93,12 @@ export function systemWord(kind, english) {
93
93
  const words = system[kind] ?? {};
94
94
  return Object.hasOwn(words, english) ? words[english] : undefined;
95
95
  }
96
+ /** A word of the game system whatever its capitals, as an effect written by hand: prone as Prone. */
97
+ export function systemWordAnyCase(kind, english) {
98
+ const words = system[kind] ?? {};
99
+ const key = Object.hasOwn(words, english) ? english : Object.keys(words).find((word) => word.toLowerCase() === english.toLowerCase());
100
+ return key === undefined ? undefined : words[key];
101
+ }
96
102
  /**
97
103
  * A phrase of the page in its language, or a text of the game system in its words, each {name} filled from values; the English where it has none. In a
98
104
  * language written from right to left each value is isolated, so that a name, a number or a notation keeps its own order: +2, 1d20+5.
@@ -16,6 +16,10 @@ export interface Page {
16
16
  body: string;
17
17
  /** The game system the page comes from, such as 5e: read-only, and nowhere (SYS-2). Undefined for the campaign's own pages. */
18
18
  system?: string;
19
+ /** A system page's name in the campaign's language, from the system's translation (D-542), as Palla di fuoco for Fireball; links still use its name. */
20
+ title?: string;
21
+ /** A system page's text in the campaign's language, for who reads it (D-542); `body` stays the system's, which the sheet's features are read from. */
22
+ translated?: string;
19
23
  }
20
24
  /** Every page of a campaign, read from its world folder, and the pages of its game system. */
21
25
  export interface World {
@@ -1,4 +1,5 @@
1
1
  import { basename, join, relative, resolve, sep } from "node:path";
2
+ import { translationFolder } from "../core/files.js";
2
3
  import { frozen } from "../core/frozen.js";
3
4
  import { files } from "../core/store.js";
4
5
  import { comparableText, valueNamed } from "../core/text.js";
@@ -29,7 +30,8 @@ export function loadWorld(root, options = {}) {
29
30
  if (system === undefined) {
30
31
  return frozen({ root, ...campaign, language, missingSystem, noSystem, ...(rigor === undefined ? {} : { rigor }) });
31
32
  }
32
- const systemPages = system.version === undefined ? packagePages(system.folder, system.name) : versionPages(packagePages(system.folder, system.name), packagePages(system.version.folder, system.name));
33
+ const read = (folder) => translatedPages(packagePages(folder, system.name), folder, system.name, language);
34
+ const systemPages = system.version === undefined ? read(system.folder) : versionPages(read(system.folder), read(system.version.folder));
33
35
  const { name, title, fields, formulas, progression, itemFormulas, alwaysIn, uses, statusLine, load, lengthUnit, bonusLists, bonusWhile } = system;
34
36
  const problems = [...campaign.problems, ...systemPages.problems];
35
37
  return frozen({
@@ -356,6 +358,30 @@ function packagePages(folder, system) {
356
358
  return known;
357
359
  }
358
360
  const packages = new Map();
361
+ /**
362
+ * A system's pages with their text and their name in the campaign's language beside their own, where the system has a translation of them in it, by the same
363
+ * path under translations/<language> (D-542); their fields and text stay, which the engine reads. Read once in a process, as the pages are.
364
+ */
365
+ function translatedPages(read, folder, system, language) {
366
+ const translations = translationFolder(folder, language);
367
+ if (translations === undefined) {
368
+ return read;
369
+ }
370
+ const key = `${translations}|${system}`;
371
+ const known = translated.get(key) ?? withTranslations(read, readPages(translations, system));
372
+ translated.set(key, known);
373
+ return known;
374
+ }
375
+ const translated = new Map();
376
+ function withTranslations(read, translations) {
377
+ const byPath = new Map(translations.pages.map((page) => [page.path, page]));
378
+ const pages = read.pages.map((page) => {
379
+ const other = byPath.get(page.path);
380
+ const title = typeof other?.fields.name === "string" && other.fields.name.trim() !== "" ? other.fields.name.trim() : undefined;
381
+ return other === undefined ? page : frozen({ ...page, translated: other.body, ...(title === undefined ? {} : { title }) });
382
+ });
383
+ return { pages, problems: [...read.problems, ...translations.problems] };
384
+ }
359
385
  /** A system's pages with those of the version of its rules over them (VER-3): a page of the version takes the place of a common one with its name. */
360
386
  function versionPages(common, version) {
361
387
  const names = new Set(version.pages.map((page) => comparableText(page.name)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
5
5
  "type": "module",
6
6
  "bin": {