rpg-engine 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/effect.d.ts +1 -1
  3. package/dist/commands/shared/inputs.d.ts +2 -2
  4. package/dist/commands/shared/inputs.js +15 -2
  5. package/dist/commands/shared/page-words.d.ts +4 -0
  6. package/dist/commands/shared/page-words.js +7 -7
  7. package/dist/commands/shared/system-texts.d.ts +11 -0
  8. package/dist/commands/shared/system-texts.js +203 -0
  9. package/dist/commands/shared/world.d.ts +2 -0
  10. package/dist/commands/shared/world.js +13 -3
  11. package/dist/commands/view/view.d.ts +4 -0
  12. package/dist/commands/view/view.js +14 -3
  13. package/dist/commands/write/write.d.ts +3 -3
  14. package/dist/core/context.d.ts +16 -0
  15. package/dist/core/files.js +2 -3
  16. package/dist/core/language.d.ts +2 -0
  17. package/dist/core/language.js +8 -0
  18. package/dist/core/text.d.ts +2 -0
  19. package/dist/core/text.js +5 -0
  20. package/dist/dashboard/app.js +2 -1
  21. package/dist/dashboard/guide/ar.md +2 -2
  22. package/dist/dashboard/guide/cs.md +2 -2
  23. package/dist/dashboard/guide/da.md +2 -2
  24. package/dist/dashboard/guide/de.md +2 -2
  25. package/dist/dashboard/guide/el.md +2 -2
  26. package/dist/dashboard/guide/en.md +1 -1
  27. package/dist/dashboard/guide/es.md +2 -2
  28. package/dist/dashboard/guide/fi.md +2 -2
  29. package/dist/dashboard/guide/fr.md +2 -2
  30. package/dist/dashboard/guide/he.md +2 -2
  31. package/dist/dashboard/guide/hi.md +2 -2
  32. package/dist/dashboard/guide/hu.md +2 -2
  33. package/dist/dashboard/guide/is.md +2 -2
  34. package/dist/dashboard/guide/it.md +2 -2
  35. package/dist/dashboard/guide/ja.md +2 -2
  36. package/dist/dashboard/guide/ko.md +2 -2
  37. package/dist/dashboard/guide/nb.md +2 -2
  38. package/dist/dashboard/guide/nl.md +2 -2
  39. package/dist/dashboard/guide/pl.md +2 -2
  40. package/dist/dashboard/guide/pt.md +2 -2
  41. package/dist/dashboard/guide/ro.md +2 -2
  42. package/dist/dashboard/guide/ru.md +2 -2
  43. package/dist/dashboard/guide/sv.md +2 -2
  44. package/dist/dashboard/guide/tr.md +2 -2
  45. package/dist/dashboard/guide/uk.md +2 -2
  46. package/dist/dashboard/guide/zh.md +2 -2
  47. package/dist/dashboard/i18n/ar.json +2 -1
  48. package/dist/dashboard/i18n/cs.json +2 -1
  49. package/dist/dashboard/i18n/da.json +2 -1
  50. package/dist/dashboard/i18n/de.json +2 -1
  51. package/dist/dashboard/i18n/el.json +2 -1
  52. package/dist/dashboard/i18n/es.json +2 -1
  53. package/dist/dashboard/i18n/fi.json +2 -1
  54. package/dist/dashboard/i18n/fr.json +2 -1
  55. package/dist/dashboard/i18n/he.json +2 -1
  56. package/dist/dashboard/i18n/hi.json +2 -1
  57. package/dist/dashboard/i18n/hu.json +2 -1
  58. package/dist/dashboard/i18n/is.json +2 -1
  59. package/dist/dashboard/i18n/it.json +2 -1
  60. package/dist/dashboard/i18n/ja.json +2 -1
  61. package/dist/dashboard/i18n/ko.json +2 -1
  62. package/dist/dashboard/i18n/nb.json +2 -1
  63. package/dist/dashboard/i18n/nl.json +2 -1
  64. package/dist/dashboard/i18n/pl.json +2 -1
  65. package/dist/dashboard/i18n/pt.json +2 -1
  66. package/dist/dashboard/i18n/ro.json +2 -1
  67. package/dist/dashboard/i18n/ru.json +2 -1
  68. package/dist/dashboard/i18n/sv.json +2 -1
  69. package/dist/dashboard/i18n/tr.json +2 -1
  70. package/dist/dashboard/i18n/uk.json +2 -1
  71. package/dist/dashboard/i18n/zh.json +2 -1
  72. package/dist/dashboard/notices.js +9 -2
  73. package/dist/dashboard/saves.js +1 -1
  74. package/dist/dashboard/text.js +7 -2
  75. package/dist/documents/png.d.ts +2 -3
  76. package/dist/documents/png.js +6 -6
  77. package/dist/documents/read.js +2 -1
  78. package/dist/extensions/words.js +2 -1
  79. package/dist/languages/language-pack.js +2 -2
  80. package/dist/pages/index.d.ts +1 -1
  81. package/dist/pages/index.js +1 -1
  82. package/dist/pages/world.d.ts +5 -0
  83. package/dist/pages/world.js +22 -11
  84. package/dist/server/dashboard/files.js +3 -2
  85. package/dist/server/dashboard/index.d.ts +3 -1
  86. package/dist/server/dashboard/index.js +3 -1
  87. package/dist/server/mcp.js +3 -1
  88. package/dist/systems/game-system.js +2 -1
  89. package/dist/systems/words.js +2 -1
  90. package/dist/testing/index.js +1 -1
  91. package/instructions/play.md +1 -1
  92. package/package.json +4 -4
@@ -248,7 +248,8 @@ export async function pageWords(request, response, served, url) {
248
248
  sendJson(response, 400, { error: "Send the language and the phrases the page lacks now, { language, first }." });
249
249
  return;
250
250
  }
251
- served.words.ask(parsed.data.language.toLowerCase(), parsed.data.first);
251
+ // Through the session, which keeps the system's words translated on this computer (D-539).
252
+ withFiles(served.session, () => served.words.ask(parsed.data.language.toLowerCase(), parsed.data.first));
252
253
  sendJson(response, 202, {});
253
254
  return;
254
255
  }
@@ -262,7 +263,7 @@ export async function pageWords(request, response, served, url) {
262
263
  const found = root === undefined ? undefined : campaignSystem(root, served.context);
263
264
  return found === undefined ? undefined : { name: found.name, folder: found.folder };
264
265
  });
265
- sendJson(response, 200, served.words.read(language.toLowerCase(), system));
266
+ sendJson(response, 200, withFiles(served.session, () => served.words.read(language.toLowerCase(), system)));
266
267
  }
267
268
  /** A request's body as bytes, up to `most`; undefined when it is more. */
268
269
  export async function readBytes(request, most) {
@@ -2,7 +2,7 @@ import { type ServerResponse } from "node:http";
2
2
  import type { PlayerSetting } from "../../commands/config.ts";
3
3
  import type { Catalog } from "../../commands/shared/packages/catalog.ts";
4
4
  import { type PageTranslator } from "../../commands/shared/page-words.ts";
5
- import type { Context, Player } from "../../core/context.ts";
5
+ import type { Context, Player, SystemTexts } from "../../core/context.ts";
6
6
  import type { SessionStore } from "../../core/session-store.ts";
7
7
  import { type Acts } from "../player-acts.ts";
8
8
  import { type Asked, type ShownCard } from "./player.ts";
@@ -85,6 +85,8 @@ export interface Served {
85
85
  notify(): void;
86
86
  /** The page in a language the package does not ship, translated on the fly (D-406). */
87
87
  words: PageTranslator;
88
+ /** The game system's pages in the campaign's language, translated as the page reads them (D-539): the page's alone, never the master's calls. */
89
+ texts: SystemTexts;
88
90
  /** The package the player is adding, updating or taking away on the page, while npm works (D-475): one at a time. */
89
91
  packageWork?: {
90
92
  name: string;
@@ -8,6 +8,7 @@ import { importShown } from "../../commands/import/import.js";
8
8
  import { loadCampaignCode } from "../../commands/shared/packages/code.js";
9
9
  import { campaignWidgets, packageWidget } from "../../commands/shared/packages/widgets.js";
10
10
  import { pageTranslator } from "../../commands/shared/page-words.js";
11
+ import { systemTexts } from "../../commands/shared/system-texts.js";
11
12
  import { view } from "../../commands/view/view.js";
12
13
  import { isBoolean } from "../../core/registry.js";
13
14
  import { withFiles } from "../../core/store.js";
@@ -66,6 +67,7 @@ export async function startDashboard(context, session, options = {}) {
66
67
  shared: new Map(),
67
68
  notify: () => undefined,
68
69
  words: pageTranslator(context, options.page ?? builtPage, () => served.notify()),
70
+ texts: systemTexts(context, () => served.notify()),
69
71
  acts: newActs(),
70
72
  queue: options.queue ?? codexQueue(),
71
73
  };
@@ -380,7 +382,7 @@ async function runCommand(name, parameters, response, served) {
380
382
  }
381
383
  try {
382
384
  await served.session.ready();
383
- const result = await command.run(parsed.data, served.context);
385
+ const result = await command.run(parsed.data, { ...served.context, texts: served.texts });
384
386
  keepProblems(served, result);
385
387
  sendJson(response, 200, isSetup(result) ? { ...result, left: result.questions.filter((question) => served.left.has(question.name) && question.value === undefined && question.items === undefined).map((question) => question.name) } : result);
386
388
  }
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { spawn } from "node:child_process";
4
+ import { join } from "node:path";
4
5
  import { z } from "zod";
5
6
  import { findCampaign, hasCharacterAgent, readTextSetting, refreshHostFiles } from "../campaign/index.js";
6
7
  import { commands } from "../commands/index.js";
@@ -134,7 +135,8 @@ export async function startMcpServer() {
134
135
  };
135
136
  // The systems' code, loaded once for the session, as the engine's own: a system changed since needs the server started again (D-448).
136
137
  context.systemCode = await loadSystemCode(context.systemFolders);
137
- const session = new SessionStore({ systemFolders: context.systemFolders });
138
+ // The game systems, and what this computer translated of them, written only through the session (D-539).
139
+ const session = new SessionStore({ systemFolders: [...context.systemFolders, ...(context.home === undefined ? [] : [join(context.home, "systems")])] });
138
140
  const served = { ...context, files: session };
139
141
  server = createMcpServer(served, process.env, dashboardOpener(served, session).open);
140
142
  // The extensions' tools are there in the first list the host asks for.
@@ -4,6 +4,7 @@ import { fieldKinds } from "../core/field-kind.js";
4
4
  import { formulaOf, readFormulas } from "../core/formula.js";
5
5
  import { frozen } from "../core/frozen.js";
6
6
  import { readParts } from "../core/instruction-parts.js";
7
+ import { codeAndBase } from "../core/language.js";
7
8
  import { lengthHelp, readLength, readSpeed, speedHelp } from "../core/length.js";
8
9
  import { declaredWidgets, packagePartsIssues, packagePartsShape } from "../core/package-declarations.js";
9
10
  import { files } from "../core/store.js";
@@ -105,7 +106,7 @@ export function withSettings(system, valueOf) {
105
106
  */
106
107
  export function rollName(system, dice, language) {
107
108
  const names = system.rollNames[plainRoll(dice)];
108
- return names === undefined ? undefined : (names[language] ?? names[language.split("-")[0]] ?? names[system.language]);
109
+ return names === undefined ? undefined : ([language, ...codeAndBase(language).slice(1)].map((code) => names[code]).find((name) => name !== undefined) ?? names[system.language]);
109
110
  }
110
111
  /** The systems installed in these folders, nearest folder first: each folder in them with a system.yaml. A name found twice is the nearest one. */
111
112
  export function installedSystems(folders) {
@@ -3,6 +3,7 @@
3
3
  import { existsSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { z } from "zod";
6
+ import { codeAndBase } from "../core/language.js";
6
7
  import { readYamlValues } from "../core/yaml-file.js";
7
8
  const named = z.record(z.string().min(1), z.string().min(1));
8
9
  const wordsSchema = z.object({ groups: named.optional(), fields: named.optional(), words: named.optional(), names: named.optional(), headline: z.string().min(1).optional() }, {
@@ -10,7 +11,7 @@ const wordsSchema = z.object({ groups: named.optional(), fields: named.optional(
10
11
  }).strict();
11
12
  /** The words of the system in this folder for a language, or for its base language (pt for pt-BR); undefined when the system has none in it. */
12
13
  export function systemWords(folder, language) {
13
- const file = [language, language.split("-")[0]].map((code) => join(folder, "words", `${code.toLowerCase()}.yaml`)).find((path) => existsSync(path));
14
+ const file = codeAndBase(language).map((code) => join(folder, "words", `${code}.yaml`)).find((path) => existsSync(path));
14
15
  if (file === undefined) {
15
16
  return undefined;
16
17
  }
@@ -161,7 +161,7 @@ function inPlay(folder) {
161
161
  }
162
162
  /** The dashboard of a test campaign, with a page open on it that the server has heard from, so that questions go to the page. */
163
163
  async function testDashboard(context) {
164
- const session = new SessionStore({ systemFolders: context.systemFolders, watchFolder: () => ({ close: () => undefined }) });
164
+ const session = new SessionStore({ systemFolders: [...(context.systemFolders ?? []), ...(context.home === undefined ? [] : [join(context.home, "systems")])], watchFolder: () => ({ close: () => undefined }) });
165
165
  const dashboard = await startDashboard({ ...context, files: session }, session, { ports: [0], page: context.folder });
166
166
  if (dashboard === undefined) {
167
167
  session.close();
@@ -3,7 +3,7 @@
3
3
  The story is on. Besides the tools above:
4
4
 
5
5
  - `move`: whenever someone or something goes somewhere, before you narrate it: the party (a journey: `travel`), a person who leaves, whoever climbs into a cart or gets out of it to act, an item given or taken.
6
- - `advance`: whenever time passes in the story, in a scene too, before you narrate it: once for a stretch of the story, not for each gesture. When it stops at an event, do as it says, and write the traces where they will be found.
6
+ - `advance`: whenever time passes in the story, in a scene too, before you narrate it: once for a stretch of the story, not for each gesture. When it stops at an event, do as it says, and write the traces where they will be found. A rest the game system has a recipe for, whenever the characters take it: its hours with `advance`, then `change` with the recipe.
7
7
  - `scene`: open one when a scene of any kind starts, not only a fight, with the type it is, and close it when it ends: a chase, a heist, a ritual or a race is a challenge; a deal that matters, social. Whoever the character does not know by name comes in with `seen`, two or three words of what they see, until `reveal` gives the name.
8
8
  - `effect`: every condition or effect on someone (frightened, a curse, a form), how long it lasts and who keeps it alive; it ends by itself.
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -44,7 +44,7 @@
44
44
  "docs": "node --experimental-strip-types --input-type=module -e \"import { writeFileSync } from 'node:fs'; import { commands } from './src/commands/index.ts'; import { commandReference } from './src/core/command-reference.ts'; writeFileSync('docs/commands.md', commandReference(commands));\""
45
45
  },
46
46
  "engines": {
47
- "node": ">=22.4"
47
+ "node": ">=24"
48
48
  },
49
49
  "keywords": [
50
50
  "rpg",
@@ -73,7 +73,7 @@
73
73
  "homepage": "https://github.com/stefanocaronia/rpg-engine#readme",
74
74
  "devDependencies": {
75
75
  "@stylistic/eslint-plugin": "^5.10.0",
76
- "@types/node": "^22.20.4",
76
+ "@types/node": "^24.19.2",
77
77
  "@types/three": "^0.187.0",
78
78
  "@typescript-eslint/parser": "^8.71.0",
79
79
  "betasim": "git+https://github.com/stefanocaronia/betasim.git",
@@ -90,7 +90,7 @@
90
90
  "fflate": "^0.8.2",
91
91
  "preact": "^11.2.0",
92
92
  "three": "^0.187.0",
93
- "unpdf": "1.8.1",
93
+ "unpdf": "2.1.0",
94
94
  "yaml": "^2.9.1",
95
95
  "zod": "^4.6.5"
96
96
  }