rpg-engine 0.10.0 → 0.12.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 (131) hide show
  1. package/README.md +1 -1
  2. package/dist/adventures/placement.js +4 -0
  3. package/dist/campaign/find-campaign.js +18 -0
  4. package/dist/campaign/host-files.js +8 -6
  5. package/dist/campaign/index.d.ts +1 -1
  6. package/dist/campaign/index.js +1 -1
  7. package/dist/campaign/settings.d.ts +2 -0
  8. package/dist/campaign/settings.js +12 -5
  9. package/dist/commands/advance.js +1 -1
  10. package/dist/commands/ask.js +1 -1
  11. package/dist/commands/config.js +21 -32
  12. package/dist/commands/import/import.js +1 -1
  13. package/dist/commands/instructions.js +1 -1
  14. package/dist/commands/mode.js +1 -1
  15. package/dist/commands/mood.js +2 -3
  16. package/dist/commands/move.js +1 -1
  17. package/dist/commands/package.js +2 -2
  18. package/dist/commands/reveal.js +1 -1
  19. package/dist/commands/roll/roll.js +6 -12
  20. package/dist/commands/rules.js +0 -1
  21. package/dist/commands/scene.js +6 -8
  22. package/dist/commands/shared/adventures.js +1 -1
  23. package/dist/commands/shared/images.js +3 -1
  24. package/dist/commands/shared/knowledge.d.ts +8 -0
  25. package/dist/commands/shared/knowledge.js +41 -18
  26. package/dist/commands/shared/mode.d.ts +7 -4
  27. package/dist/commands/shared/mode.js +28 -15
  28. package/dist/commands/shared/packages/code.js +13 -2
  29. package/dist/commands/shared/page-words.d.ts +2 -0
  30. package/dist/commands/shared/page-words.js +13 -0
  31. package/dist/commands/shared/sheet.d.ts +3 -2
  32. package/dist/commands/shared/sheet.js +8 -5
  33. package/dist/commands/show.js +1 -1
  34. package/dist/commands/status.js +9 -5
  35. package/dist/commands/view/place.js +9 -3
  36. package/dist/commands/write/write.js +4 -3
  37. package/dist/core/archive-paths.js +1 -1
  38. package/dist/core/package-api.d.ts +1 -1
  39. package/dist/core/package-declarations.d.ts +3 -3
  40. package/dist/core/package-declarations.js +3 -3
  41. package/dist/core/store.d.ts +4 -0
  42. package/dist/core/store.js +20 -1
  43. package/dist/dashboard/app.js +8 -8
  44. package/dist/dashboard/asked.js +2 -2
  45. package/dist/dashboard/dice/throw.js +2 -1
  46. package/dist/dashboard/dice/tray.js +1 -1
  47. package/dist/dashboard/guide/ar.md +13 -13
  48. package/dist/dashboard/guide/cs.md +11 -11
  49. package/dist/dashboard/guide/da.md +12 -12
  50. package/dist/dashboard/guide/de.md +11 -11
  51. package/dist/dashboard/guide/el.md +13 -13
  52. package/dist/dashboard/guide/en.md +2 -2
  53. package/dist/dashboard/guide/es.md +12 -12
  54. package/dist/dashboard/guide/fi.md +15 -15
  55. package/dist/dashboard/guide/fr.md +11 -11
  56. package/dist/dashboard/guide/he.md +10 -10
  57. package/dist/dashboard/guide/hi.md +15 -15
  58. package/dist/dashboard/guide/hu.md +12 -12
  59. package/dist/dashboard/guide/is.md +10 -10
  60. package/dist/dashboard/guide/it.md +3 -3
  61. package/dist/dashboard/guide/ja.md +11 -11
  62. package/dist/dashboard/guide/ko.md +14 -14
  63. package/dist/dashboard/guide/nb.md +12 -12
  64. package/dist/dashboard/guide/nl.md +13 -13
  65. package/dist/dashboard/guide/pl.md +12 -12
  66. package/dist/dashboard/guide/pt.md +9 -9
  67. package/dist/dashboard/guide/ro.md +12 -12
  68. package/dist/dashboard/guide/ru.md +11 -11
  69. package/dist/dashboard/guide/sv.md +11 -11
  70. package/dist/dashboard/guide/tr.md +14 -14
  71. package/dist/dashboard/guide/uk.md +11 -11
  72. package/dist/dashboard/guide/zh.md +13 -13
  73. package/dist/dashboard/i18n/ar.json +1 -0
  74. package/dist/dashboard/i18n/cs.json +1 -0
  75. package/dist/dashboard/i18n/da.json +1 -0
  76. package/dist/dashboard/i18n/de.json +1 -0
  77. package/dist/dashboard/i18n/el.json +1 -0
  78. package/dist/dashboard/i18n/es.json +1 -0
  79. package/dist/dashboard/i18n/fi.json +1 -0
  80. package/dist/dashboard/i18n/fr.json +1 -0
  81. package/dist/dashboard/i18n/he.json +1 -0
  82. package/dist/dashboard/i18n/hi.json +1 -0
  83. package/dist/dashboard/i18n/hu.json +1 -0
  84. package/dist/dashboard/i18n/is.json +1 -0
  85. package/dist/dashboard/i18n/it.json +1 -0
  86. package/dist/dashboard/i18n/ja.json +1 -0
  87. package/dist/dashboard/i18n/ko.json +1 -0
  88. package/dist/dashboard/i18n/nb.json +1 -0
  89. package/dist/dashboard/i18n/nl.json +1 -0
  90. package/dist/dashboard/i18n/pl.json +1 -0
  91. package/dist/dashboard/i18n/pt.json +1 -0
  92. package/dist/dashboard/i18n/ro.json +1 -0
  93. package/dist/dashboard/i18n/ru.json +1 -0
  94. package/dist/dashboard/i18n/sv.json +1 -0
  95. package/dist/dashboard/i18n/tr.json +1 -0
  96. package/dist/dashboard/i18n/uk.json +1 -0
  97. package/dist/dashboard/i18n/zh.json +1 -0
  98. package/dist/dashboard/journal.js +1 -1
  99. package/dist/dashboard/packages/packages.js +5 -5
  100. package/dist/dashboard/packages/widgets.js +1 -1
  101. package/dist/dashboard/settings.js +2 -2
  102. package/dist/dashboard/setup.js +1 -1
  103. package/dist/dashboard/world/lore.js +1 -1
  104. package/dist/dashboard/world/world.js +1 -1
  105. package/dist/dice/index.d.ts +1 -1
  106. package/dist/dice/oracle.d.ts +5 -3
  107. package/dist/dice/oracle.js +7 -6
  108. package/dist/helpers/codex.js +1 -1
  109. package/dist/packages/npm.js +13 -2
  110. package/dist/pages/index.d.ts +1 -1
  111. package/dist/pages/index.js +1 -1
  112. package/dist/pages/markdown.d.ts +2 -0
  113. package/dist/pages/markdown.js +21 -0
  114. package/dist/pages/world.js +4 -0
  115. package/dist/server/dashboard/files.js +3 -3
  116. package/dist/server/dashboard/index.js +8 -4
  117. package/dist/server/mcp.d.ts +3 -1
  118. package/dist/server/mcp.js +20 -5
  119. package/dist/systems/game-system.d.ts +2 -0
  120. package/dist/systems/game-system.js +2 -0
  121. package/instructions/adventure.md +1 -1
  122. package/instructions/combat.md +1 -1
  123. package/instructions/core.md +2 -2
  124. package/instructions/import.md +1 -0
  125. package/instructions/session-zero.md +1 -1
  126. package/instructions/session.md +1 -1
  127. package/instructions/setup.md +1 -1
  128. package/package.json +10 -10
  129. package/systems/free/instructions/outcomes-rolled.md +1 -1
  130. package/systems/free/instructions/outcomes-tossed.md +1 -1
  131. package/systems/free/instructions/play.md +1 -2
package/README.md CHANGED
@@ -75,7 +75,7 @@ RPG Engine is an MCP server and a command line, `rpg`, made from the same comman
75
75
 
76
76
  A campaign is a folder of markdown pages with `[[links]]`, the format of Obsidian, with its settings, its state, a log of every change and its saves. It holds the secrets of your story: you never need to open it.
77
77
 
78
- RPG Engine stays in that folder: it reads and writes the game only there, and never touches your other files. Outside it, it keeps only a data folder of its own (the dashboard's translations, and Codex or Claude Code if you let it install them) and temporary folders while a picture is drawn. The master plays through RPG Engine's tools; anything else your agent wants to do on your computer, it asks you first.
78
+ RPG Engine stays in that folder: it reads and writes the game only there, and never touches your other files. Outside it, it keeps only a data folder of its own (the dashboard's translations, and Codex or Claude Code if you let it install them) and temporary folders while a picture is drawn. The master plays through RPG Engine's tools; anything else your agent wants to do on your computer, it asks you first. A game system or an extension is code, as any npm package is: one that is not ours runs on your computer with your permissions, and RPG Engine installs it only with your yes, in a form of your agent or a window of your computer. Say yes only to packages whose authors you trust.
79
79
 
80
80
  For developers: [the architecture](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/architecture.md), [the commands](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/commands.md), [game systems](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/game-systems.md), [extensions](https://github.com/stefanocaronia/rpg-engine/blob/main/docs/extensions.md) and [the guide for development agents](https://github.com/stefanocaronia/rpg-engine/blob/main/AGENTS.md).
81
81
 
@@ -5,6 +5,10 @@ export function adventureFolderName(title) {
5
5
  if (name === "" || isReservedName(name)) {
6
6
  throw new Error(`The title ${title} gives no name a folder can have: give the adventure another title. Nothing changed.`);
7
7
  }
8
+ // As a page's name, so that the paths of its pages stay within what Windows writes.
9
+ if (name.length > 120) {
10
+ throw new Error(`The title ${title.slice(0, 40)}… is longer than 120 characters, too long for a folder's name: give the adventure a shorter title, as the title of its adventure.yaml. Nothing changed.`);
11
+ }
8
12
  return name;
9
13
  }
10
14
  /** Where a file of the adventure goes in the campaign (ADV-3): pages under their type's folder, the rest under a folder of the adventure's own. */
@@ -22,7 +22,25 @@ export function requireCampaign(folder) {
22
22
  if (root === undefined) {
23
23
  throw new Error(`There is no campaign here: no ${campaignFileName} in ${resolve(folder)} or in the folders above it. Create one with the init command, or work from inside a campaign folder.`);
24
24
  }
25
+ refuseLinksOut(root);
25
26
  // The session of the MCP server watches the campaign from the first call that finds it (D-193).
26
27
  files().track(root);
27
28
  return root;
28
29
  }
30
+ // The folders the engine writes in: a link among them, a junction that came with a folder someone else made, would carry its writes outside the campaign. A file
31
+ // that is a link the store refuses as it writes it.
32
+ const writtenFolders = ["world", "images", "rules", "sessions", ".saves", "exports", ".player", ".imports", ".claude", ".codex"];
33
+ /** Throws when a folder the engine writes in, or one in it two levels deep, is a link: a symbolic link or a junction. */
34
+ function refuseLinksOut(root) {
35
+ const store = files();
36
+ const folders = writtenFolders.map((name) => join(root, name));
37
+ const inside = (folder) => [
38
+ ...store.links(folder).map((name) => join(folder, name)),
39
+ ...store.entries(folder).filter((entry) => entry.isFolder).map((entry) => join(folder, entry.name)),
40
+ ];
41
+ const types = folders.flatMap(inside);
42
+ const linked = [...folders, ...types, ...types.flatMap(inside)].find((path) => store.isLink(path));
43
+ if (linked !== undefined) {
44
+ throw new Error(`${linked} is a link to somewhere else, and what the engine writes there would leave the campaign: replace it with a real folder, with what it holds copied in.`);
45
+ }
46
+ }
@@ -168,14 +168,16 @@ function claudeSettingsFile(root, effort = chosenEffort(root)) {
168
168
  const bellHook = { type: "command", command: "rpg --listen", asyncRewake: true, timeout: 86_400 };
169
169
  /**
170
170
  * Codex's settings for the campaign, read when the player trusts the folder: the rpg server, its tools approved and its calls waiting for the player's click
171
- * as long as the server does (D-412), with Codex's own home, where its queue takes the player's sentences (D-495), and its memories off; a table already
172
- * written is the player's, and stays. The effort the player chose (D-462) is a key
173
- * of the top, before the first table, where Codex reads it; under a table it would belong to that table, and be ignored.
171
+ * as long as the server does (D-412), with Codex's own home, where its queue takes the player's sentences (D-495), its memories and the master's reasoning
172
+ * off; a table already written is the player's, and stays. The effort the player chose (D-462) is a key of the top, before the first table, where Codex
173
+ * reads it; under a table it would belong to that table, and be ignored.
174
174
  */
175
175
  function codexConfigFile(root, platform, effort = chosenEffort(root)) {
176
176
  const path = join(root, ".codex", "config.toml");
177
177
  const before = files().fresh(path) ?? "";
178
- const text = effort === undefined ? before : withTopKey(before, "model_reasoning_effort", effort === "app" ? undefined : effort);
178
+ // The master's reasoning stays out of the player's sight (T-176); a value of the player's own stays.
179
+ const hidden = /^\s*"?hide_agent_reasoning"?\s*=/m.test(before) ? before : withTopKey(before, "hide_agent_reasoning", "true");
180
+ const text = effort === undefined ? hidden : withTopKey(hidden, "model_reasoning_effort", effort === "app" ? undefined : JSON.stringify(effort));
179
181
  const server = rpgServer(platform);
180
182
  const tables = [
181
183
  ["mcp_servers.rpg", `command = ${JSON.stringify(server.command)}\nargs = [${server.args.map((arg) => JSON.stringify(arg)).join(", ")}]\ntool_timeout_sec = 1800\ndefault_tools_approval_mode = "approve"\nenv_vars = ["CODEX_HOME"]`],
@@ -187,7 +189,7 @@ function codexConfigFile(root, platform, effort = chosenEffort(root)) {
187
189
  return missing.length === 0 && text === before ? undefined : { path, text: `${parts.join("\n\n")}\n` };
188
190
  }
189
191
  /**
190
- * A TOML text with a key of its top set to a value, before the first table, in place of the one there, quoted or not; without a value, the key taken away.
192
+ * A TOML text with a key of its top set to a value written as TOML, before the first table, in place of the one there, quoted or not; without a value, the key taken away.
191
193
  * As it is when nothing changes.
192
194
  */
193
195
  function withTopKey(text, key, value) {
@@ -198,7 +200,7 @@ function withTopKey(text, key, value) {
198
200
  const keyLine = new RegExp(`^\\s*"?${key}"?\\s*=`);
199
201
  const top = (firstTable === -1 ? lines : lines.slice(0, firstTable)).filter((line) => !keyLine.test(line));
200
202
  const rest = firstTable === -1 ? [] : lines.slice(firstTable);
201
- const head = [...(value === undefined ? [] : [`${key} = ${JSON.stringify(value)}`]), ...top].join("\n").trimEnd();
203
+ const head = [...(value === undefined ? [] : [`${key} = ${value}`]), ...top].join("\n").trimEnd();
202
204
  const joined = [head, rest.join("\n")].filter((part) => part.trim() !== "").join("\n\n");
203
205
  return joined.trimEnd() === plain.trimEnd() ? text : joined;
204
206
  }
@@ -1,5 +1,5 @@
1
1
  export { createCampaign } from "./create-campaign.ts";
2
2
  export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.ts";
3
3
  export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.ts";
4
- export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, type CountedByGame, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
4
+ export { type CampaignSettings, changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, type CountedByGame, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingDescription, settingMeaning, type SettingName, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.ts";
5
5
  export { type CampaignState, changeState, changeStateAt, readState, readStateValues } from "./state.ts";
@@ -2,5 +2,5 @@
2
2
  export { createCampaign } from "./create-campaign.js";
3
3
  export { campaignFileName, findCampaign, houseRulesFolderName, requireCampaign } from "./find-campaign.js";
4
4
  export { hasCharacterAgent, hostFileNames, refreshHostFiles, writeEffortFiles } from "./host-files.js";
5
- export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
5
+ export { changeExtensions, changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, checkSettings, clearSetting, closedSettings, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, missingSettings, pictureWays, preparations, proseWays, readCampaignData, readListSetting, readOneSetting, readSettings, readTextSetting, rigors, saveModes, settingDescription, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unansweredSettings, unitSystems, voiceWays, } from "./settings.js";
6
6
  export { changeState, changeStateAt, readState, readStateValues } from "./state.js";
@@ -19,6 +19,8 @@ export interface CountedByGame {
19
19
  * or a value it does not take.
20
20
  */
21
21
  export declare function settingMeaning(name: string, value: unknown, counted?: CountedByGame): string | undefined;
22
+ /** What a setting of the engine that takes one of some values is, and those values, as config gives it for that setting alone; undefined for any other. */
23
+ export declare function settingDescription(name: string): string | undefined;
22
24
  export type CampaignSettings = z.infer<typeof settingsSchema>;
23
25
  export type SettingName = keyof typeof settingsSchema.shape;
24
26
  export declare function readSettings(root: string): CampaignSettings;
@@ -19,15 +19,15 @@ export const rigors = ["smooth", "rules", "simulation"];
19
19
  const difficultyMeanings = {
20
20
  story: "fights low, yet each asks one choice that counts; the plain approach wins at a small cost, the risk falling on goals and allies; foes naive, ignoring the place, quick to flee; "
21
21
  + "clues obvious, four or more; resources plentiful; random encounters rare; threat clocks slow: one of them a step every other day; you may soften your own rolls; take-backs granted whenever asked",
22
- easy: "fights low to moderate; the plain approach wins at a cost; foes with simple tactics, using the plainest feature of the place; three clues or more; resources generous; "
22
+ easy: "fights low to moderate; the plain approach wins at a cost; foes with simple tactics, using the plainest feature of the place; clues plain; resources generous; "
23
23
  + "random encounters rare; threat clocks slow: one of them a step every other day; small take-backs granted gladly",
24
- normal: "fights moderate to high; two to four between full rests, with a reason not to rest; the plain approach wins at a real cost, a good choice cheaply; "
25
- + "foes with sensible tactics, using the place, normal morale; three clues to every conclusion; resources standard (treasure, supplies, prices); random encounters normal; "
24
+ normal: "fights moderate to high; two to four between full rests; the plain approach wins at a real cost, a good choice cheaply; "
25
+ + "foes with sensible tactics, using the place, normal morale; resources standard (treasure, supplies, prices); random encounters normal; "
26
26
  + "threat clocks at their pace: one of them a step each day; a take-back now and then, when little hangs on it",
27
- hard: "fights high and beyond; the plain approach may lose, a good choice wins at a cost; foes smart (focus, control), taking the place first, tenacious; three subtle clues; "
27
+ hard: "fights high and beyond; the plain approach may lose, a good choice wins at a cost; foes smart (focus, control), taking the place first, tenacious; clues subtle; "
28
28
  + "resources scarce; random encounters frequent; threat clocks fast: each of them a step each day; take-backs rare",
29
29
  brutal: "fights far beyond high; the plain approach loses, only good choices win; foes optimized (prepared ground, retreats, ambushes, finishing the fallen), fanatical; "
30
- + "three subtle clues; resources very scarce; random encounters frequent; threat clocks fast: each of them a step each day; rests at their harshest; no take-backs",
30
+ + "clues subtle; resources very scarce; random encounters frequent; threat clocks fast: each of them a step each day; rests at their harshest; no take-backs",
31
31
  };
32
32
  /** What each rigor means in play (D-42, D-263): what the master counts, which status and config give for the chosen one. */
33
33
  const rigorMeanings = {
@@ -47,6 +47,13 @@ export function settingMeaning(name, value, counted) {
47
47
  const own = Object.hasOwn(meanings, name) ? meanings[name] : undefined;
48
48
  return typeof value === "string" && own !== undefined && Object.hasOwn(own, value) ? own[value] : undefined;
49
49
  }
50
+ /** What a setting of the engine that takes one of some values is, and those values, as config gives it for that setting alone; undefined for any other. */
51
+ export function settingDescription(name) {
52
+ const shape = settingsSchema.shape;
53
+ const field = Object.hasOwn(shape, name) ? shape[name] : undefined;
54
+ const inner = field instanceof z.ZodOptional ? field.unwrap() : field;
55
+ return inner instanceof z.ZodEnum ? field?.description : undefined;
56
+ }
50
57
  export function readSettings(root) {
51
58
  return validateSettings(readYamlValues(join(root, campaignFileName), settingsHold));
52
59
  }
@@ -12,7 +12,7 @@ import { newDatedLogEntry, presentDate } from "./shared/time.js";
12
12
  import { campaignWorld } from "./shared/world.js";
13
13
  export const advance = defineCommand({
14
14
  name: "advance",
15
- description: "Let time pass in the story, whenever it does, before you narrate it: by a duration or to a later game date. "
15
+ description: "Let time pass in the story: by a duration or to a later game date. "
16
16
  + "At the first scene, set the date the game starts on with to, at the scene's hour. Time never goes back. "
17
17
  + "It stops at the first planned event that comes due and says how to play it; on a new day, it lists the events' clocks to move. "
18
18
  + 'Example: by 8h, why "a night at the inn".',
@@ -56,7 +56,7 @@ export const ask = defineCommand({
56
56
  + "For a roll: the question says what is at stake either way, in about 100 characters (apps may cut it); give the checks that fit, each with its dice, "
57
57
  + "naming the sheet's numbers by their fields as roll does: the engine works them out, and only then the player's sheet lights that row; the player may also change their mind. "
58
58
  + "In a fight, each roll the player's character makes is its own ask, in the order the game's rules give them. "
59
- + "For a choice the rules or the story force (a reaction, a fork): give the answers. Never to offer actions, which are the player's to say, and never for hidden rolls. "
59
+ + "For a choice the rules or the story force (a reaction, a fork): give the answers; never to offer actions, which are the player's to say. "
60
60
  + "square, without options, once the player says their character moves on the map of its place but not to which square: the engine moves them to the square the player touches and gives you the way. "
61
61
  + "recipe, without options, when change with a rest's recipe says so: the player spends their character's dice one at a time, and you get what they gave. "
62
62
  + "toss, without options, for one to three coins the player tosses, as roll's toss: the engine tosses them at the click, logs them as the player's roll, and gives you the faces. "
@@ -1,7 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { parse, stringify } from "yaml";
3
3
  import { z } from "zod";
4
- import { changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, pictureWays, preparations, proseWays, readCampaignData, readSettings, readTextSetting, refreshHostFiles, requireCampaign, rigors, saveModes, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unitSystems, voiceWays, writeEffortFiles, } from "../campaign/index.js";
4
+ import { changeListSetting, changeListSettingToNone, changeMapSetting, changeOtherSetting, changeSetting, checkSettingName, clearSetting, companionWays, diceWays, difficulties, efforts, entrySettingNames, lethalities, listSettingNames, mapSettingNames, masterRollWays, mentorWays, pictureWays, preparations, proseWays, readCampaignData, readSettings, readTextSetting, refreshHostFiles, requireCampaign, rigors, saveModes, settingDescription, settingMeaning, settingNames, setupSettingNames, storyWays, styleTextLengths, unitSystems, voiceWays, writeEffortFiles, } from "../campaign/index.js";
5
5
  import { engineSystemsFolder } from "../core/context.js";
6
6
  import { appendLogEntry } from "../core/log.js";
7
7
  import { defineCommand } from "../core/registry.js";
@@ -32,33 +32,17 @@ const counterShape = 'bulwark-dice: {max: "4 * has(features, Bulwark)"}';
32
32
  export const config = defineCommand({
33
33
  name: "config",
34
34
  description: "Show or change the campaign settings. "
35
- + "Without a setting it shows them all and which are missing; with a setting and a value it changes that one. "
36
- + "Use it at the start of a campaign, to learn what to ask the player, and whenever the player changes a setting. "
37
- + "system: one of the installed game systems, listed while it is missing; fixed once there is a player character. difficulty, how hard the world plays: story, easy, normal, hard, brutal. "
38
- + "lethality, what a fall means: narrative (the character never dies), epic (only when it matters), dice (the dice decide). "
39
- + "saves, when the game may go back: permadeath (never, only to the start, the campaign starting over), checkpoint (to the last end of a scene, once the player character dies), free (to any save, and saves when the player asks). "
40
- + "rigor, how closely travel, fatigue, food and the like follow the rules: smooth (you gloss over them), rules (as written), simulation (beyond them). "
41
- + "dice, who rolls the player character's dice: digital (rpg) or physical (the player, who tells you the values). units: metric or imperial. "
42
- + "master-rolls, your rolls for foes and NPCs: behind the screen (roll hides them, unset too: tell only the outcome) or in view; the party's are always shown. "
43
- + "voices, who voices the characters where your app has subagents: master (you, always), auto (a subagent at key moments, as you choose), "
44
- + "important (always a subagent for the companions and the characters with kind main), always (always a subagent); unset, auto. "
45
- + "companions: none, made with the player or made by the master in session zero, or met in play. "
46
- + "Without a written world: premise (the genre, the tone, a few elements of the world and what the player enjoys most in a game, such as fights, mysteries, talk or exploring, in the player's words) and preparation (on the fly or all at the start). "
47
- + "lines (what never appears in the game) and veils (what happens only off screen) change with add and remove, or value none when the player wants none; when the player signals stop, add that content to lines. "
48
- + "mentor, how much you teach the game, out of the story: off (the story alone, answering what the player asks between brackets), "
49
- + "hints (a tip before choices that matter and when a rule slips by), tutorial (each mechanic explained the first time, a roll's whole sum, a debrief after fights). "
50
- + "learned: the mechanics you explained, by their names in the system's language. "
51
- + "How you write and build what you invent, as the player asks: prose (plain, literary, pulp, wry), story (situations, arcs, episodes, mystery), author (one whose way of writing you take), "
52
- + "style (the player's own words on how you write); none takes away an author or a style. "
53
- + "table: what you promise the player about how you play, in the words you said. "
54
- + "precedents: each ruling you made without the text, the name of the rule in the system's language first, then what you said, such as 'Poisoned: …'. "
55
- + "library: the player's own books, folders or files by their full path, which rules searches after the system: added once to this computer, with the player's yes "
56
- + "in a window of their computer, then turned on in each campaign with add and off with remove; remove with computer takes one off this computer; "
57
- + "text, or PDFs whose text can be selected, read best: a scan is read from its pictures, on Windows only, slowly. "
58
- + 'coins, for a game with money whose system does not give them: each coin with its value in the smallest coin, other names after a slash, "rare" for a coin never given as change; totals count in the first. '
59
- + "widgets: where the dashboard shows the extensions' widgets, which the player arranges in its Settings, such as value 'weather.today: side' (top, side, scene, sheet, world, journal or off); remove gives one back its extension's place. "
60
- + "The game system may add settings of its own: config lists them with what each value means; ruleset, the version of its rules, is the player's: change it only when they ask. "
61
- + "fields, tables, computed, counters and recipes add to the game system what it lacks, or change it as a house rule: the value gives entries by name, written as in system.yaml, "
35
+ + "Without a setting it shows them all and which are missing; with a setting alone, that one with what it is and its values; with a value it changes it. "
36
+ + "Use it in the setup, for each setting status says is missing, and whenever the player changes one. "
37
+ + "system is fixed once there is a player character. lines and veils change with add and remove, or value none when the player wants none. "
38
+ + "effort and ruleset are the player's: change them only when they ask. "
39
+ + "library: the player's own books, folders or files by their full path, added once to this computer with the player's yes in a window of their computer, "
40
+ + "then turned on in each campaign with add and off with remove; remove with computer takes one off this computer. "
41
+ + "precedents: each ruling you made without the text, the rule's name in the system's language first, such as 'Poisoned: …'. learned: the mechanics you explained, by name. "
42
+ + "table: what you promised the player about how you play, in the words you said. "
43
+ + 'coins, when the system gives none: each coin with its value in the smallest coin, other names after a slash, "rare" for one never given as change. '
44
+ + "widgets: where the dashboard shows an extension's widget, such as value 'weather.today: side'; remove gives it back its place. "
45
+ + "fields, tables, computed, counters and recipes add to the game system what it lacks, or change it as a house rule: entries by name, written as in system.yaml, "
62
46
  + "each replacing the system's one of that name (a recipe adds to the system's); remove takes their names. status-line adds fields to the player character's line. "
63
47
  + "A formula with commas goes in quotes; a use's max reads what gives it, so that only who has it has it. "
64
48
  + `Example: setting language, value it; or setting lines, add "spiders"; or setting counters, value '${counterExample}'.`,
@@ -313,6 +297,11 @@ function configure(input, context) {
313
297
  if (input.setting?.trim() === "calendar" && input.value !== undefined) {
314
298
  replaced = [...replaced, ...campaignCalendar(root, context).problems.map((problem) => `${problem.message.replace(/\.$/, "")}: ${problem.fix ?? "fix it"}.`)];
315
299
  }
300
+ // A setting asked alone comes with what it is and its values, which the description leaves to it (T-64).
301
+ const about = input.setting !== undefined && input.value === undefined && !listChange ? settingDescription(checkSettingName(input.setting)) : undefined;
302
+ if (about !== undefined) {
303
+ replaced = [...replaced, `${checkSettingName(input.setting ?? "")}: ${about}.`];
304
+ }
316
305
  const settings = readSettings(root);
317
306
  // Listed all together, what the campaign adds to its system only when it adds something.
318
307
  const added = (name) => campaignDataNames.includes(name);
@@ -332,7 +321,7 @@ function configure(input, context) {
332
321
  ...Object.fromEntries(listed.map((name) => [name, offeredShown(root, context, name, shownValue(root, context, settings, name))])),
333
322
  ...Object.fromEntries(system.map((setting) => [setting.name, systemShownValue(root, context, setting)])),
334
323
  },
335
- note: campaignNote(root, context),
324
+ note: campaignNote(root, context, true),
336
325
  replaced,
337
326
  part,
338
327
  };
@@ -567,7 +556,7 @@ function systemSettingResult(root, context, setting, input) {
567
556
  if (setting.name === rulesetSetting && before !== undefined && comparableText(before) !== comparableText(value.value)) {
568
557
  return {
569
558
  settings: { [setting.name]: systemShownValue(root, context, setting) },
570
- note: campaignNote(root, context),
559
+ note: campaignNote(root, context, true),
571
560
  replaced: [`From now on the campaign plays the rules ${value.value}, in place of ${before}: the pages already written stay as they are.`, ...unofferedLines(root, context)],
572
561
  };
573
562
  }
@@ -575,12 +564,12 @@ function systemSettingResult(root, context, setting, input) {
575
564
  const part = context.actor === "player" || campaignMode(root, campaignWorld(root, context)) !== "play" ? undefined : valuePart(root, context, setting.name, value.value);
576
565
  return {
577
566
  settings: { [setting.name]: systemShownValue(root, context, setting) },
578
- note: campaignNote(root, context),
567
+ note: campaignNote(root, context, true),
579
568
  replaced: unofferedLines(root, context),
580
569
  ...(part === undefined ? {} : { part }),
581
570
  };
582
571
  }
583
- return { settings: { [setting.name]: systemShownValue(root, context, setting) }, note: campaignNote(root, context), replaced: [] };
572
+ return { settings: { [setting.name]: systemShownValue(root, context, setting) }, note: campaignNote(root, context, true), replaced: [] };
584
573
  }
585
574
  /** An engine's setting as config shows it where the game offers only some of its values (DAT-16): the one it plays alone, or missing with those it offers. */
586
575
  function offeredShown(root, context, name, shown) {
@@ -383,7 +383,7 @@ function chatPieceText(state, piece) {
383
383
  `Importing ${state.title} here in the chat, piece ${piece.number} of ${state.pieces}: write its pages with write, and add what it adds to the pages you `
384
384
  + `wrote before, which find shows. A picture marked [picture: name] is the file "${piece.pictures}${sep}name": give it to its page with image. ${then}`,
385
385
  piece.instructions,
386
- piece.text,
386
+ `Piece ${piece.number} of "${state.title}", the document's own text:\n${piece.text}`,
387
387
  ].filter((part) => part !== "").join("\n\n");
388
388
  }
389
389
  // How long an import that nothing runs may stay still before the dashboard says it waits: a runner just started takes a moment to claim it.
@@ -41,7 +41,7 @@ export const instructions = defineCommand({
41
41
  // The dashboard, where the MCP server serves one, so that the master can tell the player how to use it (D-404).
42
42
  context.dashboard === undefined ? "" : dashboardInstructions(context.dashboard),
43
43
  // The opening of an evening, said to the player while the master read the game, reached them (playtest 15).
44
- "Now read where the game stands, writing nothing: your first words to the player are the opening itself.",
44
+ "Now read where the game stands, writing nothing.",
45
45
  ];
46
46
  return { text: parts.filter((part) => part !== "").join("\n\n") };
47
47
  },
@@ -14,7 +14,7 @@ export const mode = defineCommand({
14
14
  name: "mode",
15
15
  description: "Move the campaign to another mode: setup (the settings, out of the game), session zero (the player character and the companions, made in play) or play. "
16
16
  + "It refuses while that mode's checklist is incomplete, saying what is missing; otherwise it gives the new mode's instructions. "
17
- + "Call it when status says nothing is missing and the player confirms; back to session zero to make a new player character. "
17
+ + "Back to session zero to make a new player character. "
18
18
  + 'Example: to "session zero".',
19
19
  group: "game",
20
20
  positionals: ["to"],
@@ -18,10 +18,9 @@ const moodAdvice = {
18
18
  export const mood = defineCommand({
19
19
  name: "mood",
20
20
  description: "Set a mood: yours as the master, which the dashboard's robot shows, or a character's when it changes for a while: the party's show on their sheets, "
21
- + "anyone else's only you see, in status. Set yours when the story's tone turns as the player lives it, and let your voice follow it. "
21
+ + "anyone else's only you see, in status. "
22
22
  + "moment: a reaction to what the player has just seen happen, what a roll decides or a bold choice, a few times a session; the dashboard already reacts to the dice's highs and lows. "
23
- + "Your face never shows what the player does not know yet: no grin before the trap is sprung. "
24
- + "Mirror the player character's mood from how the player plays them, never decide it for them. neutral takes a mood away. "
23
+ + "neutral takes a mood away. "
25
24
  + "Example: master worried; master surprised, moment; Lena afraid.",
26
25
  group: "game",
27
26
  positionals: ["who", "mood"],
@@ -18,7 +18,7 @@ import { newDatedLogEntry } from "./shared/time.js";
18
18
  import { campaignSystem, campaignWorld, missingSystemHint } from "./shared/world.js";
19
19
  export const move = defineCommand({
20
20
  name: "move",
21
- description: "Move characters, items or places into a place, a character's inventory or an item: whenever someone or something goes somewhere, before you narrate it. "
21
+ description: "Move characters, items or places into a place, a character's inventory or an item. "
22
22
  + "Each ends up only there, wherever it was before, and conditions such as party in [[Ossario]] fire. Time does not pass: advance does that. "
23
23
  + "Pieces of a stack go with from and count. Example: page [Ettore, Lena], to Ossario; or page Torch, from Ettore, to Lena, count 3.",
24
24
  group: "game",
@@ -614,8 +614,8 @@ async function playerYes(context, name, pack, local, holds = "", replaces = "")
614
614
  const from = context.actor === "player" ? "the dashboard" : context.host === undefined ? "the command line" : "the chat";
615
615
  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.";
616
616
  const warning = local
617
- ? `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}`
618
- : `Not verified by RPG Engine: ${name}, asked from ${from}. ${can} Install it only if you trust who made it.`;
617
+ ? `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: install it only if you trust who made it.${replaces}`
618
+ : `Not verified by RPG Engine: ${name}, from npm, asked from ${from}. ${can} RPG Engine takes no responsibility for it: install it only if you trust who made it.`;
619
619
  const question = `Install ${name}? ${warning}`;
620
620
  const title = "A package not ours";
621
621
  const answer = context.player === undefined ? "unavailable" : await context.player.choose(question, title, ["Install it, at my risk", "Do not install it"], context.signal);
@@ -13,7 +13,7 @@ import { campaignWorld } from "./shared/world.js";
13
13
  export const reveal = defineCommand({
14
14
  name: "reveal",
15
15
  description: "Record what characters learn: a secret, as Page#Secret, or a whole page they did not know. "
16
- + "Use it as soon as a character learns it. It adds the links to their knows and answers without the text: read a secret with show before you tell it. "
16
+ + "It adds the links to their knows and answers without the text: read a secret with show before you tell it. "
17
17
  + "Example: page [Coppa#Veleno, Varro], to [Ettore, Bruna].",
18
18
  group: "game",
19
19
  positionals: ["page"],
@@ -28,14 +28,8 @@ export const roll = defineCommand({
28
28
  name: "roll",
29
29
  description: "Roll dice and log the roll. "
30
30
  + "Give why and, if it belongs to someone, who; for a roll the player sees, check names it for them, while why stays yours. "
31
- + "When the player rolls physical dice, pass their faces as values. Make it hidden when the player must not see the result; "
32
- + "left out, a roll for a foe or anyone outside the party is hidden or shown as the master-rolls setting says. "
33
- + "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; "
34
- + "use takes one of those instead of the die and logs which roll it replaced. "
35
- + "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; "
36
- + "toss tosses one to three coins, each heads or tails, in any game. "
37
- + "On the player's dashboard a shown roll goes in its list of rolls; tray true throws it in the dice tray too, landing on its faces, false keeps it in the list alone; "
38
- + "left out, coins fly and dice do not. "
31
+ + "With physical dice, pass the player's faces as values. hidden when the player must not see the result; left out, master-rolls decides for who is outside the party. "
32
+ + "Instead of a notation: table, oracle or toss, in any game; keep stores dice for later, use spends one. "
39
33
  + '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?"; '
40
34
  + 'toss 2, why "does the rope hold?", who Lena.',
41
35
  group: "game",
@@ -207,7 +201,7 @@ function answerRoll(input, root, context) {
207
201
  }
208
202
  const physical = input.values !== undefined;
209
203
  const source = input.values ? { values: input.values } : { random: context.random };
210
- const answer = input.table !== undefined ? tableAnswer(root, context, input.table, source) : input.toss !== undefined ? tossAnswer(input.toss, source) : oracleAnswer(input.oracle ?? "", source);
204
+ const answer = input.table !== undefined ? tableAnswer(root, context, input.table, source) : input.toss !== undefined ? tossAnswer(input.toss, source) : oracleAnswer(input.oracle ?? "", source, campaignSystem(root, context)?.oracleYes);
211
205
  // A table or the oracle is the master's own roll, behind the screen as master-rolls says, but for a party member's (D-287); a secret's table is never shown.
212
206
  const masters = input.who === undefined || !ofTheParty(root, context, input.who);
213
207
  const screened = answer.secret || (input.hidden === undefined && !physical && masters && screenUp(root));
@@ -225,10 +219,10 @@ function tableAnswer(root, context, table, source) {
225
219
  const rolled = rollPageTable(root, context, table, source);
226
220
  return { secret: rolled.secret, notation: rolled.die, total: rolled.result, text: rolled.text, dice: rolled.roll.dice, data: { table: rolled.table, row: rolled.row.label } };
227
221
  }
228
- /** The oracle's answer, with its odds and the answer for the log. */
229
- function oracleAnswer(odds, source) {
222
+ /** The oracle's answer, read where the game system says a d100 says yes, with its odds and the answer for the log. */
223
+ function oracleAnswer(odds, source, yesOn) {
230
224
  try {
231
- const asked = askOracle(odds, source);
225
+ const asked = askOracle(odds, source, yesOn);
232
226
  return { secret: false, notation: "d100", total: asked.roll.total, text: asked.text, dice: asked.roll.dice, data: { oracle: asked.odds, odds: asked.chance, answer: `${asked.extreme ? "extreme " : ""}${asked.yes ? "yes" : "no"}` } };
233
227
  }
234
228
  catch (error) {
@@ -18,7 +18,6 @@ const namedSections = 8;
18
18
  export const rules = defineCommand({
19
19
  name: "rules",
20
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. "
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. "
22
21
  + "Give the book's words, such as grappled, cover or falling; a heading, or headings joined by ›, reads that section. "
23
22
  + "It searches the player's own books too, after the system, each excerpt with its book and page: Book › p. 194 reads that page.",
24
23
  group: "game",
@@ -50,14 +50,12 @@ const mostCopies = 50;
50
50
  export const scene = defineCommand({
51
51
  name: "scene",
52
52
  description: "Open, run and close a scene of the story. "
53
- + "open starts one with a title, a type, a place, who is in it and creatures as numbered copies, such as Annegato 1: a copy holds only what changes, the rest is read from the creature. "
54
- + "Whoever of the party is elsewhere moves to the scene's place, except in a travel scene. "
55
- + "add brings in more characters or creatures; leave takes out who goes (fled, fallen, gone); order sets who takes turns, after rolling for it if the game does; next passes the turn; "
56
- + "use marks what one uses of a turn, such as who Ettore, uses attack: the engine counts the uses of a turn the game declares and refuses one too many; "
57
- + "now gives the line the player's dashboard shows: give it at open too, and change it as the scene turns. "
58
- + "In a fight, hostile marks who attacks the party, the moment they show it, and calm takes the mark off one who surrenders, flees or parleys: the player's dashboard shows it. "
59
- + "seen, at open or add, gives what the character sees of those it does not know by name; the player's dashboard calls them so until the character learns the name. "
60
- + "close ends the scene with a summary: the player may read the title and summary. Change a copy's counters with change, as for a page. "
53
+ + "Creatures come as numbered copies, such as Annegato 1: a copy holds only what changes, the rest is read from the creature. "
54
+ + "At open, whoever of the party is elsewhere moves to the scene's place, except in a travel scene. "
55
+ + "order sets who takes turns, after rolling for it if the game does; next passes the turn; use marks what one uses of a turn: the engine counts the uses the game declares and refuses one too many. "
56
+ + "now is the line the player's dashboard shows: give it at open too, and change it as the scene turns. "
57
+ + "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of those it does not know by name; the player's dashboard shows both. "
58
+ + "close ends the scene with a summary the player may read. Change a copy's counters with change, as for a page. "
61
59
  + 'Example: action open, title "Scontro all\'ossario", type combat, creatures {"Annegato": 2}.',
62
60
  group: "game",
63
61
  positionals: ["action"],
@@ -153,7 +153,7 @@ export function exportAdventure(root, context, credits) {
153
153
  ...(start === undefined ? {} : { start }),
154
154
  ...(opening === undefined ? {} : { opening: basename(opening.path, ".md") }),
155
155
  };
156
- const file = join(root, exportsFolderName, `${settings.name.replace(/[\\/:*?"<>|]/g, "").trim()}.adventure.zip`);
156
+ const file = join(root, exportsFolderName, `${settings.name.replace(/[\\/:*?"<>|\u0000-\u001f]/g, "").trim()}.adventure.zip`);
157
157
  files().writeBytes(file, packAdventure(manifest, kept));
158
158
  const adventures = adventuresOfLog(log).map((adventure) => adventure.title);
159
159
  return {
@@ -5,6 +5,7 @@ import { files } from "../../core/store.js";
5
5
  import { findImage, imageFileName } from "../../images/index.js";
6
6
  import { baseChain, isPartyMember, ownField } from "../../pages/index.js";
7
7
  import { systemContentFolders } from "../../systems/index.js";
8
+ import { firstInChat } from "./parts.js";
8
9
  import { campaignSystem } from "./world.js";
9
10
  /**
10
11
  * What the master hears of the places' pictures (D-308, PIC-4): where pictures can be made and the player has not chosen, to ask them once; with new elements, that
@@ -13,7 +14,8 @@ import { campaignSystem } from "./world.js";
13
14
  export function picturesNote(root, context, world, place) {
14
15
  const setting = readSettings(root).pictures;
15
16
  if (setting === undefined) {
16
- const ready = context.pictures?.ready();
17
+ // Asked once in a chat, not at every status and scene (T-64).
18
+ const ready = context.told === undefined || firstInChat(context, "pictures-ask") ? context.pictures?.ready() : undefined;
17
19
  return ready?.ready === true
18
20
  ? `Pictures: this computer can make the pictures of places, quests and those met with the player's ${ready.maker === "Claude" ? "Claude Code" : "Codex"}, which spends their plan: ask them once whether they want one for each new place, quest and one met, only those they ask for, or none; then config pictures (new elements, on request or none).`
19
21
  : undefined;
@@ -38,6 +38,14 @@ export declare function knowsPage(knowledge: Knowledge, page: Page): boolean;
38
38
  * without a name is never known; comments are left out (LNK-2).
39
39
  */
40
40
  export declare function knownText(world: World, knowledge: Knowledge, page: Page): string;
41
+ /**
42
+ * A text as the character may read it (VIEW-3): a link to a page it does not know, or to none, written as its words, so that no name tells the page exists; a link
43
+ * to a secret it has not discovered too, so that the secret's name tells nothing, and to a section that tells it nothing but its title, as one over a secret; a
44
+ * secret written so that the engine does not read it as one, left out.
45
+ */
46
+ export declare function inKnownWords(world: World, knowledge: Knowledge, text: string): string;
47
+ /** Whether the character may read where a link points (VIEW-3): a page it knows, and of it a secret it discovered or a section that tells it more than its title. */
48
+ export declare function readsLink(world: World, knowledge: Knowledge, link: Link): boolean;
41
49
  /** The secrets a page's text shows (VIEW-3) that only some of the player characters discovered, when more than one is played, each by its name and with who (VIEW-12). */
42
50
  export declare function knownSecretsApart(world: World, knowledge: Knowledge, page: Page): {
43
51
  secret: string;
@@ -2,7 +2,7 @@
2
2
  // with more than one player character, what any of them knows, and who (VIEW-12).
3
3
  import { readLog } from "../../core/log.js";
4
4
  import { comparableText } from "../../core/text.js";
5
- import { baseChain, inheritedByBase, introductionText, isPartyMember, isPlayerCharacter, links, locate, pagesWithNameOrAlias, parsePageReference, partContent, playerCharacters, readSection, secretNames, stacksOf, systemPageNamed, textParts, textsIn, withLinksAsWords, withoutComments, } from "../../pages/index.js";
5
+ import { baseChain, inheritedByBase, introductionText, isPartyMember, isPlayerCharacter, links, locate, pagesWithNameOrAlias, parsePageReference, partContent, playerCharacters, readSection, secretNames, stacksOf, systemPageNamed, textParts, textsIn, withLinksAsWords, withoutComments, withoutUnreadSecrets, } from "../../pages/index.js";
6
6
  import { readOpenScene } from "./scene.js";
7
7
  /** The player character: the first living character with role pc, else the first dead one; undefined before there is one. */
8
8
  export function playerCharacter(world) {
@@ -87,6 +87,22 @@ export function knownText(world, knowledge, page) {
87
87
  ].filter((part) => isShown(knowledge, page, part));
88
88
  return inKnownWords(world, knowledge, withoutComments([knownIntroduction(world, knowledge, page), ...parts.map((part) => part.text)].filter((text) => text !== "").join("\n\n")));
89
89
  }
90
+ /**
91
+ * A text as the character may read it (VIEW-3): a link to a page it does not know, or to none, written as its words, so that no name tells the page exists; a link
92
+ * to a secret it has not discovered too, so that the secret's name tells nothing, and to a section that tells it nothing but its title, as one over a secret; a
93
+ * secret written so that the engine does not read it as one, left out.
94
+ */
95
+ export function inKnownWords(world, knowledge, text) {
96
+ return withLinksAsWords(withoutUnreadSecrets(text), (link) => readsLink(world, knowledge, link));
97
+ }
98
+ /** Whether the character may read where a link points (VIEW-3): a page it knows, and of it a secret it discovered or a section that tells it more than its title. */
99
+ export function readsLink(world, knowledge, link) {
100
+ const known = [...pagesWithNameOrAlias(world, link.page), systemPageNamed(world, link.page)].filter((page) => page !== undefined && knowsPage(knowledge, page));
101
+ const wanted = comparableText(link.section ?? "");
102
+ const secrets = wanted === "" ? [] : known.flatMap((page) => secretNames(page.body).filter((name) => comparableText(name) === wanted).map((name) => secretKey(page.name, name)));
103
+ const empty = wanted !== "" && secrets.length === 0 && known.length > 0 && known.every((page) => saysNothing(world, knowledge, page, link.section ?? ""));
104
+ return known.length > 0 && !empty && (secrets.length === 0 || secrets.some((key) => knowledge.secrets.has(key)));
105
+ }
90
106
  /** The secrets a page's text shows (VIEW-3) that only some of the player characters discovered, when more than one is played, each by its name and with who (VIEW-12). */
91
107
  export function knownSecretsApart(world, knowledge, page) {
92
108
  const parts = [...partsOf(page), ...inheritedByBase(world, page).flatMap((group) => group.parts.map((part) => ({ ...part, holder: group.base })))];
@@ -130,20 +146,8 @@ export function playerStory(page) {
130
146
  * from a base, only one it knows, or a secret it discovered. Undefined when it knows none.
131
147
  */
132
148
  export function knownPart(world, knowledge, page, name) {
133
- const wanted = comparableText(name.trim());
134
- for (const holder of [page, ...baseChain(world, page)]) {
135
- const part = partsOf(holder).find((candidate) => comparableText(candidate.name) === wanted);
136
- if (part === undefined) {
137
- continue;
138
- }
139
- if (!isShown(knowledge, page, part)) {
140
- return undefined;
141
- }
142
- const whole = isSecretText(part.text) ? part.text : (readSection(holder.body, part.name) ?? part.text);
143
- const kept = isSecretText(part.text) ? [part] : partsOf({ ...holder, body: whole }).map((inner) => ({ ...inner, holder })).filter((inner) => isShown(knowledge, page, inner));
144
- return inKnownWords(world, knowledge, withoutComments(kept.map((inner) => inner.text).join("\n\n")));
145
- }
146
- return undefined;
149
+ const kept = knownParts(world, knowledge, page, name);
150
+ return kept === undefined ? undefined : inKnownWords(world, knowledge, withoutComments(kept.map((inner) => inner.text).join("\n\n")));
147
151
  }
148
152
  /** Whether a page's own text, not its bases', tells the character something: its introduction, or a section or secret of it the character may read (VIEW-3). */
149
153
  export function writesKnownText(knowledge, page) {
@@ -188,9 +192,28 @@ function foregroundCharacter(root, world, wanted) {
188
192
  const named = (page, name) => name !== undefined && pagesWithNameOrAlias(world, parsePageReference(name).name)[0] === page;
189
193
  return living.find((page) => named(page, scene?.turn)) ?? living.find((page) => (scene?.with ?? []).some((link) => named(page, link))) ?? living[0] ?? players[0];
190
194
  }
191
- /** A text as the character may read it (VIEW-3): a link to a page it does not know, or to none, written as its words, so that no name tells the page exists. */
192
- function inKnownWords(world, knowledge, text) {
193
- return withLinksAsWords(text, (link) => [...pagesWithNameOrAlias(world, link.page), systemPageNamed(world, link.page)].some((page) => page !== undefined && knowsPage(knowledge, page)));
195
+ /** The parts of a page's section or secret by this name that the character may read, as knownPart gives them; undefined when it knows none. */
196
+ function knownParts(world, knowledge, page, name) {
197
+ const wanted = comparableText(name.trim());
198
+ for (const holder of [page, ...baseChain(world, page)]) {
199
+ const part = partsOf(holder).find((candidate) => comparableText(candidate.name) === wanted);
200
+ if (part === undefined) {
201
+ continue;
202
+ }
203
+ if (!isShown(knowledge, page, part)) {
204
+ return undefined;
205
+ }
206
+ const whole = isSecretText(part.text) ? part.text : (readSection(holder.body, part.name) ?? part.text);
207
+ return isSecretText(part.text) ? [part] : partsOf({ ...holder, body: whole }).map((inner) => ({ ...inner, holder })).filter((inner) => isShown(knowledge, page, inner));
208
+ }
209
+ return undefined;
210
+ }
211
+ /** Whether a section the character may read tells it nothing but its title, as a heading over secrets it has not discovered (VIEW-3). */
212
+ function saysNothing(world, knowledge, page, section) {
213
+ const kept = knownParts(world, knowledge, page, section);
214
+ // A section's text begins with its heading; a secret's with its mark, which names it.
215
+ const said = (part) => withoutComments(isSecretText(part.text) ? part.text : part.text.split("\n").slice(1).join("\n")).trim() !== "";
216
+ return kept !== undefined && !kept.some(said);
194
217
  }
195
218
  /** Whether a part shows to the player character: a secret it discovered, or a section of the page or of a base it knows (D-254). */
196
219
  function isShown(knowledge, page, part) {