rpg-engine 0.17.1 → 0.18.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/commands/change/change.d.ts +1 -0
- package/dist/commands/change/recipe-pace.d.ts +5 -0
- package/dist/commands/change/recipe-pace.js +20 -1
- package/dist/commands/change/recipe.d.ts +4 -0
- package/dist/commands/change/recipe.js +9 -5
- package/dist/commands/reveal.d.ts +2 -0
- package/dist/commands/reveal.js +22 -3
- package/dist/commands/scene/close.js +3 -1
- package/dist/commands/scene/open.js +1 -1
- package/dist/commands/scene/scene.js +3 -2
- package/dist/commands/shared/packages/updates.d.ts +6 -0
- package/dist/commands/shared/packages/updates.js +114 -0
- package/dist/commands/shared/scene/scene.js +4 -0
- package/dist/commands/shared/time/recipes.d.ts +5 -0
- package/dist/commands/shared/time/recipes.js +19 -1
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +5 -0
- package/dist/commands/travel/travel.js +1 -0
- package/dist/commands/view/place.d.ts +6 -0
- package/dist/commands/view/place.js +37 -13
- package/dist/commands/view/result.d.ts +2 -0
- package/dist/commands/view/view.d.ts +1 -0
- package/dist/commands/view/view.js +34 -11
- package/dist/core/context.d.ts +5 -0
- package/dist/dashboard/app.js +1 -1
- package/dist/dashboard/dice/tray.js +7 -5
- package/dist/dashboard/parts/labels.js +26 -4
- package/dist/dashboard/parts/widgets.js +1 -1
- package/dist/dashboard/play/rolls.js +3 -3
- package/dist/dashboard/settings/setup.js +30 -13
- package/dist/dashboard/shell/table.js +7 -3
- package/dist/packages/npm.js +32 -7
- package/dist/pages/index.d.ts +1 -1
- package/dist/pages/index.js +1 -1
- package/dist/scene/scene.d.ts +4 -1
- package/instructions/combat.md +2 -2
- package/instructions/core.md +2 -2
- package/instructions/play.md +4 -4
- package/package.json +1 -1
|
@@ -2,5 +2,10 @@ import type { Context } from "../../core/context.ts";
|
|
|
2
2
|
import type { Recipe } from "../../systems/index.ts";
|
|
3
3
|
/** Why a page gains nothing from a recipe it had too recently (RST-1), as "Ettore had a long rest at day 2, 08:00: …"; undefined when it may have it. */
|
|
4
4
|
export declare function tooSoonNote(root: string, recipe: Recipe, page: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* When the last advance ended now and was shorter than the rest, as a night of 6h10 for a long rest of 8h (D-500): "The last advance covered 6h 10m (day 1,
|
|
7
|
+
* 23:50 → day 2, 06:00) …"; undefined otherwise. A watch split into advances may trip it, hence the "if".
|
|
8
|
+
*/
|
|
9
|
+
export declare function shortRestNote(root: string, recipe: Recipe): string | undefined;
|
|
5
10
|
/** Writes in the log that a recipe gave a page something, when the system counts how often it may (RST-1). */
|
|
6
11
|
export declare function logRecipeApplied(root: string, context: Context, recipe: Recipe, page: string, visibility: "public" | "hidden"): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendLogEntry, readLog } from "../../core/log.js";
|
|
2
2
|
import { comparableText } from "../../core/text.js";
|
|
3
|
-
import { addDuration, formatGameDate, minutesBetween, readDuration, readGameDate } from "../../time/index.js";
|
|
3
|
+
import { addDuration, formatDuration, formatGameDate, minutesBetween, readDuration, readGameDate } from "../../time/index.js";
|
|
4
4
|
import { newDatedLogEntry, readPresent } from "../shared/time/time.js";
|
|
5
5
|
const appliedType = "recipe-applied";
|
|
6
6
|
/** Why a page gains nothing from a recipe it had too recently (RST-1), as "Ettore had a long rest at day 2, 08:00: …"; undefined when it may have it. */
|
|
@@ -17,6 +17,25 @@ export function tooSoonNote(root, recipe, page) {
|
|
|
17
17
|
}
|
|
18
18
|
return `${page} had a ${recipe.name} at ${formatGameDate(then)}, and gains nothing from another before ${formatGameDate(addDuration(then, every))}: one in ${recipe.oncePer}.`;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* When the last advance ended now and was shorter than the rest, as a night of 6h10 for a long rest of 8h (D-500): "The last advance covered 6h 10m (day 1,
|
|
22
|
+
* 23:50 → day 2, 06:00) …"; undefined otherwise. A watch split into advances may trip it, hence the "if".
|
|
23
|
+
*/
|
|
24
|
+
export function shortRestNote(root, recipe) {
|
|
25
|
+
const lasts = recipe.lasts === undefined ? undefined : readDuration(recipe.lasts);
|
|
26
|
+
const now = readPresent(root).date;
|
|
27
|
+
const last = readLog(root).filter((entry) => entry.type === "time-advanced").at(-1);
|
|
28
|
+
const from = last === undefined ? undefined : readGameDate(String(last.data.from));
|
|
29
|
+
const to = last === undefined ? undefined : readGameDate(String(last.data.to));
|
|
30
|
+
if (lasts === undefined || now === undefined || from === undefined || to === undefined || minutesBetween(to, now) !== 0) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const covered = minutesBetween(from, to);
|
|
34
|
+
if (covered <= 0 || covered >= lasts) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return `The last advance covered ${formatDuration(covered)} (${formatGameDate(from)} → ${formatGameDate(to)}) of the ${recipe.name}'s ${recipe.lasts}: if it began at ${formatGameDate(from)}, it ends at ${formatGameDate(addDuration(from, lasts))}; advance the other ${formatDuration(lasts - covered)} before anyone acts.`;
|
|
38
|
+
}
|
|
20
39
|
/** Writes in the log that a recipe gave a page something, when the system counts how often it may (RST-1). */
|
|
21
40
|
export function logRecipeApplied(root, context, recipe, page, visibility) {
|
|
22
41
|
if (recipe.oncePer !== undefined) {
|
|
@@ -14,6 +14,8 @@ export interface RecipeOutcome {
|
|
|
14
14
|
/** The dice the recipe lets the page spend that would give something, as hit-dice-d8 2/3, which the player chooses for the player character (ASK-14). */
|
|
15
15
|
spendable: string[];
|
|
16
16
|
notBroughtBack: string[];
|
|
17
|
+
/** The counters below their maximum of the items the page carries, as Wand charges 3/7, whose text says what comes back and when. */
|
|
18
|
+
carried: string[];
|
|
17
19
|
kept: string[];
|
|
18
20
|
/** The effects without an end still on the page, which a rest may ask something of (EFF-15). */
|
|
19
21
|
resting: string;
|
|
@@ -39,6 +41,7 @@ export declare function recipeResult(root: string, context: Context, world: Worl
|
|
|
39
41
|
outcomes: RecipeOutcome[];
|
|
40
42
|
rules: string[];
|
|
41
43
|
lasts?: string;
|
|
44
|
+
short?: string;
|
|
42
45
|
buttons?: boolean;
|
|
43
46
|
physical?: boolean;
|
|
44
47
|
spent?: string;
|
|
@@ -53,6 +56,7 @@ export declare function recipeText(result: {
|
|
|
53
56
|
outcomes: RecipeOutcome[];
|
|
54
57
|
rules: string[];
|
|
55
58
|
lasts?: string;
|
|
59
|
+
short?: string;
|
|
56
60
|
buttons?: boolean;
|
|
57
61
|
physical?: boolean;
|
|
58
62
|
}): string;
|
|
@@ -11,11 +11,11 @@ import { restingEffectsNote } from "../shared/scene/reminders.js";
|
|
|
11
11
|
import { keptRolls } from "../shared/sheet/counters.js";
|
|
12
12
|
import { effectiveFields } from "../shared/sheet/effect-layer.js";
|
|
13
13
|
import { spendableDice, spendDice } from "../shared/time/dice-pool.js";
|
|
14
|
-
import { effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "../shared/time/recipes.js";
|
|
14
|
+
import { carriedCounters, effectsAtRecipe, notBroughtBack, partyPages, recipeChoices, recipeNamed, recipeTargets } from "../shared/time/recipes.js";
|
|
15
15
|
import { newDatedLogEntry } from "../shared/time/time.js";
|
|
16
16
|
import { counterStep } from "./amounts.js";
|
|
17
17
|
import { applyStep, holderNamed, pageHolder, stepNotes } from "./holder.js";
|
|
18
|
-
import { logRecipeApplied, tooSoonNote } from "./recipe-pace.js";
|
|
18
|
+
import { logRecipeApplied, shortRestNote, tooSoonNote } from "./recipe-pace.js";
|
|
19
19
|
/**
|
|
20
20
|
* A recipe of the game system applied to a page, or to the living player characters and the companions with them (DAT-4). Every page is checked before any
|
|
21
21
|
* is written.
|
|
@@ -52,7 +52,9 @@ export function recipeResult(root, context, world, input) {
|
|
|
52
52
|
});
|
|
53
53
|
// Where the dashboard serves a page, the player spends their dice there with ask (ASK-14); with physical dice, they roll their own (ASK-8).
|
|
54
54
|
const physical = readSettings(root).dice === "physical";
|
|
55
|
-
|
|
55
|
+
// A night advanced shorter than the rest, as 6h10 for a long rest of 8h (D-500): said, not refused, since the rest may have begun earlier.
|
|
56
|
+
const short = shortRestNote(root, recipe);
|
|
57
|
+
return { recipe: recipe.name, system: system.name, outcomes, rules: recipe.rules, lasts: recipe.lasts, short, buttons: context.page?.spendDice !== undefined, physical };
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
* A recipe applied to one page (DAT-4): the effects that last until one of its occasions end first (DAT-5), then each field it names goes to its maximum or to
|
|
@@ -93,6 +95,7 @@ function recipeOn(root, context, world, system, recipe, name, why) {
|
|
|
93
95
|
choices: recipeChoices(current, recipe, pageCalled(current, name)),
|
|
94
96
|
spendable: barred ? [] : spendableDice(current, recipe, pageCalled(current, name)),
|
|
95
97
|
notBroughtBack: notBroughtBack(current, system, recipe, pageCalled(current, name)),
|
|
98
|
+
carried: carriedCounters(current, pageCalled(current, name)),
|
|
96
99
|
kept: keptRolls(current, pageCalled(current, name)).map(([field, values]) => `${field} ${values.join(", ")}`),
|
|
97
100
|
barred,
|
|
98
101
|
resting: [atZero ? `At 0 ${recipe.needs ?? ""} when it began, ${name} gains nothing from it.` : tooSoon ?? "", restingEffectsNote(pageCalled(current, name))].filter((note) => note !== "").join(" "),
|
|
@@ -136,20 +139,21 @@ export function recipeText(result) {
|
|
|
136
139
|
const lines = result.outcomes.flatMap((outcome) => {
|
|
137
140
|
const done = [...outcome.ended.map((effect) => `${effect} ended`), ...outcome.steps.map(stepText)];
|
|
138
141
|
const left = outcome.notBroughtBack.length === 0 ? "" : ` Not brought back: ${outcome.notBroughtBack.join(", ")}.`;
|
|
142
|
+
const carried = outcome.carried.length === 0 ? "" : ` ${outcome.page} carries ${outcome.carried.join(", ")}: ${outcome.carried.length === 1 ? "its page says" : "their pages say"} what comes back and when; give it with change.`;
|
|
139
143
|
// The player chooses and rolls for the player character, the master for a companion (D-206, D-213).
|
|
140
144
|
const chosen = [...outcome.choices.map((choice) => ` ${outcome.pc ? "Ask the player" : `Choose for ${outcome.page}`}: ${choice}.`), spendText(outcome, result)].join("");
|
|
141
145
|
// Rolls kept for later: if this rest brings them back, they are rolled again (KEP-4).
|
|
142
146
|
const roller = outcome.pc ? "the player rolls" : "roll";
|
|
143
147
|
const kept = outcome.kept.length === 0 ? "" : ` ${outcome.page} keeps ${outcome.kept.join("; ")}: if this rest brings them back, ${roller} them again, with roll and keep.`;
|
|
144
148
|
const resting = outcome.resting === "" ? "" : ` ${outcome.resting}`;
|
|
145
|
-
return [`${outcome.page}: ${done.length === 0 ? "nothing changed" : done.join("; ")}.${chosen}${left}${kept}${resting}`, ...outcome.steps.flatMap(stepNotes).filter((note) => !note.includes("\n"))];
|
|
149
|
+
return [`${outcome.page}: ${done.length === 0 ? "nothing changed" : done.join("; ")}.${chosen}${left}${carried}${kept}${resting}`, ...outcome.steps.flatMap(stepNotes).filter((note) => !note.includes("\n"))];
|
|
146
150
|
});
|
|
147
151
|
const rules = result.rules.length === 0 ? "" : `For the rest, read ${result.rules.map((rule) => `rules "${rule}"`).join(" and ")}.`;
|
|
148
152
|
const title = `${result.recipe.charAt(0).toUpperCase()}${result.recipe.slice(1)} (a recipe of the system ${result.system}):`;
|
|
149
153
|
// A refused rest has no hours to advance (D-500).
|
|
150
154
|
const hours = result.outcomes.every((outcome) => outcome.barred)
|
|
151
155
|
? ""
|
|
152
|
-
: `The game date did not move: apply a rest once its hours${result.lasts === undefined ? "" : ` (${result.lasts})`} have passed; if they have not yet, advance them now.`;
|
|
156
|
+
: result.short ?? `The game date did not move: apply a rest once its hours${result.lasts === undefined ? "" : ` (${result.lasts})`} have passed; if they have not yet, advance them now.`;
|
|
153
157
|
const text = [title, ...lines, rules, hours].filter((line) => line !== "").join("\n");
|
|
154
158
|
return [text, ...notes.filter((note) => note.includes("\n"))].join("\n\n");
|
|
155
159
|
}
|
package/dist/commands/reveal.js
CHANGED
|
@@ -8,12 +8,13 @@ import { campaignWorld } from "./shared/campaign/world.js";
|
|
|
8
8
|
import { knownLink, knownLinks } from "./shared/characters/knowledge.js";
|
|
9
9
|
import { textList, textsOf } from "./shared/inputs.js";
|
|
10
10
|
import { placedPosition } from "./shared/places/positions.js";
|
|
11
|
-
import { copyName, readOpenScene } from "./shared/scene/scene.js";
|
|
11
|
+
import { copyName, readOpenScene, updateScene } from "./shared/scene/scene.js";
|
|
12
12
|
import { newDatedLogEntry } from "./shared/time/time.js";
|
|
13
13
|
export const reveal = defineCommand({
|
|
14
14
|
name: "reveal",
|
|
15
15
|
description: "Record what characters learn: a secret, as Page#Secret, or a whole page they did not know. "
|
|
16
16
|
+ "It adds the links to their knows and answers without the text: read a secret with show before you tell it. "
|
|
17
|
+
+ "A whole page the player's character learns that the open scene gives by seen goes by its name again, known before or not. "
|
|
17
18
|
+ "Example: page [Coppa#Veleno, Varro], to [Ettore, Bruna].",
|
|
18
19
|
group: "game",
|
|
19
20
|
positionals: ["page"],
|
|
@@ -62,17 +63,35 @@ export const reveal = defineCommand({
|
|
|
62
63
|
result.learned.push({ who: learner.name, what: learned.map((item) => (item.asked === undefined ? item.shown : `${item.shown} (as ${item.asked} shows it)`)) });
|
|
63
64
|
}
|
|
64
65
|
logLearned(root, context, world, lines);
|
|
66
|
+
const named = learners.some(isPlayerCharacter) ? namedInScene(root, context, scene, known.map((item) => item.link)) : [];
|
|
65
67
|
const unplaced = unplacedPlaces(world, lines);
|
|
66
|
-
return
|
|
68
|
+
return { ...result, ...(named.length === 0 ? {} : { named }), ...(unplaced === undefined ? {} : { unplaced }) };
|
|
67
69
|
},
|
|
68
70
|
format(result) {
|
|
69
71
|
const learned = result.learned.map((entry) => `${entry.who} now knows ${entry.what.join(", ")}.`);
|
|
70
72
|
const known = result.known.length === 0 ? "" : `Already known: ${result.known.map((entry) => `${entry.who}: ${entry.what.join(", ")}`).join("; ")}.`;
|
|
71
73
|
const notSecret = result.notSecret.length === 0 ? "" : `Not secrets, nothing to record: ${result.notSecret.map((entry) => `${entry.what} (whoever knows ${entry.page} knows it)`).join(", ")}.`;
|
|
72
74
|
const unplaced = result.unplaced === undefined ? "" : placesNote(result.unplaced.places, result.unplaced.from);
|
|
73
|
-
|
|
75
|
+
const named = result.named === undefined ? "" : `The open scene now gives ${result.named.join(", ")} by name: the player sees it, no longer what the character saw.`;
|
|
76
|
+
return [...(learned.length === 0 && named === "" ? ["Nothing new to record."] : learned), known, notSecret, named, unplaced].filter((line) => line !== "").join(" ");
|
|
74
77
|
},
|
|
75
78
|
});
|
|
79
|
+
/**
|
|
80
|
+
* Takes out of the open scene's seen the pages the player's character learns whole (D-568): from now the player sees their name; a hidden line of the log
|
|
81
|
+
* says so. The names taken out.
|
|
82
|
+
*/
|
|
83
|
+
function namedInScene(root, context, scene, learned) {
|
|
84
|
+
const pages = learned.flatMap((link) => links(link)).filter((link) => link.section === undefined).map((link) => comparableText(link.page));
|
|
85
|
+
const seen = Object.entries(scene?.seen ?? {});
|
|
86
|
+
const named = seen.filter(([name]) => pages.includes(comparableText(name))).map(([name]) => name);
|
|
87
|
+
if (scene === undefined || named.length === 0) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
const kept = seen.filter(([name]) => !named.includes(name));
|
|
91
|
+
updateScene(root, [[["seen"], kept.length === 0 ? undefined : Object.fromEntries(kept)]]);
|
|
92
|
+
appendLogEntry(root, newDatedLogEntry(root, context, "scene-changed", "hidden", { title: scene.title, named }));
|
|
93
|
+
return named;
|
|
94
|
+
}
|
|
76
95
|
/**
|
|
77
96
|
* One line in the log for each who learned something (REV-3, D-158): public only for what the player's character knows, theirs and a companion's who learned it
|
|
78
97
|
* with them; what someone else learned alone stays hidden, since a secret's name may tell too much.
|
|
@@ -125,8 +125,10 @@ function rewardLines(world, system, scene) {
|
|
|
125
125
|
const calls = party.map((page) => (held(page) ? `change ${page.name}, field ${reward.field}, by ${share}` : `write ${page.name}, set ${reward.field}=${share}`)).join("; ");
|
|
126
126
|
const kinds = [...new Set(unknown.map((item) => item.kind))];
|
|
127
127
|
const characters = overcome.filter((item) => item.character).map((item) => item.name);
|
|
128
|
+
// The share is said to the player at once, where a master who divides it right may forget it.
|
|
129
|
+
const tell = `Then tell the player what each got: ${share} ${reward.field}${party.length === 1 ? "" : " each"}.`;
|
|
128
130
|
const parts = [
|
|
129
|
-
total === 0 ? `${reward.field}:` : `${reward.field} of those overcome: ${overcome.map((item) => `${item.name} ${item.worth}`).join(", ")}, ${total} in all; ${to}: ${calls}
|
|
131
|
+
total === 0 ? `${reward.field}:` : `${reward.field} of those overcome: ${overcome.map((item) => `${item.name} ${item.worth}`).join(", ")}, ${total} in all; ${to}: ${calls}. ${tell}`,
|
|
130
132
|
characters.length === 0 ? "" : `${characters.join(", ")} ${characters.length === 1 ? "is a character" : "are characters"}: leave out any who fought on your side, and share again.`,
|
|
131
133
|
fled.length === 0 ? "" : `Fled: ${fled.map((item) => `${item.name} ${item.worth}`).join(", ")}, to count if the party overcame them.`,
|
|
132
134
|
unknown.length === 0
|
|
@@ -161,7 +161,7 @@ function copyCreatures(world, copies) {
|
|
|
161
161
|
return [...new Set(Object.values(copies).flatMap((copy) => findPage(world, parsePageReference(copy.creature).name) ?? []))];
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* What the character sees of
|
|
164
|
+
* What the character sees of someone, known by name or not (D-416, D-568), by the name of a character in the scene or of a creature with copies in it: Bandito=brigante
|
|
165
165
|
* incappucciato on the command line, {"Varro": "il mugnaio"} through MCP; none when not given.
|
|
166
166
|
*/
|
|
167
167
|
function seenOf(world, seen, characters, copies) {
|
|
@@ -36,7 +36,8 @@ export const scene = defineCommand({
|
|
|
36
36
|
+ "At open, whoever of the party is elsewhere moves to the scene's place, except in a travel scene. "
|
|
37
37
|
+ "order sets who takes turns, after rolling for it if the game does; next passes the turn; use marks what one uses of a turn: the engine counts the uses the game declares and refuses one too many. "
|
|
38
38
|
+ "now is the line the player's dashboard shows: give it at open too, and change it as the scene turns. "
|
|
39
|
-
+ "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of
|
|
39
|
+
+ "hostile marks who attacks the party, calm takes the mark off; seen gives what the character sees of someone, which the player sees instead of the name, "
|
|
40
|
+
+ "even one they know, until the scene closes or reveal names them; the player's dashboard shows both. "
|
|
40
41
|
+ "close ends the scene with a summary the player may read. Change a copy's counters with change, as for a page. "
|
|
41
42
|
+ 'Example: action open, title "Scontro all\'ossario", type combat, creatures {"Annegato": 2}.',
|
|
42
43
|
group: "game",
|
|
@@ -54,7 +55,7 @@ export const scene = defineCommand({
|
|
|
54
55
|
order: textList.optional().describe("order: who takes turns, in order; those left out (fallen, fled) take none"),
|
|
55
56
|
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'),
|
|
56
57
|
summary: z.string().optional().describe("close: what happened, in one or two sentences, as the player saw it"),
|
|
57
|
-
seen: z.union([textList, z.record(z.string(), z.string())]).optional().describe("open, add: what the character sees of
|
|
58
|
+
seen: z.union([textList, z.record(z.string(), z.string())]).optional().describe("open, add: what the character sees of someone in the scene, by its page or creature, in two or three words, never its kind when that is a secret; the player sees it instead of the name: "
|
|
58
59
|
+ 'Bandito=brigante incappucciato, or through MCP an object such as {"Varro": "il mugnaio"}'),
|
|
59
60
|
}),
|
|
60
61
|
run(given, context) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Context } from "../../../core/context.ts";
|
|
2
|
+
/**
|
|
3
|
+
* "Newer on npm: 5e 0.14.1 (here 0.11.2)…": the campaign's game system and extensions installed from npm that npm has a newer version of, one this engine reads,
|
|
4
|
+
* with the command that updates each; undefined when there is none, without npm, or offline, which is never an error.
|
|
5
|
+
*/
|
|
6
|
+
export declare function packageUpdates(root: string, context: Context): Promise<string | undefined>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Newer versions of the campaign's packages on npm (D-569): asked at most once a day and with a short wait, told to the master, never installed by themselves
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { readTextSetting } from "../../../campaign/index.js";
|
|
5
|
+
import { engineSystemsFolder } from "../../../core/context.js";
|
|
6
|
+
import { installedFromFolder } from "../../../core/files.js";
|
|
7
|
+
import { files, isInside } from "../../../core/store.js";
|
|
8
|
+
import { comparableText } from "../../../core/text.js";
|
|
9
|
+
import { isNewerVersion } from "../../../core/version.js";
|
|
10
|
+
import { findExtension, shortName } from "../../../extensions/index.js";
|
|
11
|
+
import { verifiedScope } from "../../../packages/index.js";
|
|
12
|
+
import { systemFolders } from "../../../systems/index.js";
|
|
13
|
+
import { listedExtensions } from "./extensions.js";
|
|
14
|
+
// What npm said, kept in the player's folder on this computer for a day, so that a session starts without asking it again.
|
|
15
|
+
const fileName = "package-updates.json";
|
|
16
|
+
const checkHolds = 24 * 60 * 60 * 1000;
|
|
17
|
+
/**
|
|
18
|
+
* "Newer on npm: 5e 0.14.1 (here 0.11.2)…": the campaign's game system and extensions installed from npm that npm has a newer version of, one this engine reads,
|
|
19
|
+
* with the command that updates each; undefined when there is none, without npm, or offline, which is never an error.
|
|
20
|
+
*/
|
|
21
|
+
export async function packageUpdates(root, context) {
|
|
22
|
+
const newest = context.packages?.newest;
|
|
23
|
+
const packages = campaignPackages(root, context);
|
|
24
|
+
if (newest === undefined || packages.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const known = await newestVersions(context, packages.map((one) => one.name), newest);
|
|
28
|
+
const newer = packages.flatMap((one) => {
|
|
29
|
+
const version = known[one.name];
|
|
30
|
+
return version !== undefined && isNewerVersion(version, one.version) ? [{ ...one, newer: version }] : [];
|
|
31
|
+
});
|
|
32
|
+
if (newer.length === 0) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const listed = newer.map((one) => `${one.install} ${one.newer} (here ${one.version})`).join(", ");
|
|
36
|
+
const commands = newer.map((one) => `package install ${one.install}`).join(", ");
|
|
37
|
+
return `Newer on npm: ${listed}. Tell the player; update only if they want it, with ${commands}.`;
|
|
38
|
+
}
|
|
39
|
+
/** The newest versions of these packages npm has, by name: those kept from today, else asked now and kept; none for one npm did not answer. */
|
|
40
|
+
async function newestVersions(context, names, newest) {
|
|
41
|
+
const now = context.now().getTime();
|
|
42
|
+
const kept = keptCheck(context.home);
|
|
43
|
+
if (kept !== undefined && now - kept.checked >= 0 && now - kept.checked < checkHolds && names.every((name) => name in kept.newest)) {
|
|
44
|
+
return Object.fromEntries(Object.entries(kept.newest).filter((entry) => entry[1] !== null));
|
|
45
|
+
}
|
|
46
|
+
const asked = await Promise.all(names.map(async (name) => [name, (await newest(name)) ?? null]));
|
|
47
|
+
keepCheck(context.home, now, Object.fromEntries(asked));
|
|
48
|
+
return Object.fromEntries(asked.filter((entry) => entry[1] !== null));
|
|
49
|
+
}
|
|
50
|
+
/** The game system the campaign plays and the extensions it lists, those installed from npm alone: a folder's copy, or a system the engine ships, has no newer version there. */
|
|
51
|
+
function campaignPackages(root, context) {
|
|
52
|
+
const plays = readTextSetting(root, "system");
|
|
53
|
+
const system = plays === undefined ? undefined : systemFolders(context.systemFolders).find((one) => comparableText(one.name) === comparableText(plays));
|
|
54
|
+
const manifest = system === undefined || isInside(engineSystemsFolder, system.folder) || installedFromFolder(system.folder) ? undefined : packageOf(system.folder);
|
|
55
|
+
const systemPackage = manifest === undefined || system === undefined ? [] : [{ ...manifest, install: installName(manifest.name, system.name) }];
|
|
56
|
+
const extensions = Object.keys(listedExtensions(root)).flatMap((name) => {
|
|
57
|
+
try {
|
|
58
|
+
const extension = findExtension(context.extensionFolders ?? [], name);
|
|
59
|
+
return extension === undefined || extension.linked ? [] : [{ name: extension.package, version: extension.version, install: installName(extension.package) }];
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return [...systemPackage, ...extensions];
|
|
66
|
+
}
|
|
67
|
+
/** The name package install takes for a package: one of ours by its short name, the 5e for @rpgengine/system-5e; another's by its npm name, npm: before one without a scope. */
|
|
68
|
+
function installName(name, system) {
|
|
69
|
+
if (name.startsWith(verifiedScope)) {
|
|
70
|
+
return system !== undefined && name === `${verifiedScope}system-${system}` ? system : shortName(name);
|
|
71
|
+
}
|
|
72
|
+
return name.startsWith("@") ? name : `npm:${name}`;
|
|
73
|
+
}
|
|
74
|
+
/** The name and the version a package.json in this folder gives; undefined when it has none that reads. */
|
|
75
|
+
function packageOf(folder) {
|
|
76
|
+
try {
|
|
77
|
+
const read = JSON.parse(files().text(join(folder, "package.json")) ?? "");
|
|
78
|
+
return typeof read.name === "string" && typeof read.version === "string" ? { name: read.name, version: read.version } : undefined;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** The last check, as kept in the player's folder: when, and the newest version of each package, null where npm did not answer; none when it does not read. */
|
|
85
|
+
function keptCheck(home) {
|
|
86
|
+
if (home === undefined) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const read = JSON.parse(readFileSync(join(home, fileName), "utf8"));
|
|
91
|
+
const checked = typeof read.checked === "string" ? Date.parse(read.checked) : Number.NaN;
|
|
92
|
+
const newest = read.newest !== null && typeof read.newest === "object" ? read.newest : undefined;
|
|
93
|
+
if (Number.isNaN(checked) || newest === undefined) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return { checked, newest: Object.fromEntries(Object.entries(newest).map(([name, version]) => [name, typeof version === "string" ? version : null])) };
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Keeps a check in the player's folder; a folder that cannot be written only means npm is asked again next time. */
|
|
103
|
+
function keepCheck(home, now, newest) {
|
|
104
|
+
if (home === undefined) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
mkdirSync(home, { recursive: true });
|
|
109
|
+
writeFileSync(join(home, fileName), `${JSON.stringify({ checked: new Date(now).toISOString(), newest }, null, 2)}\n`);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Nothing to keep is no reason to stop the session.
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -305,6 +305,10 @@ function sceneChangeLine(data) {
|
|
|
305
305
|
if (Array.isArray(data.left)) {
|
|
306
306
|
return `left: ${data.left.map((name) => withNumbers(String(name))).join(", ")}`;
|
|
307
307
|
}
|
|
308
|
+
// Who reveal gave back their name, no longer seen (D-568).
|
|
309
|
+
if (Array.isArray(data.named)) {
|
|
310
|
+
return `named: ${namesText(data.named)}`;
|
|
311
|
+
}
|
|
308
312
|
const seen = data.seen !== null && typeof data.seen === "object" ? Object.entries(data.seen).map(([name, said]) => `${name} as ${String(said)}`) : [];
|
|
309
313
|
const joined = Array.isArray(data.added) && data.added.length > 0 ? [`joined: ${namesText(data.added)}`] : [];
|
|
310
314
|
if (joined.length > 0 || seen.length > 0) {
|
|
@@ -32,3 +32,8 @@ export declare function recipeChoices(world: World, recipe: Recipe, page: Page):
|
|
|
32
32
|
* when they are not, such as exhaustion; each with the rule of a threshold it is at, or of one without a value, as in "exhaustion 1/6 (rules "Exhaustion")".
|
|
33
33
|
*/
|
|
34
34
|
export declare function notBroughtBack(world: World, system: GameSystem, recipe: Recipe, page: Page): string[];
|
|
35
|
+
/**
|
|
36
|
+
* The counters below their maximum of the items a page carries, also inside others, as in "Wand charges 3/7": what comes back to them, and when, only
|
|
37
|
+
* their text says, which a rest never applies by itself.
|
|
38
|
+
*/
|
|
39
|
+
export declare function carriedCounters(world: World, page: Page): string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The recipes of a game system (D-185, DAT-4): which pages a rest goes to, the effects it ends, the fields it brings back, and what it leaves to the master.
|
|
2
2
|
import { comparableText } from "../../../core/text.js";
|
|
3
3
|
import { readCounter } from "../../../counters/index.js";
|
|
4
|
-
import { isDeclaredUncounted, isInParty, locate, playerCharacters } from "../../../pages/index.js";
|
|
4
|
+
import { findPage, heldNames, isDeclaredUncounted, isInParty, locate, playerCharacters } from "../../../pages/index.js";
|
|
5
5
|
import { effectiveFields, effectsOf } from "../sheet/effect-layer.js";
|
|
6
6
|
import { formulaValue } from "../sheet/formula-scope.js";
|
|
7
7
|
import { refillAmount } from "../sheet/worked-out.js";
|
|
@@ -81,6 +81,24 @@ export function notBroughtBack(world, system, recipe, page) {
|
|
|
81
81
|
return [`${field} ${String(value).trim()}${rule === undefined ? "" : ` (rules "${rule}")`}`];
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* The counters below their maximum of the items a page carries, also inside others, as in "Wand charges 3/7": what comes back to them, and when, only
|
|
86
|
+
* their text says, which a rest never applies by itself.
|
|
87
|
+
*/
|
|
88
|
+
export function carriedCounters(world, page) {
|
|
89
|
+
return carriedItems(world, page, new Set([page])).flatMap((item) => Object.entries(effectiveFields(world, item)).flatMap(([field, value]) => {
|
|
90
|
+
const counter = isDeclaredUncounted(world, field) ? undefined : readCounter(value);
|
|
91
|
+
return counter?.max === undefined || counter.value >= counter.max ? [] : [`${item.name} ${field} ${counter.value}/${counter.max}`];
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
/** The items a holder carries, and those inside them, each once. */
|
|
95
|
+
function carriedItems(world, holder, seen) {
|
|
96
|
+
const held = heldNames(holder).flatMap((name) => findPage(world, name) ?? []).filter((item) => item.type === "item" && !seen.has(item));
|
|
97
|
+
for (const item of held) {
|
|
98
|
+
seen.add(item);
|
|
99
|
+
}
|
|
100
|
+
return held.flatMap((item) => [item, ...carriedItems(world, item, seen)]);
|
|
101
|
+
}
|
|
84
102
|
/**
|
|
85
103
|
* The regains of a recipe on these fields (DAT-4): for each, the counters it names that are spent and how many come back in all. When all that is spent comes
|
|
86
104
|
* back, or only one counter is spent, they are targets; otherwise the player chooses.
|
package/dist/commands/status.js
CHANGED
|
@@ -23,6 +23,7 @@ import { quotedOrders } from "./shared/characters/orders.js";
|
|
|
23
23
|
import { installableSystems } from "./shared/packages/catalog.js";
|
|
24
24
|
import { packageCodeProblems } from "./shared/packages/code.js";
|
|
25
25
|
import { extensionsLine } from "./shared/packages/extensions.js";
|
|
26
|
+
import { packageUpdates } from "./shared/packages/updates.js";
|
|
26
27
|
import { surroundings, surroundingsText } from "./shared/places/environment.js";
|
|
27
28
|
import { journeyText, readJourney } from "./shared/places/journey.js";
|
|
28
29
|
import { measuresOf, roadsOf } from "./shared/places/roads.js";
|
|
@@ -105,6 +106,8 @@ export const status = defineCommand({
|
|
|
105
106
|
const installable = settings.system === undefined ? await installableSystems(context) : [];
|
|
106
107
|
// The opening of an evening, once in a chat: notes said while the master read the game reached the player (playtests 15, 16).
|
|
107
108
|
const opening = firstInChat(context, "opening");
|
|
109
|
+
// At the start of a session, the campaign's packages npm has newer (D-569): once in a chat, at every status on the command line.
|
|
110
|
+
const updates = opening || context.told === undefined ? await packageUpdates(root, context) : undefined;
|
|
108
111
|
return {
|
|
109
112
|
campaign: [
|
|
110
113
|
settings.name,
|
|
@@ -150,6 +153,7 @@ export const status = defineCommand({
|
|
|
150
153
|
precedents: settings.precedents ?? [],
|
|
151
154
|
// The extensions it uses, each with what it brings (D-28).
|
|
152
155
|
extensions: extensionsLine(root, context),
|
|
156
|
+
updates,
|
|
153
157
|
houseRules: bookTitles(readRuleBook(join(root, houseRulesFolderName), "house rules")),
|
|
154
158
|
players: players.map(member),
|
|
155
159
|
companions: characters.filter((page) => page.fields.role === "companion").map(member),
|
|
@@ -217,6 +221,7 @@ export const status = defineCommand({
|
|
|
217
221
|
result.table.length === 0 ? "" : `Table: ${result.table.join("; ")}`,
|
|
218
222
|
result.precedents.length === 0 ? "" : `Precedents: ${result.precedents.join("; ")}`,
|
|
219
223
|
result.extensions,
|
|
224
|
+
result.updates ?? "",
|
|
220
225
|
result.houseRules.length === 0 ? "" : `House rules (rules): ${result.houseRules.join(", ")}`,
|
|
221
226
|
timeLine(result),
|
|
222
227
|
result.betweenSessions ?? "",
|
|
@@ -19,6 +19,7 @@ import { acrossHint, crossedRoads, openLegs } from "./open.js";
|
|
|
19
19
|
export const travel = defineCommand({
|
|
20
20
|
name: "travel",
|
|
21
21
|
description: "Make a journey: whenever the party goes somewhere, use it instead of advance and move. "
|
|
22
|
+
+ "Before anyone says how long a journey takes, ask route, which tells it without moving anyone. "
|
|
22
23
|
+ "By road it takes the quickest way, in the vehicle the party is in if any; off the roads, across and toward go through the regions and their terrain. "
|
|
23
24
|
+ "It moves the travellers and lets the time pass, stopping on arrival, at an event that comes due and at the end of the day's travel; travel again goes on from there. "
|
|
24
25
|
+ "When others go with the party, name in who everyone who goes, the party too: companions, hirelings, mounts; a vehicle goes with those in it. "
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from "../../core/context.ts";
|
|
2
2
|
import type { Effect, EffectEnd } from "../../effects/index.ts";
|
|
3
3
|
import { type Page, type World } from "../../pages/index.ts";
|
|
4
|
+
import type { Scene } from "../../scene/index.ts";
|
|
4
5
|
import type { GameSystem } from "../../systems/index.ts";
|
|
5
6
|
import { type Knowledge } from "../shared/characters/knowledge.ts";
|
|
6
7
|
import { type SeenEffect } from "../shared/scene/effects.ts";
|
|
@@ -167,6 +168,11 @@ export declare function strangerImage(root: string, context: Context, world: Wor
|
|
|
167
168
|
file: string;
|
|
168
169
|
version: number;
|
|
169
170
|
} | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Whether the open scene gives someone by what the character sees of them (D-568), by their name, a copy's or its creature's: one in the scene the master gave
|
|
173
|
+
* seen for, known by name or not, while the scene keeps them; never one of the party.
|
|
174
|
+
*/
|
|
175
|
+
export declare function seenInScene(world: World, party: Page[], scene: Pick<Scene, "with" | "copies" | "gone" | "seen"> | undefined, name: string): boolean;
|
|
170
176
|
/**
|
|
171
177
|
* "Scontro all'ossario (combat), at Ossario, with Ennio, Lena, uomo col coltello, brigante 1 and brigante 2": the open scene as the player sees it, with the words
|
|
172
178
|
* of the page (D-254, D-416): who the character does not know by what it sees of them, else someone, and two or more of them as others.
|