rpg-engine 0.4.1 → 0.6.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.
- package/README.md +1 -1
- package/dist/campaign/settings.d.ts +1 -0
- package/dist/campaign/settings.js +6 -5
- package/dist/command-line.js +12 -5
- package/dist/commands/advance.js +1 -1
- package/dist/commands/ask.d.ts +37 -2
- package/dist/commands/ask.js +106 -35
- package/dist/commands/change.js +28 -17
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +69 -21
- package/dist/commands/effect.js +42 -23
- package/dist/commands/find.js +1 -1
- package/dist/commands/game-adventures.js +2 -2
- package/dist/commands/game-catalog.d.ts +13 -0
- package/dist/commands/game-catalog.js +26 -2
- package/dist/commands/game-checks.js +23 -21
- package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
- package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
- package/dist/commands/game-effects.d.ts +12 -4
- package/dist/commands/game-effects.js +21 -13
- package/dist/commands/game-examples.d.ts +22 -0
- package/dist/commands/game-examples.js +72 -0
- package/dist/commands/game-extension-list.d.ts +31 -3
- package/dist/commands/game-extension-list.js +94 -6
- package/dist/commands/game-images.d.ts +1 -1
- package/dist/commands/game-images.js +3 -2
- package/dist/commands/game-library.d.ts +3 -0
- package/dist/commands/game-library.js +2 -2
- package/dist/commands/game-mode.js +1 -1
- package/dist/commands/game-package-code.d.ts +87 -0
- package/dist/commands/game-package-code.js +648 -0
- package/dist/commands/game-package-hooks.d.ts +37 -0
- package/dist/commands/game-package-hooks.js +116 -0
- package/dist/commands/game-recipes.js +2 -2
- package/dist/commands/game-reminders.d.ts +5 -2
- package/dist/commands/game-reminders.js +7 -4
- package/dist/commands/game-rules.d.ts +4 -1
- package/dist/commands/game-rules.js +7 -1
- package/dist/commands/game-upkeep.js +3 -3
- package/dist/commands/game-view-place.d.ts +8 -20
- package/dist/commands/game-view-place.js +16 -35
- package/dist/commands/game-widgets.d.ts +42 -8
- package/dist/commands/game-widgets.js +182 -31
- package/dist/commands/game-world.d.ts +32 -3
- package/dist/commands/game-world.js +113 -24
- package/dist/commands/image.js +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package.d.ts +15 -1
- package/dist/commands/package.js +96 -24
- package/dist/commands/progression.d.ts +2 -0
- package/dist/commands/progression.js +7 -2
- package/dist/commands/roll.d.ts +2 -0
- package/dist/commands/roll.js +50 -24
- package/dist/commands/rules.js +6 -4
- package/dist/commands/scene.d.ts +2 -2
- package/dist/commands/scene.js +13 -10
- package/dist/commands/sheet.js +10 -1
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +14 -4
- package/dist/commands/trade.js +6 -4
- package/dist/commands/translate.js +2 -2
- package/dist/commands/travel.js +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/view.d.ts +12 -4
- package/dist/commands/view.js +11 -8
- package/dist/commands/worked-out.js +11 -5
- package/dist/commands/write.d.ts +8 -1
- package/dist/commands/write.js +84 -25
- package/dist/core/command-reference.js +3 -2
- package/dist/core/consents.d.ts +18 -0
- package/dist/core/consents.js +93 -0
- package/dist/core/context.d.ts +68 -27
- package/dist/core/context.js +3 -1
- package/dist/core/examples.d.ts +25 -0
- package/dist/core/examples.js +19 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +10 -1
- package/dist/core/package-api.d.ts +388 -0
- package/dist/core/package-declarations.d.ts +102 -0
- package/dist/core/package-declarations.js +81 -0
- package/dist/core/registry.d.ts +4 -0
- package/dist/core/text.d.ts +5 -0
- package/dist/core/text.js +12 -0
- package/dist/dashboard/acts.js +31 -24
- package/dist/dashboard/address.js +4 -1
- package/dist/dashboard/api.js +65 -3
- package/dist/dashboard/app.js +222 -98
- package/dist/dashboard/ask-card.js +169 -0
- package/dist/dashboard/asked-dice.js +57 -0
- package/dist/dashboard/dice/tray.js +6 -4
- package/dist/dashboard/extension-widgets.js +136 -16
- package/dist/dashboard/faces.js +6 -4
- package/dist/dashboard/help.js +10 -3
- package/dist/dashboard/i18n/ar.json +34 -29
- package/dist/dashboard/i18n/cs.json +34 -29
- package/dist/dashboard/i18n/da.json +34 -29
- package/dist/dashboard/i18n/de.json +34 -29
- package/dist/dashboard/i18n/el.json +34 -29
- package/dist/dashboard/i18n/es.json +34 -29
- package/dist/dashboard/i18n/fi.json +34 -29
- package/dist/dashboard/i18n/fr.json +34 -29
- package/dist/dashboard/i18n/he.json +34 -29
- package/dist/dashboard/i18n/hi.json +34 -29
- package/dist/dashboard/i18n/hu.json +34 -29
- package/dist/dashboard/i18n/is.json +34 -29
- package/dist/dashboard/i18n/it.json +34 -29
- package/dist/dashboard/i18n/ja.json +34 -29
- package/dist/dashboard/i18n/ko.json +34 -29
- package/dist/dashboard/i18n/nb.json +34 -29
- package/dist/dashboard/i18n/nl.json +34 -29
- package/dist/dashboard/i18n/pl.json +34 -29
- package/dist/dashboard/i18n/pt.json +34 -29
- package/dist/dashboard/i18n/ro.json +34 -29
- package/dist/dashboard/i18n/ru.json +34 -29
- package/dist/dashboard/i18n/sv.json +34 -29
- package/dist/dashboard/i18n/tr.json +34 -29
- package/dist/dashboard/i18n/uk.json +34 -29
- package/dist/dashboard/i18n/zh.json +34 -29
- package/dist/dashboard/icons.js +4 -1
- package/dist/dashboard/kit.js +35 -0
- package/dist/dashboard/labels.js +1 -0
- package/dist/dashboard/pack-card.js +97 -0
- package/dist/dashboard/package-page.js +50 -0
- package/dist/dashboard/packages.js +180 -24
- package/dist/dashboard/page-code.js +248 -0
- package/dist/dashboard/party.js +13 -14
- package/dist/dashboard/people.js +4 -0
- package/dist/dashboard/person-panel.js +110 -0
- package/dist/dashboard/place-map-view.js +11 -6
- package/dist/dashboard/rolls.js +2 -2
- package/dist/dashboard/scene.js +12 -9
- package/dist/dashboard/settings.js +55 -9
- package/dist/dashboard/sheet.js +21 -13
- package/dist/dashboard/status.js +69 -15
- package/dist/dashboard/style.css +859 -574
- package/dist/dashboard/top.js +75 -25
- package/dist/dashboard/turns.js +34 -13
- package/dist/dashboard/widgets.js +9 -2
- package/dist/dashboard-server.js +246 -11
- package/dist/dice/roll-dice.js +1 -1
- package/dist/effects/effect.d.ts +7 -4
- package/dist/effects/effect.js +12 -9
- package/dist/extensions/engine.d.ts +4 -0
- package/dist/extensions/engine.js +74 -0
- package/dist/extensions/extension.d.ts +28 -33
- package/dist/extensions/extension.js +37 -46
- package/dist/extensions/index.d.ts +4 -3
- package/dist/extensions/index.js +5 -2
- package/dist/extensions/packages.d.ts +14 -0
- package/dist/extensions/packages.js +148 -12
- package/dist/extensions/words.d.ts +2 -1
- package/dist/extensions/words.js +5 -4
- package/dist/index.d.ts +1 -3
- package/dist/mcp-server.js +52 -15
- package/dist/page-words.d.ts +4 -0
- package/dist/page-words.js +4 -4
- package/dist/page.d.ts +218 -0
- package/dist/page.js +2 -0
- package/dist/pages/index.d.ts +1 -1
- package/dist/pages/index.js +1 -1
- package/dist/pages/load.d.ts +7 -1
- package/dist/pages/load.js +10 -5
- package/dist/pages/page-file.js +1 -1
- package/dist/pages/stack-writes.js +5 -4
- package/dist/pages/standard-fields.d.ts +2 -0
- package/dist/pages/standard-fields.js +8 -1
- package/dist/pages/world.d.ts +8 -0
- package/dist/pages/world.js +9 -2
- package/dist/systems/game-system.d.ts +61 -30
- package/dist/systems/game-system.js +159 -50
- package/dist/systems/index.d.ts +3 -3
- package/dist/systems/index.js +3 -3
- package/dist/systems/system-code.d.ts +29 -88
- package/dist/systems/system-code.js +68 -23
- package/dist/systems/words.d.ts +2 -0
- package/dist/systems/words.js +11 -0
- package/dist/testing.d.ts +76 -0
- package/dist/testing.js +197 -0
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/dashboard.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/play.md +2 -2
- package/instructions/setup.md +1 -1
- package/package.json +15 -2
- package/systems/5e/LICENSE.md +13 -3
- package/systems/5e/dist/dying.js +83 -16
- package/systems/5e/dist/index.js +2 -2
- package/systems/5e/dist/page-style.js +634 -0
- package/systems/5e/dist/page.js +166 -0
- package/systems/5e/dist/shown.js +23 -0
- package/systems/5e/instructions/combat.md +1 -0
- package/systems/5e/package.json +4 -2
- package/systems/5e/system.yaml +35 -7
- package/systems/5e/versions/srd-5.1/system.yaml +2 -0
- package/systems/5e/words/ar.yaml +30 -0
- package/systems/5e/words/cs.yaml +30 -0
- package/systems/5e/words/da.yaml +30 -0
- package/systems/5e/words/de.yaml +30 -0
- package/systems/5e/words/el.yaml +30 -0
- package/systems/5e/words/es.yaml +30 -0
- package/systems/5e/words/fi.yaml +30 -0
- package/systems/5e/words/fr.yaml +30 -0
- package/systems/5e/words/he.yaml +30 -0
- package/systems/5e/words/hi.yaml +30 -0
- package/systems/5e/words/hu.yaml +30 -0
- package/systems/5e/words/is.yaml +30 -0
- package/systems/5e/words/it.yaml +30 -0
- package/systems/5e/words/ja.yaml +30 -0
- package/systems/5e/words/ko.yaml +30 -0
- package/systems/5e/words/nb.yaml +30 -0
- package/systems/5e/words/nl.yaml +30 -0
- package/systems/5e/words/pl.yaml +30 -0
- package/systems/5e/words/pt.yaml +30 -0
- package/systems/5e/words/ro.yaml +30 -0
- package/systems/5e/words/ru.yaml +30 -0
- package/systems/5e/words/sv.yaml +30 -0
- package/systems/5e/words/tr.yaml +30 -0
- package/systems/5e/words/uk.yaml +30 -0
- package/systems/5e/words/zh.yaml +30 -0
- package/dist/commands/game-extensions.d.ts +0 -34
- package/dist/commands/game-extensions.js +0 -182
- package/dist/commands/game-system-code.d.ts +0 -25
- package/dist/commands/game-system-code.js +0 -172
- package/dist/dashboard/death-save.js +0 -67
- package/dist/dashboard/dying.js +0 -46
- package/dist/dashboard/save-outcome.js +0 -42
- package/dist/dashboard/spend.js +0 -115
- package/dist/extensions/api.d.ts +0 -155
- /package/dist/{extensions/api.js → core/package-api.js} +0 -0
package/dist/commands/package.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { changeExtensions, readTextSetting, requireCampaign } from "../campaign/index.js";
|
|
4
|
+
import { engineSystemsFolder } from "../core/context.js";
|
|
4
5
|
import { installedFromFolder } from "../core/files.js";
|
|
5
6
|
import { appendLogEntry } from "../core/log.js";
|
|
7
|
+
import { apiProblem, ourSystems, readsApi } from "../core/package-declarations.js";
|
|
6
8
|
import { defineCommand } from "../core/registry.js";
|
|
7
|
-
import { files } from "../core/store.js";
|
|
9
|
+
import { files, isInside } from "../core/store.js";
|
|
8
10
|
import { comparableText } from "../core/text.js";
|
|
9
11
|
import { isNewerVersion } from "../core/version.js";
|
|
10
|
-
import {
|
|
12
|
+
import { dropConsent, findExtension, installedExtensions, isLocalSpec, issuesPage, isTarball, isVerified, readExtension, recordConsent, shortName, verifiedScope } from "../extensions/index.js";
|
|
11
13
|
import { installedLanguages, languagePackProblems, readLanguagePack } from "../languages/index.js";
|
|
12
14
|
import { installedSystems, systemFolders, systemHasCode } from "../systems/index.js";
|
|
13
15
|
import { exportAdventure, installAdventure, installedAdventures, isAdventureSpec, readAdventureSpec, removeAdventure, storyTouching } from "./game-adventures.js";
|
|
14
16
|
import { listedExtensions, runsCode } from "./game-extension-list.js";
|
|
15
|
-
import { extensionCommandNames, packagesInstalled } from "./game-extensions.js";
|
|
16
17
|
import { campaignMode } from "./game-mode.js";
|
|
18
|
+
import { loadCampaignCode, packageCommandNames, packagesInstalled } from "./game-package-code.js";
|
|
17
19
|
import { newDatedLogEntry } from "./game-time.js";
|
|
18
20
|
import { campaignWorld } from "./game-world.js";
|
|
19
21
|
/** The player's yes to a package not ours, not given (D-478): they said no or closed the question, or no window could be shown here. */
|
|
@@ -89,8 +91,13 @@ export const packageCommand = defineCommand({
|
|
|
89
91
|
const { system } = result;
|
|
90
92
|
return [
|
|
91
93
|
`Installed the game system ${system.name}${system.version === undefined ? "" : ` ${system.version}`}, ${system.title}${system.verified ? "" : ", not verified: at the player's risk"}.`,
|
|
92
|
-
|
|
93
|
-
system.
|
|
94
|
+
// In a setup with no system yet, the one just installed is chosen next (D-513 (1)).
|
|
95
|
+
system.used
|
|
96
|
+
? "The campaign plays it."
|
|
97
|
+
: result.plays === undefined
|
|
98
|
+
? `The campaign has no system yet: if the player chose this one, set it with config, setting system, value ${system.name}.`
|
|
99
|
+
: `It is for a new campaign, chosen in its setup: this one plays ${result.plays}.`,
|
|
100
|
+
!system.code ? "" : result.plays === undefined ? "Its code runs once config sets it." : "Its code runs from the next start of the game's server.",
|
|
94
101
|
].filter((line) => line !== "").join(" ");
|
|
95
102
|
}
|
|
96
103
|
if (result.kind === "removed") {
|
|
@@ -106,7 +113,7 @@ export const packageCommand = defineCommand({
|
|
|
106
113
|
const what = `${extension.name} ${extension.version}${result.verified ? ", verified" : ", not verified: at the player's risk"}`;
|
|
107
114
|
const said = [
|
|
108
115
|
`${result.already ? `The campaign already uses ${what}` : `Installed ${what}, and the campaign uses it`}: ${extension.about}.`,
|
|
109
|
-
result.codeLeftOut ? "Its code is not used:
|
|
116
|
+
result.codeLeftOut ? "Its code is not used: the player's yes holds for another version or other files; install it again for their yes." : "",
|
|
110
117
|
result.commands.length === 0 ? "" : `Its commands: ${result.commands.join(", ")}.${result.tools === "" ? "" : ` ${result.tools}`}`,
|
|
111
118
|
Object.keys(extension.parts).length === 0 ? "" : `Its parts of your instructions are given when they apply: ${Object.keys(extension.parts).join(", ")}.`,
|
|
112
119
|
].filter((line) => line !== "").join(" ");
|
|
@@ -119,7 +126,8 @@ export const packageCommand = defineCommand({
|
|
|
119
126
|
const lines = result.packages.map((one) => {
|
|
120
127
|
const here = one.installed === undefined ? "" : one.update ? `, installed ${one.installed}: an update` : ", installed";
|
|
121
128
|
const by = one.author === undefined ? "" : ` by ${one.author}`;
|
|
122
|
-
|
|
129
|
+
const newer = one.newer === undefined ? "" : ` (its ${one.newer.version} needs ${one.newer.engine === undefined ? "a newer rpg-engine" : `rpg-engine ${one.newer.engine}`})`;
|
|
130
|
+
return `${one.name} ${one.version}${one.verified ? "" : " (not verified)"}${by}${here}${newer}${one.description === undefined ? "" : `: ${one.description.replace(/\.$/, "")}`}`;
|
|
123
131
|
});
|
|
124
132
|
return `On npm: ${lines.length === 0 ? "none" : lines.join("; ")}.`;
|
|
125
133
|
}
|
|
@@ -136,6 +144,7 @@ export const packageCommand = defineCommand({
|
|
|
136
144
|
function listed(root, context) {
|
|
137
145
|
const used = Object.keys(listedExtensions(root));
|
|
138
146
|
const here = installedExtensions(context.extensionFolders ?? []).map((found) => {
|
|
147
|
+
const issues = issuesOf(found.folder);
|
|
139
148
|
try {
|
|
140
149
|
const extension = readExtension(found.folder);
|
|
141
150
|
return {
|
|
@@ -146,10 +155,11 @@ function listed(root, context) {
|
|
|
146
155
|
about: extension.about,
|
|
147
156
|
verified: isVerified(extension.package, extension.linked),
|
|
148
157
|
used: used.includes(extension.package),
|
|
158
|
+
...issues,
|
|
149
159
|
};
|
|
150
160
|
}
|
|
151
161
|
catch (error) {
|
|
152
|
-
return { name: shortName(found.package), package: found.package, broken: error instanceof Error ? error.message : String(error) };
|
|
162
|
+
return { name: shortName(found.package), package: found.package, broken: error instanceof Error ? error.message : String(error), ...issues };
|
|
153
163
|
}
|
|
154
164
|
});
|
|
155
165
|
const adventures = installedAdventures(root).map((one) => ({ title: one.title, version: one.version, ...(one.since === undefined ? {} : { since: one.since }), removable: storyTouching(root, one) === undefined }));
|
|
@@ -162,7 +172,7 @@ async function available(context) {
|
|
|
162
172
|
return { kind: "available", packages: [], failed: searched.failed };
|
|
163
173
|
}
|
|
164
174
|
const here = installedExtensions(context.extensionFolders ?? []);
|
|
165
|
-
const packages = searched.filter((one) => one.kind === "extension" && readsApi(one.api)).map((one) => {
|
|
175
|
+
const packages = searched.filter((one) => one.kind === "extension" && readsApi(one.api, "extension")).map((one) => {
|
|
166
176
|
const installed = here.find((found) => found.package === one.name);
|
|
167
177
|
const copy = installed === undefined ? undefined : usable(context, one.name);
|
|
168
178
|
const version = copy?.version;
|
|
@@ -176,19 +186,29 @@ async function available(context) {
|
|
|
176
186
|
verified: isVerified(one.name, copy?.linked ?? false),
|
|
177
187
|
...(installed === undefined ? {} : { installed: version ?? "broken" }),
|
|
178
188
|
update: version !== undefined && isNewerVersion(one.version, version),
|
|
189
|
+
...(one.newer === undefined ? {} : { newer: one.newer }),
|
|
179
190
|
};
|
|
180
191
|
});
|
|
181
192
|
return { kind: "available", packages: packages.sort((first, second) => Number(second.verified) - Number(first.verified) || first.name.localeCompare(second.name)) };
|
|
182
193
|
}
|
|
194
|
+
/** The npm names of ours a name alone may be, with its version if given: an extension's, then a game system's; a system of the engine's list first (D-513). */
|
|
195
|
+
function ourNames(name) {
|
|
196
|
+
const names = [`${verifiedScope}${name}`, `${verifiedScope}system-${name}`];
|
|
197
|
+
const bare = name.replace(/(?<=.)@[^@/]*$/, "");
|
|
198
|
+
return ourSystems.some((system) => comparableText(system.name) === comparableText(bare)) ? [names[1], names[0]] : names;
|
|
199
|
+
}
|
|
183
200
|
/** Installs a package on this computer and adds it to the campaign (D-27, D-428, D-441): ours, or another once the player wants it; an extension, for this game. */
|
|
184
201
|
async function installed(root, context, name) {
|
|
185
202
|
const packages = context.packages;
|
|
186
203
|
if (packages === undefined) {
|
|
187
204
|
throw new Error("Packages are installed only by the game's server or the command line, which reach npm.");
|
|
188
205
|
}
|
|
189
|
-
// A name alone is one of ours: weather is @rpgengine/weather, never a stranger's of that name, which is given as npm:weather
|
|
190
|
-
|
|
191
|
-
const
|
|
206
|
+
// A name alone is one of ours: weather is @rpgengine/weather, never a stranger's of that name, which is given as npm:weather; or our game system's, as 5e
|
|
207
|
+
// is @rpgengine/system-5e (D-513).
|
|
208
|
+
const [first, second] = name.startsWith("npm:") ? [name.slice(4)] : isLocalSpec(name) || name.startsWith("@") ? [name] : ourNames(name);
|
|
209
|
+
const tried = await packages.describe(first);
|
|
210
|
+
const other = second !== undefined && "failed" in tried && tried.missing === true ? await packages.describe(second) : undefined;
|
|
211
|
+
const [asked, described] = second !== undefined && other !== undefined && !("failed" in other && other.missing === true) ? [second, other] : [first, tried];
|
|
192
212
|
if ("failed" in described) {
|
|
193
213
|
throw new Error(`${described.failed}. Nothing changed${asked === name ? "" : `: ${name} alone means ${asked}, one of RPG Engine's; another's is named with its scope, or as npm:${name} without one`}.`);
|
|
194
214
|
}
|
|
@@ -202,11 +222,12 @@ async function installed(root, context, name) {
|
|
|
202
222
|
}
|
|
203
223
|
if (described.kind !== "extension") {
|
|
204
224
|
throw new Error(described.kind === undefined
|
|
205
|
-
? `${described.name} is not a package for RPG Engine: its package.json does not say "rpg-engine": {"kind": "extension"}. Nothing changed.`
|
|
225
|
+
? `${described.name} is not a package for RPG Engine: its package.json does not say "rpg-engine": {"kind": "extension"}, or {"kind": "system"} for a game system. Nothing changed.`
|
|
206
226
|
: `${described.name} is a package of kind ${described.kind}: for now extensions, game systems and adventures are installed this way. Nothing changed.`);
|
|
207
227
|
}
|
|
208
|
-
|
|
209
|
-
|
|
228
|
+
const unread = apiProblem(described.api, "extension");
|
|
229
|
+
if (unread !== undefined) {
|
|
230
|
+
throw new Error(`${described.name} ${described.version} cannot be used, because ${unread}. Nothing changed.`);
|
|
210
231
|
}
|
|
211
232
|
const local = isLocalSpec(spec);
|
|
212
233
|
const before = usable(context, described.name);
|
|
@@ -214,10 +235,11 @@ async function installed(root, context, name) {
|
|
|
214
235
|
// A file or a folder says what it holds, and when it takes the place of a copy from npm, which is one for the whole computer (D-452).
|
|
215
236
|
const holds = local ? ` (${described.name} ${described.version}${described.author === undefined ? "" : `, by ${described.author}`})` : "";
|
|
216
237
|
const replaces = local && before !== undefined && !before.linked ? ` It takes the place of ${before.package} ${before.version} from npm, in every campaign on this computer.` : "";
|
|
217
|
-
await playerYes(context, local ? name : described.name, local, holds, replaces);
|
|
238
|
+
await playerYes(context, local ? name : `${described.name} ${described.version}`, described.name, local, holds, replaces);
|
|
218
239
|
}
|
|
219
240
|
// A copy from a file or a folder never stands for the one npm has: asked by its name, npm's comes back.
|
|
220
|
-
|
|
241
|
+
// Another's whose code may not run is installed again before its yes is kept: the yes goes to npm's files, never to files changed since (D-478, D-510).
|
|
242
|
+
const reinstall = before === undefined || before.version !== described.version || local || before.linked || (!isVerified(described.name, local) && !runsCode(before));
|
|
221
243
|
if (reinstall) {
|
|
222
244
|
const why = await packages.install(spec);
|
|
223
245
|
if (why !== undefined) {
|
|
@@ -231,17 +253,25 @@ async function installed(root, context, name) {
|
|
|
231
253
|
if (extension === undefined) {
|
|
232
254
|
throw new Error(`${described.name} was installed, but RPG Engine cannot use it as an extension. Nothing changed in the campaign.`);
|
|
233
255
|
}
|
|
256
|
+
// The player's yes holds for this version and these files, on this computer: its code runs on the server and in the page (D-478, D-510).
|
|
257
|
+
if (!isVerified(described.name, local) && !extension.linked) {
|
|
258
|
+
recordConsent(extension.folder, extension.package, extension.version);
|
|
259
|
+
}
|
|
234
260
|
const system = readTextSetting(root, "system");
|
|
235
261
|
if (extension.needs.system !== undefined && comparableText(extension.needs.system) !== comparableText(system ?? "")) {
|
|
236
262
|
throw new Error(`${extension.name} is installed on this computer, but it is for the game system ${extension.needs.system}, and the campaign plays ${system ?? "none"}: the campaign does not use it.`);
|
|
237
263
|
}
|
|
264
|
+
// Its state, widgets and pictures go by its name, which the system's would share (D-514).
|
|
265
|
+
if (comparableText(extension.name) === comparableText(system ?? "")) {
|
|
266
|
+
throw new Error(`${extension.name} is installed on this computer, but it has the name of the game system the campaign plays: the campaign does not use it. Nothing changed in the campaign.`);
|
|
267
|
+
}
|
|
238
268
|
const others = Object.keys(listedExtensions(root)).filter((other) => other !== extension.package && shortName(other) === extension.name);
|
|
239
269
|
if (others.length > 0) {
|
|
240
270
|
throw new Error(`The campaign uses ${others[0]}, with the same name, ${extension.name}: take it away with package remove ${others[0]} first. Nothing changed in the campaign.`);
|
|
241
271
|
}
|
|
242
272
|
// Its code is checked before the campaign lists it: a package that would not work is never added.
|
|
243
273
|
const commands = runsCode(extension)
|
|
244
|
-
? await
|
|
274
|
+
? await packageCommandNames(extension, context, []).catch((error) => {
|
|
245
275
|
throw new Error(`The code of ${extension.package} cannot be used: ${error instanceof Error ? error.message : String(error)}. Nothing changed in the campaign.`);
|
|
246
276
|
})
|
|
247
277
|
: [];
|
|
@@ -252,12 +282,14 @@ async function installed(root, context, name) {
|
|
|
252
282
|
changeExtensions(root, { ...listedBefore, [extension.package]: extension.version });
|
|
253
283
|
appendLogEntry(root, newDatedLogEntry(root, context, "package-installed", "public", { package: extension.package, version: extension.version, verified }));
|
|
254
284
|
}
|
|
285
|
+
// The campaign's code anew, the new one's included: their hooks are called at the next change, never skipped (D-514).
|
|
286
|
+
await loadCampaignCode(context);
|
|
255
287
|
return {
|
|
256
288
|
kind: "installed",
|
|
257
289
|
extension,
|
|
258
290
|
verified,
|
|
259
291
|
commands,
|
|
260
|
-
codeLeftOut: extension.code !== undefined && !runsCode(extension),
|
|
292
|
+
codeLeftOut: (extension.code !== undefined || extension.page !== undefined) && !runsCode(extension),
|
|
261
293
|
already,
|
|
262
294
|
...modePart(root, context, extension),
|
|
263
295
|
tools: toolsNote(context),
|
|
@@ -270,18 +302,27 @@ async function installed(root, context, name) {
|
|
|
270
302
|
async function systemInstalled(root, context, spec, name, described) {
|
|
271
303
|
const local = isLocalSpec(spec);
|
|
272
304
|
const named = shortName(described.name).replace(/^system-/, "");
|
|
305
|
+
const unread = apiProblem(described.api, "system");
|
|
306
|
+
if (unread !== undefined) {
|
|
307
|
+
throw new Error(`${described.name} ${described.version} cannot be used, because ${unread}. Nothing changed.`);
|
|
308
|
+
}
|
|
273
309
|
const taken = systemsHere(root, context).find((one) => comparableText(one.name) === comparableText(named) && one.package !== described.name);
|
|
274
310
|
if (taken !== undefined) {
|
|
275
311
|
throw new Error(`There is already a game system named ${taken.name} on this computer${taken.package === undefined ? ", the engine's own" : `, from ${taken.package}`}: ${described.name} would take its name. Nothing changed.`);
|
|
276
312
|
}
|
|
277
313
|
if (!isVerified(described.name, local)) {
|
|
278
|
-
await playerYes(context, local ? name : described.name, local, local ? ` (${described.name} ${described.version})` : "");
|
|
314
|
+
await playerYes(context, local ? name : `${described.name} ${described.version}`, described.name, local, local ? ` (${described.name} ${described.version})` : "");
|
|
279
315
|
}
|
|
280
316
|
const why = await context.packages.install(spec);
|
|
281
317
|
if (why !== undefined) {
|
|
282
318
|
throw new Error(`${described.name} could not be installed: ${why}. Nothing changed.`);
|
|
283
319
|
}
|
|
284
320
|
[...context.systemFolders, ...(context.extensionFolders ?? [])].forEach((folder) => files().refresh(folder));
|
|
321
|
+
const installed = installedExtensionFolder(context, described.name);
|
|
322
|
+
// The player's yes holds for this version and these files: its code runs at the next start of the game's server (D-478, D-511).
|
|
323
|
+
if (!isVerified(described.name, local) && !local && installed !== undefined) {
|
|
324
|
+
recordConsent(installed, described.name, described.version);
|
|
325
|
+
}
|
|
285
326
|
let system;
|
|
286
327
|
try {
|
|
287
328
|
system = systemsHere(root, context).find((one) => one.package === described.name);
|
|
@@ -303,7 +344,7 @@ function systemsHere(root, context) {
|
|
|
303
344
|
return installedSystems(context.systemFolders).map((system) => {
|
|
304
345
|
const manifest = packageOf(folders.find((one) => one.name === system.name)?.folder ?? system.folder);
|
|
305
346
|
// The engine's own have no package of their own here; one npm installed is ours only by our scope, and never from a folder (D-441).
|
|
306
|
-
const shipped = system.folder
|
|
347
|
+
const shipped = isInside(engineSystemsFolder, system.folder);
|
|
307
348
|
const linked = installedFromFolder(system.folder);
|
|
308
349
|
return {
|
|
309
350
|
name: system.name,
|
|
@@ -313,9 +354,21 @@ function systemsHere(root, context) {
|
|
|
313
354
|
verified: shipped || (manifest !== undefined && isVerified(manifest.name, linked)),
|
|
314
355
|
used: comparableText(system.name) === comparableText(plays),
|
|
315
356
|
code: systemHasCode(system.folder),
|
|
357
|
+
// The engine's own are reported where the engine is: its package.json is in the folder above its systems.
|
|
358
|
+
...issuesOf(shipped ? join(engineSystemsFolder, "..") : system.folder),
|
|
316
359
|
};
|
|
317
360
|
});
|
|
318
361
|
}
|
|
362
|
+
/** Where the package in this folder takes reports of its problems, as its package.json says; nothing when it says none or has none that reads. */
|
|
363
|
+
function issuesOf(folder) {
|
|
364
|
+
try {
|
|
365
|
+
const issues = issuesPage(JSON.parse(files().text(join(folder, "package.json")) ?? ""));
|
|
366
|
+
return issues === undefined ? {} : { issues };
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return {};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
319
372
|
/** The name and the version a package.json in this folder gives; undefined when it has none that reads. */
|
|
320
373
|
function packageOf(folder) {
|
|
321
374
|
try {
|
|
@@ -378,8 +431,14 @@ function languagesHere(context) {
|
|
|
378
431
|
package: pack.package,
|
|
379
432
|
version: pack.version,
|
|
380
433
|
verified: isVerified(pack.package, installedFromFolder(pack.folder)),
|
|
434
|
+
...issuesOf(pack.folder),
|
|
381
435
|
}));
|
|
382
436
|
}
|
|
437
|
+
/** Whether a package is on this computer, by its name as package takes it: an extension, a game system or a language npm installed (D-510). */
|
|
438
|
+
export function isInstalledPackage(context, name) {
|
|
439
|
+
const asked = name.startsWith("npm:") ? name.slice(4) : name.startsWith("@") ? name : `${verifiedScope}${name}`;
|
|
440
|
+
return [asked, name].some((one) => installedExtensionFolder(context, one) !== undefined);
|
|
441
|
+
}
|
|
383
442
|
/** The folder npm installed a package in, among the extensions' folders; undefined when it is not there. */
|
|
384
443
|
function installedExtensionFolder(context, name) {
|
|
385
444
|
return (context.extensionFolders ?? []).map((folder) => join(folder, ...name.split("/"))).find((folder) => files().exists(join(folder, "package.json")));
|
|
@@ -397,10 +456,17 @@ function pagePhrases(context) {
|
|
|
397
456
|
* The player's own yes to a package not ours (D-441, D-478), where the master cannot give it with its own tools: the host's form first, never the dashboard's
|
|
398
457
|
* page, whose click a local program can forge; else a window of their operating system; else none, and it throws.
|
|
399
458
|
*/
|
|
400
|
-
async function playerYes(context, name, local, holds = "", replaces = "") {
|
|
459
|
+
async function playerYes(context, name, pack, local, holds = "", replaces = "") {
|
|
460
|
+
// A no in a window holds for the package npm describes, however it was written, until the server starts again (D-510).
|
|
461
|
+
if (context.declined?.has(pack) === true) {
|
|
462
|
+
throw new YesRefused(`The player said no to ${pack} in this session: it is not asked again until the game's server starts again. Nothing changed.`, "declined");
|
|
463
|
+
}
|
|
464
|
+
// Said in plain words, the fixed text before the name its author chose; and where the request comes from (D-510).
|
|
465
|
+
const from = context.actor === "player" ? "the dashboard" : context.host === undefined ? "the command line" : "the chat";
|
|
466
|
+
const can = "Its code runs on this computer with your permissions, and in the dashboard, where it can see the whole campaign, its secrets included, and press buttons and speak to the master for you.";
|
|
401
467
|
const warning = local
|
|
402
|
-
?
|
|
403
|
-
:
|
|
468
|
+
? `Not verified by RPG Engine: ${name}${holds}, ${isTarball(name) ? "a file" : "a folder"} of this computer, asked from ${from}. ${can} RPG Engine takes no responsibility for it.${replaces}`
|
|
469
|
+
: `Not verified by RPG Engine: ${name}, asked from ${from}. ${can} Install it only if you trust who made it.`;
|
|
404
470
|
const question = `Install ${name}? ${warning}`;
|
|
405
471
|
const title = "A package not ours";
|
|
406
472
|
const answer = context.player === undefined ? "unavailable" : await context.player.choose(question, title, ["Install it, at my risk", "Do not install it"], context.signal);
|
|
@@ -419,6 +485,7 @@ async function playerYes(context, name, local, holds = "", replaces = "") {
|
|
|
419
485
|
return;
|
|
420
486
|
}
|
|
421
487
|
if (window === "no") {
|
|
488
|
+
context.declined?.add(pack);
|
|
422
489
|
throw new YesRefused(`The player did not want ${name}. Nothing changed.`, "declined");
|
|
423
490
|
}
|
|
424
491
|
throw new YesRefused(`${warning} Only the player can say yes to it, in the host's form or in a window of their computer, and neither can be shown here (no desktop, as over SSH; `
|
|
@@ -484,10 +551,15 @@ async function uninstalled(root, context, name) {
|
|
|
484
551
|
if (packages === undefined) {
|
|
485
552
|
throw new Error("Packages are uninstalled only by the game's server or the command line, which reach npm.");
|
|
486
553
|
}
|
|
554
|
+
const folder = installedExtensionFolder(context, found.package);
|
|
487
555
|
const why = await packages.uninstall(found.package);
|
|
488
556
|
if (why !== undefined) {
|
|
489
557
|
throw new Error(`${found.package} could not be uninstalled: ${why}. Nothing changed.`);
|
|
490
558
|
}
|
|
559
|
+
// Off this computer, its yes goes with it: installed again, it is asked again.
|
|
560
|
+
if (folder !== undefined) {
|
|
561
|
+
dropConsent(folder, found.package);
|
|
562
|
+
}
|
|
491
563
|
[...context.systemFolders, ...(context.extensionFolders ?? [])].forEach((folder) => files().refresh(folder));
|
|
492
564
|
const listed = listedExtensions(root);
|
|
493
565
|
const wasUsed = Object.hasOwn(listed, found.package);
|
|
@@ -25,6 +25,8 @@ export interface Progression {
|
|
|
25
25
|
name: string;
|
|
26
26
|
pages: Page[];
|
|
27
27
|
}[];
|
|
28
|
+
/** The features written on the character by hand, as what a feat or the story gives, that no row or part gives: counted with them (PRO-3). */
|
|
29
|
+
written: string[];
|
|
28
30
|
/** Each feature as a row or a part gives it, before they are merged, with its level and page: what a new level adds, even a feature gained again. */
|
|
29
31
|
gains: {
|
|
30
32
|
name: string;
|
|
@@ -41,11 +41,15 @@ export function progressionOf(world, fields) {
|
|
|
41
41
|
}
|
|
42
42
|
// Item by item, then level by level; at the same level, a class's own features before its subclass's.
|
|
43
43
|
features.sort((first, second) => first.order - second.order || first.level - second.level || first.part - second.part);
|
|
44
|
+
const merged = mergedFeatures(features);
|
|
45
|
+
const gainedNames = new Set(merged.map(({ name }) => comparableText(featureParts(name).name)));
|
|
46
|
+
const handWritten = listItems(valueNamed(fields, featuresField)).map((item) => item.name).filter((name) => !gainedNames.has(comparableText(featureParts(name).name)));
|
|
44
47
|
return {
|
|
45
48
|
lists: rule.parts === undefined ? [rule.list] : [rule.list, rule.parts.list],
|
|
46
49
|
values: [...values.values()],
|
|
47
50
|
featuresField,
|
|
48
|
-
features:
|
|
51
|
+
features: merged.map(({ name }) => ({ name, pages: pagesGiving(features, name) })),
|
|
52
|
+
written: [...new Set(handWritten)],
|
|
49
53
|
gains: features.map(({ name, level, page }) => ({ name, level, page })),
|
|
50
54
|
given,
|
|
51
55
|
from: [...entries.map((entry) => ({ list: rule.list, name: entry.page.name, level: entry.level })), ...parts.map((part) => ({ list: rule.parts?.list ?? "", name: part.page.name }))],
|
|
@@ -60,8 +64,9 @@ export function progressionValue(progression, field) {
|
|
|
60
64
|
if (progression === undefined) {
|
|
61
65
|
return undefined;
|
|
62
66
|
}
|
|
67
|
+
// Those of the rows and the parts, then those written by hand (PRO-3).
|
|
63
68
|
if (comparableText(field) === comparableText(progression.featuresField)) {
|
|
64
|
-
return progression.features.map((feature) => feature.name);
|
|
69
|
+
return [...progression.features.map((feature) => feature.name), ...progression.written];
|
|
65
70
|
}
|
|
66
71
|
return progression.values.find((value) => comparableText(value.field) === comparableText(field))?.value;
|
|
67
72
|
}
|
package/dist/commands/roll.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export declare const roll: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
40
40
|
sha256: string;
|
|
41
41
|
fingerprint: string;
|
|
42
42
|
}>;
|
|
43
|
+
/** The dice a game system rolls a number of its sheet with, for an example: that field's, else its first; 2d6 without them (D-280, D-514). */
|
|
44
|
+
export declare function sheetDiceOf(system: GameSystem | undefined, field?: string): string;
|
|
43
45
|
/**
|
|
44
46
|
* The page of who rolls, a character or a copy in the open scene, with its world; undefined when who names neither, as a free label does. Without names to
|
|
45
47
|
* read, a name two pages share is a label too: the roll needs no sheet.
|
package/dist/commands/roll.js
CHANGED
|
@@ -8,12 +8,13 @@ import { readCounter } from "../counters/index.js";
|
|
|
8
8
|
import { askOracle, DiceError, rollDice, sha256 } from "../dice/index.js";
|
|
9
9
|
import { declaredKind, findPage, pagesWithName, writePage } from "../pages/index.js";
|
|
10
10
|
import { effectiveFields, effectsOf } from "./effect-layer.js";
|
|
11
|
+
import { systemNamed } from "./game-effects.js";
|
|
11
12
|
import { behindTheScreen, namesNoOne, ofTheParty, screenNote, screenUp, sealHiddenRoll } from "./game-master-rolls.js";
|
|
13
|
+
import { packagesRolled } from "./game-package-hooks.js";
|
|
12
14
|
import { copyPage, readOpenScene } from "./game-scene.js";
|
|
13
|
-
import { systemRolled } from "./game-system-code.js";
|
|
14
15
|
import { rollPageTable } from "./game-tables.js";
|
|
15
16
|
import { newDatedLogEntry } from "./game-time.js";
|
|
16
|
-
import { campaignSystem, campaignWorld, missingSystemHint } from "./game-world.js";
|
|
17
|
+
import { campaignSystem, campaignSystemWords, campaignWorld, missingSystemHint } from "./game-world.js";
|
|
17
18
|
import { itemList, signedText, workedFields } from "./worked-out.js";
|
|
18
19
|
// Faces arrive as "14,7" or "14 7" from a shell (PowerShell turns 14,7 into "14 7"), or as an array.
|
|
19
20
|
export const faceValues = z.preprocess((value) => (typeof value === "string" ? value.split(/[\s,;]+/).filter(Boolean).map(Number) : value), z.array(z.number()));
|
|
@@ -27,23 +28,23 @@ export const roll = defineCommand({
|
|
|
27
28
|
+ "Give why and, if it belongs to someone, who; for a roll the player sees, check names it for them, while why stays yours. "
|
|
28
29
|
+ "When the player rolls physical dice, pass their faces as values. Make it hidden when the player must not see the result; "
|
|
29
30
|
+ "left out, a roll for a foe or anyone outside the party is hidden or shown as the master-rolls setting says. "
|
|
30
|
-
+ "keep stores the dice rolled for later,
|
|
31
|
+
+ "keep stores the dice rolled for later, as a power of foresight does, rolled by the player for the player character, by you for a companion; "
|
|
31
32
|
+ "use takes one of those instead of the die and logs which roll it replaced. "
|
|
32
33
|
+ "Instead of a notation, table rolls on a random table of a page and gives its row, for you to tell; oracle answers a yes/no question with its odds. "
|
|
33
|
-
+ 'Example: notation
|
|
34
|
+
+ 'Example: notation {{roll}}, why "notice the trap", who Lena; table "Colli di Vallerana#Incontri", why "a night on the hills"; oracle likely, why "is the ferryman awake?".',
|
|
34
35
|
group: "game",
|
|
35
36
|
positionals: ["notation"],
|
|
36
37
|
input: z.object({
|
|
37
38
|
notation: z.string().optional().describe("dice to roll: 1d20+5, 2d20kh1 (keep the highest), 4d6dl1 (drop the lowest), 2d6ro<=2 (reroll once), 1d6! (exploding), 6d10>=8 (count successes), 4dF, d%; "
|
|
38
|
-
+ "with who, a field of their sheet stands for its value, such as
|
|
39
|
+
+ "with who, a field of their sheet stands for its value, such as {{roll}}"),
|
|
39
40
|
why: z.string().optional().describe("what the roll is for"),
|
|
40
41
|
check: z.string().optional().describe("what the roll is, as the player sees it in the dashboard's rolls, such as Bite or Stealth: never what only you know"),
|
|
41
42
|
who: z.string().optional().describe("character the roll belongs to, or a copy in the open scene, the damage and heals they deal too, never who takes them; leave it out only for a roll that is no one's, such as an oracle"),
|
|
42
43
|
values: faceValues.optional().describe("faces rolled by the player with physical dice, separated by commas; on the command line write --values=-1,0,1 for negative faces"),
|
|
43
44
|
hidden: z.boolean().optional().describe("only the master sees the result; its fingerprint goes to the player only if they ask for it; left out, the master-rolls setting decides for who outside the party"),
|
|
44
45
|
reveal: z.string().optional().describe("id of a hidden roll whose proof to show, later"),
|
|
45
|
-
keep: z.string().optional().describe("a field of who that keeps rolls for later, such as
|
|
46
|
-
use: z.string().optional().describe("a kept roll to use instead of the die, as field=value, such as
|
|
46
|
+
keep: z.string().optional().describe("a field of who that keeps rolls for later, such as omens: the dice rolled go there, in place of what it held"),
|
|
47
|
+
use: z.string().optional().describe("a kept roll to use instead of the die, as field=value, such as omens=3: the notation has one die"),
|
|
47
48
|
from: z.string().optional().describe("who keeps the roll that use takes, when it is not who rolls"),
|
|
48
49
|
double: z.boolean().optional().describe("roll twice the dice, never the numbers added, as a critical hit's damage: 1d8+3 rolls 2d8+3"),
|
|
49
50
|
table: z.string().optional().describe("a random table to roll on, as Page#Section: the first table under that heading, its die in the first header cell (d8, 2d6, d100, d66) or as big as its highest row"),
|
|
@@ -61,7 +62,7 @@ export const roll = defineCommand({
|
|
|
61
62
|
throw new Error("Give one of the dice to roll, table or oracle, not more: each is a roll of its own. Nothing rolled.");
|
|
62
63
|
}
|
|
63
64
|
if (input.notation === undefined && input.table === undefined && input.oracle === undefined) {
|
|
64
|
-
throw new Error(
|
|
65
|
+
throw new Error(`Give the dice to roll, for example ${sheetDiceOf(campaignSystem(root, context))}+2; or table, for a random table, or oracle, for a yes/no question.`);
|
|
65
66
|
}
|
|
66
67
|
if (input.values && input.hidden) {
|
|
67
68
|
throw new Error("Physical dice are rolled by the player, so they cannot be hidden.");
|
|
@@ -99,9 +100,12 @@ export const roll = defineCommand({
|
|
|
99
100
|
appendLogEntry(root, entry);
|
|
100
101
|
// A roll of a dying party member is their death save, which the engine writes (DIE-4, D-460).
|
|
101
102
|
// A hidden roll writes nothing the player would see (review of 17 October).
|
|
102
|
-
const said = input.who === undefined || hidden
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
const said = input.who === undefined || hidden
|
|
104
|
+
? { lines: [], added: [] }
|
|
105
|
+
: packagesRolled(root, context, { who: input.who, notation: diceRoll.notation, total: diceRoll.total, faces: diceRoll.faces, dice: diceRoll.dice, text, id: entry.id });
|
|
106
|
+
const own = said.lines.length > 0 ? said.lines.join("\n") : roller === undefined ? undefined : rollerNote(roller.world, system, roller.page, campaignSystemWords(root, context));
|
|
107
|
+
// The system's lines take the place of the engine's note, as a death save does; the extensions' come after it (D-514).
|
|
108
|
+
const note = [own, ...said.added, said.problem].filter((line) => line !== undefined && line !== "").join("\n") || undefined;
|
|
105
109
|
const shown = { kind: "roll", id: entry.id, text, total: diceRoll.total, why: input.why, who: input.who, check: input.check, physical, hidden, fingerprint: shownFingerprint, note, kept };
|
|
106
110
|
// A who of no page may be a party member named wrongly: the master is told how to undo the screen (review of 25 October).
|
|
107
111
|
const stranger = screened && input.who !== undefined && namesNoOne(root, context, input.who) ? { stranger: true } : {};
|
|
@@ -178,7 +182,7 @@ function keptField(root, context, who, field) {
|
|
|
178
182
|
function keptRoll(root, context, holder, use) {
|
|
179
183
|
const match = /^\s*([^=]+?)\s*=\s*([+-]?\d+)\s*$/.exec(use);
|
|
180
184
|
if (match === null) {
|
|
181
|
-
throw new Error(`Give use as the field and the kept number, such as
|
|
185
|
+
throw new Error(`Give use as the field and the kept number, such as ${keptExample(campaignWorld(root, context))}=3, not "${use}". Nothing rolled.`);
|
|
182
186
|
}
|
|
183
187
|
if (holder === undefined) {
|
|
184
188
|
throw new Error(`Give who keeps the roll, with from or who, such as from Elara. Nothing rolled.`);
|
|
@@ -219,7 +223,25 @@ function notRollsText(world, field, value) {
|
|
|
219
223
|
const kind = declaredKind(world, field) ?? (readCounter(value) === undefined ? undefined : "counter");
|
|
220
224
|
return kind === undefined
|
|
221
225
|
? `${field} keeps no rolls: declare it so first, such as config, setting fields, value "${field}: rolls".`
|
|
222
|
-
: `${field} is ${kind === "counter" ? "a counter" : `a field of kind ${kind}`}, not kept rolls: keep and use take a field declared as rolls
|
|
226
|
+
: `${field} is ${kind === "counter" ? "a counter" : `a field of kind ${kind}`}, not kept rolls: keep and use take a field declared as rolls${rollsExample(world)}.`;
|
|
227
|
+
}
|
|
228
|
+
/** ", such as omen": a field the system or the campaign declares as kept rolls; how to declare one when none is. */
|
|
229
|
+
function rollsExample(world) {
|
|
230
|
+
const declared = declaredRolls(world);
|
|
231
|
+
return declared === undefined ? ', which config declares, such as setting fields, value "luck: rolls"' : `, such as ${declared}`;
|
|
232
|
+
}
|
|
233
|
+
/** A field of kept rolls for an example: one the system or the campaign declares, else a neutral name (D-514). */
|
|
234
|
+
function keptExample(world) {
|
|
235
|
+
return declaredRolls(world) ?? "omens";
|
|
236
|
+
}
|
|
237
|
+
function declaredRolls(world) {
|
|
238
|
+
return Object.keys(world.system?.fields ?? {}).find((name) => declaredKind(world, name) === "rolls");
|
|
239
|
+
}
|
|
240
|
+
/** The dice a game system rolls a number of its sheet with, for an example: that field's, else its first; 2d6 without them (D-280, D-514). */
|
|
241
|
+
export function sheetDiceOf(system, field) {
|
|
242
|
+
const dice = Object.entries(system?.sheetDice ?? {});
|
|
243
|
+
const own = field === undefined ? undefined : dice.find(([listed]) => comparableText(listed) === comparableText(field))?.[1];
|
|
244
|
+
return own ?? dice[0]?.[1] ?? "2d6";
|
|
223
245
|
}
|
|
224
246
|
/** " Elara keeps 3, 4 in portent: give from Elara.": the characters whose field holds the number use asked for, when the page asked does not (KEP-3). */
|
|
225
247
|
function otherKeepers(world, kept, value) {
|
|
@@ -241,7 +263,9 @@ function rollWith(notation, used, source) {
|
|
|
241
263
|
catch (error) {
|
|
242
264
|
// A kept number is not a face rolled now: there is nothing to roll again.
|
|
243
265
|
const why = (error instanceof DiceError ? error.message : String(error)).replace(/: ask the player to roll it again\.$/, "");
|
|
244
|
-
|
|
266
|
+
// The example with the notation's own die, as 1d6+2 for 2d6+2.
|
|
267
|
+
const die = /d(\d+|%|F)/i.exec(notation)?.[1] ?? "6";
|
|
268
|
+
throw new Error(`A kept roll takes the place of one die, of the kind it was rolled with: give a notation with that one die, such as 1d${die}+2 (${why}). Nothing rolled.`);
|
|
245
269
|
}
|
|
246
270
|
}
|
|
247
271
|
/** Writes the dice rolled in the field of kept rolls, in place of what it held (KEP-2), and says so. */
|
|
@@ -293,7 +317,7 @@ export function withSheetValues(notation, roller, who, system) {
|
|
|
293
317
|
// "sleight of hand": a name of several words, which a notation cannot hold.
|
|
294
318
|
const words = /^\s+[A-Za-z]/.test(notation.slice(offset + whole.length));
|
|
295
319
|
checkNotScore(roller, system, fields, name);
|
|
296
|
-
const value = sheetValue(roller, fields, name, who, words);
|
|
320
|
+
const value = sheetValue(roller, fields, name, who, words, system);
|
|
297
321
|
taken[name] = value;
|
|
298
322
|
const negative = (sign === "-") !== (value < 0);
|
|
299
323
|
return `${negative ? "-" : sign === "" ? "" : "+"}${Math.abs(value)}`;
|
|
@@ -308,15 +332,15 @@ function checkNotScore(roller, system, fields, name) {
|
|
|
308
332
|
const modifier = entry?.beside === undefined ? undefined : numberOf(read(entry.beside));
|
|
309
333
|
if (roller !== undefined && entry?.beside !== undefined && modifier !== undefined) {
|
|
310
334
|
const worked = `${entry.beside} ${signedText(roller.world, entry.beside, modifier)}`;
|
|
311
|
-
throw new Error(`${name} ${String(read(name))} is a score: the system ${system?.name ?? ""} works out ${worked} from it, which is what a roll adds, such as
|
|
335
|
+
throw new Error(`${name} ${String(read(name))} is a score: the system ${system?.name ?? ""} works out ${worked} from it, which is what a roll adds, such as ${sheetDiceOf(system, entry.beside)}+${entry.beside}. Nothing rolled.`);
|
|
312
336
|
}
|
|
313
337
|
}
|
|
314
338
|
/** The whole number a field holds on the sheet of who rolls; refused, with the numbers it has, when there is no sheet or it holds none. */
|
|
315
|
-
function sheetValue(roller, fields, name, who, words) {
|
|
339
|
+
function sheetValue(roller, fields, name, who, words, system) {
|
|
316
340
|
const page = roller?.page;
|
|
317
341
|
if (roller === undefined || fields === undefined || page === undefined) {
|
|
318
342
|
throw new Error(who === undefined
|
|
319
|
-
? `"${name}" is no die: to take it from a sheet, give who rolls, such as who Bruna; or give the number, such as
|
|
343
|
+
? `"${name}" is no die: to take it from a sheet, give who rolls, such as who Bruna; or give the number, such as ${sheetDiceOf(system)}+2.`
|
|
320
344
|
: `There is no page named ${who}, nor a copy of that name in the open scene, to take ${name} from: give who as the name of a character, or the number in the notation.`);
|
|
321
345
|
}
|
|
322
346
|
const value = valueNamed(fields, name);
|
|
@@ -325,15 +349,17 @@ function sheetValue(roller, fields, name, who, words) {
|
|
|
325
349
|
// Only numbers: a class's martial-arts 1d6 or its features are no bonus (PRO-2).
|
|
326
350
|
const numbers = workedFields(roller.world, fields).filter((worked) => numberOf(worked.value) !== undefined).map((worked) => `${worked.field} ${signedText(roller.world, worked.field, worked.value)}`);
|
|
327
351
|
const has = numbers.length === 0 ? "" : ` Its numbers: ${numbers.join(", ")}.`;
|
|
328
|
-
|
|
352
|
+
// The master's own field in the example, as athletics - 1 for athletics-1.
|
|
353
|
+
const subtracted = /^(.+)-(\d+)$/.exec(name);
|
|
354
|
+
const subtraction = subtracted === null ? "" : ` To subtract, put spaces around the minus, such as ${sheetDiceOf(system, subtracted[1])}+${subtracted[1]} - ${subtracted[2]}.`;
|
|
329
355
|
const hyphens = words ? " A name of several words is written with hyphens, such as sleight-of-hand." : "";
|
|
330
|
-
throw new Error(`${page.name} has no ${name}.${has} Give one of them, or the number, such as
|
|
356
|
+
throw new Error(`${page.name} has no ${name}.${has} Give one of them, or the number, such as ${sheetDiceOf(system)}+2.${subtraction}${hyphens}${missingSystemHint(roller.world)}`);
|
|
331
357
|
}
|
|
332
358
|
// One value for each item of a list, as the attacks of two weapons (PRO-5): the roll takes the number of the one used.
|
|
333
359
|
const list = itemList(roller.world, name);
|
|
334
360
|
const first = typeof value === "string" ? /[+-]\d+/.exec(value)?.[0] : undefined;
|
|
335
361
|
if (number === undefined && list !== undefined && first !== undefined) {
|
|
336
|
-
throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, one for each item in its ${list}: give the number of the one used, such as
|
|
362
|
+
throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, one for each item in its ${list}: give the number of the one used, such as ${sheetDiceOf(system, name)}${first}.`);
|
|
337
363
|
}
|
|
338
364
|
if (number === undefined || !Number.isInteger(number)) {
|
|
339
365
|
throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}, not a whole number: give the number in the notation.`);
|
|
@@ -342,11 +368,11 @@ function sheetValue(roller, fields, name, who, words) {
|
|
|
342
368
|
}
|
|
343
369
|
/**
|
|
344
370
|
* "Lena has Poisoned, Bless, exhaustion 1: see whether they change this roll.": the effects on who rolls that are not already in their numbers, being no more
|
|
345
|
-
* than a name, and the conditions (DAT-6); then the fields of their line written with ?, when they are not at zero (DAT-8).
|
|
371
|
+
* than a name, and the conditions, maybe in the campaign's language (DAT-6, D-403); then the fields of their line written with ?, when they are not at zero (DAT-8).
|
|
346
372
|
*/
|
|
347
|
-
function rollerNote(world, system, page) {
|
|
373
|
+
function rollerNote(world, system, page, words) {
|
|
348
374
|
const fields = effectiveFields(world, page);
|
|
349
|
-
const effects = effectsOf(page).filter((effect) => effect.values.length === 0 ||
|
|
375
|
+
const effects = effectsOf(page).filter((effect) => effect.values.length === 0 || systemNamed(system?.conditions ?? [], effect.name, words) !== undefined);
|
|
350
376
|
// Kept rolls are no number that changes a roll: use takes them.
|
|
351
377
|
const marked = (system?.statusLine ?? []).filter((entry) => entry.whenSet && declaredKind(world, entry.field) !== "rolls").flatMap((entry) => {
|
|
352
378
|
const value = valueNamed(fields, entry.field);
|
package/dist/commands/rules.js
CHANGED
|
@@ -5,8 +5,9 @@ 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
7
|
import { bookTitles, findRules, hasAllWords, readRuleBook, shownRules } from "../rules/index.js";
|
|
8
|
+
import { systemContentFolders } from "../systems/index.js";
|
|
8
9
|
import { libraryAnswer, libraryLines, systemWordsNamed } from "./game-library.js";
|
|
9
|
-
import { disagreementAdvice, houseRules, precedentRule } from "./game-rules.js";
|
|
10
|
+
import { disagreementAdvice, houseRules, precedentRule, systemRuleBook } from "./game-rules.js";
|
|
10
11
|
import { campaignSystem, campaignWorld, foreignLanguage } from "./game-world.js";
|
|
11
12
|
// About how many words an answer shows: a section of the system has about 80 words in the middle (D-178).
|
|
12
13
|
const answerWords = 800;
|
|
@@ -18,7 +19,7 @@ export const rules = defineCommand({
|
|
|
18
19
|
name: "rules",
|
|
19
20
|
description: "Find the exact text of a rule: the campaign's house rules first, then the game system's rules, then the table's precedents. "
|
|
20
21
|
+ "Use it whenever you are unsure how a rule works, before you rule and say what is at stake, and when the player questions a ruling. "
|
|
21
|
-
+ "Give the book's words, such as grappled,
|
|
22
|
+
+ "Give the book's words, such as grappled, cover or falling; a heading, or headings joined by ›, reads that section. "
|
|
22
23
|
+ "It searches the player's own books too, after the system, each excerpt with its book and page: Book › p. 194 reads that page.",
|
|
23
24
|
group: "game",
|
|
24
25
|
readOnly: true,
|
|
@@ -33,7 +34,7 @@ export const rules = defineCommand({
|
|
|
33
34
|
// Read one by one, as the system is (SYS-1): a mistake elsewhere in campaign.yaml does not stop the rules.
|
|
34
35
|
const precedents = readListSetting(root, "precedents");
|
|
35
36
|
const house = readRuleBook(join(root, houseRulesFolderName), houseRules);
|
|
36
|
-
const book = system === undefined ? [] :
|
|
37
|
+
const book = system === undefined ? [] : systemRuleBook(system);
|
|
37
38
|
const text = input.text?.trim() ?? "";
|
|
38
39
|
const common = {
|
|
39
40
|
text,
|
|
@@ -114,7 +115,8 @@ function isAboutAny(precedent, text, titles) {
|
|
|
114
115
|
*/
|
|
115
116
|
function pageNamed(root, context, system, text) {
|
|
116
117
|
const page = pageFileNamed(root, text);
|
|
117
|
-
|
|
118
|
+
// The version's page first, which takes the place of a common one (VER-3).
|
|
119
|
+
const systemPage = page === undefined && system !== undefined ? [...systemContentFolders(system)].reverse().map((folder) => pageFileNamed(folder, text)).find((found) => found !== undefined) : undefined;
|
|
118
120
|
if (page !== undefined) {
|
|
119
121
|
return page;
|
|
120
122
|
}
|
package/dist/commands/scene.d.ts
CHANGED
|
@@ -29,12 +29,12 @@ export declare const scene: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
29
29
|
action: z.ZodEnum<{
|
|
30
30
|
next: "next";
|
|
31
31
|
open: "open";
|
|
32
|
+
hostile: "hostile";
|
|
32
33
|
add: "add";
|
|
33
34
|
close: "close";
|
|
34
|
-
use: "use";
|
|
35
35
|
order: "order";
|
|
36
|
+
use: "use";
|
|
36
37
|
now: "now";
|
|
37
|
-
hostile: "hostile";
|
|
38
38
|
leave: "leave";
|
|
39
39
|
calm: "calm";
|
|
40
40
|
}>;
|