rpg-engine 0.7.0 → 0.8.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 (393) hide show
  1. package/dist/adventures/index.d.ts +1 -1
  2. package/dist/adventures/index.js +1 -1
  3. package/dist/adventures/source.js +13 -13
  4. package/dist/campaign/create-campaign.js +10 -1
  5. package/dist/campaign/host-files.d.ts +2 -1
  6. package/dist/campaign/host-files.js +11 -11
  7. package/dist/campaign/index.d.ts +1 -1
  8. package/dist/campaign/index.js +1 -1
  9. package/dist/campaign/settings.d.ts +55 -64
  10. package/dist/campaign/settings.js +171 -174
  11. package/dist/{cli.js → cli/cli.js} +3 -3
  12. package/dist/{command-line.d.ts → cli/command-line.d.ts} +1 -1
  13. package/dist/{command-line.js → cli/command-line.js} +21 -20
  14. package/dist/commands/advance.d.ts +1 -1
  15. package/dist/commands/advance.js +7 -7
  16. package/dist/commands/ask.d.ts +1 -8
  17. package/dist/commands/ask.js +16 -29
  18. package/dist/commands/{change.d.ts → change/change.d.ts} +2 -2
  19. package/dist/commands/{change.js → change/change.js} +46 -52
  20. package/dist/commands/{game-damage.d.ts → change/damage.d.ts} +2 -2
  21. package/dist/commands/{game-damage.js → change/damage.js} +3 -3
  22. package/dist/commands/{game-recipe-pace.d.ts → change/recipe-pace.d.ts} +2 -2
  23. package/dist/commands/{game-recipe-pace.js → change/recipe-pace.js} +4 -4
  24. package/dist/commands/config.d.ts +4 -4
  25. package/dist/commands/config.js +142 -138
  26. package/dist/commands/effect.d.ts +1 -1
  27. package/dist/commands/effect.js +11 -12
  28. package/dist/commands/find.d.ts +4 -4
  29. package/dist/commands/find.js +2 -2
  30. package/dist/commands/image.js +6 -6
  31. package/dist/commands/{import.d.ts → import/import.d.ts} +2 -2
  32. package/dist/commands/{import.js → import/import.js} +101 -101
  33. package/dist/commands/{game-import.d.ts → import/run.d.ts} +3 -3
  34. package/dist/commands/{game-import.js → import/run.js} +13 -12
  35. package/dist/commands/index.js +7 -7
  36. package/dist/commands/init.js +3 -3
  37. package/dist/commands/install.js +1 -1
  38. package/dist/commands/instructions.js +6 -6
  39. package/dist/commands/mode.d.ts +2 -2
  40. package/dist/commands/mode.js +8 -8
  41. package/dist/commands/mood.js +4 -4
  42. package/dist/commands/move.js +13 -20
  43. package/dist/commands/package.d.ts +2 -2
  44. package/dist/commands/package.js +138 -93
  45. package/dist/commands/rename.js +3 -3
  46. package/dist/commands/reveal.js +29 -18
  47. package/dist/commands/{roll.d.ts → roll/roll.d.ts} +4 -4
  48. package/dist/commands/{roll.js → roll/roll.js} +69 -69
  49. package/dist/commands/{game-tables.d.ts → roll/tables.d.ts} +2 -2
  50. package/dist/commands/{game-tables.js → roll/tables.js} +4 -4
  51. package/dist/commands/rules.d.ts +2 -2
  52. package/dist/commands/rules.js +3 -3
  53. package/dist/commands/save.d.ts +1 -1
  54. package/dist/commands/save.js +18 -18
  55. package/dist/commands/scene.d.ts +4 -4
  56. package/dist/commands/scene.js +31 -28
  57. package/dist/commands/{game-advance.d.ts → shared/advance.d.ts} +4 -4
  58. package/dist/commands/{game-advance.js → shared/advance.js} +27 -27
  59. package/dist/commands/{game-adventures.d.ts → shared/adventures.d.ts} +3 -3
  60. package/dist/commands/{game-adventures.js → shared/adventures.js} +20 -27
  61. package/dist/commands/{game-bonds.d.ts → shared/bonds.d.ts} +3 -3
  62. package/dist/commands/{game-bonds.js → shared/bonds.js} +2 -2
  63. package/dist/commands/{game-checks.d.ts → shared/checks.d.ts} +3 -3
  64. package/dist/commands/{game-checks.js → shared/checks.js} +7 -7
  65. package/dist/commands/{game-dice-pool.d.ts → shared/dice-pool.d.ts} +3 -3
  66. package/dist/commands/{game-dice-pool.js → shared/dice-pool.js} +19 -12
  67. package/dist/commands/{effect-layer.d.ts → shared/effect-layer.d.ts} +2 -2
  68. package/dist/commands/{effect-layer.js → shared/effect-layer.js} +12 -12
  69. package/dist/commands/{game-effects.d.ts → shared/effects.d.ts} +7 -7
  70. package/dist/commands/{game-effects.js → shared/effects.js} +19 -19
  71. package/dist/commands/{game-environment.d.ts → shared/environment.d.ts} +1 -1
  72. package/dist/commands/{game-environment.js → shared/environment.js} +3 -3
  73. package/dist/commands/{game-events.d.ts → shared/events.d.ts} +5 -5
  74. package/dist/commands/{game-events.js → shared/events.js} +20 -22
  75. package/dist/commands/{game-examples.d.ts → shared/examples.d.ts} +4 -8
  76. package/dist/commands/{game-examples.js → shared/examples.js} +23 -23
  77. package/dist/commands/{game-experience.d.ts → shared/experience.d.ts} +2 -2
  78. package/dist/commands/{game-experience.js → shared/experience.js} +8 -11
  79. package/dist/commands/{game-grid-moves.d.ts → shared/grid-moves.d.ts} +6 -6
  80. package/dist/commands/{game-grid-moves.js → shared/grid-moves.js} +5 -5
  81. package/dist/commands/{game-grids.d.ts → shared/grids.d.ts} +4 -9
  82. package/dist/commands/{game-grids.js → shared/grids.js} +20 -19
  83. package/dist/commands/{game-images.d.ts → shared/images.d.ts} +3 -3
  84. package/dist/commands/{game-images.js → shared/images.js} +7 -6
  85. package/dist/commands/shared/inputs.d.ts +9 -0
  86. package/dist/commands/shared/inputs.js +12 -0
  87. package/dist/commands/{game-journey.d.ts → shared/journey.d.ts} +4 -6
  88. package/dist/commands/{game-journey.js → shared/journey.js} +13 -15
  89. package/dist/commands/{game-knowledge.d.ts → shared/knowledge.d.ts} +15 -8
  90. package/dist/commands/{game-knowledge.js → shared/knowledge.js} +42 -42
  91. package/dist/{library-reader.js → commands/shared/library-reader.js} +4 -4
  92. package/dist/commands/{game-library.d.ts → shared/library.d.ts} +7 -4
  93. package/dist/commands/{game-library.js → shared/library.js} +70 -50
  94. package/dist/commands/{game-limits.d.ts → shared/limits.d.ts} +3 -3
  95. package/dist/commands/{game-limits.js → shared/limits.js} +3 -3
  96. package/dist/commands/{game-loot.d.ts → shared/loot.d.ts} +2 -2
  97. package/dist/commands/{game-loot.js → shared/loot.js} +3 -3
  98. package/dist/commands/{game-master-rolls.d.ts → shared/master-rolls.d.ts} +2 -2
  99. package/dist/commands/{game-master-rolls.js → shared/master-rolls.js} +6 -6
  100. package/dist/commands/{game-mode.d.ts → shared/mode.d.ts} +4 -6
  101. package/dist/commands/{game-mode.js → shared/mode.js} +10 -10
  102. package/dist/commands/{game-money.d.ts → shared/money.d.ts} +3 -3
  103. package/dist/commands/{game-money.js → shared/money.js} +4 -4
  104. package/dist/commands/{game-moods.d.ts → shared/moods.d.ts} +3 -3
  105. package/dist/commands/{game-moods.js → shared/moods.js} +3 -3
  106. package/dist/commands/{game-moves.d.ts → shared/moves.d.ts} +2 -2
  107. package/dist/commands/{game-moves.js → shared/moves.js} +5 -5
  108. package/dist/commands/{game-offers.d.ts → shared/offers.d.ts} +3 -3
  109. package/dist/commands/{game-offers.js → shared/offers.js} +9 -12
  110. package/dist/commands/{game-outside.d.ts → shared/outside.d.ts} +3 -3
  111. package/dist/commands/{game-outside.js → shared/outside.js} +9 -9
  112. package/dist/commands/{game-catalog.d.ts → shared/packages/catalog.d.ts} +1 -3
  113. package/dist/commands/{game-catalog.js → shared/packages/catalog.js} +17 -22
  114. package/dist/commands/{game-package-code.d.ts → shared/packages/code.d.ts} +10 -14
  115. package/dist/commands/{game-package-code.js → shared/packages/code.js} +156 -59
  116. package/dist/commands/{game-extension-list.d.ts → shared/packages/extensions.d.ts} +6 -6
  117. package/dist/commands/{game-extension-list.js → shared/packages/extensions.js} +43 -22
  118. package/dist/commands/{game-package-hooks.d.ts → shared/packages/hooks.d.ts} +3 -3
  119. package/dist/commands/{game-package-hooks.js → shared/packages/hooks.js} +3 -3
  120. package/dist/commands/{game-widgets.d.ts → shared/packages/widgets.d.ts} +6 -10
  121. package/dist/commands/{game-widgets.js → shared/packages/widgets.js} +57 -57
  122. package/dist/commands/{page-counters.d.ts → shared/page-counters.d.ts} +3 -3
  123. package/dist/commands/{page-counters.js → shared/page-counters.js} +5 -5
  124. package/dist/{page-words.d.ts → commands/shared/page-words.d.ts} +2 -2
  125. package/dist/{page-words.js → commands/shared/page-words.js} +5 -4
  126. package/dist/commands/{parts.d.ts → shared/parts.d.ts} +3 -3
  127. package/dist/commands/{parts.js → shared/parts.js} +4 -4
  128. package/dist/commands/{game-positions.d.ts → shared/positions.d.ts} +3 -5
  129. package/dist/commands/{game-positions.js → shared/positions.js} +6 -7
  130. package/dist/commands/{problems.d.ts → shared/problems.d.ts} +3 -3
  131. package/dist/commands/{problems.js → shared/problems.js} +21 -22
  132. package/dist/commands/{progression.d.ts → shared/progression.d.ts} +2 -2
  133. package/dist/commands/{progression.js → shared/progression.js} +4 -4
  134. package/dist/commands/{game-quests.d.ts → shared/quests.d.ts} +4 -4
  135. package/dist/commands/{game-quests.js → shared/quests.js} +6 -6
  136. package/dist/commands/{game-recipes.d.ts → shared/recipes.d.ts} +3 -3
  137. package/dist/commands/{game-recipes.js → shared/recipes.js} +3 -3
  138. package/dist/commands/{game-reminders.d.ts → shared/reminders.d.ts} +4 -4
  139. package/dist/commands/{game-reminders.js → shared/reminders.js} +4 -4
  140. package/dist/commands/{game-roads.d.ts → shared/roads.d.ts} +5 -5
  141. package/dist/commands/{game-roads.js → shared/roads.js} +43 -44
  142. package/dist/commands/{game-rules.d.ts → shared/rules.d.ts} +2 -2
  143. package/dist/commands/{game-rules.js → shared/rules.js} +4 -4
  144. package/dist/commands/{game-saves.d.ts → shared/saves.d.ts} +4 -4
  145. package/dist/commands/{game-saves.js → shared/saves.js} +51 -51
  146. package/dist/commands/{game-scene.d.ts → shared/scene.d.ts} +13 -3
  147. package/dist/commands/{game-scene.js → shared/scene.js} +41 -13
  148. package/dist/commands/{sheet.d.ts → shared/sheet.d.ts} +5 -5
  149. package/dist/commands/{sheet.js → shared/sheet.js} +76 -76
  150. package/dist/commands/{game-stacks.d.ts → shared/stacks.d.ts} +2 -9
  151. package/dist/commands/{game-stacks.js → shared/stacks.js} +22 -22
  152. package/dist/commands/{game-theme.d.ts → shared/theme.d.ts} +3 -3
  153. package/dist/commands/{game-theme.js → shared/theme.js} +2 -2
  154. package/dist/commands/{game-thoughts.d.ts → shared/thoughts.d.ts} +2 -4
  155. package/dist/commands/{game-thoughts.js → shared/thoughts.js} +6 -8
  156. package/dist/commands/{game-thresholds.d.ts → shared/thresholds.d.ts} +1 -1
  157. package/dist/commands/{game-thresholds.js → shared/thresholds.js} +4 -4
  158. package/dist/commands/{game-time.d.ts → shared/time.d.ts} +4 -4
  159. package/dist/commands/{game-time.js → shared/time.js} +6 -6
  160. package/dist/commands/{game-turn-uses.d.ts → shared/turn-uses.d.ts} +3 -3
  161. package/dist/commands/{game-turn-uses.js → shared/turn-uses.js} +12 -15
  162. package/dist/commands/{game-upkeep.d.ts → shared/upkeep.d.ts} +3 -3
  163. package/dist/commands/{game-upkeep.js → shared/upkeep.js} +69 -57
  164. package/dist/commands/{game-voices.d.ts → shared/voices.d.ts} +1 -1
  165. package/dist/commands/{game-voices.js → shared/voices.js} +2 -2
  166. package/dist/commands/{worked-out.d.ts → shared/worked-out.d.ts} +3 -8
  167. package/dist/commands/{worked-out.js → shared/worked-out.js} +238 -238
  168. package/dist/commands/{game-world.d.ts → shared/world.d.ts} +5 -14
  169. package/dist/commands/{game-world.js → shared/world.js} +72 -76
  170. package/dist/commands/show.d.ts +1 -1
  171. package/dist/commands/show.js +32 -17
  172. package/dist/commands/status.d.ts +1 -1
  173. package/dist/commands/status.js +28 -28
  174. package/dist/commands/thoughts.js +3 -3
  175. package/dist/commands/trade.js +9 -10
  176. package/dist/commands/translate.d.ts +1 -1
  177. package/dist/commands/translate.js +3 -3
  178. package/dist/commands/{game-open.d.ts → travel/open.d.ts} +3 -3
  179. package/dist/commands/{game-open.js → travel/open.js} +4 -5
  180. package/dist/commands/{route.d.ts → travel/route.d.ts} +1 -1
  181. package/dist/commands/{route.js → travel/route.js} +9 -10
  182. package/dist/commands/{travel.d.ts → travel/travel.d.ts} +2 -2
  183. package/dist/commands/{travel.js → travel/travel.js} +19 -21
  184. package/dist/commands/validate.js +5 -5
  185. package/dist/commands/{game-view-journal.d.ts → view/journal.d.ts} +5 -5
  186. package/dist/commands/{game-view-journal.js → view/journal.js} +5 -5
  187. package/dist/commands/{game-view-map.d.ts → view/map.d.ts} +3 -3
  188. package/dist/commands/{game-view-map.js → view/map.js} +15 -16
  189. package/dist/commands/{game-view-place.d.ts → view/place.d.ts} +6 -6
  190. package/dist/commands/{game-view-place.js → view/place.js} +108 -108
  191. package/dist/commands/{view.d.ts → view/view.d.ts} +16 -16
  192. package/dist/commands/{view.js → view/view.js} +35 -35
  193. package/dist/commands/{game-view-world.d.ts → view/world.d.ts} +4 -4
  194. package/dist/commands/{game-view-world.js → view/world.js} +7 -7
  195. package/dist/commands/{game-here.d.ts → write/here.d.ts} +5 -3
  196. package/dist/commands/{game-here.js → write/here.js} +18 -12
  197. package/dist/commands/{write.d.ts → write/write.d.ts} +6 -6
  198. package/dist/commands/{write.js → write/write.js} +44 -41
  199. package/dist/confirm/confirm.d.ts +2 -0
  200. package/dist/confirm/confirm.js +15 -5
  201. package/dist/core/consents.d.ts +3 -2
  202. package/dist/core/consents.js +43 -4
  203. package/dist/core/context.d.ts +8 -6
  204. package/dist/core/context.js +4 -2
  205. package/dist/core/download.js +16 -5
  206. package/dist/core/files.d.ts +6 -1
  207. package/dist/core/files.js +47 -21
  208. package/dist/core/formula.d.ts +7 -2
  209. package/dist/core/formula.js +63 -66
  210. package/dist/core/instruction-parts.js +1 -1
  211. package/dist/core/mood.d.ts +0 -1
  212. package/dist/core/mood.js +3 -3
  213. package/dist/core/package-api.d.ts +11 -0
  214. package/dist/core/package-api.js +2 -1
  215. package/dist/core/package-declarations.d.ts +9 -9
  216. package/dist/core/package-declarations.js +3 -3
  217. package/dist/core/process-mark.d.ts +8 -0
  218. package/dist/core/process-mark.js +72 -0
  219. package/dist/core/registry.d.ts +5 -0
  220. package/dist/core/registry.js +10 -0
  221. package/dist/core/session-store.d.ts +0 -1
  222. package/dist/core/session-store.js +11 -14
  223. package/dist/core/store.d.ts +4 -0
  224. package/dist/core/store.js +29 -8
  225. package/dist/core/text.d.ts +4 -0
  226. package/dist/core/text.js +11 -2
  227. package/dist/core/yaml-file.js +2 -2
  228. package/dist/dashboard/{acts.js → acts/acts.js} +2 -2
  229. package/dist/dashboard/{act-names.js → acts/names.js} +1 -1
  230. package/dist/dashboard/{act-sheet.js → acts/sheet.js} +3 -3
  231. package/dist/dashboard/{act-strip.js → acts/strip.js} +2 -2
  232. package/dist/dashboard/app.js +13 -13
  233. package/dist/dashboard/asked.js +1 -1
  234. package/dist/dashboard/dice/burn.js +1 -1
  235. package/dist/dashboard/dice/stage.js +1 -1
  236. package/dist/dashboard/{guide-blocks.js → help/blocks.js} +1 -1
  237. package/dist/dashboard/{help.js → help/help.js} +6 -6
  238. package/dist/dashboard/journal.js +1 -1
  239. package/dist/dashboard/kit.js +6 -5
  240. package/dist/dashboard/labels.js +7 -3
  241. package/dist/dashboard/markdown.js +1 -1
  242. package/dist/dashboard/{ask-card.js → packages/ask-card.js} +6 -6
  243. package/dist/dashboard/{package-page.js → packages/package-page.js} +3 -3
  244. package/dist/dashboard/{packages.js → packages/packages.js} +12 -12
  245. package/dist/dashboard/{page-code.js → packages/page-code.js} +4 -4
  246. package/dist/dashboard/{extension-widgets.js → packages/widgets.js} +5 -5
  247. package/dist/dashboard/party.js +1 -1
  248. package/dist/dashboard/person-panel.js +2 -13
  249. package/dist/dashboard/{map-sheet.js → place/map-sheet.js} +4 -4
  250. package/dist/dashboard/{place-map-view.js → place/map-view.js} +11 -11
  251. package/dist/dashboard/scene.js +4 -4
  252. package/dist/dashboard/settings.js +1 -1
  253. package/dist/dashboard/sheet.js +3 -3
  254. package/dist/dashboard/top.js +2 -2
  255. package/dist/dashboard/turns.js +2 -2
  256. package/dist/dashboard/widgets.js +1 -1
  257. package/dist/dashboard/{world-calendar.js → world/calendar.js} +7 -7
  258. package/dist/dashboard/{lore.js → world/known.js} +1 -1
  259. package/dist/dashboard/{world-lore.js → world/lore.js} +9 -9
  260. package/dist/dashboard/{world-map.js → world/map.js} +1 -1
  261. package/dist/dashboard/{world.js → world/world.js} +14 -14
  262. package/dist/dice/evaluate.js +1 -1
  263. package/dist/dice/index.d.ts +2 -2
  264. package/dist/dice/index.js +2 -2
  265. package/dist/dice/notation.d.ts +2 -0
  266. package/dist/dice/notation.js +22 -4
  267. package/dist/documents/markup.js +2 -2
  268. package/dist/documents/read.js +29 -13
  269. package/dist/effects/effect.js +2 -5
  270. package/dist/extensions/extension.js +6 -8
  271. package/dist/extensions/index.d.ts +1 -4
  272. package/dist/extensions/index.js +1 -4
  273. package/dist/extensions/words.js +2 -1
  274. package/dist/{pictures → helpers}/briefs.js +17 -14
  275. package/dist/{pictures → helpers}/claude.js +8 -18
  276. package/dist/{pictures → helpers}/codex.js +3 -15
  277. package/dist/helpers/index.d.ts +7 -0
  278. package/dist/helpers/index.js +9 -0
  279. package/dist/{pictures/helpers.d.ts → helpers/programs.d.ts} +6 -1
  280. package/dist/{pictures/helpers.js → helpers/programs.js} +16 -2
  281. package/dist/images/images.js +7 -5
  282. package/dist/images/index.d.ts +1 -1
  283. package/dist/images/index.js +1 -1
  284. package/dist/importer/index.d.ts +1 -1
  285. package/dist/importer/index.js +1 -1
  286. package/dist/importer/work.d.ts +0 -2
  287. package/dist/importer/work.js +9 -30
  288. package/dist/instructions/index.d.ts +2 -0
  289. package/dist/instructions/index.js +10 -0
  290. package/dist/languages/index.d.ts +1 -1
  291. package/dist/languages/index.js +1 -1
  292. package/dist/languages/language-pack.js +15 -3
  293. package/dist/library/books.js +29 -83
  294. package/dist/{extensions → packages}/engine.d.ts +1 -1
  295. package/dist/{extensions → packages}/engine.js +1 -1
  296. package/dist/packages/index.d.ts +3 -0
  297. package/dist/packages/index.js +4 -0
  298. package/dist/{extensions/packages.d.ts → packages/npm.d.ts} +2 -0
  299. package/dist/{extensions/packages.js → packages/npm.js} +74 -45
  300. package/dist/page.d.ts +9 -11
  301. package/dist/page.js +1 -2
  302. package/dist/pages/check.js +31 -40
  303. package/dist/pages/containers.js +20 -20
  304. package/dist/pages/environment.js +15 -15
  305. package/dist/pages/index.d.ts +9 -9
  306. package/dist/pages/index.js +9 -9
  307. package/dist/pages/inheritance.d.ts +2 -1
  308. package/dist/pages/inheritance.js +24 -24
  309. package/dist/pages/load.js +7 -7
  310. package/dist/pages/maps.d.ts +20 -0
  311. package/dist/pages/maps.js +51 -1
  312. package/dist/pages/markdown.d.ts +2 -0
  313. package/dist/pages/markdown.js +110 -79
  314. package/dist/pages/page-file.d.ts +2 -1
  315. package/dist/pages/page-file.js +31 -29
  316. package/dist/pages/rename-page.d.ts +4 -1
  317. package/dist/pages/rename-page.js +7 -3
  318. package/dist/pages/{stack-entry.d.ts → stacks/entry.d.ts} +0 -2
  319. package/dist/pages/{stack-entry.js → stacks/entry.js} +2 -6
  320. package/dist/pages/{stacks.d.ts → stacks/kinds.d.ts} +8 -1
  321. package/dist/pages/{stacks.js → stacks/kinds.js} +36 -41
  322. package/dist/pages/{stack-writes.d.ts → stacks/writes.d.ts} +2 -2
  323. package/dist/pages/{stack-writes.js → stacks/writes.js} +32 -32
  324. package/dist/pages/system-pages.js +15 -15
  325. package/dist/pages/world.js +25 -19
  326. package/dist/pages/write-page.js +35 -34
  327. package/dist/player-notes/index.d.ts +1 -1
  328. package/dist/player-notes/index.js +1 -1
  329. package/dist/rules/page-search.js +3 -4
  330. package/dist/rules/rule-book.js +1 -1
  331. package/dist/rules/search.js +21 -21
  332. package/dist/rules/shown.js +1 -3
  333. package/dist/saves/saves.d.ts +2 -2
  334. package/dist/saves/saves.js +15 -3
  335. package/dist/{bell-listener.js → server/bell-listener.js} +3 -3
  336. package/dist/server/dashboard/files.d.ts +59 -0
  337. package/dist/server/dashboard/files.js +326 -0
  338. package/dist/server/dashboard/index.d.ts +114 -0
  339. package/dist/server/dashboard/index.js +419 -0
  340. package/dist/server/dashboard/news.d.ts +39 -0
  341. package/dist/server/dashboard/news.js +390 -0
  342. package/dist/server/dashboard/player.d.ts +48 -0
  343. package/dist/server/dashboard/player.js +242 -0
  344. package/dist/server/dashboard/ports.d.ts +10 -0
  345. package/dist/server/dashboard/ports.js +15 -0
  346. package/dist/server/dashboard/writes.d.ts +58 -0
  347. package/dist/server/dashboard/writes.js +492 -0
  348. package/dist/{mcp-server.d.ts → server/mcp.d.ts} +2 -2
  349. package/dist/{mcp-server.js → server/mcp.js} +57 -42
  350. package/dist/systems/game-system.d.ts +5 -3
  351. package/dist/systems/game-system.js +178 -149
  352. package/dist/systems/index.d.ts +1 -1
  353. package/dist/systems/index.js +1 -1
  354. package/dist/{testing.d.ts → testing/index.d.ts} +6 -6
  355. package/dist/{testing.js → testing/index.js} +32 -18
  356. package/dist/{system-checks.js → testing/system-checks.js} +18 -12
  357. package/dist/themes/theme.d.ts +3 -3
  358. package/dist/themes/theme.js +14 -14
  359. package/dist/time/calendar.js +5 -2
  360. package/dist/triggers/trigger.js +5 -8
  361. package/instructions/dashboard-guide.md +2 -1
  362. package/instructions/play.md +1 -1
  363. package/package.json +5 -5
  364. package/dist/commands/game-maps.d.ts +0 -20
  365. package/dist/commands/game-maps.js +0 -51
  366. package/dist/dashboard-server.d.ts +0 -47
  367. package/dist/dashboard-server.js +0 -1830
  368. package/dist/pictures/index.d.ts +0 -7
  369. package/dist/pictures/index.js +0 -9
  370. /package/dist/{cli.d.ts → cli/cli.d.ts} +0 -0
  371. /package/dist/{library-reader.d.ts → commands/shared/library-reader.d.ts} +0 -0
  372. /package/dist/commands/{notes.d.ts → shared/notes.d.ts} +0 -0
  373. /package/dist/commands/{notes.js → shared/notes.js} +0 -0
  374. /package/dist/dashboard/{guide-markdown.js → help/markdown.js} +0 -0
  375. /package/dist/dashboard/{pack-card.js → packages/card.js} +0 -0
  376. /package/dist/dashboard/{people.js → packages/people.js} +0 -0
  377. /package/dist/dashboard/{place-map.js → place/map.js} +0 -0
  378. /package/dist/dashboard/{calendar.js → world/days.js} +0 -0
  379. /package/dist/{pictures → helpers}/briefs.d.ts +0 -0
  380. /package/dist/{pictures → helpers}/chosen.d.ts +0 -0
  381. /package/dist/{pictures → helpers}/chosen.js +0 -0
  382. /package/dist/{pictures → helpers}/claude.d.ts +0 -0
  383. /package/dist/{pictures → helpers}/codex.d.ts +0 -0
  384. /package/dist/{pictures → helpers}/stop.d.ts +0 -0
  385. /package/dist/{pictures → helpers}/stop.js +0 -0
  386. /package/dist/{pictures → helpers}/svg.d.ts +0 -0
  387. /package/dist/{pictures → helpers}/svg.js +0 -0
  388. /package/dist/{extensions → packages}/tarball.d.ts +0 -0
  389. /package/dist/{extensions → packages}/tarball.js +0 -0
  390. /package/dist/{bell-listener.d.ts → server/bell-listener.d.ts} +0 -0
  391. /package/dist/{player-acts.d.ts → server/player-acts.d.ts} +0 -0
  392. /package/dist/{player-acts.js → server/player-acts.js} +0 -0
  393. /package/dist/{system-checks.d.ts → testing/system-checks.d.ts} +0 -0
@@ -2,30 +2,28 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { spawn } from "node:child_process";
4
4
  import { z } from "zod";
5
- import { findCampaign, hasCharacterAgent, refreshHostFiles } from "./campaign/index.js";
6
- import { campaignExamples } from "./commands/game-examples.js";
7
- import { outsideNews, whileClosedNews } from "./commands/game-outside.js";
8
- import { packageCommands } from "./commands/game-package-code.js";
9
- import { newChatText, wentBackTo } from "./commands/game-saves.js";
10
- import { campaignWorld } from "./commands/game-world.js";
11
- import { commands } from "./commands/index.js";
12
- import { installCampaignSystem } from "./commands/package.js";
13
- import { systemConfirm } from "./confirm/index.js";
14
- import { defaultContext, packagesFolder } from "./core/context.js";
15
- import { downloadBytes } from "./core/download.js";
16
- import { neutralExamples, withExamples } from "./core/examples.js";
17
- import { SessionStore } from "./core/session-store.js";
18
- import { FileStore, withFiles } from "./core/store.js";
19
- import { getVersion } from "./core/version.js";
20
- import { startDashboard } from "./dashboard-server.js";
21
- import { systemPageReader } from "./documents/index.js";
22
- import { npmEngine, npmPackages } from "./extensions/index.js";
23
- import { hostInstructions, startInstructions } from "./instructions/index.js";
24
- import { libraryRunner } from "./library-reader.js";
25
- import { computerHelpers, hostPictures, hostReader, hostWriter } from "./pictures/index.js";
26
- import { loadSystemCode } from "./systems/index.js";
27
- // How long the player may take to click: as long as a host waits for a tool call that keeps reporting progress.
28
- const playerWait = 30 * 60 * 1000;
5
+ import { findCampaign, hasCharacterAgent, refreshHostFiles } from "../campaign/index.js";
6
+ import { commands } from "../commands/index.js";
7
+ import { installCampaignSystem } from "../commands/package.js";
8
+ import { campaignExamples } from "../commands/shared/examples.js";
9
+ import { libraryRunner } from "../commands/shared/library-reader.js";
10
+ import { outsideNews, whileClosedNews } from "../commands/shared/outside.js";
11
+ import { packageCommands } from "../commands/shared/packages/code.js";
12
+ import { newChatText, wentBackTo } from "../commands/shared/saves.js";
13
+ import { campaignWorld } from "../commands/shared/world.js";
14
+ import { systemConfirm } from "../confirm/index.js";
15
+ import { defaultContext, packagesFolder, playerWait } from "../core/context.js";
16
+ import { downloadBytes } from "../core/download.js";
17
+ import { neutralExamples, withExamples } from "../core/examples.js";
18
+ import { SessionStore } from "../core/session-store.js";
19
+ import { FileStore, withFiles } from "../core/store.js";
20
+ import { getVersion } from "../core/version.js";
21
+ import { systemPageReader } from "../documents/index.js";
22
+ import { computerHelpers, hostPictures, hostReader, hostWriter } from "../helpers/index.js";
23
+ import { hostInstructions, startInstructions } from "../instructions/index.js";
24
+ import { npmEngine, npmPackages } from "../packages/index.js";
25
+ import { loadSystemCode } from "../systems/index.js";
26
+ import { startDashboard } from "./dashboard/index.js";
29
27
  // While the player decides, the call reports progress this often, so that a host does not take it for a call that hangs.
30
28
  const progressEvery = 20 * 1000;
31
29
  // A form closed faster than anyone could read it was never shown: the host declares forms it does not show (ASK-6).
@@ -159,6 +157,14 @@ export function dashboardOpener(context, session, ports) {
159
157
  },
160
158
  };
161
159
  }
160
+ /** What a host reads of each of the core's tools in the campaign of this context's folder: its description, then its parameters', with the examples of its system (D-518). */
161
+ export function toolDescriptions(context) {
162
+ const examples = examplesFor(context, new FileStore(context.systemFolders));
163
+ return Object.fromEntries(commands.map((command) => {
164
+ const fields = Object.values(shownInput(command, examples).properties ?? {}).map((field) => field.description ?? "");
165
+ return [command.name, [withExamples(command.description, examples), ...fields].join("\n")];
166
+ }));
167
+ }
162
168
  /**
163
169
  * Reads the campaign of the server's folder, if there is one, before the first call needs it; a campaign that does not read waits for that call to say why.
164
170
  * Its start lines in AGENTS.md follow the engine, as after an update (D-97).
@@ -190,13 +196,12 @@ const firstExtensions = new WeakMap();
190
196
  function extensionTools(server, context, handler) {
191
197
  // Each tool with the package and version that give it: another one in its place is registered anew.
192
198
  const registered = new Map();
193
- const taken = commands.map((command) => command.name);
194
199
  let running = Promise.resolve();
195
200
  const sync = async () => {
196
201
  const store = context.files ?? new FileStore(context.systemFolders);
197
202
  const own = await withFiles(store, async () => {
198
203
  const root = findCampaign(context.folder);
199
- return root === undefined ? { commands: [], sources: {} } : await packageCommands(root, context, taken);
204
+ return root === undefined ? { commands: [], sources: {} } : await packageCommands(root, context);
200
205
  });
201
206
  for (const command of own.commands) {
202
207
  const kept = registered.get(command.name);
@@ -205,7 +210,13 @@ function extensionTools(server, context, handler) {
205
210
  kept.tool.remove();
206
211
  }
207
212
  if (kept === undefined || kept.source !== source) {
208
- registered.set(command.name, { tool: server.registerTool(command.name, toolConfig(command, neutralExamples), handler(command)), source });
213
+ // A command that does not register leaves the others theirs: validate names what is wrong with it.
214
+ try {
215
+ registered.set(command.name, { tool: server.registerTool(command.name, toolConfig(command, neutralExamples), handler(command)), source });
216
+ }
217
+ catch {
218
+ registered.delete(command.name);
219
+ }
209
220
  }
210
221
  else if (!kept.tool.enabled) {
211
222
  kept.tool.enable();
@@ -229,14 +240,6 @@ function toolConfig(command, examples) {
229
240
  const meta = command.alwaysLoad ? { "anthropic/alwaysLoad": true } : undefined;
230
241
  return { description: withExamples(command.description, examples), inputSchema: shownSchema(command, examples), annotations, _meta: meta };
231
242
  }
232
- /** What a host reads of each of the core's tools in the campaign of this context's folder: its description, then its parameters', with the examples of its system (D-518). */
233
- export function toolDescriptions(context) {
234
- const examples = examplesFor(context, new FileStore(context.systemFolders));
235
- return Object.fromEntries(commands.map((command) => {
236
- const fields = Object.values(shownInput(command, examples).properties ?? {}).map((field) => field.description ?? "");
237
- return [command.name, [withExamples(command.description, examples), ...fields].join("\n")];
238
- }));
239
- }
240
243
  /** The examples for the campaign of the server's folder, read through a store; neutral where it has none, or where it does not read. */
241
244
  function examplesFor(context, store) {
242
245
  try {
@@ -307,7 +310,9 @@ async function runTool(command, input, context, extra, prepare, installer, outsi
307
310
  let news;
308
311
  let changedOutside = [];
309
312
  let installed = [];
310
- // What the chat was told before the call: an answer that never goes tells nothing, so its parts are told again (D-97).
313
+ // The call tells its parts on a copy of what the chat was told, given back at its end: an answer that never goes tells nothing, so its parts are told again
314
+ // (D-97), and what a call beside it told stays told.
315
+ const before = new Set(context.told);
311
316
  const told = new Set(context.told);
312
317
  const chat = context.chat;
313
318
  const offered = chat?.dashboardOffered;
@@ -328,20 +333,24 @@ async function runTool(command, input, context, extra, prepare, installer, outsi
328
333
  // After a load the chat going on remembers what is gone: nothing runs in it, until a new chat begins with instructions (D-361).
329
334
  const back = chatAfterLoad(context, command.name, input);
330
335
  if (back.refused !== undefined) {
331
- news = context.news?.();
336
+ news = context.news?.(told);
332
337
  return { content: [{ type: "text", text: [...installed, ...(news?.lines ?? []), back.refused].join("\n\n") }], isError: true };
333
338
  }
334
339
  const checked = checkedInput(command, input, examples.shown);
340
+ // Stopped while the call was made ready, as while the system installed: the command never runs, so that calling it again does it once.
341
+ if (extra.signal.aborted) {
342
+ throw new Error("The call was stopped before it ran: nothing changed.");
343
+ }
335
344
  // What changed outside the chat comes before the command runs on it, its events fired (OUT-3).
336
345
  changedOutside = outside.take();
337
346
  // The call's own context, with its cancel, as the user stopping it (ASK-9).
338
- const text = command.format(await command.run(checked, { ...context, signal: extra.signal }));
347
+ const text = command.format(await command.run(checked, { ...context, told, signal: extra.signal }));
339
348
  // What the player changed on the dashboard comes first, once, what they changed while the call waited included (D-341).
340
- news = context.news?.();
349
+ news = context.news?.(told);
341
350
  return { content: [{ type: "text", text: [...installed, ...(news?.lines ?? []), ...changedOutside, ...back.begun, text].join("\n\n") }] };
342
351
  }
343
352
  catch (error) {
344
- news ??= context.news?.();
353
+ news ??= context.news?.(told);
345
354
  return { content: [{ type: "text", text: [...installed, ...(news?.lines ?? []), ...changedOutside, error instanceof Error ? error.message : String(error)].join("\n\n") }], isError: true };
346
355
  }
347
356
  finally {
@@ -351,12 +360,13 @@ async function runTool(command, input, context, extra, prepare, installer, outsi
351
360
  news?.restore();
352
361
  installer.giveBack(installed);
353
362
  outside.giveBack(changedOutside);
354
- context.told?.clear();
355
- told.forEach((name) => context.told?.add(name));
356
363
  if (chat !== undefined) {
357
364
  chat.dashboardOffered = offered;
358
365
  }
359
366
  }
367
+ if (!extra.signal.aborted) {
368
+ keepTold(context.told, before, told);
369
+ }
360
370
  if (chat !== undefined) {
361
371
  chat.calls--;
362
372
  chat.afterCall?.();
@@ -501,3 +511,8 @@ function reportProgress(extra, saying) {
501
511
  void extra.sendNotification({ method: "notifications/progress", params: { progressToken, progress: ++progress, message: saying() } }).catch(() => undefined);
502
512
  }, progressEvery);
503
513
  }
514
+ /** What a call told, and what it took back as no longer so, brought into what the chat was told: never what another call beside it changed. */
515
+ function keepTold(chat, before, after) {
516
+ after.forEach((name) => (before.has(name) ? undefined : chat?.add(name)));
517
+ before.forEach((name) => (after.has(name) ? undefined : chat?.delete(name)));
518
+ }
@@ -320,7 +320,6 @@ export interface GameSystem {
320
320
  icons: Record<string, string>;
321
321
  widgets: DeclaredWidget[];
322
322
  figures: Record<string, FigureSize>;
323
- /** What can break what someone keeps alive, when the game has it (EFF-14). */
324
323
  /** The lists a character binds items in, as attunement (BND-1): at most so many, each an item whose field asks for it, with the rules to read. */
325
324
  bonds: Record<string, {
326
325
  most: number;
@@ -353,6 +352,7 @@ export interface GameSystem {
353
352
  atMost: Record<string, Formula>;
354
353
  /** What damage of a type does, by the lists of who takes it (DMG-1). */
355
354
  damage?: DamageRule;
355
+ /** What can break what someone keeps alive, when the game has it (EFF-14). */
356
356
  keeping?: Keeping;
357
357
  /** What a fight follows on the dashboard (D-314). */
358
358
  combat?: CombatData;
@@ -411,8 +411,8 @@ export declare function withSettings(system: GameSystem, valueOf: (setting: stri
411
411
  export declare function rollName(system: GameSystem, dice: string, language: string): string | undefined;
412
412
  /** The systems installed in these folders, nearest folder first: each folder in them with a system.yaml. A name found twice is the nearest one. */
413
413
  export declare function installedSystems(folders: string[]): GameSystem[];
414
- /** What a campaign may add to its game system in campaign.yaml (CAM-1): its own fields, tables, formulas, counters, recipes, line of the player character and travel. */
415
- export declare const campaignDataNames: readonly ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
414
+ /** The installed game systems that read, for a list of them: one whose system.yaml does not read stops no list, and the campaign that plays it hears why. */
415
+ export declare function readableSystems(folders: string[]): GameSystem[];
416
416
  /** What campaign.yaml adds to the game system, as it writes it: checked when the system is read with it (CAM-3). */
417
417
  export type CampaignData = Partial<Record<(typeof campaignDataNames)[number], unknown>>;
418
418
  /** What an extension or the campaign adds to the game system (CAM-1, CAM-2): from where, as messages name it, and what. */
@@ -445,3 +445,5 @@ export declare function systemContentFolders(system: {
445
445
  folder: string;
446
446
  };
447
447
  }): string[];
448
+ /** What a campaign may add to its game system in campaign.yaml (CAM-1): its own fields, tables, formulas, counters, recipes, line of the player character and travel. */
449
+ export declare const campaignDataNames: readonly ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
@@ -1,7 +1,7 @@
1
1
  import { isAbsolute, join } from "node:path";
2
2
  import { z } from "zod";
3
3
  import { fieldKinds } from "../core/field-kind.js";
4
- import { formulaOf, parseFormula, readFormulas } from "../core/formula.js";
4
+ import { formulaOf, readFormulas } from "../core/formula.js";
5
5
  import { frozen } from "../core/frozen.js";
6
6
  import { readParts } from "../core/instruction-parts.js";
7
7
  import { lengthHelp, readLength, readSpeed, speedHelp } from "../core/length.js";
@@ -33,6 +33,150 @@ const rollNamePattern = /^\d*d(?:\d+|%)(?:[kd][hl]\d*)?$/i;
33
33
  const headlineFieldPattern = /\{([^{}]+)\}/g;
34
34
  // A group's icon on the dashboard: the d of an SVG path, its letters and numbers alone (D-284).
35
35
  const iconPattern = /^[Mm][MmLlHhVvCcSsQqTtAaZz\d.,\s+-]*$/;
36
+ /** The settings of a system that hold, in its order (DAT-17): those no value asks, and those a value played asks; `valueOf` gives the value played. */
37
+ export function heldSettings(system, valueOf) {
38
+ const asked = (setting) => system.settings.some((other) => other.values.some((value) => value.asks.some((name) => comparableText(name) === comparableText(setting.name))));
39
+ const held = system.settings.filter((setting) => !asked(setting));
40
+ for (let index = 0; index < held.length; index++) {
41
+ for (const name of playedValueOf(held[index], valueOf)?.asks ?? []) {
42
+ const found = system.settings.find((setting) => comparableText(setting.name) === comparableText(name));
43
+ if (found !== undefined && !held.includes(found)) {
44
+ held.push(found);
45
+ }
46
+ }
47
+ }
48
+ return system.settings.filter((setting) => held.includes(setting));
49
+ }
50
+ /** The value of a system's setting played, with what it offers and asks; undefined while it is to be chosen. */
51
+ export function playedValueOf(setting, valueOf) {
52
+ const value = valueOf(setting);
53
+ return setting.values.find((one) => value !== undefined && comparableText(one.value) === comparableText(value));
54
+ }
55
+ /** What narrows the engine's settings (DAT-16): the system, then each value played, with whom to name. */
56
+ export function engineOfferings(system, valueOf) {
57
+ return [
58
+ { from: `the game system ${system.name}`, offers: system.engineSettings },
59
+ ...heldSettings(system, valueOf).flatMap((setting) => {
60
+ const value = playedValueOf(setting, valueOf);
61
+ return value === undefined ? [] : [{ from: `${setting.name} ${value.value}`, offers: value.engineSettings }];
62
+ }),
63
+ ];
64
+ }
65
+ /** The values a game offers of an engine's setting (DAT-16): those the system and the values played share; undefined when none of them narrows it. */
66
+ export function offeredEngineValues(system, valueOf, name) {
67
+ const lists = (system === undefined ? [] : engineOfferings(system, valueOf)).flatMap((offering) => Object.entries(offering.offers).filter(([setting]) => comparableText(setting) === comparableText(name)).map(([, values]) => values));
68
+ return lists.length === 0 ? undefined : lists.reduce((shared, list) => shared.filter((value) => list.some((other) => comparableText(other) === comparableText(value))));
69
+ }
70
+ /** An engine's setting as a game plays it (DAT-16): the one value it offers, else the written one when it offers it; undefined while it is to be asked. */
71
+ export function engineSettingValue(system, valueOf, name, written) {
72
+ const offered = offeredEngineValues(system, valueOf, name);
73
+ if (offered === undefined) {
74
+ return written;
75
+ }
76
+ return offered.length === 1 ? offered[0] : offered.find((value) => typeof written === "string" && comparableText(value) === comparableText(written));
77
+ }
78
+ /**
79
+ * The system as a campaign plays it, with the values its settings have (DAT-10): the fields a value leaves out are gone from the sheet, the line, the experience
80
+ * and the rewards. A setting without a value, or with one the system lacks, leaves out nothing.
81
+ */
82
+ export function withSettings(system, valueOf) {
83
+ // A setting asked by a value the campaign does not play does not hold, nor what its value leaves out (DAT-17).
84
+ const leftOut = heldSettings(system, (setting) => valueOf(setting.name)).flatMap((setting) => {
85
+ const chosen = valueOf(setting.name);
86
+ return setting.values.find((value) => chosen !== undefined && comparableText(value.value) === comparableText(chosen))?.without ?? [];
87
+ });
88
+ if (leftOut.length === 0) {
89
+ return system;
90
+ }
91
+ const kept = (field) => !leftOut.some((name) => comparableText(name) === comparableText(field));
92
+ const progression = system.progression === undefined ? undefined : withoutExperience(system.progression, kept);
93
+ return frozen({
94
+ ...system,
95
+ sheet: system.sheet.map((group) => ({ ...group, entries: group.entries.filter((entry) => kept(entry.field)) })).filter((group) => group.entries.length > 0),
96
+ statusLine: system.statusLine.filter((entry) => kept(entry.field)),
97
+ ...(progression === undefined ? {} : { progression }),
98
+ rewards: system.rewards.filter((reward) => kept(reward.field)),
99
+ leftOut,
100
+ });
101
+ }
102
+ /**
103
+ * The name the game gives a roll of these dice, in the language asked, else in the system's (D-399): 2d20kh1, or 2d20dl1, is "with advantage" in 5e; undefined
104
+ * when the game names it not, or the dice are more than one kind.
105
+ */
106
+ export function rollName(system, dice, language) {
107
+ const names = system.rollNames[plainRoll(dice)];
108
+ return names === undefined ? undefined : (names[language] ?? names[language.split("-")[0]] ?? names[system.language]);
109
+ }
110
+ /** The systems installed in these folders, nearest folder first: each folder in them with a system.yaml. A name found twice is the nearest one. */
111
+ export function installedSystems(folders) {
112
+ const systems = [];
113
+ for (const found of systemFolders(folders)) {
114
+ if (!systems.some((system) => comparableText(system.name) === comparableText(found.name))) {
115
+ systems.push(readSystem(found.folder, found.name));
116
+ }
117
+ }
118
+ return systems;
119
+ }
120
+ /** The installed game systems that read, for a list of them: one whose system.yaml does not read stops no list, and the campaign that plays it hears why. */
121
+ export function readableSystems(folders) {
122
+ return systemFolders(folders).flatMap((found, index, all) => {
123
+ if (all.slice(0, index).some((before) => comparableText(before.name) === comparableText(found.name))) {
124
+ return [];
125
+ }
126
+ try {
127
+ return [readSystem(found.folder, found.name)];
128
+ }
129
+ catch {
130
+ return [];
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * The installed system with the layers over it, in order, the nearest to the campaign last and winning (CAM-2); a layer with which it does not read is left out,
136
+ * with why, and the others stay (CAM-3). Undefined as a system when none is installed by that name.
137
+ */
138
+ export function findCampaignSystem(folders, name, layers, ruleset) {
139
+ const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
140
+ const given = layers.filter((layer) => campaignDataNames.some((key) => layer.data[key] !== undefined && layer.data[key] !== null));
141
+ if (found === undefined) {
142
+ return { refused: [] };
143
+ }
144
+ try {
145
+ return { system: readSystem(found.folder, found.name, given, ruleset), refused: [] };
146
+ }
147
+ catch {
148
+ // One layer at a time, to leave out only those that do not read.
149
+ }
150
+ const kept = [];
151
+ const refused = [];
152
+ for (const layer of given) {
153
+ try {
154
+ readSystem(found.folder, found.name, [...kept, layer], ruleset);
155
+ kept.push(layer);
156
+ }
157
+ catch (error) {
158
+ const message = error instanceof Error ? error.message : String(error);
159
+ refused.push({ from: layer.from, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") });
160
+ }
161
+ }
162
+ return { system: readSystem(found.folder, found.name, kept, ruleset), refused };
163
+ }
164
+ /**
165
+ * The installed system with this name, ignoring case, from the nearest folder that has it, with the version of its rules asked, else its first (VER-2); undefined
166
+ * when none is. Only its own system.yaml is read, and its version's.
167
+ */
168
+ export function findSystem(folders, name, ruleset) {
169
+ const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
170
+ return found === undefined ? undefined : readSystem(found.folder, found.name, [], ruleset);
171
+ }
172
+ /** The game system in this folder by the name a campaign gives it, as installed, without a version of its rules; it throws when its system.yaml does not read. */
173
+ export function systemInFolder(folder, name) {
174
+ return readSystem(folder, name);
175
+ }
176
+ /** The folders a system's pages, rules, words, pictures and instructions come from, in order: its own, then its version's, which wins by name (VER-3). */
177
+ export function systemContentFolders(system) {
178
+ return system.version === undefined ? [system.folder] : [system.folder, system.version.folder];
179
+ }
36
180
  /** A sentence of a system's verb, with the {names} the page fills (D-514). */
37
181
  function phraseWith(names) {
38
182
  const shown = names.map((name) => `{${name}}`).join(" and ");
@@ -276,145 +420,23 @@ function settingsAsking(settings) {
276
420
  }
277
421
  return undefined;
278
422
  }
279
- /** The settings of a system that hold, in its order (DAT-17): those no value asks, and those a value played asks; `valueOf` gives the value played. */
280
- export function heldSettings(system, valueOf) {
281
- const asked = (setting) => system.settings.some((other) => other.values.some((value) => value.asks.some((name) => comparableText(name) === comparableText(setting.name))));
282
- const held = system.settings.filter((setting) => !asked(setting));
283
- for (let index = 0; index < held.length; index++) {
284
- for (const name of playedValueOf(held[index], valueOf)?.asks ?? []) {
285
- const found = system.settings.find((setting) => comparableText(setting.name) === comparableText(name));
286
- if (found !== undefined && !held.includes(found)) {
287
- held.push(found);
288
- }
289
- }
290
- }
291
- return system.settings.filter((setting) => held.includes(setting));
292
- }
293
- /** The value of a system's setting played, with what it offers and asks; undefined while it is to be chosen. */
294
- export function playedValueOf(setting, valueOf) {
295
- const value = valueOf(setting);
296
- return setting.values.find((one) => value !== undefined && comparableText(one.value) === comparableText(value));
297
- }
298
- /** What narrows the engine's settings (DAT-16): the system, then each value played, with whom to name. */
299
- export function engineOfferings(system, valueOf) {
300
- return [
301
- { from: `the game system ${system.name}`, offers: system.engineSettings },
302
- ...heldSettings(system, valueOf).flatMap((setting) => {
303
- const value = playedValueOf(setting, valueOf);
304
- return value === undefined ? [] : [{ from: `${setting.name} ${value.value}`, offers: value.engineSettings }];
305
- }),
306
- ];
307
- }
308
- /** The values a game offers of an engine's setting (DAT-16): those the system and the values played share; undefined when none of them narrows it. */
309
- export function offeredEngineValues(system, valueOf, name) {
310
- const lists = (system === undefined ? [] : engineOfferings(system, valueOf)).flatMap((offering) => Object.entries(offering.offers).filter(([setting]) => comparableText(setting) === comparableText(name)).map(([, values]) => values));
311
- return lists.length === 0 ? undefined : lists.reduce((shared, list) => shared.filter((value) => list.some((other) => comparableText(other) === comparableText(value))));
312
- }
313
- /** An engine's setting as a game plays it (DAT-16): the one value it offers, else the written one when it offers it; undefined while it is to be asked. */
314
- export function engineSettingValue(system, valueOf, name, written) {
315
- const offered = offeredEngineValues(system, valueOf, name);
316
- if (offered === undefined) {
317
- return written;
318
- }
319
- return offered.length === 1 ? offered[0] : offered.find((value) => typeof written === "string" && comparableText(value) === comparableText(written));
320
- }
321
- /**
322
- * The system as a campaign plays it, with the values its settings have (DAT-10): the fields a value leaves out are gone from the sheet, the line, the experience
323
- * and the rewards. A setting without a value, or with one the system lacks, leaves out nothing.
324
- */
325
- export function withSettings(system, valueOf) {
326
- const leftOut = system.settings.flatMap((setting) => {
327
- const chosen = valueOf(setting.name);
328
- return setting.values.find((value) => chosen !== undefined && comparableText(value.value) === comparableText(chosen))?.without ?? [];
329
- });
330
- if (leftOut.length === 0) {
331
- return system;
332
- }
333
- const kept = (field) => !leftOut.some((name) => comparableText(name) === comparableText(field));
334
- const progression = system.progression === undefined ? undefined : withoutExperience(system.progression, kept);
335
- return frozen({
336
- ...system,
337
- sheet: system.sheet.map((group) => ({ ...group, entries: group.entries.filter((entry) => kept(entry.field)) })).filter((group) => group.entries.length > 0),
338
- statusLine: system.statusLine.filter((entry) => kept(entry.field)),
339
- ...(progression === undefined ? {} : { progression }),
340
- rewards: system.rewards.filter((reward) => kept(reward.field)),
341
- leftOut,
342
- });
343
- }
344
- /**
345
- * The name the game gives a roll of these dice, in the language asked, else in the system's (D-399): 2d20kh1, or 2d20dl1, is "with advantage" in 5e; undefined
346
- * when the game names it not, or the dice are more than one kind.
347
- */
348
- export function rollName(system, dice, language) {
349
- const names = system.rollNames[plainRoll(dice)];
350
- return names === undefined ? undefined : (names[language] ?? names[language.split("-")[0] ?? language] ?? names[system.language]);
351
- }
352
423
  /** A roll's dice as a name reads them: in lower case, the highest or the lowest kept one when one of two is dropped, as 2d20dl1 is 2d20kh1. */
353
424
  function plainRoll(dice) {
354
425
  const compact = dice.toLowerCase().replace(/\s+/g, "").replace(/([kd][hl])$/, (rule) => `${rule}1`);
355
426
  return /^2d/.test(compact) ? compact.replace(/dl1$/, "kh1").replace(/dh1$/, "kl1") : compact;
356
427
  }
357
- /** The systems installed in these folders, nearest folder first: each folder in them with a system.yaml. A name found twice is the nearest one. */
358
- export function installedSystems(folders) {
359
- const systems = [];
360
- for (const found of systemFolders(folders)) {
361
- if (!systems.some((system) => comparableText(system.name) === comparableText(found.name))) {
362
- systems.push(readSystem(found.folder, found.name));
363
- }
364
- }
365
- return systems;
366
- }
367
428
  /** What a campaign may add to its game system in campaign.yaml (CAM-1): its own fields, tables, formulas, counters, recipes, line of the player character and travel. */
368
429
  export const campaignDataNames = ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
369
- /**
370
- * The installed system with the layers over it, in order, the nearest to the campaign last and winning (CAM-2); a layer with which it does not read is left out,
371
- * with why, and the others stay (CAM-3). Undefined as a system when none is installed by that name.
372
- */
373
- export function findCampaignSystem(folders, name, layers, ruleset) {
374
- const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
375
- const given = layers.filter((layer) => campaignDataNames.some((key) => layer.data[key] !== undefined && layer.data[key] !== null));
376
- if (found === undefined) {
377
- return { refused: [] };
378
- }
430
+ function readSystem(folder, name, layers = [], ruleset) {
431
+ const file = join(folder, systemFileName);
432
+ let own;
433
+ // The YAML's own error names only system.yaml: the system and its folder are said, so that one played is found and fixed.
379
434
  try {
380
- return { system: readSystem(found.folder, found.name, given, ruleset), refused: [] };
381
- }
382
- catch {
383
- // One layer at a time, to leave out only those that do not read.
435
+ own = readYamlValues(file, 'what the system is, such as "title: ..."');
384
436
  }
385
- const kept = [];
386
- const refused = [];
387
- for (const layer of given) {
388
- try {
389
- readSystem(found.folder, found.name, [...kept, layer], ruleset);
390
- kept.push(layer);
391
- }
392
- catch (error) {
393
- const message = error instanceof Error ? error.message : String(error);
394
- refused.push({ from: layer.from, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") });
395
- }
437
+ catch (error) {
438
+ throw new Error(`The game system ${name} cannot be read, because ${file} is not valid: ${error instanceof Error ? error.message : String(error)}`);
396
439
  }
397
- return { system: readSystem(found.folder, found.name, kept, ruleset), refused };
398
- }
399
- /**
400
- * The installed system with this name, ignoring case, from the nearest folder that has it, with the version of its rules asked, else its first (VER-2); undefined
401
- * when none is. Only its own system.yaml is read, and its version's.
402
- */
403
- export function findSystem(folders, name, ruleset) {
404
- const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
405
- return found === undefined ? undefined : readSystem(found.folder, found.name, [], ruleset);
406
- }
407
- /** The game system in this folder by the name a campaign gives it, as installed, without a version of its rules; it throws when its system.yaml does not read. */
408
- export function systemInFolder(folder, name) {
409
- return readSystem(folder, name);
410
- }
411
- /** The folders a system's pages, rules, words, pictures and instructions come from, in order: its own, then its version's, which wins by name (VER-3). */
412
- export function systemContentFolders(system) {
413
- return system.version === undefined ? [system.folder] : [system.folder, system.version.folder];
414
- }
415
- function readSystem(folder, name, layers = [], ruleset) {
416
- const file = join(folder, systemFileName);
417
- const own = readYamlValues(file, 'what the system is, such as "title: ..."');
418
440
  const version = chosenVersion(own, file, name, ruleset);
419
441
  const read = version === undefined ? file : `${file} with its version ${version.name}`;
420
442
  const path = layers.length === 0 ? read : `${read} with the additions of ${layers.map((layer) => layer.from).join(", ")}`;
@@ -589,12 +611,12 @@ function readSystem(folder, name, layers = [], ruleset) {
589
611
  field: data.load.field,
590
612
  // Formulas in order, the first with a value counts, as a computed field's (D-210).
591
613
  limit: Array.isArray(data.load.limit)
592
- ? { kind: "first", options: data.load.limit.map((option) => parseFormula(String(option))) }
593
- : parseFormula(data.load.limit),
614
+ ? { kind: "first", options: data.load.limit.map((option, index) => formulaAt(String(option), `load.limit.${index}`, name, path)) }
615
+ : formulaAt(data.load.limit, "load.limit", name, path),
594
616
  ...(data.load.coins === undefined ? {} : { coins: data.load.coins }),
595
617
  ...(data.load.weightless === undefined ? {} : { weightless: data.load.weightless }),
596
618
  ...(data.load.bundle === undefined ? {} : { bundle: data.load.bundle }),
597
- ...(data.load.stages === undefined ? {} : { stages: data.load.stages.map((stage) => ({ name: stage.name, formula: parseFormula(stage.when) })) }),
619
+ ...(data.load.stages === undefined ? {} : { stages: data.load.stages.map((stage) => ({ name: stage.name, formula: formulaAt(stage.when, `load.stages.${stage.name}`, name, path) })) }),
598
620
  },
599
621
  }),
600
622
  ...(data.travel === undefined ? {} : { travel: travelOf(data.travel) }),
@@ -608,8 +630,8 @@ function readSystem(folder, name, layers = [], ruleset) {
608
630
  worse: data["sheet-odds"].worse,
609
631
  when: data["sheet-odds"].when.map((when) => ({
610
632
  fields: when.fields,
611
- ...(when.better === undefined ? {} : { better: parseFormula(when.better) }),
612
- ...(when.worse === undefined ? {} : { worse: parseFormula(when.worse) }),
633
+ ...(when.better === undefined ? {} : { better: formulaAt(when.better, "sheet-odds.when.better", name, path) }),
634
+ ...(when.worse === undefined ? {} : { worse: formulaAt(when.worse, "sheet-odds.when.worse", name, path) }),
613
635
  ...(when.why === undefined ? {} : { why: when.why }),
614
636
  })),
615
637
  },
@@ -632,11 +654,11 @@ function readSystem(folder, name, layers = [], ruleset) {
632
654
  name: recipe,
633
655
  set: value.set ?? {},
634
656
  regain: regainOf(value.regain ?? {}, name, path, recipe),
635
- lower: Object.fromEntries(Object.entries(value.lower ?? {}).map(([field, amount]) => [field, parseFormula(String(amount))])),
657
+ lower: Object.fromEntries(Object.entries(value.lower ?? {}).map(([field, amount]) => [field, formulaAt(String(amount), `recipes.${recipe}.lower.${field}`, name, path)])),
636
658
  ...(value.needs === undefined ? {} : { needs: value.needs }),
637
659
  ...(value["once-per"] === undefined ? {} : { oncePer: value["once-per"] }),
638
660
  ...(value.lasts === undefined ? {} : { lasts: value.lasts }),
639
- spend: Object.fromEntries(Object.entries(value.spend ?? {}).map(([field, rule]) => [field, { gives: rule.gives, adds: parseFormula(String(rule.adds ?? 0)) }])),
661
+ spend: Object.fromEntries(Object.entries(value.spend ?? {}).map(([field, rule]) => [field, { gives: rule.gives, adds: formulaAt(String(rule.adds ?? 0), `recipes.${recipe}.spend.${field}`, name, path) }])),
640
662
  ends: value.ends ?? [],
641
663
  rules: value.rules ?? [],
642
664
  })),
@@ -650,15 +672,15 @@ function readSystem(folder, name, layers = [], ruleset) {
650
672
  burning: data.burning ?? {},
651
673
  ...(data.immune === undefined ? {} : { immune: data.immune }),
652
674
  turnUses: Object.fromEntries(Object.entries(data["turn-uses"] ?? {}).map(([use, rule]) => [use, {
653
- ...(rule.most === undefined ? {} : { most: parseFormula(String(rule.most)) }),
675
+ ...(rule.most === undefined ? {} : { most: formulaAt(String(rule.most), `turn-uses.${use}.most`, name, path) }),
654
676
  ...(rule.within === undefined ? {} : { within: rule.within }),
655
- ...(rule.needs === undefined ? {} : { needs: parseFormula(rule.needs) }),
677
+ ...(rule.needs === undefined ? {} : { needs: formulaAt(rule.needs, `turn-uses.${use}.needs`, name, path) }),
656
678
  anyTurn: rule["any-turn"] ?? false,
657
679
  resets: rule.resets ?? "own turn",
658
680
  ...(rule.note === undefined ? {} : { note: rule.note }),
659
- ...(rule["note-when"] === undefined ? {} : { noteWhen: parseFormula(rule["note-when"]) }),
681
+ ...(rule["note-when"] === undefined ? {} : { noteWhen: formulaAt(rule["note-when"], `turn-uses.${use}.note-when`, name, path) }),
660
682
  }])),
661
- atMost: Object.fromEntries(Object.entries(data["at-most"] ?? {}).map(([field, most]) => [field, parseFormula(String(most))])),
683
+ atMost: Object.fromEntries(Object.entries(data["at-most"] ?? {}).map(([field, most]) => [field, formulaAt(String(most), `at-most.${field}`, name, path)])),
662
684
  ...(data.damage === undefined ? {} : { damage: data.damage }),
663
685
  ...(data.keeping === undefined ? {} : { keeping: { counter: data.keeping.counter, conditions: data.keeping.conditions ?? [], rules: data.keeping.rules } }),
664
686
  ...(data.combat === undefined ? {} : { combat: { track: data.combat.track, inWords: data.combat["in-words"] ?? [], inactive: data.combat.inactive ?? [] } }),
@@ -701,6 +723,11 @@ function readSystem(folder, name, layers = [], ruleset) {
701
723
  function chosenVersion(own, file, name, asked) {
702
724
  const versions = isMap(own) && isMap(own.versions) ? Object.keys(own.versions).filter((key) => key !== "about") : [];
703
725
  const folder = join(file, "..");
726
+ // A version is a folder of versions/ itself, never one a path leads to out of the system.
727
+ const astray = versions.find((version) => /[\\/]/.test(version) || version.trim() === "." || version.trim() === "..");
728
+ if (astray !== undefined) {
729
+ throw new Error(`The game system ${name} cannot be read, because ${file} is not valid: versions.${astray}: a version is a folder of ${versionsFolderName}/, named such as srd-5.1.`);
730
+ }
704
731
  const unfound = versions.find((version) => files().files(join(folder, versionsFolderName, version), () => true).length === 0);
705
732
  if (unfound !== undefined) {
706
733
  throw new Error(`The game system ${name} cannot be read, because ${file} is not valid: versions.${unfound}: there is no folder ${versionsFolderName}/${unfound} with files beside it; give each version its folder, with what it changes.`);
@@ -945,14 +972,16 @@ function usesOf(data) {
945
972
  }
946
973
  /** The formulas of a recipe's regain, each read at its place (FOR-9). */
947
974
  function regainOf(regain, name, path, recipe) {
948
- return Object.fromEntries(Object.entries(regain).map(([field, amount]) => {
949
- try {
950
- return [field, formulaOf(amount)];
951
- }
952
- catch (error) {
953
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: recipes.${recipe}.regain.${field}: ${error instanceof Error ? error.message : String(error)}`);
954
- }
955
- }));
975
+ return Object.fromEntries(Object.entries(regain).map(([field, amount]) => [field, formulaAt(amount, `recipes.${recipe}.regain.${field}`, name, path)]));
976
+ }
977
+ /** A formula of a system's file, refused with the key it stands at (FOR-9). */
978
+ function formulaAt(written, place, name, path) {
979
+ try {
980
+ return formulaOf(written);
981
+ }
982
+ catch (error) {
983
+ throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${place}: ${error instanceof Error ? error.message : String(error)}`);
984
+ }
956
985
  }
957
986
  /** The formulas of a system, read once; a system whose formulas do not read cannot be read either (FOR-9). */
958
987
  function systemFormulas(data, name, path) {
@@ -1,4 +1,4 @@
1
- export { type ActVerb, actVerbs, type CampaignData, campaignDataNames, type CheckAtom, type CheckOperator, type DamageRule, engineOfferings, engineSettingValue, findCampaignSystem, findSystem, type GameSystem, type GridRules, heldSettings, installedSystems, type Lifestyle, offeredEngineValues, playedValueOf, type Recipe, type Reward, rollName, rulesetSetting, type SheetEntry, type SheetGroup, type SheetVerb, type SystemCheck, systemContentFolders, systemFileName, systemInFolder, type SystemLayer, type SystemSetting, type Threshold, type Travel, type TravelKind, type TurnUse, withSettings, } from "./game-system.ts";
1
+ export { type ActVerb, type CampaignData, campaignDataNames, type CheckAtom, type CheckOperator, type DamageRule, engineOfferings, engineSettingValue, findCampaignSystem, findSystem, type GameSystem, type GridRules, heldSettings, installedSystems, type Lifestyle, offeredEngineValues, playedValueOf, readableSystems, type Recipe, type Reward, rollName, rulesetSetting, type SheetEntry, type SheetGroup, type SheetVerb, type SystemCheck, systemContentFolders, systemFileName, systemInFolder, type SystemLayer, type SystemSetting, type Threshold, type Travel, type TravelKind, type TurnUse, withSettings, } from "./game-system.ts";
2
2
  export { givenCode, type LoadedSystemCode, loadSystemCode, systemApiProblem, systemHasCode, type SystemPackage, systemPackage, systemPageModule } from "./system-code.ts";
3
3
  export { type SystemFolder, systemFolders } from "./system-folders.ts";
4
4
  export { layeredSystemWords, type SystemWords, systemWords } from "./words.ts";