rpg-engine 0.15.0 → 0.17.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 (503) hide show
  1. package/dist/adventures/source.d.ts +3 -1
  2. package/dist/adventures/source.js +31 -1
  3. package/dist/campaign/find-campaign.js +8 -4
  4. package/dist/campaign/index.d.ts +1 -1
  5. package/dist/campaign/index.js +1 -1
  6. package/dist/campaign/settings.d.ts +6 -0
  7. package/dist/campaign/settings.js +22 -1
  8. package/dist/cli/cli.js +1 -1
  9. package/dist/cli/command-line.js +1 -1
  10. package/dist/commands/advance.d.ts +1 -1
  11. package/dist/commands/advance.js +6 -6
  12. package/dist/commands/ask.js +7 -7
  13. package/dist/commands/change/amounts.d.ts +32 -0
  14. package/dist/commands/change/amounts.js +150 -0
  15. package/dist/commands/change/change.d.ts +4 -54
  16. package/dist/commands/change/change.js +19 -749
  17. package/dist/commands/change/damage.d.ts +30 -0
  18. package/dist/commands/change/damage.js +73 -2
  19. package/dist/commands/change/dice.d.ts +34 -0
  20. package/dist/commands/change/dice.js +59 -0
  21. package/dist/commands/change/fields.d.ts +37 -0
  22. package/dist/commands/change/fields.js +156 -0
  23. package/dist/commands/change/holder.d.ts +48 -0
  24. package/dist/commands/change/holder.js +162 -0
  25. package/dist/commands/change/recipe-pace.js +1 -1
  26. package/dist/commands/change/recipe.d.ts +58 -0
  27. package/dist/commands/change/recipe.js +179 -0
  28. package/dist/commands/choices.js +3 -3
  29. package/dist/commands/config/config.d.ts +15 -0
  30. package/dist/commands/config/config.js +355 -0
  31. package/dist/commands/config/custom-levels.d.ts +7 -0
  32. package/dist/commands/config/custom-levels.js +32 -0
  33. package/dist/commands/{config.d.ts → config/dashboard.d.ts} +2 -24
  34. package/dist/commands/config/dashboard.js +171 -0
  35. package/dist/commands/config/entries.d.ts +17 -0
  36. package/dist/commands/config/entries.js +76 -0
  37. package/dist/commands/config/news.d.ts +7 -0
  38. package/dist/commands/config/news.js +88 -0
  39. package/dist/commands/config/shown.d.ts +9 -0
  40. package/dist/commands/config/shown.js +80 -0
  41. package/dist/commands/config/words.d.ts +27 -0
  42. package/dist/commands/config/words.js +204 -0
  43. package/dist/commands/effect.js +9 -9
  44. package/dist/commands/find.js +1 -1
  45. package/dist/commands/image.js +6 -6
  46. package/dist/commands/import/import.d.ts +0 -2
  47. package/dist/commands/import/import.js +68 -45
  48. package/dist/commands/import/run.js +1 -1
  49. package/dist/commands/index.js +3 -3
  50. package/dist/commands/init.js +2 -2
  51. package/dist/commands/install.js +1 -1
  52. package/dist/commands/instructions.js +6 -6
  53. package/dist/commands/mode.d.ts +2 -2
  54. package/dist/commands/mode.js +8 -8
  55. package/dist/commands/mood.js +4 -4
  56. package/dist/commands/move.js +10 -10
  57. package/dist/commands/package/consent.d.ts +11 -0
  58. package/dist/commands/package/consent.js +52 -0
  59. package/dist/commands/package/here.d.ts +51 -0
  60. package/dist/commands/package/here.js +128 -0
  61. package/dist/commands/package/install.d.ts +10 -0
  62. package/dist/commands/package/install.js +337 -0
  63. package/dist/commands/package/package.d.ts +18 -0
  64. package/dist/commands/package/package.js +270 -0
  65. package/dist/commands/package/result.d.ts +89 -0
  66. package/dist/commands/package/result.js +1 -0
  67. package/dist/commands/package/uninstall.d.ts +6 -0
  68. package/dist/commands/package/uninstall.js +70 -0
  69. package/dist/commands/rename.js +3 -3
  70. package/dist/commands/reveal.js +5 -5
  71. package/dist/commands/roll/roll.js +11 -9
  72. package/dist/commands/roll/tables.js +1 -1
  73. package/dist/commands/rules.d.ts +2 -2
  74. package/dist/commands/rules.js +3 -3
  75. package/dist/commands/save.d.ts +2 -2
  76. package/dist/commands/save.js +2 -2
  77. package/dist/commands/scene/close.d.ts +18 -0
  78. package/dist/commands/scene/close.js +179 -0
  79. package/dist/commands/scene/members.d.ts +14 -0
  80. package/dist/commands/scene/members.js +32 -0
  81. package/dist/commands/scene/open.d.ts +6 -0
  82. package/dist/commands/scene/open.js +298 -0
  83. package/dist/commands/scene/result.d.ts +98 -0
  84. package/dist/commands/scene/result.js +2 -0
  85. package/dist/commands/{scene.d.ts → scene/scene.d.ts} +10 -36
  86. package/dist/commands/scene/scene.js +210 -0
  87. package/dist/commands/scene/turns.d.ts +18 -0
  88. package/dist/commands/scene/turns.js +229 -0
  89. package/dist/commands/shared/books/adventure-layers.d.ts +89 -0
  90. package/dist/commands/shared/books/adventure-layers.js +201 -0
  91. package/dist/commands/shared/{adventures.d.ts → books/adventures.d.ts} +28 -9
  92. package/dist/commands/shared/{adventures.js → books/adventures.js} +77 -35
  93. package/dist/commands/shared/{library-reader.js → books/library-reader.js} +3 -3
  94. package/dist/commands/shared/{library.d.ts → books/library.d.ts} +2 -2
  95. package/dist/commands/shared/{library.js → books/library.js} +9 -9
  96. package/dist/commands/shared/{rules.d.ts → books/rules.d.ts} +2 -2
  97. package/dist/commands/shared/{rules.js → books/rules.js} +5 -5
  98. package/dist/commands/shared/{system-texts.d.ts → books/system-texts.d.ts} +2 -2
  99. package/dist/commands/shared/{system-texts.js → books/system-texts.js} +9 -8
  100. package/dist/commands/shared/{page-words.d.ts → books/words.d.ts} +2 -2
  101. package/dist/commands/shared/{page-words.js → books/words.js} +4 -4
  102. package/dist/commands/shared/{checks.d.ts → campaign/checks.d.ts} +3 -3
  103. package/dist/commands/shared/{checks.js → campaign/checks.js} +7 -7
  104. package/dist/commands/shared/{images.d.ts → campaign/images.d.ts} +3 -3
  105. package/dist/commands/shared/{images.js → campaign/images.js} +5 -5
  106. package/dist/commands/shared/{mode.d.ts → campaign/mode.d.ts} +4 -4
  107. package/dist/commands/shared/{mode.js → campaign/mode.js} +24 -13
  108. package/dist/commands/shared/{money.d.ts → campaign/money.d.ts} +3 -3
  109. package/dist/commands/shared/{money.js → campaign/money.js} +2 -2
  110. package/dist/commands/shared/{offers.d.ts → campaign/offers.d.ts} +3 -3
  111. package/dist/commands/shared/{offers.js → campaign/offers.js} +3 -3
  112. package/dist/commands/shared/{outside.d.ts → campaign/outside.d.ts} +3 -3
  113. package/dist/commands/shared/{outside.js → campaign/outside.js} +7 -7
  114. package/dist/commands/shared/{parts.d.ts → campaign/parts.d.ts} +3 -3
  115. package/dist/commands/shared/{parts.js → campaign/parts.js} +3 -3
  116. package/dist/commands/shared/{problems.d.ts → campaign/problems.d.ts} +3 -3
  117. package/dist/commands/shared/{problems.js → campaign/problems.js} +17 -17
  118. package/dist/commands/shared/{quests.d.ts → campaign/quests.d.ts} +4 -4
  119. package/dist/commands/shared/{quests.js → campaign/quests.js} +6 -6
  120. package/dist/commands/shared/{saves.d.ts → campaign/saves.d.ts} +4 -4
  121. package/dist/commands/shared/{saves.js → campaign/saves.js} +10 -10
  122. package/dist/commands/shared/{theme.d.ts → campaign/theme.d.ts} +3 -3
  123. package/dist/commands/shared/{theme.js → campaign/theme.js} +1 -1
  124. package/dist/commands/shared/{world.d.ts → campaign/world.d.ts} +5 -5
  125. package/dist/commands/shared/{world.js → campaign/world.js} +17 -14
  126. package/dist/commands/shared/{knowledge.d.ts → characters/knowledge.d.ts} +3 -3
  127. package/dist/commands/shared/{knowledge.js → characters/knowledge.js} +4 -4
  128. package/dist/commands/shared/{moods.d.ts → characters/moods.d.ts} +3 -3
  129. package/dist/commands/shared/{moods.js → characters/moods.js} +3 -3
  130. package/dist/commands/shared/characters/orders.d.ts +4 -0
  131. package/dist/commands/shared/characters/orders.js +10 -0
  132. package/dist/commands/shared/{thoughts.d.ts → characters/thoughts.d.ts} +9 -6
  133. package/dist/commands/shared/{thoughts.js → characters/thoughts.js} +17 -7
  134. package/dist/commands/shared/{voices.d.ts → characters/voices.d.ts} +1 -1
  135. package/dist/commands/shared/{voices.js → characters/voices.js} +2 -2
  136. package/dist/commands/shared/examples.js +2 -2
  137. package/dist/commands/shared/packages/catalog.js +2 -2
  138. package/dist/commands/shared/packages/code.d.ts +1 -1
  139. package/dist/commands/shared/packages/code.js +8 -8
  140. package/dist/commands/shared/packages/extensions.d.ts +1 -1
  141. package/dist/commands/shared/packages/extensions.js +1 -1
  142. package/dist/commands/shared/packages/hooks.d.ts +1 -1
  143. package/dist/commands/shared/packages/hooks.js +1 -1
  144. package/dist/commands/shared/packages/widgets.d.ts +3 -3
  145. package/dist/commands/shared/packages/widgets.js +3 -3
  146. package/dist/commands/shared/{environment.d.ts → places/environment.d.ts} +1 -1
  147. package/dist/commands/shared/{environment.js → places/environment.js} +4 -4
  148. package/dist/commands/shared/{grid-moves.d.ts → places/grid-moves.d.ts} +4 -4
  149. package/dist/commands/shared/{grid-moves.js → places/grid-moves.js} +8 -7
  150. package/dist/commands/shared/{grids.d.ts → places/grids.d.ts} +4 -4
  151. package/dist/commands/shared/{grids.js → places/grids.js} +6 -6
  152. package/dist/commands/shared/{journey.d.ts → places/journey.d.ts} +3 -3
  153. package/dist/commands/shared/{journey.js → places/journey.js} +6 -6
  154. package/dist/commands/shared/{moves.d.ts → places/moves.d.ts} +2 -2
  155. package/dist/commands/shared/{moves.js → places/moves.js} +4 -4
  156. package/dist/commands/shared/{positions.d.ts → places/positions.d.ts} +2 -2
  157. package/dist/commands/shared/{positions.js → places/positions.js} +4 -4
  158. package/dist/commands/shared/{roads.d.ts → places/roads.d.ts} +5 -5
  159. package/dist/commands/shared/{roads.js → places/roads.js} +6 -6
  160. package/dist/commands/shared/{effects.d.ts → scene/effects.d.ts} +7 -7
  161. package/dist/commands/shared/{effects.js → scene/effects.js} +10 -10
  162. package/dist/commands/shared/{loot.d.ts → scene/loot.d.ts} +2 -2
  163. package/dist/commands/shared/{loot.js → scene/loot.js} +3 -3
  164. package/dist/commands/shared/{master-rolls.d.ts → scene/master-rolls.d.ts} +2 -2
  165. package/dist/commands/shared/{master-rolls.js → scene/master-rolls.js} +5 -5
  166. package/dist/commands/shared/{reminders.d.ts → scene/reminders.d.ts} +4 -4
  167. package/dist/commands/shared/{reminders.js → scene/reminders.js} +4 -4
  168. package/dist/commands/shared/{scene.d.ts → scene/scene.d.ts} +3 -3
  169. package/dist/commands/shared/{scene.js → scene/scene.js} +10 -8
  170. package/dist/commands/shared/{bonds.d.ts → sheet/bonds.d.ts} +3 -3
  171. package/dist/commands/shared/{bonds.js → sheet/bonds.js} +2 -2
  172. package/dist/commands/shared/{page-counters.d.ts → sheet/counters.d.ts} +3 -3
  173. package/dist/commands/shared/{page-counters.js → sheet/counters.js} +5 -5
  174. package/dist/commands/shared/{effect-layer.d.ts → sheet/effect-layer.d.ts} +2 -2
  175. package/dist/commands/shared/{effect-layer.js → sheet/effect-layer.js} +9 -6
  176. package/dist/commands/shared/sheet/effect-values.d.ts +9 -0
  177. package/dist/commands/shared/sheet/effect-values.js +69 -0
  178. package/dist/commands/shared/{experience.d.ts → sheet/experience.d.ts} +3 -3
  179. package/dist/commands/shared/{experience.js → sheet/experience.js} +5 -5
  180. package/dist/commands/shared/sheet/formula-problems.d.ts +8 -0
  181. package/dist/commands/shared/sheet/formula-problems.js +140 -0
  182. package/dist/commands/shared/sheet/formula-scope.d.ts +32 -0
  183. package/dist/commands/shared/sheet/formula-scope.js +235 -0
  184. package/dist/commands/shared/{limits.d.ts → sheet/limits.d.ts} +3 -3
  185. package/dist/commands/shared/{limits.js → sheet/limits.js} +5 -4
  186. package/dist/commands/shared/{progression.d.ts → sheet/progression.d.ts} +2 -2
  187. package/dist/commands/shared/{progression.js → sheet/progression.js} +4 -4
  188. package/dist/commands/shared/{sheet.d.ts → sheet/sheet.d.ts} +7 -5
  189. package/dist/commands/shared/{sheet.js → sheet/sheet.js} +11 -7
  190. package/dist/commands/shared/{stacks.d.ts → sheet/stacks.d.ts} +2 -2
  191. package/dist/commands/shared/{stacks.js → sheet/stacks.js} +4 -4
  192. package/dist/commands/shared/sheet/system-fields.d.ts +21 -0
  193. package/dist/commands/shared/sheet/system-fields.js +45 -0
  194. package/dist/commands/shared/{thresholds.d.ts → sheet/thresholds.d.ts} +1 -1
  195. package/dist/commands/shared/{thresholds.js → sheet/thresholds.js} +4 -4
  196. package/dist/commands/shared/{turn-uses.d.ts → sheet/turn-uses.d.ts} +3 -3
  197. package/dist/commands/shared/{turn-uses.js → sheet/turn-uses.js} +4 -3
  198. package/dist/commands/shared/{worked-out.d.ts → sheet/worked-out.d.ts} +11 -46
  199. package/dist/commands/shared/sheet/worked-out.js +291 -0
  200. package/dist/commands/shared/sheet/worked-text.d.ts +14 -0
  201. package/dist/commands/shared/sheet/worked-text.js +55 -0
  202. package/dist/commands/shared/{advance.d.ts → time/advance.d.ts} +3 -3
  203. package/dist/commands/shared/{advance.js → time/advance.js} +11 -11
  204. package/dist/commands/shared/{dice-pool.d.ts → time/dice-pool.d.ts} +3 -3
  205. package/dist/commands/shared/{dice-pool.js → time/dice-pool.js} +11 -11
  206. package/dist/commands/shared/{events.d.ts → time/events.d.ts} +5 -5
  207. package/dist/commands/shared/{events.js → time/events.js} +10 -13
  208. package/dist/commands/shared/{recipes.d.ts → time/recipes.d.ts} +3 -3
  209. package/dist/commands/shared/{recipes.js → time/recipes.js} +6 -5
  210. package/dist/commands/shared/{time.d.ts → time/time.d.ts} +4 -4
  211. package/dist/commands/shared/{time.js → time/time.js} +6 -6
  212. package/dist/commands/shared/{upkeep.d.ts → time/upkeep.d.ts} +3 -3
  213. package/dist/commands/shared/{upkeep.js → time/upkeep.js} +14 -13
  214. package/dist/commands/show.d.ts +9 -0
  215. package/dist/commands/show.js +43 -10
  216. package/dist/commands/status.d.ts +2 -1
  217. package/dist/commands/status.js +28 -22
  218. package/dist/commands/thoughts.d.ts +1 -0
  219. package/dist/commands/thoughts.js +26 -18
  220. package/dist/commands/trade.js +8 -8
  221. package/dist/commands/translate.d.ts +1 -1
  222. package/dist/commands/translate.js +3 -3
  223. package/dist/commands/travel/open.d.ts +1 -1
  224. package/dist/commands/travel/open.js +2 -2
  225. package/dist/commands/travel/route.js +7 -6
  226. package/dist/commands/travel/travel.d.ts +1 -1
  227. package/dist/commands/travel/travel.js +8 -8
  228. package/dist/commands/validate.js +3 -3
  229. package/dist/commands/view/journal.d.ts +2 -2
  230. package/dist/commands/view/journal.js +2 -2
  231. package/dist/commands/view/layers.d.ts +34 -0
  232. package/dist/commands/view/layers.js +44 -0
  233. package/dist/commands/view/map.d.ts +1 -1
  234. package/dist/commands/view/map.js +6 -6
  235. package/dist/commands/view/memory.d.ts +16 -0
  236. package/dist/commands/view/memory.js +96 -0
  237. package/dist/commands/view/page.d.ts +32 -0
  238. package/dist/commands/view/page.js +166 -0
  239. package/dist/commands/view/place.d.ts +7 -2
  240. package/dist/commands/view/place.js +30 -12
  241. package/dist/commands/view/result.d.ts +252 -0
  242. package/dist/commands/view/result.js +1 -0
  243. package/dist/commands/view/saves.d.ts +6 -0
  244. package/dist/commands/view/saves.js +53 -0
  245. package/dist/commands/view/story.d.ts +32 -0
  246. package/dist/commands/view/story.js +227 -0
  247. package/dist/commands/view/view.d.ts +29 -292
  248. package/dist/commands/view/view.js +31 -536
  249. package/dist/commands/view/world.d.ts +1 -1
  250. package/dist/commands/view/world.js +3 -3
  251. package/dist/commands/write/checks.d.ts +42 -0
  252. package/dist/commands/write/checks.js +291 -0
  253. package/dist/commands/write/here.d.ts +1 -1
  254. package/dist/commands/write/here.js +5 -5
  255. package/dist/commands/write/inheritance.d.ts +40 -0
  256. package/dist/commands/write/inheritance.js +185 -0
  257. package/dist/commands/write/input.d.ts +29 -0
  258. package/dist/commands/write/input.js +124 -0
  259. package/dist/commands/write/layer.d.ts +44 -0
  260. package/dist/commands/write/layer.js +68 -0
  261. package/dist/commands/write/notes.d.ts +22 -0
  262. package/dist/commands/write/notes.js +76 -0
  263. package/dist/commands/write/progression.d.ts +27 -0
  264. package/dist/commands/write/progression.js +175 -0
  265. package/dist/commands/write/write.d.ts +2 -0
  266. package/dist/commands/write/write.js +36 -816
  267. package/dist/core/files.d.ts +2 -0
  268. package/dist/core/files.js +7 -0
  269. package/dist/core/{package-declarations.d.ts → packages/declarations.d.ts} +1 -1
  270. package/dist/core/{package-declarations.js → packages/declarations.js} +1 -1
  271. package/dist/core/session-store.js +3 -3
  272. package/dist/core/store.d.ts +2 -2
  273. package/dist/core/store.js +18 -4
  274. package/dist/core/text.d.ts +2 -0
  275. package/dist/core/text.js +4 -0
  276. package/dist/dashboard/acts/acts.js +1 -1
  277. package/dist/dashboard/acts/sending.js +110 -0
  278. package/dist/dashboard/acts/sheet.js +2 -2
  279. package/dist/dashboard/acts/strip.js +1 -1
  280. package/dist/dashboard/address.js +6 -0
  281. package/dist/dashboard/api.js +19 -1
  282. package/dist/dashboard/app.js +51 -171
  283. package/dist/dashboard/dice/roller.js +1 -1
  284. package/dist/dashboard/dice/sets.js +2 -2
  285. package/dist/dashboard/dice/stage.js +1 -1
  286. package/dist/dashboard/dice/tray.js +6 -6
  287. package/dist/dashboard/guide/ar.md +7 -3
  288. package/dist/dashboard/guide/cs.md +9 -5
  289. package/dist/dashboard/guide/da.md +9 -5
  290. package/dist/dashboard/guide/de.md +7 -3
  291. package/dist/dashboard/guide/el.md +9 -5
  292. package/dist/dashboard/guide/en.md +4 -0
  293. package/dist/dashboard/guide/es.md +8 -4
  294. package/dist/dashboard/guide/fi.md +9 -5
  295. package/dist/dashboard/guide/fr.md +8 -4
  296. package/dist/dashboard/guide/he.md +7 -3
  297. package/dist/dashboard/guide/hi.md +10 -6
  298. package/dist/dashboard/guide/hu.md +8 -4
  299. package/dist/dashboard/guide/is.md +9 -5
  300. package/dist/dashboard/guide/it.md +5 -1
  301. package/dist/dashboard/guide/ja.md +9 -5
  302. package/dist/dashboard/guide/ko.md +8 -4
  303. package/dist/dashboard/guide/nb.md +8 -4
  304. package/dist/dashboard/guide/nl.md +8 -4
  305. package/dist/dashboard/guide/pl.md +8 -4
  306. package/dist/dashboard/guide/pt.md +7 -3
  307. package/dist/dashboard/guide/ro.md +9 -5
  308. package/dist/dashboard/guide/ru.md +8 -4
  309. package/dist/dashboard/guide/sv.md +9 -5
  310. package/dist/dashboard/guide/tr.md +9 -5
  311. package/dist/dashboard/guide/uk.md +8 -4
  312. package/dist/dashboard/guide/zh.md +8 -4
  313. package/dist/dashboard/help/help.js +3 -3
  314. package/dist/dashboard/i18n/ar.json +29 -0
  315. package/dist/dashboard/i18n/cs.json +29 -0
  316. package/dist/dashboard/i18n/da.json +29 -0
  317. package/dist/dashboard/i18n/de.json +29 -0
  318. package/dist/dashboard/i18n/el.json +29 -0
  319. package/dist/dashboard/i18n/es.json +29 -0
  320. package/dist/dashboard/i18n/fi.json +29 -0
  321. package/dist/dashboard/i18n/fr.json +29 -0
  322. package/dist/dashboard/i18n/he.json +29 -0
  323. package/dist/dashboard/i18n/hi.json +29 -0
  324. package/dist/dashboard/i18n/hu.json +29 -0
  325. package/dist/dashboard/i18n/is.json +29 -0
  326. package/dist/dashboard/i18n/it.json +29 -0
  327. package/dist/dashboard/i18n/ja.json +30 -1
  328. package/dist/dashboard/i18n/ko.json +29 -0
  329. package/dist/dashboard/i18n/nb.json +29 -0
  330. package/dist/dashboard/i18n/nl.json +29 -0
  331. package/dist/dashboard/i18n/pl.json +29 -0
  332. package/dist/dashboard/i18n/pt.json +29 -0
  333. package/dist/dashboard/i18n/ro.json +29 -0
  334. package/dist/dashboard/i18n/ru.json +29 -0
  335. package/dist/dashboard/i18n/sv.json +29 -0
  336. package/dist/dashboard/i18n/tr.json +29 -0
  337. package/dist/dashboard/i18n/uk.json +29 -0
  338. package/dist/dashboard/i18n/zh.json +29 -0
  339. package/dist/dashboard/{journal.js → journal/journal.js} +16 -16
  340. package/dist/dashboard/{notes.js → journal/notes.js} +4 -4
  341. package/dist/dashboard/kit.js +3 -3
  342. package/dist/dashboard/packages/ask-card.js +3 -3
  343. package/dist/dashboard/packages/catalog.js +196 -0
  344. package/dist/dashboard/packages/changes.js +111 -0
  345. package/dist/dashboard/packages/engine.js +87 -0
  346. package/dist/dashboard/packages/installed.js +53 -0
  347. package/dist/dashboard/packages/library.js +97 -0
  348. package/dist/dashboard/packages/outcomes.js +45 -0
  349. package/dist/dashboard/packages/packages.js +27 -578
  350. package/dist/dashboard/packages/page-code.js +15 -2
  351. package/dist/dashboard/packages/{package-page.js → page.js} +12 -5
  352. package/dist/dashboard/packages/rows.js +84 -0
  353. package/dist/dashboard/packages/share.js +44 -0
  354. package/dist/dashboard/packages/widgets.js +3 -3
  355. package/dist/dashboard/{card.js → parts/card.js} +1 -1
  356. package/dist/dashboard/parts/changed.js +37 -0
  357. package/dist/dashboard/{faces.js → parts/faces.js} +5 -5
  358. package/dist/dashboard/{game-words.js → parts/game-words.js} +1 -1
  359. package/dist/dashboard/{icons.js → parts/icons.js} +1 -1
  360. package/dist/dashboard/{labels.js → parts/labels.js} +2 -1
  361. package/dist/dashboard/{map-symbols.js → parts/map-symbols.js} +1 -1
  362. package/dist/dashboard/{markdown.js → parts/markdown.js} +2 -2
  363. package/dist/dashboard/{mood.js → parts/mood.js} +1 -1
  364. package/dist/dashboard/{refusals.js → parts/refusals.js} +5 -1
  365. package/dist/dashboard/{status.js → parts/status.js} +4 -4
  366. package/dist/dashboard/{widgets.js → parts/widgets.js} +5 -3
  367. package/dist/dashboard/place/key.js +24 -0
  368. package/dist/dashboard/place/paper.js +67 -0
  369. package/dist/dashboard/place/{map-sheet.js → sheet.js} +2 -2
  370. package/dist/dashboard/place/things.js +129 -0
  371. package/dist/dashboard/place/tokens.js +93 -0
  372. package/dist/dashboard/place/view.js +124 -0
  373. package/dist/dashboard/{asked-dice.js → play/asked-dice.js} +3 -3
  374. package/dist/dashboard/{asked.js → play/asked.js} +10 -10
  375. package/dist/dashboard/{choices.js → play/choices.js} +11 -10
  376. package/dist/dashboard/{requested.js → play/requested.js} +1 -1
  377. package/dist/dashboard/{rolls.js → play/rolls.js} +9 -9
  378. package/dist/dashboard/{scene.js → play/scene.js} +14 -14
  379. package/dist/dashboard/{turns.js → play/turns.js} +12 -12
  380. package/dist/dashboard/{language-choice.js → settings/language-choice.js} +1 -1
  381. package/dist/dashboard/{languages.js → settings/languages.js} +1 -1
  382. package/dist/dashboard/{saves.js → settings/saves.js} +8 -8
  383. package/dist/dashboard/{settings.js → settings/settings.js} +17 -15
  384. package/dist/dashboard/{setup.js → settings/setup.js} +5 -5
  385. package/dist/dashboard/{party.js → sheet/party.js} +8 -8
  386. package/dist/dashboard/{person-panel.js → sheet/person-panel.js} +4 -4
  387. package/dist/dashboard/{sheet.js → sheet/sheet.js} +27 -24
  388. package/dist/dashboard/{story.js → sheet/story.js} +3 -3
  389. package/dist/dashboard/{columns.js → shell/columns.js} +1 -1
  390. package/dist/dashboard/{footer.js → shell/footer.js} +3 -3
  391. package/dist/dashboard/{master.js → shell/master.js} +2 -2
  392. package/dist/dashboard/{notices.js → shell/notices.js} +3 -3
  393. package/dist/dashboard/{pages.js → shell/pages.js} +5 -5
  394. package/dist/dashboard/shell/shown.js +38 -0
  395. package/dist/dashboard/{table.js → shell/table.js} +2 -2
  396. package/dist/dashboard/{tabs.js → shell/tabs.js} +2 -2
  397. package/dist/dashboard/{top.js → shell/top.js} +7 -7
  398. package/dist/dashboard/style.css +288 -4
  399. package/dist/dashboard/world/calendar.js +4 -4
  400. package/dist/dashboard/world/drawing.js +92 -0
  401. package/dist/dashboard/world/key.js +21 -0
  402. package/dist/dashboard/world/lore.js +10 -6
  403. package/dist/dashboard/world/map-card.js +186 -0
  404. package/dist/dashboard/world/place-card.js +39 -0
  405. package/dist/dashboard/world/places.js +29 -0
  406. package/dist/dashboard/world/world.js +9 -341
  407. package/dist/extensions/extension.d.ts +1 -1
  408. package/dist/extensions/extension.js +1 -1
  409. package/dist/images/images.js +12 -9
  410. package/dist/index.d.ts +1 -1
  411. package/dist/languages/index.d.ts +1 -1
  412. package/dist/languages/index.js +1 -1
  413. package/dist/packages/npm.js +1 -1
  414. package/dist/page.d.ts +2 -2
  415. package/dist/page.js +1 -1
  416. package/dist/pages/check.js +23 -1
  417. package/dist/pages/containers.d.ts +1 -1
  418. package/dist/pages/containers.js +1 -1
  419. package/dist/pages/index.d.ts +4 -2
  420. package/dist/pages/index.js +4 -2
  421. package/dist/pages/inheritance.d.ts +2 -2
  422. package/dist/pages/layers.d.ts +52 -0
  423. package/dist/pages/layers.js +105 -0
  424. package/dist/pages/markdown.d.ts +5 -1
  425. package/dist/pages/markdown.js +13 -1
  426. package/dist/pages/rename-page.js +1 -1
  427. package/dist/pages/stacks/writes.js +48 -22
  428. package/dist/pages/standard-fields.d.ts +1 -1
  429. package/dist/pages/system-pages.d.ts +5 -3
  430. package/dist/pages/system-pages.js +16 -7
  431. package/dist/pages/world.d.ts +8 -1
  432. package/dist/pages/world.js +16 -4
  433. package/dist/pages/write-layer.d.ts +23 -0
  434. package/dist/pages/write-layer.js +162 -0
  435. package/dist/pages/write-page.d.ts +2 -2
  436. package/dist/pages/write-page.js +2 -2
  437. package/dist/rules/index.d.ts +1 -1
  438. package/dist/rules/index.js +1 -1
  439. package/dist/rules/search.d.ts +1 -1
  440. package/dist/rules/shown.d.ts +1 -1
  441. package/dist/server/dashboard/choices.d.ts +2 -0
  442. package/dist/server/dashboard/choices.js +6 -4
  443. package/dist/server/dashboard/files.js +5 -5
  444. package/dist/server/dashboard/index.d.ts +2 -2
  445. package/dist/server/dashboard/index.js +7 -3
  446. package/dist/server/dashboard/news.js +4 -3
  447. package/dist/server/dashboard/player.js +1 -1
  448. package/dist/server/dashboard/writes.d.ts +7 -0
  449. package/dist/server/dashboard/writes.js +48 -7
  450. package/dist/server/mcp.js +28 -13
  451. package/dist/systems/campaign-data.d.ts +15 -0
  452. package/dist/systems/campaign-data.js +85 -0
  453. package/dist/systems/{system-code.d.ts → code.d.ts} +1 -1
  454. package/dist/systems/{system-code.js → code.js} +2 -2
  455. package/dist/systems/game-system.d.ts +7 -61
  456. package/dist/systems/game-system.js +1 -984
  457. package/dist/systems/index.d.ts +6 -3
  458. package/dist/systems/index.js +6 -3
  459. package/dist/systems/installed.d.ts +31 -0
  460. package/dist/systems/installed.js +89 -0
  461. package/dist/systems/maps.d.ts +3 -0
  462. package/dist/systems/maps.js +9 -0
  463. package/dist/systems/read.d.ts +3 -0
  464. package/dist/systems/read.js +471 -0
  465. package/dist/systems/schema.d.ts +289 -0
  466. package/dist/systems/schema.js +243 -0
  467. package/dist/systems/settings.d.ts +19 -0
  468. package/dist/systems/settings.js +78 -0
  469. package/dist/systems/versions.d.ts +12 -0
  470. package/dist/systems/versions.js +52 -0
  471. package/dist/testing/index.js +1 -1
  472. package/instructions/import.md +1 -1
  473. package/instructions/play.md +1 -1
  474. package/instructions/voices.md +1 -1
  475. package/package.json +1 -1
  476. package/dist/commands/config.js +0 -948
  477. package/dist/commands/package.d.ts +0 -143
  478. package/dist/commands/package.js +0 -785
  479. package/dist/commands/scene.js +0 -894
  480. package/dist/commands/shared/worked-out.js +0 -805
  481. package/dist/dashboard/place/map-view.js +0 -417
  482. /package/dist/commands/shared/{library-reader.d.ts → books/library-reader.d.ts} +0 -0
  483. /package/dist/core/{package-api.d.ts → packages/api.d.ts} +0 -0
  484. /package/dist/core/{package-api.js → packages/api.js} +0 -0
  485. /package/dist/dashboard/{coins.js → parts/coins.js} +0 -0
  486. /package/dist/dashboard/{glass.js → parts/glass.js} +0 -0
  487. /package/dist/dashboard/{layout.js → parts/layout.js} +0 -0
  488. /package/dist/dashboard/{mood-faces.js → parts/mood-faces.js} +0 -0
  489. /package/dist/dashboard/{free-rolls.js → play/free-rolls.js} +0 -0
  490. /package/dist/dashboard/{reactions.js → play/reactions.js} +0 -0
  491. /package/dist/dashboard/{prefs.js → shell/prefs.js} +0 -0
  492. /package/dist/dashboard/{system-style.js → shell/system-style.js} +0 -0
  493. /package/dist/dashboard/{theme.js → shell/theme.js} +0 -0
  494. /package/dist/languages/{language-pack.d.ts → pack.d.ts} +0 -0
  495. /package/dist/languages/{language-pack.js → pack.js} +0 -0
  496. /package/dist/pages/{page-file.d.ts → file.d.ts} +0 -0
  497. /package/dist/pages/{page-file.js → file.js} +0 -0
  498. /package/dist/pages/{page-types.d.ts → types.d.ts} +0 -0
  499. /package/dist/pages/{page-types.js → types.js} +0 -0
  500. /package/dist/rules/{rule-book.d.ts → book.d.ts} +0 -0
  501. /package/dist/rules/{rule-book.js → book.js} +0 -0
  502. /package/dist/systems/{system-folders.d.ts → folders.d.ts} +0 -0
  503. /package/dist/systems/{system-folders.js → folders.js} +0 -0
@@ -1,105 +1,14 @@
1
- import { isAbsolute, join } from "node:path";
2
- import { z } from "zod";
3
- import { fieldKinds } from "../core/field-kind.js";
4
- import { formulaOf, readFormulas } from "../core/formula.js";
5
- import { frozen } from "../core/frozen.js";
6
- import { readParts } from "../core/instruction-parts.js";
7
1
  import { codeAndBase } from "../core/language.js";
8
- import { lengthHelp, readLength, readSpeed, speedHelp } from "../core/length.js";
9
- import { declaredWidgets, packagePartsIssues, packagePartsShape } from "../core/package-declarations.js";
10
- import { files } from "../core/store.js";
11
- import { comparableText, sameName } from "../core/text.js";
12
- import { readYamlValues } from "../core/yaml-file.js";
13
- import { systemApiProblem, systemHasCode } from "./system-code.js";
14
- import { systemFolders } from "./system-folders.js";
15
2
  /** The file that makes a folder a game system and says what it is. */
16
3
  export const systemFileName = "system.yaml";
17
4
  /** The setting by which a campaign plays one of the versions of its system's rules (VER-1): the engine's name for it, whatever the system. */
18
5
  export const rulesetSetting = "ruleset";
19
- // The folder that holds a system's versions of its rules, each in a folder named after it (VER-1).
20
- const versionsFolderName = "versions";
21
6
  /**
22
7
  * What the player does with an item of the sheet on the dashboard, said as their own sentence to the master (D-495): the engine's verbs, whose sentences
23
8
  * the page has in every language; a system declares its own beside them in sheet-verbs (D-514), and says which fields take which. Talking to someone comes
24
9
  * from the people, never from the sheet.
25
10
  */
26
11
  export const actVerbs = ["attack", "use", "equip", "unequip"];
27
- // An entry of the sheet: a field, ? when it is written only when it applies, and a field shown beside it in parentheses.
28
- const sheetEntryPattern = /^([^\s()?]+)(\?)?(?: \(([^\s()?]+)\))?$/;
29
- // The dice a number of the sheet is rolled with: dice alone, as 1d20 or 2d6+1d4 (D-280).
30
- const sheetDicePattern = /^\d*d\d+(?:\+\d*d\d+)*$/;
31
- // A roll the game has a name for: dice of one kind, with the highest or the lowest kept or dropped, as 2d20kh1 (D-399).
32
- const rollNamePattern = /^\d*d(?:\d+|%)(?:[kd][hl]\d*)?$/i;
33
- // A field named in the headline under a character's name: {level} (D-288).
34
- const headlineFieldPattern = /\{([^{}]+)\}/g;
35
- // A group's icon on the dashboard: the d of an SVG path, its letters and numbers alone (D-284).
36
- const iconPattern = /^[Mm][MmLlHhVvCcSsQqTtAaZz\d.,\s+-]*$/;
37
- /** 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. */
38
- export function heldSettings(system, valueOf) {
39
- const asked = (setting) => system.settings.some((other) => other.values.some((value) => value.asks.some((name) => comparableText(name) === comparableText(setting.name))));
40
- const held = system.settings.filter((setting) => !asked(setting));
41
- for (let index = 0; index < held.length; index++) {
42
- for (const name of playedValueOf(held[index], valueOf)?.asks ?? []) {
43
- const found = system.settings.find((setting) => comparableText(setting.name) === comparableText(name));
44
- if (found !== undefined && !held.includes(found)) {
45
- held.push(found);
46
- }
47
- }
48
- }
49
- return system.settings.filter((setting) => held.includes(setting));
50
- }
51
- /** The value of a system's setting played, with what it offers and asks; undefined while it is to be chosen. */
52
- export function playedValueOf(setting, valueOf) {
53
- const value = valueOf(setting);
54
- return setting.values.find((one) => value !== undefined && comparableText(one.value) === comparableText(value));
55
- }
56
- /** What narrows the engine's settings (DAT-16): the system, then each value played, with whom to name. */
57
- export function engineOfferings(system, valueOf) {
58
- return [
59
- { from: `the game system ${system.name}`, offers: system.engineSettings },
60
- ...heldSettings(system, valueOf).flatMap((setting) => {
61
- const value = playedValueOf(setting, valueOf);
62
- return value === undefined ? [] : [{ from: `${setting.name} ${value.value}`, offers: value.engineSettings }];
63
- }),
64
- ];
65
- }
66
- /** 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. */
67
- export function offeredEngineValues(system, valueOf, name) {
68
- const lists = (system === undefined ? [] : engineOfferings(system, valueOf)).flatMap((offering) => Object.entries(offering.offers).filter(([setting]) => comparableText(setting) === comparableText(name)).map(([, values]) => values));
69
- return lists.length === 0 ? undefined : lists.reduce((shared, list) => shared.filter((value) => list.some((other) => comparableText(other) === comparableText(value))));
70
- }
71
- /** 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. */
72
- export function engineSettingValue(system, valueOf, name, written) {
73
- const offered = offeredEngineValues(system, valueOf, name);
74
- if (offered === undefined) {
75
- return written;
76
- }
77
- return offered.length === 1 ? offered[0] : offered.find((value) => typeof written === "string" && comparableText(value) === comparableText(written));
78
- }
79
- /**
80
- * 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
81
- * and the rewards. A setting without a value, or with one the system lacks, leaves out nothing.
82
- */
83
- export function withSettings(system, valueOf) {
84
- // A setting asked by a value the campaign does not play does not hold, nor what its value leaves out (DAT-17).
85
- const leftOut = heldSettings(system, (setting) => valueOf(setting.name)).flatMap((setting) => {
86
- const chosen = valueOf(setting.name);
87
- return setting.values.find((value) => chosen !== undefined && comparableText(value.value) === comparableText(chosen))?.without ?? [];
88
- });
89
- if (leftOut.length === 0) {
90
- return system;
91
- }
92
- const kept = (field) => !leftOut.some((name) => comparableText(name) === comparableText(field));
93
- const progression = system.progression === undefined ? undefined : withoutExperience(system.progression, kept);
94
- return frozen({
95
- ...system,
96
- sheet: system.sheet.map((group) => ({ ...group, entries: group.entries.filter((entry) => kept(entry.field)) })).filter((group) => group.entries.length > 0),
97
- statusLine: system.statusLine.filter((entry) => kept(entry.field)),
98
- ...(progression === undefined ? {} : { progression }),
99
- rewards: system.rewards.filter((reward) => kept(reward.field)),
100
- leftOut,
101
- });
102
- }
103
12
  /**
104
13
  * 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
105
14
  * when the game names it not, or the dice are more than one kind.
@@ -108,900 +17,8 @@ export function rollName(system, dice, language) {
108
17
  const names = system.rollNames[plainRoll(dice)];
109
18
  return names === undefined ? undefined : ([language, ...codeAndBase(language).slice(1)].map((code) => names[code]).find((name) => name !== undefined) ?? names[system.language]);
110
19
  }
111
- /** 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. */
112
- export function installedSystems(folders) {
113
- const systems = [];
114
- for (const found of systemFolders(folders)) {
115
- if (!systems.some((system) => comparableText(system.name) === comparableText(found.name))) {
116
- systems.push(readSystem(found.folder, found.name));
117
- }
118
- }
119
- return systems;
120
- }
121
- /** 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. */
122
- export function readableSystems(folders) {
123
- return systemFolders(folders).flatMap((found, index, all) => {
124
- if (all.slice(0, index).some((before) => comparableText(before.name) === comparableText(found.name))) {
125
- return [];
126
- }
127
- try {
128
- return [readSystem(found.folder, found.name)];
129
- }
130
- catch {
131
- return [];
132
- }
133
- });
134
- }
135
- /**
136
- * 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,
137
- * with why, and the others stay (CAM-3). Undefined as a system when none is installed by that name.
138
- */
139
- export function findCampaignSystem(folders, name, layers, ruleset) {
140
- const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
141
- const given = layers.filter((layer) => campaignDataNames.some((key) => layer.data[key] !== undefined && layer.data[key] !== null));
142
- if (found === undefined) {
143
- return { refused: [] };
144
- }
145
- try {
146
- return { system: readSystem(found.folder, found.name, given, ruleset), refused: [] };
147
- }
148
- catch {
149
- // One layer at a time, to leave out only those that do not read.
150
- }
151
- const kept = [];
152
- const refused = [];
153
- for (const layer of given) {
154
- try {
155
- readSystem(found.folder, found.name, [...kept, layer], ruleset);
156
- kept.push(layer);
157
- }
158
- catch (error) {
159
- const message = error instanceof Error ? error.message : String(error);
160
- refused.push({ from: layer.from, problem: message.replace(/^The game system .*? cannot be read, because .*? is not valid:\s*/s, "") });
161
- }
162
- }
163
- return { system: readSystem(found.folder, found.name, kept, ruleset), refused };
164
- }
165
- /**
166
- * 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
167
- * when none is. Only its own system.yaml is read, and its version's.
168
- */
169
- export function findSystem(folders, name, ruleset) {
170
- const found = systemFolders(folders).find((candidate) => comparableText(candidate.name) === comparableText(name.trim()));
171
- return found === undefined ? undefined : readSystem(found.folder, found.name, [], ruleset);
172
- }
173
- /** 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. */
174
- export function systemInFolder(folder, name) {
175
- return readSystem(folder, name);
176
- }
177
- /** 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). */
178
- export function systemContentFolders(system) {
179
- return system.version === undefined ? [system.folder] : [system.folder, system.version.folder];
180
- }
181
- /** A sentence of a system's verb, with the {names} the page fills (D-514). */
182
- function phraseWith(names) {
183
- const shown = names.map((name) => `{${name}}`).join(" and ");
184
- return z.string().min(1).refine((text) => names.every((name) => text.includes(`{${name}}`)), `write it with ${shown}, which the page fills`);
185
- }
186
- const recipeSchema = z.object({
187
- set: z.record(z.string(), z.union([z.literal("max"), z.number().int()])).optional(),
188
- regain: z.record(z.string(), z.union([z.number(), z.string().min(1)])).optional(),
189
- lower: z.record(z.string(), z.union([z.number().int().positive(), z.string().min(1)])).optional(),
190
- needs: z.string().min(1).optional(),
191
- "once-per": z.string().regex(/^(\d+d)?\s*(\d+h)?\s*(\d+m)?$/, "write it as a duration, such as 24h").optional(),
192
- lasts: z.string().regex(/^(\d+d)?\s*(\d+h)?\s*(\d+m)?$/, "write it as a duration, such as 8h").optional(),
193
- spend: z.record(z.string(), z.object({ gives: z.string().min(1), adds: z.union([z.string().min(1), z.number()]).optional() }).strict()).optional(),
194
- ends: z.array(z.string().min(1)).optional(),
195
- rules: z.array(z.string().min(1)).optional(),
196
- }).strict();
197
- const lengthSchema = z.string().refine((text) => readLength(text) !== undefined, `write it ${lengthHelp}`);
198
- const speedSchema = z.string().refine((text) => readSpeed(text) !== undefined, `write ${speedHelp}`);
199
- // A factor of speed, such as 1/2 for difficult terrain, or 0.5.
200
- const factorSchema = z.union([z.number().positive(), z.string().regex(/^\d+\/[1-9]\d*$/, "write it as 1/2, or as a number such as 0.5")]);
201
- const hoursSchema = z.number().positive().max(24);
202
- // What a state check reads (CHK-2): an effect by its name, or a field against a number, as hp <= 0.
203
- const checkFieldPattern = /^([\p{L}][\p{L}\p{M}\p{N}_-]*)\s*(<=|>=|!=|=|<|>)\s*(-?\d+)$/u;
204
- const checkAtomSchema = z.string().trim().min(1, "give an effect's name, or a field against a number, such as hp <= 0");
205
- const inWordsHelp = "give the words a foe's counter is heard in, from full to 0, such as [unhurt, hurt, badly hurt, down]";
206
- const inWordsSchema = z.array(z.string().min(1), { error: inWordsHelp }).min(2, inWordsHelp);
207
- const travelSchema = z.object({
208
- paces: z.record(z.string().min(1), speedSchema).optional(),
209
- pace: z.string().min(1).optional(),
210
- hours: hoursSchema.optional(),
211
- rule: z.string().min(1).optional(),
212
- beyond: z.string().min(1).optional(),
213
- terrain: z.record(z.string().min(1), factorSchema).optional(),
214
- vehicles: z.record(z.string().min(1), z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]), {
215
- error: "give a field and the values of what is a vehicle, such as {category: drawn vehicle}",
216
- }).optional(),
217
- kinds: z.record(z.string().min(1), z.object({
218
- vehicle: z.record(z.string().min(1), z.string().min(1)).refine((match) => Object.keys(match).length === 1, "give one field and its value, such as {category: waterborne vehicle}").optional(),
219
- speed: z.string().min(1).optional(),
220
- hours: hoursSchema.optional(),
221
- current: speedSchema.optional(),
222
- }).strict().refine((kind) => (kind.vehicle === undefined) === (kind.speed === undefined), "give vehicle and speed together: what carries one on it, and its field that holds its speed")).optional(),
223
- }).strict().refine((travel) => travel.pace === undefined || Object.keys(travel.paces ?? {}).some((pace) => comparableText(pace) === comparableText(travel.pace ?? "")), {
224
- message: "pace must be one of paces",
225
- path: ["pace"],
226
- });
227
- const gridSchema = z.object({
228
- square: lengthSchema,
229
- diagonal: z.number().positive(),
230
- difficult: z.number().positive(),
231
- speed: z.string().min(1),
232
- walking: z.string().min(1).optional(),
233
- size: z.string().min(1).optional(),
234
- footprints: z.record(z.string().min(1), z.number().int().min(1)).optional(),
235
- leaving: z.string().min(1).optional(),
236
- }, { error: "write it as a square's length, a diagonal step's cost in squares, the factor of difficult ground and the field of the speed, such as {square: 1.5 m, diagonal: 1, difficult: 2, speed: speed}" }).strict();
237
- // A setting the setup asks (DAT-10), or the versions of the rules (VER-1): what it is to the player, then its values, each with what it means: a setting at
238
- // least two, the versions at least one.
239
- // The values of the engine's settings a game offers, or one of its values (DAT-16): one alone is no choice.
240
- const engineSettingsSchema = z.record(z.string().min(1), z.array(z.string().min(1)).min(1), {
241
- error: "write it as the engine's settings, each with the values the game offers, such as {rigor: [smooth]}",
242
- });
243
- function settingSchema(fewest) {
244
- return z.record(z.string().min(1), z.union([
245
- z.string().min(1),
246
- z.object({
247
- means: z.string().min(1),
248
- player: z.string().min(1).optional(),
249
- without: z.array(z.string().min(1)).optional(),
250
- "engine-settings": engineSettingsSchema.optional(),
251
- asks: z.array(z.string().min(1)).optional(),
252
- suggested: z.literal(true).optional(),
253
- }).strict(),
254
- ])).refine((values) => Object.entries(values).every(([key, value]) => (key === "about") === (typeof value === "string")), "give about as what the setting is to the player, in a few words, and each value with what it means, such as {about: how your character levels up, xp: {means: ...}}").refine((values) => Object.keys(values).filter((key) => key !== "about").length >= fewest, fewest === 1 ? "give at least one version, with what it means, such as {srd-5.1: {means: ...}}" : "give at least two values, each with what it means, such as {xp: {means: ...}, milestones: {means: ...}}");
255
- }
256
- const systemSchema = z.object({
257
- title: z.string().min(1),
258
- language: z.string().regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/),
259
- attribution: z.string().min(1).optional(),
260
- // Its theme of the dashboard (D-528): a folder of its own, written from it, as theme.
261
- theme: z.string().min(1).refine((folder) => !isAbsolute(folder) && !folder.split(/[\\/]/).includes(".."), { error: "write it as a folder of the system, such as theme" }).optional(),
262
- fields: z.record(z.string(), z.enum(fieldKinds)).optional(),
263
- coins: z.union([z.string().min(1), z.record(z.string(), z.unknown())]).optional(),
264
- "coin-metals": z.record(z.string().min(1), z.string().min(1), { error: "write it as a map, each coin with its metal, such as {gp: gold, sp: silver}" }).optional(),
265
- round: z.string().regex(/^[1-9]\d* seconds?$/, 'write it as "6 seconds"').optional(),
266
- imperial: z.object({ mile: lengthSchema, foot: lengthSchema, pound: z.string().regex(/^\d+(\.\d+)? kg$/, { error: "write it in kilograms, such as 0.5 kg" }).optional() }).strict().optional(),
267
- "length-unit": z.string().min(1).optional(),
268
- "bonus-lists": z.array(z.string().min(1)).optional(),
269
- load: z.object({
270
- field: z.string().min(1),
271
- limit: z.union([z.string().min(1), z.array(z.union([z.string().min(1), z.number()])).min(1)]),
272
- coins: z.number().int().positive().optional(),
273
- weightless: z.string().min(1).optional(),
274
- bundle: z.string().min(1).optional(),
275
- stages: z.array(z.object({ name: z.string().min(1), when: z.string().min(1) }).strict()).optional(),
276
- }, {
277
- error: "write it as the field of an item's weight, the formula of the limit, and how many coins weigh one unit, such as {field: weight, limit: str * 15, coins: 50}; weightless names the field of an item whose contents weigh nothing, bundle the field of how many pieces one of a kind sold by the bundle holds; "
278
- + "stages lists what a load makes a character, the heaviest last, each with when, the formula that says so above 0, such as [{name: Encumbered, when: ceil(load - 5 * str)}]",
279
- }).strict().optional(),
280
- travel: travelSchema.optional(),
281
- grid: gridSchema.optional(),
282
- sheet: z.record(z.string().min(1), z.array(z.string().regex(sheetEntryPattern, 'write it as "str", "str (str-mod)" for a field shown beside it, or "flaw?" for one written only when it applies')).min(1), {
283
- error: "write the sheet as groups, each with its fields, such as Abilities: [str (str-mod), dex (dex-mod)]",
284
- }).optional(),
285
- "sheet-notes": z.record(z.string().min(1), z.string().min(1)).optional(),
286
- "sheet-cards": z.object({ rail: z.array(z.string().min(1)).optional(), order: z.array(z.string().min(1)).optional(), "at-hand": z.array(z.string().min(1)).optional() }, {
287
- error: "write it as the groups the dashboard puts in its rail, the order of the others, and the fields and groups at hand in a fight, such as {rail: [Abilities], order: [Skills, Combat], at-hand: [ac, hp, Attacks]}",
288
- }).strict().optional(),
289
- "sheet-actions": z.record(z.string().min(1), z.array(z.string().min(1)).min(1), {
290
- error: `write it as the fields whose items the player acts with on the dashboard, each with its verbs, among ${actVerbs.join(", ")} and those of sheet-verbs, such as {inventory: [use, equip]}`,
291
- }).optional(),
292
- "sheet-verbs": z.record(z.string().regex(/^[a-z][a-z-]*$/, "write a verb's name in lowercase, such as invoke"), z.object({
293
- label: z.string().min(1),
294
- title: phraseWith(["item"]),
295
- says: phraseWith(["item"]),
296
- "says-on": phraseWith(["item", "target"]).optional(),
297
- "says-at": phraseWith(["item", "square"]).optional(),
298
- "says-self": phraseWith(["item"]).optional(),
299
- }).strict().refine((verb) => [verb["says-on"], verb["says-at"], verb["says-self"]].every((said, _index, all) => (said === undefined) === (all[0] === undefined)), {
300
- message: "give says-on, says-at and says-self together, for a verb that lets the player choose on whom, or none of them",
301
- }), { error: 'write it as the system\'s own verbs, each with its words, such as {invoke: {label: Invoke, title: "Invoke {item}", says: "I invoke {item}."}}' }).optional(),
302
- "sheet-headline": z.string().min(1).regex(/\{[^{}\s]+\}/, "write it as words with fields in braces, such as Level {level} {classes}").optional(),
303
- "sheet-icons": z.record(z.string().min(1), z.string().max(2000).regex(iconPattern, "write it as the d of an SVG path on a grid of 24, its letters and numbers alone, such as M4 12h16")).optional(),
304
- "token-icons": z.object({
305
- field: z.string().min(1),
306
- icons: z.record(z.string().min(1), z.string().max(2000).regex(iconPattern, "write it as the d of an SVG path on a grid of 24, its letters and numbers alone, such as M4 12h16")),
307
- }).strict().optional(),
308
- "sheet-dice": z.record(z.string().regex(sheetDicePattern), z.array(z.string().min(1)).min(1), {
309
- error: "write it as dice alone, as 1d20 or 2d6+1d4, and the fields of the sheet rolled with them, such as 1d20: [athletics, stealth]",
310
- }).optional(),
311
- "sheet-knowledge": z.array(z.string().min(1)).min(1).optional(),
312
- "sheet-odds": z.object({
313
- better: z.string().regex(rollNamePattern),
314
- worse: z.string().regex(rollNamePattern),
315
- when: z.array(z.object({ fields: z.array(z.string().min(1)).min(1), better: z.string().min(1).optional(), worse: z.string().min(1).optional(), why: z.string().min(1).optional() }).strict()),
316
- }, {
317
- error: "write it as the dice of a better and a worse roll, and when: fields of the sheet with the formulas that make them better or worse above 0, and why in a word of the system, "
318
- + "such as {better: 2d20kh1, worse: 2d20kl1, when: [{fields: [stealth], worse: count(equipped, stealth-disadvantage = true), why: Armor}]}",
319
- }).strict().optional(),
320
- "roll-names": z.record(z.string().regex(rollNamePattern), z.union([z.string().min(1), z.record(z.string().min(2), z.string().min(1))]), {
321
- error: "write it as dice with the highest or the lowest kept or dropped, and the name the game gives such a roll, by language, such as 2d20kh1: {en: with advantage, it: con vantaggio}",
322
- }).optional(),
323
- values: z.record(z.string().min(1), z.array(z.string().min(1)).min(1)).optional(),
324
- "sheet-values": z.record(z.string().min(1), z.array(z.string().min(1)).min(1)).optional(),
325
- marks: z.array(z.string().min(1)).optional(),
326
- "status-line": z.array(z.string().min(1)).optional(),
327
- thresholds: z.record(z.string().regex(/^[^\s]+( -?\d+)?$/, 'write it as "hp 0", or the field alone'), z.string().min(1)).optional(),
328
- recipes: z.record(z.string(), recipeSchema).optional(),
329
- conditions: z.array(z.string().min(1)).optional(),
330
- "condition-icons": z.record(z.string().min(1), z.string().max(2000).regex(iconPattern, "write it as the d of an SVG path on a grid of 24, its letters and numbers alone, such as M4 12h16")).optional(),
331
- upkeep: z.object({
332
- daily: z.string().min(1),
333
- short: z.string().min(1),
334
- grace: z.string().min(1),
335
- worsens: z.string().min(1),
336
- water: z.string().min(1).optional(),
337
- lifestyle: z.object({ field: z.string().min(1), costs: z.record(z.string().min(1), z.string().min(1)), rules: z.string().min(1) }).strict().optional(),
338
- rules: z.string().min(1),
339
- }, {
340
- error: "write it as the kind spent each day, the field that counts the days without it, the formula of the days one goes without, the counter they then raise, "
341
- + "a word on water, what a day in a settlement costs by the lifestyle chosen, and the rules, such as {daily: Rations, short: days-without-food, grace: 3 + con-mod, "
342
- + "worsens: exhaustion, lifestyle: {field: lifestyle, costs: {modest: 1 gp}, rules: Lifestyle Expenses}, rules: Food and Water}",
343
- }).strict().optional(),
344
- burning: z.record(z.string().min(1), z.object({ lasts: z.string().min(1), spends: z.string().min(1).optional() }).strict(), {
345
- error: "write each thing that burns with how long it lasts, and what it spends when not itself, such as Lamp: {lasts: 6 hours, spends: Oil}",
346
- }).optional(),
347
- bonds: z.record(z.string().min(1), z.object({ most: z.number().int().positive(), needs: z.string().min(1), while: z.string().min(1).optional(), rules: z.string().min(1) }).strict(), {
348
- error: "write each list with the most items it holds, the field an item that asks for it has, the list it gives its bonuses only while in, and the rules to read, "
349
- + "such as attuned: {most: 3, needs: attunement, while: equipped, rules: Attunement}",
350
- }).optional(),
351
- immune: z.string().min(1).optional(),
352
- oracle: z.object({ yes: z.enum(["low", "high"]) }, { error: "write it as where the oracle's d100 says yes, low up to the odds or high above 100 less them, such as {yes: high}" }).strict().optional(),
353
- "turn-uses": z.record(z.string().min(1).refine((name) => !/ (by|for) /i.test(` ${name} `), "a use's name takes no word by or for, which the engine reads in what it keeps"), z.object({
354
- most: z.union([z.string().min(1), z.number()]).optional(),
355
- within: z.string().min(1).optional(),
356
- needs: z.string().min(1).optional(),
357
- "any-turn": z.boolean().optional(),
358
- resets: z.enum(["own turn", "each turn"]).optional(),
359
- note: z.string().min(1).optional(),
360
- "note-when": z.string().min(1).optional(),
361
- }).strict(), { error: "write each use of a turn with its most, the use it goes within, what it needs, whether it goes in any turn and when it comes back, such as attack: {within: action, most: 1 + extra-attacks}" }).optional(),
362
- "at-most": z.record(z.string().min(1), z.union([z.string().min(1), z.number()]), {
363
- error: "write each field of a sheet with the most it holds, a number or a formula, such as str: 20 + 4 * has(features, Primal Champion), or prepared: max-prepared",
364
- }).optional(),
365
- damage: z.object({ counter: z.string().min(1), halves: z.string().min(1), ignores: z.string().min(1), doubles: z.string().min(1), rules: z.string().min(1) }, {
366
- error: "write it as the counter damage takes from and the lists of a page that halve, ignore and double a type, such as "
367
- + "{counter: hp, halves: damage-resistances, ignores: damage-immunities, doubles: damage-vulnerabilities, rules: Damage Resistance and Vulnerability}",
368
- }).strict().optional(),
369
- keeping: z.object({ counter: z.string().min(1), conditions: z.array(z.string().min(1)).optional(), rules: z.string().min(1) }, {
370
- error: "write it as what can break what someone keeps alive, such as {counter: hp, conditions: [Unconscious], rules: Concentration}",
371
- }).strict().optional(),
372
- combat: z.object({ track: z.string().min(1), "in-words": inWordsSchema.optional(), inactive: z.array(z.string().min(1)).optional() }, {
373
- error: "write it as the counter a fight follows, the words the player hears a foe's in, from full to 0, and the conditions that keep from acting, "
374
- + "such as {track: hp, in-words: [unhurt, hurt, badly hurt, down], inactive: [Stunned]}",
375
- }).strict().optional(),
376
- down: z.object({ at: z.string().regex(/^[^\s]+ -?\d+$/, 'write it as "hp 0"') }, {
377
- error: "write it as when one of the party is down, such as {at: hp 0}; what being down does, and how the dashboard draws it, is the system's code (D-448, D-516)",
378
- }).strict().optional(),
379
- checks: z.array(z.object({ when: checkAtomSchema, needs: checkAtomSchema, say: z.string().min(1) }, {
380
- error: 'write each as what holds, what must hold with it, and the line for the master, such as {when: Stable, needs: hp <= 0, say: "{page} is Stable with {hp}: effect end {page} Stable."}',
381
- }).strict()).optional(),
382
- tables: z.record(z.string(), z.record(z.string(), z.number())).optional(),
383
- progression: z.object({
384
- list: z.string().min(1),
385
- level: z.string().min(1).optional(),
386
- features: z.string().min(1),
387
- skip: z.array(z.string().min(1)).optional(),
388
- parts: z.object({ list: z.string().min(1), field: z.string().min(1), lists: z.array(z.string().min(1)).optional() }).strict().optional(),
389
- experience: z.object({ field: z.string().min(1), table: z.string().min(1), rules: z.string().min(1).optional() }).strict().optional(),
390
- }).strict().optional(),
391
- settings: z.record(z.string().min(1).refine((name) => comparableText(name) !== rulesetSetting, `${rulesetSetting} is the engine's setting of the versions: give this one another name`), settingSchema(2))
392
- .optional(),
393
- // Its versions of the rules, each a folder in versions/ (VER-1): a setting of their own, ruleset.
394
- versions: settingSchema(1).optional(),
395
- "engine-settings": engineSettingsSchema.optional(),
396
- rewards: z.record(z.string().min(1), z.object({ from: z.string().min(1), overcome: z.string().regex(/^[^\s]+ -?\d+$/, 'write it as "hp 0"') }).strict()).optional(),
397
- "item-formulas": z.record(z.string().min(1), z.array(z.string().min(1)).min(1)).optional(),
398
- "always-in": z.record(z.string().min(1), z.array(z.string().min(1)).min(1), { error: "write it as lists, each with the names of the pages in it, such as equipped: [Unarmed Strike]" }).optional(),
399
- computed: z.record(z.string(), z.union([z.number(), z.string().min(1), z.array(z.union([z.number(), z.string().min(1)]))])).optional(),
400
- counters: z.record(z.string(), z.object({
401
- min: z.union([z.number(), z.string().min(1)]).optional(),
402
- max: z.union([z.number(), z.string().min(1)]).optional(),
403
- refill: z.union([z.string().min(1), z.record(z.string().min(1), z.union([z.number(), z.string().min(1)]))]).optional(),
404
- shields: z.string().min(1).optional(),
405
- }).strict()).optional(),
406
- ...packagePartsShape,
407
- }).strict();
408
- /** What is wrong in the settings a value asks, or in the value a setting suggests (DAT-17): "die.d6: asks die, which is its own setting"; undefined when nothing is. */
409
- function settingsAsking(settings) {
410
- const names = Object.keys(settings);
411
- for (const [setting, values] of Object.entries(settings)) {
412
- const shown = Object.entries(values).flatMap(([value, meaning]) => (typeof meaning === "string" ? [] : [[value, meaning]]));
413
- if (shown.filter(([, meaning]) => meaning.suggested === true).length > 1) {
414
- return `${setting}: suggest one value at most`;
415
- }
416
- for (const [value, meaning] of shown) {
417
- const stray = (meaning.asks ?? []).find((asked) => comparableText(asked) === comparableText(setting) || !names.some((name) => comparableText(name) === comparableText(asked)));
418
- if (stray !== undefined) {
419
- return `${setting}.${value}: asks ${stray}, which is ${comparableText(stray) === comparableText(setting) ? "its own setting" : "no setting of the system"}: name another of its settings`;
420
- }
421
- }
422
- }
423
- return undefined;
424
- }
425
20
  /** 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. */
426
- function plainRoll(dice) {
21
+ export function plainRoll(dice) {
427
22
  const compact = dice.toLowerCase().replace(/\s+/g, "").replace(/([kd][hl])$/, (rule) => `${rule}1`);
428
23
  return /^2d/.test(compact) ? compact.replace(/dl1$/, "kh1").replace(/dh1$/, "kl1") : compact;
429
24
  }
430
- /** 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. */
431
- export const campaignDataNames = ["fields", "tables", "computed", "counters", "recipes", "status-line", "travel", "values", "condition-icons"];
432
- function readSystem(folder, name, layers = [], ruleset) {
433
- const file = join(folder, systemFileName);
434
- let own;
435
- // The YAML's own error names only system.yaml: the system and its folder are said, so that one played is found and fixed.
436
- try {
437
- own = readYamlValues(file, 'what the system is, such as "title: ..."');
438
- }
439
- catch (error) {
440
- throw new Error(`The game system ${name} cannot be read, because ${file} is not valid: ${error instanceof Error ? error.message : String(error)}`);
441
- }
442
- const version = chosenVersion(own, file, name, ruleset);
443
- const read = version === undefined ? file : `${file} with its version ${version.name}`;
444
- const path = layers.length === 0 ? read : `${read} with the additions of ${layers.map((layer) => layer.from).join(", ")}`;
445
- const raw = version === undefined || !isMap(own) ? own : withVersion(own, version.data);
446
- let merged = raw;
447
- try {
448
- merged = layers.reduce((below, layer) => withCampaignData(below, layer.data), raw);
449
- }
450
- catch (error) {
451
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${error instanceof Error ? error.message : String(error)}`);
452
- }
453
- const parsed = systemSchema.safeParse(merged);
454
- if (!parsed.success) {
455
- // One made for a newer API may declare what this engine does not know yet (D-515).
456
- const unread = systemApiProblem(folder);
457
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${issuesText(parsed.error)}${unread === undefined ? "" : ` Besides, ${unread}.`}`);
458
- }
459
- const data = parsed.data;
460
- const parts = packagePartsIssues(data, "a game system")[0];
461
- if (parts !== undefined) {
462
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${[...parts.path, ""].join(".").replace(/\.$/, ": ")}${parts.message}.`);
463
- }
464
- // What a counter shields is no limit of it: a counter with only that has none (DAT-14).
465
- const limited = Object.entries(data.counters ?? {}).flatMap(([counter, { min, max, refill }]) => min === undefined && max === undefined && refill === undefined ? [] : [[counter, { min, max, refill }]]);
466
- const formulas = systemFormulas({ ...data, counters: Object.fromEntries(limited) }, name, path);
467
- const stray = strayOccasion(data, formulas);
468
- if (stray !== undefined) {
469
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${stray}`);
470
- }
471
- const sheet = sheetOf(data, name, path);
472
- const values = data.values ?? {};
473
- const sheetValues = data["sheet-values"] ?? {};
474
- const kindOf = (field) => Object.entries(data.fields ?? {}).find(([declared]) => comparableText(declared) === comparableText(field))?.[1];
475
- // Closed names for a list, as the skills, or for a text, as an alignment.
476
- const notList = [...Object.keys(values), ...Object.keys(sheetValues)].find((field) => kindOf(field) !== "list" && kindOf(field) !== "text");
477
- if (notList !== undefined) {
478
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: values.${notList}: declare ${notList} as a list or a text in fields, or give no values to it.`);
479
- }
480
- // What breaks what someone keeps, and what a counter shields, read counters (EFF-14, DAT-14).
481
- const counted = [
482
- ...(data.keeping === undefined ? [] : [{ where: "keeping.counter", field: data.keeping.counter }]),
483
- ...(data.damage === undefined ? [] : [{ where: "damage.counter", field: data.damage.counter }]),
484
- ...(data.combat === undefined ? [] : [{ where: "combat.track", field: data.combat.track }]),
485
- ...(data.down === undefined ? [] : [{ where: "down.at", field: data.down.at.split(" ")[0] }]),
486
- ...Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [{ where: `counters.${counter}.shields`, field: limits.shields }])),
487
- ].find((entry) => kindOf(entry.field) !== "counter");
488
- const unknownCondition = [
489
- ...(data.keeping?.conditions ?? []).map((condition) => ({ where: "keeping.conditions", condition })),
490
- ...(data.combat?.inactive ?? []).map((condition) => ({ where: "combat.inactive", condition })),
491
- ].find((entry) => !(data.conditions ?? []).some((named) => comparableText(named) === comparableText(entry.condition)));
492
- if (unknownCondition !== undefined) {
493
- const named = (data.conditions ?? []).length === 0 ? "" : ` (${(data.conditions ?? []).join(", ")})`;
494
- const what = `${unknownCondition.where}: ${unknownCondition.condition} is not one of its conditions${named}; write it as one of them, or add it to conditions.`;
495
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${what}`);
496
- }
497
- const gridField = [data.grid?.speed, data.grid?.size].find((field) => field !== undefined && kindOf(field) === undefined);
498
- if (gridField !== undefined) {
499
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: grid: ${gridField} is not declared in fields.`);
500
- }
501
- if (counted !== undefined) {
502
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${counted.where}: ${counted.field} is not declared as a counter in fields.`);
503
- }
504
- // A state check compares a field the system declares, written as one, and its line names only the page and such fields (CHK-2).
505
- const checks = data.checks ?? [];
506
- const atoms = checks.flatMap((check) => [check.when, check.needs]);
507
- const miswritten = atoms.find((atom) => /[<>=!]/.test(atom) && !checkFieldPattern.test(atom.trim()));
508
- const checkField = atoms.map(checkAtom).find((atom) => "field" in atom && kindOf(atom.field) === undefined);
509
- const placeholder = checks.flatMap((check) => [...check.say.matchAll(/\{([^{}]+)\}/g)].map((found) => found[1])).find((named) => named !== "page" && kindOf(named) === undefined);
510
- const checkProblem = miswritten !== undefined
511
- ? `"${miswritten}" is no comparison: write a field, one of < <= = != >= >, and a whole number, such as hp <= 0`
512
- : checkField !== undefined && "field" in checkField
513
- ? `${checkField.field} is not declared in fields`
514
- : placeholder === undefined
515
- ? undefined
516
- : `{${placeholder}} in say is neither {page} nor a field declared in fields`;
517
- if (checkProblem !== undefined) {
518
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: checks: ${checkProblem}.`);
519
- }
520
- // A use of a turn goes within another the system names (TRN-3).
521
- const turnUses = data["turn-uses"] ?? {};
522
- const looseUse = Object.entries(turnUses).find(([, rule]) => rule.within !== undefined && !Object.keys(turnUses).some((use) => comparableText(use) === comparableText(rule.within ?? "")));
523
- if (looseUse !== undefined) {
524
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: turn-uses.${looseUse[0]}: ${looseUse[1].within} is not one of its turn-uses; name one, or add it.`);
525
- }
526
- // The lists whose types change damage are lists (DMG-1).
527
- const damageLists = data.damage === undefined ? [] : ["halves", "ignores", "doubles"].map((key) => ({ where: `damage.${key}`, field: data.damage?.[key] ?? "" }));
528
- const notListed = damageLists.find((entry) => kindOf(entry.field) !== "list");
529
- if (notListed !== undefined) {
530
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${notListed.where}: ${notListed.field} is not declared as a list in fields.`);
531
- }
532
- const notMarking = [...(data.marks ?? []), ...[data.progression?.list, data.progression?.parts?.list].filter((field) => field !== undefined)].find((field) => kindOf(field) !== "list");
533
- if (notMarking !== undefined) {
534
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${notMarking} is not declared as a list in fields, as marks and progression need.`);
535
- }
536
- // Each number rolled with dice is a declared field, and has one set of dice (D-280).
537
- const rolled = Object.entries(data["sheet-dice"] ?? {}).flatMap(([dice, fields]) => fields.map((field) => [field, dice]));
538
- const undeclared = rolled.find(([field]) => kindOf(field) === undefined);
539
- const twice = rolled.find(([field], index) => rolled.findIndex(([other]) => comparableText(other) === comparableText(field)) !== index);
540
- if (undeclared !== undefined) {
541
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-dice.${undeclared[1]}: ${undeclared[0]} is not declared in fields.`);
542
- }
543
- if (twice !== undefined) {
544
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-dice: ${twice[0]} is listed twice; give each field one set of dice.`);
545
- }
546
- const unknownKnowledge = (data["sheet-knowledge"] ?? []).find((field) => kindOf(field) === undefined);
547
- if (unknownKnowledge !== undefined) {
548
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-knowledge: ${unknownKnowledge} is not declared in fields.`);
549
- }
550
- // The cards the dashboard places are groups of the sheet (D-295); at hand in a fight, its fields too (D-315).
551
- for (const [key, names] of Object.entries(data["sheet-cards"] ?? {})) {
552
- const fields = key === "at-hand" ? sheet.flatMap((group) => group.entries.map((entry) => comparableText(entry.field))) : [];
553
- const stray = (names ?? []).find((group) => !sheet.some((declared) => comparableText(declared.name) === comparableText(group)) && !fields.includes(comparableText(group)));
554
- if (stray !== undefined) {
555
- const kinds = key === "at-hand" ? "group or field" : "group";
556
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-cards.${key}: the sheet has no ${kinds} ${stray}; its groups are ${sheet.map((group) => group.name).join(", ")}.`);
557
- }
558
- }
559
- // The fields the player acts with are fields of the sheet (D-495).
560
- const actless = Object.keys(data["sheet-actions"] ?? {}).find((field) => !sheet.some((group) => group.entries.some((entry) => entry.field === field)));
561
- if (actless !== undefined) {
562
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-actions: the sheet has no field ${actless}.`);
563
- }
564
- // Each verb is the engine's or one the system declares, never both (D-514).
565
- const ownVerbs = Object.keys(data["sheet-verbs"] ?? {});
566
- const taken = ownVerbs.find((verb) => actVerbs.includes(verb));
567
- const verbs = [...actVerbs, ...ownVerbs];
568
- const unknownVerb = Object.entries(data["sheet-actions"] ?? {}).flatMap(([field, listed]) => listed.filter((verb) => !verbs.includes(verb)).map((verb) => `${field}: ${verb}`))[0];
569
- if (taken !== undefined) {
570
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-verbs: ${taken} is one of the engine's verbs, whose words the dashboard has; leave it out.`);
571
- }
572
- if (unknownVerb !== undefined) {
573
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-actions.${unknownVerb} is no verb: give one of ${verbs.join(", ")}, or declare it in sheet-verbs.`);
574
- }
575
- // Each field the headline names is a declared one (D-288).
576
- const unnamed = [...(data["sheet-headline"] ?? "").matchAll(headlineFieldPattern)].map((match) => match[1]).find((field) => kindOf(field) === undefined);
577
- if (unnamed !== undefined) {
578
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: sheet-headline: ${unnamed} is not declared in fields.`);
579
- }
580
- // The tokens' icons read a declared field (D-414).
581
- const iconField = data["token-icons"]?.field;
582
- if (iconField !== undefined && kindOf(iconField) === undefined) {
583
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: token-icons.field: ${iconField} is not declared in fields.`);
584
- }
585
- const asking = settingsAsking(data.settings ?? {});
586
- if (asking !== undefined) {
587
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: settings.${asking}.`);
588
- }
589
- const experience = data.progression?.experience?.table;
590
- if (experience !== undefined && !Object.keys(formulas.tables).some((table) => comparableText(table) === comparableText(experience))) {
591
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: progression.experience.table: there is no table ${experience} in tables.`);
592
- }
593
- return frozen({
594
- name,
595
- folder,
596
- ...(version === undefined ? {} : { version: { name: version.name, ...(version.title === undefined ? {} : { title: version.title }), folder: version.folder } }),
597
- code: systemHasCode(folder),
598
- title: data.title,
599
- language: data.language,
600
- attribution: data.attribution,
601
- ...(data.theme === undefined ? {} : { theme: join(folder, data.theme) }),
602
- fields: data.fields ?? {},
603
- coins: data.coins,
604
- coinMetals: data["coin-metals"] ?? {},
605
- roundSeconds: data.round === undefined ? undefined : Number.parseInt(data.round, 10),
606
- ...(data.imperial === undefined ? {} : { imperial: { mile: readLength(data.imperial.mile) ?? 0, foot: readLength(data.imperial.foot) ?? 0 } }),
607
- ...(data.imperial?.pound === undefined ? {} : { pound: Number.parseFloat(data.imperial.pound) }),
608
- ...(data["length-unit"] === undefined ? {} : { lengthUnit: data["length-unit"] }),
609
- bonusLists: data["bonus-lists"] ?? [],
610
- bonusWhile: Object.fromEntries(Object.entries(data.bonds ?? {}).flatMap(([list, bond]) => (bond.while === undefined ? [] : [[list, bond.while]]))),
611
- ...(data.load === undefined ? {} : {
612
- load: {
613
- field: data.load.field,
614
- // Formulas in order, the first with a value counts, as a computed field's (D-210).
615
- limit: Array.isArray(data.load.limit)
616
- ? { kind: "first", options: data.load.limit.map((option, index) => formulaAt(String(option), `load.limit.${index}`, name, path)) }
617
- : formulaAt(data.load.limit, "load.limit", name, path),
618
- ...(data.load.coins === undefined ? {} : { coins: data.load.coins }),
619
- ...(data.load.weightless === undefined ? {} : { weightless: data.load.weightless }),
620
- ...(data.load.bundle === undefined ? {} : { bundle: data.load.bundle }),
621
- ...(data.load.stages === undefined ? {} : { stages: data.load.stages.map((stage) => ({ name: stage.name, formula: formulaAt(stage.when, `load.stages.${stage.name}`, name, path) })) }),
622
- },
623
- }),
624
- ...(data.travel === undefined ? {} : { travel: travelOf(data.travel) }),
625
- ...(data.grid === undefined ? {} : { grid: gridOf(data.grid) }),
626
- sheet,
627
- sheetDice: Object.fromEntries(rolled),
628
- sheetKnowledge: data["sheet-knowledge"] ?? [],
629
- ...(data["sheet-odds"] === undefined ? {} : {
630
- sheetOdds: {
631
- better: data["sheet-odds"].better,
632
- worse: data["sheet-odds"].worse,
633
- when: data["sheet-odds"].when.map((when) => ({
634
- fields: when.fields,
635
- ...(when.better === undefined ? {} : { better: formulaAt(when.better, "sheet-odds.when.better", name, path) }),
636
- ...(when.worse === undefined ? {} : { worse: formulaAt(when.worse, "sheet-odds.when.worse", name, path) }),
637
- ...(when.why === undefined ? {} : { why: when.why }),
638
- })),
639
- },
640
- }),
641
- rollNames: Object.fromEntries(Object.entries(data["roll-names"] ?? {}).map(([dice, names]) => [plainRoll(dice), typeof names === "string" ? { [data.language]: names } : names])),
642
- ...(data["sheet-headline"] === undefined ? {} : { sheetHeadline: data["sheet-headline"] }),
643
- ...(data["token-icons"] === undefined ? {} : { tokenIcons: data["token-icons"] }),
644
- ...(data["sheet-actions"] === undefined ? {} : { sheetActions: data["sheet-actions"] }),
645
- sheetVerbs: Object.fromEntries(Object.entries(data["sheet-verbs"] ?? {}).map(([verb, words]) => [verb, sheetVerbOf(words)])),
646
- ...(data["sheet-cards"] === undefined ? {} : { sheetCards: { rail: data["sheet-cards"].rail ?? [], order: data["sheet-cards"].order ?? [], atHand: data["sheet-cards"]["at-hand"] ?? [] } }),
647
- values,
648
- sheetValues,
649
- marks: data.marks ?? [],
650
- statusLine: (data["status-line"] ?? []).map((entry) => ({ field: entry.replace(/\?$/, ""), whenSet: entry.endsWith("?") })),
651
- thresholds: Object.entries(data.thresholds ?? {}).map(([key, rule]) => {
652
- const [field, value] = key.split(" ");
653
- return { field, value: value === undefined ? undefined : Number(value), rule };
654
- }),
655
- recipes: Object.entries(data.recipes ?? {}).map(([recipe, value]) => ({
656
- name: recipe,
657
- set: value.set ?? {},
658
- regain: regainOf(value.regain ?? {}, name, path, recipe),
659
- lower: Object.fromEntries(Object.entries(value.lower ?? {}).map(([field, amount]) => [field, formulaAt(String(amount), `recipes.${recipe}.lower.${field}`, name, path)])),
660
- ...(value.needs === undefined ? {} : { needs: value.needs }),
661
- ...(value["once-per"] === undefined ? {} : { oncePer: value["once-per"] }),
662
- ...(value.lasts === undefined ? {} : { lasts: value.lasts }),
663
- 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) }])),
664
- ends: value.ends ?? [],
665
- rules: value.rules ?? [],
666
- })),
667
- conditions: data.conditions ?? [],
668
- conditionIcons: data["condition-icons"] ?? {},
669
- icons: data.icons ?? {},
670
- widgets: declaredWidgets(data.widgets),
671
- figures: data.figures ?? {},
672
- bonds: data.bonds ?? {},
673
- ...(data.upkeep === undefined ? {} : { upkeep: data.upkeep }),
674
- burning: data.burning ?? {},
675
- ...(data.immune === undefined ? {} : { immune: data.immune }),
676
- ...(data.oracle === undefined ? {} : { oracleYes: data.oracle.yes }),
677
- turnUses: Object.fromEntries(Object.entries(data["turn-uses"] ?? {}).map(([use, rule]) => [use, {
678
- ...(rule.most === undefined ? {} : { most: formulaAt(String(rule.most), `turn-uses.${use}.most`, name, path) }),
679
- ...(rule.within === undefined ? {} : { within: rule.within }),
680
- ...(rule.needs === undefined ? {} : { needs: formulaAt(rule.needs, `turn-uses.${use}.needs`, name, path) }),
681
- anyTurn: rule["any-turn"] ?? false,
682
- resets: rule.resets ?? "own turn",
683
- ...(rule.note === undefined ? {} : { note: rule.note }),
684
- ...(rule["note-when"] === undefined ? {} : { noteWhen: formulaAt(rule["note-when"], `turn-uses.${use}.note-when`, name, path) }),
685
- }])),
686
- atMost: Object.fromEntries(Object.entries(data["at-most"] ?? {}).map(([field, most]) => [field, formulaAt(String(most), `at-most.${field}`, name, path)])),
687
- ...(data.damage === undefined ? {} : { damage: data.damage }),
688
- ...(data.keeping === undefined ? {} : { keeping: { counter: data.keeping.counter, conditions: data.keeping.conditions ?? [], rules: data.keeping.rules } }),
689
- ...(data.combat === undefined ? {} : { combat: { track: data.combat.track, inWords: data.combat["in-words"] ?? [], inactive: data.combat.inactive ?? [] } }),
690
- ...(data.down === undefined ? {} : { down: downRule(data.down.at) }),
691
- checks: (data.checks ?? []).map((check) => ({ when: checkAtom(check.when), needs: checkAtom(check.needs), say: check.say })),
692
- shields: Object.fromEntries(Object.entries(data.counters ?? {}).flatMap(([counter, limits]) => (limits.shields === undefined ? [] : [[counter, limits.shields]]))),
693
- formulas,
694
- ...(data.progression === undefined ? {} : { progression: progressionRule(data.progression) }),
695
- itemFormulas: data["item-formulas"] ?? {},
696
- alwaysIn: data["always-in"] ?? {},
697
- uses: usesOf(data),
698
- // The versions first, as the setup asks them before what they may change; one alone is no choice, and no setting (VER-1).
699
- settings: [...(Object.keys(data.versions ?? {}).filter((key) => key !== "about").length < 2 ? [] : [[rulesetSetting, data.versions ?? {}]]), ...Object.entries(data.settings ?? {})].map(([setting, values]) => ({
700
- name: setting,
701
- ...(typeof values.about === "string" ? { about: values.about } : {}),
702
- values: Object.entries(values).flatMap(([value, meaning]) => typeof meaning === "string" ? [] : [{
703
- value,
704
- means: meaning.means,
705
- ...(meaning.player === undefined ? {} : { player: meaning.player }),
706
- without: meaning.without ?? [],
707
- engineSettings: meaning["engine-settings"] ?? {},
708
- asks: meaning.asks ?? [],
709
- ...(meaning.suggested === true ? { suggested: true } : {}),
710
- }]),
711
- })),
712
- engineSettings: data["engine-settings"] ?? {},
713
- leftOut: [],
714
- rewards: Object.entries(data.rewards ?? {}).map(([field, reward]) => {
715
- const [counter, value] = reward.overcome.split(" ");
716
- return { field, from: reward.from, counter, value: Number(value) };
717
- }),
718
- // A part of its version takes the place of its own of that name (VER-3).
719
- parts: { ...readParts(folder, `The game system ${name}`), ...(version === undefined ? {} : readParts(version.folder, `The game system ${name}, its version ${version.name},`)) },
720
- });
721
- }
722
- /**
723
- * The version of its rules a system is read with (VER-1, VER-2): the one asked, by any case, else the first it lists; none for a system without versions.
724
- * Each version it lists has its folder in versions/, with a system.yaml of what it changes, if any, and a title of its own.
725
- */
726
- function chosenVersion(own, file, name, asked) {
727
- const versions = isMap(own) && isMap(own.versions) ? Object.keys(own.versions).filter((key) => key !== "about") : [];
728
- const folder = join(file, "..");
729
- // A version is a folder of versions/ itself, never one a path leads to out of the system.
730
- const astray = versions.find((version) => /[\\/]/.test(version) || version.trim() === "." || version.trim() === "..");
731
- if (astray !== undefined) {
732
- 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.`);
733
- }
734
- const unfound = versions.find((version) => files().files(join(folder, versionsFolderName, version), () => true).length === 0);
735
- if (unfound !== undefined) {
736
- 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.`);
737
- }
738
- const chosen = versions.find((version) => asked !== undefined && comparableText(version) === comparableText(asked.trim())) ?? versions[0];
739
- if (chosen === undefined) {
740
- return undefined;
741
- }
742
- const at = join(folder, versionsFolderName, chosen);
743
- const versionFile = join(at, systemFileName);
744
- const data = files().exists(versionFile) ? (readYamlValues(versionFile, 'what the version changes, such as "title: ..."') ?? {}) : {};
745
- if (!isMap(data) || data.versions !== undefined) {
746
- const why = isMap(data) ? "a version lists no versions of its own" : "write it as the keys of system.yaml the version changes, such as title: the second rules";
747
- throw new Error(`The game system ${name} cannot be read, because ${versionFile} is not valid: ${why}.`);
748
- }
749
- const { title, ...changes } = data;
750
- return { name: chosen, ...(typeof title === "string" ? { title } : {}), folder: at, data: changes };
751
- }
752
- /** A system's data with its version's over it (VER-3): a map by its names, at every depth, the version's winning; a list or a value in the place of the common one. */
753
- function withVersion(below, over) {
754
- const taken = new Set();
755
- const merged = Object.entries(below).map(([key, value]) => {
756
- const named = nameIn(over, key);
757
- if (named === undefined) {
758
- return [key, value];
759
- }
760
- taken.add(named);
761
- return [named, isMap(value) && isMap(over[named]) ? withVersion(value, over[named]) : over[named]];
762
- });
763
- return Object.fromEntries([...merged, ...Object.entries(over).filter(([key]) => !taken.has(key))]);
764
- }
765
- /**
766
- * "counters.bulwark-dice: unknown key "Bulwark)", a formula with commas goes in quotes": the problems of a system's data, one after the other on
767
- * a line, each at its place.
768
- */
769
- function issuesText(error) {
770
- return error.issues.map((issue) => {
771
- const place = issue.path.map(String).join(".");
772
- const keys = issue.code === "unrecognized_keys" ? issue.keys : [];
773
- const quotes = keys.some((key) => /[()]/.test(key)) ? ": a formula with commas goes in quotes" : "";
774
- const vague = issue.message === "Invalid input" ? "not a value it takes, as system.yaml writes it" : issue.message;
775
- const message = keys.length > 0 ? `unknown ${keys.length === 1 ? "key" : "keys"} ${keys.map((key) => `"${key}"`).join(", ")}${quotes}` : vague;
776
- return place === "" ? `${message}.` : `${place}: ${message}.`;
777
- }).join(" ");
778
- }
779
- /**
780
- * A recipe that sets kept rolls (KEP-4), or a refill on an occasion that no recipe ends, which would never bring the use back (DAT-9): where it is and why;
781
- * undefined when there is none.
782
- */
783
- function strayOccasion(data, formulas) {
784
- const occasions = Object.values(data.recipes ?? {}).flatMap((recipe) => recipe.ends ?? []).filter((occasion, index, all) => all.findIndex((other) => comparableText(other) === comparableText(occasion)) === index);
785
- // Kept rolls come back as the player rolls them again (KEP-4), never at a value a recipe gives.
786
- for (const [recipe, value] of Object.entries(data.recipes ?? {})) {
787
- const rolls = Object.keys(value.set ?? {}).find((field) => Object.entries(data.fields ?? {}).some(([declared, kind]) => kind === "rolls" && comparableText(declared) === comparableText(field)));
788
- if (rolls !== undefined) {
789
- return `recipes.${recipe}.set.${rolls}: ${rolls} keeps rolls, which come back as they are rolled again with roll and keep, not at a value.`;
790
- }
791
- }
792
- for (const [counter, limits] of Object.entries(formulas.counters)) {
793
- const occasion = Object.keys(limits.refill ?? {}).find((candidate) => !occasions.some((other) => comparableText(other) === comparableText(candidate)));
794
- if (occasion !== undefined) {
795
- const known = occasions.length === 0 ? "no recipe ends one yet: give a recipe its ends" : `the occasions are ${occasions.join(", ")}`;
796
- return `counters.${counter}.refill: ${occasion} is no occasion a recipe ends, so it would never come back; ${known}.`;
797
- }
798
- }
799
- return undefined;
800
- }
801
- /** The progression as the system declares it (PRO-1–PRO-4, PRO-6). */
802
- function progressionRule(data) {
803
- const { skip, ...rule } = data;
804
- return { ...rule, skip: skip ?? [] };
805
- }
806
- /** The progression without its experience, when a setting leaves its field out (DAT-10). */
807
- function withoutExperience(progression, kept) {
808
- if (progression.experience === undefined || kept(progression.experience.field)) {
809
- return progression;
810
- }
811
- const rest = { ...progression };
812
- delete rest.experience;
813
- return rest;
814
- }
815
- /** The groups of a system's sheet, each with its note and its icon; a note or an icon for a group the sheet does not have is refused. */
816
- function sheetOf(data, name, path) {
817
- const groups = Object.entries(data.sheet ?? {});
818
- const notes = Object.entries(data["sheet-notes"] ?? {});
819
- const icons = Object.entries(data["sheet-icons"] ?? {});
820
- const byGroup = (pairs, group) => pairs.find(([other]) => comparableText(other) === comparableText(group))?.[1];
821
- for (const [key, pairs] of [["sheet-notes", notes], ["sheet-icons", icons]]) {
822
- const stray = pairs.find(([group]) => !groups.some(([other]) => comparableText(other) === comparableText(group)));
823
- if (stray !== undefined) {
824
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${key}.${stray[0]}: the sheet has no group ${stray[0]}; its groups are ${groups.map(([group]) => group).join(", ")}.`);
825
- }
826
- }
827
- return groups.map(([group, entries]) => {
828
- const note = byGroup(notes, group);
829
- const icon = byGroup(icons, group);
830
- return {
831
- name: group,
832
- entries: entries.map((entry) => {
833
- const [, field, optional, beside] = sheetEntryPattern.exec(entry) ?? [];
834
- return { field, optional: optional === "?", ...(beside === undefined ? {} : { beside }) };
835
- }),
836
- ...(note === undefined ? {} : { note }),
837
- ...(icon === undefined ? {} : { icon }),
838
- };
839
- });
840
- }
841
- /**
842
- * A system's data with a campaign's additions over it (CAM-2): fields, tables, formulas and counters by name, the campaign's taking the place of the system's
843
- * with that name; a recipe added to the system's of that name, field by field, with its occasions and rules; the line's fields after the system's; travel key
844
- * by key, its paces, terrain, vehicles and kinds by name.
845
- */
846
- function withCampaignData(raw, data) {
847
- const base = isMap(raw) ? raw : {};
848
- const merged = { ...base };
849
- for (const key of ["fields", "tables", "computed", "counters", "condition-icons"]) {
850
- const added = mapOf(data[key], key);
851
- merged[key] = added === undefined ? base[key] : { ...withoutNames(isMap(base[key]) ? base[key] : {}, Object.keys(added)), ...added };
852
- }
853
- const recipes = mapOf(data.recipes, "recipes");
854
- if (recipes !== undefined) {
855
- const own = isMap(base.recipes) ? base.recipes : {};
856
- merged.recipes = { ...own, ...Object.fromEntries(Object.entries(recipes).map(([recipe, added]) => [nameIn(own, recipe) ?? recipe, recipeWith(own[nameIn(own, recipe) ?? ""], added, recipe)])) };
857
- }
858
- const travel = mapOf(data.travel, "travel");
859
- if (travel !== undefined) {
860
- const own = isMap(base.travel) ? base.travel : {};
861
- const byName = (key) => (isMap(travel[key]) ? { ...withoutNames(isMap(own[key]) ? own[key] : {}, Object.keys(travel[key])), ...travel[key] } : own[key]);
862
- merged.travel = Object.fromEntries(Object.entries({ ...own, ...travel, paces: byName("paces"), terrain: byName("terrain"), vehicles: byName("vehicles"), kinds: byName("kinds") }).filter(([, value]) => value !== undefined));
863
- }
864
- const names = mapOf(data.values, "values");
865
- if (names !== undefined) {
866
- // A campaign's own names, as a language of its world, join the system's list, on the sheet or everywhere (D-435).
867
- const onSheet = isMap(base["sheet-values"]) ? { ...base["sheet-values"] } : {};
868
- const everywhere = isMap(base.values) ? { ...base.values } : {};
869
- for (const [field, added] of Object.entries(names)) {
870
- if (!Array.isArray(added)) {
871
- throw new Error(`values.${field}: give the names the campaign adds as a list, such as ${field}: [Lingua dei Guadi].`);
872
- }
873
- const target = nameIn(onSheet, field) !== undefined ? onSheet : everywhere;
874
- const key = nameIn(target, field) ?? field;
875
- const own = Array.isArray(target[key]) ? target[key].map(String) : [];
876
- target[key] = [...own, ...added.map(String).filter((name) => !own.some((other) => comparableText(other) === comparableText(name)))];
877
- }
878
- merged.values = everywhere;
879
- merged["sheet-values"] = onSheet;
880
- }
881
- const line = data["status-line"];
882
- if (line !== undefined && line !== null) {
883
- if (!Array.isArray(line)) {
884
- throw new Error("status-line: give it as a list of fields, such as [portent?].");
885
- }
886
- const own = Array.isArray(base["status-line"]) ? base["status-line"].map(String) : [];
887
- const plain = (entry) => comparableText(entry.replace(/\?$/, ""));
888
- const added = line.map(String).filter((entry, index, all) => all.findIndex((other) => plain(other) === plain(entry)) === index);
889
- merged["status-line"] = [...own, ...added.filter((entry) => !own.some((other) => plain(other) === plain(entry)))];
890
- }
891
- return merged;
892
- }
893
- /** A system's recipe with a campaign's over it (CAM-2): what both set and regain, the campaign's first, and the occasions and rules of both. */
894
- function recipeWith(own, added, name) {
895
- if (!isMap(added)) {
896
- throw new Error(`recipes.${name}: give it as what it sets, regains, ends and the rules to read, such as {set: {bulwark-dice: max}}.`);
897
- }
898
- const base = isMap(own) ? own : {};
899
- const map = (key) => isMap(base[key]) || isMap(added[key]) ? { ...withoutNames(isMap(base[key]) ? base[key] : {}, Object.keys(isMap(added[key]) ? added[key] : {})), ...(isMap(added[key]) ? added[key] : {}) } : undefined;
900
- const list = (key) => {
901
- const items = [...(Array.isArray(base[key]) ? base[key] : []), ...(Array.isArray(added[key]) ? added[key] : [])];
902
- return items.length === 0 ? undefined : items.filter((item, index) => items.findIndex((other) => comparableText(String(other)) === comparableText(String(item))) === index);
903
- };
904
- const merged = { ...base, ...added, set: map("set"), regain: map("regain"), lower: map("lower"), ends: list("ends"), rules: list("rules") };
905
- return Object.fromEntries(Object.entries(merged).filter(([, value]) => value !== undefined));
906
- }
907
- /** An addition that must be a map by name, such as counters; undefined when the campaign gives none. */
908
- function mapOf(value, key) {
909
- if (value === undefined || value === null) {
910
- return undefined;
911
- }
912
- if (!isMap(value)) {
913
- throw new Error(`${key}: give it as a map by name, such as {bulwark-dice: ...}.`);
914
- }
915
- return value;
916
- }
917
- /** The entries of a map whose names are none of these, as names are compared. */
918
- function withoutNames(map, names) {
919
- return Object.fromEntries(Object.entries(map).filter(([name]) => !names.some((other) => comparableText(other) === comparableText(name))));
920
- }
921
- /** The name under which a map holds this one, as names are compared. */
922
- function nameIn(map, name) {
923
- return sameName(Object.keys(map), name);
924
- }
925
- /** A verb of the system as the dashboard reads it (D-514): with its sentences on someone, at a square and on oneself only when it lets the player choose. */
926
- function sheetVerbOf(words) {
927
- const choosing = words["says-on"] === undefined ? {} : { on: words["says-on"], at: words["says-at"], self: words["says-self"] };
928
- return { label: words.label, title: words.title, says: words.says, ...choosing };
929
- }
930
- /** How the system's map of a place counts, as the engine reads it (GRD-4): the square in metres. */
931
- function gridOf(data) {
932
- const { square, size, footprints, leaving, ...rest } = data;
933
- return { ...rest, square: readLength(square) ?? 0, ...(size === undefined ? {} : { size }), footprints: footprints ?? {}, ...(leaving === undefined ? {} : { leaving }) };
934
- }
935
- /** The system's travel as the engine reads it (TRV-1–TRV-3): speeds in metres an hour, factors as numbers. */
936
- function travelOf(data) {
937
- const paces = Object.fromEntries(Object.entries(data.paces ?? {}).map(([name, speed]) => [name, readSpeed(speed) ?? 0]));
938
- return {
939
- paces,
940
- pace: data.pace === undefined ? Object.keys(paces)[0] : sameName(Object.keys(paces), data.pace),
941
- hours: data.hours,
942
- rule: data.rule,
943
- beyond: data.beyond,
944
- terrain: Object.fromEntries(Object.entries(data.terrain ?? {}).map(([value, factor]) => [value, factorOf(factor)])),
945
- vehicles: Object.entries(data.vehicles ?? {}).flatMap(([field, values]) => [values].flat().map((value) => ({ field, value }))),
946
- kinds: Object.entries(data.kinds ?? {}).map(([name, kind]) => {
947
- const [field, value] = Object.entries(kind.vehicle ?? {})[0] ?? [];
948
- return {
949
- name,
950
- ...(field === undefined || value === undefined || kind.speed === undefined ? {} : { vehicle: { field, value, speed: kind.speed } }),
951
- hours: kind.hours,
952
- current: kind.current === undefined ? undefined : readSpeed(kind.current),
953
- };
954
- }),
955
- };
956
- }
957
- /** A factor of speed as a number: 1/2 is 0.5. */
958
- function factorOf(factor) {
959
- if (typeof factor === "number") {
960
- return factor;
961
- }
962
- const [numerator, denominator] = factor.split("/").map(Number);
963
- return numerator / denominator;
964
- }
965
- function isMap(value) {
966
- return value !== null && typeof value === "object" && !Array.isArray(value);
967
- }
968
- /** The counters that come back with a rest (DAT-9): those with a refill, and those a recipe sets or regains. */
969
- function usesOf(data) {
970
- const names = [
971
- ...Object.entries(data.counters ?? {}).filter(([, limits]) => limits.refill !== undefined).map(([name]) => name),
972
- ...Object.values(data.recipes ?? {}).flatMap((recipe) => [...Object.keys(recipe.set ?? {}), ...Object.keys(recipe.regain ?? {})]),
973
- ];
974
- return names.filter((name, index) => names.findIndex((other) => comparableText(other) === comparableText(name)) === index);
975
- }
976
- /** The formulas of a recipe's regain, each read at its place (FOR-9). */
977
- function regainOf(regain, name, path, recipe) {
978
- return Object.fromEntries(Object.entries(regain).map(([field, amount]) => [field, formulaAt(amount, `recipes.${recipe}.regain.${field}`, name, path)]));
979
- }
980
- /** A formula of a system's file, refused with the key it stands at (FOR-9). */
981
- function formulaAt(written, place, name, path) {
982
- try {
983
- return formulaOf(written);
984
- }
985
- catch (error) {
986
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${place}: ${error instanceof Error ? error.message : String(error)}`);
987
- }
988
- }
989
- /** The formulas of a system, read once; a system whose formulas do not read cannot be read either (FOR-9). */
990
- function systemFormulas(data, name, path) {
991
- try {
992
- return readFormulas(data);
993
- }
994
- catch (error) {
995
- throw new Error(`The game system ${name} cannot be read, because ${path} is not valid: ${error instanceof Error ? error.message : String(error)}`);
996
- }
997
- }
998
- /** What a state check reads, as written (CHK-2): "hp <= 0" a field against a number, anything else an effect's name. */
999
- function checkAtom(text) {
1000
- const field = checkFieldPattern.exec(text.trim());
1001
- return field === null ? { effect: text.trim() } : { field: field[1], op: field[2], value: Number(field[3]) };
1002
- }
1003
- /** When one is down as the system writes it: "hp 0" read as a field and a number. */
1004
- function downRule(at) {
1005
- const [field, value] = at.split(" ");
1006
- return { field, value: Number(value) };
1007
- }