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.
Files changed (231) hide show
  1. package/README.md +1 -1
  2. package/dist/campaign/settings.d.ts +1 -0
  3. package/dist/campaign/settings.js +6 -5
  4. package/dist/command-line.js +12 -5
  5. package/dist/commands/advance.js +1 -1
  6. package/dist/commands/ask.d.ts +37 -2
  7. package/dist/commands/ask.js +106 -35
  8. package/dist/commands/change.js +28 -17
  9. package/dist/commands/config.d.ts +1 -1
  10. package/dist/commands/config.js +69 -21
  11. package/dist/commands/effect.js +42 -23
  12. package/dist/commands/find.js +1 -1
  13. package/dist/commands/game-adventures.js +2 -2
  14. package/dist/commands/game-catalog.d.ts +13 -0
  15. package/dist/commands/game-catalog.js +26 -2
  16. package/dist/commands/game-checks.js +23 -21
  17. package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
  18. package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
  19. package/dist/commands/game-effects.d.ts +12 -4
  20. package/dist/commands/game-effects.js +21 -13
  21. package/dist/commands/game-examples.d.ts +22 -0
  22. package/dist/commands/game-examples.js +72 -0
  23. package/dist/commands/game-extension-list.d.ts +31 -3
  24. package/dist/commands/game-extension-list.js +94 -6
  25. package/dist/commands/game-images.d.ts +1 -1
  26. package/dist/commands/game-images.js +3 -2
  27. package/dist/commands/game-library.d.ts +3 -0
  28. package/dist/commands/game-library.js +2 -2
  29. package/dist/commands/game-mode.js +1 -1
  30. package/dist/commands/game-package-code.d.ts +87 -0
  31. package/dist/commands/game-package-code.js +648 -0
  32. package/dist/commands/game-package-hooks.d.ts +37 -0
  33. package/dist/commands/game-package-hooks.js +116 -0
  34. package/dist/commands/game-recipes.js +2 -2
  35. package/dist/commands/game-reminders.d.ts +5 -2
  36. package/dist/commands/game-reminders.js +7 -4
  37. package/dist/commands/game-rules.d.ts +4 -1
  38. package/dist/commands/game-rules.js +7 -1
  39. package/dist/commands/game-upkeep.js +3 -3
  40. package/dist/commands/game-view-place.d.ts +8 -20
  41. package/dist/commands/game-view-place.js +16 -35
  42. package/dist/commands/game-widgets.d.ts +42 -8
  43. package/dist/commands/game-widgets.js +182 -31
  44. package/dist/commands/game-world.d.ts +32 -3
  45. package/dist/commands/game-world.js +113 -24
  46. package/dist/commands/image.js +1 -1
  47. package/dist/commands/init.js +2 -2
  48. package/dist/commands/mode.d.ts +1 -1
  49. package/dist/commands/package.d.ts +15 -1
  50. package/dist/commands/package.js +96 -24
  51. package/dist/commands/progression.d.ts +2 -0
  52. package/dist/commands/progression.js +7 -2
  53. package/dist/commands/roll.d.ts +2 -0
  54. package/dist/commands/roll.js +50 -24
  55. package/dist/commands/rules.js +6 -4
  56. package/dist/commands/scene.d.ts +2 -2
  57. package/dist/commands/scene.js +13 -10
  58. package/dist/commands/sheet.js +10 -1
  59. package/dist/commands/status.d.ts +1 -0
  60. package/dist/commands/status.js +14 -4
  61. package/dist/commands/trade.js +6 -4
  62. package/dist/commands/translate.js +2 -2
  63. package/dist/commands/travel.js +1 -1
  64. package/dist/commands/validate.js +2 -2
  65. package/dist/commands/view.d.ts +12 -4
  66. package/dist/commands/view.js +11 -8
  67. package/dist/commands/worked-out.js +11 -5
  68. package/dist/commands/write.d.ts +8 -1
  69. package/dist/commands/write.js +84 -25
  70. package/dist/core/command-reference.js +3 -2
  71. package/dist/core/consents.d.ts +18 -0
  72. package/dist/core/consents.js +93 -0
  73. package/dist/core/context.d.ts +68 -27
  74. package/dist/core/context.js +3 -1
  75. package/dist/core/examples.d.ts +25 -0
  76. package/dist/core/examples.js +19 -0
  77. package/dist/core/files.d.ts +2 -0
  78. package/dist/core/files.js +10 -1
  79. package/dist/core/package-api.d.ts +388 -0
  80. package/dist/core/package-declarations.d.ts +102 -0
  81. package/dist/core/package-declarations.js +81 -0
  82. package/dist/core/registry.d.ts +4 -0
  83. package/dist/core/text.d.ts +5 -0
  84. package/dist/core/text.js +12 -0
  85. package/dist/dashboard/acts.js +31 -24
  86. package/dist/dashboard/address.js +4 -1
  87. package/dist/dashboard/api.js +65 -3
  88. package/dist/dashboard/app.js +222 -98
  89. package/dist/dashboard/ask-card.js +169 -0
  90. package/dist/dashboard/asked-dice.js +57 -0
  91. package/dist/dashboard/dice/tray.js +6 -4
  92. package/dist/dashboard/extension-widgets.js +136 -16
  93. package/dist/dashboard/faces.js +6 -4
  94. package/dist/dashboard/help.js +10 -3
  95. package/dist/dashboard/i18n/ar.json +34 -29
  96. package/dist/dashboard/i18n/cs.json +34 -29
  97. package/dist/dashboard/i18n/da.json +34 -29
  98. package/dist/dashboard/i18n/de.json +34 -29
  99. package/dist/dashboard/i18n/el.json +34 -29
  100. package/dist/dashboard/i18n/es.json +34 -29
  101. package/dist/dashboard/i18n/fi.json +34 -29
  102. package/dist/dashboard/i18n/fr.json +34 -29
  103. package/dist/dashboard/i18n/he.json +34 -29
  104. package/dist/dashboard/i18n/hi.json +34 -29
  105. package/dist/dashboard/i18n/hu.json +34 -29
  106. package/dist/dashboard/i18n/is.json +34 -29
  107. package/dist/dashboard/i18n/it.json +34 -29
  108. package/dist/dashboard/i18n/ja.json +34 -29
  109. package/dist/dashboard/i18n/ko.json +34 -29
  110. package/dist/dashboard/i18n/nb.json +34 -29
  111. package/dist/dashboard/i18n/nl.json +34 -29
  112. package/dist/dashboard/i18n/pl.json +34 -29
  113. package/dist/dashboard/i18n/pt.json +34 -29
  114. package/dist/dashboard/i18n/ro.json +34 -29
  115. package/dist/dashboard/i18n/ru.json +34 -29
  116. package/dist/dashboard/i18n/sv.json +34 -29
  117. package/dist/dashboard/i18n/tr.json +34 -29
  118. package/dist/dashboard/i18n/uk.json +34 -29
  119. package/dist/dashboard/i18n/zh.json +34 -29
  120. package/dist/dashboard/icons.js +4 -1
  121. package/dist/dashboard/kit.js +35 -0
  122. package/dist/dashboard/labels.js +1 -0
  123. package/dist/dashboard/pack-card.js +97 -0
  124. package/dist/dashboard/package-page.js +50 -0
  125. package/dist/dashboard/packages.js +180 -24
  126. package/dist/dashboard/page-code.js +248 -0
  127. package/dist/dashboard/party.js +13 -14
  128. package/dist/dashboard/people.js +4 -0
  129. package/dist/dashboard/person-panel.js +110 -0
  130. package/dist/dashboard/place-map-view.js +11 -6
  131. package/dist/dashboard/rolls.js +2 -2
  132. package/dist/dashboard/scene.js +12 -9
  133. package/dist/dashboard/settings.js +55 -9
  134. package/dist/dashboard/sheet.js +21 -13
  135. package/dist/dashboard/status.js +69 -15
  136. package/dist/dashboard/style.css +859 -574
  137. package/dist/dashboard/top.js +75 -25
  138. package/dist/dashboard/turns.js +34 -13
  139. package/dist/dashboard/widgets.js +9 -2
  140. package/dist/dashboard-server.js +246 -11
  141. package/dist/dice/roll-dice.js +1 -1
  142. package/dist/effects/effect.d.ts +7 -4
  143. package/dist/effects/effect.js +12 -9
  144. package/dist/extensions/engine.d.ts +4 -0
  145. package/dist/extensions/engine.js +74 -0
  146. package/dist/extensions/extension.d.ts +28 -33
  147. package/dist/extensions/extension.js +37 -46
  148. package/dist/extensions/index.d.ts +4 -3
  149. package/dist/extensions/index.js +5 -2
  150. package/dist/extensions/packages.d.ts +14 -0
  151. package/dist/extensions/packages.js +148 -12
  152. package/dist/extensions/words.d.ts +2 -1
  153. package/dist/extensions/words.js +5 -4
  154. package/dist/index.d.ts +1 -3
  155. package/dist/mcp-server.js +52 -15
  156. package/dist/page-words.d.ts +4 -0
  157. package/dist/page-words.js +4 -4
  158. package/dist/page.d.ts +218 -0
  159. package/dist/page.js +2 -0
  160. package/dist/pages/index.d.ts +1 -1
  161. package/dist/pages/index.js +1 -1
  162. package/dist/pages/load.d.ts +7 -1
  163. package/dist/pages/load.js +10 -5
  164. package/dist/pages/page-file.js +1 -1
  165. package/dist/pages/stack-writes.js +5 -4
  166. package/dist/pages/standard-fields.d.ts +2 -0
  167. package/dist/pages/standard-fields.js +8 -1
  168. package/dist/pages/world.d.ts +8 -0
  169. package/dist/pages/world.js +9 -2
  170. package/dist/systems/game-system.d.ts +61 -30
  171. package/dist/systems/game-system.js +159 -50
  172. package/dist/systems/index.d.ts +3 -3
  173. package/dist/systems/index.js +3 -3
  174. package/dist/systems/system-code.d.ts +29 -88
  175. package/dist/systems/system-code.js +68 -23
  176. package/dist/systems/words.d.ts +2 -0
  177. package/dist/systems/words.js +11 -0
  178. package/dist/testing.d.ts +76 -0
  179. package/dist/testing.js +197 -0
  180. package/instructions/combat.md +2 -2
  181. package/instructions/core.md +2 -2
  182. package/instructions/dashboard.md +1 -1
  183. package/instructions/mentor-tutorial.md +1 -1
  184. package/instructions/play.md +2 -2
  185. package/instructions/setup.md +1 -1
  186. package/package.json +15 -2
  187. package/systems/5e/LICENSE.md +13 -3
  188. package/systems/5e/dist/dying.js +83 -16
  189. package/systems/5e/dist/index.js +2 -2
  190. package/systems/5e/dist/page-style.js +634 -0
  191. package/systems/5e/dist/page.js +166 -0
  192. package/systems/5e/dist/shown.js +23 -0
  193. package/systems/5e/instructions/combat.md +1 -0
  194. package/systems/5e/package.json +4 -2
  195. package/systems/5e/system.yaml +35 -7
  196. package/systems/5e/versions/srd-5.1/system.yaml +2 -0
  197. package/systems/5e/words/ar.yaml +30 -0
  198. package/systems/5e/words/cs.yaml +30 -0
  199. package/systems/5e/words/da.yaml +30 -0
  200. package/systems/5e/words/de.yaml +30 -0
  201. package/systems/5e/words/el.yaml +30 -0
  202. package/systems/5e/words/es.yaml +30 -0
  203. package/systems/5e/words/fi.yaml +30 -0
  204. package/systems/5e/words/fr.yaml +30 -0
  205. package/systems/5e/words/he.yaml +30 -0
  206. package/systems/5e/words/hi.yaml +30 -0
  207. package/systems/5e/words/hu.yaml +30 -0
  208. package/systems/5e/words/is.yaml +30 -0
  209. package/systems/5e/words/it.yaml +30 -0
  210. package/systems/5e/words/ja.yaml +30 -0
  211. package/systems/5e/words/ko.yaml +30 -0
  212. package/systems/5e/words/nb.yaml +30 -0
  213. package/systems/5e/words/nl.yaml +30 -0
  214. package/systems/5e/words/pl.yaml +30 -0
  215. package/systems/5e/words/pt.yaml +30 -0
  216. package/systems/5e/words/ro.yaml +30 -0
  217. package/systems/5e/words/ru.yaml +30 -0
  218. package/systems/5e/words/sv.yaml +30 -0
  219. package/systems/5e/words/tr.yaml +30 -0
  220. package/systems/5e/words/uk.yaml +30 -0
  221. package/systems/5e/words/zh.yaml +30 -0
  222. package/dist/commands/game-extensions.d.ts +0 -34
  223. package/dist/commands/game-extensions.js +0 -182
  224. package/dist/commands/game-system-code.d.ts +0 -25
  225. package/dist/commands/game-system-code.js +0 -172
  226. package/dist/dashboard/death-save.js +0 -67
  227. package/dist/dashboard/dying.js +0 -46
  228. package/dist/dashboard/save-outcome.js +0 -42
  229. package/dist/dashboard/spend.js +0 -115
  230. package/dist/extensions/api.d.ts +0 -155
  231. /package/dist/{extensions/api.js → core/package-api.js} +0 -0
@@ -199,6 +199,27 @@ words:
199
199
  Stable: Stabil
200
200
  Successes: Başarılar
201
201
  Failures: Başarısızlıklar
202
+ # The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
203
+ "Dying": "Can çekişiyor"
204
+ "Dead": "Ölü"
205
+ "Success": "Başarı"
206
+ "Failure": "Başarısızlık"
207
+ "Two failures": "İki başarısızlık"
208
+ "{count} failures": "{count} başarısızlık"
209
+ "Back up with {value}": "{value} ile ayakta"
210
+ "{value} or more: a success": "{value} veya üstü: başarı"
211
+ "{face}: two failures": "{face}: iki başarısızlık"
212
+ "{face}: {count} failures": "{face}: {count} başarısızlık"
213
+ "{face}: back up with {value}": "{face}: {value} ile ayağa kalkış"
214
+ "at the maximum": "maksimumda"
215
+ "None left": "Kalmadı"
216
+ "One die at a time: stop when you like.": "Her seferinde tek zar: istediğin zaman dur."
217
+ "Dice rolled": "Atılan zarlar"
218
+ "I spend none": "Hiç harcamıyorum"
219
+ "Done": "Bitti"
220
+ "Left: {count}": "Kalan: {count}"
221
+ "{value} of {max}": "{value} / {max}"
222
+ "Roll": "At"
202
223
  Wretched: Sefil
203
224
  Squalid: Pejmürde
204
225
  Poor: Yoksul
@@ -481,6 +502,15 @@ words:
481
502
  Hooded Lantern: Kapaklı Fener
482
503
  Bullseye Lantern: Mercekli Fener
483
504
  Oil: Yağ
505
+ "Cast": "Büyü yap"
506
+ "Cast {item}": "{item} büyüsünü yap"
507
+ "I cast {item}.": "{item} büyüsünü yapıyorum."
508
+ "I cast {item} on {target}.": "{item} büyüsünü {target} hedefine yapıyorum."
509
+ "I cast {item} at {square}.": "{item} büyüsünü {square} karesine yapıyorum."
510
+ "I cast {item} on myself.": "{item} büyüsünü kendime yapıyorum."
511
+ "Prepare": "Hazırla"
512
+ "Prepare {item}": "{item} hazırla"
513
+ "I prepare {item}.": "{item} hazırlıyorum."
484
514
  names:
485
515
  str: Güç
486
516
  str-mod: Güç
@@ -199,6 +199,27 @@ words:
199
199
  Stable: Стабільно
200
200
  Successes: Успіхи
201
201
  Failures: Невдачі
202
+ # The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
203
+ "Dying": "Конає"
204
+ "Dead": "Смерть"
205
+ "Success": "Успіх"
206
+ "Failure": "Невдача"
207
+ "Two failures": "Дві невдачі"
208
+ "{count} failures": "Невдач: {count}"
209
+ "Back up with {value}": "На ногах з {value}"
210
+ "{value} or more: a success": "{value} або більше: успіх"
211
+ "{face}: two failures": "{face}: дві невдачі"
212
+ "{face}: {count} failures": "{face}: невдач — {count}"
213
+ "{face}: back up with {value}": "{face}: на ногах з {value}"
214
+ "at the maximum": "на максимумі"
215
+ "None left": "Не лишилось"
216
+ "One die at a time: stop when you like.": "По одному кубику: зупиняйся, коли захочеш."
217
+ "Dice rolled": "Кубики кинуто"
218
+ "I spend none": "Не витрачати"
219
+ "Done": "Готово"
220
+ "Left: {count}": "Лишилось: {count}"
221
+ "{value} of {max}": "{value} з {max}"
222
+ "Roll": "Кинути"
202
223
  Wretched: Жалюгідний
203
224
  Squalid: Убогий
204
225
  Poor: Бідний
@@ -481,6 +502,15 @@ words:
481
502
  Hooded Lantern: Ліхтар із заслінкою
482
503
  Bullseye Lantern: Направлений ліхтар
483
504
  Oil: Олива
505
+ "Cast": "Накласти"
506
+ "Cast {item}": "Накласти {item}"
507
+ "I cast {item}.": "Накладаю {item}."
508
+ "I cast {item} on {target}.": "Накладаю {item} на {target}."
509
+ "I cast {item} at {square}.": "Накладаю {item} на клітинку {square}."
510
+ "I cast {item} on myself.": "Накладаю {item} на себе."
511
+ "Prepare": "Підготувати"
512
+ "Prepare {item}": "Підготувати {item}"
513
+ "I prepare {item}.": "Готую {item}."
484
514
  names:
485
515
  str: Сила
486
516
  str-mod: Сила
@@ -199,6 +199,27 @@ words:
199
199
  Stable: 稳定
200
200
  Successes: 成功
201
201
  Failures: 失败
202
+ # The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
203
+ "Dying": "濒死"
204
+ "Dead": "死亡"
205
+ "Success": "成功"
206
+ "Failure": "失败"
207
+ "Two failures": "两次失败"
208
+ "{count} failures": "{count} 次失败"
209
+ "Back up with {value}": "以 {value} 点生命站起"
210
+ "{value} or more: a success": "{value} 或更高:成功"
211
+ "{face}: two failures": "{face}:两次失败"
212
+ "{face}: {count} failures": "{face}:{count} 次失败"
213
+ "{face}: back up with {value}": "{face}:以 {value} 点生命站起"
214
+ "at the maximum": "已达上限"
215
+ "None left": "已用完"
216
+ "One die at a time: stop when you like.": "一次掷一个骰子,想停就停。"
217
+ "Dice rolled": "已掷骰子"
218
+ "I spend none": "不消耗"
219
+ "Done": "完成"
220
+ "Left: {count}": "剩余:{count}"
221
+ "{value} of {max}": "{value}/{max}"
222
+ "Roll": "掷骰"
202
223
  Wretched: 赤贫
203
224
  Squalid: 肮脏
204
225
  Poor: 贫穷
@@ -481,6 +502,15 @@ words:
481
502
  Hooded Lantern: 遮光提灯
482
503
  Bullseye Lantern: 牛眼提灯
483
504
  Oil: 油
505
+ "Cast": "施放"
506
+ "Cast {item}": "施放{item}"
507
+ "I cast {item}.": "我施放{item}。"
508
+ "I cast {item} on {target}.": "我对{target}施放{item}。"
509
+ "I cast {item} at {square}.": "我向{square}格子施放{item}。"
510
+ "I cast {item} on myself.": "我对自己施放{item}。"
511
+ "Prepare": "准备"
512
+ "Prepare {item}": "准备{item}"
513
+ "I prepare {item}.": "我准备{item}。"
484
514
  names:
485
515
  str: 力量
486
516
  str-mod: 力量
@@ -1,34 +0,0 @@
1
- import type { Context } from "../core/context.ts";
2
- import type { Problem } from "../core/problem.ts";
3
- import { type Command } from "../core/registry.ts";
4
- import type { Extension, ExtensionCode, GameView } from "../extensions/index.ts";
5
- import { type GameDate } from "../time/index.ts";
6
- /** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
7
- export declare const extensionsFolderName = "extensions";
8
- /**
9
- * The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
10
- * master its text; by name, the package and version that give it, so that a server knows when another takes its place.
11
- */
12
- export declare function extensionCommands(root: string, context: Context, taken: string[]): Promise<{
13
- commands: Command[];
14
- sources: Record<string, string>;
15
- problems: Problem[];
16
- }>;
17
- /** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
18
- export declare function extensionCommandNames(extension: Extension, taken: string[]): Promise<string[]>;
19
- /** Tells the loader npm has just installed: code installed again at the same version is read anew. */
20
- export declare function packagesInstalled(): void;
21
- /** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
22
- export declare function extensionCodeProblems(root: string, context: Context, taken: string[]): Promise<Problem[]>;
23
- /**
24
- * What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
25
- * whatever they do: one that fails says so in its line, never in place of the output.
26
- */
27
- export declare function timePassedLines(root: string, context: Context, from: GameDate, to: GameDate): Promise<string[]>;
28
- /**
29
- * The code of an extension, when it may run (D-441): its module's default export, given the kit. Where the engine itself runs from its source, as in the tests,
30
- * an extension that ships its source too is loaded from it.
31
- */
32
- export declare function extensionCode(extension: Extension): Promise<ExtensionCode | undefined>;
33
- /** The game as a widget of an extension reads it (D-502): the game its commands reach, without the dice, the log or writing. */
34
- export declare function gameViewOf(root: string, context: Context, extension: Extension): GameView;
@@ -1,182 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- // The code of the campaign's extensions (D-63, D-428, D-436): its commands, what it does when time passes, and the API it reaches the game through.
10
- import { join } from "node:path";
11
- import { pathToFileURL } from "node:url";
12
- import { parse, stringify } from "yaml";
13
- import { z } from "zod";
14
- import { campaignFileName, readTextSetting, requireCampaign } from "../campaign/index.js";
15
- import { appendLogEntry } from "../core/log.js";
16
- import { defineCommand } from "../core/registry.js";
17
- import { files } from "../core/store.js";
18
- import { rollDice } from "../dice/index.js";
19
- import { environmentAt, isInParty, locate, playerCharacters } from "../pages/index.js";
20
- import { formatGameDate } from "../time/index.js";
21
- import { campaignExtensions, runsCode } from "./game-extension-list.js";
22
- import { calendarDayOf, newDatedLogEntry, presentDate } from "./game-time.js";
23
- import { campaignWorld } from "./game-world.js";
24
- /** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
25
- export const extensionsFolderName = "extensions";
26
- /** The longest description a command of an extension may give the master, in words (D-441): it is read in every chat. */
27
- const descriptionWords = 150;
28
- /**
29
- * The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
30
- * master its text; by name, the package and version that give it, so that a server knows when another takes its place.
31
- */
32
- export async function extensionCommands(root, context, taken) {
33
- const commands = [];
34
- const sources = {};
35
- const problems = [];
36
- for (const extension of campaignExtensions(root, context).extensions) {
37
- try {
38
- const own = [];
39
- for (const command of (await extensionCode(extension))?.commands ?? []) {
40
- own.push(asCommand(extension, command, [...taken, ...commands.map((other) => other.name), ...own.map((other) => other.name)]));
41
- }
42
- commands.push(...own);
43
- own.forEach((command) => (sources[command.name] = `${extension.package}@${extension.version}#${installs}`));
44
- }
45
- catch (error) {
46
- problems.push(codeProblem(extension, error));
47
- }
48
- }
49
- return { commands, sources, problems };
50
- }
51
- /** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
52
- export async function extensionCommandNames(extension, taken) {
53
- const names = [];
54
- for (const command of (await extensionCode(extension))?.commands ?? []) {
55
- names.push(asCommand(extension, command, [...taken, ...names]).name);
56
- }
57
- return names;
58
- }
59
- /** Tells the loader npm has just installed: code installed again at the same version is read anew. */
60
- export function packagesInstalled() {
61
- installs += 1;
62
- }
63
- /** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
64
- export async function extensionCodeProblems(root, context, taken) {
65
- return (await extensionCommands(root, context, taken)).problems;
66
- }
67
- /**
68
- * What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
69
- * whatever they do: one that fails says so in its line, never in place of the output.
70
- */
71
- export async function timePassedLines(root, context, from, to) {
72
- const lines = [];
73
- for (const extension of campaignExtensions(root, context).extensions) {
74
- try {
75
- const code = await extensionCode(extension);
76
- if (code?.timePassed !== undefined) {
77
- lines.push(...await code.timePassed({ from: momentOf(root, context, from), to: momentOf(root, context, to) }, gameOf(root, context, extension)));
78
- }
79
- }
80
- catch (error) {
81
- // One line: the master reads it among others.
82
- const why = (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
83
- lines.push(`The extension ${extension.name} failed after the time passed: ${why}. The time did pass: do not advance again; validate says how to fix it.`);
84
- }
85
- }
86
- return lines;
87
- }
88
- /** A command of an extension as a command of rpg-engine, refused when its name is not the extension's or is taken, or its description is too long. */
89
- function asCommand(extension, command, taken) {
90
- const name = command.name.trim();
91
- const words = command.description.split(/\s+/).length;
92
- if (name !== extension.name && !name.startsWith(`${extension.name}-`)) {
93
- throw new Error(`its command ${name} must be named ${extension.name}, or start with ${extension.name}-`);
94
- }
95
- if (taken.includes(name)) {
96
- throw new Error(`its command ${name} has the name of another command`);
97
- }
98
- if (words > descriptionWords) {
99
- throw new Error(`its command ${name} has a description of ${words} words, and ${descriptionWords} at most are read`);
100
- }
101
- return defineCommand({
102
- name,
103
- description: command.description,
104
- group: "game",
105
- input: command.input,
106
- readOnly: command.readOnly,
107
- positionals: command.positionals,
108
- async run(input, called) {
109
- const campaign = requireCampaign(called.folder);
110
- return { text: await command.run(input, gameOf(campaign, called, extension)) };
111
- },
112
- format: (result) => result.text,
113
- });
114
- }
115
- // The code of each extension, by its file and version, loaded once for the process: an import is never undone, a new version is another.
116
- const loaded = new Map();
117
- let installs = 0;
118
- /**
119
- * The code of an extension, when it may run (D-441): its module's default export, given the kit. Where the engine itself runs from its source, as in the tests,
120
- * an extension that ships its source too is loaded from it.
121
- */
122
- export function extensionCode(extension) {
123
- const source = join(extension.folder, "src", "index.ts");
124
- const entry = !runsCode(extension) ? undefined : import.meta.url.endsWith(".ts") && files().exists(source) ? source : extension.code;
125
- if (entry === undefined) {
126
- return Promise.resolve(undefined);
127
- }
128
- const url = `${pathToFileURL(entry).href}?v=${encodeURIComponent(extension.version)}&installs=${installs}`;
129
- const code = loaded.get(url) ?? import(__rewriteRelativeImportExtension(url)).then((module) => {
130
- if (typeof module.default !== "function") {
131
- throw new Error(`its code, ${entry}, has no default export that gives its commands`);
132
- }
133
- return module.default({ z });
134
- });
135
- loaded.set(url, code);
136
- return code;
137
- }
138
- /** The game as an extension's code reaches it (D-436): the dice, the time, where the party is, its own state and the log; nothing else is written. */
139
- function gameOf(root, context, extension) {
140
- const statePath = join(root, extensionsFolderName, extension.name, "state.yaml");
141
- return {
142
- roll: (notation) => {
143
- const rolled = rollDice(notation, { random: context.random });
144
- return { total: rolled.total, faces: rolled.faces, text: rolled.text };
145
- },
146
- now: () => {
147
- const now = presentDate(root);
148
- return now === undefined ? undefined : momentOf(root, context, now);
149
- },
150
- calendarDay: (day) => calendarDayOf(root, context, day),
151
- units: () => (readTextSetting(root, "units") === "imperial" ? "imperial" : "metric"),
152
- party: () => {
153
- const world = campaignWorld(root, context);
154
- const player = playerCharacters(world).find(isInParty);
155
- return player === undefined
156
- ? undefined
157
- : {
158
- places: locate(world, player).chain.filter((page) => page.type === "place").map((page) => page.name),
159
- environment: Object.fromEntries(environmentAt(world, player).map(({ entry }) => [entry.name, entry.value])),
160
- };
161
- },
162
- state: {
163
- read: () => parse(files().text(statePath) ?? "null"),
164
- write: (value) => files().write(statePath, `# The state of the extension ${extension.package}, kept by its code.\n${stringify(value, { lineWidth: 0 })}`),
165
- },
166
- log: (text, visibility = "hidden") => appendLogEntry(root, newDatedLogEntry(root, context, "extension", visibility, { extension: extension.name, text })),
167
- };
168
- }
169
- /** The game as a widget of an extension reads it (D-502): the game its commands reach, without the dice, the log or writing. */
170
- export function gameViewOf(root, context, extension) {
171
- const { now, calendarDay, units, party, state } = gameOf(root, context, extension);
172
- return { now, calendarDay, units, party, state: { read: state.read } };
173
- }
174
- /** A game date as the API gives it: as written, its day and minute, and its day of the calendar. */
175
- function momentOf(root, context, date) {
176
- const calendar = calendarDayOf(root, context, date.day);
177
- return { date: formatGameDate(date), day: date.day, ...(date.minute === undefined ? {} : { minute: date.minute }), ...(calendar === undefined ? {} : { calendar }) };
178
- }
179
- function codeProblem(extension, error) {
180
- const why = error instanceof Error ? error.message : String(error);
181
- return { path: campaignFileName, message: `The code of the extension ${extension.package} cannot be used: ${why}. Its commands are left out.`, fix: `install it again, or another version, with package install ${extension.name}` };
182
- }
@@ -1,25 +0,0 @@
1
- import type { Context, SaveAsked } from "../core/context.ts";
2
- import type { CounterChange, RollMade } from "../systems/index.ts";
3
- /** What a system's code said after a command's change, and apart why it did not run or failed, which the caller adds to its notes, never deciding by it. */
4
- export interface SystemSaid {
5
- lines: string[];
6
- problem?: string;
7
- }
8
- /** All a system's code said, its problem last. */
9
- export declare function allSaid(said: SystemSaid): string[];
10
- /** After a counter of a page changed, as by change or the hit dice: the system's lines. */
11
- export declare function systemCounterChanged(root: string, context: Context, change: CounterChange): SystemSaid;
12
- /** As someone's turn starts in a scene: the system's lines. */
13
- export declare function systemTurnStarted(root: string, context: Context, who: string): SystemSaid;
14
- /** After a roll for someone was logged, never a hidden one: the system's lines. */
15
- export declare function systemRolled(root: string, context: Context, roll: RollMade): SystemSaid;
16
- /** After an effect was added to a page, never to a copy: the system's lines. */
17
- export declare function systemEffectAdded(root: string, context: Context, added: {
18
- page: string;
19
- effect: string;
20
- }): SystemSaid;
21
- /** What the page draws of a question, as a death save, by the system's code; undefined when it says nothing, fails or is not there: ask asks as always. */
22
- export declare function systemAsking(root: string, context: Context, question: {
23
- who: string;
24
- notations: string[];
25
- }): SaveAsked | undefined;
@@ -1,172 +0,0 @@
1
- // The glue between the engine and a game system's code (D-448): the game its hooks may read and change, and where the commands call them. A hook comes after
2
- // the engine's own writes, each with its line in the log; one that fails, or code that is not loaded, is a line for the master, and the change stands.
3
- import { readTextSetting } from "../campaign/index.js";
4
- import { appendLogEntry } from "../core/log.js";
5
- import { comparableText, valueNamed } from "../core/text.js";
6
- import { formatCounter, readCounter } from "../counters/index.js";
7
- import { rollDice } from "../dice/index.js";
8
- import { withEffect } from "../effects/index.js";
9
- import { concernsPlayer, isPartyMember, isPlayerCharacter, pagesWithName, writePage } from "../pages/index.js";
10
- import { effectiveFields, effectsOf } from "./effect-layer.js";
11
- import { saveEffects } from "./game-effects.js";
12
- import { behindTheScreen, sealHiddenRoll } from "./game-master-rolls.js";
13
- import { keepingConditionNote } from "./game-reminders.js";
14
- import { readOpenScene } from "./game-scene.js";
15
- import { newDatedLogEntry } from "./game-time.js";
16
- import { campaignSystem, campaignWorld } from "./game-world.js";
17
- /** All a system's code said, its problem last. */
18
- export function allSaid(said) {
19
- return said.problem === undefined ? said.lines : [...said.lines, said.problem];
20
- }
21
- /** After a counter of a page changed, as by change or the hit dice: the system's lines. */
22
- export function systemCounterChanged(root, context, change) {
23
- return called(root, context, "this change", (hooks, game) => hooks.counterChanged?.(change, game) ?? []);
24
- }
25
- /** As someone's turn starts in a scene: the system's lines. */
26
- export function systemTurnStarted(root, context, who) {
27
- return called(root, context, "this turn began", (hooks, game) => hooks.turnStarted?.({ who }, game) ?? []);
28
- }
29
- /** After a roll for someone was logged, never a hidden one: the system's lines. */
30
- export function systemRolled(root, context, roll) {
31
- return called(root, context, "this roll", (hooks, game) => hooks.rolled?.(roll, game) ?? []);
32
- }
33
- /** After an effect was added to a page, never to a copy: the system's lines. */
34
- export function systemEffectAdded(root, context, added) {
35
- return called(root, context, "this effect", (hooks, game) => hooks.effectAdded?.(added, game) ?? []);
36
- }
37
- /** What the page draws of a question, as a death save, by the system's code; undefined when it says nothing, fails or is not there: ask asks as always. */
38
- export function systemAsking(root, context, question) {
39
- const hooks = loadedHooks(campaignSystem(root, context), context);
40
- try {
41
- return typeof hooks === "string" || hooks === undefined ? undefined : hooks.asking?.(question, reader(root, context));
42
- }
43
- catch {
44
- return undefined;
45
- }
46
- }
47
- /** A hook called with the game: its lines; when the code is not loaded or fails, apart, a line that says so and what to do, the engine's change made all the same. */
48
- function called(root, context, after, call) {
49
- const system = campaignSystem(root, context);
50
- const hooks = loadedHooks(system, context);
51
- const byHand = "meanwhile apply its rules yourself, as its pages say";
52
- if (typeof hooks === "string") {
53
- return { lines: [], problem: `The system ${system?.name}'s code ${hooks}, so nothing of it followed ${after}; ${byHand}.` };
54
- }
55
- if (hooks === undefined) {
56
- return { lines: [] };
57
- }
58
- try {
59
- const lines = call(hooks, game(root, context));
60
- return Array.isArray(lines) ? { lines } : { lines: [], problem: `The system ${system?.name} gave no lines after ${after}: its hooks give a list. It is done all the same; ${byHand}.` };
61
- }
62
- catch (error) {
63
- const why = (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
64
- return { lines: [], problem: `The system ${system?.name} failed after ${after}: ${why}. It is done all the same; ${byHand}.` };
65
- }
66
- }
67
- /** The hooks of the campaign's system; why not, when it has code that is not loaded or could not load; undefined when it brings none. */
68
- function loadedHooks(system, context) {
69
- if (system?.code !== true) {
70
- return undefined;
71
- }
72
- const loaded = context.systemCode?.[system.name];
73
- if (loaded === undefined) {
74
- return "is not loaded: start the MCP server again (/mcp in Claude Code), or open a new chat";
75
- }
76
- return "problem" in loaded ? `cannot load (${loaded.problem}): install rpg-engine again, or run npm run build in its repository, then start the MCP server again` : loaded.hooks;
77
- }
78
- /** The game as a system's code reads it. */
79
- function reader(root, context) {
80
- return {
81
- page: (name) => {
82
- const world = campaignWorld(root, context);
83
- const found = pagesWithName(world, name);
84
- return found.length === 1 ? systemPage(world, found[0]) : undefined;
85
- },
86
- setting: (name) => readTextSetting(root, name),
87
- sameName: (one, other) => comparableText(one) === comparableText(other),
88
- };
89
- }
90
- /** The game as a system's code reads and changes it: each write with its line in the log, as the engine shows that page to the player. */
91
- function game(root, context) {
92
- return {
93
- ...reader(root, context),
94
- set: (name, values, why) => setNumbers(root, context, name, values, why),
95
- addEffect: (name, effect, why) => addEffect(root, context, name, effect, why),
96
- endEffect: (name, effect, why) => endEffect(root, context, name, effect, why),
97
- roll: (notation, by) => {
98
- const rolled = rollDice(notation, { random: context.random });
99
- // For anyone outside the party, hidden as the master-rolls setting says (D-287).
100
- const hidden = behindTheScreen(root, context, by.who);
101
- const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", { notation: rolled.notation, total: rolled.total, result: rolled.text, why: by.why, who: by.who, physical: false, dice: rolled.dice });
102
- if (hidden) {
103
- sealHiddenRoll(entry, rolled.text, context);
104
- }
105
- appendLogEntry(root, entry);
106
- return { total: rolled.total, dice: rolled.dice, text: rolled.text };
107
- },
108
- };
109
- }
110
- function systemPage(world, page) {
111
- const fields = effectiveFields(world, page);
112
- return {
113
- name: page.name,
114
- party: isPartyMember(page),
115
- pc: isPlayerCharacter(page),
116
- counter: (field) => {
117
- const counter = readCounter(valueNamed(fields, field));
118
- return counter === undefined ? undefined : { value: counter.value, ...(counter.max === undefined ? {} : { max: counter.max }) };
119
- },
120
- has: (effect) => effectsOf(page).some((one) => comparableText(one.name) === comparableText(effect)),
121
- };
122
- }
123
- /** The page by a name only it has. */
124
- function uniquePage(world, name) {
125
- const found = pagesWithName(world, name);
126
- return found.length === 1 ? found[0] : undefined;
127
- }
128
- /** Sets numbers on a page, a counter keeping its maximum, each with its line in the log. */
129
- function setNumbers(root, context, name, values, why) {
130
- const world = campaignWorld(root, context);
131
- const page = uniquePage(world, name);
132
- if (page === undefined || Object.keys(values).length === 0) {
133
- return;
134
- }
135
- const before = effectiveFields(world, page);
136
- const written = Object.fromEntries(Object.entries(values).map(([field, value]) => {
137
- const own = readCounter(valueNamed(page.fields, field));
138
- return [field, own?.max === undefined ? value : formatCounter({ ...own, value })];
139
- }));
140
- writePage(world, page.name, undefined, { set: written });
141
- const visibility = concernsPlayer(world, page) ? "public" : "hidden";
142
- for (const [field, after] of Object.entries(written)) {
143
- const was = readCounter(valueNamed(before, field));
144
- const shown = was === undefined ? "0" : was.max === undefined ? String(was.value) : formatCounter(was);
145
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: shown, after: String(after), why }));
146
- }
147
- }
148
- /** Adds an effect without end: the engine's notes on what it breaks of what one keeps; undefined when the page has it already. */
149
- function addEffect(root, context, name, effect, why) {
150
- const world = campaignWorld(root, context);
151
- const page = uniquePage(world, name);
152
- if (page === undefined || effectsOf(page).some((one) => comparableText(one.name) === comparableText(effect))) {
153
- return undefined;
154
- }
155
- const system = campaignSystem(root, context);
156
- const keeping = keepingConditionNote(world, readOpenScene(root).scene, system, page.name, effect);
157
- saveEffects(root, context, world, { page, copy: false }, withEffect(effectsOf(page), { name: effect, values: [] }));
158
- appendLogEntry(root, newDatedLogEntry(root, context, "effect-added", concernsPlayer(world, page) ? "public" : "hidden", { page: page.name, effect, why }));
159
- return keeping === "" ? [] : [keeping];
160
- }
161
- /** Ends an effect; whether the page had it. */
162
- function endEffect(root, context, name, effect, why) {
163
- const world = campaignWorld(root, context);
164
- const page = uniquePage(world, name);
165
- const effects = page === undefined ? [] : effectsOf(page);
166
- if (page === undefined || !effects.some((one) => comparableText(one.name) === comparableText(effect))) {
167
- return false;
168
- }
169
- saveEffects(root, context, world, { page, copy: false }, effects.filter((one) => comparableText(one.name) !== comparableText(effect)));
170
- appendLogEntry(root, newDatedLogEntry(root, context, "effect-ended", concernsPlayer(world, page) ? "public" : "hidden", { page: page.name, effect, why }));
171
- return true;
172
- }
@@ -1,67 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
- // The death save the master asks of the player (D-460, D-461): a card of its own over the page, which stays until the outcome is told. The character's portrait
3
- // greyed, a ring that beats and a line of the heart; the successes on one side, the failures on the other, what each face does under the one button. Once the
4
- // dice land, the outcome in words, the new mark lit, the line and the portrait as it says: back in colour on the highest face, flat and grey at the last failure.
5
- import { useEffect, useRef } from "preact/hooks";
6
- import { CheckLabel } from "./asked.js";
7
- import { HeartLine, Marks, sideLabel, Skull, stableWord } from "./dying.js";
8
- import { Icon } from "./icons.js";
9
- import { checkOf, fieldLabel } from "./labels.js";
10
- import { Token } from "./party.js";
11
- import { t } from "./text.js";
12
- import { turnWords } from "./turns.js";
13
- /** The card of a death save asked of the player, from the question to its outcome, which the player closes once read. */
14
- export function DeathSaveCard({ asked, save, member, name, roll, outcome, rolling, onRoll, onClose }) {
15
- const card = useRef(null);
16
- const check = checkOf(asked.labels[0] ?? "", asked.title);
17
- const successes = outcome?.successes ?? save.successes.value;
18
- const failures = outcome?.failures ?? save.failures.value;
19
- const highest = save.highest === undefined ? undefined : `${save.highest.value} ${fieldLabel(save.highest.field)}`;
20
- const told = roll === undefined ? (rolling ? "rolling" : "asking") : outcome === undefined ? "told" : `told ${outcome.kind}`;
21
- const classes = ["dying-card", told].join(" ");
22
- const words = outcome === undefined ? "" : outcomeWords(outcome, highest, stableWord(member?.dying));
23
- // Each side named as the panel of the dying names it, by the counters of who rolls.
24
- const label = (side) => sideLabel({ field: save[side].field, mark: member?.dying?.find((counter) => counter.side === side)?.mark });
25
- // While it is there, the rolls beside the sheet stay in sight under it, as under the master's question (D-291).
26
- useEffect(() => {
27
- const element = card.current;
28
- if (element === null) {
29
- return;
30
- }
31
- const root = document.documentElement;
32
- const observer = new ResizeObserver(() => root.style.setProperty("--asked-space", `${element.offsetHeight + 16}px`));
33
- observer.observe(element);
34
- return () => {
35
- observer.disconnect();
36
- root.style.removeProperty("--asked-space");
37
- };
38
- }, []);
39
- return (_jsxs("section", { ref: card, class: classes, "aria-labelledby": `dying-${asked.id}`, children: [roll !== undefined && (_jsx("button", { type: "button", class: "icon-button dying-close", "aria-label": t("Close"), "data-tip": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) })), _jsx("p", { class: "eyebrow asked-turn", children: check === undefined ? turnWords(name) : `${turnWords(name)} · ${check.check}` }), _jsx("p", { id: `dying-${asked.id}`, class: "asked-question", role: roll === undefined ? "alert" : undefined, children: asked.question }), _jsxs("div", { class: "dying-life", children: [_jsx(HeartLine, { line: heartLine(outcome?.kind) }), _jsx(Marks, { kind: "successes", label: label("successes"), value: successes, most: save.successes.most, lit: outcome?.kind === "success" || outcome?.kind === "stable" ? 1 : 0 }), _jsx("span", { class: "dying-token", children: member !== undefined && _jsx(Token, { member: member, large: true }) }), _jsx(Marks, { kind: "failures", label: label("failures"), value: failures, most: save.failures.most, lit: outcome?.count ?? 0 })] }), _jsxs("div", { class: "dying-foot", children: [roll === undefined && (_jsx("button", { type: "button", class: rolling ? "dying-roll sent" : "dying-roll", disabled: rolling, "aria-describedby": `dying-stakes-${asked.id}`, onClick: onRoll, children: check === undefined ? asked.labels[0] : _jsx(CheckLabel, { check: check.check, dice: check.dice, name: undefined }) })), _jsx("p", { class: "dying-word", role: "status", children: roll !== undefined && (_jsxs(_Fragment, { children: [_jsxs("span", { "aria-hidden": "true", children: [outcome === undefined ? roll.total : `${roll.total} · `, outcome?.kind === "dead" && _jsx(Skull, {}), words] }), _jsx("span", { class: "visually-hidden", children: outcome === undefined
40
- ? String(roll.total)
41
- : `${roll.total}: ${words}. ${label("successes")}: ${t("{value} of {max}", { value: successes, max: save.successes.most })}; ${label("failures")}: ${t("{value} of {max}", { value: failures, max: save.failures.most })}.` })] })) }), _jsx("p", { id: `dying-stakes-${asked.id}`, class: "dying-stakes", children: [
42
- t("{value} or more: a success", { value: save.atLeast }),
43
- ...(save.lowest === undefined ? [] : [save.lowest === 2 ? t("{face}: two failures", { face: 1 }) : t("{face}: {count} failures", { face: 1, count: save.lowest })]),
44
- ...(highest === undefined ? [] : [t("{face}: back up with {value}", { face: save.sides, value: highest })]),
45
- ].join(" · ") })] })] }));
46
- }
47
- /** The outcome in the page's words, stable as the system calls it. */
48
- function outcomeWords(outcome, highest, stable) {
49
- switch (outcome.kind) {
50
- case "success":
51
- return t("Success");
52
- case "stable":
53
- return stable;
54
- case "failure":
55
- return t("Failure");
56
- case "failures":
57
- return outcome.count === 2 ? t("Two failures") : t("{count} failures", { count: outcome.count });
58
- case "dead":
59
- return t("Dead");
60
- case "back":
61
- return highest === undefined ? t("Back up") : t("Back up with {value}", { value: highest });
62
- }
63
- }
64
- /** The line of the heart for an outcome: faint while it is to roll, a beat at a success, weaker at a failure, strong back on their feet, flat at the last. */
65
- function heartLine(kind) {
66
- return kind === undefined ? "faint" : kind === "back" ? "strong" : kind === "dead" ? "flat" : kind === "success" || kind === "stable" ? "beat" : "weak";
67
- }