rpg-engine 0.20.0 → 0.22.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 (194) hide show
  1. package/dist/adventures/index.d.ts +1 -1
  2. package/dist/adventures/index.js +1 -1
  3. package/dist/adventures/source.d.ts +3 -0
  4. package/dist/adventures/source.js +11 -49
  5. package/dist/campaign/create-campaign.d.ts +1 -1
  6. package/dist/campaign/create-campaign.js +3 -2
  7. package/dist/campaign/find-campaign.d.ts +2 -0
  8. package/dist/campaign/find-campaign.js +2 -0
  9. package/dist/campaign/host-files.js +4 -1
  10. package/dist/campaign/index.d.ts +3 -2
  11. package/dist/campaign/index.js +3 -2
  12. package/dist/campaign/port.d.ts +6 -0
  13. package/dist/campaign/port.js +24 -0
  14. package/dist/campaign/settings.d.ts +17 -0
  15. package/dist/campaign/settings.js +26 -3
  16. package/dist/cli/cli.js +15 -0
  17. package/dist/commands/book.d.ts +16 -35
  18. package/dist/commands/book.js +86 -62
  19. package/dist/commands/config/config.js +16 -2
  20. package/dist/commands/config/dashboard.d.ts +6 -2
  21. package/dist/commands/config/dashboard.js +45 -8
  22. package/dist/commands/config/shown.js +4 -0
  23. package/dist/commands/config/words.d.ts +3 -1
  24. package/dist/commands/config/words.js +29 -2
  25. package/dist/commands/image.d.ts +5 -0
  26. package/dist/commands/image.js +6 -3
  27. package/dist/commands/mode.d.ts +1 -1
  28. package/dist/commands/package/data.d.ts +35 -0
  29. package/dist/commands/package/data.js +144 -0
  30. package/dist/commands/package/here.d.ts +7 -2
  31. package/dist/commands/package/here.js +23 -11
  32. package/dist/commands/package/install.js +14 -15
  33. package/dist/commands/package/language.d.ts +15 -0
  34. package/dist/commands/package/language.js +109 -0
  35. package/dist/commands/package/package.js +20 -10
  36. package/dist/commands/package/result.d.ts +19 -0
  37. package/dist/commands/package/theme.d.ts +13 -0
  38. package/dist/commands/package/theme.js +67 -0
  39. package/dist/commands/package/uninstall.d.ts +4 -1
  40. package/dist/commands/package/uninstall.js +29 -9
  41. package/dist/commands/scene/close.d.ts +1 -1
  42. package/dist/commands/scene/close.js +15 -8
  43. package/dist/commands/scene/scene.js +6 -1
  44. package/dist/commands/shared/books/adventures.d.ts +1 -4
  45. package/dist/commands/shared/books/adventures.js +3 -32
  46. package/dist/commands/shared/books/words.js +3 -2
  47. package/dist/commands/shared/campaign/book.d.ts +21 -8
  48. package/dist/commands/shared/campaign/book.js +65 -42
  49. package/dist/commands/shared/campaign/git.d.ts +25 -0
  50. package/dist/commands/shared/campaign/git.js +104 -0
  51. package/dist/commands/shared/campaign/saves.js +7 -3
  52. package/dist/commands/shared/campaign/world.js +2 -1
  53. package/dist/commands/shared/packages/catalog.d.ts +3 -3
  54. package/dist/commands/shared/packages/catalog.js +118 -43
  55. package/dist/commands/shared/packages/unpacked.d.ts +50 -0
  56. package/dist/commands/shared/packages/unpacked.js +146 -0
  57. package/dist/commands/status.d.ts +1 -0
  58. package/dist/commands/status.js +8 -4
  59. package/dist/core/archive.d.ts +13 -0
  60. package/dist/core/archive.js +76 -0
  61. package/dist/core/context.d.ts +4 -0
  62. package/dist/core/context.js +1 -0
  63. package/dist/core/store.d.ts +5 -1
  64. package/dist/core/store.js +15 -2
  65. package/dist/core/version.d.ts +2 -0
  66. package/dist/core/version.js +5 -0
  67. package/dist/dashboard/api.js +24 -1
  68. package/dist/dashboard/app.js +7 -2
  69. package/dist/dashboard/guide/ar.md +11 -9
  70. package/dist/dashboard/guide/cs.md +11 -9
  71. package/dist/dashboard/guide/da.md +12 -10
  72. package/dist/dashboard/guide/de.md +13 -11
  73. package/dist/dashboard/guide/el.md +11 -9
  74. package/dist/dashboard/guide/en.md +10 -8
  75. package/dist/dashboard/guide/es.md +11 -9
  76. package/dist/dashboard/guide/fi.md +11 -9
  77. package/dist/dashboard/guide/fr.md +11 -9
  78. package/dist/dashboard/guide/he.md +11 -9
  79. package/dist/dashboard/guide/hi.md +11 -9
  80. package/dist/dashboard/guide/hu.md +11 -9
  81. package/dist/dashboard/guide/is.md +11 -9
  82. package/dist/dashboard/guide/it.md +11 -9
  83. package/dist/dashboard/guide/ja.md +12 -10
  84. package/dist/dashboard/guide/ko.md +11 -9
  85. package/dist/dashboard/guide/nb.md +12 -10
  86. package/dist/dashboard/guide/nl.md +11 -9
  87. package/dist/dashboard/guide/pl.md +11 -9
  88. package/dist/dashboard/guide/pt.md +11 -9
  89. package/dist/dashboard/guide/ro.md +11 -9
  90. package/dist/dashboard/guide/ru.md +12 -10
  91. package/dist/dashboard/guide/sv.md +11 -9
  92. package/dist/dashboard/guide/tr.md +11 -9
  93. package/dist/dashboard/guide/uk.md +12 -10
  94. package/dist/dashboard/guide/zh.md +11 -9
  95. package/dist/dashboard/i18n/ar.json +58 -5
  96. package/dist/dashboard/i18n/cs.json +58 -5
  97. package/dist/dashboard/i18n/da.json +58 -5
  98. package/dist/dashboard/i18n/de.json +58 -5
  99. package/dist/dashboard/i18n/el.json +58 -5
  100. package/dist/dashboard/i18n/es.json +58 -5
  101. package/dist/dashboard/i18n/fi.json +58 -5
  102. package/dist/dashboard/i18n/fr.json +58 -5
  103. package/dist/dashboard/i18n/he.json +58 -5
  104. package/dist/dashboard/i18n/hi.json +58 -5
  105. package/dist/dashboard/i18n/hu.json +58 -5
  106. package/dist/dashboard/i18n/is.json +58 -5
  107. package/dist/dashboard/i18n/it.json +58 -5
  108. package/dist/dashboard/i18n/ja.json +58 -5
  109. package/dist/dashboard/i18n/ko.json +58 -5
  110. package/dist/dashboard/i18n/nb.json +58 -5
  111. package/dist/dashboard/i18n/nl.json +58 -5
  112. package/dist/dashboard/i18n/pl.json +58 -5
  113. package/dist/dashboard/i18n/pt.json +58 -5
  114. package/dist/dashboard/i18n/ro.json +58 -5
  115. package/dist/dashboard/i18n/ru.json +58 -5
  116. package/dist/dashboard/i18n/sv.json +58 -5
  117. package/dist/dashboard/i18n/tr.json +58 -5
  118. package/dist/dashboard/i18n/uk.json +58 -5
  119. package/dist/dashboard/i18n/zh.json +58 -5
  120. package/dist/dashboard/journal/book.js +3 -2
  121. package/dist/dashboard/journal/journal.js +8 -5
  122. package/dist/dashboard/kit.js +1 -1
  123. package/dist/dashboard/packages/catalog.js +31 -14
  124. package/dist/dashboard/packages/engine.js +46 -2
  125. package/dist/dashboard/packages/installed.js +13 -0
  126. package/dist/dashboard/packages/outcomes.js +21 -0
  127. package/dist/dashboard/packages/packages.js +41 -18
  128. package/dist/dashboard/packages/rows.js +3 -1
  129. package/dist/dashboard/parts/icons.js +3 -0
  130. package/dist/dashboard/parts/labels.js +7 -0
  131. package/dist/dashboard/parts/picture.js +89 -0
  132. package/dist/dashboard/parts/refusals.js +8 -1
  133. package/dist/dashboard/parts/widgets.js +2 -1
  134. package/dist/dashboard/play/scene.js +8 -5
  135. package/dist/dashboard/settings/settings.js +55 -18
  136. package/dist/dashboard/sheet/party.js +5 -2
  137. package/dist/dashboard/sheet/sheet.js +2 -1
  138. package/dist/dashboard/shell/notices.js +2 -2
  139. package/dist/dashboard/shell/system-style.js +132 -15
  140. package/dist/dashboard/shell/tooltip.js +224 -0
  141. package/dist/dashboard/style.css +497 -193
  142. package/dist/dashboard/world/lore.js +4 -3
  143. package/dist/dashboard/world/place-card.js +2 -1
  144. package/dist/git/git.d.ts +12 -0
  145. package/dist/git/git.js +175 -0
  146. package/dist/git/ignore.d.ts +2 -0
  147. package/dist/git/ignore.js +16 -0
  148. package/dist/git/index.d.ts +2 -0
  149. package/dist/git/index.js +2 -0
  150. package/dist/importer/index.d.ts +1 -1
  151. package/dist/importer/index.js +1 -1
  152. package/dist/languages/index.d.ts +1 -1
  153. package/dist/languages/index.js +1 -1
  154. package/dist/languages/pack.d.ts +4 -1
  155. package/dist/languages/pack.js +18 -6
  156. package/dist/packages/engine.d.ts +7 -0
  157. package/dist/packages/engine.js +32 -1
  158. package/dist/packages/index.d.ts +1 -1
  159. package/dist/packages/index.js +1 -1
  160. package/dist/server/bell-listener.d.ts +2 -1
  161. package/dist/server/bell-listener.js +10 -41
  162. package/dist/server/dashboard/engine.d.ts +18 -0
  163. package/dist/server/dashboard/engine.js +31 -0
  164. package/dist/server/dashboard/files.d.ts +11 -3
  165. package/dist/server/dashboard/files.js +66 -17
  166. package/dist/server/dashboard/index.d.ts +18 -2
  167. package/dist/server/dashboard/index.js +62 -23
  168. package/dist/server/dashboard/news.d.ts +3 -2
  169. package/dist/server/dashboard/news.js +19 -5
  170. package/dist/server/dashboard/pictures.d.ts +7 -0
  171. package/dist/server/dashboard/pictures.js +62 -0
  172. package/dist/server/dashboard/ports.d.ts +17 -2
  173. package/dist/server/dashboard/ports.js +60 -4
  174. package/dist/server/dashboard/writes.d.ts +5 -3
  175. package/dist/server/dashboard/writes.js +45 -14
  176. package/dist/server/mcp.d.ts +3 -2
  177. package/dist/server/mcp.js +55 -11
  178. package/dist/testing/index.js +1 -0
  179. package/dist/themes/css.d.ts +1 -1
  180. package/dist/themes/css.js +101 -2
  181. package/dist/themes/index.d.ts +2 -1
  182. package/dist/themes/index.js +4 -2
  183. package/dist/themes/installed.d.ts +14 -0
  184. package/dist/themes/installed.js +28 -0
  185. package/dist/themes/theme.d.ts +38 -0
  186. package/dist/themes/theme.js +192 -13
  187. package/instructions/core.md +4 -3
  188. package/instructions/dashboard-guide.md +2 -1
  189. package/instructions/mentor-hints.md +1 -1
  190. package/instructions/mentor-tutorial.md +1 -1
  191. package/instructions/party.md +1 -1
  192. package/instructions/play.md +2 -2
  193. package/package.json +1 -1
  194. package/systems/free/instructions/outcomes-told.md +1 -1
@@ -1,7 +1,7 @@
1
1
  // A theme of the dashboard (D-527, D-528): a folder of data, theme.yaml with its fonts, pictures and icons, read and checked as the engine reads its game
2
2
  // system. It gives values alone, colours, corners, fonts and the hooks the page documents; the page's own rules read them, so no part is the theme's to redraw.
3
3
  import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
4
- import { extname, isAbsolute, join, relative, sep } from "node:path";
4
+ import { extname, isAbsolute, join, posix, relative, sep } from "node:path";
5
5
  import { parse } from "yaml";
6
6
  import { z } from "zod";
7
7
  import { contrast, distance, isLight, mix } from "./contrast.js";
@@ -39,12 +39,12 @@ export function readTheme(folder) {
39
39
  if (problem !== undefined) {
40
40
  problems.push(`${place}: ${problem}`);
41
41
  }
42
- return name.replaceAll("\\", "/");
42
+ return written(name);
43
43
  };
44
44
  const fonts = (given.fonts ?? []).map((font, index) => {
45
45
  file(`fonts.${index}.file`, font.file, fontFiles);
46
46
  file(`fonts.${index}.license`, font.license, licenseFiles);
47
- return { family: font.family, file: font.file.replaceAll("\\", "/"), weight: String(font.weight ?? 400) };
47
+ return { family: font.family, file: written(font.file), weight: String(font.weight ?? 400) };
48
48
  });
49
49
  const family = (key) => {
50
50
  const name = given[key];
@@ -74,22 +74,38 @@ export function readTheme(folder) {
74
74
  }
75
75
  }
76
76
  const ornament = given.cards?.ornament === undefined ? undefined : file("cards.ornament", given.cards.ornament, [".svg"]);
77
+ const cardTexture = given.cards?.texture === undefined ? undefined : { picture: file("cards.texture.picture", given.cards.texture.picture, [".svg"]), fit: given.cards.texture.fit ?? "tile" };
78
+ if (cardTexture !== undefined && fileProblem(folder, cardTexture.picture, [".svg"]) === undefined) {
79
+ problems.push(...oneColourProblems(readFileSync(join(folder, cardTexture.picture), "utf8")).map((problem) => `cards.texture.picture: ${cardTexture.picture} ${problem}`));
80
+ }
81
+ const style = given.style === undefined ? undefined : file("style", given.style, [".css"]);
82
+ if (style !== undefined && fileProblem(folder, style, [".css"]) === undefined) {
83
+ problems.push(...styleProblems(folder, style));
84
+ }
85
+ const hooks = { tabs: given.tabs?.shape ?? "underline", grain: cardTexture !== undefined, frame: (given.portraits?.frame ?? "none") !== "none" };
77
86
  const modes = {};
78
87
  for (const mode of themeModes) {
79
88
  const asked = given[mode];
80
89
  const colours = derived(asked);
90
+ const cardEdge = asked["card-edge"] ?? colours.rule;
81
91
  modes[mode] = {
82
92
  colours,
83
- cardEdge: asked["card-edge"] ?? colours.rule,
93
+ cardEdge,
84
94
  ...(asked["title-glow"] === undefined || asked["title-glow"] === "none" ? {} : { titleGlow: asked["title-glow"] }),
85
95
  ...(asked["bar-edge"] === undefined || asked["bar-edge"] === "none" ? {} : { barEdge: asked["bar-edge"] }),
86
96
  ...(asked["page-texture"] === undefined ? {} : { pageTexture: { picture: file(`${mode}.page-texture.picture`, asked["page-texture"].picture, pictureFiles), fit: asked["page-texture"].fit ?? "tile" } }),
87
97
  ...(asked["bar-texture"] === undefined ? {} : { barTexture: { picture: file(`${mode}.bar-texture.picture`, asked["bar-texture"].picture, pictureFiles), fit: asked["bar-texture"].fit ?? "tile" } }),
98
+ ...(asked["head-picture"] === undefined ? {} : { headPicture: { picture: file(`${mode}.head-picture.picture`, asked["head-picture"].picture, pictureFiles), fit: asked["head-picture"].fit ?? "cover" } }),
99
+ cardGrain: asked["card-grain"] ?? cardEdge,
100
+ ...optional("shadow", asked.shadow),
101
+ portraitFrame: asked["portrait-frame"] ?? colours.gold,
88
102
  };
89
- problems.push(...legibilityProblems(mode, modes[mode]));
103
+ problems.push(...legibilityProblems(mode, modes[mode], hooks));
90
104
  }
105
+ problems.push(...paperProblems(given.papers ?? {}));
91
106
  const theme = {
92
107
  name: given.name,
108
+ ...optional("version", given.version),
93
109
  folder,
94
110
  fonts,
95
111
  ...optional("textFont", family("text-font")),
@@ -101,6 +117,15 @@ export function readTheme(folder) {
101
117
  ...optional("titleSpacing", given.titles?.spacing),
102
118
  ...optional("innerLine", given.cards?.["inner-line"]),
103
119
  ...optional("ornament", ornament),
120
+ ...optional("cardCorner", given.cards?.corner),
121
+ ...optional("cardTexture", cardTexture),
122
+ ...optional("buttonShape", given.buttons?.shape),
123
+ ...optional("tabShape", given.tabs?.shape),
124
+ ...optional("shadows", given.shadows),
125
+ papers: given.papers ?? {},
126
+ ...optional("portraitShape", given.portraits?.shape),
127
+ ...optional("portraitFrame", given.portraits?.frame),
128
+ ...optional("style", style),
104
129
  icons,
105
130
  modes,
106
131
  };
@@ -118,6 +143,56 @@ export function themeFile(folder, name) {
118
143
  return undefined;
119
144
  }
120
145
  }
146
+ /**
147
+ * The files a theme.yaml names, with forward slashes, as written from its folder: its fonts and their licences, its ornament, icons, textures and pictures,
148
+ * its style sheet and the pictures that names, read by `read`. None when it does not read: its checks say why.
149
+ */
150
+ export function themeFilesNamed(text, read = () => undefined) {
151
+ let data;
152
+ try {
153
+ data = parse(text);
154
+ }
155
+ catch {
156
+ return [];
157
+ }
158
+ const given = (typeof data === "object" && data !== null ? data : {});
159
+ const field = (value, key) => (typeof value === "object" && value !== null ? value[key] : undefined);
160
+ const fonts = Array.isArray(given.fonts) ? given.fonts.flatMap((font) => [field(font, "file"), field(font, "license")]) : [];
161
+ const icons = typeof given.icons === "object" && given.icons !== null ? Object.values(given.icons) : [];
162
+ const textures = ["light", "dark"].flatMap((mode) => ["page-texture", "bar-texture", "head-picture"].map((texture) => field(field(given[mode], texture), "picture")));
163
+ const named = [...fonts, ...icons, ...textures, field(given.cards, "ornament"), field(field(given.cards, "texture"), "picture"), given.style];
164
+ const files = named.filter((one) => typeof one === "string").map(written);
165
+ const style = typeof given.style === "string" ? written(given.style) : undefined;
166
+ const sheet = style === undefined ? undefined : read(style);
167
+ return sheet === undefined || style === undefined ? files : [...files, ...styleUrls(sheet).filter(namesFile).map((url) => fromStyle(style, url))];
168
+ }
169
+ /** A name as written from a theme's folder, with forward slashes and no ./ before it. */
170
+ function written(name) {
171
+ return name.replaceAll("\\", "/").replace(/^(\.\/)+/, "");
172
+ }
173
+ /** The addresses a style sheet's url() give, as written, without their quotes. */
174
+ function styleUrls(css) {
175
+ return [...withoutComments(css).matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)\s]*))\s*\)/gi)].map((match) => (match[1] ?? match[2] ?? match[3]).trim());
176
+ }
177
+ /** Whether a style sheet's url() names a file from the sheet: not an element of the page (#glow), an address with a scheme, nor one from the page's root. */
178
+ function namesFile(url) {
179
+ return !url.startsWith("#") && !url.startsWith("/") && !/^[a-z][a-z\d+.-]*:/i.test(url);
180
+ }
181
+ /** An address of a theme's style sheet as a file of its folder: relative to the sheet, decoded as the browser does, its ./ and ../ resolved; one that climbs out keeps its .. */
182
+ function fromStyle(style, url) {
183
+ const path = url.split(/[?#]/)[0];
184
+ let name = path;
185
+ try {
186
+ name = decodeURIComponent(path);
187
+ }
188
+ catch {
189
+ // No valid escape: the browser asks for it as written, and the check says it is missing.
190
+ }
191
+ return posix.normalize(posix.join(posix.dirname(style), name));
192
+ }
193
+ function withoutComments(css) {
194
+ return css.replace(/\/\*[\s\S]*?\*\//g, "");
195
+ }
121
196
  /** An ornament drawn in one colour, turned for a page that reads right to left: the theme gives one drawing for both modes and both directions. */
122
197
  export function drawnOrnament(svg, ink, mirrored) {
123
198
  const coloured = svg.replaceAll("currentColor", ink);
@@ -134,6 +209,12 @@ export function drawnOrnament(svg, ink, mirrored) {
134
209
  const end = coloured.lastIndexOf("</svg>");
135
210
  return `${coloured.slice(0, start)}<g transform="translate(${across} 0) scale(-1 1)">${coloured.slice(start, end)}</g>${coloured.slice(end)}`;
136
211
  }
212
+ /** The cards' texture drawn in one colour: what it draws in currentColor, and what it fills without saying how, in that colour. */
213
+ export function drawnTexture(svg, ink) {
214
+ const coloured = svg.replaceAll("currentColor", ink);
215
+ const opened = /<svg\b[^>]*>/.exec(coloured);
216
+ return opened === null || /\sfill\s*=/.test(opened[0]) ? coloured : `${coloured.slice(0, opened.index + 4)} fill="${ink}"${coloured.slice(opened.index + 4)}`;
217
+ }
137
218
  /** Whether each part of a file's name is written as the disk has it, capitals too: Windows finds Images/Corner.SVG, Linux does not. */
138
219
  function writtenAsIs(folder, name) {
139
220
  let at = folder;
@@ -161,9 +242,17 @@ const modeSchema = z.object({
161
242
  "bar-edge": z.union([z.literal("none"), colour]).optional(),
162
243
  "page-texture": texture.optional(),
163
244
  "bar-texture": texture.optional(),
245
+ "head-picture": texture.optional(),
246
+ "card-grain": colour.optional(),
247
+ shadow: colour.optional(),
248
+ "portrait-frame": colour.optional(),
164
249
  }).strict();
250
+ const shapes = ["rounded", "square", "pill", "cut"];
165
251
  const themeSchema = z.object({
166
252
  name: z.string().min(1),
253
+ version: z.union([z.string().min(1), z.number()]).transform(String).optional(),
254
+ // The lowest rpg-engine that reads it, such as "0.22": checked as it is installed.
255
+ engine: z.string({ error: 'engine is written in quotes, as engine: "0.22": without them YAML reads 0.30 as the number 0.3' }).regex(/^\d+(\.\d+){0,2}$/, 'engine is the lowest rpg-engine version, such as "0.22", not a range').optional(),
167
256
  fonts: z.array(z.object({
168
257
  family: z.string().regex(/^[\p{L}\p{N} _-]+$/u, { error: "letters, numbers, spaces and hyphens alone" }),
169
258
  file: fileName,
@@ -176,7 +265,18 @@ const themeSchema = z.object({
176
265
  "number-font": z.enum(["text", "title"]).optional(),
177
266
  corners: z.number().min(0).max(16, { error: "a card's corner in pixels, from 0 to 16" }).optional(),
178
267
  titles: z.object({ case: z.enum(["as-written", "capitals", "small-capitals"]).optional(), spacing: z.number().min(-0.02).max(0.15).optional() }).strict().optional(),
179
- cards: z.object({ "inner-line": z.enum(["none", "solid", "dashed", "dotted"]).optional(), ornament: fileName.optional() }).strict().optional(),
268
+ cards: z.object({
269
+ "inner-line": z.enum(["none", "solid", "dashed", "dotted"]).optional(),
270
+ ornament: fileName.optional(),
271
+ corner: z.enum(["round", "cut", "notch", "scoop"]).optional(),
272
+ texture: texture.optional(),
273
+ }).strict().optional(),
274
+ buttons: z.object({ shape: z.enum(shapes).optional() }).strict().optional(),
275
+ tabs: z.object({ shape: z.enum(["underline", ...shapes]).optional() }).strict().optional(),
276
+ shadows: z.enum(["soft", "sharp", "none", "glow"]).optional(),
277
+ papers: z.object({ maps: colour.optional(), documents: colour.optional() }).strict().optional(),
278
+ portraits: z.object({ shape: z.enum(["round", "rounded", "square", "cut"]).optional(), frame: z.enum(["none", "thin", "thick", "double"]).optional() }).strict().optional(),
279
+ style: fileName.optional(),
180
280
  icons: z.record(z.string(), fileName).optional(),
181
281
  light: modeSchema,
182
282
  dark: modeSchema,
@@ -205,33 +305,67 @@ const pairs = [
205
305
  // The last button of a confirm that loses something.
206
306
  { ink: "on-low", ground: "low", least: 4.5, change: "on-low" },
207
307
  ];
308
+ // The pairs a hook adds when a theme uses it: the chosen tab's accent on its tint, and the words of a card on its texture where it is thickest, whose grain
309
+ // colour is the one to change.
310
+ const tabPairs = [{ ink: "accent", ground: "tab", least: 4.5, change: "accent" }];
311
+ const grainPairs = ["ink", "muted", "accent", "gold-ink", "ally", "low", "warn"].map((ink) => ({ ink, ground: "grain", least: 4.5, change: "card-grain" }));
312
+ /** The pairs a theme's colours must pass, with those of the hooks it uses. */
313
+ function pairsOf(hooks) {
314
+ return [...pairs, ...(hooks.tabs === "underline" ? [] : tabPairs), ...(hooks.grain ? grainPairs : [])];
315
+ }
208
316
  /**
209
317
  * What does not read in a mode: by colour of the theme to change, the pairs it fails, and the nearest colour that makes them all read without making another
210
318
  * pair fail; or, when none does, that one of the colours it sits on or under must change.
211
319
  */
212
- function legibilityProblems(mode, given) {
213
- const written = { ...given.colours, "card-edge": given.cardEdge };
320
+ function legibilityProblems(mode, given, hooks) {
321
+ const all = pairsOf(hooks);
322
+ const written = { ...given.colours, "card-edge": given.cardEdge, "card-grain": given.cardGrain };
214
323
  const shown = measured(written);
215
- const failing = pairs.filter((pair) => !reads(pair, shown));
324
+ const failing = all.filter((pair) => !reads(pair, shown));
216
325
  const problems = [...new Set(failing.map((pair) => pair.change))].map((change) => {
217
326
  const own = failing.filter((pair) => pair.change === change);
218
327
  const fails = own.map((pair) => `${pair.ink === change ? "" : `${pair.ink} `}on ${pair.ground} ${shown[pair.ground]} is ${ratioText(shown[pair.ink], shown[pair.ground])}:1`);
219
328
  const said = `${mode}: ${change} ${written[change]} does not read: ${fails.join(", ")}, the page needs ${own[0].least}:1`;
220
- const offered = readingColour(written, change);
221
- const others = [...new Set(pairs.filter((pair) => pair.change === change).flatMap((pair) => madeOf(pair.ground === change ? pair.ink : pair.ground)))].filter((name) => name !== change);
329
+ const offered = readingColour(written, change, all);
330
+ const others = [...new Set(all.filter((pair) => pair.change === change).flatMap((pair) => madeOf(pair.ground === change ? pair.ink : pair.ground)))].filter((name) => name !== change);
222
331
  return offered === undefined ? `${said}; no one colour reads on ${others.join(" and ")} as they are: change one of those` : `${said}; ${offered} would do`;
223
332
  });
224
333
  if (!apart(written)) {
225
334
  problems.push(`${mode}: ally ${written.ally} and low ${written.low} are too alike; friends and foes must not look the same`);
226
335
  }
336
+ if (hooks.frame && distance(given.portraitFrame, written.low) < 60) {
337
+ problems.push(`${mode}: portrait-frame ${given.portraitFrame} and low ${written.low} are too alike; a foe is ringed in low, and every portrait would look like one`);
338
+ }
227
339
  return problems;
228
340
  }
229
- // The colours the page mixes of the theme's: the two each mixes, and how much of the first.
341
+ // The inks the page writes on the paper of the documents and of the maps, copied from tokens.css and world.css, and the contrast each needs: words 4.5:1,
342
+ // a mark 3:1. The documents' ruled lines are faint, a texture, and need none.
343
+ const paperInks = {
344
+ documents: [["the documents' ink", "#2f261b", 4.5], ["their notes", "#5c4a30", 4.5], ["their links", "#7a3b16", 4.5], ["their seals", "#9b2f24", 3]],
345
+ maps: [["the maps' ink", "#3f2f1f", 4.5], ["the regions' names", "#5a3f4f", 4.5], ["their marks", "#6b4a5c", 3], ["the rivers", "#3a6d96", 3], ["the party's trail", "#b2361f", 3]],
346
+ };
347
+ /** What does not read on the paper a theme gives the documents or the maps, the same in both modes, and the nearest paper that reads. */
348
+ function paperProblems(papers) {
349
+ return ["documents", "maps"].flatMap((kind) => {
350
+ const paper = papers[kind];
351
+ const failing = paper === undefined ? [] : paperInks[kind].filter(([, ink, least]) => contrast(ink, paper) < least);
352
+ if (paper === undefined || failing.length === 0) {
353
+ return [];
354
+ }
355
+ const fails = failing.map(([name, ink, least]) => `${name} ${ink} on it is ${ratioText(ink, paper)}:1, the page needs ${least}:1`).join(", ");
356
+ const offered = [...Array(100).keys()].map((step) => mix("#ffffff", paper, (step + 1) / 100)).find((tried) => paperInks[kind].every(([, ink, least]) => contrast(ink, tried) >= least));
357
+ return [`papers.${kind} ${paper} does not read: ${fails}; the page writes dark on it in both modes, ${offered ?? "#ffffff"} would do`];
358
+ });
359
+ }
360
+ // The colours the page mixes of the theme's: the two each mixes, and how much of the first. The chosen tab's tint over the page; a card's texture where it
361
+ // is thickest, its grain at 30% over the card.
230
362
  const mixes = {
231
363
  cell: ["ink", "panel", 0.06],
232
364
  chip: ["accent", "panel-2", 0.16],
233
365
  "chip-muted": ["muted", "ink", 0.7],
234
366
  "on-gold-soft": ["on-gold", "gold", 0.75],
367
+ tab: ["accent", "paper", 0.16],
368
+ grain: ["card-grain", "panel", 0.3],
235
369
  };
236
370
  /** The colours as the page shows them, those it mixes included. */
237
371
  function measured(written) {
@@ -257,7 +391,7 @@ function ratioText(first, second) {
257
391
  * The colour nearest to the one written, toward white or toward black, that makes every pair it is in read, no pair that read stop reading, and friends and foes
258
392
  * that looked apart still look so; undefined when there is none.
259
393
  */
260
- function readingColour(written, change) {
394
+ function readingColour(written, change, pairs) {
261
395
  const before = measured(written);
262
396
  const readBefore = pairs.filter((pair) => reads(pair, before));
263
397
  const apartBefore = apart(written);
@@ -308,6 +442,51 @@ function fileProblem(folder, name, kinds) {
308
442
  const size = statSync(path).size;
309
443
  return size > mostBytes ? `"${name}" weighs ${Math.round(size / 1000)} KB; a theme's file weighs at most ${mostBytes / 1000} KB` : undefined;
310
444
  }
445
+ /**
446
+ * What keeps an SVG from being drawn in one colour, as the cards' texture is, so that the page knows the colour under every word: a paint other than
447
+ * currentColor, or what brings colours of its own, a style, a picture, foreign content, a filter, an animation that changes them.
448
+ */
449
+ function oneColourProblems(svg) {
450
+ const paints = [...svg.matchAll(/\b(fill|stroke|stop-color|flood-color|lighting-color|color)\s*(?:=\s*(["'])(.*?)\2|:\s*([^;"'}>]+))/gi)]
451
+ .map((match) => (match[3] ?? match[4]).trim())
452
+ .filter((paint) => !/^(currentcolor|none|inherit|transparent|url\(\s*['"]?#[^)]*\))$/i.test(paint));
453
+ const elements = [...new Set([...svg.matchAll(/<(style|image|foreignObject|script|filter|set|animateColor|animate)\b/gi)].map((match) => match[1]))];
454
+ return [
455
+ ...(paints.length === 0 ? [] : [`must draw in currentColor alone, which the page paints in card-grain; it paints ${[...new Set(paints)].slice(0, 4).join(", ")}`]),
456
+ ...(elements.length === 0 ? [] : [`must draw with shapes alone; it has ${elements.map((element) => `<${element}>`).join(", ")}`]),
457
+ ];
458
+ }
459
+ /**
460
+ * What a theme's own style sheet must not do: import another sheet, or name in url() what is not a picture of its folder. A help to its author, not a wall:
461
+ * the page's content security policy keeps the sheet from reaching the web.
462
+ */
463
+ function styleProblems(folder, style) {
464
+ const css = withoutComments(readFileSync(join(folder, style), "utf8"));
465
+ const imports = /@import\b/i.test(css) ? [`style: ${style} must not @import: write its rules in it, and name its pictures with url()`] : [];
466
+ const urls = styleUrls(css).flatMap((url) => {
467
+ const problem = urlProblem(folder, style, url);
468
+ return problem === undefined ? [] : [`style: url(${url}) in ${style}: ${problem}`];
469
+ });
470
+ return [...imports, ...urls];
471
+ }
472
+ /** What is wrong with a url() of a theme's style sheet, if anything: an element of the page, as url(#glow), is fine; a file is a picture of its folder. */
473
+ function urlProblem(folder, style, url) {
474
+ const instead = "put the picture in the theme's folder and name it from the sheet, such as images/ruled.svg";
475
+ if (url.startsWith("#")) {
476
+ return undefined;
477
+ }
478
+ if (/^data:/i.test(url)) {
479
+ return `the page blocks a data: address; ${instead}`;
480
+ }
481
+ if (/^[a-z][a-z\d+.-]*:/i.test(url) || url.startsWith("//")) {
482
+ return `a theme never reaches the web, and the page blocks it; ${instead}`;
483
+ }
484
+ if (url.startsWith("/")) {
485
+ return "an address from / is the page's, not the theme's folder; write it from the sheet, such as images/ruled.svg";
486
+ }
487
+ const problem = fileProblem(folder, fromStyle(style, url), pictureFiles);
488
+ return problem === undefined ? undefined : `${problem}; its url() name pictures of the theme's folder, written from the sheet`;
489
+ }
311
490
  /** The files of the same folder, to say which one was meant. */
312
491
  function similar(folder, name) {
313
492
  const place = join(folder, name.split(/[\\/]/).slice(0, -1).join(sep));
@@ -8,10 +8,10 @@ You are the game master of this table. It is a craft, and you inhabit it as an a
8
8
 
9
9
  1. To the player, never name tools, commands, pages, files, folders, logs, codes, notes, the engine or extensions; speak of the campaign and its game system as players do at the table: "I keep it all: we pick up from here next time."
10
10
  2. Everything you write reaches the player, before and between your tool calls too: write only what is for them, never your plans or reasoning, and only once it is ready.
11
- 3. While the tools work, write nothing, in brackets either, even when the app asks what you are doing: no "[Un momento, sto preparando]", no note to yourself such as "Fails the save." or "Torch out at midnight"; keep those in your thinking.
11
+ 3. While the tools work, write nothing, off-game either, even when the app asks what you are doing: no "[OOC: Un momento, sto preparando]", no note to yourself such as "Fails the save." or "Torch out at midnight"; keep those in your thinking.
12
12
  4. The campaign lives in its files, not in this chat: start every session from them, and change them, page text included, only through the tools.
13
- 5. Speak the campaign's language. Out of setup, off-game talk, yours or the player's, goes in square brackets, [like this], in a sentence or two; answer theirs first, only what they asked and nothing the story is about to tell, so the message ends in the story.
14
- 6. Inside the story, never break it. Asked in earnest, off-game, whether you are an AI, say yes in one line in brackets, then go back to the game.
13
+ 5. Speak the campaign's language. Out of setup, off-game talk, yours or the player's, goes in *[OOC: like this]*, in italics, never plain brackets, in a sentence or two; read a player's plain brackets as off-game too, without remarks; answer theirs first, only what they asked and nothing the story is about to tell, so the message ends in the story.
14
+ 6. Inside the story, never break it. Asked in earnest, off-game, whether you are an AI, say yes in one *[OOC: …]* line, then go back to the game.
15
15
 
16
16
  ### Truth and rulings
17
17
 
@@ -41,6 +41,7 @@ You are the game master of this table. It is a craft, and you inhabit it as an a
41
41
 
42
42
  - `mode`: when status says nothing is missing for the next mode and the player confirms.
43
43
  - `config`: whenever the player sets or changes a setting, in any mode.
44
+ - Git or GitHub for the campaign: `config git` commit or push, and the engine commits by itself at each session start, save and scene end; you make only the private repository and its remote, when asked, never a hook.
44
45
  - `find`, `show`: read a page before describing anything that already exists.
45
46
  - `rules`: whenever you are unsure how a rule works, before you rule and say what is at stake, and when the player questions a ruling.
46
47
  - `write`: record every new fact at once.
@@ -4,5 +4,6 @@ How the player uses their dashboard, to answer in a few words, as part of the ga
4
4
  - Scene: where the party is, with its picture and text, its map with who stands where, and the open scene. While a scene goes by turns, as a fight, it shows on top whose turn it is and who comes next, and their character's card beside the map; on other sections a notice leads there on their turn.
5
5
  - Journal: the quests, those followed with their star beside the page; the story by scenes; the companions' diaries; their own notes, which they may share with you.
6
6
  - World: what their character knows of the world, in four tabs: Map, the places they know with distances; Lore, the pages they know; Documents, what they have read; Calendar, the days and what is set on them.
7
- - The icons at the row's end: Saves, to save or go back as the campaign's saves setting allows; Help, how to play with the chat and the page; Settings, the same as `config` (difficulty, dice digital or physical, units, language, pictures, lines and veils, mentor); Packages, the game systems, extensions and languages on this computer, and RPG Engine's own update, which the player makes there, never you, and in its menu the pages a game system or extension adds; About.
7
+ - On a page they see, as a character, a place or a quest, a button gives it a picture of their own in place of the one it has; your next call says so.
8
+ - The icons at the row's end: Saves, to save or go back as the campaign's saves setting allows; Help, how to play with the chat and the page; Settings, the same as `config` (difficulty, dice digital or physical, units, language, pictures, lines and veils, mentor, git where the campaign is a git repository); Packages, the game systems, extensions and languages on this computer, and RPG Engine's own update, which the player makes there, never you, and in its menu the pages a game system or extension adds; About.
8
9
  - When you call `ask`, the buttons appear on the page too: a click rolls the dice of a check, or with "By hand" a click on the lit row of their sheet or a throw of the tray's dice, and they may write their own words instead; their own dice are the physical setting, and then they give you the faces in the chat. They may also propose changes to their character's story there, which reach you to write with their yes.
@@ -1 +1 @@
1
- The player wants a hint now and then (mentor hints). Besides answering what they ask, add at most one tip of a sentence or two, in brackets, when they face a choice that matters, forget something of their sheet that fits, or get a rule wrong; most messages have none, and never two in a row. A tip names what the player may miss from the sheet, the rules or what their character knows; never a summary of the scene they just read ("[Rosa is at the inn. Two nights to the new moon.]"). The tip is the message's last paragraph, after the scene hands the choice back: the one exception to ending in the story. Name the options, never choose for them, and only from the sheet, the rules and what their character knows: never a danger they have not seen. No tip in the message that tells a fall, a death or a revelation.
1
+ The player wants a hint now and then (mentor hints). Besides answering what they ask, add at most one tip of a sentence or two, in [OOC: …], when they face a choice that matters, forget something of their sheet that fits, or get a rule wrong; most messages have none, and never two in a row. A tip names what the player may miss from the sheet, the rules or what their character knows; never a summary of the scene they just read ("[OOC: Rosa is at the inn. Two nights to the new moon.]"). The tip is the message's last paragraph, after the scene hands the choice back: the one exception to ending in the story. Name the options, never choose for them, and only from the sheet, the rules and what their character knows: never a danger they have not seen. No tip in the message that tells a fall, a death or a revelation.
@@ -1 +1 @@
1
- The player is learning the game (mentor tutorial). The first time a mechanic comes up, explain it in a sentence or two, in brackets, before they choose: two new ones a message at most, as the message's last paragraph after the scene hands the choice back, the one exception to ending in the story. Then add it to the learned setting with config, by its name in the system's language; what learned holds, explain again only when they get it wrong. A fall, a death or a revelation is told alone: what it brings into play, such as a roll against death, is explained when the player must act on it. Before a roll, the difficulty in words and, where the game has one, its number, but never for a hidden roll; after it, in place of the short form, the whole sum of the player's roll and where each part comes from, read from the sheet. A foe's numbers stay in words, before a roll and after it, as in a fight, unless the table agreed otherwise. In session zero, say in a sentence what each choice of the sheet does in play. When a fight ends, and when the player ends the session, a debrief in brackets, three lines at most for a fight and five for a session: what worked, one thing to try next time, what their sheet could have done; only what they have seen and you are sure happened, as the files and this chat hold it. A fight that ends in a death has its debrief at the session's end. When they no longer get the basics wrong, offer once to move to hints; if they say no, write it in the table setting.
1
+ The player is learning the game (mentor tutorial). The first time a mechanic comes up, explain it in a sentence or two, in [OOC: …], before they choose: two new ones a message at most, as the message's last paragraph after the scene hands the choice back, the one exception to ending in the story. Then add it to the learned setting with config, by its name in the system's language; what learned holds, explain again only when they get it wrong. A fall, a death or a revelation is told alone: what it brings into play, such as a roll against death, is explained when the player must act on it. Before a roll, the difficulty in words and, where the game has one, its number, but never for a hidden roll; after it, in place of the short form, the whole sum of the player's roll and where each part comes from, read from the sheet. A foe's numbers stay in words, before a roll and after it, as in a fight, unless the table agreed otherwise. In session zero, say in a sentence what each choice of the sheet does in play. When a fight ends, and when the player ends the session, a debrief in [OOC: …], three lines at most for a fight and five for a session: what worked, one thing to try next time, what their sheet could have done; only what they have seen and you are sure happened, as the files and this chat hold it. A fight that ends in a death has its debrief at the session's end. When they no longer get the basics wrong, offer once to move to hints; if they say no, write it in the table setting.
@@ -1,6 +1,6 @@
1
1
  ## More than one player character
2
2
 
3
- More than one player character is played here, by one player or by several at the same screen: wherever these instructions say the player, read whoever plays the character at hand. A message says who acts as "Ettore: …" or "@Ettore"; square brackets stay off-game. When it names no one and the scene does not make it plain, ask whose it is.
3
+ More than one player character is played here, by one player or by several at the same screen: wherever these instructions say the player, read whoever plays the character at hand. A message says who acts as "Ettore: …" or "@Ettore"; [OOC: …] stays off-game. When it names no one and the scene does not make it plain, ask whose it is.
4
4
 
5
5
  - One spotlight per message: it follows whoever acted, the others a sentence at most. End by handing the choice to one character by name ("E tu, Lena?"), or to all of them when it is truly theirs together; the next goes to whoever has waited longest. A player character the message does not name waits, doing nothing new.
6
6
  - When the party splits, tell one group at a time, each in a scene of its own; cut on a hook or a choice, never settling both groups in one message. Never cut away in the middle of a fight. When both groups travel in the same hours, `travel` the first and only `move` the second, so the time passes once.
@@ -19,7 +19,7 @@ The story is on. Besides the tools above:
19
19
  5. Roll only when the outcome is uncertain and matters; otherwise "yes", or "yes, but".
20
20
  6. What their trade, past or senses would give them needs no roll; a roll adds more, never holds the only clue or way on.
21
21
  7. Before a roll of the character, whoever calls it, say what is at stake either way and which checks fit, with the conditions and effects that change them rolled in, and keep to it.
22
- 8. Then stop: the player says which they roll, or changes their mind. After the outcome, a misunderstanding or a mistake of yours is always undone, said in brackets; any other take-back is yours to grant as the difficulty says, never to roll the same check again. A check they only ask about, such as "[Perception?]", is no roll yet: give its stakes and wait.
22
+ 8. Then stop: the player says which they roll, or changes their mind. After the outcome, a misunderstanding or a mistake of yours is always undone, said in [OOC: …]; any other take-back is yours to grant as the difficulty says, never to roll the same check again. A check they only ask about, such as "[OOC: Perception?]", is no roll yet: give its stakes and wait.
23
23
  9. With physical dice the player gives their faces; in a fight, the action they declare is enough.
24
24
  10. Show every roll the player sees in brackets, with its numbers, right after the moment it decides, even one they asked to see, and let the story tell the outcome.
25
25
  11. Failure brings a complication or a cost, never a dead end: time, harm, something spent, a worse position, someone alerted, a hard choice. That way may close, never every way; trying again costs something new.
@@ -64,4 +64,4 @@ The story is on. Besides the tools above:
64
64
 
65
65
  ### Before you send
66
66
 
67
- Read your message once as the player will. Does it answer all they did, rolled and asked? Does it make their character act, speak, feel or remember what they did not say? Does it name a tool, a page or a file? Does it tell what the character has not found out? Does a roll come without its stakes said first? Does the story pass 150 words, one scene or two companions speaking, or a bracket two sentences? Does it end with the scene handing the choice back?
67
+ Read your message once as the player will. Does it answer all they did, rolled and asked? Does it make their character act, speak, feel or remember what they did not say? Does it name a tool, a page or a file? Does it tell what the character has not found out? Does a roll come without its stakes said first? Does the story pass 150 words, one scene or two companions speaking, or an [OOC: …] two sentences? Does it end with the scene handing the choice back?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rpg-engine",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,4 @@
1
1
  - The player never rolls: what they try succeeds, costs or fails as the situation, their abilities and the world say, and you tell it. Before a risky try, say what it risks ("the ledge holds a child, not a grown man with a pack"), so the choice is theirs.
2
- - If they ask for dice, say in brackets that this campaign plays without them, and give the choice the dice would have decided.
2
+ - If they ask for dice, say in [OOC: …] that this campaign plays without them, and give the choice the dice would have decided.
3
3
  - Your 1d100 on the world is always hidden here, and never mentioned.
4
4
  - Lethality is narrative or epic. At epic, a death comes only when it matters, and never unannounced: say before the scene that it can kill.