rpg-engine 0.13.0 → 0.14.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 +2 -0
- package/dist/campaign/choices.d.ts +30 -0
- package/dist/campaign/choices.js +84 -0
- package/dist/campaign/index.d.ts +4 -1
- package/dist/campaign/index.js +4 -1
- package/dist/campaign/last-choices.d.ts +6 -0
- package/dist/campaign/last-choices.js +34 -0
- package/dist/campaign/levels.d.ts +50 -0
- package/dist/campaign/levels.js +189 -0
- package/dist/campaign/settings.d.ts +35 -13
- package/dist/campaign/settings.js +20 -51
- package/dist/commands/ask.d.ts +8 -0
- package/dist/commands/ask.js +2 -1
- package/dist/commands/change/change.js +6 -4
- package/dist/commands/choices.d.ts +64 -0
- package/dist/commands/choices.js +216 -0
- package/dist/commands/config.d.ts +8 -1
- package/dist/commands/config.js +165 -21
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +8 -4
- package/dist/commands/rename.js +8 -3
- package/dist/commands/save.d.ts +1 -1
- package/dist/commands/shared/experience.d.ts +9 -2
- package/dist/commands/shared/experience.js +42 -7
- package/dist/commands/shared/knowledge.d.ts +2 -0
- package/dist/commands/shared/knowledge.js +5 -0
- package/dist/commands/shared/mode.js +10 -3
- package/dist/commands/shared/offers.d.ts +3 -1
- package/dist/commands/shared/offers.js +6 -1
- package/dist/commands/shared/rules.js +5 -1
- package/dist/commands/shared/time.d.ts +6 -0
- package/dist/commands/shared/time.js +35 -3
- package/dist/commands/shared/upkeep.js +3 -3
- package/dist/commands/shared/world.js +7 -4
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +15 -7
- package/dist/commands/view/view.js +10 -7
- package/dist/commands/write/write.js +5 -2
- package/dist/dashboard/address.js +8 -1
- package/dist/dashboard/api.js +20 -0
- package/dist/dashboard/app.js +18 -6
- package/dist/dashboard/choices.js +343 -0
- package/dist/dashboard/guide/ar.md +12 -10
- package/dist/dashboard/guide/cs.md +12 -10
- package/dist/dashboard/guide/da.md +13 -11
- package/dist/dashboard/guide/de.md +12 -10
- package/dist/dashboard/guide/el.md +14 -12
- package/dist/dashboard/guide/en.md +11 -9
- package/dist/dashboard/guide/es.md +12 -10
- package/dist/dashboard/guide/fi.md +12 -10
- package/dist/dashboard/guide/fr.md +12 -10
- package/dist/dashboard/guide/he.md +12 -10
- package/dist/dashboard/guide/hi.md +12 -10
- package/dist/dashboard/guide/hu.md +12 -10
- package/dist/dashboard/guide/is.md +13 -11
- package/dist/dashboard/guide/it.md +12 -10
- package/dist/dashboard/guide/ja.md +12 -10
- package/dist/dashboard/guide/ko.md +14 -12
- package/dist/dashboard/guide/nb.md +13 -11
- package/dist/dashboard/guide/nl.md +12 -10
- package/dist/dashboard/guide/pl.md +12 -10
- package/dist/dashboard/guide/pt.md +12 -10
- package/dist/dashboard/guide/ro.md +12 -10
- package/dist/dashboard/guide/ru.md +12 -10
- package/dist/dashboard/guide/sv.md +12 -10
- package/dist/dashboard/guide/tr.md +12 -10
- package/dist/dashboard/guide/uk.md +13 -11
- package/dist/dashboard/guide/zh.md +12 -10
- package/dist/dashboard/i18n/ar.json +80 -0
- package/dist/dashboard/i18n/cs.json +80 -0
- package/dist/dashboard/i18n/da.json +80 -0
- package/dist/dashboard/i18n/de.json +80 -0
- package/dist/dashboard/i18n/el.json +80 -0
- package/dist/dashboard/i18n/es.json +80 -0
- package/dist/dashboard/i18n/fi.json +80 -0
- package/dist/dashboard/i18n/fr.json +80 -0
- package/dist/dashboard/i18n/he.json +80 -0
- package/dist/dashboard/i18n/hi.json +80 -0
- package/dist/dashboard/i18n/hu.json +80 -0
- package/dist/dashboard/i18n/is.json +80 -0
- package/dist/dashboard/i18n/it.json +80 -0
- package/dist/dashboard/i18n/ja.json +80 -0
- package/dist/dashboard/i18n/ko.json +80 -0
- package/dist/dashboard/i18n/nb.json +80 -0
- package/dist/dashboard/i18n/nl.json +80 -0
- package/dist/dashboard/i18n/pl.json +80 -0
- package/dist/dashboard/i18n/pt.json +80 -0
- package/dist/dashboard/i18n/ro.json +80 -0
- package/dist/dashboard/i18n/ru.json +80 -0
- package/dist/dashboard/i18n/sv.json +80 -0
- package/dist/dashboard/i18n/tr.json +80 -0
- package/dist/dashboard/i18n/uk.json +80 -0
- package/dist/dashboard/i18n/zh.json +80 -0
- package/dist/dashboard/icons.js +4 -0
- package/dist/dashboard/labels.js +32 -0
- package/dist/dashboard/party.js +13 -5
- package/dist/dashboard/settings.js +89 -40
- package/dist/dashboard/setup.js +1 -1
- package/dist/dashboard/sheet.js +3 -2
- package/dist/dashboard/style.css +744 -6
- package/dist/dashboard/top.js +8 -4
- package/dist/server/dashboard/choices.d.ts +41 -0
- package/dist/server/dashboard/choices.js +176 -0
- package/dist/server/dashboard/index.js +17 -1
- package/dist/time/game-date.d.ts +9 -0
- package/dist/time/game-date.js +9 -0
- package/dist/time/index.d.ts +1 -1
- package/dist/time/index.js +1 -1
- package/instructions/dashboard-guide.md +1 -1
- package/package.json +1 -1
package/dist/dashboard/top.js
CHANGED
|
@@ -30,14 +30,14 @@ export function Top(top) {
|
|
|
30
30
|
setPoke({ id: String(Date.now()), mood: pokedMoods[Date.now() % pokedMoods.length] ?? "happy" });
|
|
31
31
|
};
|
|
32
32
|
const title = top.campaign ?? top.product;
|
|
33
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { ref: room, class: "top-room", children: [_jsx("span", { class: "top-mark far", "aria-hidden": "true" }), _jsx("span", { class: "top-mark near", "aria-hidden": "true" })] }), _jsxs("header", { ref: header, class: compact ? "top compact" : "top", children: [_jsx(MasterHome, { top: top, poke: poke, onHome: home }), _jsxs("div", { class: "titles", children: [_jsx("h1", { dir: "auto", children: _jsx("a", { class: "title-home", dir: "auto", href: sectionAddress("party"), onClick: home, children: title }) }), top.campaign !== undefined && (_jsxs("p", { class: "product", children: [top.product, top.system && _jsx("span", { class: "system-chip", children: top.system })] })), top.campaign !== undefined && top.now !== undefined && _jsx("p", { class: "product-time", children: gameDateLabel(top.now) })] }), _jsx(StatusChips, { now: top.now, calendar: top.calendar, live: top.live }), _jsx(Navigation, { current: top.section, fight: top.fight, yourTurn: top.yourTurn, turnName: top.turnName, ownPages: top.ownPages ?? [], ownShown: top.ownShown }), top.path !== undefined && top.path.length > 0 && _jsx(PlacePath, { path: top.path })] }), _jsx(ThemeCorner, {})] }));
|
|
33
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ref: room, class: "top-room", children: [_jsx("span", { class: "top-mark far", "aria-hidden": "true" }), _jsx("span", { class: "top-mark near", "aria-hidden": "true" })] }), _jsxs("header", { ref: header, class: compact ? "top compact" : "top", children: [_jsx(MasterHome, { top: top, poke: poke, onHome: home }), _jsxs("div", { class: "titles", children: [_jsx("h1", { dir: "auto", children: _jsx("a", { class: "title-home", dir: "auto", href: sectionAddress("party"), onClick: home, children: title }) }), top.campaign !== undefined && (_jsxs("p", { class: "product", children: [top.product, top.system && _jsx("span", { class: "system-chip", children: top.system })] })), top.campaign !== undefined && top.now !== undefined && _jsx("p", { class: "product-time", children: gameDateLabel(top.now) })] }), _jsx(StatusChips, { now: top.now, calendar: top.calendar, live: top.live }), _jsx(Navigation, { current: top.section, fight: top.fight, yourTurn: top.yourTurn, turnName: top.turnName, ownPages: top.ownPages ?? [], ownShown: top.ownShown, choices: top.choices }), top.path !== undefined && top.path.length > 0 && _jsx(PlacePath, { path: top.path })] }), _jsx(ThemeCorner, {})] }));
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* The sections, each a link to its address (D-276, D-309), the one shown marked, then the packages' pages that are tabs (D-512); then the saves, Help, the
|
|
37
37
|
* settings, the packages and About as icons at the row's end (D-333, D-409), the packages a menu of the packages' other pages when they have some: what does
|
|
38
38
|
* not fit goes into the menu, those icons first, then the tabs from the last.
|
|
39
39
|
*/
|
|
40
|
-
function Navigation({ current, fight, yourTurn, turnName, ownPages, ownShown }) {
|
|
40
|
+
function Navigation({ current, fight, yourTurn, turnName, ownPages, ownShown, choices }) {
|
|
41
41
|
// While the scene goes by turns the Scene's name is in gold; on the player's turn, from another section, it pulses (D-315, D-349, D-351, D-444).
|
|
42
42
|
const turns = fight === true && current !== "scene";
|
|
43
43
|
const turn = yourTurn === true && current !== "scene";
|
|
@@ -51,8 +51,12 @@ function Navigation({ current, fight, yourTurn, turnName, ownPages, ownShown })
|
|
|
51
51
|
const gone = awayTabs.includes(tab);
|
|
52
52
|
const kinds = [tab.key === "scene" && turns ? (turn ? "your-turn" : "in-turns") : "", tab.own ? "own-tab" : "", gone ? "away" : ""];
|
|
53
53
|
// The scene's whole name for a screen reader in a turn: Scene, your turn.
|
|
54
|
-
const named = tab.key === "scene" && turn
|
|
55
|
-
|
|
54
|
+
const named = tab.key === "scene" && turn
|
|
55
|
+
? `${tab.label}, ${turnName === undefined ? t("your turn") : t("It's {name}'s turn", { name: turnName })}`
|
|
56
|
+
: tab.key === "party" && choices === true
|
|
57
|
+
? t("Party, choices waiting")
|
|
58
|
+
: undefined;
|
|
59
|
+
return (_jsxs("a", { href: tab.href, class: kinds.filter((kind) => kind !== "").join(" ") || undefined, "aria-label": named, "aria-current": tab.current ? "page" : undefined, "aria-hidden": gone ? true : undefined, tabIndex: gone ? -1 : undefined, children: [_jsxs("span", { class: "section-mark", children: [tab.icon, tab.key === "party" && choices === true && _jsx("span", { class: "choices-dot", "aria-hidden": "true" })] }), _jsx("span", { class: "section-name", dir: "auto", children: tab.label })] }, tab.key));
|
|
56
60
|
}), menuPages.map((page, index) => {
|
|
57
61
|
const gone = !fitting.pages;
|
|
58
62
|
const kinds = ["page-link tip-below", index === 0 ? "pages-start" : "", gone ? "away" : ""].filter((kind) => kind !== "").join(" ");
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Served } from "./index.ts";
|
|
3
|
+
/** An option as the page shows it: the master's words, its label without dice, its dice when it is a roll, the pages it names with their titles and first sentences. */
|
|
4
|
+
export interface ShownOption {
|
|
5
|
+
text: string;
|
|
6
|
+
label: string;
|
|
7
|
+
notation?: string;
|
|
8
|
+
pages?: OptionPage[];
|
|
9
|
+
}
|
|
10
|
+
/** A page an option names: its name, its title in the campaign's language, its first sentence as the character may read it. */
|
|
11
|
+
export interface OptionPage {
|
|
12
|
+
name: string;
|
|
13
|
+
title: string;
|
|
14
|
+
opening: string;
|
|
15
|
+
}
|
|
16
|
+
/** A set of choices as the page shows it. */
|
|
17
|
+
export interface ShownChoices {
|
|
18
|
+
id: string;
|
|
19
|
+
title: string;
|
|
20
|
+
who: string;
|
|
21
|
+
made: string;
|
|
22
|
+
confirmed?: string;
|
|
23
|
+
items: {
|
|
24
|
+
question: string;
|
|
25
|
+
least: number;
|
|
26
|
+
most: number;
|
|
27
|
+
options: ShownOption[];
|
|
28
|
+
answer: string[];
|
|
29
|
+
rolled?: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
/** GET: the choices waiting, as the page shows them, and whether the player rolls their own dice. POST: an answer, a roll, or the confirm. */
|
|
33
|
+
export declare function choicesRequest(request: IncomingMessage, response: ServerResponse, served: Served): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* What the master hears at the head of their next call of the choices the player confirmed (D-556): the answers to write, with the part of the game system on
|
|
36
|
+
* what a level gives, once in a chat, as the call's told keeps it; a call that never answers keeps nothing it told, so the next one tells them again.
|
|
37
|
+
*/
|
|
38
|
+
export declare function choicesNews(served: Served, told?: Set<string>): {
|
|
39
|
+
lines: string[];
|
|
40
|
+
restore(): void;
|
|
41
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { findCampaign, readChoices, readSettings, writeChoices } from "../../campaign/index.js";
|
|
3
|
+
import { confirmedNotes, offeredPages, optionParts } from "../../commands/choices.js";
|
|
4
|
+
import { knownIntroduction, playerKnowledge, withPagesKnown } from "../../commands/shared/knowledge.js";
|
|
5
|
+
import { newDatedLogEntry } from "../../commands/shared/time.js";
|
|
6
|
+
import { campaignSystem, campaignWorld } from "../../commands/shared/world.js";
|
|
7
|
+
import { appendLogEntry } from "../../core/log.js";
|
|
8
|
+
import { withFiles } from "../../core/store.js";
|
|
9
|
+
import { firstSentence } from "../../core/text.js";
|
|
10
|
+
import { rollDice } from "../../dice/index.js";
|
|
11
|
+
import { findPage, introductionText, withoutComments } from "../../pages/index.js";
|
|
12
|
+
import { actText } from "../player-acts.js";
|
|
13
|
+
import { mostSaid, readBody, sendJson } from "./files.js";
|
|
14
|
+
import { deliverActs } from "./news.js";
|
|
15
|
+
const answerBody = z.union([
|
|
16
|
+
z.object({ id: z.string().min(1).max(64), item: z.number().int().min(0), answer: z.array(z.string().max(mostSaid)).max(200) }).strict(),
|
|
17
|
+
z.object({ id: z.string().min(1).max(64), item: z.number().int().min(0), roll: z.string().max(mostSaid), faces: z.array(z.number().int()).max(100).optional() }).strict(),
|
|
18
|
+
z.object({ id: z.string().min(1).max(64), confirm: z.literal(true), said: z.string().max(mostSaid) }).strict(),
|
|
19
|
+
]);
|
|
20
|
+
/** GET: the choices waiting, as the page shows them, and whether the player rolls their own dice. POST: an answer, a roll, or the confirm. */
|
|
21
|
+
export async function choicesRequest(request, response, served) {
|
|
22
|
+
const root = withFiles(served.session, () => findCampaign(served.context.folder));
|
|
23
|
+
if (root === undefined) {
|
|
24
|
+
sendJson(response, 404, { error: "No campaign here." });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (request.method === "GET") {
|
|
28
|
+
sendJson(response, 200, withFiles(served.session, () => shownChoices(root, served)));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const parsed = answerBody.safeParse(await readBody(request));
|
|
32
|
+
if (!parsed.success) {
|
|
33
|
+
sendJson(response, 400, { error: "Send { id, item, answer } with the options picked, { id, item, roll } with the option that rolls, or { id, confirm: true, said }." });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const body = parsed.data;
|
|
38
|
+
withFiles(served.session, () => {
|
|
39
|
+
if ("confirm" in body) {
|
|
40
|
+
confirm(root, served, body.id, body.said);
|
|
41
|
+
}
|
|
42
|
+
else if ("roll" in body) {
|
|
43
|
+
roll(root, served, body.id, body.item, body.roll, body.faces);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
answer(root, body.id, body.item, body.answer);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
served.notify();
|
|
50
|
+
sendJson(response, 200, withFiles(served.session, () => shownChoices(root, served)));
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
sendJson(response, 409, { error: error instanceof Error ? error.message : String(error) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* What the master hears at the head of their next call of the choices the player confirmed (D-556): the answers to write, with the part of the game system on
|
|
58
|
+
* what a level gives, once in a chat, as the call's told keeps it; a call that never answers keeps nothing it told, so the next one tells them again.
|
|
59
|
+
*/
|
|
60
|
+
export function choicesNews(served, told) {
|
|
61
|
+
const root = withFiles(served.session, () => findCampaign(served.context.folder));
|
|
62
|
+
const context = told === undefined ? served.context : { ...served.context, told };
|
|
63
|
+
const lines = root === undefined ? [] : withFiles(served.session, () => confirmedNotes(root, context, campaignWorld(root, served.context), campaignSystem(root, served.context)));
|
|
64
|
+
return { lines, restore: () => undefined };
|
|
65
|
+
}
|
|
66
|
+
function shownChoices(root, served) {
|
|
67
|
+
const world = campaignWorld(root, served.context);
|
|
68
|
+
// The options' pages as the player reads them to choose (VIEW-2, VIEW-3).
|
|
69
|
+
const known = playerKnowledge(root, world);
|
|
70
|
+
const knowledge = known === undefined ? undefined : withPagesKnown(known, offeredPages(root, world));
|
|
71
|
+
const sets = readChoices(root).map((set) => ({
|
|
72
|
+
id: set.id,
|
|
73
|
+
title: set.title,
|
|
74
|
+
who: set.who,
|
|
75
|
+
made: set.made,
|
|
76
|
+
...(set.confirmed === undefined ? {} : { confirmed: set.confirmed }),
|
|
77
|
+
items: set.items.map((item) => ({
|
|
78
|
+
question: item.question,
|
|
79
|
+
least: item.pick.least,
|
|
80
|
+
most: item.pick.most,
|
|
81
|
+
options: item.options.map((option) => shownOption(world, knowledge, option)),
|
|
82
|
+
answer: item.answer ?? [],
|
|
83
|
+
...(item.rolled === undefined ? {} : { rolled: item.rolled }),
|
|
84
|
+
})),
|
|
85
|
+
}));
|
|
86
|
+
return { sets, physical: readSettings(root).dice === "physical" };
|
|
87
|
+
}
|
|
88
|
+
function shownOption(world, knowledge, option) {
|
|
89
|
+
const parts = optionParts(option);
|
|
90
|
+
const found = parts.pages.map((name) => findPage(world, name)).filter((page) => page !== undefined);
|
|
91
|
+
const pages = found.filter((page, index) => found.findIndex((other) => other.name === page.name) === index).map((page) => {
|
|
92
|
+
const introduction = knowledge === undefined ? withoutComments(introductionText(page.translated ?? page.body)) : knownIntroduction(world, knowledge, page);
|
|
93
|
+
return { name: page.name, title: page.title ?? page.name, opening: firstSentence(linkWords(world, introduction).replace(/\s+/g, " ").trim()) };
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
text: option,
|
|
97
|
+
label: linkWords(world, parts.label).trim(),
|
|
98
|
+
...(parts.notation === undefined ? {} : { notation: parts.notation }),
|
|
99
|
+
...(pages.length === 0 ? {} : { pages }),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** A text's links as their words; one without words as its page's name in the campaign's language, a system page's title (D-542). */
|
|
103
|
+
function linkWords(world, text) {
|
|
104
|
+
return text.replace(/\[\[([^\]|#]+)(?:#[^\]|]*)?(?:\|([^\]]*))?\]\]/g, (_, name, words) => words ?? findPage(world, name)?.title ?? name);
|
|
105
|
+
}
|
|
106
|
+
/** The player's pick for an item, before the confirm: options of the item, as many as it allows; never one that rolls, nor in place of a roll made. */
|
|
107
|
+
function answer(root, id, index, picked) {
|
|
108
|
+
const { sets, set, item } = waiting(root, id, index);
|
|
109
|
+
const unique = [...new Set(picked)];
|
|
110
|
+
if (item.rolled !== undefined) {
|
|
111
|
+
throw new Error("A roll made stays: this choice is answered.");
|
|
112
|
+
}
|
|
113
|
+
if (unique.some((option) => !item.options.includes(option) || optionParts(option).notation !== undefined)) {
|
|
114
|
+
throw new Error("Pick among the options of this choice; one that rolls is rolled.");
|
|
115
|
+
}
|
|
116
|
+
if (unique.length > item.pick.most) {
|
|
117
|
+
throw new Error(`This choice takes at most ${item.pick.most}.`);
|
|
118
|
+
}
|
|
119
|
+
write(root, sets, set, index, { ...item, answer: unique });
|
|
120
|
+
}
|
|
121
|
+
/** An option that rolls, picked: the engine rolls it, or reads the player's own dice, logs it as the player's roll, and keeps it as the answer. */
|
|
122
|
+
function roll(root, served, id, index, option, faces) {
|
|
123
|
+
const { sets, set, item } = waiting(root, id, index);
|
|
124
|
+
const notation = item.options.includes(option) ? optionParts(option).notation : undefined;
|
|
125
|
+
if (notation === undefined) {
|
|
126
|
+
throw new Error("That option does not roll.");
|
|
127
|
+
}
|
|
128
|
+
if (item.rolled !== undefined) {
|
|
129
|
+
throw new Error("A roll made stays: this choice is answered.");
|
|
130
|
+
}
|
|
131
|
+
const physical = readSettings(root).dice === "physical";
|
|
132
|
+
if (physical !== (faces !== undefined)) {
|
|
133
|
+
throw new Error(physical ? "The player rolls their own dice here: send the faces." : "The engine rolls the dice here: send no faces.");
|
|
134
|
+
}
|
|
135
|
+
const diceRoll = rollDice(notation, faces === undefined ? { random: served.context.random } : { values: faces });
|
|
136
|
+
// The roll reads by its question, as Hit points, on the dashboard's list of rolls.
|
|
137
|
+
const why = `${item.question}: ${optionParts(option).label}`;
|
|
138
|
+
const data = { notation: diceRoll.notation, total: diceRoll.total, result: diceRoll.text, why, check: item.question, who: set.who, physical, dice: diceRoll.dice };
|
|
139
|
+
appendLogEntry(root, newDatedLogEntry(root, { ...served.context, actor: "player" }, "roll", "public", data));
|
|
140
|
+
write(root, sets, set, index, { ...item, answer: [option], rolled: diceRoll.text });
|
|
141
|
+
}
|
|
142
|
+
/** The confirm: every choice answered as it allows; the set waits for the master with its answers, and the player's sentence rings for them. */
|
|
143
|
+
function confirm(root, served, id, said) {
|
|
144
|
+
const { sets, set } = waiting(root, id, 0);
|
|
145
|
+
const open = set.items.find((item) => (item.answer ?? []).length < item.pick.least || (optionParts(item.answer?.[0] ?? "").notation !== undefined && item.rolled === undefined));
|
|
146
|
+
if (open !== undefined) {
|
|
147
|
+
throw new Error(`${open.question} still waits for an answer.`);
|
|
148
|
+
}
|
|
149
|
+
const confirmed = { ...set, confirmed: served.context.now().toISOString().slice(0, 10) };
|
|
150
|
+
writeChoices(root, sets.map((other) => (other.id === id ? confirmed : other)));
|
|
151
|
+
appendLogEntry(root, newDatedLogEntry(root, { ...served.context, actor: "player" }, "choices-confirmed", "public", { who: set.who, title: set.title }));
|
|
152
|
+
const text = actText(said);
|
|
153
|
+
if (text !== "") {
|
|
154
|
+
served.acts.pending.push({ id: served.context.newId(), text });
|
|
155
|
+
deliverActs(served);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** A set still waiting for the player, by its id, with one of its items. */
|
|
159
|
+
function waiting(root, id, index) {
|
|
160
|
+
const sets = readChoices(root);
|
|
161
|
+
const set = sets.find((candidate) => candidate.id === id);
|
|
162
|
+
if (set === undefined) {
|
|
163
|
+
throw new Error("These choices are no longer there: the master took them away or heard them.");
|
|
164
|
+
}
|
|
165
|
+
if (set.confirmed !== undefined) {
|
|
166
|
+
throw new Error("These choices are confirmed: they are the master's now.");
|
|
167
|
+
}
|
|
168
|
+
const item = set.items[index];
|
|
169
|
+
if (item === undefined) {
|
|
170
|
+
throw new Error("No such choice in this set.");
|
|
171
|
+
}
|
|
172
|
+
return { sets, set, item };
|
|
173
|
+
}
|
|
174
|
+
function write(root, sets, set, index, item) {
|
|
175
|
+
writeChoices(root, sets.map((other) => (other.id === set.id ? { ...set, items: set.items.map((one, at) => (at === index ? item : one)) } : other)));
|
|
176
|
+
}
|
|
@@ -16,6 +16,7 @@ import { notationParts } from "../../dice/index.js";
|
|
|
16
16
|
import { helperCommand, queueInCodex } from "../../helpers/index.js";
|
|
17
17
|
import { loadSystemCode } from "../../systems/index.js";
|
|
18
18
|
import { newActs } from "../player-acts.js";
|
|
19
|
+
import { choicesNews, choicesRequest } from "./choices.js";
|
|
19
20
|
import { builtPage, packagePageFile, pageFile, pageHtml, pageModulesOf, pagePolicy, pageWords, securityHeaders, send, sendFile, sendImage, sendJson, sendPacked, sendThemeFile, themeAddress, themeNow, vendorModule } from "./files.js";
|
|
20
21
|
import { act, deliverActs, keepProblems, listenForBell, notes, pageNews, setupWord, story } from "./news.js";
|
|
21
22
|
import { answerAsked, closeCard, listenForChanges, pagePlayer, pageSeen, rollNamesOf, spendShown } from "./player.js";
|
|
@@ -141,7 +142,18 @@ function serve(server, served) {
|
|
|
141
142
|
return {
|
|
142
143
|
url: `http://127.0.0.1:${served.port}`,
|
|
143
144
|
player: pagePlayer(served),
|
|
144
|
-
news: (told) =>
|
|
145
|
+
news: (told) => {
|
|
146
|
+
// The player's doings on the page, then the choices they confirmed (D-556).
|
|
147
|
+
const page = pageNews(served, told);
|
|
148
|
+
const confirmed = choicesNews(served, told);
|
|
149
|
+
return {
|
|
150
|
+
lines: [...page.lines, ...confirmed.lines],
|
|
151
|
+
restore: () => {
|
|
152
|
+
page.restore();
|
|
153
|
+
confirmed.restore();
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
},
|
|
145
157
|
close: () => new Promise((done) => {
|
|
146
158
|
stopListening();
|
|
147
159
|
clearInterval(importLook);
|
|
@@ -191,6 +203,10 @@ async function answer(request, response, served) {
|
|
|
191
203
|
await answerAsked(request, response, served);
|
|
192
204
|
return;
|
|
193
205
|
}
|
|
206
|
+
if (path === "/api/choices" && (request.method === "GET" || (request.method === "POST" && origin !== undefined))) {
|
|
207
|
+
await choicesRequest(request, response, served);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
194
210
|
if (path === "/api/act" && (request.method === "GET" || (request.method === "POST" && origin !== undefined))) {
|
|
195
211
|
await act(request, response, served);
|
|
196
212
|
return;
|
package/dist/time/game-date.d.ts
CHANGED
|
@@ -12,6 +12,15 @@ export declare function readGameDate(value: unknown): GameDate | undefined;
|
|
|
12
12
|
export declare function formatGameDate(date: GameDate): string;
|
|
13
13
|
/** A duration in minutes, written with days, hours and minutes in this order, such as 10m, 4h or 1d 6h; undefined for anything else, and for no time at all. */
|
|
14
14
|
export declare function readDuration(text: string): number | undefined;
|
|
15
|
+
/** A rate of game time to real time: the minutes of each. */
|
|
16
|
+
export interface TimeRate {
|
|
17
|
+
game: number;
|
|
18
|
+
real: number;
|
|
19
|
+
}
|
|
20
|
+
/** A rate of game time to real time, written as 1d per 7d; undefined for anything else. */
|
|
21
|
+
export declare function readTimeRate(text: string): TimeRate | undefined;
|
|
22
|
+
/** The game time between sessions as a setting writes it (D-133): stops, or a rate of game time to real time; undefined when it reads as neither. */
|
|
23
|
+
export declare function readBetweenSessions(text: string): "stops" | TimeRate | undefined;
|
|
15
24
|
/** A duration as it is written: 1d 6h, 45m; 0m for no time. */
|
|
16
25
|
export declare function formatDuration(minutes: number): string;
|
|
17
26
|
/** The date after some minutes have passed. It keeps a time of day when the date has one, or when the minutes are not whole days. */
|
package/dist/time/game-date.js
CHANGED
|
@@ -35,6 +35,15 @@ export function readDuration(text) {
|
|
|
35
35
|
const total = days * minutesInDay + hours * 60 + minutes;
|
|
36
36
|
return total > 0 ? total : undefined;
|
|
37
37
|
}
|
|
38
|
+
/** A rate of game time to real time, written as 1d per 7d; undefined for anything else. */
|
|
39
|
+
export function readTimeRate(text) {
|
|
40
|
+
const [game, real, ...more] = text.trim().split(/\s+per\s+/i).map(readDuration);
|
|
41
|
+
return game === undefined || real === undefined || more.length > 0 ? undefined : { game, real };
|
|
42
|
+
}
|
|
43
|
+
/** The game time between sessions as a setting writes it (D-133): stops, or a rate of game time to real time; undefined when it reads as neither. */
|
|
44
|
+
export function readBetweenSessions(text) {
|
|
45
|
+
return text.trim().toLowerCase() === "stops" ? "stops" : readTimeRate(text);
|
|
46
|
+
}
|
|
38
47
|
/** A duration as it is written: 1d 6h, 45m; 0m for no time. */
|
|
39
48
|
export function formatDuration(minutes) {
|
|
40
49
|
const parts = [[Math.floor(minutes / minutesInDay), "d"], [Math.floor((minutes % minutesInDay) / 60), "h"], [minutes % 60, "m"]];
|
package/dist/time/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { type Calendar, type CalendarDay, calendarDay, type CalendarMonth, type CalendarStart, formatCalendarDay, readCalendar, readCalendarStart, realCalendar } from "./calendar.ts";
|
|
2
|
-
export { addDuration, formatDuration, formatGameDate, type GameDate, lastGameDay, minutesBetween, readDuration, readGameDate } from "./game-date.ts";
|
|
2
|
+
export { addDuration, formatDuration, formatGameDate, type GameDate, lastGameDay, minutesBetween, readBetweenSessions, readDuration, readGameDate, readTimeRate, type TimeRate } from "./game-date.ts";
|
package/dist/time/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Game time for any game: the date of the story, counted in days from the start of the adventure, durations, and the calendar that shows a date as a day of a month.
|
|
2
2
|
export { calendarDay, formatCalendarDay, readCalendar, readCalendarStart, realCalendar } from "./calendar.js";
|
|
3
|
-
export { addDuration, formatDuration, formatGameDate, lastGameDay, minutesBetween, readDuration, readGameDate } from "./game-date.js";
|
|
3
|
+
export { addDuration, formatDuration, formatGameDate, lastGameDay, minutesBetween, readBetweenSessions, readDuration, readGameDate, readTimeRate } from "./game-date.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
How the player uses their dashboard, to answer in a few words, as part of the game, naming the sections as the page shows them in the player's language:
|
|
2
2
|
- Before play, while the campaign is in its setup, the page has no sections: it is the setup, with the campaign's name to change, the steps Settings, Session zero and Play, and one question at a time as a card, each choice with what it means and the one suggested. A question can be left to you with "You decide", or skipped; lines and veils are the player's alone, and "I'm ready" tells you they are done. What they choose there reaches you at your next call; the premise and the world stay in the chat.
|
|
3
|
-
- Party: their character's sheet and the companions'. A click on a number of the sheet rolls it for fun, never logged; their rolls and those of yours they may see are in a column beside it.
|
|
3
|
+
- Party: their character's sheet and the companions'. A click on a number of the sheet rolls it for fun, never logged; their rolls and those of yours they may see are in a column beside it. Choices you prepared with `choices`, such as a new level, open from a notice on the sheet: the player picks when they like, reads the pages the options name, rolls where an option rolls, and confirms.
|
|
4
4
|
- Scene: where the party is, with its picture and text, its map with who stands where, and the open scene. While a scene goes by turns, as a fight, it shows on top whose turn it is and who comes next, and their character's card beside the map; on other sections a notice leads there on their turn.
|
|
5
5
|
- Journal: the quests, those followed with their star beside the page; the story by scenes; the companions' diaries; their own notes, which they may share with you.
|
|
6
6
|
- World: what their character knows of the world, in four tabs: Map, the places they know with distances; Lore, the pages they know; Documents, what they have read; Calendar, the days and what is set on them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpg-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Play a tabletop role-playing game with an AI as your game master: the AI tells the story; RPG Engine remembers the world, rolls the dice and keeps the accounts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|