rpg-engine 0.7.0 → 0.9.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 (397) hide show
  1. package/dist/adventures/index.d.ts +1 -1
  2. package/dist/adventures/index.js +1 -1
  3. package/dist/adventures/source.js +13 -13
  4. package/dist/campaign/create-campaign.js +10 -1
  5. package/dist/campaign/host-files.d.ts +2 -1
  6. package/dist/campaign/host-files.js +11 -11
  7. package/dist/campaign/index.d.ts +1 -1
  8. package/dist/campaign/index.js +1 -1
  9. package/dist/campaign/settings.d.ts +55 -64
  10. package/dist/campaign/settings.js +171 -174
  11. package/dist/{cli.js → cli/cli.js} +3 -3
  12. package/dist/{command-line.d.ts → cli/command-line.d.ts} +1 -1
  13. package/dist/{command-line.js → cli/command-line.js} +21 -20
  14. package/dist/commands/advance.d.ts +1 -1
  15. package/dist/commands/advance.js +7 -7
  16. package/dist/commands/ask.d.ts +1 -8
  17. package/dist/commands/ask.js +16 -29
  18. package/dist/commands/{change.d.ts → change/change.d.ts} +2 -2
  19. package/dist/commands/{change.js → change/change.js} +46 -52
  20. package/dist/commands/{game-damage.d.ts → change/damage.d.ts} +2 -2
  21. package/dist/commands/{game-damage.js → change/damage.js} +3 -3
  22. package/dist/commands/{game-recipe-pace.d.ts → change/recipe-pace.d.ts} +2 -2
  23. package/dist/commands/{game-recipe-pace.js → change/recipe-pace.js} +4 -4
  24. package/dist/commands/config.d.ts +4 -4
  25. package/dist/commands/config.js +142 -138
  26. package/dist/commands/effect.d.ts +1 -1
  27. package/dist/commands/effect.js +11 -12
  28. package/dist/commands/find.d.ts +4 -4
  29. package/dist/commands/find.js +2 -2
  30. package/dist/commands/image.js +6 -6
  31. package/dist/commands/{import.d.ts → import/import.d.ts} +2 -2
  32. package/dist/commands/{import.js → import/import.js} +101 -101
  33. package/dist/commands/{game-import.d.ts → import/run.d.ts} +3 -3
  34. package/dist/commands/{game-import.js → import/run.js} +13 -12
  35. package/dist/commands/index.js +7 -7
  36. package/dist/commands/init.js +3 -3
  37. package/dist/commands/install.js +1 -1
  38. package/dist/commands/instructions.js +6 -6
  39. package/dist/commands/mode.d.ts +2 -2
  40. package/dist/commands/mode.js +8 -8
  41. package/dist/commands/mood.js +4 -4
  42. package/dist/commands/move.js +13 -20
  43. package/dist/commands/package.d.ts +2 -2
  44. package/dist/commands/package.js +138 -93
  45. package/dist/commands/rename.js +3 -3
  46. package/dist/commands/reveal.js +29 -18
  47. package/dist/commands/{roll.d.ts → roll/roll.d.ts} +4 -4
  48. package/dist/commands/{roll.js → roll/roll.js} +69 -69
  49. package/dist/commands/{game-tables.d.ts → roll/tables.d.ts} +2 -2
  50. package/dist/commands/{game-tables.js → roll/tables.js} +4 -4
  51. package/dist/commands/rules.d.ts +2 -2
  52. package/dist/commands/rules.js +17 -9
  53. package/dist/commands/save.d.ts +1 -1
  54. package/dist/commands/save.js +18 -18
  55. package/dist/commands/scene.d.ts +4 -4
  56. package/dist/commands/scene.js +31 -28
  57. package/dist/commands/{game-advance.d.ts → shared/advance.d.ts} +4 -4
  58. package/dist/commands/{game-advance.js → shared/advance.js} +27 -27
  59. package/dist/commands/{game-adventures.d.ts → shared/adventures.d.ts} +3 -3
  60. package/dist/commands/{game-adventures.js → shared/adventures.js} +20 -27
  61. package/dist/commands/{game-bonds.d.ts → shared/bonds.d.ts} +3 -3
  62. package/dist/commands/{game-bonds.js → shared/bonds.js} +2 -2
  63. package/dist/commands/{game-checks.d.ts → shared/checks.d.ts} +3 -3
  64. package/dist/commands/{game-checks.js → shared/checks.js} +7 -7
  65. package/dist/commands/{game-dice-pool.d.ts → shared/dice-pool.d.ts} +3 -3
  66. package/dist/commands/{game-dice-pool.js → shared/dice-pool.js} +19 -12
  67. package/dist/commands/{effect-layer.d.ts → shared/effect-layer.d.ts} +2 -2
  68. package/dist/commands/{effect-layer.js → shared/effect-layer.js} +12 -12
  69. package/dist/commands/{game-effects.d.ts → shared/effects.d.ts} +7 -7
  70. package/dist/commands/{game-effects.js → shared/effects.js} +19 -19
  71. package/dist/commands/{game-environment.d.ts → shared/environment.d.ts} +1 -1
  72. package/dist/commands/{game-environment.js → shared/environment.js} +3 -3
  73. package/dist/commands/{game-events.d.ts → shared/events.d.ts} +5 -5
  74. package/dist/commands/{game-events.js → shared/events.js} +20 -22
  75. package/dist/commands/{game-examples.d.ts → shared/examples.d.ts} +4 -8
  76. package/dist/commands/{game-examples.js → shared/examples.js} +23 -23
  77. package/dist/commands/{game-experience.d.ts → shared/experience.d.ts} +2 -2
  78. package/dist/commands/{game-experience.js → shared/experience.js} +8 -11
  79. package/dist/commands/{game-grid-moves.d.ts → shared/grid-moves.d.ts} +6 -6
  80. package/dist/commands/{game-grid-moves.js → shared/grid-moves.js} +5 -5
  81. package/dist/commands/{game-grids.d.ts → shared/grids.d.ts} +4 -9
  82. package/dist/commands/{game-grids.js → shared/grids.js} +20 -19
  83. package/dist/commands/{game-images.d.ts → shared/images.d.ts} +3 -3
  84. package/dist/commands/{game-images.js → shared/images.js} +7 -6
  85. package/dist/commands/shared/inputs.d.ts +9 -0
  86. package/dist/commands/shared/inputs.js +12 -0
  87. package/dist/commands/{game-journey.d.ts → shared/journey.d.ts} +4 -6
  88. package/dist/commands/{game-journey.js → shared/journey.js} +13 -15
  89. package/dist/commands/{game-knowledge.d.ts → shared/knowledge.d.ts} +15 -8
  90. package/dist/commands/{game-knowledge.js → shared/knowledge.js} +56 -44
  91. package/dist/{library-reader.js → commands/shared/library-reader.js} +4 -4
  92. package/dist/commands/{game-library.d.ts → shared/library.d.ts} +7 -4
  93. package/dist/commands/{game-library.js → shared/library.js} +70 -50
  94. package/dist/commands/{game-limits.d.ts → shared/limits.d.ts} +3 -3
  95. package/dist/commands/{game-limits.js → shared/limits.js} +3 -3
  96. package/dist/commands/{game-loot.d.ts → shared/loot.d.ts} +2 -2
  97. package/dist/commands/{game-loot.js → shared/loot.js} +3 -3
  98. package/dist/commands/{game-master-rolls.d.ts → shared/master-rolls.d.ts} +2 -2
  99. package/dist/commands/{game-master-rolls.js → shared/master-rolls.js} +6 -6
  100. package/dist/commands/{game-mode.d.ts → shared/mode.d.ts} +4 -6
  101. package/dist/commands/{game-mode.js → shared/mode.js} +10 -10
  102. package/dist/commands/{game-money.d.ts → shared/money.d.ts} +3 -3
  103. package/dist/commands/{game-money.js → shared/money.js} +4 -4
  104. package/dist/commands/{game-moods.d.ts → shared/moods.d.ts} +3 -3
  105. package/dist/commands/{game-moods.js → shared/moods.js} +3 -3
  106. package/dist/commands/{game-moves.d.ts → shared/moves.d.ts} +2 -2
  107. package/dist/commands/{game-moves.js → shared/moves.js} +5 -5
  108. package/dist/commands/{game-offers.d.ts → shared/offers.d.ts} +3 -3
  109. package/dist/commands/{game-offers.js → shared/offers.js} +9 -12
  110. package/dist/commands/{game-outside.d.ts → shared/outside.d.ts} +3 -3
  111. package/dist/commands/{game-outside.js → shared/outside.js} +9 -9
  112. package/dist/commands/{game-catalog.d.ts → shared/packages/catalog.d.ts} +1 -3
  113. package/dist/commands/{game-catalog.js → shared/packages/catalog.js} +17 -22
  114. package/dist/commands/{game-package-code.d.ts → shared/packages/code.d.ts} +10 -14
  115. package/dist/commands/{game-package-code.js → shared/packages/code.js} +156 -59
  116. package/dist/commands/{game-extension-list.d.ts → shared/packages/extensions.d.ts} +6 -6
  117. package/dist/commands/{game-extension-list.js → shared/packages/extensions.js} +43 -22
  118. package/dist/commands/{game-package-hooks.d.ts → shared/packages/hooks.d.ts} +3 -3
  119. package/dist/commands/{game-package-hooks.js → shared/packages/hooks.js} +3 -3
  120. package/dist/commands/{game-widgets.d.ts → shared/packages/widgets.d.ts} +6 -10
  121. package/dist/commands/{game-widgets.js → shared/packages/widgets.js} +57 -57
  122. package/dist/commands/{page-counters.d.ts → shared/page-counters.d.ts} +3 -3
  123. package/dist/commands/{page-counters.js → shared/page-counters.js} +5 -5
  124. package/dist/{page-words.d.ts → commands/shared/page-words.d.ts} +2 -2
  125. package/dist/{page-words.js → commands/shared/page-words.js} +5 -4
  126. package/dist/commands/{parts.d.ts → shared/parts.d.ts} +3 -3
  127. package/dist/commands/{parts.js → shared/parts.js} +4 -4
  128. package/dist/commands/{game-positions.d.ts → shared/positions.d.ts} +3 -5
  129. package/dist/commands/{game-positions.js → shared/positions.js} +6 -7
  130. package/dist/commands/{problems.d.ts → shared/problems.d.ts} +3 -3
  131. package/dist/commands/{problems.js → shared/problems.js} +21 -22
  132. package/dist/commands/{progression.d.ts → shared/progression.d.ts} +2 -2
  133. package/dist/commands/{progression.js → shared/progression.js} +4 -4
  134. package/dist/commands/{game-quests.d.ts → shared/quests.d.ts} +4 -4
  135. package/dist/commands/{game-quests.js → shared/quests.js} +6 -6
  136. package/dist/commands/{game-recipes.d.ts → shared/recipes.d.ts} +3 -3
  137. package/dist/commands/{game-recipes.js → shared/recipes.js} +3 -3
  138. package/dist/commands/{game-reminders.d.ts → shared/reminders.d.ts} +4 -4
  139. package/dist/commands/{game-reminders.js → shared/reminders.js} +4 -4
  140. package/dist/commands/{game-roads.d.ts → shared/roads.d.ts} +5 -5
  141. package/dist/commands/{game-roads.js → shared/roads.js} +43 -44
  142. package/dist/commands/{game-rules.d.ts → shared/rules.d.ts} +13 -5
  143. package/dist/commands/shared/rules.js +66 -0
  144. package/dist/commands/{game-saves.d.ts → shared/saves.d.ts} +4 -4
  145. package/dist/commands/{game-saves.js → shared/saves.js} +51 -51
  146. package/dist/commands/{game-scene.d.ts → shared/scene.d.ts} +13 -3
  147. package/dist/commands/{game-scene.js → shared/scene.js} +41 -13
  148. package/dist/commands/{sheet.d.ts → shared/sheet.d.ts} +5 -5
  149. package/dist/commands/{sheet.js → shared/sheet.js} +76 -76
  150. package/dist/commands/{game-stacks.d.ts → shared/stacks.d.ts} +2 -9
  151. package/dist/commands/{game-stacks.js → shared/stacks.js} +22 -22
  152. package/dist/commands/{game-theme.d.ts → shared/theme.d.ts} +3 -3
  153. package/dist/commands/{game-theme.js → shared/theme.js} +2 -2
  154. package/dist/commands/{game-thoughts.d.ts → shared/thoughts.d.ts} +2 -4
  155. package/dist/commands/{game-thoughts.js → shared/thoughts.js} +6 -8
  156. package/dist/commands/{game-thresholds.d.ts → shared/thresholds.d.ts} +1 -1
  157. package/dist/commands/{game-thresholds.js → shared/thresholds.js} +4 -4
  158. package/dist/commands/{game-time.d.ts → shared/time.d.ts} +4 -4
  159. package/dist/commands/{game-time.js → shared/time.js} +6 -6
  160. package/dist/commands/{game-turn-uses.d.ts → shared/turn-uses.d.ts} +3 -3
  161. package/dist/commands/{game-turn-uses.js → shared/turn-uses.js} +12 -15
  162. package/dist/commands/{game-upkeep.d.ts → shared/upkeep.d.ts} +3 -3
  163. package/dist/commands/{game-upkeep.js → shared/upkeep.js} +69 -57
  164. package/dist/commands/{game-voices.d.ts → shared/voices.d.ts} +1 -1
  165. package/dist/commands/{game-voices.js → shared/voices.js} +2 -2
  166. package/dist/commands/{worked-out.d.ts → shared/worked-out.d.ts} +3 -8
  167. package/dist/commands/{worked-out.js → shared/worked-out.js} +238 -238
  168. package/dist/commands/{game-world.d.ts → shared/world.d.ts} +5 -14
  169. package/dist/commands/{game-world.js → shared/world.js} +72 -76
  170. package/dist/commands/show.d.ts +4 -1
  171. package/dist/commands/show.js +36 -18
  172. package/dist/commands/status.d.ts +1 -1
  173. package/dist/commands/status.js +28 -28
  174. package/dist/commands/thoughts.js +3 -3
  175. package/dist/commands/trade.js +9 -10
  176. package/dist/commands/translate.d.ts +1 -1
  177. package/dist/commands/translate.js +3 -3
  178. package/dist/commands/{game-open.d.ts → travel/open.d.ts} +3 -3
  179. package/dist/commands/{game-open.js → travel/open.js} +4 -5
  180. package/dist/commands/{route.d.ts → travel/route.d.ts} +1 -1
  181. package/dist/commands/{route.js → travel/route.js} +9 -10
  182. package/dist/commands/{travel.d.ts → travel/travel.d.ts} +2 -2
  183. package/dist/commands/{travel.js → travel/travel.js} +19 -21
  184. package/dist/commands/validate.js +5 -5
  185. package/dist/commands/{game-view-journal.d.ts → view/journal.d.ts} +5 -5
  186. package/dist/commands/{game-view-journal.js → view/journal.js} +5 -5
  187. package/dist/commands/{game-view-map.d.ts → view/map.d.ts} +3 -3
  188. package/dist/commands/{game-view-map.js → view/map.js} +15 -16
  189. package/dist/commands/{game-view-place.d.ts → view/place.d.ts} +6 -6
  190. package/dist/commands/{game-view-place.js → view/place.js} +108 -108
  191. package/dist/commands/{view.d.ts → view/view.d.ts} +16 -16
  192. package/dist/commands/{view.js → view/view.js} +41 -36
  193. package/dist/commands/{game-view-world.d.ts → view/world.d.ts} +4 -4
  194. package/dist/commands/{game-view-world.js → view/world.js} +7 -7
  195. package/dist/commands/{game-here.d.ts → write/here.d.ts} +5 -3
  196. package/dist/commands/{game-here.js → write/here.js} +18 -12
  197. package/dist/commands/{write.d.ts → write/write.d.ts} +6 -6
  198. package/dist/commands/{write.js → write/write.js} +44 -41
  199. package/dist/confirm/confirm.d.ts +2 -0
  200. package/dist/confirm/confirm.js +15 -5
  201. package/dist/core/consents.d.ts +3 -2
  202. package/dist/core/consents.js +43 -4
  203. package/dist/core/context.d.ts +8 -6
  204. package/dist/core/context.js +4 -2
  205. package/dist/core/download.js +16 -5
  206. package/dist/core/files.d.ts +8 -1
  207. package/dist/core/files.js +53 -21
  208. package/dist/core/formula.d.ts +7 -2
  209. package/dist/core/formula.js +63 -66
  210. package/dist/core/instruction-parts.js +1 -1
  211. package/dist/core/mood.d.ts +0 -1
  212. package/dist/core/mood.js +3 -3
  213. package/dist/core/package-api.d.ts +11 -0
  214. package/dist/core/package-api.js +2 -1
  215. package/dist/core/package-declarations.d.ts +9 -9
  216. package/dist/core/package-declarations.js +3 -3
  217. package/dist/core/process-mark.d.ts +8 -0
  218. package/dist/core/process-mark.js +72 -0
  219. package/dist/core/registry.d.ts +5 -0
  220. package/dist/core/registry.js +10 -0
  221. package/dist/core/session-store.d.ts +0 -1
  222. package/dist/core/session-store.js +11 -14
  223. package/dist/core/store.d.ts +4 -0
  224. package/dist/core/store.js +29 -8
  225. package/dist/core/text.d.ts +4 -0
  226. package/dist/core/text.js +11 -2
  227. package/dist/core/yaml-file.js +2 -2
  228. package/dist/dashboard/{acts.js → acts/acts.js} +2 -2
  229. package/dist/dashboard/{act-names.js → acts/names.js} +1 -1
  230. package/dist/dashboard/{act-sheet.js → acts/sheet.js} +3 -3
  231. package/dist/dashboard/{act-strip.js → acts/strip.js} +2 -2
  232. package/dist/dashboard/app.js +13 -13
  233. package/dist/dashboard/asked.js +1 -1
  234. package/dist/dashboard/dice/burn.js +1 -1
  235. package/dist/dashboard/dice/stage.js +1 -1
  236. package/dist/dashboard/game-words.js +4 -4
  237. package/dist/dashboard/{guide-blocks.js → help/blocks.js} +1 -1
  238. package/dist/dashboard/{help.js → help/help.js} +6 -6
  239. package/dist/dashboard/journal.js +1 -1
  240. package/dist/dashboard/kit.js +6 -5
  241. package/dist/dashboard/labels.js +7 -3
  242. package/dist/dashboard/markdown.js +1 -1
  243. package/dist/dashboard/{ask-card.js → packages/ask-card.js} +6 -6
  244. package/dist/dashboard/{package-page.js → packages/package-page.js} +3 -3
  245. package/dist/dashboard/{packages.js → packages/packages.js} +12 -12
  246. package/dist/dashboard/{page-code.js → packages/page-code.js} +4 -4
  247. package/dist/dashboard/{extension-widgets.js → packages/widgets.js} +5 -5
  248. package/dist/dashboard/party.js +1 -1
  249. package/dist/dashboard/person-panel.js +2 -13
  250. package/dist/dashboard/{map-sheet.js → place/map-sheet.js} +4 -4
  251. package/dist/dashboard/{place-map-view.js → place/map-view.js} +11 -11
  252. package/dist/dashboard/scene.js +4 -4
  253. package/dist/dashboard/settings.js +1 -1
  254. package/dist/dashboard/sheet.js +4 -4
  255. package/dist/dashboard/text.js +6 -0
  256. package/dist/dashboard/top.js +2 -2
  257. package/dist/dashboard/turns.js +2 -2
  258. package/dist/dashboard/widgets.js +1 -1
  259. package/dist/dashboard/{world-calendar.js → world/calendar.js} +7 -7
  260. package/dist/dashboard/{lore.js → world/known.js} +1 -1
  261. package/dist/dashboard/{world-lore.js → world/lore.js} +9 -9
  262. package/dist/dashboard/{world-map.js → world/map.js} +1 -1
  263. package/dist/dashboard/{world.js → world/world.js} +14 -14
  264. package/dist/dice/evaluate.js +1 -1
  265. package/dist/dice/index.d.ts +2 -2
  266. package/dist/dice/index.js +2 -2
  267. package/dist/dice/notation.d.ts +2 -0
  268. package/dist/dice/notation.js +22 -4
  269. package/dist/documents/markup.js +2 -2
  270. package/dist/documents/read.js +29 -13
  271. package/dist/effects/effect.js +2 -5
  272. package/dist/extensions/extension.js +6 -8
  273. package/dist/extensions/index.d.ts +1 -4
  274. package/dist/extensions/index.js +1 -4
  275. package/dist/extensions/words.js +2 -1
  276. package/dist/{pictures → helpers}/briefs.js +17 -14
  277. package/dist/{pictures → helpers}/claude.js +8 -18
  278. package/dist/{pictures → helpers}/codex.js +3 -15
  279. package/dist/helpers/index.d.ts +7 -0
  280. package/dist/helpers/index.js +9 -0
  281. package/dist/{pictures/helpers.d.ts → helpers/programs.d.ts} +6 -1
  282. package/dist/{pictures/helpers.js → helpers/programs.js} +16 -2
  283. package/dist/images/images.js +7 -5
  284. package/dist/images/index.d.ts +1 -1
  285. package/dist/images/index.js +1 -1
  286. package/dist/importer/index.d.ts +1 -1
  287. package/dist/importer/index.js +1 -1
  288. package/dist/importer/work.d.ts +0 -2
  289. package/dist/importer/work.js +9 -30
  290. package/dist/instructions/index.d.ts +2 -0
  291. package/dist/instructions/index.js +10 -0
  292. package/dist/languages/index.d.ts +1 -1
  293. package/dist/languages/index.js +1 -1
  294. package/dist/languages/language-pack.js +15 -3
  295. package/dist/library/books.js +29 -83
  296. package/dist/{extensions → packages}/engine.d.ts +1 -1
  297. package/dist/{extensions → packages}/engine.js +1 -1
  298. package/dist/packages/index.d.ts +3 -0
  299. package/dist/packages/index.js +4 -0
  300. package/dist/{extensions/packages.d.ts → packages/npm.d.ts} +2 -0
  301. package/dist/{extensions/packages.js → packages/npm.js} +74 -45
  302. package/dist/page.d.ts +9 -11
  303. package/dist/page.js +1 -2
  304. package/dist/pages/check.js +31 -40
  305. package/dist/pages/containers.js +20 -20
  306. package/dist/pages/environment.js +15 -15
  307. package/dist/pages/index.d.ts +9 -9
  308. package/dist/pages/index.js +9 -9
  309. package/dist/pages/inheritance.d.ts +2 -1
  310. package/dist/pages/inheritance.js +24 -24
  311. package/dist/pages/load.js +7 -7
  312. package/dist/pages/maps.d.ts +20 -0
  313. package/dist/pages/maps.js +51 -1
  314. package/dist/pages/markdown.d.ts +2 -0
  315. package/dist/pages/markdown.js +110 -79
  316. package/dist/pages/page-file.d.ts +2 -1
  317. package/dist/pages/page-file.js +31 -29
  318. package/dist/pages/rename-page.d.ts +4 -1
  319. package/dist/pages/rename-page.js +7 -3
  320. package/dist/pages/{stack-entry.d.ts → stacks/entry.d.ts} +0 -2
  321. package/dist/pages/{stack-entry.js → stacks/entry.js} +2 -6
  322. package/dist/pages/{stacks.d.ts → stacks/kinds.d.ts} +8 -1
  323. package/dist/pages/{stacks.js → stacks/kinds.js} +36 -41
  324. package/dist/pages/{stack-writes.d.ts → stacks/writes.d.ts} +2 -2
  325. package/dist/pages/{stack-writes.js → stacks/writes.js} +32 -32
  326. package/dist/pages/system-pages.js +15 -15
  327. package/dist/pages/world.d.ts +4 -0
  328. package/dist/pages/world.js +52 -20
  329. package/dist/pages/write-page.js +35 -34
  330. package/dist/player-notes/index.d.ts +1 -1
  331. package/dist/player-notes/index.js +1 -1
  332. package/dist/rules/page-search.js +3 -4
  333. package/dist/rules/rule-book.js +1 -1
  334. package/dist/rules/search.js +21 -21
  335. package/dist/rules/shown.js +1 -3
  336. package/dist/saves/saves.d.ts +2 -2
  337. package/dist/saves/saves.js +15 -3
  338. package/dist/{bell-listener.js → server/bell-listener.js} +3 -3
  339. package/dist/server/dashboard/files.d.ts +59 -0
  340. package/dist/server/dashboard/files.js +326 -0
  341. package/dist/server/dashboard/index.d.ts +114 -0
  342. package/dist/server/dashboard/index.js +419 -0
  343. package/dist/server/dashboard/news.d.ts +39 -0
  344. package/dist/server/dashboard/news.js +390 -0
  345. package/dist/server/dashboard/player.d.ts +48 -0
  346. package/dist/server/dashboard/player.js +242 -0
  347. package/dist/server/dashboard/ports.d.ts +10 -0
  348. package/dist/server/dashboard/ports.js +15 -0
  349. package/dist/server/dashboard/writes.d.ts +58 -0
  350. package/dist/server/dashboard/writes.js +492 -0
  351. package/dist/{mcp-server.d.ts → server/mcp.d.ts} +2 -2
  352. package/dist/{mcp-server.js → server/mcp.js} +57 -42
  353. package/dist/systems/game-system.d.ts +5 -3
  354. package/dist/systems/game-system.js +178 -149
  355. package/dist/systems/index.d.ts +1 -1
  356. package/dist/systems/index.js +1 -1
  357. package/dist/{testing.d.ts → testing/index.d.ts} +6 -6
  358. package/dist/{testing.js → testing/index.js} +32 -18
  359. package/dist/{system-checks.js → testing/system-checks.js} +18 -12
  360. package/dist/themes/theme.d.ts +3 -3
  361. package/dist/themes/theme.js +14 -14
  362. package/dist/time/calendar.js +5 -2
  363. package/dist/triggers/trigger.js +5 -8
  364. package/instructions/dashboard-guide.md +2 -1
  365. package/instructions/play.md +1 -1
  366. package/package.json +5 -5
  367. package/dist/commands/game-maps.d.ts +0 -20
  368. package/dist/commands/game-maps.js +0 -51
  369. package/dist/commands/game-rules.js +0 -36
  370. package/dist/dashboard-server.d.ts +0 -47
  371. package/dist/dashboard-server.js +0 -1830
  372. package/dist/pictures/index.d.ts +0 -7
  373. package/dist/pictures/index.js +0 -9
  374. /package/dist/{cli.d.ts → cli/cli.d.ts} +0 -0
  375. /package/dist/{library-reader.d.ts → commands/shared/library-reader.d.ts} +0 -0
  376. /package/dist/commands/{notes.d.ts → shared/notes.d.ts} +0 -0
  377. /package/dist/commands/{notes.js → shared/notes.js} +0 -0
  378. /package/dist/dashboard/{guide-markdown.js → help/markdown.js} +0 -0
  379. /package/dist/dashboard/{pack-card.js → packages/card.js} +0 -0
  380. /package/dist/dashboard/{people.js → packages/people.js} +0 -0
  381. /package/dist/dashboard/{place-map.js → place/map.js} +0 -0
  382. /package/dist/dashboard/{calendar.js → world/days.js} +0 -0
  383. /package/dist/{pictures → helpers}/briefs.d.ts +0 -0
  384. /package/dist/{pictures → helpers}/chosen.d.ts +0 -0
  385. /package/dist/{pictures → helpers}/chosen.js +0 -0
  386. /package/dist/{pictures → helpers}/claude.d.ts +0 -0
  387. /package/dist/{pictures → helpers}/codex.d.ts +0 -0
  388. /package/dist/{pictures → helpers}/stop.d.ts +0 -0
  389. /package/dist/{pictures → helpers}/stop.js +0 -0
  390. /package/dist/{pictures → helpers}/svg.d.ts +0 -0
  391. /package/dist/{pictures → helpers}/svg.js +0 -0
  392. /package/dist/{extensions → packages}/tarball.d.ts +0 -0
  393. /package/dist/{extensions → packages}/tarball.js +0 -0
  394. /package/dist/{bell-listener.d.ts → server/bell-listener.d.ts} +0 -0
  395. /package/dist/{player-acts.d.ts → server/player-acts.d.ts} +0 -0
  396. /package/dist/{player-acts.js → server/player-acts.js} +0 -0
  397. /package/dist/{system-checks.d.ts → testing/system-checks.d.ts} +0 -0
@@ -3,6 +3,7 @@
3
3
  import { dirname, join } from "node:path";
4
4
  import { files } from "../core/store.js";
5
5
  import { comparableText, linkTargetName } from "../core/text.js";
6
+ import { inProse } from "./markdown.js";
6
7
  import { changeFields, joinPageFile, readFields, splitPageFile } from "./page-file.js";
7
8
  import { checkPageName, otherPagesWithAlias, pagesWithName, systemPageNamed, textsIn } from "./world.js";
8
9
  /**
@@ -74,17 +75,20 @@ export function applyRename(plan) {
74
75
  throw error;
75
76
  }
76
77
  }
77
- /** A text with its links to a page renamed, [[Lupa]], [[Lupa#Morso]] and [[Lupa|la lupa]] alike, in any case; and how many it renamed. */
78
+ /**
79
+ * A text with its links to a page renamed, [[Lupa]], [[Lupa#Morso]] and [[Lupa|la lupa]] alike, in any case, never in code or in a comment, where there are no
80
+ * links (LNK-2); and how many it renamed.
81
+ */
78
82
  export function renamedLinks(text, from, to) {
79
83
  let count = 0;
80
- const renamed = text.replace(/\[\[([^\][|#^]+?)(\s*[#^][^\][|]*)?(\|[^\][]*)?\]\]/g, (link, name, section, words) => {
84
+ const renamed = inProse(text, (prose) => prose.replace(/\[\[([^\][|#^]+?)(\s*[#^][^\][|]*)?(\|[^\][]*)?\]\]/g, (link, name, section, words) => {
81
85
  // A link with its folder, [[items/Spada.md]], leads to the page as its name alone does (LNK-1).
82
86
  if (comparableText(linkTargetName(name)) !== comparableText(from)) {
83
87
  return link;
84
88
  }
85
89
  count += 1;
86
90
  return `[[${to}${section ?? ""}${words ?? ""}]]`;
87
- });
91
+ }));
88
92
  return { renamed, count };
89
93
  }
90
94
  /** Whether a page's frontmatter can be read. */
@@ -25,8 +25,6 @@ export type EntryReading =
25
25
  };
26
26
  /** How an entry of a container reads (STK-1). */
27
27
  export declare function readEntry(entry: string): EntryReading;
28
- /** Whether an entry is written as a stack, a link to a page and a count (STK-1). */
29
- export declare function isStackEntry(entry: unknown): boolean;
30
28
  /** A stack as the engine writes it: [[Torch]] 7, or [[Torch|torce]] 7 with the label its entry had. */
31
29
  export declare function stackEntry(kind: string, count: number, label?: string): string;
32
30
  /** Whether an entry names this kind, alone or with a count, however its link is written. */
@@ -1,6 +1,6 @@
1
1
  // How an entry of a container reads (STK-1): a link alone, a link with the count of a stack, or something else; and how a stack is written back.
2
- import { comparableText } from "../core/text.js";
3
- import { links } from "./markdown.js";
2
+ import { comparableText } from "../../core/text.js";
3
+ import { links } from "../markdown.js";
4
4
  // A link alone, [[Torch]] or [[Torch|torce]], and a link followed by a count in digits, [[Torch]] 7.
5
5
  const linkAlone = /^\[\[([^\][]+)\]\]$/;
6
6
  const linkAndCount = /^\[\[([^\][]+)\]\][ \t]+(\d+)$/;
@@ -22,10 +22,6 @@ export function readEntry(entry) {
22
22
  }
23
23
  return { shape: "other", page: found[0].page };
24
24
  }
25
- /** Whether an entry is written as a stack, a link to a page and a count (STK-1). */
26
- export function isStackEntry(entry) {
27
- return typeof entry === "string" && readEntry(entry).shape === "stack";
28
- }
29
25
  /** A stack as the engine writes it: [[Torch]] 7, or [[Torch|torce]] 7 with the label its entry had. */
30
26
  export function stackEntry(kind, count, label) {
31
27
  const shown = label === undefined || comparableText(label) === comparableText(kind) ? "" : `|${label}`;
@@ -1,4 +1,4 @@
1
- import { type Page, type World } from "./world.ts";
1
+ import { type Page, type World } from "../world.ts";
2
2
  /** A stack in a container (STK-1, STK-3): its kind, its count summed over the entries that name it, and the label of the first. */
3
3
  export interface Stack {
4
4
  kind: Page;
@@ -38,6 +38,11 @@ export declare function heldStacks(world: World, holder: Page, kind: Page): Held
38
38
  export declare function heldStacksOfKind(world: World, holder: Page, kind: Page): HeldStack[];
39
39
  /** Whether a character carries some of a kind, in its own list or inside what it carries (STK-11). */
40
40
  export declare function carriesKind(world: World, character: Page, kind: Page): boolean;
41
+ /**
42
+ * Whether a holder carries a thing by a name, in its own list or inside what it carries: an item, a copy by its base, a stack by its kind, or text as on a paper
43
+ * sheet, its count aside; the names compared by same.
44
+ */
45
+ export declare function carriesNamed(world: World, holder: Page, name: string, same: (one: string, other: string) => boolean): boolean;
41
46
  /**
42
47
  * The kind a name means for a holder (STK-4): a kind by its name or alias, or the label of an entry of the holder or of the items it holds, as torce for [[Torch|torce]] 7;
43
48
  * undefined when it means none.
@@ -50,3 +55,5 @@ export declare function kindNamed(world: World, holder: Page | undefined, name:
50
55
  export declare function goodsNamed(world: World, name: string): Page | undefined;
51
56
  /** The name a kind goes by in a stack: its label, else its own name (STK-12). */
52
57
  export declare function stackName(stack: Stack): string;
58
+ /** The page a name means, or undefined when it means none or two pages share it. */
59
+ export declare function pageNamedQuietly(world: World, name: string): Page | undefined;
@@ -1,10 +1,10 @@
1
1
  // The stacks of goods (D-429, STK-1–STK-4): which items are kinds, what a container counts of each, and which stack a holder means.
2
- import { comparableText, withArticle } from "../core/text.js";
3
- import { baseChain, inheritedFields } from "./inheritance.js";
4
- import { readEntry } from "./stack-entry.js";
5
- import { containerFieldOf } from "./standard-fields.js";
6
- import { alwaysInList, isDeclaredUncounted } from "./system-pages.js";
7
- import { heldNames, isCountedItem, pageNamed, pagesWithName, systemPageNamed, textsIn, validHoldersOf } from "./world.js";
2
+ import { comparableText, withArticle } from "../../core/text.js";
3
+ import { baseChain, inheritedFields } from "../inheritance.js";
4
+ import { containerFieldOf } from "../standard-fields.js";
5
+ import { alwaysInList, isDeclaredUncounted } from "../system-pages.js";
6
+ import { heldNames, isCountedItem, pageNamed, pagesWithName, systemPageNamed, textsIn, validHoldersOf } from "../world.js";
7
+ import { countedText, readEntry } from "./entry.js";
8
8
  // A counter with a maximum, as uses: 10/10: what a thing of its own spends, which a stack cannot keep (STK-1).
9
9
  const usesPattern = /^\s*-?\d+\s*\/\s*\d+\s*$/;
10
10
  /**
@@ -75,22 +75,10 @@ export function heldStacks(world, holder, kind) {
75
75
  if (own !== undefined) {
76
76
  return [{ container: holder, stack: own }];
77
77
  }
78
- const found = [];
79
- const seen = new Set([holder]);
80
- let level = itemsHeldBy(world, holder);
81
- while (level.length > 0) {
82
- const next = [];
83
- for (const item of level.filter((page) => !seen.has(page))) {
84
- seen.add(item);
85
- const stack = ownStack(world, item, kind);
86
- if (stack !== undefined) {
87
- found.push({ container: item, stack });
88
- }
89
- next.push(...itemsHeldBy(world, item));
90
- }
91
- level = next;
92
- }
93
- return found;
78
+ return itemsWithin(world, holder).flatMap((item) => {
79
+ const stack = ownStack(world, item, kind);
80
+ return stack === undefined ? [] : [{ container: item, stack }];
81
+ });
94
82
  }
95
83
  /**
96
84
  * The stacks a holder keeps of a kind or of a kind that derives from it, as the campaign's Razioni from the system's Rations (UPK-1): its own first, then
@@ -98,25 +86,22 @@ export function heldStacks(world, holder, kind) {
98
86
  */
99
87
  export function heldStacksOfKind(world, holder, kind) {
100
88
  const derives = (candidate) => candidate === kind || baseChain(world, candidate).includes(kind);
101
- const own = stacksOf(world, holder).filter((stack) => derives(stack.kind)).map((stack) => ({ container: holder, stack }));
102
- const found = [...own];
103
- const seen = new Set([holder]);
104
- let level = itemsHeldBy(world, holder);
105
- while (level.length > 0) {
106
- const next = [];
107
- for (const item of level.filter((page) => !seen.has(page))) {
108
- seen.add(item);
109
- found.push(...stacksOf(world, item).filter((stack) => derives(stack.kind)).map((stack) => ({ container: item, stack })));
110
- next.push(...itemsHeldBy(world, item));
111
- }
112
- level = next;
113
- }
114
- return found;
89
+ return [holder, ...itemsWithin(world, holder)].flatMap((container) => stacksOf(world, container).filter((stack) => derives(stack.kind)).map((stack) => ({ container, stack })));
115
90
  }
116
91
  /** Whether a character carries some of a kind, in its own list or inside what it carries (STK-11). */
117
92
  export function carriesKind(world, character, kind) {
118
93
  return heldStacks(world, character, kind).length > 0;
119
94
  }
95
+ /**
96
+ * Whether a holder carries a thing by a name, in its own list or inside what it carries: an item, a copy by its base, a stack by its kind, or text as on a paper
97
+ * sheet, its count aside; the names compared by same.
98
+ */
99
+ export function carriesNamed(world, holder, name, same) {
100
+ return [holder, ...itemsWithin(world, holder)].some((container) => {
101
+ const field = containerFieldOf(container.type);
102
+ return (field === undefined ? [] : textsIn(container.fields[field])).some((entry) => entryNames(world, entry).some((one) => same(one, name)));
103
+ });
104
+ }
120
105
  /**
121
106
  * The kind a name means for a holder (STK-4): a kind by its name or alias, or the label of an entry of the holder or of the items it holds, as torce for [[Torch|torce]] 7;
122
107
  * undefined when it means none.
@@ -136,21 +121,31 @@ export function kindNamed(world, holder, name) {
136
121
  export function goodsNamed(world, name) {
137
122
  const spoken = name.trim().replace(/[-_]/g, " ");
138
123
  const names = [...new Set([spoken, spoken.replace(/es$/i, ""), spoken.replace(/s$/i, "")])];
139
- return names.map((candidate) => quietly(() => pageNamed(world, candidate))).find((page) => page !== undefined && (isKind(world, page) || canCount(world, page)));
124
+ return names.map((candidate) => pageNamedQuietly(world, candidate)).find((page) => page !== undefined && (isKind(world, page) || canCount(world, page)));
140
125
  }
141
126
  /** The name a kind goes by in a stack: its label, else its own name (STK-12). */
142
127
  export function stackName(stack) {
143
128
  return stack.label ?? stack.kind.name;
144
129
  }
145
- /** What a lookup gives, or undefined when it stops at a name two pages share. */
146
- function quietly(find) {
130
+ /** The page a name means, or undefined when it means none or two pages share it. */
131
+ export function pageNamedQuietly(world, name) {
147
132
  try {
148
- return find();
133
+ return pageNamed(world, name);
149
134
  }
150
135
  catch {
151
136
  return undefined;
152
137
  }
153
138
  }
139
+ /** The names an entry of a container goes by: its page's, its bases' and its label; text by itself, its count aside. */
140
+ function entryNames(world, entry) {
141
+ const read = readEntry(entry);
142
+ if (read.shape === "text") {
143
+ return [countedText(entry)?.name ?? entry.trim()];
144
+ }
145
+ const page = entryPage(world, read.page);
146
+ const label = "label" in read && read.label !== undefined ? [read.label] : [];
147
+ return [...(page === undefined ? [read.page] : [page, ...baseChain(world, page)].map((one) => one.name)), ...label];
148
+ }
154
149
  /** The items a container holds as pages, those whose first container it is (CON-3). */
155
150
  function itemsHeldBy(world, container) {
156
151
  return heldNames(container).flatMap((name) => pagesWithName(world, name).slice(0, 1)).filter((page) => page.type === "item" && validHoldersOf(world, page)[0] === container);
@@ -160,7 +155,7 @@ function itemsWithin(world, container) {
160
155
  const found = [];
161
156
  let level = itemsHeldBy(world, container);
162
157
  while (level.length > 0) {
163
- const fresh = level.filter((page) => page !== container && !found.includes(page));
158
+ const fresh = level.filter((page, index) => page !== container && !found.includes(page) && level.indexOf(page) === index);
164
159
  found.push(...fresh);
165
160
  level = fresh.flatMap((page) => itemsHeldBy(world, page));
166
161
  }
@@ -1,5 +1,5 @@
1
- import { type Page, type World } from "./world.ts";
2
- import type { PageChange } from "./write-page.ts";
1
+ import { type Page, type World } from "../world.ts";
2
+ import type { PageChange } from "../write-page.ts";
3
3
  /**
4
4
  * A stack's count changes with change, never with write (STK-10): adding a kind the container counts already is refused, and so is taking away a stack by another count
5
5
  * than its own, each with the change that does it.
@@ -1,10 +1,10 @@
1
1
  // What write may do to the stacks of a container's list (STK-10): count only kinds, one stack of each, whose counts change only with change.
2
- import { comparableText } from "../core/text.js";
3
- import { bundleOf } from "./load.js";
4
- import { countedText, countOf, readEntry } from "./stack-entry.js";
5
- import { canCount, entryKind, entryPage, goodsNamed, isKind, notKindReason, stacksOf } from "./stacks.js";
6
- import { containerFieldOf } from "./standard-fields.js";
7
- import { pageNamed, searchSystemPages, textsIn, validHoldersOf } from "./world.js";
2
+ import { comparableText } from "../../core/text.js";
3
+ import { bundleOf } from "../load.js";
4
+ import { containerFieldOf } from "../standard-fields.js";
5
+ import { pageNamed, searchSystemPages, textsIn, validHoldersOf } from "../world.js";
6
+ import { countedText, countOf, readEntry } from "./entry.js";
7
+ import { canCount, entryKind, entryPage, goodsNamed, isKind, notKindReason, stacksOf } from "./kinds.js";
8
8
  /**
9
9
  * A stack's count changes with change, never with write (STK-10): adding a kind the container counts already is refused, and so is taking away a stack by another count
10
10
  * than its own, each with the change that does it.
@@ -65,6 +65,32 @@ export function checkStacks(world, holder, field, before, after) {
65
65
  }
66
66
  }
67
67
  }
68
+ /**
69
+ * What a count beside a link to no page means (STK-10): a name of a kind, as Arrows (20), in its units; else the system's kinds go by their English names, and a word
70
+ * of the campaign's language is their label, as [[Torch|torcia]] 3; only what the system lacks becomes a kind of the campaign. Said by write and validate.
71
+ */
72
+ export function missingKindMessage(world, holder, field, read) {
73
+ const named = goodsNamed(world, read.page);
74
+ if (named !== undefined) {
75
+ const bundle = bundleOf(world.system?.load?.bundle, named);
76
+ const pieces = read.count * bundle;
77
+ const unit = bundle > 1 ? `counted in pieces, ${bundle} for each bought` : "counted in the units the system sells it in";
78
+ return `There is no page named ${read.page}, but it is a name of ${named.name}, ${unit}: write ${holder.name}, add ${field}="[[${named.name}]] ${pieces}".`;
79
+ }
80
+ const campaignKind = `Only what the system lacks becomes a kind of the campaign, written first: write "${read.page}", type item.`;
81
+ const near = goodsLike(world, read.page);
82
+ if (near.length > 0) {
83
+ return `There is no page named ${read.page}, so [[${read.page}]] ${read.count} counts nothing. The system has ${near.map((page) => page.name).join(", ")}: if it is one of them, `
84
+ + `write ${holder.name}, add ${field}="[[${near[0].name}]] ${read.count}". ${campaignKind}`;
85
+ }
86
+ return `There is no page named ${read.page}, so [[${read.page}]] ${read.count} counts nothing. The system's kinds go by their English names, as find shows them: write the one it has `
87
+ + `with your word as its label, such as write ${holder.name}, add ${field}="[[Torch|${read.page.toLowerCase()}]] ${read.count}". ${campaignKind}`;
88
+ }
89
+ /** Whether a name leads to a kind, counted as a stack of 1 when its link stands alone (STK-1). */
90
+ export function isKindNamed(world, name) {
91
+ const page = entryPage(world, name);
92
+ return page !== undefined && isKind(world, page);
93
+ }
68
94
  /** A count beside a link counts only a kind (STK-1, STK-10): never a page with a story of its own, nor one that is not there, which the message tells how to find or make. */
69
95
  function checkCounted(world, holder, field, read, page) {
70
96
  if (page === undefined) {
@@ -87,27 +113,6 @@ function checkCountedText(world, holder, field, entry) {
87
113
  throw new Error(`"${entry}" is a count inside a text: write ${holder.name}, add ${field}="[[${page.name}]] ${counted.count}", a stack of ${page.name}. Nothing changed.`);
88
114
  }
89
115
  }
90
- /**
91
- * What a count beside a link to no page means (STK-10): a name of a kind, as Arrows (20), in its units; else the system's kinds go by their English names, and a word
92
- * of the campaign's language is their label, as [[Torch|torcia]] 3; only what the system lacks becomes a kind of the campaign. Said by write and validate.
93
- */
94
- export function missingKindMessage(world, holder, field, read) {
95
- const named = goodsNamed(world, read.page);
96
- if (named !== undefined) {
97
- const bundle = bundleOf(world.system?.load?.bundle, named);
98
- const pieces = read.count * bundle;
99
- const unit = bundle > 1 ? `counted in pieces, ${bundle} for each bought` : "counted in the units the system sells it in";
100
- return `There is no page named ${read.page}, but it is a name of ${named.name}, ${unit}: write ${holder.name}, add ${field}="[[${named.name}]] ${pieces}".`;
101
- }
102
- const campaignKind = `Only what the system lacks becomes a kind of the campaign, written first: write "${read.page}", type item.`;
103
- const near = goodsLike(world, read.page);
104
- if (near.length > 0) {
105
- return `There is no page named ${read.page}, so [[${read.page}]] ${read.count} counts nothing. The system has ${near.map((page) => page.name).join(", ")}: if it is one of them, `
106
- + `write ${holder.name}, add ${field}="[[${near[0].name}]] ${read.count}". ${campaignKind}`;
107
- }
108
- return `There is no page named ${read.page}, so [[${read.page}]] ${read.count} counts nothing. The system's kinds go by their English names, as find shows them: write the one it has `
109
- + `with your word as its label, such as write ${holder.name}, add ${field}="[[Torch|${read.page.toLowerCase()}]] ${read.count}". ${campaignKind}`;
110
- }
111
116
  /** The system's goods whose names hold a word, the shortest first, as Arrows for Arrow: for a refusal to name them, which saves a find (STK-10). */
112
117
  function goodsLike(world, word) {
113
118
  const named = searchSystemPages(world, { text: word, type: "item" }).filter((match) => match.excerpt === undefined && canCount(world, match.page)).map((match) => match.page);
@@ -122,8 +127,3 @@ function kindOfEntry(world) {
122
127
  return counted && page !== undefined ? [page.name] : [];
123
128
  };
124
129
  }
125
- /** Whether a name leads to a kind, counted as a stack of 1 when its link stands alone (STK-1). */
126
- export function isKindNamed(world, name) {
127
- const page = entryPage(world, name);
128
- return page !== undefined && isKind(world, page);
129
- }
@@ -13,21 +13,6 @@ export function declaredKind(world, field) {
13
13
  const fields = world.system?.fields;
14
14
  return fields === undefined ? undefined : kindsOf(fields).get(comparableText(field));
15
15
  }
16
- /** The kinds a system declares, by the name as it is compared, the first written winning: built once for each system, as every field read asks (D-194). */
17
- function kindsOf(fields) {
18
- let kinds = kindsByFields.get(fields);
19
- if (kinds === undefined) {
20
- kinds = new Map();
21
- for (const [name, kind] of Object.entries(fields)) {
22
- if (!kinds.has(comparableText(name))) {
23
- kinds.set(comparableText(name), kind);
24
- }
25
- }
26
- kindsByFields.set(fields, kinds);
27
- }
28
- return kinds;
29
- }
30
- const kindsByFields = new WeakMap();
31
16
  /** Whether the game system declares a field as something never counted: a number, text or a list, such as cr 1/4 or cost 15 gp (SYS-8). */
32
17
  export function isDeclaredUncounted(world, field) {
33
18
  const kind = declaredKind(world, field);
@@ -102,3 +87,18 @@ export function kindMessage(page) {
102
87
  return `${page.name} is ${systemLabel(page)}, a kind and read-only: one in a fight is a copy, brought in with scene, creatures ${page.name}=1; `
103
88
  + `one with a name of its own is a character with creature=[[${page.name}]].`;
104
89
  }
90
+ /** The kinds a system declares, by the name as it is compared, the first written winning: built once for each system, as every field read asks (D-194). */
91
+ function kindsOf(fields) {
92
+ let kinds = kindsByFields.get(fields);
93
+ if (kinds === undefined) {
94
+ kinds = new Map();
95
+ for (const [name, kind] of Object.entries(fields)) {
96
+ if (!kinds.has(comparableText(name))) {
97
+ kinds.set(comparableText(name), kind);
98
+ }
99
+ }
100
+ kindsByFields.set(fields, kinds);
101
+ }
102
+ return kinds;
103
+ }
104
+ const kindsByFields = new WeakMap();
@@ -16,6 +16,10 @@ export interface Page {
16
16
  body: string;
17
17
  /** The game system the page comes from, such as 5e: read-only, and nowhere (SYS-2). Undefined for the campaign's own pages. */
18
18
  system?: string;
19
+ /** A system page's name in the campaign's language, from the system's translation (D-542), as Palla di fuoco for Fireball; links still use its name. */
20
+ title?: string;
21
+ /** A system page's text in the campaign's language, for who reads it (D-542); `body` stays the system's, which the sheet's features are read from. */
22
+ translated?: string;
19
23
  }
20
24
  /** Every page of a campaign, read from its world folder, and the pages of its game system. */
21
25
  export interface World {
@@ -1,11 +1,12 @@
1
1
  import { basename, join, relative, resolve, sep } from "node:path";
2
+ import { translationFolder } from "../core/files.js";
2
3
  import { frozen } from "../core/frozen.js";
3
4
  import { files } from "../core/store.js";
4
5
  import { comparableText, valueNamed } from "../core/text.js";
5
- import { linkedPages } from "./markdown.js";
6
+ import { linkedPages, links } from "./markdown.js";
6
7
  import { readFields, splitPageFile } from "./page-file.js";
7
8
  import { pageTypes, typeOfFolder, worldFolderName } from "./page-types.js";
8
- import { readEntry } from "./stack-entry.js";
9
+ import { readEntry } from "./stacks/entry.js";
9
10
  import { canHold, containerFieldOf } from "./standard-fields.js";
10
11
  const forbiddenCharacters = /[\\/:*?"<>|#^[\]\u0000-\u001f]/;
11
12
  const longestName = 120;
@@ -29,7 +30,8 @@ export function loadWorld(root, options = {}) {
29
30
  if (system === undefined) {
30
31
  return frozen({ root, ...campaign, language, missingSystem, noSystem, ...(rigor === undefined ? {} : { rigor }) });
31
32
  }
32
- const systemPages = system.version === undefined ? packagePages(system.folder, system.name) : versionPages(packagePages(system.folder, system.name), packagePages(system.version.folder, system.name));
33
+ const read = (folder) => translatedPages(packagePages(folder, system.name), folder, system.name, language);
34
+ const systemPages = system.version === undefined ? read(system.folder) : versionPages(read(system.folder), read(system.version.folder));
33
35
  const { name, title, fields, formulas, progression, itemFormulas, alwaysIn, uses, statusLine, load, lengthUnit, bonusLists, bonusWhile } = system;
34
36
  const problems = [...campaign.problems, ...systemPages.problems];
35
37
  return frozen({
@@ -301,6 +303,12 @@ export function checkPageName(name) {
301
303
  if (name === "" || name.length > longestName || name.trim() !== name || name.endsWith(".") || forbiddenCharacters.test(name)) {
302
304
  throw new Error(`"${name}" cannot be a page name. Names become file names and links: at most ${longestName} characters, without \\ / : * ? " < > | # ^ [ ], line breaks, spaces at the ends or a final dot.`);
303
305
  }
306
+ // A name that ends as a file does, as Bruna.md or Mappa.png, makes a page no link reaches (LNK-1).
307
+ if (links(`[[${name}]]`)[0]?.page !== name) {
308
+ const ending = /\.[a-z0-9]+$/i.test(name);
309
+ const remedy = ending ? `Give the name without its file ending, as "${name.replace(/\.[a-z0-9]+$/i, "")}".` : "Give the name without ` or %%, which make code and comments.";
310
+ throw new Error(`"${name}" cannot be a page name: a link to it would not reach it. ${remedy}`);
311
+ }
304
312
  }
305
313
  /** Reads one page file of the campaign in `root`, once in a call (D-194). */
306
314
  export function readPage(root, fullPath) {
@@ -310,6 +318,22 @@ export function readPage(root, fullPath) {
310
318
  }
311
319
  return page;
312
320
  }
321
+ /** The page whose file in a folder's world/ is named `name`, with the type its folder gives, found by the file's name alone without reading the pages: enough to say that a page is there. */
322
+ export function pageFileNamed(root, name) {
323
+ const worldPath = join(root, worldFolderName);
324
+ const wanted = comparableText(name.trim());
325
+ const file = files().files(worldPath, (candidate) => /\.md$/i.test(candidate) && comparableText(candidate.slice(0, -3)) === wanted)[0];
326
+ return file === undefined ? undefined : { name: basename(file).slice(0, -3), type: typeOfFolder(relative(worldPath, file).split(sep)[0]) };
327
+ }
328
+ /** The pages of the system's bonus lists a page names (FOR-5, D-449): an attuned ring, a feat; of a list given only while in another, only those in it too, as a ring worn (BND-4). */
329
+ export function bonusPages(world, fields) {
330
+ return (world.system?.bonusLists ?? []).flatMap((list) => {
331
+ const named = linksIn(valueNamed(fields, list));
332
+ const whileIn = world.system?.bonusWhile?.[list];
333
+ const held = whileIn === undefined ? undefined : linksIn(valueNamed(fields, whileIn)).map(comparableText);
334
+ return named.filter((name) => held === undefined || held.includes(comparableText(name))).flatMap((name) => findPage(world, name) ?? []);
335
+ });
336
+ }
313
337
  /** The page that the text of a file in `root` writes. */
314
338
  function pageOf(root, fullPath, text) {
315
339
  const path = relative(root, fullPath).split(sep).join("/");
@@ -323,14 +347,6 @@ function pageOf(root, fullPath, text) {
323
347
  body: file.body,
324
348
  };
325
349
  }
326
- /** The page whose file in a folder's world/ is named `name`, with the type its folder gives, found by the file's name alone without reading the pages: enough to say that a page is there. */
327
- export function pageFileNamed(root, name) {
328
- const worldPath = join(root, worldFolderName);
329
- const wanted = comparableText(name.trim());
330
- const file = files().files(worldPath, (candidate) => /\.md$/i.test(candidate) && comparableText(candidate.slice(0, -3)) === wanted)[0];
331
- return file === undefined ? undefined : { name: basename(file).slice(0, -3), type: typeOfFolder(relative(worldPath, file).split(sep)[0]) };
332
- }
333
- /** The pages of a folder's world/, each marked with the game system it comes from, if any; a file that cannot be read is a problem, and the others still work. */
334
350
  /**
335
351
  * The pages of a game system, read once in a process: they ship with the package and are read-only, so a running server keeps those it started with, as a
336
352
  * change to a system asks for a reconnection (D-194).
@@ -342,12 +358,37 @@ function packagePages(folder, system) {
342
358
  return known;
343
359
  }
344
360
  const packages = new Map();
361
+ /**
362
+ * A system's pages with their text and their name in the campaign's language beside their own, where the system has a translation of them in it, by the same
363
+ * path under translations/<language> (D-542); their fields and text stay, which the engine reads. Read once in a process, as the pages are.
364
+ */
365
+ function translatedPages(read, folder, system, language) {
366
+ const translations = translationFolder(folder, language);
367
+ if (translations === undefined) {
368
+ return read;
369
+ }
370
+ const key = `${translations}|${system}`;
371
+ const known = translated.get(key) ?? withTranslations(read, readPages(translations, system));
372
+ translated.set(key, known);
373
+ return known;
374
+ }
375
+ const translated = new Map();
376
+ function withTranslations(read, translations) {
377
+ const byPath = new Map(translations.pages.map((page) => [page.path, page]));
378
+ const pages = read.pages.map((page) => {
379
+ const other = byPath.get(page.path);
380
+ const title = typeof other?.fields.name === "string" && other.fields.name.trim() !== "" ? other.fields.name.trim() : undefined;
381
+ return other === undefined ? page : frozen({ ...page, translated: other.body, ...(title === undefined ? {} : { title }) });
382
+ });
383
+ return { pages, problems: [...read.problems, ...translations.problems] };
384
+ }
345
385
  /** A system's pages with those of the version of its rules over them (VER-3): a page of the version takes the place of a common one with its name. */
346
386
  function versionPages(common, version) {
347
387
  const names = new Set(version.pages.map((page) => comparableText(page.name)));
348
388
  const pages = [...common.pages.filter((page) => !names.has(comparableText(page.name))), ...version.pages].sort((first, second) => (first.path < second.path ? -1 : 1));
349
389
  return { pages, problems: [...common.problems, ...version.problems] };
350
390
  }
391
+ /** The pages of a folder's world/, each marked with the game system it comes from, if any; a file that cannot be read is a problem, and the others still work. */
351
392
  function readPages(root, system) {
352
393
  const pages = [];
353
394
  const problems = [];
@@ -399,12 +440,3 @@ function textExcerpt(page, text) {
399
440
  function shorten(text) {
400
441
  return text.length > 120 ? `${text.slice(0, 119)}…` : text;
401
442
  }
402
- /** The pages of the system's bonus lists a page names (FOR-5, D-449): an attuned ring, a feat; of a list given only while in another, only those in it too, as a ring worn (BND-4). */
403
- export function bonusPages(world, fields) {
404
- return (world.system?.bonusLists ?? []).flatMap((list) => {
405
- const named = linksIn(valueNamed(fields, list));
406
- const whileIn = world.system?.bonusWhile?.[list];
407
- const held = whileIn === undefined ? undefined : linksIn(valueNamed(fields, whileIn)).map(comparableText);
408
- return named.filter((name) => held === undefined || held.includes(comparableText(name))).flatMap((name) => findPage(world, name) ?? []);
409
- });
410
- }
@@ -2,12 +2,12 @@ import { join } from "node:path";
2
2
  import { files } from "../core/store.js";
3
3
  import { comparableText, withArticle } from "../core/text.js";
4
4
  import { holdRefusal } from "./containers.js";
5
- import { baseChain, baseValue, derivedPages, ownFieldChange, sameAsBase } from "./inheritance.js";
5
+ import { baseChain, baseFieldOf, baseValue, derivedPages, ownFieldChange, sameAsBase } from "./inheritance.js";
6
6
  import { introductionText, partContent, readSection, repeatedNames, secretNames, sectionTitles, writeText } from "./markdown.js";
7
7
  import { changeFields, holdsNestedList, joinPageFile, readFields, splitPageFile } from "./page-file.js";
8
8
  import { pageTypeNames, pageTypes, worldFolderName } from "./page-types.js";
9
- import { checkStackEdits, checkStacks, isKindNamed } from "./stack-writes.js";
10
- import { isKind, notKindReason } from "./stacks.js";
9
+ import { isKind, notKindReason } from "./stacks/kinds.js";
10
+ import { checkStackEdits, checkStacks, isKindNamed } from "./stacks/writes.js";
11
11
  import { canHold, checkStandardFields, containerFieldOf, containerFields, isFieldName, isStandardField, misspelledStandardField, newPageFields } from "./standard-fields.js";
12
12
  import { alwaysInList, alwaysInMessage, heldSystemPageMessage, hidingMessage, readOnlyMessage, systemLabel } from "./system-pages.js";
13
13
  import { checkPageName, findPage, heldNames, holdersOf, isCountedItem, linksIn, locate, readPage, validHoldersOf, withPage } from "./world.js";
@@ -57,6 +57,35 @@ export function writePage(world, name, type, requested) {
57
57
  }
58
58
  return { page: readPage(world.root, fullPath), created: existing === undefined, changed: true, mode, retyped };
59
59
  }
60
+ /** Checks the fields of a change on a page of a type: names a field can have, no list inside a list, and each field given once. Items may be added to a list and removed from it together. */
61
+ export function checkFieldChange(type, change) {
62
+ for (const name of [...Object.keys(change.set ?? {}), ...Object.keys(change.add ?? {})]) {
63
+ if (!isFieldName(name)) {
64
+ throw new Error(`"${name}" cannot be a field name: start with a letter, and use only letters, digits, - and _.`);
65
+ }
66
+ }
67
+ for (const [name, value] of [...Object.entries(change.set ?? {}), ...Object.entries(change.add ?? {})]) {
68
+ if (holdsNestedList(value)) {
69
+ throw new Error(`"${name}" would hold a list inside a list, which a field cannot hold. Give a list of links or text, such as ["[[A]]", "[[B]]"].`);
70
+ }
71
+ }
72
+ const set = Object.keys(change.set ?? {});
73
+ const unset = change.unset ?? [];
74
+ // Removing a field in two spellings removes both, as written: only giving a value twice is unclear.
75
+ for (const names of [set, Object.keys(change.add ?? {}), Object.keys(change.remove ?? {})]) {
76
+ const [repeated] = repeatedFieldNames(type, names);
77
+ if (repeated !== undefined) {
78
+ throw new Error(`The field ${repeated} is given twice: give each field once.`);
79
+ }
80
+ }
81
+ // A list changed item by item counts once, however many items are added and removed; so does a field removed in several spellings.
82
+ const lists = new Map([...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})].map((name) => [fieldKey(type, name), name]));
83
+ const removed = new Map(unset.map((name) => [fieldKey(type, name), name]));
84
+ const [twice] = repeatedFieldNames(type, [...set, ...removed.values(), ...lists.values()]);
85
+ if (twice !== undefined) {
86
+ throw new Error(`The field ${twice} is given in two ways (set, unset, or add and remove): give it in one.`);
87
+ }
88
+ }
60
89
  /**
61
90
  * A page changes type only when it still fits where it is and what it holds still fits in it (CON-1, D-159); a creature that pages derive from keeps its type,
62
91
  * or they would derive from nothing (INH-2).
@@ -118,10 +147,11 @@ function withoutBaseValues(world, existing, page, changed, frontmatter) {
118
147
  if (changed.length === 0) {
119
148
  return frontmatter;
120
149
  }
121
- // When the creature changes, every value the page holds is checked against the new one.
150
+ // When the base changes, its creature or its item, every value the page holds is checked against the new one.
122
151
  const written = { name: existing?.name ?? page.name, type: existing?.type ?? page.type, path: page.path, fields: readFields(frontmatter, page.path), body: "" };
123
152
  const now = withPage(world, existing, written);
124
- const checked = changed.some((field) => comparableText(field) === "creature") ? Object.keys(written.fields) : changed;
153
+ const base = baseFieldOf(written.type);
154
+ const checked = base !== undefined && changed.some((field) => comparableText(field) === base) ? Object.keys(written.fields) : changed;
125
155
  const same = checked.filter((field) => Object.hasOwn(written.fields, field) && sameAsBase(now, written, field));
126
156
  return same.length === 0 ? frontmatter : changeFields(frontmatter, { unset: same }, page.path);
127
157
  }
@@ -181,35 +211,6 @@ function checkUnset(world, existing, requested, written) {
181
211
  }
182
212
  });
183
213
  }
184
- /** Checks the fields of a change on a page of a type: names a field can have, no list inside a list, and each field given once. Items may be added to a list and removed from it together. */
185
- export function checkFieldChange(type, change) {
186
- for (const name of [...Object.keys(change.set ?? {}), ...Object.keys(change.add ?? {})]) {
187
- if (!isFieldName(name)) {
188
- throw new Error(`"${name}" cannot be a field name: start with a letter, and use only letters, digits, - and _.`);
189
- }
190
- }
191
- for (const [name, value] of [...Object.entries(change.set ?? {}), ...Object.entries(change.add ?? {})]) {
192
- if (holdsNestedList(value)) {
193
- throw new Error(`"${name}" would hold a list inside a list, which a field cannot hold. Give a list of links or text, such as ["[[A]]", "[[B]]"].`);
194
- }
195
- }
196
- const set = Object.keys(change.set ?? {});
197
- const unset = change.unset ?? [];
198
- // Removing a field in two spellings removes both, as written: only giving a value twice is unclear.
199
- for (const names of [set, Object.keys(change.add ?? {}), Object.keys(change.remove ?? {})]) {
200
- const [repeated] = repeatedFieldNames(type, names);
201
- if (repeated !== undefined) {
202
- throw new Error(`The field ${repeated} is given twice: give each field once.`);
203
- }
204
- }
205
- // A list changed item by item counts once, however many items are added and removed; so does a field removed in several spellings.
206
- const lists = new Map([...Object.keys(change.add ?? {}), ...Object.keys(change.remove ?? {})].map((name) => [fieldKey(type, name), name]));
207
- const removed = new Map(unset.map((name) => [fieldKey(type, name), name]));
208
- const [twice] = repeatedFieldNames(type, [...set, ...removed.values(), ...lists.values()]);
209
- if (twice !== undefined) {
210
- throw new Error(`The field ${twice} is given in two ways (set, unset, or add and remove): give it in one.`);
211
- }
212
- }
213
214
  /** The names that give the same field more than once. */
214
215
  function repeatedFieldNames(type, names) {
215
216
  const keys = names.map((name) => fieldKey(type, name));
@@ -1 +1 @@
1
- export { type Note, playerFolderName, readNotes, removeNote, writeNote } from "./notes.ts";
1
+ export { type Note, readNotes, removeNote, writeNote } from "./notes.ts";
@@ -1,2 +1,2 @@
1
1
  // The player's notes (D-371), outside the game.
2
- export { playerFolderName, readNotes, removeNote, writeNote } from "./notes.js";
2
+ export { readNotes, removeNote, writeNote } from "./notes.js";
@@ -1,3 +1,4 @@
1
+ import { wordCount } from "../core/text.js";
1
2
  import { sameWord, searchWords } from "./search.js";
2
3
  /**
3
4
  * The pages a text finds, best first (LIB-6): as BM25 counts them, a word weighing more the fewer pages have it and the more a page repeats it for its length;
@@ -110,6 +111,7 @@ const lengthWeight = 0.75;
110
111
  const longestTitle = 60;
111
112
  const mostTitleWords = 6;
112
113
  const fewestTitleLetters = 4;
114
+ const titleLetters = new RegExp(`\\p{L}{${fewestTitleLetters}}`, "u");
113
115
  const fewestWords = 60;
114
116
  // A line on this many pages of a book or more, and on one in fifty, is the page's running head, never a title.
115
117
  const runningPages = 3;
@@ -155,7 +157,7 @@ function titleLines(lines, running) {
155
157
  const capitals = trimmed.match(/\p{Lu}/gu)?.length ?? 0;
156
158
  const short = trimmed.length <= longestTitle && trimmed.split(/\s+/).length <= mostTitleWords;
157
159
  const goesOn = /^\s*\p{Ll}/u.test(lines[index + 1] ?? "");
158
- return short && cased >= 3 && capitals >= cased * 0.7 && new RegExp(`\\p{L}{${fewestTitleLetters}}`, "u").test(trimmed) && !goesOn && !running.has(lineKey(trimmed));
160
+ return short && cased >= 3 && capitals >= cased * 0.7 && titleLetters.test(trimmed) && !goesOn && !running.has(lineKey(trimmed));
159
161
  });
160
162
  }
161
163
  /**
@@ -211,6 +213,3 @@ function headingAbove(headings, line) {
211
213
  }
212
214
  return undefined;
213
215
  }
214
- function wordCount(text) {
215
- return text.split(/\s+/).filter((word) => word !== "").length;
216
- }