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
@@ -1,13 +1,24 @@
1
1
  import { strangerLabel } from "./labels.js";
2
2
  import { t } from "./text.js";
3
- /** Whether a verb asks for someone to act on, lets the player choose one, or goes straight to the sentence (D-495). */
3
+ // The system's own verbs, by name, as the overview gives them (D-514).
4
+ let systemVerbs = {};
5
+ /** Sets the game system's own verbs; none, the engine's alone. */
6
+ export function setSystemVerbs(verbs) {
7
+ systemVerbs = verbs ?? {};
8
+ }
9
+ /** Whether a verb asks for someone to act on, lets the player choose one, or goes straight to the sentence (D-495); a system's lets choose when it says on whom. */
4
10
  export function targetMode(verb) {
5
- return verb === "attack" ? "asks" : verb === "cast" || verb === "use" ? "lets" : "none";
11
+ return verb === "attack" ? "asks" : verb === "use" || ownVerb(verb)?.on !== undefined ? "lets" : "none";
6
12
  }
7
13
  /** The player's sentence as the page first writes it, which the player may change before it goes: a model of the page's language with the names as shown. */
8
14
  export function actSentence(verb, item, target = "none") {
9
15
  const on = typeof target === "object" && "person" in target ? target.person : undefined;
10
16
  const at = typeof target === "object" && "square" in target ? target.square : undefined;
17
+ const own = ownVerb(verb);
18
+ if (own !== undefined) {
19
+ const chosen = on !== undefined ? own.on : at !== undefined ? own.at : target === "self" ? own.self : undefined;
20
+ return t(chosen ?? own.says, { item, ...(on === undefined ? {} : { target: on }), ...(at === undefined ? {} : { square: at }) });
21
+ }
11
22
  switch (verb) {
12
23
  case "attack":
13
24
  return on !== undefined
@@ -17,14 +28,6 @@ export function actSentence(verb, item, target = "none") {
17
28
  : target === "self"
18
29
  ? t("I attack myself with {item}.", { item })
19
30
  : t("I attack with {item}.", { item });
20
- case "cast":
21
- return on !== undefined
22
- ? t("I cast {item} on {target}.", { target: on, item })
23
- : at !== undefined
24
- ? t("I cast {item} at {square}.", { square: at, item })
25
- : target === "self"
26
- ? t("I cast {item} on myself.", { item })
27
- : t("I cast {item}.", { item });
28
31
  case "use":
29
32
  return on !== undefined
30
33
  ? t("I use {item} on {target}.", { target: on, item })
@@ -37,8 +40,8 @@ export function actSentence(verb, item, target = "none") {
37
40
  return t("I equip {item}.", { item });
38
41
  case "unequip":
39
42
  return t("I put away {item}.", { item });
40
- case "prepare":
41
- return t("I prepare {item}.", { item });
43
+ default:
44
+ return t("I use {item}.", { item });
42
45
  }
43
46
  }
44
47
  /** The start of what the player says to someone, the cursor after it. */
@@ -51,36 +54,36 @@ export function spokenBy(sentence, who) {
51
54
  }
52
55
  /** What a verb does with a thing, as a button's tooltip and the sheet's title say it: Attack with Mace. */
53
56
  export function actTitle(verb, item) {
57
+ const own = ownVerb(verb);
58
+ if (own !== undefined) {
59
+ return t(own.title, { item });
60
+ }
54
61
  switch (verb) {
55
62
  case "attack":
56
63
  return t("Attack with {item}", { item });
57
- case "cast":
58
- return t("Cast {item}", { item });
59
- case "use":
60
- return t("Use {item}", { item });
61
64
  case "equip":
62
65
  return t("Equip {item}", { item });
63
66
  case "unequip":
64
67
  return t("Put away {item}", { item });
65
- case "prepare":
66
- return t("Prepare {item}", { item });
68
+ default:
69
+ return t("Use {item}", { item });
67
70
  }
68
71
  }
69
72
  /** A verb alone, for the choice among a thing's verbs. */
70
73
  export function verbLabel(verb) {
74
+ const own = ownVerb(verb);
75
+ if (own !== undefined) {
76
+ return t(own.label);
77
+ }
71
78
  switch (verb) {
72
79
  case "attack":
73
80
  return t("Attack");
74
- case "cast":
75
- return t("Cast");
76
- case "use":
77
- return t("Use");
78
81
  case "equip":
79
82
  return t("Equip");
80
83
  case "unequip":
81
84
  return t("Put away");
82
- case "prepare":
83
- return t("Prepare");
85
+ default:
86
+ return t("Use");
84
87
  }
85
88
  }
86
89
  /**
@@ -138,3 +141,7 @@ export function saidStates(said, shown, live) {
138
141
  return state === undefined ? [] : [{ act, state }];
139
142
  });
140
143
  }
144
+ /** A verb the system declares, by its name; undefined for one of the engine's. */
145
+ function ownVerb(verb) {
146
+ return Object.hasOwn(systemVerbs, verb) ? systemVerbs[verb] : undefined;
147
+ }
@@ -6,11 +6,13 @@ import { t } from "./text.js";
6
6
  export const sections = ["party", "scene", "journal", "world"];
7
7
  /** The pages at the row's end, as icons, in the menu on a phone: the saves, played with, then what is read, as Help and the settings are, and the packages (D-356, D-409, D-475). */
8
8
  export const menuPages = ["saves", "help", "settings", "packages", "about"];
9
+ /** A package's own page, as #/pkg/<package>/<name>, reached from its row in Packages and by its address (D-511). */
10
+ export const packagePages = "pkg";
9
11
  /** The address a hash says, as #/party/Ettore; the sheet for none or one the page does not know. */
10
12
  export function readAddress(hash) {
11
13
  const [, written = "", ...rest] = hash.replace(/^#/, "").split("/");
12
14
  const first = written === "combat" ? "scene" : written;
13
- const section = [...sections, ...menuPages].find((candidate) => candidate === first) ?? "party";
15
+ const section = [...sections, ...menuPages, packagePages].find((candidate) => candidate === first) ?? "party";
14
16
  const sheet = first === "party" || first === "character";
15
17
  const known = section === first;
16
18
  const tab = sheet || !known ? "" : decoded(rest[0] ?? "");
@@ -33,6 +35,7 @@ export function sectionLabel(section) {
33
35
  settings: t("Settings"),
34
36
  packages: t("Packages"),
35
37
  about: t("About"),
38
+ pkg: t("Packages"),
36
39
  };
37
40
  return labels[section];
38
41
  }
@@ -147,6 +147,32 @@ export async function changeSaves(change) {
147
147
  return t("It did not reach the game: try again.");
148
148
  }
149
149
  }
150
+ /** RPG Engine and what npm has of it; undefined where the page is not served by the game's own server, which alone updates it. */
151
+ export async function readEngine() {
152
+ const response = await fetch("/api/engine");
153
+ const body = await response.json();
154
+ if (response.status === 400) {
155
+ return undefined;
156
+ }
157
+ if ("error" in body) {
158
+ throw new Error(body.error);
159
+ }
160
+ return body;
161
+ }
162
+ /** Installs npm's latest RPG Engine as it was installed: the chat and this page go on with the one they started with. */
163
+ export async function updateEngine() {
164
+ try {
165
+ const response = await fetch("/api/engine", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "update" }) });
166
+ const body = await response.json().catch(() => ({}));
167
+ if (response.status === 202 && body.version !== undefined) {
168
+ return { done: true, version: body.version, restart: body.restart === "app" ? "app" : "chat" };
169
+ }
170
+ return { done: false, error: body.error ?? t("It did not reach the game: try again."), ...(body.code === "busy" ? { code: body.code } : {}) };
171
+ }
172
+ catch {
173
+ return { done: false, error: t("It did not reach the game: try again.") };
174
+ }
175
+ }
150
176
  /** The packages here, at once: without npm. */
151
177
  export async function readPackages() {
152
178
  const response = await fetch("/api/packages");
@@ -165,6 +191,25 @@ export async function readWidgets() {
165
191
  }
166
192
  return body.widgets;
167
193
  }
194
+ /** What a package's widget shows for a card or a page of its page code, for who (D-514): nothing when the package or the widget is not the campaign's. */
195
+ export async function readWidgetData(owner, widget, who) {
196
+ const query = new URLSearchParams({ package: owner, widget, ...(who === undefined ? {} : { who }) });
197
+ const response = await fetch(`/api/widget?${query.toString()}`);
198
+ const body = await response.json();
199
+ if (body.error !== undefined) {
200
+ throw new Error(body.error);
201
+ }
202
+ return body.shows;
203
+ }
204
+ /** The page modules of the campaign's system and extensions whose code runs (D-510, D-511), the system's first. */
205
+ export async function readModules() {
206
+ const response = await fetch("/api/modules");
207
+ const body = await response.json();
208
+ if ("error" in body) {
209
+ throw new Error(body.error);
210
+ }
211
+ return body.modules;
212
+ }
168
213
  /** The catalog (D-486), as the server keeps it for ten minutes; `fresh` asks npm and GitHub again. */
169
214
  export async function readCatalog(fresh) {
170
215
  const response = await fetch(fresh ? "/api/catalog?fresh=true" : "/api/catalog");
@@ -247,11 +292,19 @@ async function sendChange(change) {
247
292
  return t("The change did not reach the game: try again.");
248
293
  }
249
294
  }
250
- /** What the master asks the player now; undefined when nothing. */
295
+ /** What the master asks the player now, null when nothing; with nothing, the card a package's last question left (D-507). */
251
296
  export async function readAsked() {
252
297
  const response = await fetch("/api/asked");
253
- const body = await response.json();
254
- return body.asked ?? undefined;
298
+ return await response.json();
299
+ }
300
+ /** Closes a package's card once told (D-507), for every page and every reading after; a server away keeps it, closed on this page alone. */
301
+ export async function closeCard(key) {
302
+ try {
303
+ await fetch("/api/card", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ close: key }) });
304
+ }
305
+ catch {
306
+ // Closed here; another page may still show it.
307
+ }
255
308
  }
256
309
  /** Tells the server whether this page is seen now (D-455); a page that cannot tell it is taken as seen. */
257
310
  export async function sendSeen(page, seen) {
@@ -313,3 +366,12 @@ export function explanations(lines) {
313
366
  return colon < 0 ? [] : [[field, line.slice(colon + 2).split(", ")]];
314
367
  }));
315
368
  }
369
+ /** Runs a command of an extension marked for the player (D-510), as its page code asks: what it said; it throws what went wrong, as the engine says it. */
370
+ export async function runCommand(command, input = {}) {
371
+ const response = await fetch("/api/run", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ command, input }) });
372
+ const body = await response.json().catch(() => ({}));
373
+ if (!response.ok || body.error !== undefined) {
374
+ throw new Error(body.error ?? `${command} did not run (${response.status})`);
375
+ }
376
+ return body.text ?? "";
377
+ }