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,37 +1,35 @@
1
+ // The write command
1
2
  import { z } from "zod";
2
3
  import { requireCampaign } from "../../campaign/index.js";
3
- import { fieldsRead, listItemNames, numberOf } from "../../core/formula.js";
4
4
  import { appendLogEntry } from "../../core/log.js";
5
5
  import { defineCommand } from "../../core/registry.js";
6
- import { comparableText, sameName, valueNamed, withArticle } from "../../core/text.js";
6
+ import { comparableText, valueNamed, withArticle } from "../../core/text.js";
7
7
  import { formatCounter, readCounter } from "../../counters/index.js";
8
- import { readEffects } from "../../effects/index.js";
9
- import { formatAmount, namesCoins, readAmount } from "../../money/index.js";
10
- import { alwaysInList, baseFieldOf, baseValue, changedEnvironment, changedFields, checkFieldChange, concernsPlayer, containerFieldOf, countedText as countInText, declaredKind, derivedPages, environmentAt, equippedNotes, findPage, followersOf, formatEnvironmentEntry, goodsFieldProblems, hidingMessage, holdsField, inheritedFields, introductionFollowersOf, introductionText, isCounterField, isDeclaredUncounted, isEmptyField, isNeverInherited, isPartyMember, isPlayerCharacter, isStandardField, keepersOf, linkListItems, linksIn, listFieldNames, misspelledFieldProblem, misspelledStandardField, namesakes, newBaseProblem, newPageFields, ownFieldChange, pageNamed, pagesWithName, pageTypeNames, parsePageReference, readEntry, readEnvironment, readFieldValue, readOnlyMessage, removedFieldName, sameAsBase, sectionFollowersOf, systemKnowsReason, systemLabel, systemPageNamed, textParts, textsIn, withPage, writePage, writtenFieldName, } from "../../pages/index.js";
11
- import { featureParts, mergedFeatures } from "../../progression/index.js";
12
- import { bondNotes, checkBonds } from "../shared/bonds.js";
13
- import { effectiveFields, effectsField } from "../shared/effect-layer.js";
14
- import { conditionNotes, consequencesNotes, eventFieldsProblem, fireEvents, heldNote, nowDueNote, plannedEventDateProblem } from "../shared/events.js";
15
- import { experienceOf, leastNotes, levelWay, newLevelNotes, settleChoices } from "../shared/experience.js";
16
- import { gridNotes } from "../shared/grids.js";
17
- import { questPictureNote } from "../shared/images.js";
8
+ import { alwaysInList, baseFieldOf, baseValue, changedFields, checkFieldChange, concernsPlayer, equippedNotes, findPage, goodsFieldProblems, hidingMessage, isNeverInherited, isPartyMember, isPlayerCharacter, isStandardField, misspelledStandardField, ownFieldChange, pageNamed, pageTypeNames, parsePageReference, readOnlyMessage, sameAsBase, withPage, writePage, } from "../../pages/index.js";
9
+ import { questPictureNote } from "../shared/campaign/images.js";
10
+ import { campaignCoins } from "../shared/campaign/money.js";
11
+ import { adventurePart, nextAdventureLead, partyPart, situationPart } from "../shared/campaign/parts.js";
12
+ import { adventureUnderWay, logQuestChange, newQuestNotes, tickedQuestNotes } from "../shared/campaign/quests.js";
13
+ import { deathNotes, isPlayerDead, partyDeathNotes } from "../shared/campaign/saves.js";
14
+ import { campaignSystem, campaignWorld, leftOutNote, missingSystemHint, systemProblems, systemSearchHint } from "../shared/campaign/world.js";
15
+ import { diaryDueLine } from "../shared/characters/thoughts.js";
18
16
  import { fieldValues } from "../shared/inputs.js";
19
- import { checkLimits } from "../shared/limits.js";
20
- import { campaignCoins } from "../shared/money.js";
21
- import { followersNote, keepersNote, skippedPagesNote } from "../shared/notes.js";
22
- import { adventurePart, partText, partyPart, situationPart } from "../shared/parts.js";
23
- import { mapLookNotes, shortRoadNotes } from "../shared/positions.js";
24
- import { givenItems, progressionOf } from "../shared/progression.js";
25
- import { adventureUnderWay, logQuestChange, newQuestNotes, tickedQuestNotes } from "../shared/quests.js";
26
- import { deathNotes, isPlayerDead, partyDeathNotes } from "../shared/saves.js";
27
- import { checkNotCopied, copyChanges, copyLink, copyName, copyPage, readOpenScene, updateScene } from "../shared/scene.js";
28
- import { checkListValues, joiningNotes, weightlessNote } from "../shared/sheet.js";
29
- import { diaryDueLine } from "../shared/thoughts.js";
30
- import { thresholdNotes } from "../shared/thresholds.js";
31
- import { newDatedLogEntry, readPresent } from "../shared/time.js";
32
- import { computedField, counterLimits, directBonuses, hasSheet, isUse, itemLines, maximumHint, maximumSources, missingUses, signedText, startingAtZero, workedMaximum, workedParts } from "../shared/worked-out.js";
33
- import { campaignSystem, campaignWorld, foreignSystemLanguage, leftOutNote, missingSystemHint, systemBaseHint, systemProblems, systemSearchHint } from "../shared/world.js";
17
+ import { followersNote, skippedPagesNote } from "../shared/notes.js";
18
+ import { gridNotes } from "../shared/places/grids.js";
19
+ import { mapLookNotes, shortRoadNotes } from "../shared/places/positions.js";
20
+ import { copyChanges, copyLink, copyName, copyPage, readOpenScene, updateScene } from "../shared/scene/scene.js";
21
+ import { bondNotes } from "../shared/sheet/bonds.js";
22
+ import { effectiveFields } from "../shared/sheet/effect-layer.js";
23
+ import { experienceOf, leastNotes, levelWay, newLevelNotes, settleChoices } from "../shared/sheet/experience.js";
24
+ import { joiningNotes } from "../shared/sheet/sheet.js";
25
+ import { newDatedLogEntry } from "../shared/time/time.js";
26
+ import { changedFieldNames, checkClearedCounters, checkCounters, checkFieldWrite, checkLists, checkNoEffects, checkValues } from "./checks.js";
34
27
  import { hereFields, hereOf, placeHere, positionToWrite, writeOrigin } from "./here.js";
28
+ import { baseNotesOrWeight, changedNames, droppedFromBaseNotes, followersOfWrite, keepersNotes, logCounterChanges, ownValuesNote, writtenNames } from "./inheritance.js";
29
+ import { asAmounts, listsWithoutComputed, moneyNotesOf, oneItemLists, readFields, readListItems, withoutComputed } from "./input.js";
30
+ import { writeCampaignLayer } from "./layer.js";
31
+ import { countedTextNotes, linkNotes, questEndNotes, questEnds, storyNotes, writtenThresholdNotes } from "./notes.js";
32
+ import { featureSectionNotes, firstItemNotes, givenListNotes, progressionNotes, workedLimitsChange } from "./progression.js";
35
33
  // How the output names each way of writing text.
36
34
  const textChanges = { replace: "wrote", append: "added to", remove: "removed" };
37
35
  export const write = defineCommand({
@@ -58,6 +56,7 @@ export const write = defineCommand({
58
56
  append: z.boolean().optional().describe("add the text at the end instead of replacing"),
59
57
  secret: z.boolean().optional().describe("with a section: create it, if missing, as a secret block > [!secret] Name"),
60
58
  here: z.boolean().optional().describe("a new place where the journey stopped: on a road it becomes a stop there, in the open it takes the point; those who travel go into it"),
59
+ layer: z.boolean().optional().describe("change a page of the game system for the whole campaign, in a layer that holds only what differs; unset or empty text gives back the system's"),
61
60
  why: z.string().optional().describe("what the change is for, kept in the master's log"),
62
61
  }),
63
62
  run(input, context) {
@@ -93,6 +92,10 @@ export const write = defineCommand({
93
92
  throw new Error(`${computedNotes.join(" ")} Nothing changed.`);
94
93
  }
95
94
  const moneyNotes = [...computedNotes, ...moneyNotesOf(world, reference.name, fields.set, coins, coinsProblem)];
95
+ if (input.layer === true) {
96
+ const layered = writeCampaignLayer(root, context, world, open, { name: reference.name, type: input.type, text: input.text, section, append: input.append, secret: input.secret, why, copy }, fields, coins);
97
+ return { ...layered, created: false, add: [], remove: [], notes: [...layered.notes, ...moneyNotes], problems: world.problems };
98
+ }
96
99
  if (open.scene !== undefined && copy !== undefined) {
97
100
  checkNoEffects(fields, copyPage(copy, open.scene.copies[copy]));
98
101
  const written = writeCopy(root, world, context, open.scene, copy, { type: input.type, text: input.text, section, why }, fields, coins);
@@ -102,7 +105,7 @@ export const write = defineCommand({
102
105
  // The campaign only reads the pages of its game system, and never hides one with a page of its own (SYS-4, SYS-6).
103
106
  if (existing?.system !== undefined) {
104
107
  const given = givenFields(fields.set, baseFieldOf(input.type ?? existing.type));
105
- throw new Error(input.type === undefined || alwaysInList(world, existing) !== undefined ? readOnlyMessage(existing, given, world) : hidingMessage(existing, input.type, given));
108
+ throw new Error(input.type === undefined || alwaysInList(world, existing) !== undefined ? readOnlyMessage(existing, given, world, true) : hidingMessage(existing, input.type, given));
106
109
  }
107
110
  checkNoEffects(fields, existing);
108
111
  if (existing === undefined && input.type === undefined) {
@@ -110,7 +113,7 @@ export const write = defineCommand({
110
113
  const unreadable = open.problem === undefined ? "" : " The open scene in state.yaml cannot be read, so a copy in it cannot be written: validate shows how to fix it.";
111
114
  const aliased = pageNamed(world, reference.name);
112
115
  // An alias of a page of the system leads to a page that is read-only (SYS-6).
113
- const readOnly = aliased?.system === undefined ? "" : ` ${readOnlyMessage(aliased).replace(/ Nothing changed\.$/, "")}`;
116
+ const readOnly = aliased?.system === undefined ? "" : ` ${readOnlyMessage(aliased, [], undefined, true).replace(/ Nothing changed\.$/, "")}`;
114
117
  const alias = aliased === undefined ? "" : readOnly !== "" ? ` ${reference.name} is an alias of ${aliased.name}.${readOnly}` : ` ${reference.name} is an alias of ${aliased.name}: to change that page, write ${aliased.name}.`;
115
118
  throw new Error(`There is no page named ${reference.name}${copies}.${alias} To create it, give its type: ${pageTypeNames.join(", ")}.${unreadable}${missingSystemHint(world) || systemSearchHint(world)}`);
116
119
  }
@@ -171,7 +174,7 @@ export const write = defineCommand({
171
174
  // A quest that ends is a time to write a diary (DIA-2).
172
175
  const diary = changed && questEnds(existing, page) ? diaryDueLine(root, context, now) : "";
173
176
  // The last quest ended: the next adventure is to build (D-530 (8)).
174
- const next = changed && questEnds(existing, page) && !adventureUnderWay(now) ? adventurePart("No quest is open or planned now: build the next adventure.", context, system) : "";
177
+ const next = changed && questEnds(existing, page) && !adventureUnderWay(now) ? adventurePart(nextAdventureLead(root), context, system) : "";
175
178
  const quest = changed
176
179
  ? [...questEndNotes(context, system, existing, page), ...(diary === "" ? [] : [diary]), ...(next === "" ? [] : [next]), ...tickedQuestNotes(existing, page), ...opened, ...(picture === undefined ? [] : [picture])]
177
180
  : [];
@@ -299,45 +302,6 @@ export function writePackageFields(root, context, world, page, values, why) {
299
302
  writeOrigin(root, context, withPage(world, page, after), positioned.placed.origin);
300
303
  }
301
304
  }
302
- /**
303
- * The checks of write on what it is about to write on a page, new or not, and on its fields (D-435, D-514): their names and values, the lists the sheet
304
- * closes, a creature's copies in the open scene, counters, uses, the base, bonds, limits and an event's fields. It throws what is wrong, with how to fix it.
305
- */
306
- function checkFieldWrite(world, system, open, coins, target, fields) {
307
- const { existing, name, type } = target;
308
- conditionsAsList(existing, fields);
309
- checkFieldNames(type, fields);
310
- checkFieldChange(type, fields);
311
- environmentAsSet(world, existing, type, name, fields);
312
- checkValues(fields);
313
- // A page that keeps the sheet, as it will be written, takes only the names the sheet closes (D-435).
314
- const asWritten = { name, path: existing?.path ?? "", body: existing?.body ?? "", ...(type === undefined ? {} : { type }), fields: { ...existing?.fields, ...fields.set } };
315
- const onSheet = hasSheet(world, asWritten);
316
- checkListValues(system, fields.set ?? {}, onSheet);
317
- checkListValues(system, fields.add ?? {}, onSheet);
318
- checkKnows(world, fields);
319
- if (existing !== undefined) {
320
- if (changedFieldNames(fields).some(passesOn)) {
321
- checkNotCopied(world, open, existing);
322
- }
323
- checkCounters(world, existing, fields.set, coins);
324
- checkUses(world, system, existing, fields.set);
325
- checkClearedCounters(world, existing, ownFieldChange(world, existing, fields), coins);
326
- checkLists(world, existing, fields);
327
- }
328
- checkBase(world, existing?.name ?? name, type, fields.set);
329
- checkBonds(world, system, existing, existing?.name ?? name, fields);
330
- checkLimits(world, system, existing, existing?.name ?? name, fields);
331
- checkEventFields(world, existing, type, fields);
332
- }
333
- /** "torce 7" written in an inventory: a count inside a text, which nothing counts, and how goods are counted instead (STK-10). */
334
- function countedTextNotes(existing, page) {
335
- const field = containerFieldOf(page.type);
336
- const before = field === undefined ? [] : textsIn(existing?.fields[field]).map((entry) => entry.trim());
337
- const added = field === undefined ? [] : textsIn(page.fields[field]).filter((entry) => !before.includes(entry.trim()));
338
- return added.filter((entry) => readEntry(entry).shape === "text" && countInText(entry) !== undefined).map((entry) => `"${entry}" is a count inside a text, which nothing counts: goods are a stack, a kind and how many. The system's kinds go by their English names, as find shows them: `
339
- + `write the one it has with your word as its label, such as [[Torch|torcia]] 3; only what the system lacks becomes a kind of the campaign, made first with write "<name>", type item.`);
340
- }
341
305
  /** A type as the parameter names it, with what tells a place from an item (D-155, D-156). */
342
306
  function typeText(type) {
343
307
  return type === "place"
@@ -399,761 +363,13 @@ function checkCopyField(name, creature, field) {
399
363
  function promotion(name, creature, what) {
400
364
  return `To give it ${what} of its own, make it a character: show it to read its values, let it leave with scene leave, write ${name} as a character with creature=${creature} and those values, then bring it back with scene add.`;
401
365
  }
402
- /** Effects change only with the effect command, which works out when they end and says what they change (EFF-6). */
403
- function checkNoEffects(change, page) {
404
- // Effects that do not read can only be removed by hand, or with unset: effect will not write over them (EFF-12).
405
- const unreadable = page !== undefined && "problem" in readEffects(effectsField(page));
406
- const onlyUnset = Object.keys(change.set ?? {}).every((name) => comparableText(name) !== "effects") && [change.add, change.remove].every((items) => Object.keys(items ?? {}).every((name) => comparableText(name) !== "effects"));
407
- if (unreadable && onlyUnset) {
408
- return;
409
- }
410
- if (changedFieldNames(change).some((name) => comparableText(name) === "effects")) {
411
- throw new Error('effects change only with the effect command: action add with a name, for how long and the values it gives, such as name "Protezione", for 10m, set bonus-armor=2; action end to take one away. Nothing changed.');
412
- }
413
- }
414
- /** A standard field written in another case, such as Status, would be a field the engine does not read: refused before any other check. */
415
- function checkFieldNames(type, change) {
416
- const names = [...Object.keys(change.set ?? {}), ...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})];
417
- const problem = names.map((name) => misspelledFieldProblem(type, name)).find((found) => found !== undefined);
418
- if (problem !== undefined) {
419
- throw new Error(problem);
420
- }
421
- }
422
- /** A counter written as current/max changes only with change, which keeps its limits and logs why (D-92, INH-11). A value that is not a counter makes it something else: on a page that holds it alone, only after unset. */
423
- function checkCounters(world, page, set, coins) {
424
- const fields = inheritedFields(world, page);
425
- for (const [field, value] of Object.entries(set ?? {}).filter(([, candidate]) => !isEmptyField(candidate))) {
426
- const name = sameName(Object.keys(fields), field);
427
- const declared = name !== undefined && startingAtZero(world, name) !== undefined;
428
- const current = name === undefined || (isStandardField(page.type, name) && !isCounterField(page.type, name)) || isDeclaredUncounted(world, name) ? undefined : guarded(fields[name], coins, declared);
429
- const next = current === undefined ? undefined : sameKind(current.kind, value, coins);
430
- const base = baseValue(world, page, field);
431
- if (name === undefined || current === undefined || next === current.text || (next === undefined && base !== undefined)) {
432
- continue;
433
- }
434
- const hint = current.kind === "counter" ? maximumHint(world, effectiveFields(world, page), name) : undefined;
435
- throw new Error(hint === undefined ? guardedMessage(page, name, current.kind, next, holdsField(page, name) ? undefined : base?.base, base !== undefined) : workedCounterMessage(page, name, hint));
436
- }
437
- }
438
- /**
439
- * A use of the system that the character does not get, as a warlock's spell-slots on a wizard or slots on a warlock, is never written by hand (DAT-9): only on who
440
- * keeps the sheet and has the system's lists, and never for one the sheet asks to write, as hp.
441
- */
442
- function checkUses(world, system, page, set) {
443
- const list = world.system?.progression?.list;
444
- const after = { ...page, fields: { ...page.fields, ...set } };
445
- const fields = inheritedFields(world, after);
446
- const classes = list === undefined ? undefined : valueNamed(fields, list);
447
- if (list === undefined || isEmptyField(classes) || !hasSheet(world, after)) {
448
- return;
449
- }
450
- const asked = askedFields(system);
451
- for (const field of Object.keys(set ?? {}).filter((name) => isUse(world, name) && !asked.has(comparableText(name)))) {
452
- const counted = Object.keys(world.system?.formulas?.counters ?? {}).some((name) => comparableText(name) === comparableText(field));
453
- const { max } = counterLimits(world, fields, field);
454
- if (counted && (max === undefined || max <= 0)) {
455
- const sources = maximumSources(world, field, fields);
456
- const whence = sources.length === 0 ? `the tables of its ${list}` : sources.join(", ");
457
- throw new Error(`${field} is a use the system ${world.system?.name ?? ""} gives from ${whence}, and ${page.name} has none of it: it is not written by hand. Nothing changed.`);
458
- }
459
- }
460
- }
461
- /**
462
- * A value that changes only with change, as it is compared: a current/max counter (D-92), a number the game system declares a counter with no maximum (CNT-7, D-266), or money
463
- * (MON-6); undefined for any other.
464
- */
465
- function guarded(value, coins, declared) {
466
- const counter = readCounter(value);
467
- if (counter !== undefined && (counter.max !== undefined || declared)) {
468
- return { kind: "counter", text: String(formatCounter(counter)) };
469
- }
470
- const purse = coins === undefined ? undefined : readAmount(value, coins);
471
- return purse === undefined || coins === undefined ? undefined : { kind: "money", text: formatAmount(purse, coins) };
472
- }
473
- /** A new value read as the kind it would replace: any counter for a counter, coins for money; undefined when it is something else. */
474
- function sameKind(kind, value, coins) {
475
- const counter = kind === "counter" ? readCounter(value) : undefined;
476
- const purse = kind === "money" && coins !== undefined ? readAmount(value, coins) : undefined;
477
- return counter !== undefined ? String(formatCounter(counter)) : purse !== undefined && coins !== undefined ? formatAmount(purse, coins) : undefined;
478
- }
479
- /** "hp is a counter whose maximum the game system works out": what to change instead, the current value with change and the maximum through what it comes from (D-226). */
480
- function workedCounterMessage(page, field, hint) {
481
- const raise = hint.raise === undefined ? "" : `; to raise the maximum, write ${hint.raise}`;
482
- return `${field} is a counter whose maximum the game system works out: ${hint.made}. Change its current value with change, page "${page.name}", field ${field}${raise}. Nothing changed.`;
483
- }
484
- function guardedMessage(page, field, kind, next, readFrom, hasBase) {
485
- const what = kind === "counter" ? "a counter" : "money";
486
- const other = hasBase ? `To make it something else, set a value that is not ${what}.` : "To make it something else, unset it, then set it.";
487
- if (kind === "money") {
488
- const from = readFrom === undefined ? "" : `, which it reads from ${readFrom.name},`;
489
- const purse = next === undefined ? "sets the purse" : `"${next}" sets the purse`;
490
- return `${page.name}'s ${field}${from} changes only with change, page "${page.name}", field ${field}: spend pays, by adds coins, to ${purse}${readFrom === undefined ? "" : `, on ${page.name} only`}. ${other}`;
491
- }
492
- const use = `use change, page "${page.name}", field ${field}, to ${next ?? "a value"} (or by an amount)`;
493
- return readFrom === undefined ? `${field} is ${what}: ${use}. ${other}` : `${field} is ${what} that ${page.name} reads from ${readFrom.name}: ${use}, which writes it on ${page.name} only. ${other}`;
494
- }
495
- /**
496
- * Removing a counter that a base also holds as current/max would bring back the base's value with no line in the log: change does it, and logs it (INH-11).
497
- * `change` names the fields as the page writes them. The same field written twice in another case may lose one of the two: validate asks for it.
498
- */
499
- function checkClearedCounters(world, page, change, coins) {
500
- for (const own of (change.unset ?? []).filter((field) => Object.hasOwn(page.fields, field))) {
501
- const current = isStandardField(page.type, own) || isDeclaredUncounted(world, own) ? undefined : guarded(page.fields[own], coins, false);
502
- const base = baseValue(world, page, own);
503
- const fromBase = base === undefined ? undefined : guarded(base.value, coins, false);
504
- const alsoHeld = Object.keys(page.fields).some((other) => other !== own && comparableText(other) === comparableText(own) && !isEmptyField(page.fields[other]));
505
- if (!alsoHeld && base !== undefined && current !== undefined && fromBase?.kind === current.kind) {
506
- const value = current.kind === "counter" ? fromBase.text : `"${fromBase.text}"`;
507
- const start = current.kind === "counter" ? `${own} on ${page.name} is a counter: without it,` : `Without ${own},`;
508
- throw new Error(`${start} ${page.name} would read ${fromBase.text} from ${base.base.name}, with no line in the log. Use change, page "${page.name}", field ${own}, to ${value}: it takes the field off, and ${page.name} follows ${base.base.name} again.`);
509
- }
510
- }
511
- }
512
- /** knows lists pages and secrets of the campaign: a page of the game system, which anyone may know, never (SYS-2). */
513
- function checkKnows(world, change) {
514
- const known = [...linksIn(change.set?.knows), ...linksIn(change.add?.knows)].map((name) => systemPageNamed(world, name)).find((page) => page !== undefined && findPage(world, page.name) === page);
515
- if (known !== undefined) {
516
- throw new Error(`${known.name} is ${systemLabel(known)}, ${systemKnowsReason(known)}: knows lists pages and secrets of the campaign. Nothing changed.`);
517
- }
518
- }
519
- /** A character or creature derives only from a creature, an item only from an item, never in a loop (INH-2, INH-3). */
520
- function checkBase(world, name, type, set) {
521
- const field = baseFieldOf(type);
522
- const link = field === undefined ? undefined : set?.[field];
523
- const problem = typeof link === "string" ? newBaseProblem(world, { name, type }, link) : undefined;
524
- if (problem !== undefined) {
525
- throw new Error(`${problem} Nothing changed.`);
526
- }
527
- }
528
- /**
529
- * A planned event comes due at its date, so a write that sets its date or status cannot leave a date the engine does not read (D-100);
530
- * nor a clock or conditions that do not read (EVT-10).
531
- */
532
- function checkEventFields(world, page, type, change) {
533
- const changed = changedFieldNames(change);
534
- if (type !== "event" || !["date", "status", "clock", "when"].some((field) => changed.includes(field))) {
535
- return;
536
- }
537
- const fields = changedFields(page?.fields ?? newPageFields(type), change);
538
- const date = changed.includes("date") || changed.includes("status") ? plannedEventDateProblem(type, fields) : undefined;
539
- const problem = date ?? eventFieldsProblem(world, fields, changed);
540
- if (problem !== undefined) {
541
- throw new Error(problem);
542
- }
543
- }
544
- /**
545
- * What the write set off in the story: the events it made due or that wait for the date it gave them (EVT-4, EVT-5), conditions on pages that do not exist yet,
546
- * and the planned events and quests linked to what changed (D-117, EVT-7).
547
- */
548
- function storyNotes(root, context, before, after, existing, page) {
549
- const present = readPresent(root).date;
550
- const fired = fireEvents(root, context, before, after, present);
551
- const written = fired.world.pages.find((candidate) => candidate.path === page.path) ?? page;
552
- const conditions = page.type === "event" && JSON.stringify(existing?.fields.when) !== JSON.stringify(page.fields.when) ? conditionNotes(fired.world, page.fields.when) : [];
553
- const consequences = consequencesNotes(fired.world, existing, written, fired.due.map((event) => event.name), present);
554
- return [nowDueNote(fired.due), heldNote(fired.held), ...conditions, ...consequences].filter((note) => note !== "");
555
- }
556
- /**
557
- * A place's environment changes entry by entry (ENV-4): add puts a line in, or in place of the one with its name; remove takes one out by name; set gives them all,
558
- * each read as a line. The lines it ends with are set whole, or the field goes when none is left.
559
- */
560
- function environmentAsSet(world, page, type, name, change) {
561
- const add = change.add?.environment;
562
- const remove = change.remove?.environment;
563
- // On a character or an item environment would hold for nothing (ENV-6); taking it away is always allowed.
564
- if ((type === "character" || type === "item") && (change.set?.environment !== undefined || add !== undefined)) {
565
- throw new Error(`${name} is ${withArticle(type)}: an environment holds only on a place, for all it contains. What a thing does around itself, such as a lantern's light, is a field or an effect of its own.`);
566
- }
567
- if (type !== "place") {
568
- return;
569
- }
570
- if (change.set?.environment !== undefined) {
571
- const read = readEnvironment(change.set.environment);
572
- if ("problem" in read) {
573
- throw new Error(read.problem);
574
- }
575
- // Written back as lines, which Obsidian edits, whatever way they were given.
576
- change.set.environment = read.entries.map(formatEnvironmentEntry);
577
- }
578
- if (add === undefined && remove === undefined) {
579
- return;
580
- }
581
- checkOwnEntries(world, page, name, remove ?? []);
582
- const lines = changedEnvironment(page?.fields.environment, add ?? [], remove ?? [], page?.name ?? name);
583
- delete change.add?.environment;
584
- delete change.remove?.environment;
585
- if (lines.length > 0) {
586
- change.set = { ...change.set, environment: lines };
587
- }
588
- else if (page !== undefined && Object.hasOwn(page.fields, "environment")) {
589
- change.unset = [...(change.unset ?? []), "environment"];
590
- }
591
- }
592
- /** An entry to remove that the place does not write but reads from a place around it: removing it there would change it for all that place holds. */
593
- function checkOwnEntries(world, page, name, remove) {
594
- const own = page === undefined ? [] : readEnvironmentNames(page.fields.environment);
595
- for (const entry of remove.map((item) => String(item).split(":")[0].trim())) {
596
- const outer = page === undefined || own.some((other) => comparableText(other) === comparableText(entry)) ? undefined : environmentAt(world, page).find((found) => comparableText(found.entry.name) === comparableText(entry));
597
- if (outer !== undefined) {
598
- throw new Error(`${entry} holds in ${name} from ${outer.place.name}: to change it in ${name} only, add environment="${outer.entry.name}: …" on ${name}; to remove it everywhere ${outer.place.name} holds, write ${outer.place.name}, remove environment=${outer.entry.name}.`);
599
- }
600
- }
601
- }
602
- /** The names a place's environment writes, as far as its lines read. */
603
- function readEnvironmentNames(value) {
604
- const read = readEnvironment(value);
605
- return "entries" in read ? read.entries.map((entry) => entry.name) : [];
606
- }
607
- /** Adding a condition to an event that has one makes a list of the two, of which one is enough (EVT-3). */
608
- function conditionsAsList(page, change) {
609
- const current = page?.type === "event" ? page.fields.when : undefined;
610
- if (change.add?.when !== undefined && typeof current === "string" && current.trim() !== "" && change.set?.when === undefined) {
611
- change.set = { ...change.set, when: [current, ...change.add.when] };
612
- delete change.add.when;
613
- }
614
- }
615
- /**
616
- * The pages that change with a page a write changed (INH-11): all those deriving from it when it is new or derives from another creature now;
617
- * else those that read a field it changed, or show the section it wrote.
618
- */
619
- function followersOfWrite(now, before, after) {
620
- if (!isBaseType(after.type)) {
621
- return { pages: [], why: "" };
622
- }
623
- const changed = before === undefined ? [] : changedNames(before, after);
624
- if (before === undefined || changed.some((field) => comparableText(field) === baseFieldOf(after.type))) {
625
- return { pages: derivedPages(now, after), why: `since they derive from ${after.name}` };
626
- }
627
- const byField = changed.map((field) => ({ name: field, pages: followersOf(now, after, field) }));
628
- const bySection = changedParts(before.body, after.body).map((part) => ({ name: part === "" ? "a secret without a name" : `#${part}`, pages: part === "" ? derivedPages(now, after) : sectionFollowersOf(now, after, part) }));
629
- const byIntroduction = introductionText(before.body) === introductionText(after.body) ? [] : [{ name: "the introduction", pages: introductionFollowersOf(now, after) }];
630
- const reasons = [...byField, ...bySection, ...byIntroduction].filter((reason) => reason.pages.length > 0);
631
- const pages = new Set(reasons.flatMap((reason) => reason.pages));
632
- return { pages: now.pages.filter((page) => pages.has(page)), why: `since they read ${reasons.map((reason) => reason.name).join(", ")} from ${after.name}` };
633
- }
634
- /** The names of the sections and secrets that a text has with another text, gained or no longer has; "" when its secrets without a name changed, which every derived page shows. */
635
- function changedParts(before, after) {
636
- const texts = (body) => new Map(textParts(body).filter((part) => part.name !== "").map((part) => [comparableText(part.name), part.text]));
637
- const unnamed = (body) => textParts(body).filter((part) => part.name === "").map((part) => part.text).join("\n");
638
- const old = texts(before);
639
- const now = texts(after);
640
- const names = new Map(textParts(`${before}\n\n${after}`).filter((part) => part.name !== "").map((part) => [comparableText(part.name), part.name]));
641
- const named = [...names].filter(([key]) => old.get(key) !== now.get(key)).map(([, name]) => name);
642
- return unnamed(before) === unnamed(after) ? named : [...named, ""];
643
- }
644
- /**
645
- * One public line for each counter that a write changed through inheritance on a page that concerns the player: a page that follows the base written,
646
- * or the page itself when its creature changes. Its name, the field, before and after (INH-10, INH-11). Each page comes as it was and as it is.
647
- */
648
- function logCounterChanges(root, context, world, now, pages, coins) {
649
- for (const [before, after] of pages.filter(([, page]) => concernsPlayer(now, page))) {
650
- const old = inheritedFields(world, before);
651
- for (const [field, value] of Object.entries(inheritedFields(now, after)).filter(([name]) => !isStandardField(after.type, name) && !isDeclaredUncounted(now, name))) {
652
- const was = countedText(valueNamed(old, field), coins);
653
- const is = countedText(value, coins);
654
- if (was !== undefined && is !== undefined && was !== is) {
655
- appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", "public", { page: after.name, field, before: was, after: is }));
656
- }
657
- }
658
- }
659
- }
660
- /** A counter or money as the log writes it; undefined for any other value. */
661
- function countedText(value, coins) {
662
- const purse = coins === undefined ? undefined : readAmount(value, coins);
663
- const counter = readCounter(value);
664
- return purse !== undefined && coins !== undefined ? formatAmount(purse, coins) : counter === undefined ? undefined : formatCounter(counter);
665
- }
666
- /** Money given to set, written as the engine writes it (MON-2): from the coin worth most, by first names. A field the game system declares is never money (SYS-8). */
667
- function asAmounts(world, set, coins) {
668
- return Object.fromEntries(Object.entries(set).map(([field, value]) => {
669
- const purse = coins === undefined || declaredKind(world, field) !== undefined ? undefined : readAmount(value, coins);
670
- return [field, purse === undefined || coins === undefined ? value : formatAmount(purse, coins)];
671
- }));
672
- }
673
- /** What a write should say about money: a value that names coins but does not read as money, and coins that cannot be read (MON-2, MON-8). */
674
- function moneyNotesOf(world, page, set, coins, problem) {
675
- // A field the game system declares is never money (SYS-8).
676
- const texts = Object.entries(set ?? {}).filter(([field, value]) => typeof value === "string" && declaredKind(world, field) === undefined);
677
- const unread = coins === undefined ? [] : texts.filter(([, value]) => readAmount(value, coins) === undefined && namesCoins(value, coins));
678
- const notes = unread.map(([field, value]) => `${field} on ${page} is "${value}", which is not money: write the coins one after the other, such as ${field}=12 ${coins?.[0].name ?? ""}, to count them.`);
679
- const looksLikeMoney = texts.some(([, value]) => /\d+\s*\p{L}/u.test(value));
680
- return problem !== undefined && looksLikeMoney ? [...notes, `The campaign's coins cannot be read, so no money is counted: ${problem.message} To fix it, ${problem.fix}.`] : notes;
681
- }
682
- /**
683
- * A list written whole that leaves out items the page read from a base, as an elf's Perception from its race: said, since the page no longer reads them (INH-7).
684
- */
685
- function droppedFromBaseNotes(now, page, set) {
686
- return Object.entries(set ?? {}).filter(([, value]) => Array.isArray(value)).flatMap(([field, value]) => {
687
- const base = baseValue(now, page, field);
688
- if (base === undefined || !Array.isArray(base.value)) {
689
- return [];
690
- }
691
- const held = new Set(listItemNames(value).map(comparableText));
692
- const missing = listItemNames(base.value).filter((name) => !held.has(comparableText(name)));
693
- const them = missing.length === 1 ? "it" : "them";
694
- return missing.length === 0 ? [] : [`${field} on ${page.name} leaves out ${missing.join(", ")}, which it read from ${base.base.name}: if the character keeps ${them}, add ${them}, such as add ${field}=${missing[0]}.`];
695
- });
696
- }
697
- /** What a new page is told of its base; a weight is asked only of an item with no base to look for, which would give one (LOAD-1). */
698
- function baseNotesOrWeight(system, now, page) {
699
- const notes = [...derivesFromNothingNote(now, page), ...noBaseNote(now, page)];
700
- return notes.length > 0 ? notes : weightlessNote(system, now, page);
701
- }
702
- /** A page created with a name that other pages give as their creature or item, though it is not one: they derive from nothing (INH-2). */
703
- function derivesFromNothingNote(now, page) {
704
- return ["creature", "item"].filter((field) => field !== page.type).flatMap((field) => {
705
- const linking = now.pages.filter((other) => baseFieldOf(other.type) === field && linksIn(other.fields[field]).some((name) => comparableText(name) === comparableText(page.name)));
706
- return linking.length === 0
707
- ? []
708
- : [`${linking.map((other) => other.name).join(", ")} name ${page.name} as their ${field}, but it is ${withArticle(page.type ?? "free page")}: they derive from nothing until ${field} links to ${withArticle(field)}.`];
709
- });
710
- }
711
- /**
712
- * For a creature or an item created without a base, when the game system has pages of its type: it may be a kind of one of them (D-165, SYS-7).
713
- * When another field already links to one, the field to use instead.
714
- */
715
- function noBaseNote(now, page) {
716
- const field = baseFieldOf(page.type);
717
- if (page.type === "character" || field === undefined || !isEmptyField(page.fields[field])) {
718
- return [];
719
- }
720
- // Only a free field links to its base by mistake: a field the system declares, such as magic, links to something else (D-164).
721
- const free = Object.entries(page.fields).filter(([name]) => declaredKind(now, name) === undefined);
722
- const elsewhere = free.flatMap(([name, value]) => linksIn(value).map((link) => ({ name, page: systemPageNamed(now, link) }))).find((link) => link.page?.type === field);
723
- if (elsewhere?.page !== undefined) {
724
- const linked = elsewhere.page;
725
- const system = linked.system ?? "";
726
- return [
727
- `${page.name} links to ${linked.name}, ${withArticle(field)} of the system ${system}, in ${elsewhere.name}: if it is a kind of it, the field is ${field}, `
728
- + `such as write "${page.name}", set ${field}=[[${linked.name}]], unset ${elsewhere.name}.`,
729
- ];
730
- }
731
- // A story item, such as a letter, writes no field of the system: it is no kind of one of its items.
732
- if (page.type === "item" && !Object.keys(page.fields).some((name) => declaredKind(now, name) !== undefined)) {
733
- return [];
734
- }
735
- const hint = systemBaseHint(now, field, field);
736
- return hint === "" ? [] : [`${page.name} derives from no ${field}:${hint.replace(" If it", " if it")}`];
737
- }
738
- /**
739
- * What a write should say of the links it gave in fields the game system declares, such as spells (D-216): those to pages that do not exist yet, which the world
740
- * gets with write, and those to a page that shares its name with another, as Shield the item beside Shield (spell). A campaign played in another language is
741
- * told the system's. The core's fields, as contains or knows, link ahead to pages still to write.
742
- */
743
- function linkNotes(world, change) {
744
- // The base a creature or an item derives from too, as item=[[Spada lunga]] for Longsword.
745
- const told = (field) => declaredKind(world, field) !== undefined || ["creature", "item"].includes(comparableText(field));
746
- const given = [...Object.entries(change.set ?? {}), ...Object.entries(change.add ?? {})].filter(([field]) => told(field)).flatMap(([, value]) => linksIn(value));
747
- const names = [...new Set(given)];
748
- const exists = (name) => pagesWithName(world, name)[0] ?? systemPageNamed(world, name);
749
- const missing = names.filter((name) => exists(name) === undefined);
750
- const system = world.system;
751
- const foreign = foreignSystemLanguage(world);
752
- const language = system === undefined || foreign === undefined ? "" : ` The system ${system.name} names its pages in ${foreign}: find looks them up.`;
753
- const absent = missing.length === 0
754
- ? []
755
- : [`No page for ${missing.map((name) => `[[${name}]]`).join(", ")} yet: create ${missing.length === 1 ? "it" : "them"} with write if ${missing.length === 1 ? "it belongs" : "they belong"} to this world, or link a page that exists.${language}`];
756
- const twins = names.flatMap((name) => {
757
- const page = exists(name);
758
- const others = page === undefined ? [] : namesakes(world, page);
759
- return page === undefined || others.length === 0 ? [] : [`[[${name}]] is ${page.system === undefined ? withArticle(page.type ?? "page") : systemLabel(page)}; there is also ${others.map((other) => other.name).join(", ")}.`];
760
- });
761
- return [...absent, ...twins];
762
- }
763
- /**
764
- * When the items of a list give a field another formula reads, as two armors in equipped or Unarmored Defense from two classes, the formula reads the first
765
- * (PRO-5): said when a write makes it so.
766
- */
767
- function firstItemNotes(before, after, existing, page) {
768
- const computed = after.system?.formulas?.computed ?? [];
769
- return Object.entries(after.system?.itemFormulas ?? {}).flatMap(([list, names]) => names.flatMap((field) => {
770
- const readers = computed.filter(([, formula]) => fieldsRead(formula).some((name) => comparableText(name) === comparableText(field))).map(([name]) => name);
771
- const giving = (world, fields) => itemLines(world, fields, list, [field]).map((line) => line.item);
772
- const is = readers.length === 0 ? [] : giving(after, effectiveFields(after, page));
773
- const was = is.length < 2 || existing === undefined ? [] : giving(before, effectiveFields(before, existing));
774
- if (is.length < 2 || (was.length === is.length && was.every((name, index) => comparableText(name) === comparableText(is[index])))) {
775
- return [];
776
- }
777
- return [`${readers.join(", ")} ${readers.length === 1 ? "reads" : "read"} ${field} from ${is[0]}, the first in ${page.name}'s ${list} that gives it, not from ${is.slice(1).join(", ")}.`];
778
- }));
779
- }
780
366
  /** "hp=15/15": the fields a refused write gave, for the call to make instead, without the base field, which that call gives. */
781
367
  function givenFields(set, baseField) {
782
368
  return Object.entries(set ?? {})
783
369
  .filter(([field]) => comparableText(field) !== baseField)
784
370
  .map(([field, value]) => `${field}=${Array.isArray(value) ? `[${value.map(String).join(", ")}]` : String(value)}`);
785
371
  }
786
- /** The fields the system's sheet asks of every character, its optional ones left out, as names are compared. */
787
- function askedFields(system) {
788
- return new Set((system?.sheet ?? []).flatMap((group) => group.entries.filter((entry) => !entry.optional).map((entry) => comparableText(entry.field))));
789
- }
790
- /** Whether pages of this type can be bases: creatures and items (INH-1). */
791
- function isBaseType(type) {
792
- return type === "creature" || type === "item";
793
- }
794
- /** "Not changed, since they hold their own fiuto: Grigio (fiuto 2)": for each field a write changed on a base, the pages deriving from it that keep their own value. */
795
- function keepersNotes(now, before, after) {
796
- if (!isBaseType(after.type)) {
797
- return [];
798
- }
799
- return changedNames(before, after).flatMap((field) => {
800
- const keepers = keepersOf(now, after, field).map((keeper) => `${keeper.name} (${field} ${valueText(valueNamed(inheritedFields(now, keeper), field))})`);
801
- const note = keepersNote(keepers, field);
802
- return note === "" ? [] : [note];
803
- });
804
- }
805
- /** After its creature changes, the values a page keeps that its new bases give otherwise: they may belong to the old one (D-125). */
806
- function ownValuesNote(now, before, after, coins) {
807
- const field = baseFieldOf(after.type);
808
- if (field === undefined || !changedNames(before, after).some((name) => comparableText(name) === field)) {
809
- return [];
810
- }
811
- const kept = Object.entries(after.fields).filter(([name, value]) => !isEmptyField(value) && !isNeverInherited(name)).flatMap(([name, value]) => {
812
- const base = baseValue(now, after, name);
813
- return base === undefined || JSON.stringify(base.value) === JSON.stringify(value) ? [] : [{ field: name, value, base }];
814
- });
815
- if (kept.length === 0) {
816
- return [];
817
- }
818
- // A current/max counter or money goes back to the base's value with change; anything else is removed.
819
- const back = kept.map(({ field, value, base }) => {
820
- const mine = guarded(value, coins, false);
821
- const theirs = guarded(base.value, coins, false);
822
- return mine !== undefined && mine.kind === theirs?.kind ? `change ${field} to ${mine.kind === "money" ? `"${theirs.text}"` : theirs.text}` : `unset ${field}`;
823
- });
824
- const listed = kept.map(({ field, value, base }) => `${field} ${valueText(value)} (${base.base.name} gives ${valueText(base.value)})`);
825
- return [`${after.name} keeps its own ${listed.join(", ")}. If they came from its old ${field}: ${back.join(", ")}.`];
826
- }
827
- /** The fields whose value a write changed on a page. */
828
- function changedNames(before, after) {
829
- return [...new Set([...Object.keys(before.fields), ...Object.keys(after.fields)])].filter((field) => JSON.stringify(before.fields[field]) !== JSON.stringify(after.fields[field]));
830
- }
831
- /** A value as the outputs show it: a list as its items, anything else as written. */
832
- function valueText(value) {
833
- return Array.isArray(value) ? value.map(String).join(", ") : typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
834
- }
835
- /** Whether changing a field reaches the pages and copies deriving from a page: a field they inherit, or the creature or item it derives from. */
836
- function passesOn(field) {
837
- return !isNeverInherited(field) || comparableText(field) === "creature" || comparableText(field) === "item";
838
- }
839
- function changedFieldNames(change) {
840
- return [...Object.keys(change.set ?? {}), ...(change.unset ?? []), ...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})];
841
- }
842
- /** "hp, ac again as Wolf": fields grouped by the base they are read from. */
843
- function byBase(fields, base, how) {
844
- return [...new Set(fields.map(base))].map((name) => `${fields.filter((field) => base(field) === name).join(", ")} ${how} ${name ?? ""}`);
845
- }
846
- /** A field is given a value: an empty one would count as missing (INH-6), and removing a field is unset, which checks what it would bring back. */
847
- function checkValues(change) {
848
- const [empty] = Object.entries(change.set ?? {}).filter(([, value]) => isEmptyField(value));
849
- if (empty !== undefined) {
850
- throw new Error(`Give ${empty[0]} a value. To remove a field, use unset.`);
851
- }
852
- }
853
- /** Items are added to or removed from a list: one that the page reads as something else, itself or from a base, is set whole first (INH-7). */
854
- function checkLists(world, page, change) {
855
- const fields = inheritedFields(world, page);
856
- for (const field of [...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})].filter((name) => !Object.hasOwn(change.set ?? {}, name))) {
857
- const [name, value] = Object.entries(fields).find(([key]) => comparableText(key) === comparableText(field)) ?? [];
858
- if (name !== undefined && !Array.isArray(value)) {
859
- const base = holdsField(page, name) ? undefined : baseValue(world, page, name)?.base;
860
- const from = base === undefined ? "" : `, which ${page.name} reads from ${base.name}`;
861
- throw new Error(`${name} on ${page.name} is ${JSON.stringify(value)}${from}, not a list: items cannot be added to it or removed from it. To make it a list, set it whole, such as set ${name}=[a, b].`);
862
- }
863
- }
864
- }
865
- /**
866
- * The names of the fields a write changed, as the page writes them (INH-5). A value equal to the base's is not written (D-125): it is no change, unless the page
867
- * held another, which it holds no more ("ac again as Lupo").
868
- */
869
- function writtenNames(world, page, change, after) {
870
- const names = (fields) => fields.map((field) => (page === undefined ? field : writtenFieldName(world, page, field)));
871
- const removed = (change.unset ?? []).map((field) => (page === undefined ? field : removedFieldName(page, field)));
872
- const [set, add, remove] = [Object.keys(change.set ?? {}), Object.keys(change.add ?? {}), Object.keys(change.remove ?? {})].map(names);
873
- const now = withPage(world, page, after);
874
- const base = (field) => baseValue(now, after, field)?.base.name;
875
- // What the page held and holds no more, without being removed: it reads it from a base again. What it was given and does not hold: it reads it from a base all the same.
876
- const gone = page === undefined ? [] : Object.keys(page.fields).filter((field) => !isEmptyField(page.fields[field]) && !Object.hasOwn(after.fields, field) && !removed.includes(field) && base(field) !== undefined);
877
- const asBase = [...set, ...add, ...remove].filter((field, index, all) => all.indexOf(field) === index && !gone.includes(field) && !Object.hasOwn(after.fields, field) && base(field) !== undefined);
878
- const shown = (field) => !gone.includes(field) && !asBase.includes(field);
879
- return {
880
- set: set.filter((field) => shown(field) && JSON.stringify(page?.fields[field]) !== JSON.stringify(after.fields[field])),
881
- again: [...byBase(gone, base, "again as"), ...byBase(asBase, base, "as")],
882
- unset: removed,
883
- add: add.filter(shown),
884
- remove: remove.filter(shown),
885
- };
886
- }
887
372
  function changeSummary(result, changes) {
888
373
  const what = result.copyOf === undefined ? `${result.created ? "Created" : "Updated"} ${result.page} (${result.type ?? "free page"}, ${result.path})` : `Updated ${result.page} (copy of ${result.copyOf} in the open scene)`;
889
374
  return changes.length > 0 ? `${what}: ${changes.join("; ")}.` : `${what}.`;
890
375
  }
891
- /** Fields from field=value pairs, each value read as a link, links, a number, true or false, a list or text; or from an object, as they are. */
892
- function readFields(fields) {
893
- if (!Array.isArray(fields)) {
894
- return Object.fromEntries(Object.entries(fields).map(([name, value]) => [name, listFromText(name, value)]));
895
- }
896
- // The same name twice would be lost in one object; the same field in another case is refused later, with the other changes.
897
- const entries = fields.map(readAssignment);
898
- const repeated = entries.find(([name], index) => entries.findIndex(([other]) => other === name) !== index);
899
- if (repeated !== undefined) {
900
- throw new Error(`The field ${repeated[0]} is given twice: give each field once.`);
901
- }
902
- return Object.fromEntries(entries);
903
- }
904
- /** Items for list fields: each value gives one item, or several when it is a list; the same field may come more than once. */
905
- function readListItems(fields) {
906
- // No prototype: a field named constructor or toString is a field like any other.
907
- const items = Object.create(null);
908
- for (const [name, given] of Array.isArray(fields) ? fields.map(readAssignment) : Object.entries(fields)) {
909
- const value = listFromText(name, given);
910
- items[name] = [...(items[name] ?? []), ...(Array.isArray(value) ? value : [value])];
911
- }
912
- return items;
913
- }
914
- /**
915
- * The fields given to set without those the game system works out on the page as the write leaves it, a copy in the open scene or a page that gets its base in
916
- * the same write included (FOR-7), with a note that gives the values the system works out and what they come from.
917
- */
918
- function withoutComputed(world, target, set, name, type) {
919
- const after = { ...(target ?? { name, path: "", body: "" }), type: type ?? target?.type, fields: { ...(target?.fields ?? {}), ...set } };
920
- const fields = effectiveFields(world, after);
921
- const computed = Object.entries(set).flatMap(([field, given]) => {
922
- const found = computedField(world, field, fields);
923
- return found === undefined ? [] : [{ ...found, given }];
924
- });
925
- if (computed.length === 0) {
926
- return { set };
927
- }
928
- const kept = Object.fromEntries(Object.entries(set).filter(([field]) => !computed.some((found) => comparableText(found.name) === comparableText(field))));
929
- const values = computed.map((found) => {
930
- const value = signedText(world, found.name, found.value);
931
- return `${found.name} ${value}${numberOf(found.given) === found.value ? ", as you gave it" : ` (you gave ${String(found.given)})`}`;
932
- });
933
- const sources = [...new Set(computed.flatMap((found) => found.from))];
934
- const bonuses = [...new Set(computed.flatMap((found) => directBonuses(world, found)))];
935
- const bonus = bonuses.length === 0 ? "" : ` A bonus such as ${bonuses[0]} comes from an effect, for what gives one, such as a magic item.`;
936
- const note = `Not written, the system ${world.system?.name ?? ""} works ${computed.length === 1 ? "it" : "them"} out: ${values.join("; ")}. They come from ${sources.join(", ")}.${bonus}`;
937
- return { set: kept, note };
938
- }
939
- /** The items given to add or remove without the fields the game system works out on the page, which no list change writes (FOR-7, D-200), with a note. */
940
- function listsWithoutComputed(world, target, lists) {
941
- if (lists === undefined || target === undefined) {
942
- return { lists };
943
- }
944
- const fields = effectiveFields(world, target);
945
- const computed = Object.keys(lists).flatMap((field) => computedField(world, field, fields) ?? []);
946
- if (computed.length === 0) {
947
- return { lists };
948
- }
949
- const kept = Object.fromEntries(Object.entries(lists).filter(([field]) => !computed.some((found) => comparableText(found.name) === comparableText(field))));
950
- const values = computed.map((found) => `${found.name} ${signedText(world, found.name, found.value)}`).join("; ");
951
- const sources = [...new Set(computed.flatMap((found) => found.from))].join(", ");
952
- return {
953
- lists: Object.keys(kept).length === 0 ? undefined : kept,
954
- note: `Not written, the system ${world.system?.name ?? ""} works ${computed.length === 1 ? "it" : "them"} out: ${values}. ${computed.length === 1 ? "It comes" : "They come"} from ${sources}.`,
955
- };
956
- }
957
- /** The part quest-ends when a quest is done or failed, such as the experience the story gives (D-233), once in a chat (D-97). */
958
- function questEndNotes(context, system, existing, page) {
959
- if (!questEnds(existing, page)) {
960
- return [];
961
- }
962
- const part = situationPart("quest-ends", context, system);
963
- return part === "" ? [] : [`${page.name} is ${String(page.fields.status)}. ${part}`];
964
- }
965
- /** Whether this write ends a quest: done or failed now, and not before. */
966
- function questEnds(existing, page) {
967
- const ended = (candidate) => ["done", "failed"].includes(String(candidate?.fields.status));
968
- return page.type === "quest" && ended(page) && !ended(existing);
969
- }
970
- /** Items written in a list where the parts of the classes already put them, as a domain's spell in prepared: always there, they do not count with the rest (PRO-7). */
971
- function givenListNotes(world, page, changed) {
972
- const progression = progressionOf(world, effectiveFields(world, page));
973
- return changed.flatMap((field) => {
974
- const written = listItemNames(valueNamed(page.fields, field));
975
- const twice = givenItems(progression, field).filter((item) => sameName(written, item.name) !== undefined);
976
- const pages = [...new Set(twice.map((item) => item.page.name))].join(" and ");
977
- return twice.length === 0
978
- ? []
979
- : [`${twice.map((item) => item.name).join(", ")} ${twice.length === 1 ? "is" : "are"} always in ${field}, from ${pages}, and not counted with the rest: write ${page.name}, remove ${field}=${twice[0].name}, to choose another in its place.`];
980
- });
981
- }
982
- /** A section of a character with the name of a feature its classes give: show gives it in place of the feature's text (PRO-4). */
983
- function featureSectionNotes(world, page, section) {
984
- const feature = progressionOf(world, effectiveFields(world, page))?.features.find((candidate) => sameFeature(candidate.name, section));
985
- return feature === undefined ? [] : [`show ${page.name}#${section} now gives this section, not the text of the feature ${featureParts(feature.name).name} its classes give.`];
986
- }
987
- /**
988
- * What a change of classes gives or takes (PRO-4): the features of the rows it reaches, new, gained again or with a new value, those no longer had, the values of
989
- * the rows and of the formulas of the classes' pages that change, and, when a class rises, the system's note for a new level (D-226), unless the same write sets
990
- * a field it names, as hp-base. Nothing when the classes give the same.
991
- */
992
- function progressionNotes(context, system, before, after, existing, page, set) {
993
- const was = progressionOf(before, effectiveFields(before, existing));
994
- const is = progressionOf(after, effectiveFields(after, page));
995
- const gains = rowGains(was, is);
996
- const lost = (was?.features ?? []).map((feature) => feature.name).filter((name) => !(is?.features ?? []).some((other) => sameFeature(other.name, name)));
997
- // The maximum of a use the rows give is said with the counters (FOR-6).
998
- const counters = Object.keys(after.system?.formulas?.counters ?? {});
999
- const valueOf = (progression, field) => {
1000
- const found = progression?.values.find((value) => comparableText(value.field) === comparableText(field));
1001
- return found === undefined ? undefined : signedText(after, found.field, found.value);
1002
- };
1003
- const fields = [...new Set([...(was?.values ?? []), ...(is?.values ?? [])].map((value) => value.field))].filter((field) => !counters.some((counter) => comparableText(counter) === comparableText(field)));
1004
- const values = fields.flatMap((field) => {
1005
- const [from, to] = [valueOf(was, field), valueOf(is, field)];
1006
- return from === to ? [] : [`${field} ${from ?? "none"} → ${to ?? "none"}`];
1007
- });
1008
- // What the formulas of the classes' pages give, as the prepared spells of a new level (PRO-5).
1009
- const [then, now] = [effectiveFields(before, existing), effectiveFields(after, page)];
1010
- const formulaValues = (after.system?.itemFormulas?.[after.system.progression?.list ?? ""] ?? []).flatMap((field) => {
1011
- const [from, to] = [valueNamed(then, field), valueNamed(now, field)];
1012
- const text = (value) => (value === undefined ? "none" : typeof value === "number" ? signedText(after, field, value) : String(value));
1013
- return text(from) === text(to) ? [] : [`${field} ${text(from)} → ${text(to)}`];
1014
- });
1015
- const shown = gains.fresh[0] ?? gains.better[0]?.name;
1016
- const parts = [
1017
- gains.fresh.length === 0 ? "" : `${gains.fresh.join(", ")} ${gains.fresh.length === 1 ? "is" : "are"} new`,
1018
- gains.again.length === 0 ? "" : `${gains.again.join(", ")} again`,
1019
- gains.better.map((feature) => feature.text).join(", "),
1020
- lost.length === 0 ? "" : `no longer ${lost.join(", ")}`,
1021
- [...values, ...formulaValues].join(", "),
1022
- ].filter((part) => part !== "");
1023
- const hint = shown === undefined ? "" : ` show ${page.name}#${featureParts(shown).name} gives a feature's text.`;
1024
- const levelUp = partText("level-up", system);
1025
- // A new level is one more in all: a class changed for another of a lower level is none.
1026
- const levels = (progression) => (progression?.from ?? []).reduce((total, item) => total + (item.level ?? 0), 0);
1027
- // Not said when the same write sets a field the note names, as hp-base: it is already done.
1028
- const named = new Set((levelUp?.match(/[\p{L}\p{N}-]+/gu) ?? []).map(comparableText));
1029
- const done = set.some((field) => named.has(comparableText(field)));
1030
- // The part level-up, once in a chat (D-97).
1031
- const risen = levelUp !== undefined && levels(is) > levels(was) && !done ? situationPart("level-up", context, system) : "";
1032
- // A value that ends in a period, such as +10 ft., ends the line.
1033
- const said = parts.length === 0 ? [] : [`What ${page.name}'s ${is?.lists[0] ?? was?.lists[0] ?? "classes"} give: ${parts.join("; ").replace(/\.$/, "")}.${hint}`];
1034
- return [...said, ...(risen === "" ? [] : [risen])];
1035
- }
1036
- /**
1037
- * The features the rows and parts give now that they did not before, each name once (PRO-3): new to the character, gained again, as a later Ability Score
1038
- * Improvement, or with a new value, as "Bardic Inspiration (d6 → d8)".
1039
- */
1040
- function rowGains(was, is) {
1041
- const key = (gain) => `${gain.page.path}|${gain.level}|${comparableText(gain.name)}`;
1042
- const old = new Set((was?.gains ?? []).map(key));
1043
- const had = was?.features ?? [];
1044
- const result = { fresh: [], again: [], better: [] };
1045
- for (const gain of mergedFeatures((is?.gains ?? []).filter((candidate) => !old.has(key(candidate))))) {
1046
- const before = had.find((feature) => sameFeature(feature.name, gain.name))?.name;
1047
- const [then, now] = [featureParts(before ?? "").value, featureParts(gain.name).value];
1048
- if (before === undefined) {
1049
- result.fresh.push(gain.name);
1050
- }
1051
- else if (now !== undefined && then !== undefined && comparableText(now) !== comparableText(then)) {
1052
- result.better.push({ name: gain.name, text: `${featureParts(gain.name).name} (${then.slice(1, -1)} → ${now.slice(1, -1)})` });
1053
- }
1054
- else {
1055
- result.again.push(featureParts(gain.name).name);
1056
- }
1057
- }
1058
- return result;
1059
- }
1060
- /** Whether two names are the same feature, with or without a value in parentheses (PRO-3). */
1061
- function sameFeature(first, second) {
1062
- return comparableText(featureParts(first).name) === comparableText(featureParts(second).name);
1063
- }
1064
- /** The thresholds the fields a write gives touch on the player character or a companion, as change says them (DAT-3): exhaustion written with write shows its rule. */
1065
- function writtenThresholdNotes(root, system, before, after, existing, page, set) {
1066
- const read = (fields, field) => valueNamed(fields, field);
1067
- const was = existing === undefined ? {} : effectiveFields(before, existing);
1068
- const is = effectiveFields(after, page);
1069
- return Object.keys(set).flatMap((field) => {
1070
- const [from, to] = [read(was, field), read(is, field)];
1071
- return String(from) === String(to) ? [] : thresholdNotes(root, system, field, { before: from, after: to, amount: {} });
1072
- });
1073
- }
1074
- /**
1075
- * The counters of a page whose written maximum is not what the game system works out from the page without its effects, set to it, and a note (FOR-6). A use
1076
- * that only the lists give and that the page no longer has, with a maximum of 0 or none where it had one, is taken off (DAT-9).
1077
- */
1078
- function workedLimitsChange(system, before, existing, world, page) {
1079
- const fields = inheritedFields(world, page);
1080
- const old = existing === undefined ? undefined : inheritedFields(before, existing);
1081
- const changes = Object.keys(world.system?.formulas?.counters ?? {}).flatMap((field) => {
1082
- const key = sameName(Object.keys(page.fields), field);
1083
- const counter = key === undefined ? undefined : readCounter(page.fields[key]);
1084
- const { max } = counterLimits(world, fields, field);
1085
- const had = old === undefined || max !== undefined ? undefined : counterLimits(before, old, field).max;
1086
- const limit = max ?? (had === undefined ? undefined : 0);
1087
- if (key === undefined || counter === undefined || limit === undefined || counter.max === limit) {
1088
- return [];
1089
- }
1090
- // Of a use, what was spent stays spent, as a table counts it: a maximum that grows by 3 gives 3 more; one that falls only caps the current, as the SRD does,
1091
- // but for what an effect allows above the written maximum (FOR-6, D-228). Any other counter keeps its current, which reads no higher than the maximum.
1092
- const grows = counter.max !== undefined && limit > counter.max;
1093
- const capped = counter.max !== undefined && counter.value <= counter.max ? Math.max(0, Math.min(counter.value, limit)) : counter.value;
1094
- const value = !isUse(world, key) || counter.max === undefined ? counter.value : grows ? counter.value + limit - counter.max : capped;
1095
- return [{ key, before: counter.max, value: formatCounter({ value, max: limit }), reads: formatCounter({ value: Math.min(value, limit), max: limit }), max: limit, lost: max === undefined }];
1096
- });
1097
- // Only a use that the lists give, such as rages from the classes, never one the sheet asks to write, as hp: it stays at any maximum.
1098
- const asked = askedFields(system);
1099
- // A maximum from a class's row, with no formula, has no sources: the lists give it.
1100
- const givenByLists = (field) => {
1101
- const sources = maximumSources(world, field, fields);
1102
- return !asked.has(comparableText(field)) && (sources.length === 0 || sources.some((name) => declaredKind(world, name) === "list"));
1103
- };
1104
- // A use whose maximum has no value now, where it had one, as the slots of a caster who is one no more, is no longer the character's either.
1105
- const gone = changes.filter((change) => change.max <= 0 && isUse(world, change.key) && !asked.has(comparableText(change.key)) && (change.lost || givenByLists(change.key)));
1106
- const kept = changes.filter((change) => !gone.includes(change));
1107
- // "hp 10/17 (max 10 → 17: hp-base 10, level 2, con-mod +2)": what the maximum comes from, so that a written maximum is not taken for the dice.
1108
- const said = kept.map((change) => {
1109
- const parts = workedParts(world, workedMaximum(world, fields, change.key)?.reads ?? []);
1110
- return `${change.key} ${change.reads} (max ${change.before ?? "none"} → ${change.max}${parts === "" ? "" : `: ${parts}`})`;
1111
- });
1112
- // A use the page gets, such as a new level's channel-divinity, is written full on who keeps the sheet (DAT-9, D-225).
1113
- const added = hasSheet(world, page) ? missingUses(world, fields).map((use) => ({ key: use.field, value: formatCounter({ value: use.max, max: use.max }) })) : [];
1114
- const name = world.system?.name ?? "";
1115
- const notes = [
1116
- said.length === 0 ? "" : `${said.join(", ")}: worked out by the system ${name}.`,
1117
- added.length === 0 ? "" : `${page.name} has ${added.map((use) => `${use.key} ${use.value}`).join(", ")}, full: uses of the system ${name} that come back with a rest.`,
1118
- gone.length === 0 ? "" : `${page.name} no longer has ${gone.map((change) => change.key).join(", ")}: the system ${name} gives no uses of ${gone.length === 1 ? "it" : "them"} now.`,
1119
- ];
1120
- return {
1121
- set: Object.fromEntries([...kept, ...added].map((change) => [change.key, change.value])),
1122
- unset: gone.map((change) => change.key),
1123
- notes: notes.filter((note) => note !== ""),
1124
- };
1125
- }
1126
- /**
1127
- * A field that is always a list, or that the game system declares one, given one item, such as contains=[[Locanda]] or tags=boss, holds a list of that one item;
1128
- * text with commas is left to the checks that ask for a list, but a road's stops, links and lengths taking turns, which are split at the commas (ROA-6).
1129
- */
1130
- function oneItemLists(world, set, type) {
1131
- const isList = (name) => listFieldNames.some((field) => comparableText(field) === comparableText(name)) || declaredKind(world, name) === "list";
1132
- const listOf = (name, value) => {
1133
- if (typeof value !== "string" || !isList(name) || value.trim() === "") {
1134
- return value;
1135
- }
1136
- return comparableText(name) === "stops" && type === "place" ? value.split(",").map((item) => item.trim()) : value.includes(",") ? value : [value];
1137
- };
1138
- return Object.fromEntries(Object.entries(set).map(([name, value]) => [name, listOf(name, value)]));
1139
- }
1140
- /**
1141
- * Text given through MCP to a field that is always a list, such as "[[A]], [[B]]", or written as a list, such as "[dex, int]", read as the command line reads it
1142
- * (D-136); any other value as it is.
1143
- */
1144
- function listFromText(name, value) {
1145
- if (typeof value !== "string") {
1146
- return value;
1147
- }
1148
- // Links separated by commas are a list, as on the command line, for a list of the game system too, such as spells (T-167).
1149
- const writtenAsList = /^\[(?!\[).*\]$/s.test(value.trim()) || linkListItems(value) !== undefined;
1150
- return writtenAsList || listFieldNames.some((field) => comparableText(field) === comparableText(name)) ? readFieldValue(value) : value;
1151
- }
1152
- function readAssignment(assignment) {
1153
- const separator = assignment.indexOf("=");
1154
- const value = assignment.slice(separator + 1).trim();
1155
- if (separator <= 0 || value === "") {
1156
- throw new Error(`Write a field as field=value, not "${assignment}". To remove a field, use unset.`);
1157
- }
1158
- return [assignment.slice(0, separator).trim(), readFieldValue(value)];
1159
- }