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/dashboard-server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { connect } from "node:net";
|
|
7
|
-
import { basename, extname, join, resolve } from "node:path";
|
|
7
|
+
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { readAdventureZip } from "./adventures/index.js";
|
|
@@ -12,22 +12,25 @@ import { findCampaign, readSettings, readTextSetting, requireCampaign, settingNa
|
|
|
12
12
|
import { config, playerChangeNews, playerSettingNamed, playerSettings, setupSettingNamed } from "./commands/config.js";
|
|
13
13
|
import { installAdventure } from "./commands/game-adventures.js";
|
|
14
14
|
import { catalog } from "./commands/game-catalog.js";
|
|
15
|
-
import {
|
|
15
|
+
import { campaignPageModules } from "./commands/game-extension-list.js";
|
|
16
16
|
import { imageFolders } from "./commands/game-images.js";
|
|
17
17
|
import { playerStory } from "./commands/game-knowledge.js";
|
|
18
18
|
import { libraryContents, libraryEntries, startLibraryReading, unquoted } from "./commands/game-library.js";
|
|
19
19
|
import { campaignMode } from "./commands/game-mode.js";
|
|
20
|
+
import { campaignPackages, loadCampaignCode, packageCommands } from "./commands/game-package-code.js";
|
|
20
21
|
import { exportsFolderName, resetPoints } from "./commands/game-saves.js";
|
|
21
|
-
import { campaignWidgets } from "./commands/game-widgets.js";
|
|
22
|
+
import { campaignWidgets, packageWidget } from "./commands/game-widgets.js";
|
|
22
23
|
import { campaignSystem, campaignWorld } from "./commands/game-world.js";
|
|
23
24
|
import { importShown } from "./commands/import.js";
|
|
24
|
-
import { adventureText, packageCommand, YesRefused } from "./commands/package.js";
|
|
25
|
+
import { adventureText, isInstalledPackage, packageCommand, YesRefused } from "./commands/package.js";
|
|
25
26
|
import { playerSaveNews, save } from "./commands/save.js";
|
|
26
27
|
import { view } from "./commands/view.js";
|
|
27
28
|
import { packagesFolder } from "./core/context.js";
|
|
29
|
+
import { realPath } from "./core/files.js";
|
|
28
30
|
import { isBoolean } from "./core/registry.js";
|
|
29
31
|
import { files, isInside, withFiles } from "./core/store.js";
|
|
30
32
|
import { comparableText } from "./core/text.js";
|
|
33
|
+
import { getVersion, isNewerVersion } from "./core/version.js";
|
|
31
34
|
import { notationParts } from "./dice/index.js";
|
|
32
35
|
import { extensionWords, findExtension } from "./extensions/index.js";
|
|
33
36
|
import { findHiddenImage, findImage } from "./images/index.js";
|
|
@@ -115,6 +118,8 @@ const importMap = JSON.stringify({
|
|
|
115
118
|
"three": "/vendor/three.module.js",
|
|
116
119
|
"three/addons/": "/vendor/three/addons/",
|
|
117
120
|
"@dimforge/rapier3d-compat": "/vendor/rapier.mjs",
|
|
121
|
+
// The kit the extensions' page code is drawn with (D-510).
|
|
122
|
+
"rpg-engine/page": "/kit.js",
|
|
118
123
|
},
|
|
119
124
|
});
|
|
120
125
|
// The page runs only its own files and the import map written in it, known by its hash; and the physics of the dice, which Rapier's module carries as
|
|
@@ -140,6 +145,8 @@ const pageHtml = [
|
|
|
140
145
|
export async function startDashboard(context, session, options = {}) {
|
|
141
146
|
// The systems' code, when no MCP server loaded it first, as the dashboard served alone (D-448).
|
|
142
147
|
context.systemCode ??= await loadSystemCode(context.systemFolders);
|
|
148
|
+
// And the campaign's extensions', whose hooks are called at once too (D-514).
|
|
149
|
+
await withFiles(session, () => loadCampaignCode(context));
|
|
143
150
|
const root = withFiles(session, () => findCampaign(context.folder)) ?? context.folder;
|
|
144
151
|
for (const port of options.ports ?? campaignPorts(root)) {
|
|
145
152
|
// A port another program answers at, even on ::1 or on every address, is its: a browser asking localhost could reach it instead (D-277).
|
|
@@ -159,6 +166,7 @@ export async function startDashboard(context, session, options = {}) {
|
|
|
159
166
|
pageHidden: options.pageHidden ?? pageHidden,
|
|
160
167
|
pageIds: new Map(),
|
|
161
168
|
seen: new Map(),
|
|
169
|
+
declined: new Set(),
|
|
162
170
|
changed: new Map(),
|
|
163
171
|
events: [],
|
|
164
172
|
left: new Set(),
|
|
@@ -217,6 +225,8 @@ function listen(server, port) {
|
|
|
217
225
|
}
|
|
218
226
|
// How long the catalog is kept before npm and GitHub are asked again.
|
|
219
227
|
const catalogLife = 10 * 60 * 1000;
|
|
228
|
+
// The version of rpg-engine this server runs, read as it starts: an update on disk comes only with a new chat (D-515 (3)).
|
|
229
|
+
const runningVersion = getVersion();
|
|
220
230
|
// How many characters the player's own words may have, in place of a button (ASK-10).
|
|
221
231
|
const mostSaid = 500;
|
|
222
232
|
// How long the page waits for the player's click: as long as a host waits for a call that keeps reporting progress, as ask does with a form.
|
|
@@ -299,6 +309,10 @@ async function answer(request, response, served) {
|
|
|
299
309
|
const url = new URL(request.url ?? "/", own[0]);
|
|
300
310
|
const path = url.pathname;
|
|
301
311
|
// The page answers the master's question with a click, and changes the player's settings: what it sends, and only from itself (D-279, D-341).
|
|
312
|
+
if (request.method === "POST" && path === "/api/run" && origin !== undefined) {
|
|
313
|
+
await runForPlayer(request, response, served);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
302
316
|
if (request.method === "POST" && path === "/api/answer" && origin !== undefined) {
|
|
303
317
|
await answerAsked(request, response, served);
|
|
304
318
|
return;
|
|
@@ -312,6 +326,10 @@ async function answer(request, response, served) {
|
|
|
312
326
|
listenForBell(request, response, served, url.searchParams.has("probe"));
|
|
313
327
|
return;
|
|
314
328
|
}
|
|
329
|
+
if (request.method === "POST" && path === "/api/card" && origin !== undefined) {
|
|
330
|
+
await closeCard(request, response, served);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
315
333
|
if (request.method === "POST" && path === "/api/seen" && origin !== undefined) {
|
|
316
334
|
await pageSeen(request, response, served);
|
|
317
335
|
return;
|
|
@@ -357,6 +375,11 @@ async function answer(request, response, served) {
|
|
|
357
375
|
await pageWords(request, response, served, url);
|
|
358
376
|
return;
|
|
359
377
|
}
|
|
378
|
+
// rpg-engine itself (D-515 (3)): what it is and what npm has, for the page; its update, from the page alone, never by the master.
|
|
379
|
+
if (path === "/api/engine" && (request.method === "GET" || (request.method === "POST" && origin !== undefined))) {
|
|
380
|
+
await engineNow(request, response, served);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
360
383
|
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
361
384
|
send(response, 405, "text/plain; charset=utf-8", "The dashboard only gives what the player may see, and takes a click on what the master asks, the player's settings and their saves.");
|
|
362
385
|
return;
|
|
@@ -372,6 +395,8 @@ async function answer(request, response, served) {
|
|
|
372
395
|
// The dice of a rest as they are now, read again at each look (ASK-14).
|
|
373
396
|
const spend = asked?.spending === undefined ? undefined : spendShown(asked.spending, served);
|
|
374
397
|
sendJson(response, 200, {
|
|
398
|
+
// How the card of a package's last question was left, while no other question is asked (D-507).
|
|
399
|
+
...(asked === undefined && served.card !== undefined ? { card: served.card } : {}),
|
|
375
400
|
asked: asked === undefined
|
|
376
401
|
? null
|
|
377
402
|
: {
|
|
@@ -382,7 +407,11 @@ async function answer(request, response, served) {
|
|
|
382
407
|
words,
|
|
383
408
|
names,
|
|
384
409
|
...rows,
|
|
385
|
-
...(asked.rows?.
|
|
410
|
+
...(asked.rows?.forced === true ? { forced: true } : {}),
|
|
411
|
+
...(asked.rows?.buttons === undefined ? {} : { buttons: asked.rows.buttons }),
|
|
412
|
+
...(asked.rows?.rule === undefined ? {} : { rule: asked.rows.rule }),
|
|
413
|
+
// Its card, or that one comes, until its widget answers: the page waits for it rather than show the question twice (D-507).
|
|
414
|
+
...(asked.card !== undefined ? { card: asked.card } : asked.rows?.card === undefined ? {} : { card: { widget: asked.rows.card.widget, key: asked.rows.card.key, coming: true } }),
|
|
386
415
|
...(asked.square ? { square: true } : {}),
|
|
387
416
|
...(spend === undefined ? {} : { who: spend.who, spend }),
|
|
388
417
|
},
|
|
@@ -393,10 +422,21 @@ async function answer(request, response, served) {
|
|
|
393
422
|
await packagesNow(response, served, url.searchParams.get("npm") === "true");
|
|
394
423
|
return;
|
|
395
424
|
}
|
|
425
|
+
if (path === "/api/modules") {
|
|
426
|
+
const root = findCampaign(served.context.folder);
|
|
427
|
+
await served.session.ready();
|
|
428
|
+
const modules = root === undefined ? [] : withFiles(served.session, () => pageModulesOf(root, served));
|
|
429
|
+
sendJson(response, 200, { modules: modules.map((one) => ({ package: one.package, kind: one.kind, version: one.version, address: one.address, figures: one.figures, ...(one.words === undefined ? {} : { words: one.words }) })) });
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
396
432
|
if (path === "/api/widgets") {
|
|
397
433
|
await widgetsNow(response, served);
|
|
398
434
|
return;
|
|
399
435
|
}
|
|
436
|
+
if (path === "/api/widget") {
|
|
437
|
+
await widgetForCard(response, served, url.searchParams);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
400
440
|
if (path === "/api/library") {
|
|
401
441
|
await libraryNow(response, served);
|
|
402
442
|
return;
|
|
@@ -431,6 +471,9 @@ async function answer(request, response, served) {
|
|
|
431
471
|
else if (path.startsWith("/vendor/")) {
|
|
432
472
|
sendFile(vendorModule(path.slice("/vendor/".length)), path, request, response, served);
|
|
433
473
|
}
|
|
474
|
+
else if (path.startsWith("/pkg/")) {
|
|
475
|
+
sendFile(packagePageFile(path.slice("/pkg/".length), served), path, request, response, served);
|
|
476
|
+
}
|
|
434
477
|
else {
|
|
435
478
|
sendFile(pageFile(served.page, path), path, request, response, served);
|
|
436
479
|
}
|
|
@@ -486,6 +529,71 @@ function sendFile(file, path, request, response, served) {
|
|
|
486
529
|
}
|
|
487
530
|
sendTagged(request, response, bytes, { "Content-Type": type, "Content-Security-Policy": type.startsWith("image/") ? picturePolicy : securityHeaders["Content-Security-Policy"] });
|
|
488
531
|
}
|
|
532
|
+
/**
|
|
533
|
+
* A file of a package's page code (D-510, D-511), at pkg/<package>/<version>/<path>: only of the campaign's system or one of its extensions, at the version
|
|
534
|
+
* installed, whose code runs, and only beside its page module, by real paths, links included; a script, a style sheet or a picture. Undefined for anything else.
|
|
535
|
+
*/
|
|
536
|
+
function packagePageFile(path, served) {
|
|
537
|
+
let parts;
|
|
538
|
+
try {
|
|
539
|
+
parts = path.split("/").map((part) => decodeURIComponent(part));
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
return undefined;
|
|
543
|
+
}
|
|
544
|
+
const [name, version, ...rest] = parts;
|
|
545
|
+
const root = findCampaign(served.context.folder);
|
|
546
|
+
const module = root === undefined ? undefined : withFiles(served.session, () => pageModulesOf(root, served).find((one) => one.package === name && one.version === version));
|
|
547
|
+
if (module === undefined || rest.length === 0 || ![".js", ".mjs", ".css", ".svg"].includes(extname(rest.at(-1) ?? ""))) {
|
|
548
|
+
return undefined;
|
|
549
|
+
}
|
|
550
|
+
const folder = realPath(dirname(module.file));
|
|
551
|
+
const file = realPath(resolve(folder, ...rest));
|
|
552
|
+
return isInside(folder, file) ? file : undefined;
|
|
553
|
+
}
|
|
554
|
+
/** The page modules of the campaign's packages whose code runs: its system's and its extensions'. */
|
|
555
|
+
function pageModulesOf(root, served) {
|
|
556
|
+
return campaignPageModules(root, served.context, campaignSystem(root, served.context));
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Runs a command of a package the player may run from its page code (D-510, D-514): one the campaign's packages give with player, whose code runs; as the
|
|
560
|
+
* player's, its output among what the master hears at their next call, quoted as another's words.
|
|
561
|
+
*/
|
|
562
|
+
async function runForPlayer(request, response, served) {
|
|
563
|
+
const parsed = z.object({ command: z.string().trim().min(1).max(80), input: z.record(z.string(), z.unknown()).optional() }).strict().safeParse(await readBody(request));
|
|
564
|
+
if (!parsed.success) {
|
|
565
|
+
sendJson(response, 400, { error: "Send the command to run and its input: { command, input }." });
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
try {
|
|
569
|
+
await served.session.ready();
|
|
570
|
+
const context = { ...served.context, actor: "player" };
|
|
571
|
+
const { text, readOnly } = await withFiles(served.session, async () => {
|
|
572
|
+
const root = requireCampaign(context.folder);
|
|
573
|
+
const command = (await packageCommands(root, context, [])).commands.find((one) => one.name === parsed.data.command && one.forPlayer === true);
|
|
574
|
+
if (command === undefined) {
|
|
575
|
+
throw new Error(`No package of the campaign gives ${parsed.data.command} to the player: a page runs only the commands its package marks player.`);
|
|
576
|
+
}
|
|
577
|
+
const input = command.input.safeParse(parsed.data.input ?? {});
|
|
578
|
+
if (!input.success) {
|
|
579
|
+
throw new Error(`The input of ${command.name} is not valid: ${input.error.issues.map((issue) => `${issue.path.join(".") || "input"}: ${issue.message}`).join("; ")}.`);
|
|
580
|
+
}
|
|
581
|
+
return { text: command.format(await command.run(input.data, context)), readOnly: command.readOnly === true };
|
|
582
|
+
});
|
|
583
|
+
const quoted = text.split("\n").map((line) => `> ${line}`).join("\n");
|
|
584
|
+
// A command that only reads tells the master nothing (D-514).
|
|
585
|
+
if (readOnly) {
|
|
586
|
+
sendJson(response, 200, { text });
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
served.events.push(`The player, on the dashboard, ran ${parsed.data.command}: it is already done, do not run it again. It said, as its package's words:\n${quoted}`);
|
|
590
|
+
served.notify();
|
|
591
|
+
sendJson(response, 200, { text });
|
|
592
|
+
}
|
|
593
|
+
catch (error) {
|
|
594
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
595
|
+
}
|
|
596
|
+
}
|
|
489
597
|
/** Bytes with a tag of what they hold, read again at each load: the same bytes come back as not modified, as three.js and the dice after the first load. */
|
|
490
598
|
function sendTagged(request, response, bytes, headers) {
|
|
491
599
|
const tag = `"${createHash("sha1").update(bytes).digest("base64url")}"`;
|
|
@@ -496,11 +604,21 @@ function sendTagged(request, response, bytes, headers) {
|
|
|
496
604
|
}
|
|
497
605
|
response.writeHead(200, all).end(request.method === "HEAD" ? undefined : bytes);
|
|
498
606
|
}
|
|
607
|
+
/** Reads what a package's card shows, never in the way of its question: given once it answers, with nothing to show when it fails or is late (D-507). */
|
|
608
|
+
function readCard(served, card, read) {
|
|
609
|
+
if (card === undefined) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
void card.shows().then((shows) => read({ widget: card.widget, key: card.key, ...(shows === undefined ? {} : { shows }) }), () => read({ widget: card.widget, key: card.key }));
|
|
613
|
+
}
|
|
499
614
|
/**
|
|
500
615
|
* The player through the page (D-279): the question shows on every page open, and the first click settles it; with no page open, "absent", so that ask turns to
|
|
501
616
|
* the form or to words. A stop of the call takes the question away and nothing is logged (ASK-9).
|
|
502
617
|
*/
|
|
503
618
|
function pagePlayer(served) {
|
|
619
|
+
// The card the last question on the page was asked in, which the call that asked it leaves as it ends, and how many were put (D-507).
|
|
620
|
+
let cardKey;
|
|
621
|
+
let questions = 0;
|
|
504
622
|
const put = (question, title, labels, signal, more = {}) => {
|
|
505
623
|
if (served.pages.size === 0) {
|
|
506
624
|
return Promise.resolve("absent");
|
|
@@ -509,8 +627,9 @@ function pagePlayer(served) {
|
|
|
509
627
|
if (signal?.aborted === true) {
|
|
510
628
|
return Promise.resolve(undefined);
|
|
511
629
|
}
|
|
512
|
-
// A question asked again, as after a summary, takes the place of the one before.
|
|
630
|
+
// A question asked again, as after a summary, takes the place of the one before; and of a card left from before.
|
|
513
631
|
served.asked?.settle(undefined);
|
|
632
|
+
served.card = undefined;
|
|
514
633
|
return new Promise((done) => {
|
|
515
634
|
const timer = setTimeout(() => settle(undefined), playerWait).unref();
|
|
516
635
|
const settle = (choice) => {
|
|
@@ -525,6 +644,14 @@ function pagePlayer(served) {
|
|
|
525
644
|
const stop = () => settle(undefined);
|
|
526
645
|
const asked = { id: randomUUID(), question, title, labels, ...more, settle };
|
|
527
646
|
served.asked = asked;
|
|
647
|
+
questions += 1;
|
|
648
|
+
cardKey = more.rows?.card?.key ?? cardKey;
|
|
649
|
+
readCard(served, more.rows?.card, (card) => {
|
|
650
|
+
if (served.asked === asked) {
|
|
651
|
+
asked.card = card;
|
|
652
|
+
served.notify();
|
|
653
|
+
}
|
|
654
|
+
});
|
|
528
655
|
signal?.addEventListener("abort", stop);
|
|
529
656
|
served.notify();
|
|
530
657
|
watchHidden(served);
|
|
@@ -532,6 +659,20 @@ function pagePlayer(served) {
|
|
|
532
659
|
};
|
|
533
660
|
return {
|
|
534
661
|
asking: () => served.asked !== undefined,
|
|
662
|
+
cardEnded(card) {
|
|
663
|
+
// Only a card its questions were asked in on the page.
|
|
664
|
+
if (card.key !== cardKey) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const at = questions;
|
|
668
|
+
readCard(served, card, (read) => {
|
|
669
|
+
// Only while no other question came meanwhile, answered or not.
|
|
670
|
+
if (served.asked === undefined && questions === at) {
|
|
671
|
+
served.card = { ...read, ended: true };
|
|
672
|
+
served.notify();
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
},
|
|
535
676
|
async choose(question, title, labels, signal, rows) {
|
|
536
677
|
const chosen = await put(question, title, labels, signal, rows === undefined ? {} : { rows });
|
|
537
678
|
return typeof chosen === "object" && "square" in chosen ? undefined : chosen;
|
|
@@ -541,8 +682,8 @@ function pagePlayer(served) {
|
|
|
541
682
|
const chosen = await put(question, title, [change], signal, { square: true, rows: { who, fields: [] } });
|
|
542
683
|
return typeof chosen === "number" ? (chosen === 0 ? 0 : undefined) : chosen;
|
|
543
684
|
},
|
|
544
|
-
async spendDice(question, title, done, spending, signal) {
|
|
545
|
-
const chosen = await put(question, title, [done], signal, { spending });
|
|
685
|
+
async spendDice(question, title, done, spending, signal, card) {
|
|
686
|
+
const chosen = await put(question, title, [done], signal, { spending, ...(card === undefined ? {} : { rows: { who: spending.shown().who, fields: [], card } }) });
|
|
546
687
|
// The call stopped, its answer never goes: the dice spent reach the master at the next one, as the player's other news (ASK-14).
|
|
547
688
|
const told = signal?.aborted === true ? spending.spent() : undefined;
|
|
548
689
|
if (told !== undefined) {
|
|
@@ -694,6 +835,19 @@ async function changeSetting(request, response, served) {
|
|
|
694
835
|
}
|
|
695
836
|
}
|
|
696
837
|
/** Whether a page is seen now, as it says when it comes in sight or goes out of it (D-455): a question on pages no one sees goes to the chat. */
|
|
838
|
+
/** The player closed a package's card that its call left (D-507): it is gone on every page and every device, and after a reload. */
|
|
839
|
+
async function closeCard(request, response, served) {
|
|
840
|
+
const parsed = z.object({ close: z.string().min(1).max(200) }).strict().safeParse(await readBody(request));
|
|
841
|
+
if (!parsed.success) {
|
|
842
|
+
sendJson(response, 400, { error: "Send the key of the card to close: { close }." });
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (served.card?.key === parsed.data.close) {
|
|
846
|
+
served.card = undefined;
|
|
847
|
+
served.notify();
|
|
848
|
+
}
|
|
849
|
+
sendJson(response, 202, {});
|
|
850
|
+
}
|
|
697
851
|
async function pageSeen(request, response, served) {
|
|
698
852
|
const parsed = z.object({ page: z.string().min(1).max(64), seen: z.boolean() }).strict().safeParse(await readBody(request));
|
|
699
853
|
if (!parsed.success) {
|
|
@@ -767,6 +921,21 @@ function inLanguage(installed, served, language) {
|
|
|
767
921
|
}
|
|
768
922
|
});
|
|
769
923
|
}
|
|
924
|
+
/** What one widget of a package shows for a card or a page of its page code, for the character it shows (D-514): its data, or nothing. */
|
|
925
|
+
async function widgetForCard(response, served, query) {
|
|
926
|
+
const [owner, name, who] = [query.get("package") ?? "", query.get("widget") ?? "", query.get("who") ?? undefined];
|
|
927
|
+
try {
|
|
928
|
+
await served.session.ready();
|
|
929
|
+
const shows = await withFiles(served.session, async () => {
|
|
930
|
+
const root = findCampaign(served.context.folder);
|
|
931
|
+
return root === undefined ? undefined : await packageWidget(root, served.context, owner, name, who === "" ? undefined : who);
|
|
932
|
+
});
|
|
933
|
+
sendJson(response, 200, shows === undefined ? {} : { shows });
|
|
934
|
+
}
|
|
935
|
+
catch (error) {
|
|
936
|
+
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
937
|
+
}
|
|
938
|
+
}
|
|
770
939
|
/** The widgets of the campaign's extensions as the page shows them (D-502): where each stands, and what it shows now; none without a campaign. */
|
|
771
940
|
async function widgetsNow(response, served) {
|
|
772
941
|
try {
|
|
@@ -792,6 +961,11 @@ async function changePackage(request, response, served) {
|
|
|
792
961
|
return;
|
|
793
962
|
}
|
|
794
963
|
const { action, name } = parsed.data;
|
|
964
|
+
// The page updates or takes away only what this computer has: it never brings a package new to it, nor its window, by these (D-510).
|
|
965
|
+
if (!isInstalledPackage(served.context, name)) {
|
|
966
|
+
sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it.` });
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
795
969
|
const done = action === "update" ? "updated" : action === "remove" ? "took out of the campaign" : "uninstalled";
|
|
796
970
|
await packageWork(response, served, name, action, async (context) => {
|
|
797
971
|
const result = await packageCommand.run(packageCommand.input.parse({ action: action === "update" ? "install" : action, name }), context);
|
|
@@ -911,6 +1085,8 @@ async function packageWork(response, served, name, action, work) {
|
|
|
911
1085
|
player: undefined,
|
|
912
1086
|
// Never the terminal: a folder new to the library asks the yes in a window (D-477).
|
|
913
1087
|
terminal: undefined,
|
|
1088
|
+
// A no in a window holds for the session: a page, or a package's code in it, cannot make the window come back and back (D-510).
|
|
1089
|
+
declined: served.declined,
|
|
914
1090
|
...(confirm === undefined ? {} : {
|
|
915
1091
|
confirm: {
|
|
916
1092
|
ask: async (title, text, signal, answers) => {
|
|
@@ -926,7 +1102,7 @@ async function packageWork(response, served, name, action, work) {
|
|
|
926
1102
|
if (done.news !== "") {
|
|
927
1103
|
served.events.push(done.news);
|
|
928
1104
|
}
|
|
929
|
-
sendJson(response, 202, { kind: done.kind });
|
|
1105
|
+
sendJson(response, 202, { kind: done.kind, ...done.answer });
|
|
930
1106
|
}
|
|
931
1107
|
catch (error) {
|
|
932
1108
|
sendJson(response, 400, { error: error instanceof Error ? error.message : String(error), ...(error instanceof YesRefused ? { code: error.code } : {}) });
|
|
@@ -936,6 +1112,65 @@ async function packageWork(response, served, name, action, work) {
|
|
|
936
1112
|
served.notify();
|
|
937
1113
|
}
|
|
938
1114
|
}
|
|
1115
|
+
/**
|
|
1116
|
+
* rpg-engine itself on the Packages page (D-515 (3)): its version, npm's latest and whether it is newer, and how it is installed, read at each look; its update,
|
|
1117
|
+
* from the page alone, globally with npm as it was installed, a development link or another install told and never touched; then how the chat takes it.
|
|
1118
|
+
*/
|
|
1119
|
+
async function engineNow(request, response, served) {
|
|
1120
|
+
const updater = served.context.engine;
|
|
1121
|
+
const version = runningVersion;
|
|
1122
|
+
// Where nothing updates it, as in the demo, its version alone.
|
|
1123
|
+
if (updater === undefined) {
|
|
1124
|
+
sendJson(response, request.method === "GET" ? 200 : 400, request.method === "GET" ? { version } : { error: "Only the game's server, started by the chat, updates rpg-engine." });
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
// What npm installed since this server started comes with a new chat: said apart, never as the version that runs.
|
|
1128
|
+
const onDisk = updater.onDisk();
|
|
1129
|
+
if (request.method === "GET") {
|
|
1130
|
+
const [latest, installed] = await Promise.all([updater.latest(), updater.installed()]);
|
|
1131
|
+
sendJson(response, 200, {
|
|
1132
|
+
version,
|
|
1133
|
+
...(onDisk === version ? {} : { installed: onDisk }),
|
|
1134
|
+
...("failed" in latest ? { failed: latest.failed } : { latest: latest.version, update: isNewerVersion(latest.version, onDisk) }),
|
|
1135
|
+
install: installed.how,
|
|
1136
|
+
...("folder" in installed ? { folder: installed.folder } : {}),
|
|
1137
|
+
...(served.packageWork === undefined ? {} : { working: served.packageWork }),
|
|
1138
|
+
});
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
const parsed = z.object({ action: z.literal("update") }).strict().safeParse(await readBody(request));
|
|
1142
|
+
if (!parsed.success) {
|
|
1143
|
+
sendJson(response, 400, { error: "Send what to do with rpg-engine: { action: update }." });
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
await packageWork(response, served, "rpg-engine", "engine", async () => {
|
|
1147
|
+
const latest = await updater.latest();
|
|
1148
|
+
if ("failed" in latest) {
|
|
1149
|
+
throw new Error(`${latest.failed}: update it once this computer is online. Nothing changed.`);
|
|
1150
|
+
}
|
|
1151
|
+
if (!isNewerVersion(latest.version, onDisk)) {
|
|
1152
|
+
throw new Error(onDisk === version ? `rpg-engine ${version} is npm's latest: there is nothing to update.` : `rpg-engine ${onDisk} is installed already: it comes with a new chat.`);
|
|
1153
|
+
}
|
|
1154
|
+
const installed = await updater.installed();
|
|
1155
|
+
if (installed.how !== "global") {
|
|
1156
|
+
throw new Error(installed.how === "link"
|
|
1157
|
+
? `rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed.`
|
|
1158
|
+
: `rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed.`);
|
|
1159
|
+
}
|
|
1160
|
+
const why = await updater.update(latest.version);
|
|
1161
|
+
if (why !== undefined) {
|
|
1162
|
+
throw new Error(`rpg-engine could not be updated: ${why}. Nothing changed.`);
|
|
1163
|
+
}
|
|
1164
|
+
// The chat goes on with the server it started, and so does this page: the new engine comes with a new chat, or the app opened again.
|
|
1165
|
+
const host = served.context.host?.() ?? "";
|
|
1166
|
+
const restart = /codex|claude-ai|claude desktop/i.test(host) ? "app" : "chat";
|
|
1167
|
+
return {
|
|
1168
|
+
kind: "engine-updated",
|
|
1169
|
+
news: `The player updated rpg-engine from ${version} to ${latest.version} on the dashboard: this chat goes on with ${version}, the new one comes with their next chat. Nothing to do now.`,
|
|
1170
|
+
answer: { version: latest.version, restart },
|
|
1171
|
+
};
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
939
1174
|
/** The kind of package a result of package install says it installed. */
|
|
940
1175
|
function kindOf(result) {
|
|
941
1176
|
return result === "adventure-installed" ? "adventure" : result === "system-installed" ? "system" : result === "language-installed" ? "language" : "extension";
|
|
@@ -1481,7 +1716,7 @@ async function runCommand(name, parameters, response, served) {
|
|
|
1481
1716
|
* runs nothing, even an SVG opened by itself.
|
|
1482
1717
|
*/
|
|
1483
1718
|
function sendImage(name, request, response, served) {
|
|
1484
|
-
//
|
|
1719
|
+
// A package's own, which its widgets show, at an address of its own, ext/<package>/<file>, never mistaken for the campaign's (D-502, D-514).
|
|
1485
1720
|
const [, extensionName, extensionFile] = /^ext\/([^/]+)\/([^/]+)$/.exec(name) ?? [];
|
|
1486
1721
|
const fileName = decoded(extensionFile ?? name);
|
|
1487
1722
|
const ownerName = extensionName === undefined ? undefined : decoded(extensionName);
|
|
@@ -1491,7 +1726,7 @@ function sendImage(name, request, response, served) {
|
|
|
1491
1726
|
return undefined;
|
|
1492
1727
|
}
|
|
1493
1728
|
if (extensionName !== undefined) {
|
|
1494
|
-
const owner =
|
|
1729
|
+
const owner = campaignPackages(root, served.context).find((extension) => extension.name === ownerName);
|
|
1495
1730
|
return owner === undefined ? undefined : findImage([owner.folder], fileName);
|
|
1496
1731
|
}
|
|
1497
1732
|
// A stranger's picture comes by a name of its bytes, from the campaign's own (D-420).
|
package/dist/dice/roll-dice.js
CHANGED
|
@@ -18,7 +18,7 @@ export function rollDice(notation, source) {
|
|
|
18
18
|
function rollPhysical(terms, values) {
|
|
19
19
|
const neededCount = minimumDice(terms);
|
|
20
20
|
if (values.length < neededCount) {
|
|
21
|
-
throw new DiceError(`This roll needs at least ${neededCount} values (${describeDice(terms)}), but ${values.length} were given.`);
|
|
21
|
+
throw new DiceError(`This roll needs at least ${neededCount} values (${describeDice(terms)}), but ${values.length} ${values.length === 1 ? "was" : "were"} given.`);
|
|
22
22
|
}
|
|
23
23
|
const faces = physicalFaces(values);
|
|
24
24
|
const breakdown = evaluateTerms(terms, faces.nextFace);
|
package/dist/effects/effect.d.ts
CHANGED
|
@@ -44,12 +44,15 @@ export declare function formatEnd(end: EffectEnd): string;
|
|
|
44
44
|
export declare function readRounds(text: string): number | undefined;
|
|
45
45
|
/** Whether a duration is the scene itself: the effect ends when the scene does. */
|
|
46
46
|
export declare function isSceneDuration(text: string): boolean;
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The effects with one added, as the newest: an effect with the same name is replaced (EFF-3, EFF-4), or with its word in `words`, the game system's in the
|
|
49
|
+
* campaign's language, Prono for Prone (D-403).
|
|
50
|
+
*/
|
|
51
|
+
export declare function withEffect(effects: Effect[], effect: Effect, words?: Record<string, string>): Effect[];
|
|
49
52
|
/** Who keeps an effect alive, by name: [[Lena]] and Lena are the same; undefined when no one does. */
|
|
50
53
|
export declare function keeperOf(effect: Effect): string | undefined;
|
|
51
|
-
/** The effect with this name, ignoring case and how accents are written. */
|
|
52
|
-
export declare function effectNamed(effects: Effect[], name: string): Effect | undefined;
|
|
54
|
+
/** The effect with this name, ignoring case and how accents are written, or with its word in `words`, as withEffect reads them. */
|
|
55
|
+
export declare function effectNamed(effects: Effect[], name: string, words?: Record<string, string>): Effect | undefined;
|
|
53
56
|
/** Whether an effect counted in rounds has ended when the turn passes to `turn` in `round` (EFF-9): at its turn in its round, at the start of its round when that one is no longer in the order, a round later anyway. */
|
|
54
57
|
export declare function endsAtTurn(end: {
|
|
55
58
|
round: number;
|
package/dist/effects/effect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { comparableText } from "../core/text.js";
|
|
1
|
+
import { comparableText, sameWord } from "../core/text.js";
|
|
2
2
|
// "Scudo della fede (by: [[Lena]], ac: 15) until day 2, 14:20": a name, values in brackets, an end; the brackets and the end may be missing.
|
|
3
3
|
const linePattern = /^(.+?)(?:\s+\(([^()]*)\))?(?:\s+until\s+(.+))?$/i;
|
|
4
4
|
const roundPattern = /^round\s+(\d{1,9})\s*,\s*(.+)$/i;
|
|
@@ -8,7 +8,7 @@ const sceneEnd = "scene end";
|
|
|
8
8
|
export function readEffect(line) {
|
|
9
9
|
const match = linePattern.exec(line.trim());
|
|
10
10
|
if (match === null) {
|
|
11
|
-
return { problem: `"${line}" is not an effect: write its name, then its values in brackets and its end, such as
|
|
11
|
+
return { problem: `"${line}" is not an effect: write its name, then its values in brackets and its end, such as Protezione (armor: 2) until day 2, 14:20.` };
|
|
12
12
|
}
|
|
13
13
|
const [, written, valuesText, endText] = match;
|
|
14
14
|
const values = valuesText === undefined ? [] : readValues(valuesText);
|
|
@@ -32,7 +32,7 @@ export function readEffects(value) {
|
|
|
32
32
|
}
|
|
33
33
|
const lines = (Array.isArray(value) ? value : [value]).map(asLine);
|
|
34
34
|
if (lines.some((line) => line === undefined)) {
|
|
35
|
-
return { problem: "effects must be a list of lines of text, such as
|
|
35
|
+
return { problem: "effects must be a list of lines of text, such as Protezione (armor: 2) until day 2, 14:20." };
|
|
36
36
|
}
|
|
37
37
|
const effects = [];
|
|
38
38
|
for (const line of lines.filter((text) => text.trim() !== "")) {
|
|
@@ -67,17 +67,20 @@ export function readRounds(text) {
|
|
|
67
67
|
export function isSceneDuration(text) {
|
|
68
68
|
return comparableText(text.trim()) === "scene";
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
/**
|
|
71
|
+
* The effects with one added, as the newest: an effect with the same name is replaced (EFF-3, EFF-4), or with its word in `words`, the game system's in the
|
|
72
|
+
* campaign's language, Prono for Prone (D-403).
|
|
73
|
+
*/
|
|
74
|
+
export function withEffect(effects, effect, words) {
|
|
75
|
+
return [...effects.filter((other) => !sameWord(other.name, effect.name, words)), effect];
|
|
73
76
|
}
|
|
74
77
|
/** Who keeps an effect alive, by name: [[Lena]] and Lena are the same; undefined when no one does. */
|
|
75
78
|
export function keeperOf(effect) {
|
|
76
79
|
return effect.by === undefined ? undefined : pageName(effect.by);
|
|
77
80
|
}
|
|
78
|
-
/** The effect with this name, ignoring case and how accents are written. */
|
|
79
|
-
export function effectNamed(effects, name) {
|
|
80
|
-
return effects.find((effect) =>
|
|
81
|
+
/** The effect with this name, ignoring case and how accents are written, or with its word in `words`, as withEffect reads them. */
|
|
82
|
+
export function effectNamed(effects, name, words) {
|
|
83
|
+
return effects.find((effect) => sameWord(effect.name, name, words));
|
|
81
84
|
}
|
|
82
85
|
/** Whether an effect counted in rounds has ended when the turn passes to `turn` in `round` (EFF-9): at its turn in its round, at the start of its round when that one is no longer in the order, a round later anyway. */
|
|
83
86
|
export function endsAtTurn(end, round, turn, order) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EngineUpdater } from "../core/context.ts";
|
|
2
|
+
import { type NpmRun } from "./packages.ts";
|
|
3
|
+
/** rpg-engine on npm, for the engine in this folder, from src/ and dist/ alike its package's own; `run` runs npm, a fake in tests. */
|
|
4
|
+
export declare function npmEngine(folder?: string, run?: (args: string) => Promise<NpmRun>): EngineUpdater;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// rpg-engine itself on npm (D-515 (3)): its latest version, how this one is installed, and its update with npm, globally as it was installed; a development
|
|
2
|
+
// link, or any other install, is told and never touched.
|
|
3
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { npmError, npmErrorCode, runNpm } from "./packages.js";
|
|
7
|
+
const registry = "https://registry.npmjs.org";
|
|
8
|
+
/** rpg-engine on npm, for the engine in this folder, from src/ and dist/ alike its package's own; `run` runs npm, a fake in tests. */
|
|
9
|
+
export function npmEngine(folder = fileURLToPath(new URL("../../", import.meta.url)), run = runNpm) {
|
|
10
|
+
return {
|
|
11
|
+
latest: async () => {
|
|
12
|
+
try {
|
|
13
|
+
const answer = await fetch(`${registry}/rpg-engine/latest`, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(20_000) });
|
|
14
|
+
const read = answer.ok ? await answer.json() : undefined;
|
|
15
|
+
return typeof read?.version === "string" ? { version: read.version } : { failed: `npm's registry answered ${answer.status} ${answer.statusText}` };
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return { failed: `npm's registry could not be reached: ${error instanceof Error ? error.message : String(error)}` };
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
installed: async () => engineInstall(folder, await run("root -g")),
|
|
22
|
+
onDisk: () => {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(readFileSync(join(folder, "package.json"), "utf8")).version ?? "0.0.0";
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return "0.0.0";
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
update: async (version) => {
|
|
31
|
+
if (!/^\d+\.\d+\.\d+$/.test(version)) {
|
|
32
|
+
return `${version} is not a version of rpg-engine`;
|
|
33
|
+
}
|
|
34
|
+
const ran = await run(`install -g rpg-engine@${version} --no-audit --no-fund --json --loglevel=error`);
|
|
35
|
+
return ran.code === 0 ? undefined : updateProblem(ran);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** How the engine in this folder is installed, by npm's global folder: the package there, a link to this folder, or neither. */
|
|
40
|
+
function engineInstall(folder, root) {
|
|
41
|
+
const own = realFolder(folder);
|
|
42
|
+
if (root.code !== 0 || own === undefined) {
|
|
43
|
+
return { how: "other", folder: own ?? folder };
|
|
44
|
+
}
|
|
45
|
+
const global = join(root.out.trim(), "rpg-engine");
|
|
46
|
+
try {
|
|
47
|
+
const linked = lstatSync(global).isSymbolicLink();
|
|
48
|
+
return realFolder(global) !== own ? { how: "other", folder: own } : linked ? { how: "link", folder: own } : { how: "global" };
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return { how: "other", folder: own };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** A folder as the file system resolves it, through links; undefined when it is not there. */
|
|
55
|
+
function realFolder(folder) {
|
|
56
|
+
try {
|
|
57
|
+
return realpathSync(folder);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Why npm did not update rpg-engine, with what the player can do. */
|
|
64
|
+
function updateProblem(ran) {
|
|
65
|
+
const code = npmErrorCode(ran);
|
|
66
|
+
// On Windows a file another program holds is refused as EPERM.
|
|
67
|
+
if (code === "EBUSY" || (code === "EPERM" && process.platform === "win32")) {
|
|
68
|
+
return "a file of rpg-engine is in use by another program: close the other chats with RPG Engine, then update it again";
|
|
69
|
+
}
|
|
70
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
71
|
+
return `npm may not write its global folder (${code}): update it in a terminal with npm install -g rpg-engine, as the computer's administrator if it asks`;
|
|
72
|
+
}
|
|
73
|
+
return `npm said: ${npmError(ran)}`;
|
|
74
|
+
}
|