rpg-engine 0.9.0 → 0.9.1
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/dist/commands/find.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const find: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
18
18
|
system: string | undefined;
|
|
19
19
|
systemMatches: {
|
|
20
20
|
page: string;
|
|
21
|
+
title: string | undefined;
|
|
21
22
|
type: "place" | "quest" | "creature" | "item" | "character" | "faction" | "event" | "topic" | undefined;
|
|
22
23
|
excerpt: string | undefined;
|
|
23
24
|
}[];
|
package/dist/commands/find.js
CHANGED
|
@@ -25,14 +25,15 @@ export const find = defineCommand({
|
|
|
25
25
|
// The game system's pages are found by name only, and listed only for a text: there may be hundreds (SYS-3).
|
|
26
26
|
const withText = (input.text?.trim() ?? "") !== "";
|
|
27
27
|
const system = searchSystemPages(world, input);
|
|
28
|
-
const listed = withText ? system.slice(0, listedSystemPages).map(({ page, excerpt }) => ({ page: page.name, type: page.type, excerpt })) : [];
|
|
28
|
+
const listed = withText ? system.slice(0, listedSystemPages).map(({ page, excerpt }) => ({ page: page.name, title: page.title, type: page.type, excerpt })) : [];
|
|
29
29
|
const byName = system.slice(listed.length).filter((match) => match.excerpt === undefined).length;
|
|
30
30
|
const systemFound = { system: world.system?.name, systemMatches: listed, systemMore: system.length - listed.length, systemMoreByName: byName, withText, type: input.type };
|
|
31
31
|
return { matches, ...systemFound, language: foreignSystemLanguage(world), searchHint: systemSearchHint(world).trim(), problems: world.problems };
|
|
32
32
|
},
|
|
33
33
|
format(result) {
|
|
34
34
|
const lines = result.matches.map((match) => `${match.page} (${match.type ?? "free page"})${match.excerpt === undefined ? "" : `: ${match.excerpt}`}`);
|
|
35
|
-
|
|
35
|
+
// A page's name in the campaign's language beside it, where the system has it (D-542): Hooded Lantern «Lanterna schermabile».
|
|
36
|
+
const system = result.systemMatches.map((match) => `${match.page}${match.title === undefined ? "" : ` «${match.title}»`} (${match.type ?? "page"}, system ${result.system ?? ""})${match.excerpt === undefined ? "" : `: ${match.excerpt}`}`);
|
|
36
37
|
const found = [...lines, ...system];
|
|
37
38
|
const note = systemNote(result, lines.length > 0);
|
|
38
39
|
// A name said in play and never written is no page: the player who remembers it is right (D-266).
|
package/dist/commands/rules.js
CHANGED
|
@@ -4,7 +4,7 @@ import { houseRulesFolderName, readListSetting, readTextSetting, requireCampaign
|
|
|
4
4
|
import { defineCommand } from "../core/registry.js";
|
|
5
5
|
import { comparableText } from "../core/text.js";
|
|
6
6
|
import { findPage, pageFileNamed, pageNamed as pageWithName, sectionTitles } from "../pages/index.js";
|
|
7
|
-
import { bookTitles, findRules, hasAllWords, readRuleBook, shownRules } from "../rules/index.js";
|
|
7
|
+
import { bookTitles, findRules, hasAllWords, isTitled, 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
10
|
import { disagreementAdvice, hasTranslatedRules, houseRules, precedentRule, systemRuleBook } from "./shared/rules.js";
|
|
@@ -62,7 +62,9 @@ export const rules = defineCommand({
|
|
|
62
62
|
const systemNames = ownNames.map((one) => one.named);
|
|
63
63
|
// A name answers for the system only when its words are the whole search: tiro per colpire is no question about Archery, Tiro.
|
|
64
64
|
const answering = ownNames.filter((one) => one.whole).map((one) => one.named);
|
|
65
|
-
|
|
65
|
+
// A text that is a section's title reads that section, by its own title or the one it has in the system's language (D-542).
|
|
66
|
+
const titled = [...house, ...book].some((section) => isTitled(section, text));
|
|
67
|
+
const found = findRules([...house, ...book], titled ? text : [text, ...systemNames].join(" "));
|
|
66
68
|
const houseAnswer = answerOf(found.filter((finding) => finding.section.source === houseRules), budget);
|
|
67
69
|
const systemAnswer = answerOf(found.filter((finding) => finding.section.source !== houseRules), budget - houseAnswer.used);
|
|
68
70
|
const shownTitles = withEnglishTitles([...houseAnswer.shown, ...systemAnswer.shown].map((shown) => shown.path.at(-1) ?? ""), translated ? campaignSystemWords(root, context) : undefined);
|
|
@@ -30,7 +30,8 @@ export function ruleTitled(root, system, title) {
|
|
|
30
30
|
* In a language the system has its rules in, a chapter translated takes the place of its English one (D-542).
|
|
31
31
|
*/
|
|
32
32
|
export function systemRuleBook(system, language) {
|
|
33
|
-
const
|
|
33
|
+
const words = language === undefined ? undefined : systemWordsIn(system, language);
|
|
34
|
+
const [own, version] = systemContentFolders(system).map((folder) => translatedBook(readRuleBook(join(folder, "rules"), system.name), translationFolder(folder, language), system.name, words));
|
|
34
35
|
return version === undefined ? own : [...own.filter((section) => !version.some((other) => other.file === section.file)), ...version];
|
|
35
36
|
}
|
|
36
37
|
/** Whether a game system has its rules in a language, in one of its folders (D-542). */
|
|
@@ -42,17 +43,40 @@ export function hasTranslatedRules(system, language) {
|
|
|
42
43
|
}
|
|
43
44
|
/** 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
45
|
function ownWord(system, language, english) {
|
|
46
|
+
return language === undefined ? undefined : systemWordsIn(system, language)?.[english];
|
|
47
|
+
}
|
|
48
|
+
/** The system's words in a language, by their English; none when it has none, or they do not read, which validate says. */
|
|
49
|
+
function systemWordsIn(system, language) {
|
|
45
50
|
try {
|
|
46
|
-
return
|
|
51
|
+
return layeredSystemWords(systemContentFolders(system), language)?.words;
|
|
47
52
|
}
|
|
48
53
|
catch {
|
|
49
54
|
return undefined;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A book with its chapters in a language in place of its own; a chapter whose sections match its own one by one, at the same levels and with the titles the
|
|
59
|
+
* system's words give, gives each the path it has there, so that the system's own titles, as its outputs name them, still find it (D-542).
|
|
60
|
+
*/
|
|
61
|
+
function translatedBook(book, translations, system, words) {
|
|
53
62
|
const translated = translations === undefined ? [] : readRuleBook(join(translations, "rules"), system);
|
|
54
|
-
const files = new Set(translated.map((section) => section.file));
|
|
55
|
-
|
|
63
|
+
const files = [...new Set(translated.map((section) => section.file))];
|
|
64
|
+
if (files.length === 0) {
|
|
65
|
+
return book;
|
|
66
|
+
}
|
|
67
|
+
const aliased = files.flatMap((file) => {
|
|
68
|
+
const own = book.filter((section) => section.file === file);
|
|
69
|
+
const other = translated.filter((section) => section.file === file);
|
|
70
|
+
return isParallel(own, other, words) ? other.map((section, index) => ({ ...section, alias: own[index].path })) : other;
|
|
71
|
+
});
|
|
72
|
+
return [...book.filter((section) => !files.includes(section.file)), ...aliased].sort((first, second) => (first.file < second.file ? -1 : first.file > second.file ? 1 : 0));
|
|
73
|
+
}
|
|
74
|
+
/** Whether a chapter's translation has its sections in the same order: as many, at the same levels, none named otherwise than the system's words name it. */
|
|
75
|
+
function isParallel(own, other, words) {
|
|
76
|
+
return own.length === other.length && own.every((section, index) => {
|
|
77
|
+
const word = words?.[section.path.at(-1) ?? ""];
|
|
78
|
+
return section.level === other[index].level && (word === undefined || comparableText(word) === comparableText(other[index].path.at(-1) ?? ""));
|
|
79
|
+
});
|
|
56
80
|
}
|
|
57
81
|
/** "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. */
|
|
58
82
|
export function ruleBlock(rule) {
|
|
@@ -17,6 +17,8 @@ export interface RuleSection {
|
|
|
17
17
|
ownText: string;
|
|
18
18
|
/** The titles of its parts, one level below. */
|
|
19
19
|
parts: string[];
|
|
20
|
+
/** Its path in the book it is translated from, by which it is found too, as Death Saving Throws for Tiri salvezza contro morte (D-542). */
|
|
21
|
+
alias?: string[];
|
|
20
22
|
}
|
|
21
23
|
/** The sections of the markdown files in a folder and its folders, file by file in order of path; none when there is no such folder. */
|
|
22
24
|
export declare function readRuleBook(folder: string, source: string): RuleSection[];
|
package/dist/rules/search.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export interface RuleFinding {
|
|
|
12
12
|
* After sections it names, the others are found by the words of its last title alone: "Combat › Grappling" looks for grappling.
|
|
13
13
|
*/
|
|
14
14
|
export declare function findRules(sections: RuleSection[], text: string): RuleFinding[];
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Whether a section is the one a text names: its title, or titles of its path ending with its own, as in "Combat › Grappling"; a translated section by the
|
|
17
|
+
* path it has in its book's own language too (D-542).
|
|
18
|
+
*/
|
|
16
19
|
export declare function isTitled(section: RuleSection, text: string): boolean;
|
|
17
20
|
/** Whether a text holds every word of a search, as search compares words: what finds a precedent. */
|
|
18
21
|
export declare function hasAllWords(text: string, search: string): boolean;
|
package/dist/rules/search.js
CHANGED
|
@@ -22,10 +22,16 @@ export function findRules(sections, text) {
|
|
|
22
22
|
scored.sort((first, second) => second.score - first.score || titleLength(first.entry.section) - titleLength(second.entry.section) || first.entry.index - second.entry.index);
|
|
23
23
|
return [...named, ...scored.map(({ entry, score }) => ({ section: entry.section, titled: false, score }))];
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Whether a section is the one a text names: its title, or titles of its path ending with its own, as in "Combat › Grappling"; a translated section by the
|
|
27
|
+
* path it has in its book's own language too (D-542).
|
|
28
|
+
*/
|
|
26
29
|
export function isTitled(section, text) {
|
|
30
|
+
return pathTitled(section.path, text) || (section.alias !== undefined && pathTitled(section.alias, text));
|
|
31
|
+
}
|
|
32
|
+
function pathTitled(sectionPath, text) {
|
|
27
33
|
const titles = titlesIn(text).map(comparableText);
|
|
28
|
-
const path =
|
|
34
|
+
const path = sectionPath.map(comparableText);
|
|
29
35
|
if (titles.length === 0 || titles.at(-1) !== path.at(-1)) {
|
|
30
36
|
return false;
|
|
31
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpg-engine",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
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": {
|