rpg-engine 0.14.1 → 0.16.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 (493) hide show
  1. package/dist/campaign/index.d.ts +1 -1
  2. package/dist/campaign/index.js +1 -1
  3. package/dist/campaign/last-choices.js +1 -1
  4. package/dist/campaign/settings.d.ts +25 -5
  5. package/dist/campaign/settings.js +38 -9
  6. package/dist/cli/cli.js +1 -1
  7. package/dist/cli/command-line.js +1 -1
  8. package/dist/commands/advance.d.ts +1 -1
  9. package/dist/commands/advance.js +6 -6
  10. package/dist/commands/ask.js +7 -7
  11. package/dist/commands/change/amounts.d.ts +32 -0
  12. package/dist/commands/change/amounts.js +150 -0
  13. package/dist/commands/change/change.d.ts +4 -54
  14. package/dist/commands/change/change.js +19 -749
  15. package/dist/commands/change/damage.d.ts +30 -0
  16. package/dist/commands/change/damage.js +73 -2
  17. package/dist/commands/change/dice.d.ts +34 -0
  18. package/dist/commands/change/dice.js +59 -0
  19. package/dist/commands/change/fields.d.ts +37 -0
  20. package/dist/commands/change/fields.js +156 -0
  21. package/dist/commands/change/holder.d.ts +48 -0
  22. package/dist/commands/change/holder.js +162 -0
  23. package/dist/commands/change/recipe-pace.js +1 -1
  24. package/dist/commands/change/recipe.d.ts +58 -0
  25. package/dist/commands/change/recipe.js +179 -0
  26. package/dist/commands/choices.js +3 -3
  27. package/dist/commands/config/config.d.ts +15 -0
  28. package/dist/commands/config/config.js +355 -0
  29. package/dist/commands/config/custom-levels.d.ts +7 -0
  30. package/dist/commands/config/custom-levels.js +32 -0
  31. package/dist/commands/{config.d.ts → config/dashboard.d.ts} +4 -26
  32. package/dist/commands/config/dashboard.js +171 -0
  33. package/dist/commands/config/entries.d.ts +17 -0
  34. package/dist/commands/config/entries.js +76 -0
  35. package/dist/commands/config/news.d.ts +7 -0
  36. package/dist/commands/config/news.js +88 -0
  37. package/dist/commands/config/shown.d.ts +9 -0
  38. package/dist/commands/config/shown.js +80 -0
  39. package/dist/commands/config/words.d.ts +27 -0
  40. package/dist/commands/config/words.js +204 -0
  41. package/dist/commands/effect.js +9 -9
  42. package/dist/commands/find.d.ts +4 -4
  43. package/dist/commands/find.js +1 -1
  44. package/dist/commands/image.js +6 -6
  45. package/dist/commands/import/import.d.ts +0 -2
  46. package/dist/commands/import/import.js +45 -44
  47. package/dist/commands/import/run.js +1 -1
  48. package/dist/commands/index.js +3 -3
  49. package/dist/commands/init.js +2 -2
  50. package/dist/commands/install.js +1 -1
  51. package/dist/commands/instructions.js +17 -6
  52. package/dist/commands/mode.d.ts +2 -2
  53. package/dist/commands/mode.js +17 -9
  54. package/dist/commands/mood.js +4 -4
  55. package/dist/commands/move.js +10 -10
  56. package/dist/commands/package/consent.d.ts +11 -0
  57. package/dist/commands/package/consent.js +52 -0
  58. package/dist/commands/package/here.d.ts +51 -0
  59. package/dist/commands/package/here.js +128 -0
  60. package/dist/commands/package/install.d.ts +10 -0
  61. package/dist/commands/package/install.js +337 -0
  62. package/dist/commands/package/package.d.ts +18 -0
  63. package/dist/commands/package/package.js +236 -0
  64. package/dist/commands/package/result.d.ts +90 -0
  65. package/dist/commands/package/result.js +1 -0
  66. package/dist/commands/package/uninstall.d.ts +6 -0
  67. package/dist/commands/package/uninstall.js +70 -0
  68. package/dist/commands/rename.js +3 -3
  69. package/dist/commands/reveal.js +5 -5
  70. package/dist/commands/roll/roll.js +11 -9
  71. package/dist/commands/roll/tables.js +1 -1
  72. package/dist/commands/rules.d.ts +2 -2
  73. package/dist/commands/rules.js +3 -3
  74. package/dist/commands/save.d.ts +1 -1
  75. package/dist/commands/save.js +2 -2
  76. package/dist/commands/scene/close.d.ts +18 -0
  77. package/dist/commands/scene/close.js +179 -0
  78. package/dist/commands/scene/members.d.ts +14 -0
  79. package/dist/commands/scene/members.js +32 -0
  80. package/dist/commands/scene/open.d.ts +6 -0
  81. package/dist/commands/scene/open.js +298 -0
  82. package/dist/commands/scene/result.d.ts +98 -0
  83. package/dist/commands/scene/result.js +2 -0
  84. package/dist/commands/{scene.d.ts → scene/scene.d.ts} +10 -36
  85. package/dist/commands/scene/scene.js +210 -0
  86. package/dist/commands/scene/turns.d.ts +18 -0
  87. package/dist/commands/scene/turns.js +229 -0
  88. package/dist/commands/shared/{adventures.d.ts → books/adventures.d.ts} +5 -3
  89. package/dist/commands/shared/{adventures.js → books/adventures.js} +23 -19
  90. package/dist/commands/shared/{library-reader.js → books/library-reader.js} +3 -3
  91. package/dist/commands/shared/{library.d.ts → books/library.d.ts} +2 -2
  92. package/dist/commands/shared/{library.js → books/library.js} +9 -9
  93. package/dist/commands/shared/{rules.d.ts → books/rules.d.ts} +2 -2
  94. package/dist/commands/shared/{rules.js → books/rules.js} +5 -5
  95. package/dist/commands/shared/{system-texts.d.ts → books/system-texts.d.ts} +2 -2
  96. package/dist/commands/shared/{system-texts.js → books/system-texts.js} +9 -8
  97. package/dist/commands/shared/{page-words.d.ts → books/words.d.ts} +2 -2
  98. package/dist/commands/shared/{page-words.js → books/words.js} +4 -4
  99. package/dist/commands/shared/{checks.d.ts → campaign/checks.d.ts} +3 -3
  100. package/dist/commands/shared/{checks.js → campaign/checks.js} +7 -7
  101. package/dist/commands/shared/{images.d.ts → campaign/images.d.ts} +3 -3
  102. package/dist/commands/shared/{images.js → campaign/images.js} +5 -5
  103. package/dist/commands/shared/{mode.d.ts → campaign/mode.d.ts} +4 -4
  104. package/dist/commands/shared/{mode.js → campaign/mode.js} +28 -13
  105. package/dist/commands/shared/{money.d.ts → campaign/money.d.ts} +3 -3
  106. package/dist/commands/shared/{money.js → campaign/money.js} +2 -2
  107. package/dist/commands/shared/{offers.d.ts → campaign/offers.d.ts} +3 -3
  108. package/dist/commands/shared/{offers.js → campaign/offers.js} +3 -3
  109. package/dist/commands/shared/{outside.d.ts → campaign/outside.d.ts} +3 -3
  110. package/dist/commands/shared/{outside.js → campaign/outside.js} +7 -7
  111. package/dist/commands/shared/{parts.d.ts → campaign/parts.d.ts} +10 -3
  112. package/dist/commands/shared/{parts.js → campaign/parts.js} +26 -3
  113. package/dist/commands/shared/{problems.d.ts → campaign/problems.d.ts} +3 -3
  114. package/dist/commands/shared/{problems.js → campaign/problems.js} +17 -17
  115. package/dist/commands/shared/{quests.d.ts → campaign/quests.d.ts} +4 -4
  116. package/dist/commands/shared/{quests.js → campaign/quests.js} +6 -6
  117. package/dist/commands/shared/{saves.d.ts → campaign/saves.d.ts} +4 -4
  118. package/dist/commands/shared/{saves.js → campaign/saves.js} +10 -10
  119. package/dist/commands/shared/{theme.d.ts → campaign/theme.d.ts} +3 -3
  120. package/dist/commands/shared/{theme.js → campaign/theme.js} +1 -1
  121. package/dist/commands/shared/{world.d.ts → campaign/world.d.ts} +5 -5
  122. package/dist/commands/shared/{world.js → campaign/world.js} +17 -14
  123. package/dist/commands/shared/{knowledge.d.ts → characters/knowledge.d.ts} +3 -3
  124. package/dist/commands/shared/{knowledge.js → characters/knowledge.js} +4 -4
  125. package/dist/commands/shared/{moods.d.ts → characters/moods.d.ts} +3 -3
  126. package/dist/commands/shared/{moods.js → characters/moods.js} +3 -3
  127. package/dist/commands/shared/characters/orders.d.ts +4 -0
  128. package/dist/commands/shared/characters/orders.js +10 -0
  129. package/dist/commands/shared/{thoughts.d.ts → characters/thoughts.d.ts} +2 -2
  130. package/dist/commands/shared/{thoughts.js → characters/thoughts.js} +3 -3
  131. package/dist/commands/shared/{voices.d.ts → characters/voices.d.ts} +1 -1
  132. package/dist/commands/shared/{voices.js → characters/voices.js} +2 -2
  133. package/dist/commands/shared/examples.js +2 -2
  134. package/dist/commands/shared/packages/catalog.js +2 -2
  135. package/dist/commands/shared/packages/code.d.ts +1 -1
  136. package/dist/commands/shared/packages/code.js +8 -8
  137. package/dist/commands/shared/packages/extensions.d.ts +1 -1
  138. package/dist/commands/shared/packages/extensions.js +1 -1
  139. package/dist/commands/shared/packages/hooks.d.ts +1 -1
  140. package/dist/commands/shared/packages/hooks.js +1 -1
  141. package/dist/commands/shared/packages/widgets.d.ts +3 -3
  142. package/dist/commands/shared/packages/widgets.js +3 -3
  143. package/dist/commands/shared/{environment.d.ts → places/environment.d.ts} +1 -1
  144. package/dist/commands/shared/{environment.js → places/environment.js} +4 -4
  145. package/dist/commands/shared/{grid-moves.d.ts → places/grid-moves.d.ts} +4 -4
  146. package/dist/commands/shared/{grid-moves.js → places/grid-moves.js} +8 -7
  147. package/dist/commands/shared/{grids.d.ts → places/grids.d.ts} +4 -4
  148. package/dist/commands/shared/{grids.js → places/grids.js} +6 -6
  149. package/dist/commands/shared/{journey.d.ts → places/journey.d.ts} +3 -3
  150. package/dist/commands/shared/{journey.js → places/journey.js} +6 -6
  151. package/dist/commands/shared/{moves.d.ts → places/moves.d.ts} +2 -2
  152. package/dist/commands/shared/{moves.js → places/moves.js} +4 -4
  153. package/dist/commands/shared/{positions.d.ts → places/positions.d.ts} +2 -2
  154. package/dist/commands/shared/{positions.js → places/positions.js} +4 -4
  155. package/dist/commands/shared/{roads.d.ts → places/roads.d.ts} +5 -5
  156. package/dist/commands/shared/{roads.js → places/roads.js} +6 -6
  157. package/dist/commands/shared/{effects.d.ts → scene/effects.d.ts} +7 -7
  158. package/dist/commands/shared/{effects.js → scene/effects.js} +10 -10
  159. package/dist/commands/shared/{loot.d.ts → scene/loot.d.ts} +2 -2
  160. package/dist/commands/shared/{loot.js → scene/loot.js} +3 -3
  161. package/dist/commands/shared/{master-rolls.d.ts → scene/master-rolls.d.ts} +2 -2
  162. package/dist/commands/shared/{master-rolls.js → scene/master-rolls.js} +5 -5
  163. package/dist/commands/shared/{reminders.d.ts → scene/reminders.d.ts} +4 -4
  164. package/dist/commands/shared/{reminders.js → scene/reminders.js} +4 -4
  165. package/dist/commands/shared/{scene.d.ts → scene/scene.d.ts} +3 -3
  166. package/dist/commands/shared/{scene.js → scene/scene.js} +7 -7
  167. package/dist/commands/shared/{bonds.d.ts → sheet/bonds.d.ts} +3 -3
  168. package/dist/commands/shared/{bonds.js → sheet/bonds.js} +2 -2
  169. package/dist/commands/shared/{page-counters.d.ts → sheet/counters.d.ts} +3 -3
  170. package/dist/commands/shared/{page-counters.js → sheet/counters.js} +5 -5
  171. package/dist/commands/shared/{effect-layer.d.ts → sheet/effect-layer.d.ts} +2 -2
  172. package/dist/commands/shared/{effect-layer.js → sheet/effect-layer.js} +9 -6
  173. package/dist/commands/shared/sheet/effect-values.d.ts +9 -0
  174. package/dist/commands/shared/sheet/effect-values.js +69 -0
  175. package/dist/commands/shared/{experience.d.ts → sheet/experience.d.ts} +3 -3
  176. package/dist/commands/shared/{experience.js → sheet/experience.js} +5 -5
  177. package/dist/commands/shared/sheet/formula-problems.d.ts +8 -0
  178. package/dist/commands/shared/sheet/formula-problems.js +140 -0
  179. package/dist/commands/shared/sheet/formula-scope.d.ts +32 -0
  180. package/dist/commands/shared/sheet/formula-scope.js +235 -0
  181. package/dist/commands/shared/{limits.d.ts → sheet/limits.d.ts} +3 -3
  182. package/dist/commands/shared/{limits.js → sheet/limits.js} +5 -4
  183. package/dist/commands/shared/{progression.d.ts → sheet/progression.d.ts} +2 -2
  184. package/dist/commands/shared/{progression.js → sheet/progression.js} +4 -4
  185. package/dist/commands/shared/{sheet.d.ts → sheet/sheet.d.ts} +5 -5
  186. package/dist/commands/shared/{sheet.js → sheet/sheet.js} +11 -7
  187. package/dist/commands/shared/{stacks.d.ts → sheet/stacks.d.ts} +2 -2
  188. package/dist/commands/shared/{stacks.js → sheet/stacks.js} +4 -4
  189. package/dist/commands/shared/sheet/system-fields.d.ts +21 -0
  190. package/dist/commands/shared/sheet/system-fields.js +45 -0
  191. package/dist/commands/shared/{thresholds.d.ts → sheet/thresholds.d.ts} +1 -1
  192. package/dist/commands/shared/{thresholds.js → sheet/thresholds.js} +4 -4
  193. package/dist/commands/shared/{turn-uses.d.ts → sheet/turn-uses.d.ts} +3 -3
  194. package/dist/commands/shared/{turn-uses.js → sheet/turn-uses.js} +4 -3
  195. package/dist/commands/shared/{worked-out.d.ts → sheet/worked-out.d.ts} +11 -46
  196. package/dist/commands/shared/sheet/worked-out.js +291 -0
  197. package/dist/commands/shared/sheet/worked-text.d.ts +14 -0
  198. package/dist/commands/shared/sheet/worked-text.js +55 -0
  199. package/dist/commands/shared/{advance.d.ts → time/advance.d.ts} +3 -3
  200. package/dist/commands/shared/{advance.js → time/advance.js} +11 -11
  201. package/dist/commands/shared/{dice-pool.d.ts → time/dice-pool.d.ts} +3 -3
  202. package/dist/commands/shared/{dice-pool.js → time/dice-pool.js} +11 -11
  203. package/dist/commands/shared/{events.d.ts → time/events.d.ts} +5 -5
  204. package/dist/commands/shared/{events.js → time/events.js} +10 -13
  205. package/dist/commands/shared/{recipes.d.ts → time/recipes.d.ts} +3 -3
  206. package/dist/commands/shared/{recipes.js → time/recipes.js} +6 -5
  207. package/dist/commands/shared/{time.d.ts → time/time.d.ts} +4 -4
  208. package/dist/commands/shared/{time.js → time/time.js} +6 -6
  209. package/dist/commands/shared/{upkeep.d.ts → time/upkeep.d.ts} +3 -3
  210. package/dist/commands/shared/{upkeep.js → time/upkeep.js} +14 -13
  211. package/dist/commands/show.d.ts +4 -1
  212. package/dist/commands/show.js +28 -9
  213. package/dist/commands/status.d.ts +2 -1
  214. package/dist/commands/status.js +34 -23
  215. package/dist/commands/thoughts.js +3 -3
  216. package/dist/commands/trade.js +8 -8
  217. package/dist/commands/translate.d.ts +1 -1
  218. package/dist/commands/translate.js +3 -3
  219. package/dist/commands/travel/open.d.ts +1 -1
  220. package/dist/commands/travel/open.js +2 -2
  221. package/dist/commands/travel/route.js +7 -6
  222. package/dist/commands/travel/travel.d.ts +1 -1
  223. package/dist/commands/travel/travel.js +8 -8
  224. package/dist/commands/validate.js +3 -3
  225. package/dist/commands/view/journal.d.ts +2 -2
  226. package/dist/commands/view/journal.js +2 -2
  227. package/dist/commands/view/map.d.ts +1 -1
  228. package/dist/commands/view/map.js +6 -6
  229. package/dist/commands/view/memory.d.ts +16 -0
  230. package/dist/commands/view/memory.js +90 -0
  231. package/dist/commands/view/page.d.ts +32 -0
  232. package/dist/commands/view/page.js +163 -0
  233. package/dist/commands/view/place.d.ts +7 -2
  234. package/dist/commands/view/place.js +30 -12
  235. package/dist/commands/view/result.d.ts +245 -0
  236. package/dist/commands/view/result.js +1 -0
  237. package/dist/commands/view/saves.d.ts +6 -0
  238. package/dist/commands/view/saves.js +53 -0
  239. package/dist/commands/view/story.d.ts +32 -0
  240. package/dist/commands/view/story.js +227 -0
  241. package/dist/commands/view/view.d.ts +26 -292
  242. package/dist/commands/view/view.js +26 -534
  243. package/dist/commands/view/world.d.ts +1 -1
  244. package/dist/commands/view/world.js +3 -3
  245. package/dist/commands/write/checks.d.ts +42 -0
  246. package/dist/commands/write/checks.js +291 -0
  247. package/dist/commands/write/here.d.ts +1 -1
  248. package/dist/commands/write/here.js +5 -5
  249. package/dist/commands/write/inheritance.d.ts +40 -0
  250. package/dist/commands/write/inheritance.js +189 -0
  251. package/dist/commands/write/input.d.ts +29 -0
  252. package/dist/commands/write/input.js +124 -0
  253. package/dist/commands/write/layer.d.ts +36 -0
  254. package/dist/commands/write/layer.js +48 -0
  255. package/dist/commands/write/notes.d.ts +22 -0
  256. package/dist/commands/write/notes.js +76 -0
  257. package/dist/commands/write/progression.d.ts +27 -0
  258. package/dist/commands/write/progression.js +175 -0
  259. package/dist/commands/write/write.d.ts +2 -1
  260. package/dist/commands/write/write.js +33 -817
  261. package/dist/core/files.d.ts +2 -0
  262. package/dist/core/files.js +7 -0
  263. package/dist/core/{package-declarations.d.ts → packages/declarations.d.ts} +1 -1
  264. package/dist/core/{package-declarations.js → packages/declarations.js} +1 -1
  265. package/dist/core/session-store.js +3 -3
  266. package/dist/core/store.d.ts +2 -2
  267. package/dist/core/store.js +18 -4
  268. package/dist/dashboard/acts/acts.js +1 -1
  269. package/dist/dashboard/acts/sending.js +110 -0
  270. package/dist/dashboard/acts/sheet.js +2 -2
  271. package/dist/dashboard/acts/strip.js +1 -1
  272. package/dist/dashboard/address.js +6 -0
  273. package/dist/dashboard/api.js +1 -1
  274. package/dist/dashboard/app.js +47 -171
  275. package/dist/dashboard/dice/roller.js +1 -1
  276. package/dist/dashboard/dice/sets.js +2 -2
  277. package/dist/dashboard/dice/stage.js +1 -1
  278. package/dist/dashboard/dice/tray.js +6 -6
  279. package/dist/dashboard/guide/ar.md +9 -4
  280. package/dist/dashboard/guide/cs.md +10 -5
  281. package/dist/dashboard/guide/da.md +9 -4
  282. package/dist/dashboard/guide/de.md +9 -4
  283. package/dist/dashboard/guide/el.md +10 -5
  284. package/dist/dashboard/guide/en.md +7 -2
  285. package/dist/dashboard/guide/es.md +9 -4
  286. package/dist/dashboard/guide/fi.md +9 -4
  287. package/dist/dashboard/guide/fr.md +9 -4
  288. package/dist/dashboard/guide/he.md +9 -4
  289. package/dist/dashboard/guide/hi.md +10 -5
  290. package/dist/dashboard/guide/hu.md +10 -5
  291. package/dist/dashboard/guide/is.md +9 -4
  292. package/dist/dashboard/guide/it.md +9 -4
  293. package/dist/dashboard/guide/ja.md +12 -7
  294. package/dist/dashboard/guide/ko.md +11 -6
  295. package/dist/dashboard/guide/nb.md +9 -4
  296. package/dist/dashboard/guide/nl.md +10 -5
  297. package/dist/dashboard/guide/pl.md +9 -4
  298. package/dist/dashboard/guide/pt.md +9 -4
  299. package/dist/dashboard/guide/ro.md +9 -4
  300. package/dist/dashboard/guide/ru.md +9 -4
  301. package/dist/dashboard/guide/sv.md +9 -4
  302. package/dist/dashboard/guide/tr.md +11 -6
  303. package/dist/dashboard/guide/uk.md +9 -4
  304. package/dist/dashboard/guide/zh.md +9 -4
  305. package/dist/dashboard/help/help.js +3 -3
  306. package/dist/dashboard/i18n/ar.json +20 -0
  307. package/dist/dashboard/i18n/cs.json +20 -0
  308. package/dist/dashboard/i18n/da.json +20 -0
  309. package/dist/dashboard/i18n/de.json +20 -0
  310. package/dist/dashboard/i18n/el.json +20 -0
  311. package/dist/dashboard/i18n/es.json +20 -0
  312. package/dist/dashboard/i18n/fi.json +20 -0
  313. package/dist/dashboard/i18n/fr.json +20 -0
  314. package/dist/dashboard/i18n/he.json +20 -0
  315. package/dist/dashboard/i18n/hi.json +20 -0
  316. package/dist/dashboard/i18n/hu.json +20 -0
  317. package/dist/dashboard/i18n/is.json +20 -0
  318. package/dist/dashboard/i18n/it.json +20 -0
  319. package/dist/dashboard/i18n/ja.json +21 -1
  320. package/dist/dashboard/i18n/ko.json +20 -0
  321. package/dist/dashboard/i18n/nb.json +20 -0
  322. package/dist/dashboard/i18n/nl.json +20 -0
  323. package/dist/dashboard/i18n/pl.json +20 -0
  324. package/dist/dashboard/i18n/pt.json +20 -0
  325. package/dist/dashboard/i18n/ro.json +20 -0
  326. package/dist/dashboard/i18n/ru.json +20 -0
  327. package/dist/dashboard/i18n/sv.json +20 -0
  328. package/dist/dashboard/i18n/tr.json +20 -0
  329. package/dist/dashboard/i18n/uk.json +20 -0
  330. package/dist/dashboard/i18n/zh.json +20 -0
  331. package/dist/dashboard/{journal.js → journal/journal.js} +16 -16
  332. package/dist/dashboard/{notes.js → journal/notes.js} +4 -4
  333. package/dist/dashboard/kit.js +3 -3
  334. package/dist/dashboard/packages/ask-card.js +3 -3
  335. package/dist/dashboard/packages/catalog.js +196 -0
  336. package/dist/dashboard/packages/engine.js +87 -0
  337. package/dist/dashboard/packages/installed.js +53 -0
  338. package/dist/dashboard/packages/library.js +97 -0
  339. package/dist/dashboard/packages/outcomes.js +45 -0
  340. package/dist/dashboard/packages/packages.js +20 -576
  341. package/dist/dashboard/packages/page-code.js +15 -2
  342. package/dist/dashboard/packages/{package-page.js → page.js} +12 -5
  343. package/dist/dashboard/packages/rows.js +84 -0
  344. package/dist/dashboard/packages/share.js +44 -0
  345. package/dist/dashboard/packages/widgets.js +3 -3
  346. package/dist/dashboard/{card.js → parts/card.js} +1 -1
  347. package/dist/dashboard/{faces.js → parts/faces.js} +5 -5
  348. package/dist/dashboard/{game-words.js → parts/game-words.js} +1 -1
  349. package/dist/dashboard/{icons.js → parts/icons.js} +1 -1
  350. package/dist/dashboard/{labels.js → parts/labels.js} +8 -1
  351. package/dist/dashboard/{map-symbols.js → parts/map-symbols.js} +1 -1
  352. package/dist/dashboard/{markdown.js → parts/markdown.js} +2 -2
  353. package/dist/dashboard/{mood.js → parts/mood.js} +1 -1
  354. package/dist/dashboard/{refusals.js → parts/refusals.js} +1 -1
  355. package/dist/dashboard/{status.js → parts/status.js} +4 -4
  356. package/dist/dashboard/{widgets.js → parts/widgets.js} +2 -2
  357. package/dist/dashboard/place/key.js +24 -0
  358. package/dist/dashboard/place/paper.js +67 -0
  359. package/dist/dashboard/place/{map-sheet.js → sheet.js} +2 -2
  360. package/dist/dashboard/place/things.js +129 -0
  361. package/dist/dashboard/place/tokens.js +93 -0
  362. package/dist/dashboard/place/view.js +124 -0
  363. package/dist/dashboard/{asked-dice.js → play/asked-dice.js} +3 -3
  364. package/dist/dashboard/{asked.js → play/asked.js} +10 -10
  365. package/dist/dashboard/{choices.js → play/choices.js} +9 -9
  366. package/dist/dashboard/{requested.js → play/requested.js} +1 -1
  367. package/dist/dashboard/{rolls.js → play/rolls.js} +9 -9
  368. package/dist/dashboard/{scene.js → play/scene.js} +14 -14
  369. package/dist/dashboard/{turns.js → play/turns.js} +12 -12
  370. package/dist/dashboard/{language-choice.js → settings/language-choice.js} +1 -1
  371. package/dist/dashboard/{languages.js → settings/languages.js} +1 -1
  372. package/dist/dashboard/{saves.js → settings/saves.js} +8 -8
  373. package/dist/dashboard/{settings.js → settings/settings.js} +17 -15
  374. package/dist/dashboard/{setup.js → settings/setup.js} +6 -6
  375. package/dist/dashboard/{party.js → sheet/party.js} +8 -8
  376. package/dist/dashboard/{person-panel.js → sheet/person-panel.js} +4 -4
  377. package/dist/dashboard/{sheet.js → sheet/sheet.js} +17 -17
  378. package/dist/dashboard/{story.js → sheet/story.js} +3 -3
  379. package/dist/dashboard/{columns.js → shell/columns.js} +1 -1
  380. package/dist/dashboard/{footer.js → shell/footer.js} +3 -3
  381. package/dist/dashboard/{master.js → shell/master.js} +2 -2
  382. package/dist/dashboard/{notices.js → shell/notices.js} +3 -3
  383. package/dist/dashboard/{pages.js → shell/pages.js} +5 -5
  384. package/dist/dashboard/shell/shown.js +37 -0
  385. package/dist/dashboard/{table.js → shell/table.js} +2 -2
  386. package/dist/dashboard/{tabs.js → shell/tabs.js} +2 -2
  387. package/dist/dashboard/{top.js → shell/top.js} +7 -7
  388. package/dist/dashboard/style.css +90 -9
  389. package/dist/dashboard/world/calendar.js +4 -4
  390. package/dist/dashboard/world/drawing.js +92 -0
  391. package/dist/dashboard/world/key.js +21 -0
  392. package/dist/dashboard/world/lore.js +5 -5
  393. package/dist/dashboard/world/map-card.js +186 -0
  394. package/dist/dashboard/world/place-card.js +39 -0
  395. package/dist/dashboard/world/places.js +29 -0
  396. package/dist/dashboard/world/world.js +9 -341
  397. package/dist/extensions/extension.d.ts +1 -1
  398. package/dist/extensions/extension.js +1 -1
  399. package/dist/images/images.js +12 -9
  400. package/dist/index.d.ts +1 -1
  401. package/dist/languages/index.d.ts +1 -1
  402. package/dist/languages/index.js +1 -1
  403. package/dist/library/books.js +2 -0
  404. package/dist/packages/npm.js +1 -1
  405. package/dist/page.d.ts +2 -2
  406. package/dist/page.js +1 -1
  407. package/dist/pages/check.js +23 -1
  408. package/dist/pages/containers.d.ts +1 -1
  409. package/dist/pages/containers.js +1 -1
  410. package/dist/pages/index.d.ts +4 -2
  411. package/dist/pages/index.js +4 -2
  412. package/dist/pages/inheritance.d.ts +2 -2
  413. package/dist/pages/layers.d.ts +50 -0
  414. package/dist/pages/layers.js +97 -0
  415. package/dist/pages/rename-page.js +1 -1
  416. package/dist/pages/stacks/writes.js +48 -22
  417. package/dist/pages/standard-fields.d.ts +1 -1
  418. package/dist/pages/system-pages.d.ts +5 -3
  419. package/dist/pages/system-pages.js +16 -7
  420. package/dist/pages/world.d.ts +8 -1
  421. package/dist/pages/world.js +16 -4
  422. package/dist/pages/write-layer.d.ts +18 -0
  423. package/dist/pages/write-layer.js +108 -0
  424. package/dist/pages/write-page.d.ts +2 -2
  425. package/dist/pages/write-page.js +2 -2
  426. package/dist/rules/index.d.ts +1 -1
  427. package/dist/rules/index.js +1 -1
  428. package/dist/rules/search.d.ts +1 -1
  429. package/dist/rules/shown.d.ts +1 -1
  430. package/dist/server/dashboard/choices.js +3 -3
  431. package/dist/server/dashboard/files.js +5 -5
  432. package/dist/server/dashboard/index.d.ts +2 -2
  433. package/dist/server/dashboard/index.js +2 -2
  434. package/dist/server/dashboard/news.js +4 -3
  435. package/dist/server/dashboard/player.js +1 -1
  436. package/dist/server/dashboard/writes.js +10 -8
  437. package/dist/server/mcp.js +28 -13
  438. package/dist/systems/campaign-data.d.ts +15 -0
  439. package/dist/systems/campaign-data.js +85 -0
  440. package/dist/systems/{system-code.d.ts → code.d.ts} +1 -1
  441. package/dist/systems/{system-code.js → code.js} +2 -2
  442. package/dist/systems/game-system.d.ts +7 -61
  443. package/dist/systems/game-system.js +1 -984
  444. package/dist/systems/index.d.ts +6 -3
  445. package/dist/systems/index.js +6 -3
  446. package/dist/systems/installed.d.ts +31 -0
  447. package/dist/systems/installed.js +89 -0
  448. package/dist/systems/maps.d.ts +3 -0
  449. package/dist/systems/maps.js +9 -0
  450. package/dist/systems/read.d.ts +3 -0
  451. package/dist/systems/read.js +471 -0
  452. package/dist/systems/schema.d.ts +289 -0
  453. package/dist/systems/schema.js +243 -0
  454. package/dist/systems/settings.d.ts +19 -0
  455. package/dist/systems/settings.js +78 -0
  456. package/dist/systems/versions.d.ts +12 -0
  457. package/dist/systems/versions.js +52 -0
  458. package/dist/testing/index.js +1 -1
  459. package/instructions/import.md +1 -1
  460. package/instructions/length-a-few-sessions.md +1 -0
  461. package/instructions/length-one-evening.md +1 -0
  462. package/instructions/play.md +1 -1
  463. package/instructions/session-zero.md +1 -1
  464. package/instructions/setup.md +1 -1
  465. package/package.json +1 -1
  466. package/dist/commands/config.js +0 -917
  467. package/dist/commands/package.d.ts +0 -143
  468. package/dist/commands/package.js +0 -785
  469. package/dist/commands/scene.js +0 -894
  470. package/dist/commands/shared/worked-out.js +0 -805
  471. package/dist/dashboard/place/map-view.js +0 -417
  472. /package/dist/commands/shared/{library-reader.d.ts → books/library-reader.d.ts} +0 -0
  473. /package/dist/core/{package-api.d.ts → packages/api.d.ts} +0 -0
  474. /package/dist/core/{package-api.js → packages/api.js} +0 -0
  475. /package/dist/dashboard/{coins.js → parts/coins.js} +0 -0
  476. /package/dist/dashboard/{glass.js → parts/glass.js} +0 -0
  477. /package/dist/dashboard/{layout.js → parts/layout.js} +0 -0
  478. /package/dist/dashboard/{mood-faces.js → parts/mood-faces.js} +0 -0
  479. /package/dist/dashboard/{free-rolls.js → play/free-rolls.js} +0 -0
  480. /package/dist/dashboard/{reactions.js → play/reactions.js} +0 -0
  481. /package/dist/dashboard/{prefs.js → shell/prefs.js} +0 -0
  482. /package/dist/dashboard/{system-style.js → shell/system-style.js} +0 -0
  483. /package/dist/dashboard/{theme.js → shell/theme.js} +0 -0
  484. /package/dist/languages/{language-pack.d.ts → pack.d.ts} +0 -0
  485. /package/dist/languages/{language-pack.js → pack.js} +0 -0
  486. /package/dist/pages/{page-file.d.ts → file.d.ts} +0 -0
  487. /package/dist/pages/{page-file.js → file.js} +0 -0
  488. /package/dist/pages/{page-types.d.ts → types.d.ts} +0 -0
  489. /package/dist/pages/{page-types.js → types.js} +0 -0
  490. /package/dist/rules/{rule-book.d.ts → book.d.ts} +0 -0
  491. /package/dist/rules/{rule-book.js → book.js} +0 -0
  492. /package/dist/systems/{system-folders.d.ts → folders.d.ts} +0 -0
  493. /package/dist/systems/{system-folders.js → folders.js} +0 -0
@@ -1,12 +1,12 @@
1
1
  export { checkWorld, equippedNotes, goodsFieldProblems } from "./check.ts";
2
2
  export { applyMove, type MovePlan, MoveStopped, planLeave, planMove, type StackCount } from "./containers.ts";
3
3
  export { changedEnvironment, environmentAt, type EnvironmentEntry, formatEnvironmentEntry, placesAround, readEnvironment } from "./environment.ts";
4
+ export { changedFields, type FieldChange, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./file.ts";
4
5
  export { baseChain, baseFieldOf, baseValue, derivedPages, followersOf, holdsField, type Inherited, inheritedByBase, inheritedFields, introductionFollowersOf, isNeverInherited, keepersOf, newBaseProblem, ownField, ownFieldChange, removedFieldName, sameAsBase, sectionFollowersOf, shownPart, uniquePage, writtenFieldName, } from "./inheritance.ts";
6
+ export { layeredPage, layeredPages, layerFolder, type LayerMark, layersFolderName, systemOriginal } from "./layers.ts";
5
7
  export { carriedWeight, type LoadRule, weightUnit } from "./load.ts";
6
8
  export { type MapField, mapKey, mapOf, mapProblems, type PlaceMap, readMapField, sameFrame } from "./maps.ts";
7
9
  export { everyGoalTicked, firstTable, goalsIn, introductionText, type Link, links, partContent, readSection, secretNames, sectionTitles, type TextMode, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, withoutUnreadSecrets, } from "./markdown.ts";
8
- export { changedFields, type FieldChange, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./page-file.ts";
9
- export { type PageType, pageTypeNames, worldFolderName } from "./page-types.ts";
10
10
  export { formatPosition, type Position, readPosition } from "./positions.ts";
11
11
  export { applyRename, planRename, type Renamed, renamedLinks, type RenamePlan } from "./rename-page.ts";
12
12
  export { readStops, type Stops } from "./roads.ts";
@@ -14,5 +14,7 @@ export { countedText, entryOfKind, type EntryReading, readEntry, withStackCount
14
14
  export { carriesKind, carriesNamed, entryKind, entryPage, goodsNamed, type HeldStack, heldStacks, heldStacksOfKind, isKind, kindNamed, ownStack, pageNamedQuietly, type Stack, stackName, stacksOf } from "./stacks/kinds.ts";
15
15
  export { canHold, containerFieldOf, isCoreField, isCounterField, isEmptyField, isStandardField, listFieldNames, misspelledFieldProblem, misspelledStandardField, newPageFields, standardValues } from "./standard-fields.ts";
16
16
  export { alwaysInList, declaredKind, hidingMessage, isDeclaredUncounted, kindMessage, readOnlyMessage, systemKnowsReason, systemLabel } from "./system-pages.ts";
17
+ export { type PageType, pageTypeNames, worldFolderName } from "./types.ts";
17
18
  export { type Backlink, backlinks, bonusPages, concernsPlayer, createWorld, findPage, isCountedItem, isInParty, isPartyMember, isPlayerCharacter, linksIn, loadWorld, locate, namesakes, type Page, pageFileNamed, type PageMatch, pageNamed, pagesWithName, pagesWithNameOrAlias, pageWithPath, parsePageReference, playerCharacters, searchPages, searchSystemPages, systemFirstFix, type SystemInfo, systemPageNamed, type SystemPages, textsIn, validHoldersOf, versionTranslations, withPage, type World, } from "./world.ts";
19
+ export { type LayerWrite, writeLayer } from "./write-layer.ts";
18
20
  export { checkFieldChange, type PageChange, writePage } from "./write-page.ts";
@@ -2,12 +2,12 @@
2
2
  export { checkWorld, equippedNotes, goodsFieldProblems } from "./check.js";
3
3
  export { applyMove, MoveStopped, planLeave, planMove } from "./containers.js";
4
4
  export { changedEnvironment, environmentAt, formatEnvironmentEntry, placesAround, readEnvironment } from "./environment.js";
5
+ export { changedFields, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./file.js";
5
6
  export { baseChain, baseFieldOf, baseValue, derivedPages, followersOf, holdsField, inheritedByBase, inheritedFields, introductionFollowersOf, isNeverInherited, keepersOf, newBaseProblem, ownField, ownFieldChange, removedFieldName, sameAsBase, sectionFollowersOf, shownPart, uniquePage, writtenFieldName, } from "./inheritance.js";
7
+ export { layeredPage, layeredPages, layerFolder, layersFolderName, systemOriginal } from "./layers.js";
6
8
  export { carriedWeight, weightUnit } from "./load.js";
7
9
  export { mapKey, mapOf, mapProblems, readMapField, sameFrame } from "./maps.js";
8
10
  export { everyGoalTicked, firstTable, goalsIn, introductionText, links, partContent, readSection, secretNames, sectionTitles, textParts, withLinksAsWords, withoutComments, withoutFencedBlocks, withoutUnreadSecrets, } from "./markdown.js";
9
- export { changedFields, formatFields, linkListItems, readFields, readFieldValue, splitPageFile } from "./page-file.js";
10
- export { pageTypeNames, worldFolderName } from "./page-types.js";
11
11
  export { formatPosition, readPosition } from "./positions.js";
12
12
  export { applyRename, planRename, renamedLinks } from "./rename-page.js";
13
13
  export { readStops } from "./roads.js";
@@ -15,5 +15,7 @@ export { countedText, entryOfKind, readEntry, withStackCount } from "./stacks/en
15
15
  export { carriesKind, carriesNamed, entryKind, entryPage, goodsNamed, heldStacks, heldStacksOfKind, isKind, kindNamed, ownStack, pageNamedQuietly, stackName, stacksOf } from "./stacks/kinds.js";
16
16
  export { canHold, containerFieldOf, isCoreField, isCounterField, isEmptyField, isStandardField, listFieldNames, misspelledFieldProblem, misspelledStandardField, newPageFields, standardValues } from "./standard-fields.js";
17
17
  export { alwaysInList, declaredKind, hidingMessage, isDeclaredUncounted, kindMessage, readOnlyMessage, systemKnowsReason, systemLabel } from "./system-pages.js";
18
+ export { pageTypeNames, worldFolderName } from "./types.js";
18
19
  export { backlinks, bonusPages, concernsPlayer, createWorld, findPage, isCountedItem, isInParty, isPartyMember, isPlayerCharacter, linksIn, loadWorld, locate, namesakes, pageFileNamed, pageNamed, pagesWithName, pagesWithNameOrAlias, pageWithPath, parsePageReference, playerCharacters, searchPages, searchSystemPages, systemFirstFix, systemPageNamed, textsIn, validHoldersOf, versionTranslations, withPage, } from "./world.js";
20
+ export { writeLayer } from "./write-layer.js";
19
21
  export { checkFieldChange, writePage } from "./write-page.js";
@@ -1,5 +1,5 @@
1
- import type { FieldChange } from "./page-file.ts";
2
- import type { PageType } from "./page-types.ts";
1
+ import type { FieldChange } from "./file.ts";
2
+ import type { PageType } from "./types.ts";
3
3
  import { type Page, type World } from "./world.ts";
4
4
  /** A field and its value as a page writes it. */
5
5
  interface FieldValue {
@@ -0,0 +1,50 @@
1
+ import type { FieldKind } from "../core/field-kind.ts";
2
+ import type { Page } from "./world.ts";
3
+ /** The folder of a campaign that holds its layers, one folder for each game system. */
4
+ export declare const layersFolderName = "layers";
5
+ /** What a campaign's layer changed on a page of its game system (SYS-11), for show and validate. */
6
+ export interface LayerMark {
7
+ /** The layer's file, from the campaign folder, such as layers/5e/world/creatures/Goblin.md. */
8
+ path: string;
9
+ /** The fields the layer gives the page, as it names them. */
10
+ fields: string[];
11
+ /** The sections and secrets the layer writes, replaced or added. */
12
+ sections: string[];
13
+ /** Whether the layer writes the introduction. */
14
+ introduction: boolean;
15
+ /** Fields written by hand that a layer cannot change, which the page reads from the system all the same: the type, the name, those never inherited (INH-8) and a kind's counters (STK-1). */
16
+ ignored: string[];
17
+ }
18
+ /** The folder of the layers a campaign in `root` writes over the pages of a game system. */
19
+ export declare function layerFolder(root: string, system: string): string;
20
+ /**
21
+ * The pages of a game system with the campaign's layers over them (SYS-11), and the layers that lie over no page. `layers` are read from the layers' folder of the
22
+ * system, with their paths from it, the same as the pages' from the system's; `prefix` is that folder from the campaign, for the mark. A page without a layer stays
23
+ * the very object it was.
24
+ */
25
+ export declare function layeredPages(pages: Page[], layers: Page[], prefix: string, declared?: Record<string, FieldKind>): {
26
+ pages: Page[];
27
+ stray: string[];
28
+ };
29
+ /**
30
+ * A page of the game system with a layer over it: the layer's fields take the place of the page's, a section of the layer that of the section with its name, or is added,
31
+ * and its introduction, when it has one, that of the page's. The translated text changes the same way where it has the section, else it goes, so that the
32
+ * campaign's text is never hidden. The page stays the system's.
33
+ */
34
+ export declare function layeredPage(page: Page, layer: {
35
+ fields: Record<string, unknown>;
36
+ body: string;
37
+ }, path: string, declared?: Record<string, FieldKind>): Page;
38
+ /** The page of the game system as the system writes it, under the campaign's layer; the page itself when it has none. */
39
+ export declare function systemOriginal(page: Page): Page;
40
+ /**
41
+ * Whether a layer may give a page of the game system this field (SYS-11): never its name or type, a field never inherited (INH-8), which would put it somewhere or
42
+ * make it known, nor a counter of uses to an item that has none, which would make a kind no kind (STK-1); a field the system `declared` uncounted is no counter.
43
+ */
44
+ export declare function layerTakes(page: Page, field: string, value: unknown, declared?: Record<string, FieldKind>): boolean;
45
+ /** The sections and secrets of a layer's text, each with its own text and whether it is a secret. */
46
+ export declare function layerParts(body: string): {
47
+ name: string;
48
+ content: string;
49
+ secret: boolean;
50
+ }[];
@@ -0,0 +1,97 @@
1
+ // The campaign's layers over the pages of its game system (SYS-11, D-564): a file at the page's path under layers/<system>/, holding only what changes.
2
+ import { join } from "node:path";
3
+ import { frozen } from "../core/frozen.js";
4
+ import { comparableText } from "../core/text.js";
5
+ import { isNeverInherited } from "./inheritance.js";
6
+ import { introductionText, partContent, textParts, writeText } from "./markdown.js";
7
+ import { kindIn } from "./system-pages.js";
8
+ /** The folder of a campaign that holds its layers, one folder for each game system. */
9
+ export const layersFolderName = "layers";
10
+ /** The folder of the layers a campaign in `root` writes over the pages of a game system. */
11
+ export function layerFolder(root, system) {
12
+ return join(root, layersFolderName, system);
13
+ }
14
+ /**
15
+ * The pages of a game system with the campaign's layers over them (SYS-11), and the layers that lie over no page. `layers` are read from the layers' folder of the
16
+ * system, with their paths from it, the same as the pages' from the system's; `prefix` is that folder from the campaign, for the mark. A page without a layer stays
17
+ * the very object it was.
18
+ */
19
+ export function layeredPages(pages, layers, prefix, declared) {
20
+ const byPath = new Map(layers.map((layer) => [comparableText(layer.path), layer]));
21
+ const used = new Set();
22
+ const merged = pages.map((page) => {
23
+ const layer = byPath.get(comparableText(page.path));
24
+ if (layer === undefined) {
25
+ return page;
26
+ }
27
+ used.add(layer);
28
+ return layeredPage(page, layer, `${prefix}/${layer.path}`, declared);
29
+ });
30
+ const stray = layers.filter((layer) => !used.has(layer)).map((layer) => `${prefix}/${layer.path}`);
31
+ return { pages: merged, stray };
32
+ }
33
+ /**
34
+ * A page of the game system with a layer over it: the layer's fields take the place of the page's, a section of the layer that of the section with its name, or is added,
35
+ * and its introduction, when it has one, that of the page's. The translated text changes the same way where it has the section, else it goes, so that the
36
+ * campaign's text is never hidden. The page stays the system's.
37
+ */
38
+ export function layeredPage(page, layer, path, declared) {
39
+ const ignored = Object.entries(layer.fields).filter(([field, value]) => !layerTakes(page, field, value, declared)).map(([field]) => field);
40
+ const given = Object.entries(layer.fields).filter(([field]) => !ignored.includes(field));
41
+ const fields = { ...page.fields };
42
+ for (const [field, value] of given) {
43
+ // Under the name the system gives the field, as INH-5 compares names.
44
+ const key = Object.keys(page.fields).find((own) => comparableText(own) === comparableText(field)) ?? field;
45
+ fields[key] = value;
46
+ }
47
+ const parts = layerParts(layer.body);
48
+ const introduction = introductionText(layer.body);
49
+ let body = page.body;
50
+ let translated = page.translated;
51
+ for (const part of parts) {
52
+ body = writeText(body, part.content, { section: part.name, mode: "replace", secret: part.secret && partContent(body, part.name) === undefined });
53
+ translated = translated === undefined || partContent(translated, part.name) === undefined
54
+ ? undefined
55
+ : writeText(translated, part.content, { section: part.name, mode: "replace", secret: false });
56
+ }
57
+ if (introduction !== "") {
58
+ body = writeText(body, introduction, { mode: "replace" });
59
+ translated = translated === undefined ? undefined : writeText(translated, introduction, { mode: "replace" });
60
+ }
61
+ const layered = { path, fields: given.map(([field]) => field), sections: parts.map((part) => part.name), introduction: introduction !== "", ignored };
62
+ const merged = { ...page, fields, body, translated, layer: layered };
63
+ // A translation the layer could not follow goes, so that the campaign's text is never hidden.
64
+ if (translated === undefined) {
65
+ delete merged.translated;
66
+ }
67
+ originals.set(merged, page);
68
+ return frozen(merged);
69
+ }
70
+ /** The page of the game system as the system writes it, under the campaign's layer; the page itself when it has none. */
71
+ export function systemOriginal(page) {
72
+ return originals.get(page) ?? page;
73
+ }
74
+ /**
75
+ * Whether a layer may give a page of the game system this field (SYS-11): never its name or type, a field never inherited (INH-8), which would put it somewhere or
76
+ * make it known, nor a counter of uses to an item that has none, which would make a kind no kind (STK-1); a field the system `declared` uncounted is no counter.
77
+ */
78
+ export function layerTakes(page, field, value, declared) {
79
+ if (["name", "type"].includes(comparableText(field)) || isNeverInherited(field)) {
80
+ return false;
81
+ }
82
+ const counted = (name, given) => isUses(given) && [undefined, "counter"].includes(kindIn(declared, name));
83
+ return page.type !== "item" || !counted(field, value) || Object.entries(page.fields).some(([name, given]) => counted(name, given));
84
+ }
85
+ /** The sections and secrets of a layer's text, each with its own text and whether it is a secret. */
86
+ export function layerParts(body) {
87
+ return textParts(body).filter((part) => part.name !== "").flatMap((part) => {
88
+ const own = partContent(body, part.name);
89
+ return own === undefined ? [] : [{ name: part.name, ...own }];
90
+ });
91
+ }
92
+ const originals = new WeakMap();
93
+ // A counter with a maximum, as uses: 3/3, which an item that is a kind never has (STK-1).
94
+ const usesPattern = /^\s*-?\d+\s*\/\s*\d+\s*$/;
95
+ function isUses(value) {
96
+ return typeof value === "string" && usesPattern.test(value);
97
+ }
@@ -3,8 +3,8 @@
3
3
  import { dirname, join } from "node:path";
4
4
  import { files } from "../core/store.js";
5
5
  import { comparableText, linkTargetName } from "../core/text.js";
6
+ import { changeFields, joinPageFile, readFields, splitPageFile } from "./file.js";
6
7
  import { inProse } from "./markdown.js";
7
- import { changeFields, joinPageFile, readFields, splitPageFile } from "./page-file.js";
8
8
  import { checkPageName, otherPagesWithAlias, pagesWithName, systemPageNamed, textsIn } from "./world.js";
9
9
  /**
10
10
  * Plans the rename of a page of the campaign and of every link to it in the campaign's pages, writing nothing; refused for a page of the game system, a name
@@ -1,8 +1,8 @@
1
1
  // What write may do to the stacks of a container's list (STK-10): count only kinds, one stack of each, whose counts change only with change.
2
2
  import { comparableText } from "../../core/text.js";
3
3
  import { bundleOf } from "../load.js";
4
- import { containerFieldOf } from "../standard-fields.js";
5
- import { pageNamed, searchSystemPages, textsIn, validHoldersOf } from "../world.js";
4
+ import { canHold, containerFieldOf } from "../standard-fields.js";
5
+ import { pageNamed, pagesWithNameOrAlias, searchSystemPages, systemPageNamed, textsIn, validHoldersOf } from "../world.js";
6
6
  import { countedText, countOf, readEntry } from "./entry.js";
7
7
  import { canCount, entryKind, entryPage, goodsNamed, isKind, notKindReason, stacksOf } from "./kinds.js";
8
8
  /**
@@ -38,18 +38,10 @@ export function checkStacks(world, holder, field, before, after) {
38
38
  const was = textsIn(before).map((entry) => entry.trim());
39
39
  const now = textsIn(after).map((entry) => entry.trim());
40
40
  const added = now.filter((entry) => !was.includes(entry));
41
- for (const entry of added) {
42
- const read = readEntry(entry);
43
- const page = read.shape === "text" ? undefined : entryPage(world, read.page);
44
- if (read.shape === "text") {
45
- checkCountedText(world, holder, field, entry);
46
- }
47
- else if (read.shape === "other" && page !== undefined && isKind(world, page)) {
48
- throw new Error(`"${entry}" is no stack: a stack is a link and a count from 1 up, such as write ${holder.name}, add ${field}="[[${page.name}]] 3". Nothing changed.`);
49
- }
50
- else if (read.shape === "stack") {
51
- checkCounted(world, holder, field, read, page);
52
- }
41
+ // Every entry that is wrong in one refusal, so that the master fixes them all at once.
42
+ const problems = added.flatMap((entry) => entryProblem(world, holder, field, entry) ?? []);
43
+ if (problems.length > 0) {
44
+ throw new Error(`${problems.join(" ")} Nothing changed.`);
53
45
  }
54
46
  const kindOf = kindOfEntry(world);
55
47
  for (const kind of new Set(added.flatMap(kindOf))) {
@@ -91,27 +83,61 @@ export function isKindNamed(world, name) {
91
83
  const page = entryPage(world, name);
92
84
  return page !== undefined && isKind(world, page);
93
85
  }
86
+ /** What is wrong with an entry a write adds to a container's list, with how to fix it; undefined when nothing is. */
87
+ function entryProblem(world, holder, field, entry) {
88
+ const read = readEntry(entry);
89
+ const page = read.shape === "text" ? undefined : entryPage(world, read.page);
90
+ if (read.shape === "text") {
91
+ return countedTextProblem(world, holder, field, entry);
92
+ }
93
+ if (read.shape === "other" && page !== undefined && isKind(world, page)) {
94
+ return `"${entry}" is no stack: a stack is a link and a count from 1 up, such as write ${holder.name}, add ${field}="[[${page.name}]] 3".`;
95
+ }
96
+ if (read.shape === "link") {
97
+ return missingLinkProblem(world, holder, field, read.page);
98
+ }
99
+ return read.shape === "stack" ? countedProblem(world, holder, field, read, page) : undefined;
100
+ }
101
+ /**
102
+ * A link alone to no page puts nothing in a container (STK-10, D-560): a name of a kind becomes its stack; in an inventory, a new thing gets its page first. Not judged
103
+ * while the campaign's system is missing or not chosen, whose pages it may name (D-167).
104
+ */
105
+ function missingLinkProblem(world, holder, field, name) {
106
+ const exists = pagesWithNameOrAlias(world, name).length > 0 || systemPageNamed(world, name) !== undefined;
107
+ if (exists || world.noSystem === true || world.missingSystem !== undefined || comparableText(name) === comparableText(holder.name)) {
108
+ return undefined;
109
+ }
110
+ if (goodsNamed(world, name) !== undefined) {
111
+ return missingKindMessage(world, holder, field, { page: name, count: 1 });
112
+ }
113
+ // A place, or a cart, may list a character or a place still to write.
114
+ if (canHold(holder.type, "character")) {
115
+ return undefined;
116
+ }
117
+ // No guess at a near name: a wrong kind would be worse than a page to write.
118
+ return `There is no page named ${name}, so [[${name}]] would put nothing in ${holder.name}: what a container lists is a page. If the system has it by another name, find shows it: `
119
+ + `link that name. For a new thing, write its page first, such as write "${name}", type item; then write ${holder.name}, add ${field}="[[${name}]]".`;
120
+ }
94
121
  /** A count beside a link counts only a kind (STK-1, STK-10): never a page with a story of its own, nor one that is not there, which the message tells how to find or make. */
95
- function checkCounted(world, holder, field, read, page) {
122
+ function countedProblem(world, holder, field, read, page) {
96
123
  if (page === undefined) {
97
- throw new Error(`${missingKindMessage(world, holder, field, read)} Nothing changed.`);
124
+ return missingKindMessage(world, holder, field, read);
98
125
  }
99
126
  const reason = notKindReason(world, page);
100
127
  const elsewhere = validHoldersOf(world, page).filter((other) => other.path !== holder.path);
101
128
  if (reason !== undefined) {
102
- throw new Error(`${page.name} is no kind to count: ${reason}. Nothing changed.`);
129
+ return `${page.name} is no kind to count: ${reason}.`;
103
130
  }
104
131
  if (!isKind(world, page) && elsewhere.length > 0) {
105
- throw new Error(`${page.name} is in ${elsewhere[0].name} as one thing with a story of its own: a count goes only beside a kind, as [[Name]] 7. Nothing changed.`);
132
+ return `${page.name} is in ${elsewhere[0].name} as one thing with a story of its own: a count goes only beside a kind, as [[Name]] 7.`;
106
133
  }
134
+ return undefined;
107
135
  }
108
136
  /** Text with a count at one end, as Torch 7, is a count inside a text (STK-10): refused when the rest names a kind, with its stack. */
109
- function checkCountedText(world, holder, field, entry) {
137
+ function countedTextProblem(world, holder, field, entry) {
110
138
  const counted = countedText(entry);
111
139
  const page = counted === undefined ? undefined : pageNamed(world, counted.name);
112
- if (counted !== undefined && page !== undefined && isKind(world, page)) {
113
- throw new Error(`"${entry}" is a count inside a text: write ${holder.name}, add ${field}="[[${page.name}]] ${counted.count}", a stack of ${page.name}. Nothing changed.`);
114
- }
140
+ return counted !== undefined && page !== undefined && isKind(world, page) ? `"${entry}" is a count inside a text: write ${holder.name}, add ${field}="[[${page.name}]] ${counted.count}", a stack of ${page.name}.` : undefined;
115
141
  }
116
142
  /** The system's goods whose names hold a word, the shortest first, as Arrows for Arrow: for a refusal to name them, which saves a find (STK-10). */
117
143
  function goodsLike(world, word) {
@@ -1,4 +1,4 @@
1
- import type { PageType } from "./page-types.ts";
1
+ import type { PageType } from "./types.ts";
2
2
  /** The fields a new page of this type starts with, unless they are given. */
3
3
  export declare function newPageFields(type: PageType): Record<string, unknown>;
4
4
  /** The fields that list what a page holds: a place's or an item's contents and a character's inventory. */
@@ -1,5 +1,5 @@
1
1
  import type { FieldKind } from "../core/field-kind.ts";
2
- import type { PageType } from "./page-types.ts";
2
+ import type { PageType } from "./types.ts";
3
3
  import type { Page, World } from "./world.ts";
4
4
  /**
5
5
  * Why a page of the game system never goes in a knows: anyone may know its rules, and a creature's numbers are the master's, which the player's view never
@@ -8,6 +8,8 @@ import type { Page, World } from "./world.ts";
8
8
  export declare function systemKnowsReason(page: Page): string;
9
9
  /** The kind the game system declares for a field, by its name in any case (SYS-8); undefined when it declares none. */
10
10
  export declare function declaredKind(world: World, field: string): FieldKind | undefined;
11
+ /** The kind that a system's declared fields give a field, by its name in any case (SYS-8); undefined when they give none. */
12
+ export declare function kindIn(fields: Record<string, FieldKind> | undefined, field: string): FieldKind | undefined;
11
13
  /** Whether the game system declares a field as something never counted: a number, text or a list, such as cr 1/4 or cost 15 gp (SYS-8). */
12
14
  export declare function isDeclaredUncounted(world: World, field: string): boolean;
13
15
  /** "a creature of the system 5e": what a page of the game system is, for messages. */
@@ -18,9 +20,9 @@ export declare function alwaysInList(world: World, page: Page): string | undefin
18
20
  export declare function alwaysInMessage(page: Page, list: string): string;
19
21
  /**
20
22
  * Why a page of the game system cannot be written, and what to write instead: a page of the campaign that derives from it (SYS-6, SYS-7); for one the system puts
21
- * in a list of every character, that it is there already (DAT-13).
23
+ * in a list of every character, that it is there already (DAT-13). `layer` names the campaign's layer too, for write alone (SYS-11): play spends nothing on it.
22
24
  */
23
- export declare function readOnlyMessage(page: Page, fields?: string[], world?: World): string;
25
+ export declare function readOnlyMessage(page: Page, fields?: string[], world?: World, layer?: boolean): string;
24
26
  /**
25
27
  * Why a page of the campaign cannot take the name of a page of the game system, which it would hide (SYS-4), with the name to give it instead; `fields` are those the refused
26
28
  * write gave, such as hp=15/15, for the call to make instead.
@@ -10,7 +10,10 @@ export function systemKnowsReason(page) {
10
10
  }
11
11
  /** The kind the game system declares for a field, by its name in any case (SYS-8); undefined when it declares none. */
12
12
  export function declaredKind(world, field) {
13
- const fields = world.system?.fields;
13
+ return kindIn(world.system?.fields, field);
14
+ }
15
+ /** The kind that a system's declared fields give a field, by its name in any case (SYS-8); undefined when they give none. */
16
+ export function kindIn(fields, field) {
14
17
  return fields === undefined ? undefined : kindsOf(fields).get(comparableText(field));
15
18
  }
16
19
  /** Whether the game system declares a field as something never counted: a number, text or a list, such as cr 1/4 or cost 15 gp (SYS-8). */
@@ -32,24 +35,30 @@ export function alwaysInMessage(page, list) {
32
35
  }
33
36
  /**
34
37
  * Why a page of the game system cannot be written, and what to write instead: a page of the campaign that derives from it (SYS-6, SYS-7); for one the system puts
35
- * in a list of every character, that it is there already (DAT-13).
38
+ * in a list of every character, that it is there already (DAT-13). `layer` names the campaign's layer too, for write alone (SYS-11): play spends nothing on it.
36
39
  */
37
- export function readOnlyMessage(page, fields = [], world) {
40
+ export function readOnlyMessage(page, fields = [], world, layer = false) {
38
41
  const list = world === undefined ? undefined : alwaysInList(world, page);
42
+ const layerWay = layer ? layerSentence(page, fields) : "";
39
43
  if (list !== undefined) {
40
- return `${alwaysInMessage(page, list)} Nothing changed.`;
44
+ return `${alwaysInMessage(page, list)}${layerWay} Nothing changed.`;
41
45
  }
42
46
  if (page.type === "creature") {
43
47
  const set = [`creature=[[${page.name}]]`, ...fields].join(", ");
44
48
  return `${page.name} is ${systemLabel(page)}: read-only. For a kind of your own, create a creature that derives from it, under a name in the campaign's language: `
45
- + `write "<name>", type creature, set ${set}; for one in particular, a character with creature=[[${page.name}]]. Nothing changed.`;
49
+ + `write "<name>", type creature, set ${set}; for one in particular, a character with creature=[[${page.name}]].${layerWay} Nothing changed.`;
46
50
  }
47
51
  if (page.type === "item") {
48
52
  const set = [`item=[[${page.name}]]`, ...fields].join(", ");
49
53
  return `${page.name} is ${systemLabel(page)}: read-only. For one that someone has, create an item that derives from it, under a name in the campaign's language: `
50
- + `write "<name>", type item, set ${set}, then move it to them. Nothing changed.`;
54
+ + `write "<name>", type item, set ${set}, then move it to them.${layerWay} Nothing changed.`;
51
55
  }
52
- return `${page.name} is ${systemLabel(page)}: read-only. Nothing changed.`;
56
+ return `${page.name} is ${systemLabel(page)}: read-only.${layerWay} Nothing changed.`;
57
+ }
58
+ /** " To change Goblin itself for the whole campaign, write it with layer…": the other way, a campaign's layer over the page (SYS-11). */
59
+ function layerSentence(page, fields) {
60
+ const set = fields.length === 0 ? "" : `, set ${fields.join(", ")}`;
61
+ return ` To change ${page.name} itself for the whole campaign, write it with layer: write "${page.name}", layer${set}.`;
53
62
  }
54
63
  /**
55
64
  * Why a page of the campaign cannot take the name of a page of the game system, which it would hide (SYS-4), with the name to give it instead; `fields` are those the refused
@@ -1,7 +1,8 @@
1
1
  import type { FieldKind } from "../core/field-kind.ts";
2
2
  import type { Formula, SystemFormulas } from "../core/formula.ts";
3
3
  import type { ProgressionRule } from "../core/progression-rule.ts";
4
- import { type PageType } from "./page-types.ts";
4
+ import { type LayerMark } from "./layers.ts";
5
+ import { type PageType } from "./types.ts";
5
6
  /** A page of the world: one thing with a name. It describes only itself; who has it or knows it is written on their own pages. */
6
7
  export interface Page {
7
8
  /** The file name without .md: unique in the campaign, and the target of links such as [[Name]]. */
@@ -20,6 +21,8 @@ export interface Page {
20
21
  title?: string;
21
22
  /** A system page's text in the campaign's language, for who reads it (D-542); `body` stays the system's, which the sheet's features are read from. */
22
23
  translated?: string;
24
+ /** For a system page the campaign changes with a layer, what the layer changed (SYS-11): the page stays the system's. */
25
+ layer?: LayerMark;
23
26
  }
24
27
  /** Every page of a campaign, read from its world folder, and the pages of its game system. */
25
28
  export interface World {
@@ -40,6 +43,8 @@ export interface World {
40
43
  noSystem?: boolean;
41
44
  /** The campaign's rigor, which formulas read as rigor (FOR-2, SPD-3). */
42
45
  rigor?: string;
46
+ /** The campaign's layers that lie over no page of its system, from the campaign folder, as after a change of the rules' version (SYS-11). */
47
+ strayLayers?: string[];
43
48
  }
44
49
  /** What a game system says of itself, as the world reads it (SYS-1, SYS-8). */
45
50
  export interface SystemInfo {
@@ -116,6 +121,8 @@ export declare function loadWorld(root: string, options?: {
116
121
  rigor?: string;
117
122
  /** The folder of the system's pages translated on this computer into the campaign's language (D-539), where the system has no translation of its own. */
118
123
  ownTranslations?: string;
124
+ /** The folder of the campaign's layers over the system's pages (SYS-11), as layers/5e; without it, or when it is not there, the system's pages as they are. */
125
+ layers?: string;
119
126
  }): World;
120
127
  /**
121
128
  * The page with this name, ignoring case and Unicode normalization: the campaign's, else the game system's (SYS-3). Two pages of the campaign with that name stop the command:
@@ -4,11 +4,12 @@ import { translationFolder } from "../core/files.js";
4
4
  import { frozen } from "../core/frozen.js";
5
5
  import { files } from "../core/store.js";
6
6
  import { comparableText, textPrint, valueNamed } from "../core/text.js";
7
+ import { readFields, splitPageFile } from "./file.js";
8
+ import { layeredPages } from "./layers.js";
7
9
  import { linkedPages, links } from "./markdown.js";
8
- import { readFields, splitPageFile } from "./page-file.js";
9
- import { pageTypes, typeOfFolder, worldFolderName } from "./page-types.js";
10
10
  import { readEntry } from "./stacks/entry.js";
11
11
  import { canHold, containerFieldOf } from "./standard-fields.js";
12
+ import { pageTypes, typeOfFolder, worldFolderName } from "./types.js";
12
13
  const forbiddenCharacters = /[\\/:*?"<>|#^[\]\u0000-\u001f]/;
13
14
  const longestName = 120;
14
15
  // Built once for each world, which is never changed in place: who lists each name in their contents or inventory, so that locating a page costs as much as its chain.
@@ -27,18 +28,22 @@ export function createWorld(root) {
27
28
  */
28
29
  export function loadWorld(root, options = {}) {
29
30
  const campaign = readPages(root);
30
- const { system, language, words, missingSystem, noSystem, rigor, ownTranslations } = options;
31
+ const { system, language, words, missingSystem, noSystem, rigor, ownTranslations, layers } = options;
31
32
  if (system === undefined) {
32
33
  return frozen({ root, ...campaign, language, missingSystem, noSystem, ...(rigor === undefined ? {} : { rigor }) });
33
34
  }
34
35
  const read = (folder, own) => translatedPages(packagePages(folder, system.name), folder, system.name, language, own);
35
36
  // A version's pages translated on this computer have a folder of their own, as their text is the version's (D-539).
36
- const systemPages = system.version === undefined
37
+ const shipped = system.version === undefined
37
38
  ? read(system.folder, ownTranslations)
38
39
  : versionPages(read(system.folder, ownTranslations), read(system.version.folder, ownTranslations === undefined ? undefined : join(ownTranslations, versionTranslations(system.version.name))));
40
+ // The campaign's layers last, over the version and the translations, and never kept in the maps of a process: they are the campaign's.
41
+ const layered = layers === undefined || files().files(join(layers, worldFolderName), (file) => /\.md$/i.test(file)).length === 0 ? undefined : withLayers(root, shipped, layers, system.fields);
42
+ const systemPages = layered ?? { ...shipped, stray: [] };
39
43
  const { name, title, fields, formulas, progression, itemFormulas, alwaysIn, uses, statusLine, load, lengthUnit, bonusLists, bonusWhile } = system;
40
44
  const problems = [...campaign.problems, ...systemPages.problems];
41
45
  return frozen({
46
+ ...(systemPages.stray.length === 0 ? {} : { strayLayers: systemPages.stray }),
42
47
  root,
43
48
  pages: campaign.pages,
44
49
  problems,
@@ -403,6 +408,13 @@ function versionPages(common, version) {
403
408
  const pages = [...common.pages.filter((page) => !names.has(comparableText(page.name))), ...version.pages].sort((first, second) => (first.path < second.path ? -1 : 1));
404
409
  return { pages, problems: [...common.problems, ...version.problems] };
405
410
  }
411
+ /** A system's pages with the campaign's layers in `folder` over them (SYS-11); a layer that does not read is a problem, and the page stays the system's. */
412
+ function withLayers(root, read, folder, declared) {
413
+ const prefix = relative(root, folder).split(sep).join("/");
414
+ const layers = readPages(folder);
415
+ const { pages, stray } = layeredPages(read.pages, layers.pages, prefix, declared);
416
+ return { pages, problems: [...read.problems, ...layers.problems.map((problem) => `A layer in ${prefix}: ${problem}`)], stray };
417
+ }
406
418
  /** The pages of a folder's world/, each marked with the game system it comes from, if any; a file that cannot be read is a problem, and the others still work. */
407
419
  function readPages(root, system) {
408
420
  const pages = [];
@@ -0,0 +1,18 @@
1
+ import type { Page, World } from "./world.ts";
2
+ import type { PageChange } from "./write-page.ts";
3
+ /** What a write did to a layer: its file, whether it changed or went, and the fields set, given back to the system's value, or removed. */
4
+ export interface LayerWrite {
5
+ path: string;
6
+ changed: boolean;
7
+ /** Whether the layer was left empty, and its file removed. */
8
+ removed: boolean;
9
+ set: string[];
10
+ /** Fields given the system's own value, which the layer holds no more (INH-9). */
11
+ again: string[];
12
+ unset: string[];
13
+ }
14
+ /**
15
+ * Writes the campaign's layer over a page of its game system (SYS-11): the change is read on the page as the campaign has it, and the layer keeps only what then differs
16
+ * from the system. unset, or an empty text, takes the layer's own value or section away, and the page reads the system's again. The system's files never change.
17
+ */
18
+ export declare function writeLayer(world: World, page: Page, change: PageChange): LayerWrite;
@@ -0,0 +1,108 @@
1
+ // Writing the campaign's layer over a page of its game system (SYS-11): only what differs from the system, and no layer left empty.
2
+ import { join } from "node:path";
3
+ import { files } from "../core/store.js";
4
+ import { comparableText, sameName, valueNamed } from "../core/text.js";
5
+ import { changedFields, changeFields, joinPageFile, readFields, splitPageFile } from "./file.js";
6
+ import { isNeverInherited } from "./inheritance.js";
7
+ import { layersFolderName, layerTakes, systemOriginal } from "./layers.js";
8
+ import { introductionText, partContent, writeText } from "./markdown.js";
9
+ import { systemLabel } from "./system-pages.js";
10
+ /**
11
+ * Writes the campaign's layer over a page of its game system (SYS-11): the change is read on the page as the campaign has it, and the layer keeps only what then differs
12
+ * from the system. unset, or an empty text, takes the layer's own value or section away, and the page reads the system's again. The system's files never change.
13
+ */
14
+ export function writeLayer(world, page, change) {
15
+ if (page.system === undefined) {
16
+ throw new Error(`${page.name} is a page of the campaign: write it without layer. A layer changes a page of the game system for the whole campaign. Nothing changed.`);
17
+ }
18
+ const original = systemOriginal(page);
19
+ const path = page.layer?.path ?? `${layersFolderName}/${page.system}/${original.path}`;
20
+ const fullPath = join(world.root, path);
21
+ const before = files().fresh(fullPath);
22
+ const file = splitPageFile(before ?? "");
23
+ const held = readFields(file.frontmatter, path);
24
+ const fields = layerFields(world, page, original, held, change);
25
+ const frontmatter = fields.set.length + fields.unsetKeys.length === 0 ? file.frontmatter : changeFields(file.frontmatter, { set: fields.values, unset: fields.unsetKeys }, path);
26
+ const body = change.text === undefined ? file.body : layerText(page, original, file.body, change);
27
+ const empty = (frontmatter ?? "").trim() === "" && body.trim() === "";
28
+ const text = joinPageFile({ frontmatter, body });
29
+ const changed = empty ? before !== undefined : text !== (before === undefined ? undefined : joinPageFile(file));
30
+ if (empty && before !== undefined) {
31
+ files().remove(fullPath);
32
+ }
33
+ else if (changed) {
34
+ files().write(fullPath, text);
35
+ }
36
+ return { path, changed, removed: empty && before !== undefined, set: fields.set, again: fields.again, unset: fields.unset };
37
+ }
38
+ /** The fields a change gives the layer: those that differ from the system's go in, those equal to it come out, unset takes the layer's own away. */
39
+ function layerFields(world, page, original, held, change) {
40
+ const lists = Object.fromEntries([...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})].map((field) => {
41
+ const current = valueNamed(page.fields, field);
42
+ const list = changedFields({ [field]: current ?? [] }, { add: pick(change.add, field), remove: pick(change.remove, field) })[field];
43
+ return [field, list];
44
+ }));
45
+ const given = { ...change.set, ...lists };
46
+ const values = {};
47
+ const unsetKeys = [];
48
+ const [set, again, unset] = [[], [], []];
49
+ for (const [field, value] of Object.entries(given)) {
50
+ checkLayerField(world, page, original, field, value);
51
+ const system = sameName(Object.keys(original.fields), field);
52
+ const own = sameName(Object.keys(held), field);
53
+ const key = own ?? system ?? field;
54
+ if (system !== undefined && JSON.stringify(original.fields[system]) === JSON.stringify(value)) {
55
+ again.push(field);
56
+ if (own !== undefined) {
57
+ unsetKeys.push(own);
58
+ }
59
+ continue;
60
+ }
61
+ set.push(field);
62
+ values[key] = value;
63
+ }
64
+ for (const field of change.unset ?? []) {
65
+ const own = sameName(Object.keys(held), field);
66
+ if (own === undefined) {
67
+ const system = valueNamed(original.fields, field) === undefined ? "" : `: it is the system's own, which a layer cannot remove; set another value instead`;
68
+ throw new Error(`The campaign's layer over ${page.name} holds no ${field} to remove${system}. Nothing changed.`);
69
+ }
70
+ unset.push(field);
71
+ unsetKeys.push(own);
72
+ }
73
+ return { values, unsetKeys, set, again, unset };
74
+ }
75
+ /** Refuses what a layer never changes (SYS-11): the name, the type, a field never inherited (INH-8), and a counter of uses on an item that is a kind (STK-1). */
76
+ function checkLayerField(world, page, original, field, value) {
77
+ if (layerTakes(original, field, value, world.system?.fields)) {
78
+ return;
79
+ }
80
+ const why = ["name", "type"].includes(comparableText(field))
81
+ ? `a layer changes neither the name nor the type of ${page.name}`
82
+ : isNeverInherited(field)
83
+ ? `${field} is a field no page inherits (INH-8), and ${page.name} is ${systemLabel(page)}, which is nowhere and derives only from the system`
84
+ : `uses of its own would make ${page.name}, a kind counted in stacks, no kind: one with uses is an item of the campaign that derives from it, with item=[[${page.name}]]`;
85
+ throw new Error(`${field} cannot go in the campaign's layer over ${page.name}: ${why}. Nothing changed.`);
86
+ }
87
+ /** The layer's text after a change: a section or the introduction equal to the system's comes out, an empty one takes the layer's own away. */
88
+ function layerText(page, original, body, change) {
89
+ const section = change.section;
90
+ const own = section === undefined ? introductionText(body) : partContent(body, section)?.content;
91
+ const system = section === undefined ? introductionText(original.body) : partContent(original.body, section);
92
+ const shown = section === undefined ? introductionText(page.body) : partContent(page.body, section)?.content;
93
+ const content = change.append === true ? [shown ?? "", change.text.trim()].filter((part) => part !== "").join("\n\n") : change.text.trim();
94
+ const where = section === undefined ? "the introduction" : `"${section}"`;
95
+ const systemText = typeof system === "string" ? system : system?.content;
96
+ if (content === "" || content === systemText) {
97
+ if (own === undefined || own === "") {
98
+ const remedy = content === "" && systemText !== undefined && systemText !== "" ? `: the system's text cannot be removed, only written over with another` : "";
99
+ throw new Error(content === "" ? `The campaign's layer over ${page.name} has no ${where} of its own to remove${remedy}. Nothing changed.` : `${where} of ${page.name} already reads like that. Nothing changed.`);
100
+ }
101
+ return section === undefined ? writeText(body, "", { mode: "replace" }) : writeText(body, "", { section, mode: "remove" });
102
+ }
103
+ const secret = change.secret === true || (typeof system === "object" && system.secret);
104
+ return writeText(body, content, { mode: "replace", ...(section === undefined ? {} : { section, secret: own === undefined && secret }) });
105
+ }
106
+ function pick(lists, field) {
107
+ return lists?.[field] === undefined ? undefined : { [field]: lists[field] };
108
+ }