rpg-engine 0.5.0 → 0.6.1
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.
- package/dist/campaign/settings.d.ts +1 -0
- package/dist/campaign/settings.js +6 -5
- package/dist/command-line.js +12 -5
- package/dist/commands/advance.js +1 -1
- package/dist/commands/ask.d.ts +1 -1
- package/dist/commands/ask.js +66 -24
- package/dist/commands/change.js +28 -17
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +67 -21
- package/dist/commands/effect.js +42 -23
- package/dist/commands/find.js +1 -1
- package/dist/commands/game-adventures.js +2 -2
- package/dist/commands/game-catalog.d.ts +13 -0
- package/dist/commands/game-catalog.js +26 -2
- package/dist/commands/game-checks.js +23 -21
- package/dist/commands/{game-hit-dice.d.ts → game-dice-pool.d.ts} +3 -3
- package/dist/commands/{game-hit-dice.js → game-dice-pool.js} +7 -7
- package/dist/commands/game-effects.d.ts +12 -4
- package/dist/commands/game-effects.js +21 -13
- package/dist/commands/game-examples.d.ts +22 -0
- package/dist/commands/game-examples.js +72 -0
- package/dist/commands/game-extension-list.d.ts +31 -3
- package/dist/commands/game-extension-list.js +83 -7
- package/dist/commands/game-images.d.ts +1 -1
- package/dist/commands/game-images.js +3 -2
- package/dist/commands/game-library.d.ts +3 -0
- package/dist/commands/game-library.js +2 -2
- package/dist/commands/game-mode.js +1 -1
- package/dist/commands/game-package-code.d.ts +87 -0
- package/dist/commands/game-package-code.js +648 -0
- package/dist/commands/game-package-hooks.d.ts +37 -0
- package/dist/commands/game-package-hooks.js +116 -0
- package/dist/commands/game-recipes.js +2 -2
- package/dist/commands/game-reminders.d.ts +5 -2
- package/dist/commands/game-reminders.js +7 -4
- package/dist/commands/game-rules.d.ts +4 -1
- package/dist/commands/game-rules.js +7 -1
- package/dist/commands/game-upkeep.js +3 -3
- package/dist/commands/game-view-place.d.ts +8 -20
- package/dist/commands/game-view-place.js +16 -35
- package/dist/commands/game-widgets.d.ts +39 -10
- package/dist/commands/game-widgets.js +138 -35
- package/dist/commands/game-world.d.ts +17 -0
- package/dist/commands/game-world.js +70 -12
- package/dist/commands/image.js +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package.d.ts +8 -0
- package/dist/commands/package.js +81 -24
- package/dist/commands/progression.d.ts +2 -0
- package/dist/commands/progression.js +7 -2
- package/dist/commands/roll.d.ts +2 -0
- package/dist/commands/roll.js +50 -24
- package/dist/commands/rules.js +6 -4
- package/dist/commands/scene.d.ts +1 -1
- package/dist/commands/scene.js +13 -10
- package/dist/commands/sheet.js +10 -1
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +14 -4
- package/dist/commands/trade.js +6 -4
- package/dist/commands/translate.js +2 -2
- package/dist/commands/travel.js +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/view.d.ts +8 -4
- package/dist/commands/view.js +7 -6
- package/dist/commands/worked-out.js +11 -5
- package/dist/commands/write.d.ts +8 -1
- package/dist/commands/write.js +84 -25
- package/dist/core/command-reference.js +3 -2
- package/dist/core/consents.d.ts +18 -0
- package/dist/core/consents.js +93 -0
- package/dist/core/context.d.ts +51 -29
- package/dist/core/context.js +3 -1
- package/dist/core/examples.d.ts +25 -0
- package/dist/core/examples.js +19 -0
- package/dist/{extensions/api.d.ts → core/package-api.d.ts} +134 -32
- package/dist/core/package-declarations.d.ts +102 -0
- package/dist/core/package-declarations.js +81 -0
- package/dist/core/registry.d.ts +2 -0
- package/dist/core/text.d.ts +5 -0
- package/dist/core/text.js +12 -0
- package/dist/dashboard/acts.js +31 -24
- package/dist/dashboard/address.js +4 -1
- package/dist/dashboard/api.js +54 -0
- package/dist/dashboard/app.js +140 -96
- package/dist/dashboard/ask-card.js +76 -25
- package/dist/dashboard/asked-dice.js +57 -0
- package/dist/dashboard/dice/tray.js +3 -3
- package/dist/dashboard/extension-widgets.js +104 -10
- package/dist/dashboard/i18n/ar.json +25 -29
- package/dist/dashboard/i18n/cs.json +25 -29
- package/dist/dashboard/i18n/da.json +25 -29
- package/dist/dashboard/i18n/de.json +25 -29
- package/dist/dashboard/i18n/el.json +25 -29
- package/dist/dashboard/i18n/es.json +25 -29
- package/dist/dashboard/i18n/fi.json +25 -29
- package/dist/dashboard/i18n/fr.json +25 -29
- package/dist/dashboard/i18n/he.json +25 -29
- package/dist/dashboard/i18n/hi.json +25 -29
- package/dist/dashboard/i18n/hu.json +25 -29
- package/dist/dashboard/i18n/is.json +25 -29
- package/dist/dashboard/i18n/it.json +25 -29
- package/dist/dashboard/i18n/ja.json +25 -29
- package/dist/dashboard/i18n/ko.json +25 -29
- package/dist/dashboard/i18n/nb.json +25 -29
- package/dist/dashboard/i18n/nl.json +25 -29
- package/dist/dashboard/i18n/pl.json +25 -29
- package/dist/dashboard/i18n/pt.json +25 -29
- package/dist/dashboard/i18n/ro.json +25 -29
- package/dist/dashboard/i18n/ru.json +25 -29
- package/dist/dashboard/i18n/sv.json +25 -29
- package/dist/dashboard/i18n/tr.json +25 -29
- package/dist/dashboard/i18n/uk.json +25 -29
- package/dist/dashboard/i18n/zh.json +25 -29
- package/dist/dashboard/icons.js +4 -1
- package/dist/dashboard/kit.js +35 -0
- package/dist/dashboard/labels.js +1 -0
- package/dist/dashboard/pack-card.js +7 -2
- package/dist/dashboard/package-page.js +50 -0
- package/dist/dashboard/packages.js +172 -23
- package/dist/dashboard/page-code.js +248 -0
- package/dist/dashboard/party.js +13 -14
- package/dist/dashboard/people.js +4 -0
- package/dist/dashboard/person-panel.js +110 -0
- package/dist/dashboard/place-map-view.js +11 -6
- package/dist/dashboard/scene.js +12 -9
- package/dist/dashboard/settings.js +55 -9
- package/dist/dashboard/sheet.js +21 -13
- package/dist/dashboard/status.js +69 -15
- package/dist/dashboard/style.css +592 -825
- package/dist/dashboard/top.js +75 -25
- package/dist/dashboard/turns.js +34 -13
- package/dist/dashboard/widgets.js +9 -2
- package/dist/dashboard-server.js +189 -10
- package/dist/dice/roll-dice.js +1 -1
- package/dist/effects/effect.d.ts +7 -4
- package/dist/effects/effect.js +12 -9
- package/dist/extensions/engine.d.ts +4 -0
- package/dist/extensions/engine.js +74 -0
- package/dist/extensions/extension.d.ts +25 -37
- package/dist/extensions/extension.js +26 -48
- package/dist/extensions/index.d.ts +3 -2
- package/dist/extensions/index.js +4 -1
- package/dist/extensions/packages.d.ts +6 -0
- package/dist/extensions/packages.js +100 -11
- package/dist/index.d.ts +1 -3
- package/dist/mcp-server.js +51 -14
- package/dist/page-words.d.ts +4 -0
- package/dist/page-words.js +4 -4
- package/dist/page.d.ts +218 -0
- package/dist/page.js +2 -0
- package/dist/pages/load.d.ts +7 -1
- package/dist/pages/load.js +10 -5
- package/dist/pages/page-file.js +1 -1
- package/dist/pages/stack-writes.js +5 -4
- package/dist/pages/world.d.ts +8 -0
- package/dist/pages/world.js +9 -2
- package/dist/systems/game-system.d.ts +52 -26
- package/dist/systems/game-system.js +141 -42
- package/dist/systems/index.d.ts +3 -3
- package/dist/systems/index.js +3 -3
- package/dist/systems/system-code.d.ts +29 -88
- package/dist/systems/system-code.js +68 -23
- package/dist/systems/words.d.ts +2 -0
- package/dist/systems/words.js +11 -0
- package/dist/testing.d.ts +20 -5
- package/dist/testing.js +49 -14
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/dashboard.md +2 -2
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/play.md +3 -3
- package/instructions/setup.md +1 -1
- package/package.json +10 -2
- package/systems/5e/LICENSE.md +13 -3
- package/systems/5e/dist/dying.js +83 -16
- package/systems/5e/dist/index.js +2 -2
- package/systems/5e/dist/page-style.js +634 -0
- package/systems/5e/dist/page.js +166 -0
- package/systems/5e/dist/shown.js +23 -0
- package/systems/5e/instructions/combat.md +1 -0
- package/systems/5e/package.json +4 -2
- package/systems/5e/system.yaml +37 -9
- package/systems/5e/versions/srd-5.1/system.yaml +2 -0
- package/systems/5e/words/ar.yaml +30 -0
- package/systems/5e/words/cs.yaml +30 -0
- package/systems/5e/words/da.yaml +30 -0
- package/systems/5e/words/de.yaml +30 -0
- package/systems/5e/words/el.yaml +30 -0
- package/systems/5e/words/es.yaml +30 -0
- package/systems/5e/words/fi.yaml +30 -0
- package/systems/5e/words/fr.yaml +30 -0
- package/systems/5e/words/he.yaml +30 -0
- package/systems/5e/words/hi.yaml +30 -0
- package/systems/5e/words/hu.yaml +30 -0
- package/systems/5e/words/is.yaml +30 -0
- package/systems/5e/words/it.yaml +30 -0
- package/systems/5e/words/ja.yaml +30 -0
- package/systems/5e/words/ko.yaml +30 -0
- package/systems/5e/words/nb.yaml +30 -0
- package/systems/5e/words/nl.yaml +30 -0
- package/systems/5e/words/pl.yaml +30 -0
- package/systems/5e/words/pt.yaml +30 -0
- package/systems/5e/words/ro.yaml +30 -0
- package/systems/5e/words/ru.yaml +30 -0
- package/systems/5e/words/sv.yaml +30 -0
- package/systems/5e/words/tr.yaml +30 -0
- package/systems/5e/words/uk.yaml +30 -0
- package/systems/5e/words/zh.yaml +30 -0
- package/dist/commands/game-extensions.d.ts +0 -34
- package/dist/commands/game-extensions.js +0 -407
- package/dist/commands/game-system-code.d.ts +0 -33
- package/dist/commands/game-system-code.js +0 -188
- package/dist/dashboard/death-save.js +0 -67
- package/dist/dashboard/dying.js +0 -46
- package/dist/dashboard/save-outcome.js +0 -42
- package/dist/dashboard/spend.js +0 -115
- /package/dist/{extensions/api.js → core/package-api.js} +0 -0
package/systems/5e/words/tr.yaml
CHANGED
|
@@ -199,6 +199,27 @@ words:
|
|
|
199
199
|
Stable: Stabil
|
|
200
200
|
Successes: Başarılar
|
|
201
201
|
Failures: Başarısızlıklar
|
|
202
|
+
# The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
|
|
203
|
+
"Dying": "Can çekişiyor"
|
|
204
|
+
"Dead": "Ölü"
|
|
205
|
+
"Success": "Başarı"
|
|
206
|
+
"Failure": "Başarısızlık"
|
|
207
|
+
"Two failures": "İki başarısızlık"
|
|
208
|
+
"{count} failures": "{count} başarısızlık"
|
|
209
|
+
"Back up with {value}": "{value} ile ayakta"
|
|
210
|
+
"{value} or more: a success": "{value} veya üstü: başarı"
|
|
211
|
+
"{face}: two failures": "{face}: iki başarısızlık"
|
|
212
|
+
"{face}: {count} failures": "{face}: {count} başarısızlık"
|
|
213
|
+
"{face}: back up with {value}": "{face}: {value} ile ayağa kalkış"
|
|
214
|
+
"at the maximum": "maksimumda"
|
|
215
|
+
"None left": "Kalmadı"
|
|
216
|
+
"One die at a time: stop when you like.": "Her seferinde tek zar: istediğin zaman dur."
|
|
217
|
+
"Dice rolled": "Atılan zarlar"
|
|
218
|
+
"I spend none": "Hiç harcamıyorum"
|
|
219
|
+
"Done": "Bitti"
|
|
220
|
+
"Left: {count}": "Kalan: {count}"
|
|
221
|
+
"{value} of {max}": "{value} / {max}"
|
|
222
|
+
"Roll": "At"
|
|
202
223
|
Wretched: Sefil
|
|
203
224
|
Squalid: Pejmürde
|
|
204
225
|
Poor: Yoksul
|
|
@@ -481,6 +502,15 @@ words:
|
|
|
481
502
|
Hooded Lantern: Kapaklı Fener
|
|
482
503
|
Bullseye Lantern: Mercekli Fener
|
|
483
504
|
Oil: Yağ
|
|
505
|
+
"Cast": "Büyü yap"
|
|
506
|
+
"Cast {item}": "{item} büyüsünü yap"
|
|
507
|
+
"I cast {item}.": "{item} büyüsünü yapıyorum."
|
|
508
|
+
"I cast {item} on {target}.": "{item} büyüsünü {target} hedefine yapıyorum."
|
|
509
|
+
"I cast {item} at {square}.": "{item} büyüsünü {square} karesine yapıyorum."
|
|
510
|
+
"I cast {item} on myself.": "{item} büyüsünü kendime yapıyorum."
|
|
511
|
+
"Prepare": "Hazırla"
|
|
512
|
+
"Prepare {item}": "{item} hazırla"
|
|
513
|
+
"I prepare {item}.": "{item} hazırlıyorum."
|
|
484
514
|
names:
|
|
485
515
|
str: Güç
|
|
486
516
|
str-mod: Güç
|
package/systems/5e/words/uk.yaml
CHANGED
|
@@ -199,6 +199,27 @@ words:
|
|
|
199
199
|
Stable: Стабільно
|
|
200
200
|
Successes: Успіхи
|
|
201
201
|
Failures: Невдачі
|
|
202
|
+
# The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
|
|
203
|
+
"Dying": "Конає"
|
|
204
|
+
"Dead": "Смерть"
|
|
205
|
+
"Success": "Успіх"
|
|
206
|
+
"Failure": "Невдача"
|
|
207
|
+
"Two failures": "Дві невдачі"
|
|
208
|
+
"{count} failures": "Невдач: {count}"
|
|
209
|
+
"Back up with {value}": "На ногах з {value}"
|
|
210
|
+
"{value} or more: a success": "{value} або більше: успіх"
|
|
211
|
+
"{face}: two failures": "{face}: дві невдачі"
|
|
212
|
+
"{face}: {count} failures": "{face}: невдач — {count}"
|
|
213
|
+
"{face}: back up with {value}": "{face}: на ногах з {value}"
|
|
214
|
+
"at the maximum": "на максимумі"
|
|
215
|
+
"None left": "Не лишилось"
|
|
216
|
+
"One die at a time: stop when you like.": "По одному кубику: зупиняйся, коли захочеш."
|
|
217
|
+
"Dice rolled": "Кубики кинуто"
|
|
218
|
+
"I spend none": "Не витрачати"
|
|
219
|
+
"Done": "Готово"
|
|
220
|
+
"Left: {count}": "Лишилось: {count}"
|
|
221
|
+
"{value} of {max}": "{value} з {max}"
|
|
222
|
+
"Roll": "Кинути"
|
|
202
223
|
Wretched: Жалюгідний
|
|
203
224
|
Squalid: Убогий
|
|
204
225
|
Poor: Бідний
|
|
@@ -481,6 +502,15 @@ words:
|
|
|
481
502
|
Hooded Lantern: Ліхтар із заслінкою
|
|
482
503
|
Bullseye Lantern: Направлений ліхтар
|
|
483
504
|
Oil: Олива
|
|
505
|
+
"Cast": "Накласти"
|
|
506
|
+
"Cast {item}": "Накласти {item}"
|
|
507
|
+
"I cast {item}.": "Накладаю {item}."
|
|
508
|
+
"I cast {item} on {target}.": "Накладаю {item} на {target}."
|
|
509
|
+
"I cast {item} at {square}.": "Накладаю {item} на клітинку {square}."
|
|
510
|
+
"I cast {item} on myself.": "Накладаю {item} на себе."
|
|
511
|
+
"Prepare": "Підготувати"
|
|
512
|
+
"Prepare {item}": "Підготувати {item}"
|
|
513
|
+
"I prepare {item}.": "Готую {item}."
|
|
484
514
|
names:
|
|
485
515
|
str: Сила
|
|
486
516
|
str-mod: Сила
|
package/systems/5e/words/zh.yaml
CHANGED
|
@@ -199,6 +199,27 @@ words:
|
|
|
199
199
|
Stable: 稳定
|
|
200
200
|
Successes: 成功
|
|
201
201
|
Failures: 失败
|
|
202
|
+
# The death save's card and the hit dice of a rest on the dashboard (D-461, D-492): drawn by the 5e's page module
|
|
203
|
+
"Dying": "濒死"
|
|
204
|
+
"Dead": "死亡"
|
|
205
|
+
"Success": "成功"
|
|
206
|
+
"Failure": "失败"
|
|
207
|
+
"Two failures": "两次失败"
|
|
208
|
+
"{count} failures": "{count} 次失败"
|
|
209
|
+
"Back up with {value}": "以 {value} 点生命站起"
|
|
210
|
+
"{value} or more: a success": "{value} 或更高:成功"
|
|
211
|
+
"{face}: two failures": "{face}:两次失败"
|
|
212
|
+
"{face}: {count} failures": "{face}:{count} 次失败"
|
|
213
|
+
"{face}: back up with {value}": "{face}:以 {value} 点生命站起"
|
|
214
|
+
"at the maximum": "已达上限"
|
|
215
|
+
"None left": "已用完"
|
|
216
|
+
"One die at a time: stop when you like.": "一次掷一个骰子,想停就停。"
|
|
217
|
+
"Dice rolled": "已掷骰子"
|
|
218
|
+
"I spend none": "不消耗"
|
|
219
|
+
"Done": "完成"
|
|
220
|
+
"Left: {count}": "剩余:{count}"
|
|
221
|
+
"{value} of {max}": "{value}/{max}"
|
|
222
|
+
"Roll": "掷骰"
|
|
202
223
|
Wretched: 赤贫
|
|
203
224
|
Squalid: 肮脏
|
|
204
225
|
Poor: 贫穷
|
|
@@ -481,6 +502,15 @@ words:
|
|
|
481
502
|
Hooded Lantern: 遮光提灯
|
|
482
503
|
Bullseye Lantern: 牛眼提灯
|
|
483
504
|
Oil: 油
|
|
505
|
+
"Cast": "施放"
|
|
506
|
+
"Cast {item}": "施放{item}"
|
|
507
|
+
"I cast {item}.": "我施放{item}。"
|
|
508
|
+
"I cast {item} on {target}.": "我对{target}施放{item}。"
|
|
509
|
+
"I cast {item} at {square}.": "我向{square}格子施放{item}。"
|
|
510
|
+
"I cast {item} on myself.": "我对自己施放{item}。"
|
|
511
|
+
"Prepare": "准备"
|
|
512
|
+
"Prepare {item}": "准备{item}"
|
|
513
|
+
"I prepare {item}.": "我准备{item}。"
|
|
484
514
|
names:
|
|
485
515
|
str: 力量
|
|
486
516
|
str-mod: 力量
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Context } from "../core/context.ts";
|
|
2
|
-
import type { Problem } from "../core/problem.ts";
|
|
3
|
-
import { type Command } from "../core/registry.ts";
|
|
4
|
-
import type { Extension, ExtensionCode, GameView } from "../extensions/index.ts";
|
|
5
|
-
import { type GameDate } from "../time/index.ts";
|
|
6
|
-
/** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
|
|
7
|
-
export declare const extensionsFolderName = "extensions";
|
|
8
|
-
/**
|
|
9
|
-
* The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
|
|
10
|
-
* master its text; by name, the package and version that give it, so that a server knows when another takes its place.
|
|
11
|
-
*/
|
|
12
|
-
export declare function extensionCommands(root: string, context: Context, taken: string[]): Promise<{
|
|
13
|
-
commands: Command[];
|
|
14
|
-
sources: Record<string, string>;
|
|
15
|
-
problems: Problem[];
|
|
16
|
-
}>;
|
|
17
|
-
/** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
|
|
18
|
-
export declare function extensionCommandNames(extension: Extension, taken: string[]): Promise<string[]>;
|
|
19
|
-
/** Tells the loader npm has just installed: code installed again at the same version is read anew. */
|
|
20
|
-
export declare function packagesInstalled(): void;
|
|
21
|
-
/** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
|
|
22
|
-
export declare function extensionCodeProblems(root: string, context: Context, taken: string[]): Promise<Problem[]>;
|
|
23
|
-
/**
|
|
24
|
-
* What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
|
|
25
|
-
* whatever they do: one that fails says so in its line, never in place of the output.
|
|
26
|
-
*/
|
|
27
|
-
export declare function timePassedLines(root: string, context: Context, from: GameDate, to: GameDate): Promise<string[]>;
|
|
28
|
-
/**
|
|
29
|
-
* The code of an extension, when it may run (D-441): its module's default export, given the kit. Where the engine itself runs from its source, as in the tests,
|
|
30
|
-
* an extension that ships its source too is loaded from it.
|
|
31
|
-
*/
|
|
32
|
-
export declare function extensionCode(extension: Extension): Promise<ExtensionCode | undefined>;
|
|
33
|
-
/** The game as a widget of an extension reads it (D-502, D-505): the time, where the party is and who is in it, a page, the scene and the extension's state. */
|
|
34
|
-
export declare function gameViewOf(root: string, context: Context, extension: Extension): GameView;
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
// The code of the campaign's extensions (D-63, D-428, D-436): its commands, what it does when time passes, and the API it reaches the game through.
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { pathToFileURL } from "node:url";
|
|
12
|
-
import { parse, stringify } from "yaml";
|
|
13
|
-
import { z } from "zod";
|
|
14
|
-
import { campaignFileName, readTextSetting, requireCampaign } from "../campaign/index.js";
|
|
15
|
-
import { realPath } from "../core/files.js";
|
|
16
|
-
import { parseFormula } from "../core/formula.js";
|
|
17
|
-
import { appendLogEntry } from "../core/log.js";
|
|
18
|
-
import { defineCommand } from "../core/registry.js";
|
|
19
|
-
import { files } from "../core/store.js";
|
|
20
|
-
import { sameName, valueNamed } from "../core/text.js";
|
|
21
|
-
import { rollDice } from "../dice/index.js";
|
|
22
|
-
import { extensionWords, wordIn } from "../extensions/index.js";
|
|
23
|
-
import { environmentAt, isCoreField, isInParty, isPlayerCharacter, locate, pagesWithNameOrAlias, playerCharacters } from "../pages/index.js";
|
|
24
|
-
import { findSystem } from "../systems/index.js";
|
|
25
|
-
import { formatGameDate } from "../time/index.js";
|
|
26
|
-
import { askedRoll, isCheckDice, tonesOf } from "./ask.js";
|
|
27
|
-
import { effectiveFields } from "./effect-layer.js";
|
|
28
|
-
import { campaignExtensions, runsCode } from "./game-extension-list.js";
|
|
29
|
-
import { behindTheScreen, sealHiddenRoll } from "./game-master-rolls.js";
|
|
30
|
-
import { readOpenScene } from "./game-scene.js";
|
|
31
|
-
import { setFields, systemPage } from "./game-system-code.js";
|
|
32
|
-
import { calendarDayOf, newDatedLogEntry, presentDate } from "./game-time.js";
|
|
33
|
-
import { widgetCard } from "./game-widgets.js";
|
|
34
|
-
import { campaignWorld, extensionLayer, playedLayers } from "./game-world.js";
|
|
35
|
-
import { formulaValue } from "./worked-out.js";
|
|
36
|
-
/** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
|
|
37
|
-
export const extensionsFolderName = "extensions";
|
|
38
|
-
/** The longest description a command of an extension may give the master, in words (D-441): it is read in every chat. */
|
|
39
|
-
const descriptionWords = 150;
|
|
40
|
-
/**
|
|
41
|
-
* The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
|
|
42
|
-
* master its text; by name, the package and version that give it, so that a server knows when another takes its place.
|
|
43
|
-
*/
|
|
44
|
-
export async function extensionCommands(root, context, taken) {
|
|
45
|
-
const commands = [];
|
|
46
|
-
const sources = {};
|
|
47
|
-
const problems = [];
|
|
48
|
-
for (const extension of campaignExtensions(root, context).extensions) {
|
|
49
|
-
try {
|
|
50
|
-
const own = [];
|
|
51
|
-
for (const command of (await extensionCode(extension))?.commands ?? []) {
|
|
52
|
-
own.push(asCommand(extension, command, [...taken, ...commands.map((other) => other.name), ...own.map((other) => other.name)]));
|
|
53
|
-
}
|
|
54
|
-
commands.push(...own);
|
|
55
|
-
own.forEach((command) => (sources[command.name] = `${extension.package}@${extension.version}#${installs}`));
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
problems.push(codeProblem(extension, error));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return { commands, sources, problems };
|
|
62
|
-
}
|
|
63
|
-
/** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
|
|
64
|
-
export async function extensionCommandNames(extension, taken) {
|
|
65
|
-
const names = [];
|
|
66
|
-
for (const command of (await extensionCode(extension))?.commands ?? []) {
|
|
67
|
-
names.push(asCommand(extension, command, [...taken, ...names]).name);
|
|
68
|
-
}
|
|
69
|
-
return names;
|
|
70
|
-
}
|
|
71
|
-
/** Tells the loader npm has just installed: code installed again at the same version is read anew. */
|
|
72
|
-
export function packagesInstalled() {
|
|
73
|
-
installs += 1;
|
|
74
|
-
}
|
|
75
|
-
/** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
|
|
76
|
-
export async function extensionCodeProblems(root, context, taken) {
|
|
77
|
-
return (await extensionCommands(root, context, taken)).problems;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
|
|
81
|
-
* whatever they do: one that fails says so in its line, never in place of the output.
|
|
82
|
-
*/
|
|
83
|
-
export async function timePassedLines(root, context, from, to) {
|
|
84
|
-
const lines = [];
|
|
85
|
-
for (const extension of campaignExtensions(root, context).extensions) {
|
|
86
|
-
try {
|
|
87
|
-
const code = await extensionCode(extension);
|
|
88
|
-
if (code?.timePassed !== undefined) {
|
|
89
|
-
lines.push(...await code.timePassed({ from: momentOf(root, context, from), to: momentOf(root, context, to) }, gameOf(root, context, extension)));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
// One line: the master reads it among others.
|
|
94
|
-
const why = (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
|
|
95
|
-
lines.push(`The extension ${extension.name} failed after the time passed: ${why}. The time did pass: do not advance again; validate says how to fix it.`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return lines;
|
|
99
|
-
}
|
|
100
|
-
/** A command of an extension as a command of rpg-engine, refused when its name is not the extension's or is taken, or its description is too long. */
|
|
101
|
-
function asCommand(extension, command, taken) {
|
|
102
|
-
const name = command.name.trim();
|
|
103
|
-
const words = command.description.split(/\s+/).length;
|
|
104
|
-
if (name !== extension.name && !name.startsWith(`${extension.name}-`)) {
|
|
105
|
-
throw new Error(`its command ${name} must be named ${extension.name}, or start with ${extension.name}-`);
|
|
106
|
-
}
|
|
107
|
-
if (taken.includes(name)) {
|
|
108
|
-
throw new Error(`its command ${name} has the name of another command`);
|
|
109
|
-
}
|
|
110
|
-
if (words > descriptionWords) {
|
|
111
|
-
throw new Error(`its command ${name} has a description of ${words} words, and ${descriptionWords} at most are read`);
|
|
112
|
-
}
|
|
113
|
-
return defineCommand({
|
|
114
|
-
name,
|
|
115
|
-
description: command.description,
|
|
116
|
-
group: "game",
|
|
117
|
-
input: command.input,
|
|
118
|
-
readOnly: command.readOnly,
|
|
119
|
-
positionals: command.positionals,
|
|
120
|
-
waitsForPlayer: command.needsPlayer,
|
|
121
|
-
async run(input, called) {
|
|
122
|
-
const campaign = requireCampaign(called.folder);
|
|
123
|
-
const asked = {};
|
|
124
|
-
try {
|
|
125
|
-
return { text: await command.run(input, gameOf(campaign, called, extension, asked)) };
|
|
126
|
-
}
|
|
127
|
-
finally {
|
|
128
|
-
// The card of its last question, as it is after the dice, read once the call ends, however it ends (D-507).
|
|
129
|
-
if (asked.card !== undefined) {
|
|
130
|
-
called.page?.cardEnded?.(asked.card);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
format: (result) => result.text,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// The code of each extension, by its file and version, loaded once for the process: an import is never undone, a new version is another.
|
|
138
|
-
const loaded = new Map();
|
|
139
|
-
let installs = 0;
|
|
140
|
-
/**
|
|
141
|
-
* The code of an extension, when it may run (D-441): its module's default export, given the kit. Where the engine itself runs from its source, as in the tests,
|
|
142
|
-
* an extension that ships its source too is loaded from it.
|
|
143
|
-
*/
|
|
144
|
-
export function extensionCode(extension) {
|
|
145
|
-
const source = join(extension.folder, "src", "index.ts");
|
|
146
|
-
const entry = !runsCode(extension) ? undefined : import.meta.url.endsWith(".ts") && files().exists(source) ? source : extension.code;
|
|
147
|
-
if (entry === undefined) {
|
|
148
|
-
return Promise.resolve(undefined);
|
|
149
|
-
}
|
|
150
|
-
// By its real path, as Node would resolve it: a package linked from a folder of the player's is read from that folder, its own settings beside it.
|
|
151
|
-
const url = `${pathToFileURL(realPath(entry)).href}?v=${encodeURIComponent(extension.version)}&installs=${installs}`;
|
|
152
|
-
const code = loaded.get(url) ?? import(__rewriteRelativeImportExtension(url)).then((module) => {
|
|
153
|
-
if (typeof module.default !== "function") {
|
|
154
|
-
throw new Error(`its code, ${entry}, has no default export that gives its commands`);
|
|
155
|
-
}
|
|
156
|
-
return module.default({ z });
|
|
157
|
-
});
|
|
158
|
-
loaded.set(url, code);
|
|
159
|
-
return code;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The game as an extension's code reaches it (D-436, D-505): what a widget reads, the dice, asking the player, its own state, the fields it adds and the log;
|
|
163
|
-
* nothing else is written, and nothing once the call is stopped (ASK-9).
|
|
164
|
-
*/
|
|
165
|
-
function gameOf(root, context, extension, asked = {}) {
|
|
166
|
-
const view = gameViewOf(root, context, extension);
|
|
167
|
-
const live = () => {
|
|
168
|
-
if (context.signal?.aborted === true) {
|
|
169
|
-
throw new Error("The call was stopped: nothing more is written.");
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
return {
|
|
173
|
-
...view,
|
|
174
|
-
roll: (notation, by) => {
|
|
175
|
-
if (by !== undefined) {
|
|
176
|
-
live();
|
|
177
|
-
return rollFor(root, context, notation, by, (text) => extensionText(root, extension, text));
|
|
178
|
-
}
|
|
179
|
-
const rolled = rollDice(notation, { random: context.random });
|
|
180
|
-
return { total: rolled.total, faces: rolled.faces, text: rolled.text };
|
|
181
|
-
},
|
|
182
|
-
set: (page, values, why) => {
|
|
183
|
-
live();
|
|
184
|
-
setOwnFields(root, context, extension, page, values, why);
|
|
185
|
-
},
|
|
186
|
-
ask: async (wanted) => {
|
|
187
|
-
live();
|
|
188
|
-
const { who, question, check, notation } = wanted;
|
|
189
|
-
const told = toldOf(root, context, extension, wanted);
|
|
190
|
-
asked.card = told.card ?? asked.card;
|
|
191
|
-
return askedOf(await askedRoll(root, context, askedQuestion(extensionText(root, extension, question), check, notation), [{ label: check.trim(), notation }], who, told));
|
|
192
|
-
},
|
|
193
|
-
state: {
|
|
194
|
-
read: view.state.read,
|
|
195
|
-
write: (value) => {
|
|
196
|
-
live();
|
|
197
|
-
files().write(statePath(root, extension), `# The state of the extension ${extension.package}, kept by its code.\n${stringify(value, { lineWidth: 0 })}`);
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
log: (text, visibility = "hidden") => {
|
|
201
|
-
live();
|
|
202
|
-
appendLogEntry(root, newDatedLogEntry(root, context, "extension", visibility, { extension: extension.name, text }));
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/** The game as a widget of an extension reads it (D-502, D-505): the time, where the party is and who is in it, a page, the scene and the extension's state. */
|
|
207
|
-
export function gameViewOf(root, context, extension) {
|
|
208
|
-
return {
|
|
209
|
-
now: () => {
|
|
210
|
-
const now = presentDate(root);
|
|
211
|
-
return now === undefined ? undefined : momentOf(root, context, now);
|
|
212
|
-
},
|
|
213
|
-
calendarDay: (day) => calendarDayOf(root, context, day),
|
|
214
|
-
units: () => (readTextSetting(root, "units") === "imperial" ? "imperial" : "metric"),
|
|
215
|
-
party: () => {
|
|
216
|
-
const world = campaignWorld(root, context);
|
|
217
|
-
const player = playerCharacters(world).find(isInParty);
|
|
218
|
-
return player === undefined
|
|
219
|
-
? undefined
|
|
220
|
-
: {
|
|
221
|
-
places: locate(world, player).chain.filter((page) => page.type === "place").map((page) => page.name),
|
|
222
|
-
environment: Object.fromEntries(environmentAt(world, player).map(({ entry }) => [entry.name, entry.value])),
|
|
223
|
-
members: world.pages.filter(isInParty).map((page) => ({ name: page.name, pc: isPlayerCharacter(page) })),
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
page: (name) => {
|
|
227
|
-
const world = campaignWorld(root, context);
|
|
228
|
-
const found = pagesWithNameOrAlias(world, name);
|
|
229
|
-
return found.length === 1 ? gamePage(world, found[0]) : undefined;
|
|
230
|
-
},
|
|
231
|
-
scene: () => {
|
|
232
|
-
const scene = readOpenScene(root).scene;
|
|
233
|
-
return scene === undefined ? undefined : {
|
|
234
|
-
title: scene.title,
|
|
235
|
-
...(scene.opened === undefined ? {} : { opened: scene.opened }),
|
|
236
|
-
...(scene.round === undefined ? {} : { round: scene.round }),
|
|
237
|
-
...(scene.turn === undefined ? {} : { turn: scene.turn }),
|
|
238
|
-
};
|
|
239
|
-
},
|
|
240
|
-
state: { read: () => parse(files().text(statePath(root, extension)) ?? "null") },
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/** A game date as the API gives it: as written, its day and minute, and its day of the calendar. */
|
|
244
|
-
function momentOf(root, context, date) {
|
|
245
|
-
const calendar = calendarDayOf(root, context, date.day);
|
|
246
|
-
return { date: formatGameDate(date), day: date.day, ...(date.minute === undefined ? {} : { minute: date.minute }), ...(calendar === undefined ? {} : { calendar }) };
|
|
247
|
-
}
|
|
248
|
-
function statePath(root, extension) {
|
|
249
|
-
return join(root, extensionsFolderName, extension.name, "state.yaml");
|
|
250
|
-
}
|
|
251
|
-
/** A page as an extension reads it (D-505): as a system's code does, with its fields as show gives them, effects and what the system works out included. */
|
|
252
|
-
function gamePage(world, page) {
|
|
253
|
-
const fields = effectiveFields(world, page);
|
|
254
|
-
return {
|
|
255
|
-
...systemPage(world, page),
|
|
256
|
-
value: (field) => plainValue(valueNamed(fields, field)),
|
|
257
|
-
formula: (text) => {
|
|
258
|
-
let formula;
|
|
259
|
-
try {
|
|
260
|
-
formula = parseFormula(text);
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
throw new Error(`The formula ${text} does not read: ${error instanceof Error ? error.message : String(error)} Write it as the game system's computed fields are written.`);
|
|
264
|
-
}
|
|
265
|
-
return formulaValue(world, fields, formula);
|
|
266
|
-
},
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
/** A field's value as the API gives it: a number, text, or a list as text; undefined for anything else, as a map. */
|
|
270
|
-
function plainValue(value) {
|
|
271
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
if (typeof value === "boolean") {
|
|
275
|
-
return String(value);
|
|
276
|
-
}
|
|
277
|
-
return Array.isArray(value) ? value.map((item) => (typeof item === "object" && item !== null ? JSON.stringify(item) : String(item))) : undefined;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Sets on a page only the fields an extension adds to the game system, as fields or counters, under their own names (D-505): another is refused with the names
|
|
281
|
-
* of its own, as one the core, the system, an extension below it or the campaign declares too, so that no package reaches what another keeps, such as hit
|
|
282
|
-
* points; and all of them while its additions are left out (CAM-3).
|
|
283
|
-
*/
|
|
284
|
-
function setOwnFields(root, context, extension, name, values, why) {
|
|
285
|
-
const { kept, refused } = playedLayers(root, context);
|
|
286
|
-
const layer = extensionLayer(extension.name);
|
|
287
|
-
if (refused.includes(layer)) {
|
|
288
|
-
throw new Error(`What the extension ${extension.name} adds to the game system does not read, so the campaign plays without it and it sets none of its fields: validate says why. Nothing changed.`);
|
|
289
|
-
}
|
|
290
|
-
const below = kept.filter((other, index) => other.from === campaignFileName || index < kept.findIndex((mine) => mine.from === layer));
|
|
291
|
-
const taken = [...Object.keys(findSystem(context.systemFolders, readTextSetting(root, "system") ?? "")?.fields ?? {}), ...below.flatMap((other) => declaredFields(other.data))];
|
|
292
|
-
const declared = declaredFields(extension.adds);
|
|
293
|
-
const own = declared.filter((field, index) => sameName(declared.slice(0, index), field) === undefined && sameName(taken, field) === undefined && !isCoreField(field));
|
|
294
|
-
const others = Object.keys(values).filter((field) => sameName(own, field) === undefined);
|
|
295
|
-
const odd = Object.entries(values).find(([, value]) => typeof value !== "string" && (typeof value !== "number" || !Number.isFinite(value)));
|
|
296
|
-
if (others.length > 0) {
|
|
297
|
-
const its = own.length === 0 ? "it adds none in its extension.yaml" : `its own are ${own.join(", ")}`;
|
|
298
|
-
throw new Error(`The extension ${extension.name} sets only the fields it adds to the game system, and ${others.join(", ")} is not one of them: ${its}. Add it to fields or counters in its extension.yaml. Nothing changed.`);
|
|
299
|
-
}
|
|
300
|
-
if (odd !== undefined) {
|
|
301
|
-
throw new Error(`The extension ${extension.name} gave ${odd[0]} the value ${String(odd[1])}: give a number or text. Nothing changed.`);
|
|
302
|
-
}
|
|
303
|
-
const world = campaignWorld(root, context);
|
|
304
|
-
const found = pagesWithNameOrAlias(world, name);
|
|
305
|
-
if (found.length !== 1) {
|
|
306
|
-
throw new Error(`${found.length === 0 ? `No page alone is named ${name}` : `${found.length} pages are named ${name}`}: give the name of one page of the campaign. Nothing changed.`);
|
|
307
|
-
}
|
|
308
|
-
// Each under the name its extension.yaml gives it, whatever the case it came in.
|
|
309
|
-
setFields(root, context, world, found[0], Object.fromEntries(Object.entries(values).map(([field, value]) => [sameName(own, field) ?? field, value])), why);
|
|
310
|
-
}
|
|
311
|
-
/** The fields and counters a layer of additions declares. */
|
|
312
|
-
function declaredFields(data) {
|
|
313
|
-
const names = (map) => (typeof map === "object" && map !== null && !Array.isArray(map) ? Object.keys(map) : []);
|
|
314
|
-
return [...names(data.fields), ...names(data.counters)];
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* A roll for who, as the master's for them (D-287, D-505): a line in the log, in view for the party and behind the screen for anyone else as master-rolls says;
|
|
318
|
-
* the player's physical dice, given as their faces, always in view.
|
|
319
|
-
*/
|
|
320
|
-
function rollFor(root, context, notation, by, words) {
|
|
321
|
-
const rolled = rollDice(notation, by.values === undefined ? { random: context.random } : { values: by.values });
|
|
322
|
-
const physical = by.values !== undefined;
|
|
323
|
-
const hidden = !physical && behindTheScreen(root, context, by.who);
|
|
324
|
-
const checked = by.check === undefined ? {} : { check: by.check };
|
|
325
|
-
const says = by.says === undefined ? {} : { says: words(by.says(rolled.faces)) };
|
|
326
|
-
const tones = tonesOf(by.tones?.(rolled.faces), rolled.faces);
|
|
327
|
-
const entry = newDatedLogEntry(root, context, "roll", hidden ? "hidden" : "public", {
|
|
328
|
-
notation: rolled.notation,
|
|
329
|
-
total: rolled.total,
|
|
330
|
-
result: rolled.text,
|
|
331
|
-
...says,
|
|
332
|
-
...tones,
|
|
333
|
-
why: by.why,
|
|
334
|
-
who: by.who,
|
|
335
|
-
...checked,
|
|
336
|
-
physical,
|
|
337
|
-
dice: rolled.dice,
|
|
338
|
-
});
|
|
339
|
-
if (hidden) {
|
|
340
|
-
sealHiddenRoll(entry, rolled.text, context);
|
|
341
|
-
}
|
|
342
|
-
appendLogEntry(root, entry);
|
|
343
|
-
return { total: rolled.total, faces: rolled.faces, text: rolled.text, id: entry.id, hidden };
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* What a roll an extension asks tells the page in its own words (D-507): its buttons and its rule translated, what its faces mean and how they turned out, and
|
|
347
|
-
* the card of its widget, refused when the extension has no widget by that name.
|
|
348
|
-
*/
|
|
349
|
-
function toldOf(root, context, extension, wanted) {
|
|
350
|
-
const words = (text) => extensionText(root, extension, text);
|
|
351
|
-
const button = (given) => (typeof given === "object" && "label" in given ? { name: words(given.label), note: words(given.note) } : { name: words(given) });
|
|
352
|
-
const { roll, decline, rule, card, says, tones } = wanted;
|
|
353
|
-
if (card !== undefined && !extension.widgets.some((widget) => widget.name === card.widget)) {
|
|
354
|
-
const its = extension.widgets.length === 0 ? "it declares none in its extension.yaml" : `its own are ${extension.widgets.map((widget) => widget.name).join(", ")}`;
|
|
355
|
-
throw new Error(`The extension ${extension.name} asks in the card of a widget ${card.widget} it does not have: ${its}. Nothing was asked.`);
|
|
356
|
-
}
|
|
357
|
-
return {
|
|
358
|
-
...(roll === undefined ? {} : { roll: button(roll) }),
|
|
359
|
-
...(decline === undefined ? {} : { decline: decline === false ? false : button(decline) }),
|
|
360
|
-
...(rule === undefined ? {} : { rule: words(rule) }),
|
|
361
|
-
...(card === undefined ? {} : { card: { widget: `${extension.name}.${card.widget}`, key: card.key, shows: () => widgetCard(root, context, extension, card.widget, card.key) } }),
|
|
362
|
-
...(says === undefined ? {} : { says: (faces) => words(says(faces)) }),
|
|
363
|
-
...(tones === undefined ? {} : { tones }),
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
/** Words of an extension in the campaign's language, by its words as a widget's are, with their {names} filled; as written where its words lack them. */
|
|
367
|
-
function extensionText(root, extension, text) {
|
|
368
|
-
let words;
|
|
369
|
-
try {
|
|
370
|
-
words = extensionWords(extension.folder, readTextSetting(root, "language") ?? extension.language);
|
|
371
|
-
}
|
|
372
|
-
catch {
|
|
373
|
-
// Words that do not read leave the text as written, as validate says.
|
|
374
|
-
}
|
|
375
|
-
const { text: written, values } = typeof text === "string" ? { text, values: {} } : text;
|
|
376
|
-
return wordIn(words, written).replace(/\{(\w+)\}/g, (whole, name) => (Object.hasOwn(values, name) ? valueText(values[name]) : whole));
|
|
377
|
-
}
|
|
378
|
-
/** A value as plain text in a line of the log. */
|
|
379
|
-
function valueText(value) {
|
|
380
|
-
const unit = (given) => (given === undefined ? "" : ` ${given}`);
|
|
381
|
-
return typeof value === "number" || typeof value === "string" ? String(value) : "number" in value ? `${value.number}${unit(value.unit)}` : `${value.from}–${value.to}${unit(value.unit)}`;
|
|
382
|
-
}
|
|
383
|
-
/** The question of a roll asked, refused without words, a check's name or dice (ASK-2). */
|
|
384
|
-
function askedQuestion(question, check, notation) {
|
|
385
|
-
if (question.trim() === "" || check.trim() === "" || !isCheckDice(notation)) {
|
|
386
|
-
const dice = isCheckDice(notation) ? "" : `: ${notation} are no dice`;
|
|
387
|
-
throw new Error(`Give ask the question, what is at stake either way, the check's name, such as Stealth, and its dice, such as 1d20+5${dice}. Nothing was asked.`);
|
|
388
|
-
}
|
|
389
|
-
return question.trim();
|
|
390
|
-
}
|
|
391
|
-
/** What ask answered, as an extension's code gets it. */
|
|
392
|
-
function askedOf(result) {
|
|
393
|
-
switch (result.kind) {
|
|
394
|
-
case "roll":
|
|
395
|
-
return { rolled: { id: result.id, total: result.total, faces: result.faces, text: result.text } };
|
|
396
|
-
case "changed":
|
|
397
|
-
return { declined: true };
|
|
398
|
-
case "said":
|
|
399
|
-
return { said: result.words };
|
|
400
|
-
default:
|
|
401
|
-
return { inWords: "asked" in result ? result.asked : "", physical: result.kind === "physical" || result.kind === "dice in words" };
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
function codeProblem(extension, error) {
|
|
405
|
-
const why = error instanceof Error ? error.message : String(error);
|
|
406
|
-
return { path: campaignFileName, message: `The code of the extension ${extension.package} cannot be used: ${why}. Its commands are left out.`, fix: `install it again, or another version, with package install ${extension.name}` };
|
|
407
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Context, SaveAsked } from "../core/context.ts";
|
|
2
|
-
import { type Page, type World } from "../pages/index.ts";
|
|
3
|
-
import type { CounterChange, RollMade, SystemPage } from "../systems/index.ts";
|
|
4
|
-
/** What a system's code said after a command's change, and apart why it did not run or failed, which the caller adds to its notes, never deciding by it. */
|
|
5
|
-
export interface SystemSaid {
|
|
6
|
-
lines: string[];
|
|
7
|
-
problem?: string;
|
|
8
|
-
}
|
|
9
|
-
/** All a system's code said, its problem last. */
|
|
10
|
-
export declare function allSaid(said: SystemSaid): string[];
|
|
11
|
-
/** After a counter of a page changed, as by change or the hit dice: the system's lines. */
|
|
12
|
-
export declare function systemCounterChanged(root: string, context: Context, change: CounterChange): SystemSaid;
|
|
13
|
-
/** As someone's turn starts in a scene: the system's lines. */
|
|
14
|
-
export declare function systemTurnStarted(root: string, context: Context, who: string): SystemSaid;
|
|
15
|
-
/** After a roll for someone was logged, never a hidden one: the system's lines. */
|
|
16
|
-
export declare function systemRolled(root: string, context: Context, roll: RollMade): SystemSaid;
|
|
17
|
-
/** After an effect was added to a page, never to a copy: the system's lines. */
|
|
18
|
-
export declare function systemEffectAdded(root: string, context: Context, added: {
|
|
19
|
-
page: string;
|
|
20
|
-
effect: string;
|
|
21
|
-
}): SystemSaid;
|
|
22
|
-
/** What the page draws of a question, as a death save, by the system's code; undefined when it says nothing, fails or is not there: ask asks as always. */
|
|
23
|
-
export declare function systemAsking(root: string, context: Context, question: {
|
|
24
|
-
who: string;
|
|
25
|
-
notations: string[];
|
|
26
|
-
}): SaveAsked | undefined;
|
|
27
|
-
/** A page as a system's code reads it: in the party or not, the player's or not, its counters with what its effects give, its effects. */
|
|
28
|
-
export declare function systemPage(world: World, page: Page): SystemPage;
|
|
29
|
-
/**
|
|
30
|
-
* Sets fields on a page, numbers or text, a counter only numbers, keeping its maximum, each with its line in the log, public when the page concerns the player:
|
|
31
|
-
* for a system's code and an extension's (D-505).
|
|
32
|
-
*/
|
|
33
|
-
export declare function setFields(root: string, context: Context, world: World, page: Page, values: Record<string, number | string>, why: string): void;
|