rpg-engine 0.1.2 → 0.2.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/README.md +3 -1
- package/dist/campaign/index.d.ts +1 -1
- package/dist/campaign/index.js +1 -1
- package/dist/campaign/settings.d.ts +5 -1
- package/dist/campaign/settings.js +18 -3
- package/dist/command-line.js +26 -8
- package/dist/commands/advance.js +26 -7
- package/dist/commands/ask.d.ts +6 -0
- package/dist/commands/ask.js +3 -3
- package/dist/commands/config.js +40 -10
- package/dist/commands/game-advance.d.ts +6 -0
- package/dist/commands/game-advance.js +9 -2
- package/dist/commands/game-extension-list.d.ts +27 -0
- package/dist/commands/game-extension-list.js +92 -0
- package/dist/commands/game-extensions.d.ts +27 -0
- package/dist/commands/game-extensions.js +177 -0
- package/dist/commands/game-mode.js +2 -1
- package/dist/commands/game-time.d.ts +15 -3
- package/dist/commands/game-time.js +76 -6
- package/dist/commands/game-world.js +6 -3
- package/dist/commands/index.js +2 -0
- package/dist/commands/package.d.ts +64 -0
- package/dist/commands/package.js +293 -0
- package/dist/commands/problems.js +3 -1
- package/dist/commands/scene.d.ts +3 -3
- package/dist/commands/sheet.js +7 -1
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +10 -5
- package/dist/commands/travel.js +4 -2
- package/dist/commands/validate.js +4 -2
- package/dist/commands/view.d.ts +5 -0
- package/dist/commands/view.js +3 -1
- package/dist/core/context.d.ts +38 -0
- package/dist/core/context.js +11 -0
- package/dist/core/instruction-parts.d.ts +10 -0
- package/dist/core/instruction-parts.js +32 -0
- package/dist/core/store.d.ts +2 -0
- package/dist/core/store.js +8 -0
- package/dist/dashboard/app.js +2 -1
- package/dist/dashboard/game-words.js +21 -0
- package/dist/dashboard/i18n/ar.json +7 -0
- package/dist/dashboard/i18n/cs.json +7 -0
- package/dist/dashboard/i18n/da.json +7 -0
- package/dist/dashboard/i18n/de.json +7 -0
- package/dist/dashboard/i18n/el.json +7 -0
- package/dist/dashboard/i18n/es.json +7 -0
- package/dist/dashboard/i18n/fi.json +7 -0
- package/dist/dashboard/i18n/fr.json +7 -0
- package/dist/dashboard/i18n/he.json +7 -0
- package/dist/dashboard/i18n/hi.json +7 -0
- package/dist/dashboard/i18n/hu.json +7 -0
- package/dist/dashboard/i18n/is.json +7 -0
- package/dist/dashboard/i18n/it.json +7 -0
- package/dist/dashboard/i18n/ja.json +7 -0
- package/dist/dashboard/i18n/ko.json +7 -0
- package/dist/dashboard/i18n/nb.json +7 -0
- package/dist/dashboard/i18n/nl.json +7 -0
- package/dist/dashboard/i18n/pl.json +7 -0
- package/dist/dashboard/i18n/pt.json +7 -0
- package/dist/dashboard/i18n/ro.json +7 -0
- package/dist/dashboard/i18n/ru.json +7 -0
- package/dist/dashboard/i18n/sv.json +7 -0
- package/dist/dashboard/i18n/tr.json +7 -0
- package/dist/dashboard/i18n/uk.json +7 -0
- package/dist/dashboard/i18n/zh.json +7 -0
- package/dist/dashboard/icons.js +1 -0
- package/dist/dashboard/top.js +5 -5
- package/dist/extensions/api.d.ts +73 -0
- package/dist/extensions/api.js +1 -0
- package/dist/extensions/extension.d.ts +43 -0
- package/dist/extensions/extension.js +113 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.js +2 -0
- package/dist/extensions/packages.d.ts +11 -0
- package/dist/extensions/packages.js +155 -0
- package/dist/index.d.ts +1 -0
- package/dist/mcp-server.js +50 -4
- package/dist/systems/game-system.d.ts +1 -5
- package/dist/systems/game-system.js +6 -31
- package/dist/systems/index.d.ts +1 -1
- package/dist/time/calendar.d.ts +36 -0
- package/dist/time/calendar.js +84 -0
- package/dist/time/index.d.ts +1 -0
- package/dist/time/index.js +2 -1
- package/package.json +2 -3
- package/systems/5e/instructions/play.md +1 -0
- package/systems/5e/system.yaml +2 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Context } from "../core/context.ts";
|
|
2
|
+
import type { Problem } from "../core/problem.ts";
|
|
3
|
+
import { type Command } from "../core/registry.ts";
|
|
4
|
+
import type { Extension } from "../extensions/index.ts";
|
|
5
|
+
import { type GameDate } from "../time/index.ts";
|
|
6
|
+
/** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
|
|
7
|
+
export declare const extensionsFolderName = "extensions";
|
|
8
|
+
/**
|
|
9
|
+
* The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
|
|
10
|
+
* master its text; by name, the package and version that give it, so that a server knows when another takes its place.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extensionCommands(root: string, context: Context, taken: string[]): Promise<{
|
|
13
|
+
commands: Command[];
|
|
14
|
+
sources: Record<string, string>;
|
|
15
|
+
problems: Problem[];
|
|
16
|
+
}>;
|
|
17
|
+
/** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
|
|
18
|
+
export declare function extensionCommandNames(extension: Extension, taken: string[]): Promise<string[]>;
|
|
19
|
+
/** Tells the loader npm has just installed: code installed again at the same version is read anew. */
|
|
20
|
+
export declare function packagesInstalled(): void;
|
|
21
|
+
/** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
|
|
22
|
+
export declare function extensionCodeProblems(root: string, context: Context, taken: string[]): Promise<Problem[]>;
|
|
23
|
+
/**
|
|
24
|
+
* What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
|
|
25
|
+
* whatever they do: one that fails says so in its line, never in place of the output.
|
|
26
|
+
*/
|
|
27
|
+
export declare function timePassedLines(root: string, context: Context, from: GameDate, to: GameDate): Promise<string[]>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
// The code of the campaign's extensions (D-63, D-428, D-436): its commands, what it does when time passes, and the API it reaches the game through.
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
12
|
+
import { parse, stringify } from "yaml";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { campaignFileName, readTextSetting, requireCampaign } from "../campaign/index.js";
|
|
15
|
+
import { appendLogEntry } from "../core/log.js";
|
|
16
|
+
import { defineCommand } from "../core/registry.js";
|
|
17
|
+
import { files } from "../core/store.js";
|
|
18
|
+
import { rollDice } from "../dice/index.js";
|
|
19
|
+
import { environmentAt, isInParty, locate } from "../pages/index.js";
|
|
20
|
+
import { formatGameDate } from "../time/index.js";
|
|
21
|
+
import { campaignExtensions, runsCode } from "./game-extension-list.js";
|
|
22
|
+
import { calendarDayOf, newDatedLogEntry, presentDate } from "./game-time.js";
|
|
23
|
+
import { campaignWorld } from "./game-world.js";
|
|
24
|
+
/** The folder of the campaign where an extension keeps its own files, its state among them (D-433, D-436). */
|
|
25
|
+
export const extensionsFolderName = "extensions";
|
|
26
|
+
/** The longest description a command of an extension may give the master, in words (D-441): it is read in every chat. */
|
|
27
|
+
const descriptionWords = 150;
|
|
28
|
+
/**
|
|
29
|
+
* The commands of the campaign's extensions whose code may run (D-63, D-428, D-441), as commands of rpg-engine: each runs with the API of D-436 and gives the
|
|
30
|
+
* master its text; by name, the package and version that give it, so that a server knows when another takes its place.
|
|
31
|
+
*/
|
|
32
|
+
export async function extensionCommands(root, context, taken) {
|
|
33
|
+
const commands = [];
|
|
34
|
+
const sources = {};
|
|
35
|
+
const problems = [];
|
|
36
|
+
for (const extension of campaignExtensions(root, context).extensions) {
|
|
37
|
+
try {
|
|
38
|
+
const own = [];
|
|
39
|
+
for (const command of (await extensionCode(extension))?.commands ?? []) {
|
|
40
|
+
own.push(asCommand(extension, command, [...taken, ...commands.map((other) => other.name), ...own.map((other) => other.name)]));
|
|
41
|
+
}
|
|
42
|
+
commands.push(...own);
|
|
43
|
+
own.forEach((command) => (sources[command.name] = `${extension.package}@${extension.version}#${installs}`));
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
problems.push(codeProblem(extension, error));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { commands, sources, problems };
|
|
50
|
+
}
|
|
51
|
+
/** The names of an extension's commands, its code loaded and checked as the campaign would use it; it throws what keeps it from being used. */
|
|
52
|
+
export async function extensionCommandNames(extension, taken) {
|
|
53
|
+
const names = [];
|
|
54
|
+
for (const command of (await extensionCode(extension))?.commands ?? []) {
|
|
55
|
+
names.push(asCommand(extension, command, [...taken, ...names]).name);
|
|
56
|
+
}
|
|
57
|
+
return names;
|
|
58
|
+
}
|
|
59
|
+
/** Tells the loader npm has just installed: code installed again at the same version is read anew. */
|
|
60
|
+
export function packagesInstalled() {
|
|
61
|
+
installs += 1;
|
|
62
|
+
}
|
|
63
|
+
/** What keeps the code of the campaign's extensions from being used, for validate and status: it loads them. */
|
|
64
|
+
export async function extensionCodeProblems(root, context, taken) {
|
|
65
|
+
return (await extensionCommands(root, context, taken)).problems;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What the campaign's extensions say after time passed from one date to another, or as the game starts, when both are the same (D-436). The time has passed
|
|
69
|
+
* whatever they do: one that fails says so in its line, never in place of the output.
|
|
70
|
+
*/
|
|
71
|
+
export async function timePassedLines(root, context, from, to) {
|
|
72
|
+
const lines = [];
|
|
73
|
+
for (const extension of campaignExtensions(root, context).extensions) {
|
|
74
|
+
try {
|
|
75
|
+
const code = await extensionCode(extension);
|
|
76
|
+
if (code?.timePassed !== undefined) {
|
|
77
|
+
lines.push(...await code.timePassed({ from: momentOf(root, context, from), to: momentOf(root, context, to) }, gameOf(root, context, extension)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// One line: the master reads it among others.
|
|
82
|
+
const why = (error instanceof Error ? error.message : String(error)).split("\n")[0].replace(/[:.]$/, "");
|
|
83
|
+
lines.push(`The extension ${extension.name} failed after the time passed: ${why}. The time did pass: do not advance again; validate says how to fix it.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return lines;
|
|
87
|
+
}
|
|
88
|
+
/** A command of an extension as a command of rpg-engine, refused when its name is not the extension's or is taken, or its description is too long. */
|
|
89
|
+
function asCommand(extension, command, taken) {
|
|
90
|
+
const name = command.name.trim();
|
|
91
|
+
const words = command.description.split(/\s+/).length;
|
|
92
|
+
if (name !== extension.name && !name.startsWith(`${extension.name}-`)) {
|
|
93
|
+
throw new Error(`its command ${name} must be named ${extension.name}, or start with ${extension.name}-`);
|
|
94
|
+
}
|
|
95
|
+
if (taken.includes(name)) {
|
|
96
|
+
throw new Error(`its command ${name} has the name of another command`);
|
|
97
|
+
}
|
|
98
|
+
if (words > descriptionWords) {
|
|
99
|
+
throw new Error(`its command ${name} has a description of ${words} words, and ${descriptionWords} at most are read`);
|
|
100
|
+
}
|
|
101
|
+
return defineCommand({
|
|
102
|
+
name,
|
|
103
|
+
description: command.description,
|
|
104
|
+
group: "game",
|
|
105
|
+
input: command.input,
|
|
106
|
+
readOnly: command.readOnly,
|
|
107
|
+
positionals: command.positionals,
|
|
108
|
+
async run(input, called) {
|
|
109
|
+
const campaign = requireCampaign(called.folder);
|
|
110
|
+
return { text: await command.run(input, gameOf(campaign, called, extension)) };
|
|
111
|
+
},
|
|
112
|
+
format: (result) => result.text,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// The code of each extension, by its file and version, loaded once for the process: an import is never undone, a new version is another.
|
|
116
|
+
const loaded = new Map();
|
|
117
|
+
let installs = 0;
|
|
118
|
+
/**
|
|
119
|
+
* The code of an extension, when it may run (D-441): its module's default export, given the kit. Where the engine itself runs from its source, as in the tests,
|
|
120
|
+
* an extension that ships its source too is loaded from it.
|
|
121
|
+
*/
|
|
122
|
+
function extensionCode(extension) {
|
|
123
|
+
const source = join(extension.folder, "src", "index.ts");
|
|
124
|
+
const entry = !runsCode(extension) ? undefined : import.meta.url.endsWith(".ts") && files().exists(source) ? source : extension.code;
|
|
125
|
+
if (entry === undefined) {
|
|
126
|
+
return Promise.resolve(undefined);
|
|
127
|
+
}
|
|
128
|
+
const url = `${pathToFileURL(entry).href}?v=${encodeURIComponent(extension.version)}&installs=${installs}`;
|
|
129
|
+
const code = loaded.get(url) ?? import(__rewriteRelativeImportExtension(url)).then((module) => {
|
|
130
|
+
if (typeof module.default !== "function") {
|
|
131
|
+
throw new Error(`its code, ${entry}, has no default export that gives its commands`);
|
|
132
|
+
}
|
|
133
|
+
return module.default({ z });
|
|
134
|
+
});
|
|
135
|
+
loaded.set(url, code);
|
|
136
|
+
return code;
|
|
137
|
+
}
|
|
138
|
+
/** The game as an extension's code reaches it (D-436): the dice, the time, where the party is, its own state and the log; nothing else is written. */
|
|
139
|
+
function gameOf(root, context, extension) {
|
|
140
|
+
const statePath = join(root, extensionsFolderName, extension.name, "state.yaml");
|
|
141
|
+
return {
|
|
142
|
+
roll: (notation) => {
|
|
143
|
+
const rolled = rollDice(notation, { random: context.random });
|
|
144
|
+
return { total: rolled.total, faces: rolled.faces, text: rolled.text };
|
|
145
|
+
},
|
|
146
|
+
now: () => {
|
|
147
|
+
const now = presentDate(root);
|
|
148
|
+
return now === undefined ? undefined : momentOf(root, context, now);
|
|
149
|
+
},
|
|
150
|
+
calendarDay: (day) => calendarDayOf(root, context, day),
|
|
151
|
+
units: () => (readTextSetting(root, "units") === "imperial" ? "imperial" : "metric"),
|
|
152
|
+
party: () => {
|
|
153
|
+
const world = campaignWorld(root, context);
|
|
154
|
+
const player = world.pages.find((page) => isInParty(page) && page.fields.role === "pc");
|
|
155
|
+
return player === undefined
|
|
156
|
+
? undefined
|
|
157
|
+
: {
|
|
158
|
+
places: locate(world, player).chain.filter((page) => page.type === "place").map((page) => page.name),
|
|
159
|
+
environment: Object.fromEntries(environmentAt(world, player).map(({ entry }) => [entry.name, entry.value])),
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
state: {
|
|
163
|
+
read: () => parse(files().text(statePath) ?? "null"),
|
|
164
|
+
write: (value) => files().write(statePath, `# The state of the extension ${extension.package}, kept by its code.\n${stringify(value, { lineWidth: 0 })}`),
|
|
165
|
+
},
|
|
166
|
+
log: (text, visibility = "hidden") => appendLogEntry(root, newDatedLogEntry(root, context, "extension", visibility, { extension: extension.name, text })),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** A game date as the API gives it: as written, its day and minute, and its day of the calendar. */
|
|
170
|
+
function momentOf(root, context, date) {
|
|
171
|
+
const calendar = calendarDayOf(root, context, date.day);
|
|
172
|
+
return { date: formatGameDate(date), day: date.day, ...(date.minute === undefined ? {} : { minute: date.minute }), ...(calendar === undefined ? {} : { calendar }) };
|
|
173
|
+
}
|
|
174
|
+
function codeProblem(extension, error) {
|
|
175
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
176
|
+
return { path: campaignFileName, message: `The code of the extension ${extension.package} cannot be used: ${why}. Its commands are left out.`, fix: `install it again, or another version, with package install ${extension.name}` };
|
|
177
|
+
}
|
|
@@ -23,6 +23,7 @@ const settingLabels = {
|
|
|
23
23
|
dice: `dice (${diceWays.join(", ")})`,
|
|
24
24
|
units: `units (${unitSystems.join(", ")})`,
|
|
25
25
|
companions: `companions (${companionWays.join(", ")})`,
|
|
26
|
+
"calendar-start": "calendar-start (when the story starts: day 1 to count only the days, or a day of the world, such as 14 April 1491)",
|
|
26
27
|
lines: 'lines ("none" is an answer)',
|
|
27
28
|
veils: 'veils ("none" is an answer)',
|
|
28
29
|
};
|
|
@@ -86,7 +87,7 @@ export function checklistLine(mode, root, context, world) {
|
|
|
86
87
|
const name = unnamed ? ` The campaign is still named after its folder, ${settings.name}: propose a name that fits the premise, and set it with config name once the player likes it.` : "";
|
|
87
88
|
// With the dashboard open, the setup's closed choices are made there, one at a time (D-370).
|
|
88
89
|
const page = mode === "setup" && context.dashboard !== undefined
|
|
89
|
-
? " The player can make the setup's choices on the dashboard, one at a time: offer it, and meanwhile ask in the chat only the premise and the
|
|
90
|
+
? " The player can make the setup's choices on the dashboard, one at a time: offer it, and meanwhile ask in the chat only the premise, the language and when the story starts. "
|
|
90
91
|
+ "Ask the rest only when they leave it to you, or once they say they are ready."
|
|
91
92
|
: "";
|
|
92
93
|
return `${missing.charAt(0).toUpperCase()}${missing.slice(1)}. When ${blocked === undefined ? "" : "none is left and "}the player confirms: ${modeCall(next)}.${name}${page}`;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Context } from "../core/context.ts";
|
|
2
2
|
import { type LogEntry } from "../core/log.ts";
|
|
3
3
|
import type { Problem } from "../core/problem.ts";
|
|
4
|
-
import { type GameDate } from "../time/index.ts";
|
|
4
|
+
import { type Calendar, type CalendarDay, type CalendarStart, type GameDate } from "../time/index.ts";
|
|
5
|
+
/** The campaign's calendar and the day of it that is day 1, if the story starts on one (TIM-8); what does not read is a problem, never a stop. */
|
|
6
|
+
export interface CampaignCalendar {
|
|
7
|
+
calendar: Calendar;
|
|
8
|
+
start?: CalendarStart;
|
|
9
|
+
problems: Problem[];
|
|
10
|
+
}
|
|
5
11
|
/** The present of the game: its date, or the problem that keeps state.yaml from giving one; neither before the game has a date. */
|
|
6
12
|
export declare function readPresent(root: string): {
|
|
7
13
|
date?: GameDate;
|
|
@@ -13,5 +19,11 @@ export declare function presentDate(root: string): GameDate | undefined;
|
|
|
13
19
|
export declare function problemText(problem: Problem): string;
|
|
14
20
|
/** A new line for the log, stamped with the game date when the game has one that can be read (D-66). It never fails: validate reports a state.yaml it cannot read. */
|
|
15
21
|
export declare function newDatedLogEntry(root: string, context: Context, type: string, visibility: LogEntry["visibility"], data: Record<string, unknown>): LogEntry;
|
|
16
|
-
/** The problems of the game time: a state.yaml that cannot give the game date. The planned events have their own (eventProblems). */
|
|
17
|
-
export declare function timeProblems(root: string): Problem[];
|
|
22
|
+
/** The problems of the game time: a state.yaml that cannot give the game date, a calendar or its start that do not read. The planned events have their own (eventProblems). */
|
|
23
|
+
export declare function timeProblems(root: string, context: Context): Problem[];
|
|
24
|
+
/** The campaign's calendar (TIM-8): campaign.yaml's, else an extension's, else the core's real months; and its start. Read once until campaign.yaml changes. */
|
|
25
|
+
export declare function campaignCalendar(root: string, context: Context): CampaignCalendar;
|
|
26
|
+
/** The day of the calendar that a game day falls on; undefined without a calendar or its start. */
|
|
27
|
+
export declare function calendarDayOf(root: string, context: Context, gameDay: number): CalendarDay | undefined;
|
|
28
|
+
/** A game date with its day of the calendar, as outputs write it: day 15, 07:00 (15 April, spring); the date alone when the story counts only the days. */
|
|
29
|
+
export declare function datedText(root: string, context: Context, date: GameDate): string;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
// The game time as several commands use it: the present date from state.yaml,
|
|
2
|
-
import {
|
|
1
|
+
// The game time as several commands use it: the present date from state.yaml, the log lines stamped with it, and the calendar that shows it.
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { campaignFileName, readOneSetting, readState, readTextSetting } from "../campaign/index.js";
|
|
3
4
|
import { newLogEntry } from "../core/log.js";
|
|
5
|
+
import { files } from "../core/store.js";
|
|
4
6
|
import { isEmptyField } from "../pages/index.js";
|
|
5
|
-
import { formatGameDate, readGameDate } from "../time/index.js";
|
|
7
|
+
import { calendarDay, formatCalendarDay, formatGameDate, readCalendar, readCalendarStart, readGameDate, realCalendar } from "../time/index.js";
|
|
8
|
+
import { campaignExtensions, extensionSources } from "./game-extension-list.js";
|
|
6
9
|
/** The present of the game: its date, or the problem that keeps state.yaml from giving one; neither before the game has a date. */
|
|
7
10
|
export function readPresent(root) {
|
|
8
11
|
let text;
|
|
@@ -35,8 +38,75 @@ export function newDatedLogEntry(root, context, type, visibility, data) {
|
|
|
35
38
|
const { date } = readPresent(root);
|
|
36
39
|
return newLogEntry(context, type, visibility, data, date === undefined ? undefined : formatGameDate(date));
|
|
37
40
|
}
|
|
38
|
-
/** The problems of the game time: a state.yaml that cannot give the game date. The planned events have their own (eventProblems). */
|
|
39
|
-
export function timeProblems(root) {
|
|
41
|
+
/** The problems of the game time: a state.yaml that cannot give the game date, a calendar or its start that do not read. The planned events have their own (eventProblems). */
|
|
42
|
+
export function timeProblems(root, context) {
|
|
40
43
|
const { problem } = readPresent(root);
|
|
41
|
-
return problem === undefined ? [] : [problem];
|
|
44
|
+
return [...(problem === undefined ? [] : [problem]), ...campaignCalendar(root, context).problems];
|
|
45
|
+
}
|
|
46
|
+
/** The campaign's calendar (TIM-8): campaign.yaml's, else an extension's, else the core's real months; and its start. Read once until campaign.yaml changes. */
|
|
47
|
+
export function campaignCalendar(root, context) {
|
|
48
|
+
return files().remember(`calendar ${resolve(root)}`, extensionSources(root, context), () => readCampaignCalendar(root, context));
|
|
49
|
+
}
|
|
50
|
+
/** The day of the calendar that a game day falls on; undefined without a calendar or its start. */
|
|
51
|
+
export function calendarDayOf(root, context, gameDay) {
|
|
52
|
+
const { calendar, start } = campaignCalendar(root, context);
|
|
53
|
+
return start === undefined ? undefined : calendarDay(calendar, start, gameDay);
|
|
54
|
+
}
|
|
55
|
+
/** A game date with its day of the calendar, as outputs write it: day 15, 07:00 (15 April, spring); the date alone when the story counts only the days. */
|
|
56
|
+
export function datedText(root, context, date) {
|
|
57
|
+
const day = calendarDayOf(root, context, date.day);
|
|
58
|
+
return day === undefined ? formatGameDate(date) : `${formatGameDate(date)} (${formatCalendarDay(day)})`;
|
|
59
|
+
}
|
|
60
|
+
function readCampaignCalendar(root, context) {
|
|
61
|
+
const problem = (error, fix) => ({ path: campaignFileName, message: error instanceof Error ? error.message : String(error), fix });
|
|
62
|
+
const { calendar: brought, problems } = extensionsCalendar(root, context);
|
|
63
|
+
let written;
|
|
64
|
+
try {
|
|
65
|
+
written = readOneSetting(root, "calendar");
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// A campaign.yaml that does not read is checkSettings' problem.
|
|
69
|
+
return { calendar: brought, problems };
|
|
70
|
+
}
|
|
71
|
+
let calendar = brought;
|
|
72
|
+
try {
|
|
73
|
+
calendar = isEmptyField(written) ? brought : readCalendar(written);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
return { calendar, problems: [...problems, problem(error, "fix calendar in campaign.yaml by hand, or take it away with config calendar none")] };
|
|
77
|
+
}
|
|
78
|
+
const startText = readTextSetting(root, "calendar-start");
|
|
79
|
+
if (startText === undefined) {
|
|
80
|
+
return { calendar, problems };
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
return { calendar, start: readCalendarStart(startText, calendar), problems };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { calendar, problems: [...problems, problem(error, "set it again with config calendar-start")] };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** The calendar of the campaign's extensions, the last listed that brings one winning over the core's real months (TIM-8); two that bring one are a problem. */
|
|
90
|
+
function extensionsCalendar(root, context) {
|
|
91
|
+
const bringing = campaignExtensions(root, context).extensions.filter((extension) => extension.calendar !== undefined);
|
|
92
|
+
const problems = [];
|
|
93
|
+
let calendar = realCalendar;
|
|
94
|
+
for (const extension of bringing) {
|
|
95
|
+
try {
|
|
96
|
+
calendar = readCalendar(extension.calendar);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
100
|
+
problems.push({ path: campaignFileName, message: `The extension ${extension.name} brings a calendar that does not read: ${why}`, fix: `install it again with package install ${extension.name}` });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (bringing.length > 1) {
|
|
104
|
+
const names = bringing.map((extension) => extension.name);
|
|
105
|
+
problems.push({
|
|
106
|
+
path: campaignFileName,
|
|
107
|
+
message: `The extensions ${names.join(", ")} each bring a calendar: the last, ${names.at(-1) ?? ""}, holds.`,
|
|
108
|
+
fix: "take away one of them with package remove, or write the campaign's own calendar with config calendar",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return { calendar, problems };
|
|
42
112
|
}
|
|
@@ -4,6 +4,7 @@ import { files, isInside } from "../core/store.js";
|
|
|
4
4
|
import { comparableText } from "../core/text.js";
|
|
5
5
|
import { loadWorld, searchSystemPages, worldFolderName } from "../pages/index.js";
|
|
6
6
|
import { findCampaignSystem, findSystem, installedSystems, withSettings } from "../systems/index.js";
|
|
7
|
+
import { campaignExtensions, extensionSources, layeredParts } from "./game-extension-list.js";
|
|
7
8
|
/** The world of the campaign in `root`, with the pages of its game system when campaign.yaml names one that is installed (SYS-1, SYS-3). */
|
|
8
9
|
export function campaignWorld(root, context) {
|
|
9
10
|
// The same world until one of its pages or campaign.yaml changes: in a session, across calls (D-137). A game system does not change while the server runs.
|
|
@@ -27,11 +28,13 @@ export function campaignSystem(root, context) {
|
|
|
27
28
|
* a call asks for it many times.
|
|
28
29
|
*/
|
|
29
30
|
function systemOf(root, context) {
|
|
30
|
-
|
|
31
|
-
return files().remember(`system ${resolve(root)}`, (
|
|
31
|
+
// campaign.yaml, and the extensions' packages, whose parts it gives.
|
|
32
|
+
return files().remember(`system ${resolve(root)}`, extensionSources(root, context), () => {
|
|
32
33
|
const name = readTextSetting(root, "system");
|
|
33
34
|
const found = name === undefined ? {} : findCampaignSystem(context.systemFolders, name, readCampaignData(root));
|
|
34
|
-
|
|
35
|
+
// And the parts of the instructions of its extensions over its own (D-121).
|
|
36
|
+
const played = found.system === undefined ? undefined : withSettings(found.system, (setting) => readTextSetting(root, setting));
|
|
37
|
+
return played === undefined ? found : { ...found, system: { ...played, parts: layeredParts(played.parts, campaignExtensions(root, context).extensions) } };
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
/** A setting the campaign's game system adds to the setup (DAT-10), by its name in any case; undefined when the system has none by that name. */
|
package/dist/commands/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { instructions } from "./instructions.js";
|
|
|
11
11
|
import { mode } from "./mode.js";
|
|
12
12
|
import { mood } from "./mood.js";
|
|
13
13
|
import { move } from "./move.js";
|
|
14
|
+
import { packageCommand } from "./package.js";
|
|
14
15
|
import { rename } from "./rename.js";
|
|
15
16
|
import { reveal } from "./reveal.js";
|
|
16
17
|
import { roll } from "./roll.js";
|
|
@@ -54,4 +55,5 @@ export const commands = [
|
|
|
54
55
|
save,
|
|
55
56
|
translate,
|
|
56
57
|
install,
|
|
58
|
+
packageCommand,
|
|
57
59
|
];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Extension } from "../extensions/index.ts";
|
|
3
|
+
type PackageResult = {
|
|
4
|
+
kind: "list";
|
|
5
|
+
installed: Installed[];
|
|
6
|
+
missing: string[];
|
|
7
|
+
} | {
|
|
8
|
+
kind: "available";
|
|
9
|
+
packages: Available[];
|
|
10
|
+
failed?: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "installed";
|
|
13
|
+
extension: Extension;
|
|
14
|
+
verified: boolean;
|
|
15
|
+
commands: string[];
|
|
16
|
+
codeLeftOut: boolean;
|
|
17
|
+
already: boolean;
|
|
18
|
+
part?: string;
|
|
19
|
+
tools: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "removed";
|
|
22
|
+
name: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "uninstalled";
|
|
25
|
+
name: string;
|
|
26
|
+
wasUsed: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** A package on this computer, as list gives it to the master and to the dashboard; broken when it does not read (D-442). */
|
|
29
|
+
type Installed = {
|
|
30
|
+
name: string;
|
|
31
|
+
package: string;
|
|
32
|
+
version: string;
|
|
33
|
+
title: string;
|
|
34
|
+
about: string;
|
|
35
|
+
verified: boolean;
|
|
36
|
+
used: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
name: string;
|
|
39
|
+
package: string;
|
|
40
|
+
broken: string;
|
|
41
|
+
};
|
|
42
|
+
/** A package on npm for this rpg-engine, with the version installed here, if any, and whether it is newer (D-442). */
|
|
43
|
+
interface Available {
|
|
44
|
+
name: string;
|
|
45
|
+
package: string;
|
|
46
|
+
version: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
author?: string;
|
|
49
|
+
verified: boolean;
|
|
50
|
+
installed?: string;
|
|
51
|
+
update: boolean;
|
|
52
|
+
}
|
|
53
|
+
export declare const packageCommand: import("../core/registry.ts").Command<z.ZodObject<{
|
|
54
|
+
action: z.ZodEnum<{
|
|
55
|
+
remove: "remove";
|
|
56
|
+
list: "list";
|
|
57
|
+
install: "install";
|
|
58
|
+
available: "available";
|
|
59
|
+
uninstall: "uninstall";
|
|
60
|
+
}>;
|
|
61
|
+
name: z.ZodOptional<z.ZodString>;
|
|
62
|
+
"accept-risk": z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
}, z.core.$strip>, PackageResult>;
|
|
64
|
+
export {};
|