rpg-engine 0.4.1 → 0.6.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.
- package/README.md +1 -1
- 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 +37 -2
- package/dist/commands/ask.js +106 -35
- package/dist/commands/change.js +28 -17
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.js +69 -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 +94 -6
- 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 +42 -8
- package/dist/commands/game-widgets.js +182 -31
- package/dist/commands/game-world.d.ts +32 -3
- package/dist/commands/game-world.js +113 -24
- 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 +15 -1
- package/dist/commands/package.js +96 -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 +2 -2
- 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 +12 -4
- package/dist/commands/view.js +11 -8
- 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 +68 -27
- package/dist/core/context.js +3 -1
- package/dist/core/examples.d.ts +25 -0
- package/dist/core/examples.js +19 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +10 -1
- package/dist/core/package-api.d.ts +388 -0
- package/dist/core/package-declarations.d.ts +102 -0
- package/dist/core/package-declarations.js +81 -0
- package/dist/core/registry.d.ts +4 -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 +65 -3
- package/dist/dashboard/app.js +222 -98
- package/dist/dashboard/ask-card.js +169 -0
- package/dist/dashboard/asked-dice.js +57 -0
- package/dist/dashboard/dice/tray.js +6 -4
- package/dist/dashboard/extension-widgets.js +136 -16
- package/dist/dashboard/faces.js +6 -4
- package/dist/dashboard/help.js +10 -3
- package/dist/dashboard/i18n/ar.json +34 -29
- package/dist/dashboard/i18n/cs.json +34 -29
- package/dist/dashboard/i18n/da.json +34 -29
- package/dist/dashboard/i18n/de.json +34 -29
- package/dist/dashboard/i18n/el.json +34 -29
- package/dist/dashboard/i18n/es.json +34 -29
- package/dist/dashboard/i18n/fi.json +34 -29
- package/dist/dashboard/i18n/fr.json +34 -29
- package/dist/dashboard/i18n/he.json +34 -29
- package/dist/dashboard/i18n/hi.json +34 -29
- package/dist/dashboard/i18n/hu.json +34 -29
- package/dist/dashboard/i18n/is.json +34 -29
- package/dist/dashboard/i18n/it.json +34 -29
- package/dist/dashboard/i18n/ja.json +34 -29
- package/dist/dashboard/i18n/ko.json +34 -29
- package/dist/dashboard/i18n/nb.json +34 -29
- package/dist/dashboard/i18n/nl.json +34 -29
- package/dist/dashboard/i18n/pl.json +34 -29
- package/dist/dashboard/i18n/pt.json +34 -29
- package/dist/dashboard/i18n/ro.json +34 -29
- package/dist/dashboard/i18n/ru.json +34 -29
- package/dist/dashboard/i18n/sv.json +34 -29
- package/dist/dashboard/i18n/tr.json +34 -29
- package/dist/dashboard/i18n/uk.json +34 -29
- package/dist/dashboard/i18n/zh.json +34 -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 +97 -0
- package/dist/dashboard/package-page.js +50 -0
- package/dist/dashboard/packages.js +180 -24
- 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/rolls.js +2 -2
- 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 +859 -574
- 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 +246 -11
- 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 +28 -33
- package/dist/extensions/extension.js +37 -46
- package/dist/extensions/index.d.ts +4 -3
- package/dist/extensions/index.js +5 -2
- package/dist/extensions/packages.d.ts +14 -0
- package/dist/extensions/packages.js +148 -12
- package/dist/extensions/words.d.ts +2 -1
- package/dist/extensions/words.js +5 -4
- package/dist/index.d.ts +1 -3
- package/dist/mcp-server.js +52 -15
- 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/index.d.ts +1 -1
- package/dist/pages/index.js +1 -1
- 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/standard-fields.d.ts +2 -0
- package/dist/pages/standard-fields.js +8 -1
- package/dist/pages/world.d.ts +8 -0
- package/dist/pages/world.js +9 -2
- package/dist/systems/game-system.d.ts +61 -30
- package/dist/systems/game-system.js +159 -50
- 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 +76 -0
- package/dist/testing.js +197 -0
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/dashboard.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/play.md +2 -2
- package/instructions/setup.md +1 -1
- package/package.json +15 -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 +35 -7
- 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 -182
- package/dist/commands/game-system-code.d.ts +0 -25
- package/dist/commands/game-system-code.js +0 -172
- 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.d.ts +0 -155
- /package/dist/{extensions/api.js → core/package-api.js} +0 -0
package/dist/commands/scene.js
CHANGED
|
@@ -10,22 +10,22 @@ import { copyNames, nextTurn, sceneTypes } from "../scene/index.js";
|
|
|
10
10
|
import { formatGameDate } from "../time/index.js";
|
|
11
11
|
import { effectiveFields, effectsOf } from "./effect-layer.js";
|
|
12
12
|
import { newStateChecks } from "./game-checks.js";
|
|
13
|
-
import { effectShown, endedByTurn, endEffects, endsWithScene, keptBy } from "./game-effects.js";
|
|
13
|
+
import { effectShown, endedByTurn, endEffects, endsWithScene, keptBy, systemNamed } from "./game-effects.js";
|
|
14
14
|
import { surroundings, surroundingsText } from "./game-environment.js";
|
|
15
15
|
import { clearCopies, offMapNote, placeGrid, standing } from "./game-grids.js";
|
|
16
16
|
import { metPictureNote, picturesNote } from "./game-images.js";
|
|
17
17
|
import { readJourney } from "./game-journey.js";
|
|
18
18
|
import { campaignMode, checklistLine } from "./game-mode.js";
|
|
19
19
|
import { movePages } from "./game-moves.js";
|
|
20
|
+
import { packagesTurnStarted } from "./game-package-hooks.js";
|
|
20
21
|
import { isTickedOpenQuest, tickedQuestNote } from "./game-quests.js";
|
|
21
22
|
import { turnEffectsNote } from "./game-reminders.js";
|
|
22
23
|
import { partyLead, playersApart } from "./game-roads.js";
|
|
23
24
|
import { isPlayerDead, makeSave, saveText } from "./game-saves.js";
|
|
24
25
|
import { copyCounters, copyPage, openScene, rawScene, readOpenScene, saveScene, updateScene } from "./game-scene.js";
|
|
25
|
-
import { systemTurnStarted } from "./game-system-code.js";
|
|
26
26
|
import { newDatedLogEntry, readPresent } from "./game-time.js";
|
|
27
27
|
import { turnUsesOf, useInTurn, usesAtTurn } from "./game-turn-uses.js";
|
|
28
|
-
import { campaignSystem, campaignWorld, missingSystemHint, systemPagesHint } from "./game-world.js";
|
|
28
|
+
import { campaignSystem, campaignSystemWords, campaignWorld, missingSystemHint, systemPagesHint } from "./game-world.js";
|
|
29
29
|
import { countersText, pageCounters, partyCounters } from "./page-counters.js";
|
|
30
30
|
import { situationPart } from "./parts.js";
|
|
31
31
|
import { hasSheet, startingAtZero } from "./worked-out.js";
|
|
@@ -69,8 +69,8 @@ export const scene = defineCommand({
|
|
|
69
69
|
with: textList.optional().describe("open, add: the characters in the scene, the player character included, such as [[Lena]]; at open, the character and the companions with them if left out"),
|
|
70
70
|
creatures: z.union([textList, z.record(z.string(), z.number().int())]).optional().describe('open, add: creatures as numbered copies: Annegato=2 (Annegato alone is one), or through MCP an object such as {"Annegato": 2}'),
|
|
71
71
|
who: textList.optional().describe("leave: who leaves the scene; hostile, calm: who attacks the party, or stops; use: who uses it; characters or copies, such as Annegato 2"),
|
|
72
|
-
uses: z.string().optional().describe("use: what of a turn, by the game's names, such as
|
|
73
|
-
by: z.string().optional().describe(
|
|
72
|
+
uses: z.string().optional().describe("use: what of a turn, by the game's names, such as {{uses}}"),
|
|
73
|
+
by: z.string().optional().describe("use: what gives one more, or lets it in another's turn, such as a feature"),
|
|
74
74
|
order: textList.optional().describe("order: who takes turns, in order; those left out (fallen, fled) take none"),
|
|
75
75
|
now: z.string().optional().describe('open, now: what is happening now, in one line as the player sees it, such as "The bandits overturn the tables"; never what they cannot see'),
|
|
76
76
|
summary: z.string().optional().describe("close: what happened, in one or two sentences, as the player saw it"),
|
|
@@ -436,8 +436,9 @@ function useOfTurn(root, world, input, context, current) {
|
|
|
436
436
|
if (done.spends !== undefined) {
|
|
437
437
|
spendOne(root, context, world, { name, copy: copy !== undefined, page }, done.spends, by ?? "");
|
|
438
438
|
}
|
|
439
|
-
// One who cannot act, as Stunned, is said so: the game's rule, which the master applies (pp. 91, 358).
|
|
440
|
-
const
|
|
439
|
+
// One who cannot act, as Stunned, is said so: the game's rule, which the master applies (pp. 91, 358); by its name in the campaign's language too (D-403).
|
|
440
|
+
const words = campaignSystemWords(root, context);
|
|
441
|
+
const inactive = effectsOf(page).map((effect) => effect.name).filter((effect) => systemNamed(system?.combat?.inactive ?? [], effect, words) !== undefined);
|
|
441
442
|
const warned = inactive.length === 0 ? "" : ` ${name} is ${inactive.join(", ")}: read what it may still do.`;
|
|
442
443
|
return { action: "use", line: `${done.line}${warned}` };
|
|
443
444
|
}
|
|
@@ -628,10 +629,11 @@ function withActing(root, context, before, result) {
|
|
|
628
629
|
// The player character's turn reminds what to mark of it, which the player sees on the dashboard (TRN-1); a companion's counts went right without (playtest
|
|
629
630
|
// 08); dying, the death save it starts with (DIE-5).
|
|
630
631
|
const member = findPage(world, turns.turn);
|
|
631
|
-
const turn =
|
|
632
|
+
const turn = packagesTurnStarted(root, context, turns.turn);
|
|
632
633
|
const dying = turn.lines.join(" ");
|
|
633
634
|
// Who cannot act, as one stable but still Unconscious, marks nothing.
|
|
634
|
-
const
|
|
635
|
+
const words = campaignSystemWords(root, context);
|
|
636
|
+
const inactive = member !== undefined && effectsOf(member).some((effect) => systemNamed(system?.combat?.inactive ?? [], effect.name, words) !== undefined);
|
|
635
637
|
const pc = member !== undefined && isPlayerCharacter(member);
|
|
636
638
|
const uses = !pc || dying !== "" || inactive ? [] : turnUsesOf(system);
|
|
637
639
|
const mark = uses.length > 0 ? `Mark with scene use what ${turns.turn} uses of the turn, as it happens: ${uses.join(", ")}.` : "";
|
|
@@ -639,7 +641,8 @@ function withActing(root, context, before, result) {
|
|
|
639
641
|
const quiet = pc ? "" : "Write nothing until the round is told: what you work out stays in your thinking.";
|
|
640
642
|
// What cannot be true together, once in a chat, after the system's code had its say (CHK-3).
|
|
641
643
|
const checks = newStateChecks(root, context).join(" ");
|
|
642
|
-
|
|
644
|
+
// The extensions' lines come after the engine's reminder, which only the system's take the place of (D-514).
|
|
645
|
+
const acting = [effects, dying, mark, ...turn.added, offTheMap(world, scene, turns.turn), turn.problem ?? "", checks, quiet].filter((line) => line !== "").join(" ");
|
|
643
646
|
return acting === "" ? result : { ...result, acting };
|
|
644
647
|
}
|
|
645
648
|
/** Who acts and stands on no square of the scene's map, when its place has one (GRD-3, playtest 07): where it stands decides reach, cover and the way. */
|
package/dist/commands/sheet.js
CHANGED
|
@@ -149,7 +149,16 @@ export function sheetHeadline(world, system, page, words) {
|
|
|
149
149
|
return isEmptyField(value) ? "" : declaredKind(world, field) === "list" ? listItemNames(value).map(said).join(" / ") : said(valueText(world, field, value));
|
|
150
150
|
};
|
|
151
151
|
const named = [...headline.matchAll(/\{([^{}]+)\}/g)].map((match) => shown(match[1]));
|
|
152
|
-
|
|
152
|
+
if (named.every((text) => text === "")) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
// Its parts between commas, each kept with the comma before it unless it names fields all empty: "{calling}, rank {level}" without a calling is rank 3.
|
|
156
|
+
const parts = headline.split(/(\s*[,;،、,]\s*)/);
|
|
157
|
+
const kept = parts.flatMap((part, at) => {
|
|
158
|
+
const fields = [...part.matchAll(/\{([^{}]+)\}/g)].map((match) => shown(match[1]));
|
|
159
|
+
return at % 2 === 1 || (fields.length > 0 && fields.every((text) => text === "")) ? [] : [{ text: part.replace(/\{([^{}]+)\}/g, (_, field) => shown(field)), before: parts[at - 1] ?? "" }];
|
|
160
|
+
});
|
|
161
|
+
return kept.map((part, at) => (at === 0 ? part.text : `${part.before}${part.text}`)).join("").replace(/\s+/g, " ").trim();
|
|
153
162
|
}
|
|
154
163
|
/**
|
|
155
164
|
* The stat block of a companion who keeps no sheet, as the creature it derives from writes it (D-275): one group named after the creature, with the fields the
|
package/dist/commands/status.js
CHANGED
|
@@ -5,25 +5,27 @@ import { defineCommand } from "../core/registry.js";
|
|
|
5
5
|
import { isInParty, isPartyMember, isPlayerCharacter, locate, pagesWithName, parsePageReference, playerCharacters } from "../pages/index.js";
|
|
6
6
|
import { bookTitles, readRuleBook } from "../rules/index.js";
|
|
7
7
|
import { sceneTypes } from "../scene/index.js";
|
|
8
|
+
import { rulesetSetting } from "../systems/index.js";
|
|
8
9
|
import { effectiveFields, effectsOf } from "./effect-layer.js";
|
|
10
|
+
import { installableSystems } from "./game-catalog.js";
|
|
9
11
|
import { allStateChecks, markStateChecksTold } from "./game-checks.js";
|
|
10
12
|
import { effectShown, keptEffects } from "./game-effects.js";
|
|
11
13
|
import { surroundings, surroundingsText } from "./game-environment.js";
|
|
12
14
|
import { clocksToMove, dueAdvice, dueText, isDated, isDue, plannedEvents, plannedText, worldFacts } from "./game-events.js";
|
|
13
15
|
import { experienceOf, levelDueNote } from "./game-experience.js";
|
|
14
16
|
import { extensionsLine } from "./game-extension-list.js";
|
|
15
|
-
import { extensionCodeProblems } from "./game-extensions.js";
|
|
16
17
|
import { picturesNote } from "./game-images.js";
|
|
17
18
|
import { journeyText, readJourney } from "./game-journey.js";
|
|
18
19
|
import { campaignMode, campaignNote } from "./game-mode.js";
|
|
19
20
|
import { campaignCoins } from "./game-money.js";
|
|
20
21
|
import { livingMood, masterMood } from "./game-moods.js";
|
|
22
|
+
import { packageCodeProblems } from "./game-package-code.js";
|
|
21
23
|
import { isTickedOpenQuest, openQuestText } from "./game-quests.js";
|
|
22
24
|
import { measuresOf, roadsOf } from "./game-roads.js";
|
|
23
25
|
import { interruptedLoad } from "./game-saves.js";
|
|
24
26
|
import { closedScenes, copyCounters, copyPage, partyAwayText, readOpenScene } from "./game-scene.js";
|
|
25
27
|
import { datedText, problemText, readPresent } from "./game-time.js";
|
|
26
|
-
import { campaignSystem, campaignWorld, countedByGame,
|
|
28
|
+
import { campaignSystem, campaignWorld, countedByGame, playedSettingValue, systemInStatus } from "./game-world.js";
|
|
27
29
|
import { importLine } from "./import.js";
|
|
28
30
|
import { countersText, pageCounters, partyCounters } from "./page-counters.js";
|
|
29
31
|
import { campaignProblems } from "./problems.js";
|
|
@@ -44,7 +46,7 @@ export const status = defineCommand({
|
|
|
44
46
|
input: z.object({}),
|
|
45
47
|
async run(input, context) {
|
|
46
48
|
const root = requireCampaign(context.folder);
|
|
47
|
-
const codeProblems = await
|
|
49
|
+
const codeProblems = await packageCodeProblems(root, context, []);
|
|
48
50
|
const settings = readSettings(root);
|
|
49
51
|
const world = campaignWorld(root, context);
|
|
50
52
|
const characters = world.pages.filter((page) => page.type === "character");
|
|
@@ -88,6 +90,8 @@ export const status = defineCommand({
|
|
|
88
90
|
const due = events.filter((event) => isDue(event, now, facts));
|
|
89
91
|
const closed = closedScenes(root);
|
|
90
92
|
const mode = campaignMode(root, world);
|
|
93
|
+
// Before a system is chosen, those this computer can install, beside its own (D-513 (1)).
|
|
94
|
+
const installable = settings.system === undefined ? await installableSystems(context) : [];
|
|
91
95
|
return {
|
|
92
96
|
campaign: [
|
|
93
97
|
settings.name,
|
|
@@ -103,7 +107,8 @@ export const status = defineCommand({
|
|
|
103
107
|
// How much the master teaches, only when they do (D-347).
|
|
104
108
|
named("mentor", settings.mentor === "off" ? undefined : settings.mentor),
|
|
105
109
|
// What the system adds to the setup, as advancement xp (DAT-10).
|
|
106
|
-
|
|
110
|
+
// The version of the rules is in the system's own words above (VER-1).
|
|
111
|
+
...(system?.settings ?? []).filter((setting) => setting.name !== rulesetSetting).map((setting) => named(setting.name, playedSettingValue(root, context, setting))),
|
|
107
112
|
named("mode", mode),
|
|
108
113
|
].filter((part) => part !== undefined),
|
|
109
114
|
// What the chosen difficulty and rigor mean in play, one line each (D-263).
|
|
@@ -113,6 +118,10 @@ export const status = defineCommand({
|
|
|
113
118
|
}),
|
|
114
119
|
// Before play, what the next mode needs and how to enter it; in play, the settings still missing (MOD-7).
|
|
115
120
|
note: campaignNote(root, context),
|
|
121
|
+
systems: installable.length === 0
|
|
122
|
+
? undefined
|
|
123
|
+
: `Game systems to install, if the player wants one: ${installable.map((one) => `${one.name} (${one.title}${one.verified ? "" : ", not verified"})`).join(", ")}. `
|
|
124
|
+
+ "Install the one chosen with package install and its name, then set it with config system: the campaign keeps it once it has a player character.",
|
|
116
125
|
premise: settings.premise === undefined ? undefined : `${settings.premise}${settings.preparation === undefined ? "" : ` (preparation ${settings.preparation})`}`,
|
|
117
126
|
// How the master writes, as the player chose it, under the eyes at every start (D-395).
|
|
118
127
|
writing: [
|
|
@@ -181,6 +190,7 @@ export const status = defineCommand({
|
|
|
181
190
|
result.campaign.join(" · "),
|
|
182
191
|
...result.meanings,
|
|
183
192
|
result.note,
|
|
193
|
+
result.systems ?? "",
|
|
184
194
|
result.premise === undefined ? "" : `Premise: ${result.premise}`,
|
|
185
195
|
result.writing.length === 0 ? "" : `Your writing: ${result.writing.join(" · ")}`,
|
|
186
196
|
boundariesLine(result.lines, result.veils),
|
package/dist/commands/trade.js
CHANGED
|
@@ -5,6 +5,7 @@ import { defineCommand } from "../core/registry.js";
|
|
|
5
5
|
import { comparableText } from "../core/text.js";
|
|
6
6
|
import { addCoins, changeFrom, formatAmount, isSafePurse, payCoins, readAmount, takeCoins, totalOf } from "../money/index.js";
|
|
7
7
|
import { applyMove, canHold, concernsPlayer, countedText, declaredKind, inheritedFields, isPartyMember, kindNamed, locate, MoveStopped, ownField, pageNamed, parsePageReference, readEntry, stackName, } from "../pages/index.js";
|
|
8
|
+
import { coinExamples } from "./game-examples.js";
|
|
8
9
|
import { campaignCoins } from "./game-money.js";
|
|
9
10
|
import { afterMoves, pagesPlan } from "./game-moves.js";
|
|
10
11
|
import { copyName, readOpenScene } from "./game-scene.js";
|
|
@@ -19,13 +20,13 @@ export const trade = defineCommand({
|
|
|
19
20
|
description: "Buy, sell or barter in one go: what page gives and what it gets, items and money both ways, with the change in coins. "
|
|
20
21
|
+ "with is the merchant, a character, or the shop, a place that holds its goods: what is taken comes from there. "
|
|
21
22
|
+ "Each entry is money in the campaign's coins, a kind with how many, or an item with a story of its own; never a character. "
|
|
22
|
-
+ 'If one side lacks what it gives, nothing changes. Example: page Ettore, with Bottega di Ugo, gives "2
|
|
23
|
+
+ 'If one side lacks what it gives, nothing changes. Example: page Ettore, with Bottega di Ugo, gives "2 {{coin}}", gets ["Torch 5", "Hempen Rope"].',
|
|
23
24
|
group: "game",
|
|
24
25
|
positionals: ["page"],
|
|
25
26
|
input: z.object({
|
|
26
27
|
page: z.string().describe("who trades, usually the player character"),
|
|
27
28
|
with: z.string().describe("the other side: a merchant, or a shop, a place that holds its goods"),
|
|
28
|
-
gives: textList.optional().describe('what page gives: money such as "2
|
|
29
|
+
gives: textList.optional().describe('what page gives: money such as "2 {{coin}}", kinds with how many such as Torch 5, items such as Mazza di Matteo'),
|
|
29
30
|
gets: textList.optional().describe("what page gets, written the same way"),
|
|
30
31
|
why: z.string().optional().describe("what the trade is, such as bought torches at the market"),
|
|
31
32
|
}),
|
|
@@ -42,7 +43,7 @@ export const trade = defineCommand({
|
|
|
42
43
|
const gives = handed(world, coins, buyer, seller, listOf(input.gives), "page");
|
|
43
44
|
const gets = handed(world, coins, seller, buyer, listOf(input.gets), "with");
|
|
44
45
|
if (gives.money === undefined && gets.money === undefined && gives.stacks.length + gives.pages.length + gets.stacks.length + gets.pages.length === 0) {
|
|
45
|
-
throw new Error(`Give what ${buyer.name} gives, gives, and what it gets, gets, such as gives "2
|
|
46
|
+
throw new Error(`Give what ${buyer.name} gives, gives, and what it gets, gets, such as gives "2 ${coinExamples(coins).coin}", gets "Torch 5". Nothing changed.`);
|
|
46
47
|
}
|
|
47
48
|
if (gives.money !== undefined && gets.money !== undefined) {
|
|
48
49
|
throw new Error(`Money goes one way in a trade: give only the difference, on one side. To change coins, use change with to. Nothing changed.`);
|
|
@@ -104,7 +105,8 @@ function handed(world, coins, giver, taker, entries, side) {
|
|
|
104
105
|
const money = coins === undefined ? undefined : readAmount(entry, coins);
|
|
105
106
|
if (money !== undefined) {
|
|
106
107
|
if (result.money !== undefined) {
|
|
107
|
-
|
|
108
|
+
const { coin, smallCoin } = coinExamples(coins);
|
|
109
|
+
throw new Error(`Give the money ${giver.name} hands over as one amount, such as "2 ${coin} 5 ${smallCoin}". Nothing changed.`);
|
|
108
110
|
}
|
|
109
111
|
result.money = money;
|
|
110
112
|
continue;
|
|
@@ -19,7 +19,7 @@ export const translate = defineCommand({
|
|
|
19
19
|
const root = requireCampaign(context.folder);
|
|
20
20
|
const { home, page, language } = translationPlaces(context, readSettings(root).language?.toLowerCase());
|
|
21
21
|
const found = campaignSystem(root, context);
|
|
22
|
-
const system = found === undefined ? undefined : { name: found.name, folder: found.folder };
|
|
22
|
+
const system = found === undefined ? undefined : { name: found.name, folder: found.folder, ...(found.version === undefined ? {} : { version: found.version }) };
|
|
23
23
|
const answer = input.phrases === undefined ? undefined : readAnswer(input.phrases);
|
|
24
24
|
const saved = answer === undefined ? undefined : keepChatAnswer(home, page, language, system, answer);
|
|
25
25
|
if (saved !== undefined && saved.kept === 0) {
|
|
@@ -65,7 +65,7 @@ export function translationOffer(root, context) {
|
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
67
67
|
const found = campaignSystem(root, context);
|
|
68
|
-
const left = chatBatch(context.home, context.pageFolder, language, found === undefined ? undefined : { name: found.name, folder: found.folder })?.left;
|
|
68
|
+
const left = chatBatch(context.home, context.pageFolder, language, found === undefined ? undefined : { name: found.name, folder: found.folder, ...(found.version === undefined ? {} : { version: found.version }) })?.left;
|
|
69
69
|
const lacks = `The dashboard is not in ${languageName(language)} on this computer, and nothing here translates it in the background`;
|
|
70
70
|
if (left === undefined) {
|
|
71
71
|
return undefined;
|
package/dist/commands/travel.js
CHANGED
|
@@ -6,11 +6,11 @@ import { directionHelp, directionName, distanceBetween, pointAlong, pointFrom, r
|
|
|
6
6
|
import { environmentAt, locate, pageNamed, parsePageReference, playerCharacters } from "../pages/index.js";
|
|
7
7
|
import { addDuration, formatGameDate, minutesBetween } from "../time/index.js";
|
|
8
8
|
import { aroundLead, passedLines, passTime } from "./game-advance.js";
|
|
9
|
-
import { timePassedLines } from "./game-extensions.js";
|
|
10
9
|
import { journeyPoint, journeyStart, moversMap, moversNamed, moversPosition, readJourney, ridersOf, sameMovers, saveJourney, travelledSinceRest } from "./game-journey.js";
|
|
11
10
|
import { mapKey, mapOf } from "./game-maps.js";
|
|
12
11
|
import { movePages } from "./game-moves.js";
|
|
13
12
|
import { acrossHint, crossedRoads, openLegs } from "./game-open.js";
|
|
13
|
+
import { timePassedLines } from "./game-package-code.js";
|
|
14
14
|
import { nearPlaces, pointText, positionOf, regionAt } from "./game-positions.js";
|
|
15
15
|
import { dayHours, durationText, goingText, hoursText, isVehicleOnly, kindOf, lengthText, measuresOf, moversOf, noWayText, paceOf, partyLead, roadsOf, sameSpot, speedOf, stepEnd, stopOf, travellingParty, unknownOnRoad, wayFor, wayText, } from "./game-roads.js";
|
|
16
16
|
import { readOpenScene } from "./game-scene.js";
|
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { requireCampaign } from "../campaign/index.js";
|
|
3
3
|
import { defineCommand } from "../core/registry.js";
|
|
4
4
|
import { stateCheckProblems } from "./game-checks.js";
|
|
5
|
-
import {
|
|
5
|
+
import { packageCodeProblems } from "./game-package-code.js";
|
|
6
6
|
import { campaignWorld } from "./game-world.js";
|
|
7
7
|
import { campaignProblems } from "./problems.js";
|
|
8
8
|
export const validate = defineCommand({
|
|
@@ -16,7 +16,7 @@ export const validate = defineCommand({
|
|
|
16
16
|
async run(input, context) {
|
|
17
17
|
const root = requireCampaign(context.folder);
|
|
18
18
|
// And what keeps an extension's code from being used, which only loading it tells (D-441).
|
|
19
|
-
return { problems: [...campaignProblems(root, campaignWorld(root, context), context), ...await
|
|
19
|
+
return { problems: [...campaignProblems(root, campaignWorld(root, context), context), ...await packageCodeProblems(root, context, []), ...stateCheckProblems(root, context)] };
|
|
20
20
|
},
|
|
21
21
|
format(result) {
|
|
22
22
|
if (result.problems.length === 0) {
|
package/dist/commands/view.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { Mood } from "../core/mood.ts";
|
|
3
3
|
import { type NotationPart, type ThrownDie } from "../dice/index.ts";
|
|
4
|
-
import type { ActVerb, SystemWords } from "../systems/index.ts";
|
|
4
|
+
import type { ActVerb, SheetVerb, SystemWords } from "../systems/index.ts";
|
|
5
5
|
import { type CalendarDay } from "../time/index.ts";
|
|
6
6
|
import { type PlayerSetting } from "./config.ts";
|
|
7
7
|
import { type SeenEffect } from "./game-effects.ts";
|
|
@@ -10,7 +10,7 @@ import { type MoodMoment } from "./game-moods.ts";
|
|
|
10
10
|
import { type ResetPoint, type SaveMode } from "./game-saves.ts";
|
|
11
11
|
import { type ShownChapter, type ShownQuest, type ShownThought } from "./game-view-journal.ts";
|
|
12
12
|
import { type ShownMap } from "./game-view-map.ts";
|
|
13
|
-
import { type
|
|
13
|
+
import { type ShownPlace, type ShownScene } from "./game-view-place.ts";
|
|
14
14
|
import { type KnownEntry, type ShownCalendar, type ShownDocument } from "./game-view-world.ts";
|
|
15
15
|
import { type ShownImport } from "./import.ts";
|
|
16
16
|
import { type SheetGroupData, type SheetValue } from "./sheet.ts";
|
|
@@ -38,6 +38,10 @@ export interface ShownRoll {
|
|
|
38
38
|
words?: NotationPart[];
|
|
39
39
|
notation: string;
|
|
40
40
|
total: number;
|
|
41
|
+
/** What the faces mean, in place of the total, when an extension's roll says it: 4 pins, no 1 (D-505). */
|
|
42
|
+
says?: string;
|
|
43
|
+
/** How each die turned out, by its face in order, when an extension's roll says it: good, bad or none (D-507). */
|
|
44
|
+
tones?: ("good" | "bad" | null)[];
|
|
41
45
|
text: string;
|
|
42
46
|
dice: ThrownDie[];
|
|
43
47
|
}
|
|
@@ -63,8 +67,8 @@ export interface PartyMember {
|
|
|
63
67
|
mood?: Mood;
|
|
64
68
|
/** What they are, as the line under a sheet's name says it in the campaign's language: Level 3 Cleric (D-288, D-409). */
|
|
65
69
|
headline?: string;
|
|
66
|
-
/** At the system's
|
|
67
|
-
|
|
70
|
+
/** At the system's down point, as hp 0 (D-516). */
|
|
71
|
+
down?: true;
|
|
68
72
|
}
|
|
69
73
|
/** What the player may see: the party, the open quests and scene and the diary; a page as the player character knows it, whole or one section; or nothing. */
|
|
70
74
|
export type ViewResult = {
|
|
@@ -78,6 +82,8 @@ export type ViewResult = {
|
|
|
78
82
|
language?: string;
|
|
79
83
|
/** The game system's words in the campaign's language, when it has them (D-403). */
|
|
80
84
|
words?: SystemWords;
|
|
85
|
+
/** The game system's own verbs of the sheet, beside the engine's, which its words translate (D-514). */
|
|
86
|
+
verbs?: Record<string, SheetVerb>;
|
|
81
87
|
/** The game system the campaign plays, for the dashboard: its name, what it is, and what its source asks a work that uses it to say (D-284). */
|
|
82
88
|
system?: {
|
|
83
89
|
name: string;
|
|
@@ -234,6 +240,8 @@ export declare const view: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
234
240
|
language?: string;
|
|
235
241
|
/** The game system's words in the campaign's language, when it has them (D-403). */
|
|
236
242
|
words?: SystemWords;
|
|
243
|
+
/** The game system's own verbs of the sheet, beside the engine's, which its words translate (D-514). */
|
|
244
|
+
verbs?: Record<string, SheetVerb>;
|
|
237
245
|
/** The game system the campaign plays, for the dashboard: its name, what it is, and what its source asks a work that uses it to say (D-284). */
|
|
238
246
|
system?: {
|
|
239
247
|
name: string;
|
package/dist/commands/view.js
CHANGED
|
@@ -27,7 +27,7 @@ import { calendarDayOf, readPresent } from "./game-time.js";
|
|
|
27
27
|
import { fuelLeft } from "./game-upkeep.js";
|
|
28
28
|
import { questText, shownJournal } from "./game-view-journal.js";
|
|
29
29
|
import { mapText, shownMap } from "./game-view-map.js";
|
|
30
|
-
import {
|
|
30
|
+
import { isDown, sceneNames, seenEffect, shownPlace, shownScene, strangerImage } from "./game-view-place.js";
|
|
31
31
|
import { knownDocuments, knownEntries, knownEntryText, shownCalendar } from "./game-view-world.js";
|
|
32
32
|
import { campaignSystem, campaignWorld, systemWordsOf } from "./game-world.js";
|
|
33
33
|
import { importShown } from "./import.js";
|
|
@@ -179,15 +179,15 @@ export const view = defineCommand({
|
|
|
179
179
|
const system = campaignSystem(root, context);
|
|
180
180
|
const open = readJourney(root)?.at !== undefined;
|
|
181
181
|
const companions = world.pages.filter((page) => page.type === "character" && page.fields.role === "companion");
|
|
182
|
-
const
|
|
182
|
+
const language = readSettings(root).language;
|
|
183
|
+
const memberWords = system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context);
|
|
184
|
+
const sight = { root, context, world, knowledge, party: [...players, ...companions], ...(memberWords === undefined ? {} : { words: memberWords.words }) };
|
|
183
185
|
if (input.as !== undefined) {
|
|
184
186
|
return memoryOf({ ...sight, party: isPartyMember(pc) ? world.pages.filter((page) => page.type === "character" && isPartyMember(page)) : [pc] });
|
|
185
187
|
}
|
|
186
188
|
if (input.map === true) {
|
|
187
189
|
return { kind: "map", ...shownMap(sight, measuresOf(root, system), readSettings(root).name) };
|
|
188
190
|
}
|
|
189
|
-
const language = readSettings(root).language;
|
|
190
|
-
const memberWords = system === undefined || language === undefined ? undefined : systemWordsOf(system, language, context);
|
|
191
191
|
// Where someone is, as far as the character knows the places: elsewhere when it knows none of them (D-254).
|
|
192
192
|
const member = (page) => {
|
|
193
193
|
const chain = locate(world, page).chain;
|
|
@@ -196,7 +196,7 @@ export const view = defineCommand({
|
|
|
196
196
|
const place = where.length > 0 ? where : chain.length > 0 ? "elsewhere" : open ? "open" : undefined;
|
|
197
197
|
const image = shownImage(root, context, world, page, (base) => knowsPage(knowledge, base));
|
|
198
198
|
const mood = livingMood(page);
|
|
199
|
-
const
|
|
199
|
+
const down = isDown(world, system, page);
|
|
200
200
|
const headline = sheetHeadline(world, system, page, memberWords);
|
|
201
201
|
const icon = tokenIcon(world, system, page);
|
|
202
202
|
return {
|
|
@@ -212,7 +212,7 @@ export const view = defineCommand({
|
|
|
212
212
|
return { ...seenEffect(sight, effect), ...(burns === undefined ? {} : { burns }) };
|
|
213
213
|
}),
|
|
214
214
|
...(mood === "neutral" ? {} : { mood }),
|
|
215
|
-
...(
|
|
215
|
+
...(down ? { down: true } : {}),
|
|
216
216
|
...(headline === undefined ? {} : { headline }),
|
|
217
217
|
};
|
|
218
218
|
};
|
|
@@ -237,12 +237,13 @@ export const view = defineCommand({
|
|
|
237
237
|
const openScene = shownScene(sight);
|
|
238
238
|
const settings = readSettings(root);
|
|
239
239
|
const today = now === undefined ? undefined : calendarDayOf(root, context, now.day);
|
|
240
|
-
const words = system === undefined || settings.language === undefined ? undefined : systemWordsOf(system, settings.language, context);
|
|
240
|
+
const words = system === undefined || settings.language === undefined ? undefined : systemWordsOf(root, system, settings.language, context);
|
|
241
241
|
return {
|
|
242
242
|
kind: "overview",
|
|
243
243
|
campaign: settings.name,
|
|
244
244
|
...(settings.language === undefined ? {} : { language: settings.language }),
|
|
245
245
|
...(words === undefined ? {} : { words }),
|
|
246
|
+
...(system === undefined || Object.keys(system.sheetVerbs).length === 0 ? {} : { verbs: system.sheetVerbs }),
|
|
246
247
|
...(system === undefined ? {} : { system: { name: system.name, title: system.title, ...(system.attribution === undefined ? {} : { attribution: system.attribution }) } }),
|
|
247
248
|
...(now === undefined ? {} : { now: formatGameDate(now) }),
|
|
248
249
|
...(today === undefined ? {} : { calendar: today }),
|
|
@@ -324,7 +325,7 @@ function shownPage(root, context, world, knowledge, page, party) {
|
|
|
324
325
|
// A companion who keeps no sheet shows the stat block of the creature it derives from (D-275).
|
|
325
326
|
const sheet = withItemImages(root, context, world, withCoins(speedInUnits(!party ? [] : hasSheet(world, page) ? sheetData(world, system, page) : statBlock(world, system, page), system, measuresOf(root, system)), campaignCoins(root, context).coins, system));
|
|
326
327
|
const language = readSettings(root).language;
|
|
327
|
-
const headline = party ? sheetHeadline(world, system, page, system === undefined || language === undefined ? undefined : systemWordsOf(system, language, context)) : undefined;
|
|
328
|
+
const headline = party ? sheetHeadline(world, system, page, system === undefined || language === undefined ? undefined : systemWordsOf(root, system, language, context)) : undefined;
|
|
328
329
|
const cards = party && hasSheet(world, page) ? system?.sheetCards : undefined;
|
|
329
330
|
// Only the player's own characters act from the sheet: the others act as the master says (D-495).
|
|
330
331
|
const own = isPlayerCharacter(page) && (page === knowledge.pc || knowledge.each !== undefined);
|
|
@@ -452,6 +453,8 @@ function shownRoll(world, entry, named, picture, seen) {
|
|
|
452
453
|
notation: String(data.notation ?? ""),
|
|
453
454
|
...(words === undefined ? {} : { words }),
|
|
454
455
|
total: Number(data.total ?? 0),
|
|
456
|
+
...(typeof data.says === "string" && data.says.trim() !== "" ? { says: data.says } : {}),
|
|
457
|
+
...(Array.isArray(data.tones) ? { tones: data.tones.map((tone) => (tone === "good" || tone === "bad" ? tone : null)) } : {}),
|
|
455
458
|
text: String(data.result ?? ""),
|
|
456
459
|
dice: Array.isArray(data.dice) ? data.dice : [],
|
|
457
460
|
};
|
|
@@ -182,9 +182,9 @@ function progressionFields(world, scope) {
|
|
|
182
182
|
value: value.value,
|
|
183
183
|
reads: value.from.map((from) => ({ list: progression.lists[0], item: from.name, value: from.level })),
|
|
184
184
|
}));
|
|
185
|
-
const features = progression.features.length === 0 ? [] : [{
|
|
185
|
+
const features = progression.features.length + progression.written.length === 0 ? [] : [{
|
|
186
186
|
field: progression.featuresField,
|
|
187
|
-
value: progression.features.map((feature) => feature.name).join(", "),
|
|
187
|
+
value: [...progression.features.map((feature) => feature.name), ...progression.written].join(", "),
|
|
188
188
|
reads: progression.from.map((from) => ({ list: from.list, item: from.name, value: from.level ?? 1 })),
|
|
189
189
|
}];
|
|
190
190
|
return [...values, ...features];
|
|
@@ -305,7 +305,8 @@ export function itemLines(world, fields, list, names, explained = false) {
|
|
|
305
305
|
function progressedField(world, scope, field) {
|
|
306
306
|
const found = givenFields(world, scope).find((worked) => comparableText(worked.field) === comparableText(field.trim()));
|
|
307
307
|
const list = found === undefined ? undefined : itemList(world, found.field);
|
|
308
|
-
|
|
308
|
+
// The features are written too, beside those the rows give (PRO-3).
|
|
309
|
+
if (found === undefined || comparableText(found.field) === comparableText(scope.progression()?.featuresField ?? "")) {
|
|
309
310
|
return undefined;
|
|
310
311
|
}
|
|
311
312
|
// A formula of the items' pages comes from what it reads, as the bonus an item gives, and from its list (PRO-5); the rows, from the lists alone.
|
|
@@ -739,10 +740,10 @@ function formulaScope(world, fields) {
|
|
|
739
740
|
}
|
|
740
741
|
const key = keys.get(comparableText(name));
|
|
741
742
|
const value = key === undefined ? undefined : fields[key];
|
|
742
|
-
// The effects read by their names, as has(effects, Grappled) (FOR-2).
|
|
743
|
+
// The effects read by their names, as has(effects, Grappled) (FOR-2); one named in the campaign's language by the system's English, Afferrato as Grappled (D-403).
|
|
743
744
|
if (comparableText(name) === "effects") {
|
|
744
745
|
const read = readEffects(value);
|
|
745
|
-
return "effects" in read ? read.effects.map((effect) => effect.name) : [];
|
|
746
|
+
return "effects" in read ? read.effects.map((effect) => systemName(world.words, effect.name)) : [];
|
|
746
747
|
}
|
|
747
748
|
return value === undefined ? missingValue(world, fields, name) : withAlwaysIn(world, fields, name, value);
|
|
748
749
|
},
|
|
@@ -797,3 +798,8 @@ function isSystemCounter(world, field) {
|
|
|
797
798
|
function keyOf(fields, field) {
|
|
798
799
|
return sameName(Object.keys(fields), field);
|
|
799
800
|
}
|
|
801
|
+
/** The English name the system's words give a name written in the campaign's language, Grappled for Afferrato (D-403); the name itself when they give none. */
|
|
802
|
+
function systemName(words, name) {
|
|
803
|
+
const written = comparableText(name.trim());
|
|
804
|
+
return Object.entries(words ?? {}).find(([, word]) => comparableText(word) === written)?.[0] ?? name;
|
|
805
|
+
}
|
package/dist/commands/write.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import
|
|
2
|
+
import type { Context } from "../core/context.ts";
|
|
3
|
+
import { type Page, type PageType, type TextMode, type World } from "../pages/index.ts";
|
|
3
4
|
/** What a write did, on a page or on a copy in the open scene. */
|
|
4
5
|
interface WriteResult {
|
|
5
6
|
page: string;
|
|
@@ -49,4 +50,10 @@ export declare const write: import("../core/registry.ts").Command<z.ZodObject<{
|
|
|
49
50
|
here: z.ZodOptional<z.ZodBoolean>;
|
|
50
51
|
why: z.ZodOptional<z.ZodString>;
|
|
51
52
|
}, z.core.$strip>, WriteResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Sets fields on a page for a package's code, as write --set does (D-511, D-514): the same checks, a number on a counter keeping its maximum, a field the
|
|
55
|
+
* system works out left out, the maxima worked out again. In the log, counter-changed for a counter, public when the page concerns the player, and
|
|
56
|
+
* page-updated for the other fields; nothing for a value that stays. It throws what write refuses, with how to fix it, and writes nothing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function writePackageFields(root: string, context: Context, world: World, page: Page, values: Record<string, number | string>, why: string): void;
|
|
52
59
|
export {};
|
package/dist/commands/write.js
CHANGED
|
@@ -120,30 +120,7 @@ export const write = defineCommand({
|
|
|
120
120
|
const here = input.here === true ? hereOf(root, world, reference.name, existing, type, fields) : undefined;
|
|
121
121
|
const positioned = type === "place" ? positionToWrite(world, reference.name, here === undefined ? fields : hereFields(here, fields)) : { change: fields, placed: { notes: [] } };
|
|
122
122
|
fields = positioned.change;
|
|
123
|
-
|
|
124
|
-
checkFieldNames(type, fields);
|
|
125
|
-
checkFieldChange(type, fields);
|
|
126
|
-
environmentAsSet(world, existing, type, reference.name, fields);
|
|
127
|
-
checkValues(fields);
|
|
128
|
-
// A page that keeps the sheet, as it will be written, takes only the names the sheet closes (D-435).
|
|
129
|
-
const asWritten = { name: reference.name, path: existing?.path ?? "", body: existing?.body ?? "", ...(type === undefined ? {} : { type }), fields: { ...existing?.fields, ...fields.set } };
|
|
130
|
-
const onSheet = hasSheet(world, asWritten);
|
|
131
|
-
checkListValues(system, fields.set ?? {}, onSheet);
|
|
132
|
-
checkListValues(system, fields.add ?? {}, onSheet);
|
|
133
|
-
checkKnows(world, fields);
|
|
134
|
-
if (existing !== undefined) {
|
|
135
|
-
if (changedFieldNames(fields).some(passesOn)) {
|
|
136
|
-
checkNotCopied(world, open, existing);
|
|
137
|
-
}
|
|
138
|
-
checkCounters(world, existing, fields.set, coins);
|
|
139
|
-
checkUses(world, system, existing, fields.set);
|
|
140
|
-
checkClearedCounters(world, existing, ownFieldChange(world, existing, fields), coins);
|
|
141
|
-
checkLists(world, existing, fields);
|
|
142
|
-
}
|
|
143
|
-
checkBase(world, existing?.name ?? reference.name, type, fields.set);
|
|
144
|
-
checkBonds(world, system, existing, existing?.name ?? reference.name, fields);
|
|
145
|
-
checkLimits(world, system, existing, existing?.name ?? reference.name, fields);
|
|
146
|
-
checkEventFields(world, existing, type, fields);
|
|
123
|
+
checkFieldWrite(world, system, open, coins, { existing, name: reference.name, type }, fields);
|
|
147
124
|
const written = writePage(world, reference.name, input.type, { ...fields, text: input.text, section, append: input.append, secret: input.secret });
|
|
148
125
|
const { created, changed, mode, retyped } = written;
|
|
149
126
|
if (changed) {
|
|
@@ -265,6 +242,88 @@ export const write = defineCommand({
|
|
|
265
242
|
return [[summary, followers, ...result.notes].filter((line) => line !== "").join("\n"), skippedPagesNote(result.problems)].filter((block) => block !== "").join("\n\n");
|
|
266
243
|
},
|
|
267
244
|
});
|
|
245
|
+
/**
|
|
246
|
+
* Sets fields on a page for a package's code, as write --set does (D-511, D-514): the same checks, a number on a counter keeping its maximum, a field the
|
|
247
|
+
* system works out left out, the maxima worked out again. In the log, counter-changed for a counter, public when the page concerns the player, and
|
|
248
|
+
* page-updated for the other fields; nothing for a value that stays. It throws what write refuses, with how to fix it, and writes nothing.
|
|
249
|
+
*/
|
|
250
|
+
export function writePackageFields(root, context, world, page, values, why) {
|
|
251
|
+
const { coins } = campaignCoins(root, context);
|
|
252
|
+
const system = campaignSystem(root, context);
|
|
253
|
+
if (page.system !== undefined) {
|
|
254
|
+
throw new Error(readOnlyMessage(page, Object.keys(values), world));
|
|
255
|
+
}
|
|
256
|
+
const kept = Object.fromEntries(Object.entries(values).map(([field, value]) => {
|
|
257
|
+
const own = readCounter(valueNamed(page.fields, field));
|
|
258
|
+
return [field, typeof value !== "number" || own?.max === undefined ? value : formatCounter({ ...own, value })];
|
|
259
|
+
}));
|
|
260
|
+
const given = withoutComputed(world, page, oneItemLists(world, kept, page.type), page.name, undefined);
|
|
261
|
+
if (Object.keys(given.set).length === 0) {
|
|
262
|
+
throw new Error(`${given.note ?? "Give the fields to set."} Nothing changed.`);
|
|
263
|
+
}
|
|
264
|
+
const positioned = page.type === "place" ? positionToWrite(world, page.name, { set: asAmounts(world, given.set, coins) }) : { change: { set: asAmounts(world, given.set, coins) }, placed: { notes: [] } };
|
|
265
|
+
const fields = positioned.change;
|
|
266
|
+
checkNoEffects(fields, page);
|
|
267
|
+
checkFieldWrite(world, system, readOpenScene(root), coins, { existing: page, name: page.name, type: page.type }, fields);
|
|
268
|
+
const before = effectiveFields(world, page);
|
|
269
|
+
const written = writePage(world, page.name, undefined, fields);
|
|
270
|
+
if (!written.changed) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const now = withPage(world, page, written.page);
|
|
274
|
+
const limits = systemProblems(root, context).length === 0 ? workedLimitsChange(system, world, page, now, written.page) : { set: {}, unset: [] };
|
|
275
|
+
const after = Object.keys(limits.set).length > 0 || limits.unset.length > 0 ? writePage(now, page.name, undefined, { set: limits.set, unset: limits.unset }).page : written.page;
|
|
276
|
+
const counters = Object.keys(fields.set ?? {}).filter((field) => readCounter(valueNamed(page.fields, field)) !== undefined || valueNamed(system?.fields ?? {}, field) === "counter");
|
|
277
|
+
const others = Object.fromEntries(Object.entries(fields.set ?? {}).filter(([field, value]) => !counters.includes(field) && valueNamed(page.fields, field) !== value));
|
|
278
|
+
const visibility = concernsPlayer(world, page) ? "public" : "hidden";
|
|
279
|
+
const shown = (value) => {
|
|
280
|
+
const counter = readCounter(value);
|
|
281
|
+
return value === undefined ? "0" : counter === undefined ? String(value) : String(formatCounter(counter));
|
|
282
|
+
};
|
|
283
|
+
for (const field of counters) {
|
|
284
|
+
const [was, is] = [shown(valueNamed(before, field)), shown(valueNamed(effectiveFields(withPage(world, page, after), after), field))];
|
|
285
|
+
if (was !== is) {
|
|
286
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "counter-changed", visibility, { page: page.name, field, before: was, after: is, why }));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (Object.keys(others).length > 0) {
|
|
290
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "page-updated", "hidden", { page: page.name, type: page.type, set: others, why }));
|
|
291
|
+
}
|
|
292
|
+
if (positioned.placed.origin !== undefined) {
|
|
293
|
+
writeOrigin(root, context, withPage(world, page, after), positioned.placed.origin);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The checks of write on what it is about to write on a page, new or not, and on its fields (D-435, D-514): their names and values, the lists the sheet
|
|
298
|
+
* closes, a creature's copies in the open scene, counters, uses, the base, bonds, limits and an event's fields. It throws what is wrong, with how to fix it.
|
|
299
|
+
*/
|
|
300
|
+
function checkFieldWrite(world, system, open, coins, target, fields) {
|
|
301
|
+
const { existing, name, type } = target;
|
|
302
|
+
conditionsAsList(existing, fields);
|
|
303
|
+
checkFieldNames(type, fields);
|
|
304
|
+
checkFieldChange(type, fields);
|
|
305
|
+
environmentAsSet(world, existing, type, name, fields);
|
|
306
|
+
checkValues(fields);
|
|
307
|
+
// A page that keeps the sheet, as it will be written, takes only the names the sheet closes (D-435).
|
|
308
|
+
const asWritten = { name, path: existing?.path ?? "", body: existing?.body ?? "", ...(type === undefined ? {} : { type }), fields: { ...existing?.fields, ...fields.set } };
|
|
309
|
+
const onSheet = hasSheet(world, asWritten);
|
|
310
|
+
checkListValues(system, fields.set ?? {}, onSheet);
|
|
311
|
+
checkListValues(system, fields.add ?? {}, onSheet);
|
|
312
|
+
checkKnows(world, fields);
|
|
313
|
+
if (existing !== undefined) {
|
|
314
|
+
if (changedFieldNames(fields).some(passesOn)) {
|
|
315
|
+
checkNotCopied(world, open, existing);
|
|
316
|
+
}
|
|
317
|
+
checkCounters(world, existing, fields.set, coins);
|
|
318
|
+
checkUses(world, system, existing, fields.set);
|
|
319
|
+
checkClearedCounters(world, existing, ownFieldChange(world, existing, fields), coins);
|
|
320
|
+
checkLists(world, existing, fields);
|
|
321
|
+
}
|
|
322
|
+
checkBase(world, existing?.name ?? name, type, fields.set);
|
|
323
|
+
checkBonds(world, system, existing, existing?.name ?? name, fields);
|
|
324
|
+
checkLimits(world, system, existing, existing?.name ?? name, fields);
|
|
325
|
+
checkEventFields(world, existing, type, fields);
|
|
326
|
+
}
|
|
268
327
|
/** "torce 7" written in an inventory: a count inside a text, which nothing counts, and how goods are counted instead (STK-10). */
|
|
269
328
|
function countedTextNotes(existing, page) {
|
|
270
329
|
const field = containerFieldOf(page.type);
|
|
@@ -343,7 +402,7 @@ function checkNoEffects(change, page) {
|
|
|
343
402
|
return;
|
|
344
403
|
}
|
|
345
404
|
if (changedFieldNames(change).some((name) => comparableText(name) === "effects")) {
|
|
346
|
-
throw new Error('effects change only with the effect command: action add with a name, for how long and the values it gives, such as name "
|
|
405
|
+
throw new Error('effects change only with the effect command: action add with a name, for how long and the values it gives, such as name "Protezione", for 10m, set bonus-armor=2; action end to take one away. Nothing changed.');
|
|
347
406
|
}
|
|
348
407
|
}
|
|
349
408
|
/** A standard field written in another case, such as Status, would be a field the engine does not read: refused before any other check. */
|