rpg-engine 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adventures/index.d.ts +1 -1
- package/dist/adventures/index.js +1 -1
- package/dist/adventures/source.d.ts +3 -0
- package/dist/adventures/source.js +11 -49
- package/dist/campaign/create-campaign.d.ts +1 -1
- package/dist/campaign/create-campaign.js +3 -2
- package/dist/campaign/find-campaign.d.ts +2 -0
- package/dist/campaign/find-campaign.js +2 -0
- package/dist/campaign/host-files.js +4 -1
- package/dist/campaign/index.d.ts +3 -2
- package/dist/campaign/index.js +3 -2
- package/dist/campaign/port.d.ts +6 -0
- package/dist/campaign/port.js +24 -0
- package/dist/campaign/settings.d.ts +17 -0
- package/dist/campaign/settings.js +26 -3
- package/dist/cli/cli.js +15 -0
- package/dist/commands/book.d.ts +16 -35
- package/dist/commands/book.js +86 -62
- package/dist/commands/config/config.js +16 -2
- package/dist/commands/config/dashboard.d.ts +6 -2
- package/dist/commands/config/dashboard.js +45 -8
- package/dist/commands/config/shown.js +4 -0
- package/dist/commands/config/words.d.ts +3 -1
- package/dist/commands/config/words.js +29 -2
- package/dist/commands/image.d.ts +5 -0
- package/dist/commands/image.js +6 -3
- package/dist/commands/mode.d.ts +1 -1
- package/dist/commands/package/data.d.ts +35 -0
- package/dist/commands/package/data.js +144 -0
- package/dist/commands/package/here.d.ts +7 -2
- package/dist/commands/package/here.js +23 -11
- package/dist/commands/package/install.js +14 -15
- package/dist/commands/package/language.d.ts +15 -0
- package/dist/commands/package/language.js +109 -0
- package/dist/commands/package/package.js +20 -10
- package/dist/commands/package/result.d.ts +19 -0
- package/dist/commands/package/theme.d.ts +13 -0
- package/dist/commands/package/theme.js +67 -0
- package/dist/commands/package/uninstall.d.ts +4 -1
- package/dist/commands/package/uninstall.js +29 -9
- package/dist/commands/scene/close.d.ts +1 -1
- package/dist/commands/scene/close.js +15 -8
- package/dist/commands/scene/scene.js +6 -1
- package/dist/commands/shared/books/adventures.d.ts +1 -4
- package/dist/commands/shared/books/adventures.js +3 -32
- package/dist/commands/shared/books/words.js +3 -2
- package/dist/commands/shared/campaign/book.d.ts +21 -8
- package/dist/commands/shared/campaign/book.js +65 -42
- package/dist/commands/shared/campaign/git.d.ts +25 -0
- package/dist/commands/shared/campaign/git.js +104 -0
- package/dist/commands/shared/campaign/saves.js +7 -3
- package/dist/commands/shared/campaign/world.js +2 -1
- package/dist/commands/shared/packages/catalog.d.ts +3 -3
- package/dist/commands/shared/packages/catalog.js +118 -43
- package/dist/commands/shared/packages/unpacked.d.ts +50 -0
- package/dist/commands/shared/packages/unpacked.js +146 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +8 -4
- package/dist/core/archive.d.ts +13 -0
- package/dist/core/archive.js +76 -0
- package/dist/core/context.d.ts +4 -0
- package/dist/core/context.js +1 -0
- package/dist/core/store.d.ts +5 -1
- package/dist/core/store.js +15 -2
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.js +5 -0
- package/dist/dashboard/api.js +24 -1
- package/dist/dashboard/app.js +7 -2
- package/dist/dashboard/guide/ar.md +11 -9
- package/dist/dashboard/guide/cs.md +11 -9
- package/dist/dashboard/guide/da.md +12 -10
- package/dist/dashboard/guide/de.md +13 -11
- package/dist/dashboard/guide/el.md +11 -9
- package/dist/dashboard/guide/en.md +10 -8
- package/dist/dashboard/guide/es.md +11 -9
- package/dist/dashboard/guide/fi.md +11 -9
- package/dist/dashboard/guide/fr.md +11 -9
- package/dist/dashboard/guide/he.md +11 -9
- package/dist/dashboard/guide/hi.md +11 -9
- package/dist/dashboard/guide/hu.md +11 -9
- package/dist/dashboard/guide/is.md +11 -9
- package/dist/dashboard/guide/it.md +11 -9
- package/dist/dashboard/guide/ja.md +12 -10
- package/dist/dashboard/guide/ko.md +11 -9
- package/dist/dashboard/guide/nb.md +12 -10
- package/dist/dashboard/guide/nl.md +11 -9
- package/dist/dashboard/guide/pl.md +11 -9
- package/dist/dashboard/guide/pt.md +11 -9
- package/dist/dashboard/guide/ro.md +11 -9
- package/dist/dashboard/guide/ru.md +12 -10
- package/dist/dashboard/guide/sv.md +11 -9
- package/dist/dashboard/guide/tr.md +11 -9
- package/dist/dashboard/guide/uk.md +12 -10
- package/dist/dashboard/guide/zh.md +11 -9
- package/dist/dashboard/i18n/ar.json +58 -5
- package/dist/dashboard/i18n/cs.json +58 -5
- package/dist/dashboard/i18n/da.json +58 -5
- package/dist/dashboard/i18n/de.json +58 -5
- package/dist/dashboard/i18n/el.json +58 -5
- package/dist/dashboard/i18n/es.json +58 -5
- package/dist/dashboard/i18n/fi.json +58 -5
- package/dist/dashboard/i18n/fr.json +58 -5
- package/dist/dashboard/i18n/he.json +58 -5
- package/dist/dashboard/i18n/hi.json +58 -5
- package/dist/dashboard/i18n/hu.json +58 -5
- package/dist/dashboard/i18n/is.json +58 -5
- package/dist/dashboard/i18n/it.json +58 -5
- package/dist/dashboard/i18n/ja.json +58 -5
- package/dist/dashboard/i18n/ko.json +58 -5
- package/dist/dashboard/i18n/nb.json +58 -5
- package/dist/dashboard/i18n/nl.json +58 -5
- package/dist/dashboard/i18n/pl.json +58 -5
- package/dist/dashboard/i18n/pt.json +58 -5
- package/dist/dashboard/i18n/ro.json +58 -5
- package/dist/dashboard/i18n/ru.json +58 -5
- package/dist/dashboard/i18n/sv.json +58 -5
- package/dist/dashboard/i18n/tr.json +58 -5
- package/dist/dashboard/i18n/uk.json +58 -5
- package/dist/dashboard/i18n/zh.json +58 -5
- package/dist/dashboard/journal/book.js +3 -2
- package/dist/dashboard/journal/journal.js +8 -5
- package/dist/dashboard/kit.js +1 -1
- package/dist/dashboard/packages/catalog.js +31 -14
- package/dist/dashboard/packages/engine.js +46 -2
- package/dist/dashboard/packages/installed.js +13 -0
- package/dist/dashboard/packages/outcomes.js +21 -0
- package/dist/dashboard/packages/packages.js +41 -18
- package/dist/dashboard/packages/rows.js +3 -1
- package/dist/dashboard/parts/icons.js +3 -0
- package/dist/dashboard/parts/labels.js +7 -0
- package/dist/dashboard/parts/picture.js +89 -0
- package/dist/dashboard/parts/refusals.js +8 -1
- package/dist/dashboard/parts/widgets.js +2 -1
- package/dist/dashboard/play/scene.js +8 -5
- package/dist/dashboard/settings/settings.js +55 -18
- package/dist/dashboard/sheet/party.js +5 -2
- package/dist/dashboard/sheet/sheet.js +2 -1
- package/dist/dashboard/shell/notices.js +2 -2
- package/dist/dashboard/shell/system-style.js +132 -15
- package/dist/dashboard/shell/tooltip.js +224 -0
- package/dist/dashboard/style.css +497 -193
- package/dist/dashboard/world/lore.js +4 -3
- package/dist/dashboard/world/place-card.js +2 -1
- package/dist/git/git.d.ts +12 -0
- package/dist/git/git.js +175 -0
- package/dist/git/ignore.d.ts +2 -0
- package/dist/git/ignore.js +16 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/importer/index.d.ts +1 -1
- package/dist/importer/index.js +1 -1
- package/dist/languages/index.d.ts +1 -1
- package/dist/languages/index.js +1 -1
- package/dist/languages/pack.d.ts +4 -1
- package/dist/languages/pack.js +18 -6
- package/dist/packages/engine.d.ts +7 -0
- package/dist/packages/engine.js +32 -1
- package/dist/packages/index.d.ts +1 -1
- package/dist/packages/index.js +1 -1
- package/dist/server/bell-listener.d.ts +2 -1
- package/dist/server/bell-listener.js +10 -41
- package/dist/server/dashboard/engine.d.ts +18 -0
- package/dist/server/dashboard/engine.js +31 -0
- package/dist/server/dashboard/files.d.ts +11 -3
- package/dist/server/dashboard/files.js +66 -17
- package/dist/server/dashboard/index.d.ts +18 -2
- package/dist/server/dashboard/index.js +62 -23
- package/dist/server/dashboard/news.d.ts +3 -2
- package/dist/server/dashboard/news.js +19 -5
- package/dist/server/dashboard/pictures.d.ts +7 -0
- package/dist/server/dashboard/pictures.js +62 -0
- package/dist/server/dashboard/ports.d.ts +17 -2
- package/dist/server/dashboard/ports.js +60 -4
- package/dist/server/dashboard/writes.d.ts +5 -3
- package/dist/server/dashboard/writes.js +45 -14
- package/dist/server/mcp.d.ts +3 -2
- package/dist/server/mcp.js +55 -11
- package/dist/testing/index.js +1 -0
- package/dist/themes/css.d.ts +1 -1
- package/dist/themes/css.js +101 -2
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +4 -2
- package/dist/themes/installed.d.ts +14 -0
- package/dist/themes/installed.js +28 -0
- package/dist/themes/theme.d.ts +38 -0
- package/dist/themes/theme.js +192 -13
- package/instructions/core.md +4 -3
- package/instructions/dashboard-guide.md +2 -1
- package/instructions/mentor-hints.md +1 -1
- package/instructions/mentor-tutorial.md +1 -1
- package/instructions/party.md +1 -1
- package/instructions/play.md +2 -2
- package/package.json +1 -1
- package/systems/free/instructions/outcomes-told.md +1 -1
|
@@ -7,6 +7,7 @@ import { ChangedLine } from "../parts/changed.js";
|
|
|
7
7
|
import { Icon } from "../parts/icons.js";
|
|
8
8
|
import { placeKindLabel, placeKinds } from "../parts/map-symbols.js";
|
|
9
9
|
import { knowersOf, Markdown, plainLine } from "../parts/markdown.js";
|
|
10
|
+
import { PictureButton, PictureSpot } from "../parts/picture.js";
|
|
10
11
|
import { Token } from "../sheet/party.js";
|
|
11
12
|
import { arrowStep, capitalized, foldedText, t } from "../text.js";
|
|
12
13
|
import { documentLook, foundLore, groupedLore, knownTo, loreGroupOf } from "./known.js";
|
|
@@ -38,7 +39,7 @@ export function LoreTab({ world, version, open, onMap, players = [], kinds = new
|
|
|
38
39
|
return (_jsxs(Browse, { open: entry?.name, explicit: asked !== undefined, back: sectionAddress("world", "lore"), backLabel: t("All you know"), children: [_jsxs("div", { class: "browse-list", children: [open !== undefined && asked === undefined && _jsx("p", { class: "browse-none", role: "status", children: t("Your character knows nothing called “{name}”.", { name: open }) }), _jsx("div", { class: "browse-find", children: _jsxs("span", { class: "search", children: [_jsx(Icon, { name: "search" }), _jsx("input", { type: "search", value: search, placeholder: t("Search"), "aria-label": t("Search what your character knows"), onInput: (event) => setSearch(event.currentTarget.value) })] }) }), (groupedLore(world.known).length > 1 || each.length > 0) && (_jsx(FilterChips, { label: t("Kinds"), chosen: shownFilter, onChoose: setFilter, all: found.length, options: [
|
|
39
40
|
...groupedLore(found).map((part) => ({ key: part.group, name: groupLabel(part.group), count: part.entries.length })),
|
|
40
41
|
...each.map((member) => ({ key: `@${member.name}`, name: member.name, count: found.filter((entry) => knownTo(entry, member.name)).length, member })),
|
|
41
|
-
] })), found.length === 0 && (_jsxs("p", { class: "browse-none", role: "status", children: [t("Nothing your character knows matches “{search}”.", { search }), " ", _jsx("button", { type: "button", class: "button quiet", onClick: () => setSearch(""), children: t("Clear the search") })] })), groups.map((part) => (_jsxs("section", { class: "browse-group", "aria-labelledby": `lore-${part.group}`, children: [_jsxs("h3", { class: "eyebrow", id: `lore-${part.group}`, children: [groupLabel(part.group), _jsx("span", { class: "browse-count num", children: part.entries.length })] }), _jsx("ul", { class: "browse-rows", children: part.entries.map((one, index) => (
|
|
42
|
+
] })), found.length === 0 && (_jsxs("p", { class: "browse-none", role: "status", children: [t("Nothing your character knows matches “{search}”.", { search }), " ", _jsx("button", { type: "button", class: "button quiet", onClick: () => setSearch(""), children: t("Clear the search") })] })), groups.map((part) => (_jsxs("section", { class: "browse-group", "aria-labelledby": `lore-${part.group}`, children: [_jsxs("h3", { class: "eyebrow", id: `lore-${part.group}`, children: [groupLabel(part.group), _jsx("span", { class: "browse-count num", children: part.entries.length })] }), _jsx("ul", { class: "browse-rows", children: part.entries.map((one, index) => (_jsxs("li", { class: "picture-host", children: [_jsxs("a", { class: "browse-row", href: sectionAddress("world", "lore", one.name), "aria-current": one.name === entry?.name ? "true" : undefined, "aria-labelledby": `lore-name-${part.group}-${index}`, "aria-describedby": `lore-${part.group}-${index}`, "data-name": one.name, children: [_jsx(LoreThumb, { entry: one }), _jsxs("span", { class: "browse-words", children: [_jsx("span", { class: "browse-name", id: `lore-name-${part.group}-${index}`, children: one.name }), _jsx("span", { class: "browse-meta", id: `lore-${part.group}-${index}`, children: _jsx(MetaLine, { kind: entryKind(one, kinds), text: plainLine(one.summary) ?? one.within?.[0] }) })] })] }), _jsx(PictureButton, { page: one.name, has: one.picture !== undefined, icon: true, row: true })] }, one.name))) })] }, part.group)))] }), entry !== undefined && (_jsx(LoreReader, { entry: entry, version: version, link: link, several: each.length > 0, kinds: kinds, onMap: entry.type === "place" ? onMap([entry.name, ...entry.within ?? []]) : undefined, focus: asked !== undefined }, entry.name))] }));
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
45
|
* The documents the character has or read: those it carries, then the others; the one open on its paper, as what it is. With more than one player character
|
|
@@ -133,14 +134,14 @@ function LoreReader({ entry, version, link, onMap, focus, several, kinds }) {
|
|
|
133
134
|
useOpened(title, focus);
|
|
134
135
|
const person = entry.type === "character" || entry.type === "creature";
|
|
135
136
|
const banner = entry.picture !== undefined && !person;
|
|
136
|
-
return (_jsxs("article", { class: "browse-reader", "aria-labelledby": "reader-title", children: [banner && _jsx("img", { class: "reader-banner", src: pictureAddress(entry.picture), alt: "" }), _jsxs("header", { class: "reader-head", children: [person && _jsx(Token, { member: { name: entry.name, image: entry.picture, role: entry.companion ? "companion" : "other" }, large: true, ...(entry.companion ? { side: "ally" } : {}) }), _jsxs("div", { children: [_jsx("p", { class: "eyebrow", children: entryKind(entry, kinds) }), _jsx("h3", { id: "reader-title", tabIndex: -1, ref: title, children: entry.name }), entry.within !== undefined && (_jsxs("p", { class: "reader-where", children: [_jsx(Icon, { name: "place" }), _jsx("span", { class: "reader-path", children: entry.within.toReversed().map((place, index) => (_jsxs("span", { children: [index > 0 && _jsx("span", { class: "reader-step", "aria-hidden": "true" }), _jsx("a", { class: "md-link", href: sectionAddress("world", "lore", place), children: place })] }, place))) })] })), changed && _jsx(ChangedLine, {})] })] }),
|
|
137
|
+
return (_jsxs("article", { class: "browse-reader", "aria-labelledby": "reader-title", children: [banner && (_jsxs("div", { class: "picture-host", children: [_jsx("img", { class: "reader-banner", src: pictureAddress(entry.picture), alt: "" }), _jsx(PictureButton, { page: entry.name, has: true, icon: true })] })), _jsxs("header", { class: "reader-head", children: [person && (_jsx(PictureSpot, { page: entry.name, has: entry.picture !== undefined, children: _jsx(Token, { member: { name: entry.name, image: entry.picture, role: entry.companion ? "companion" : "other" }, large: true, ...(entry.companion ? { side: "ally" } : {}) }) })), _jsxs("div", { children: [_jsx("p", { class: "eyebrow", children: entryKind(entry, kinds) }), _jsx("h3", { id: "reader-title", tabIndex: -1, ref: title, children: entry.name }), entry.within !== undefined && (_jsxs("p", { class: "reader-where", children: [_jsx(Icon, { name: "place" }), _jsx("span", { class: "reader-path", children: entry.within.toReversed().map((place, index) => (_jsxs("span", { children: [index > 0 && _jsx("span", { class: "reader-step", "aria-hidden": "true" }), _jsx("a", { class: "md-link", href: sectionAddress("world", "lore", place), children: place })] }, place))) })] })), changed && _jsx(ChangedLine, {})] })] }), _jsxs("p", { class: "reader-actions", children: [onMap !== undefined && (_jsxs("a", { class: "button package-button", href: onMap, children: [_jsx(Icon, { name: "world" }), t("Show on the map")] })), entry.companion && (_jsxs("a", { class: "button package-button", href: `#/party/${encodeURIComponent(entry.name)}`, children: [_jsx(Icon, { name: "party" }), t("Open the sheet")] })), _jsx(PictureButton, { page: entry.name, has: entry.picture !== undefined })] }), _jsxs("div", { class: "reader-text", children: [text === undefined && !problem && entry.summary !== "" && _jsx(Markdown, { text: entry.summary, link: link }), text !== undefined && text.trim() !== "" && _jsx(Markdown, { text: text, link: link, secretKnowers: several ? knowersOf(knowers) : undefined }), ((text !== undefined && text.trim() === "") || (text === undefined && entry.summary === "")) && !problem && (_jsx("p", { class: "browse-none", children: text === undefined ? t("Reading…") : t("Your character knows its name, and nothing more yet.") })), problem && _jsx("p", { class: "browse-none", children: t("This page could not be read now: try again in a moment.") })] })] }));
|
|
137
138
|
}
|
|
138
139
|
/** A document on its paper, as what it is: a letter, a notice, a torn page; its picture first, larger at a click, for a map above all. */
|
|
139
140
|
function DocumentReader({ document, link, focus, several }) {
|
|
140
141
|
const title = useRef(null);
|
|
141
142
|
const look = documentLook(document.document);
|
|
142
143
|
useOpened(title, focus);
|
|
143
|
-
return (_jsxs("article", { class: "browse-reader", "aria-labelledby": "reader-title", children: [_jsx("header", { class: "reader-head", children: _jsxs("div", { children: [_jsx("p", { class: "eyebrow", children: [documentLabel(document.document), carriedWords(document, several)].filter((part) => part !== undefined).join(" · ") }), _jsx("h3", { id: "reader-title", tabIndex: -1, ref: title, children: document.name })] }) }), _jsxs("div", { class: `paper look-${look}`, children: [_jsx("span", { class: "paper-mark", "aria-hidden": "true" }), document.picture !== undefined && (_jsx("a", { class: "paper-picture", href: pictureAddress(document.picture), target: "_blank", rel: "noreferrer", children: _jsx("img", { src: pictureAddress(document.picture), alt: t("{name}, as drawn", { name: document.name }) }) })), document.text.trim() !== "" && _jsx(Markdown, { text: document.text, link: link })] })] }));
|
|
144
|
+
return (_jsxs("article", { class: "browse-reader", "aria-labelledby": "reader-title", children: [_jsx("header", { class: "reader-head", children: _jsxs("div", { children: [_jsx("p", { class: "eyebrow", children: [documentLabel(document.document), carriedWords(document, several)].filter((part) => part !== undefined).join(" · ") }), _jsx("h3", { id: "reader-title", tabIndex: -1, ref: title, children: document.name })] }) }), _jsx("p", { class: "reader-actions", children: _jsx(PictureButton, { page: document.name, has: document.picture !== undefined }) }), _jsxs("div", { class: `paper look-${look}`, children: [_jsx("span", { class: "paper-mark", "aria-hidden": "true" }), document.picture !== undefined && (_jsxs("div", { class: "picture-host", children: [_jsx("a", { class: "paper-picture", href: pictureAddress(document.picture), target: "_blank", rel: "noreferrer", children: _jsx("img", { src: pictureAddress(document.picture), alt: t("{name}, as drawn", { name: document.name }) }) }), _jsx(PictureButton, { page: document.name, has: true, icon: true })] })), document.text.trim() !== "" && _jsx(Markdown, { text: document.text, link: link })] })] }));
|
|
144
145
|
}
|
|
145
146
|
/** A row of filter chips: All, then each option with its count; one stop of Tab, the arrows along it. */
|
|
146
147
|
function FilterChips({ label, options, chosen, all, onChoose }) {
|
|
@@ -7,6 +7,7 @@ import { fromLabel } from "../parts/game-words.js";
|
|
|
7
7
|
import { Icon } from "../parts/icons.js";
|
|
8
8
|
import { placeKindLabel } from "../parts/map-symbols.js";
|
|
9
9
|
import { plainLine } from "../parts/markdown.js";
|
|
10
|
+
import { PictureButton } from "../parts/picture.js";
|
|
10
11
|
import { t } from "../text.js";
|
|
11
12
|
import { lengthText, waysOf } from "./map.js";
|
|
12
13
|
/** The card of a place: its picture, what it is and where, its text as the character knows it, what it holds, its ways, the scene when the party is there. */
|
|
@@ -29,7 +30,7 @@ export function PlaceCard({ place, map, layout, narrow, onClose, onGo, readMore
|
|
|
29
30
|
};
|
|
30
31
|
}, [place.name]);
|
|
31
32
|
const eyebrow = [placeKindLabel(place.kind) ?? t("Place"), region?.name, here || place.from?.direction === undefined ? undefined : t("{distance} from you", { distance: fromLabel(place.from, (km) => lengthText(km, map.unit)) })].filter((part) => part !== undefined);
|
|
32
|
-
return (_jsxs("div", { class: narrow ? "place-card sheet" : "place-card", role: "dialog", "aria-labelledby": "place-card-title", onPointerDown: (event) => event.stopPropagation(), onPointerUp: (event) => event.stopPropagation(), children: [place.image !== undefined && _jsx("img", { class: "pc-image", src: pictureAddress(place.image), alt: "" }), _jsx("button", { ref: closer, type: "button", class: "pc-close icon-button", "aria-label": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) }), _jsxs("div", { class: "pc-body", children: [_jsx("p", { class: "eyebrow pc-eyebrow", children: eyebrow.join(" · ") }), _jsx("h3", { id: "place-card-title", children: place.name }), here && (_jsxs("p", { class: "pc-here", children: [_jsx("span", { class: "here-dot", "aria-hidden": "true" }), t("Your party is here")] })), text !== undefined && _jsx("p", { class: "pc-text", children: text }), readMore !== undefined && _jsx("a", { class: "pc-more md-link", href: readMore, children: t("Read all you know") }), inside.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h4", { class: "eyebrow pc-sub", children: t("Inside") }), _jsx("ul", { class: "in-chips", children: inside.flatMap((child) => [
|
|
33
|
+
return (_jsxs("div", { class: narrow ? "place-card sheet" : "place-card", role: "dialog", "aria-labelledby": "place-card-title", onPointerDown: (event) => event.stopPropagation(), onPointerUp: (event) => event.stopPropagation(), children: [place.image !== undefined && (_jsxs("div", { class: "picture-host", children: [_jsx("img", { class: "pc-image", src: pictureAddress(place.image), alt: "" }), _jsx(PictureButton, { page: place.name, has: true, icon: true })] })), _jsx("button", { ref: closer, type: "button", class: "pc-close icon-button", "aria-label": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) }), _jsxs("div", { class: "pc-body", children: [_jsx("p", { class: "eyebrow pc-eyebrow", children: eyebrow.join(" · ") }), _jsx("h3", { id: "place-card-title", children: place.name }), here && (_jsxs("p", { class: "pc-here", children: [_jsx("span", { class: "here-dot", "aria-hidden": "true" }), t("Your party is here")] })), text !== undefined && _jsx("p", { class: "pc-text", children: text }), readMore !== undefined && _jsx("a", { class: "pc-more md-link", href: readMore, children: t("Read all you know") }), inside.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h4", { class: "eyebrow pc-sub", children: t("Inside") }), _jsx("ul", { class: "in-chips", children: inside.flatMap((child) => [
|
|
33
34
|
_jsx("li", { class: "in-chip", children: child.name }, child.name),
|
|
34
35
|
...layout.inside(child.name).map((grandchild) => (_jsxs("li", { class: "in-chip", children: [_jsx("span", { class: "in-path", children: "\u203A" }), " ", grandchild.name] }, grandchild.name))),
|
|
35
36
|
]) })] })), ways.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h4", { class: "eyebrow pc-sub", children: t("Ways") }), _jsx("ul", { class: "pc-ways", children: ways.map((way, index) => (_jsxs("li", { children: [_jsx(Icon, { name: wayIcon(way.kind) }), _jsxs("span", { children: [_jsx("b", { children: way.road }), ` ${t("to")} `, way.map === undefined || way.to === undefined ? way.to ?? t("somewhere you do not know") : (_jsx("button", { type: "button", class: "way-to-map", onClick: () => onGo(way.map, way.to), children: t("{place}, on {map}", { place: way.to, map: way.map }) })), way.km !== undefined && " · ", way.km !== undefined && _jsx("span", { class: "way-km num", children: lengthText(way.km, map.unit) })] })] }, index))) })] })), here && (_jsxs("a", { class: "pc-scene", href: sectionAddress("scene"), children: [_jsx(Icon, { name: "scene" }), _jsx("span", { children: t("Scene") })] }))] })] }));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Whether `folder` is inside a git repository: it, or a folder above it, holds a .git. Git itself need not be installed. */
|
|
2
|
+
export declare function isRepository(folder: string): boolean;
|
|
3
|
+
/** The folder of the repository `folder` is in, the one that holds the .git: it or one above it; undefined outside any. */
|
|
4
|
+
export declare function repositoryRoot(folder: string): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Commits every change under `folder`, and only there, with `message`, `left` (paths in it) taken out of the repository but left on the disk: true when there
|
|
7
|
+
* was a change, false when there was none. The commit is made on an index of its own, so that what the player staged elsewhere stays staged and out of it;
|
|
8
|
+
* then the repository's index follows it under `folder`. It throws with git's words.
|
|
9
|
+
*/
|
|
10
|
+
export declare function commitFolder(folder: string, message: string, left?: string[]): Promise<boolean>;
|
|
11
|
+
/** Pushes the branch of the repository of `folder` to where it is pushed. It throws with git's words. */
|
|
12
|
+
export declare function push(folder: string): Promise<void>;
|
package/dist/git/git.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Git in a folder, through the git of this computer: whether the folder is in a repository, a commit of its changes, a push. It never asks anything: a git
|
|
2
|
+
// that would ask for a password or a passphrase fails instead, and says why.
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { existsSync, rmSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
/** Whether `folder` is inside a git repository: it, or a folder above it, holds a .git. Git itself need not be installed. */
|
|
9
|
+
export function isRepository(folder) {
|
|
10
|
+
return repositoryRoot(folder) !== undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The folder of the repository `folder` is in, the one that holds the .git: it or one above it; undefined outside any. */
|
|
13
|
+
export function repositoryRoot(folder) {
|
|
14
|
+
for (let current = resolve(folder);; current = dirname(current)) {
|
|
15
|
+
// A folder, or a file in a worktree or a submodule.
|
|
16
|
+
if (existsSync(join(current, ".git"))) {
|
|
17
|
+
return current;
|
|
18
|
+
}
|
|
19
|
+
if (dirname(current) === current) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Commits every change under `folder`, and only there, with `message`, `left` (paths in it) taken out of the repository but left on the disk: true when there
|
|
26
|
+
* was a change, false when there was none. The commit is made on an index of its own, so that what the player staged elsewhere stays staged and out of it;
|
|
27
|
+
* then the repository's index follows it under `folder`. It throws with git's words.
|
|
28
|
+
*/
|
|
29
|
+
export async function commitFolder(folder, message, left = []) {
|
|
30
|
+
const own = { GIT_INDEX_FILE: join(tmpdir(), `rpg-git-index-${randomUUID()}`) };
|
|
31
|
+
try {
|
|
32
|
+
const before = await hasCommits(folder);
|
|
33
|
+
if (before) {
|
|
34
|
+
await git(folder, ["read-tree", "HEAD"], own);
|
|
35
|
+
}
|
|
36
|
+
await stageFolder(folder, left, own);
|
|
37
|
+
// The changes to HEAD, or in a repository with no commit yet whatever is staged.
|
|
38
|
+
const changes = await git(folder, before ? ["diff", "--cached", "--name-only"] : ["ls-files"], own);
|
|
39
|
+
if (changes.trim() === "") {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
await git(folder, ["commit", "--quiet", "--message", message], own);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
rmSync(own.GIT_INDEX_FILE, { force: true });
|
|
46
|
+
}
|
|
47
|
+
await stageFolder(folder, left);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/** Pushes the branch of the repository of `folder` to where it is pushed. It throws with git's words. */
|
|
51
|
+
export async function push(folder) {
|
|
52
|
+
// A branch with no upstream yet gets the one of its name, as the player's first git push -u would.
|
|
53
|
+
await git(folder, ["-c", "push.autoSetupRemote=true", "push", "--quiet"], await sshVariables(folder));
|
|
54
|
+
}
|
|
55
|
+
/** The ssh of the player, as GIT_SSH_COMMAND, GIT_SSH or core.sshCommand say, else ssh that never asks for a passphrase. */
|
|
56
|
+
async function sshVariables(folder) {
|
|
57
|
+
if (process.env.GIT_SSH_COMMAND !== undefined || process.env.GIT_SSH !== undefined) {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const own = (await git(folder, ["config", "--get", "core.sshCommand"])).trim();
|
|
62
|
+
if (own !== "") {
|
|
63
|
+
// Their command kept; BatchMode only where it is OpenSSH's.
|
|
64
|
+
return { GIT_SSH_COMMAND: /(^|[\\/])ssh(\.exe)?"?(\s|$)/i.test(own) ? `${own} -o BatchMode=yes` : own };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Unset: git says so with a failure.
|
|
69
|
+
}
|
|
70
|
+
return { GIT_SSH_COMMAND: "ssh -o BatchMode=yes" };
|
|
71
|
+
}
|
|
72
|
+
/** Stages every change under `folder`, `left` taken out, on the index `variables` name, or the repository's. */
|
|
73
|
+
async function stageFolder(folder, left, variables = {}) {
|
|
74
|
+
await git(folder, ["add", "--all", "--", "."], variables);
|
|
75
|
+
if (left.length > 0) {
|
|
76
|
+
await git(folder, ["rm", "-r", "--cached", "--quiet", "--ignore-unmatch", "--", ...left], variables);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function hasCommits(folder) {
|
|
80
|
+
try {
|
|
81
|
+
await git(folder, ["rev-parse", "--verify", "--quiet", "HEAD"]);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// How long git may take before it is stopped: a push that waits on a network or on a question never answers.
|
|
89
|
+
const longest = 120_000;
|
|
90
|
+
// What a git that another git holds says: tried once more a moment later.
|
|
91
|
+
const heldByAnother = /index\.lock|cannot lock ref/i;
|
|
92
|
+
/** What git printed, or an error with what it said and how to fix it when it failed, could not start or took too long; once again when another git held it. */
|
|
93
|
+
async function git(folder, args, variables = {}) {
|
|
94
|
+
try {
|
|
95
|
+
return await gitOnce(folder, args, variables);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (!(error instanceof Error) || !heldByAnother.test(error.message)) {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
await new Promise((done) => setTimeout(done, 500));
|
|
102
|
+
return gitOnce(folder, args, variables);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function gitOnce(folder, args, variables) {
|
|
106
|
+
return new Promise((done, fail) => {
|
|
107
|
+
// core.askPass emptied too: an askpass is a program that asks.
|
|
108
|
+
const child = spawn("git", ["-c", "core.askPass=", ...args], { cwd: folder, env: { ...quietEnvironment(), ...variables }, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
109
|
+
let out = "";
|
|
110
|
+
let said = "";
|
|
111
|
+
let settled = false;
|
|
112
|
+
const settle = (work) => {
|
|
113
|
+
if (!settled) {
|
|
114
|
+
settled = true;
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
work();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
// A git stopped answers at once: its hooks, ssh or the remote's helper may keep its pipes open long after.
|
|
120
|
+
const timer = setTimeout(() => {
|
|
121
|
+
stopTree(child.pid);
|
|
122
|
+
child.stdout.destroy();
|
|
123
|
+
child.stderr.destroy();
|
|
124
|
+
settle(() => fail(new Error(`git ${args[0]} took longer than ${longest / 60_000} minutes and was stopped: look at the network, or at a hook of the repository that waits.`)));
|
|
125
|
+
}, longest);
|
|
126
|
+
child.stdout.on("data", (chunk) => (out += chunk.toString("utf8")));
|
|
127
|
+
child.stderr.on("data", (chunk) => (said += chunk.toString("utf8")));
|
|
128
|
+
child.on("error", (error) => settle(() => fail(new Error(`git could not start (${error.message}): install git, or turn git off in the settings.`))));
|
|
129
|
+
child.on("close", (code) => settle(() => (code === 0 ? done(out) : fail(new Error(gitFailure(said || out, args[0]))))));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** What git said when it failed, its errors and hints, with our own fix for the failures a player meets most. */
|
|
133
|
+
function gitFailure(said, command) {
|
|
134
|
+
if (/please tell me who you are|author identity unknown/i.test(said)) {
|
|
135
|
+
return 'git does not know who commits: run git config user.name "Your Name" and git config user.email "you@example.com" in the campaign\'s folder.';
|
|
136
|
+
}
|
|
137
|
+
if (/could not read (username|password)|cannot prompt|terminal prompts disabled|permission denied \(publickey|authentication failed/i.test(said)) {
|
|
138
|
+
return "git has no credentials for the remote: run git push once from a terminal in the campaign's folder and sign in; then the engine pushes with what git keeps.";
|
|
139
|
+
}
|
|
140
|
+
if (/has no upstream branch/i.test(said)) {
|
|
141
|
+
return "the branch has no upstream yet: run git push -u origin with the branch's name once in the campaign's folder.";
|
|
142
|
+
}
|
|
143
|
+
if (/no configured push destination|does not appear to be a git repository/i.test(said)) {
|
|
144
|
+
return "the repository has no remote to push to: add one with git remote add origin and its address, or choose commit alone in the settings.";
|
|
145
|
+
}
|
|
146
|
+
const lines = said.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");
|
|
147
|
+
const told = lines.filter((line) => /^(fatal|error|hint):/i.test(line));
|
|
148
|
+
return (told.length > 0 ? told : lines.slice(0, 6)).join(" ") || `git ${command} stopped`;
|
|
149
|
+
}
|
|
150
|
+
/** Stops a process and every process it started: on Windows by its tree, elsewhere by a kill its children see as their pipes close. */
|
|
151
|
+
function stopTree(pid) {
|
|
152
|
+
if (pid === undefined) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (process.platform === "win32") {
|
|
156
|
+
spawn("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" }).on("error", () => undefined);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
process.kill(pid, "SIGKILL");
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Already gone.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** The environment of git: the one of this process, with every question it could ask turned into a failure. */
|
|
167
|
+
function quietEnvironment() {
|
|
168
|
+
return {
|
|
169
|
+
...process.env,
|
|
170
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
171
|
+
GCM_INTERACTIVE: "never",
|
|
172
|
+
GIT_ASKPASS: "",
|
|
173
|
+
SSH_ASKPASS: "",
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The engine's block of a .gitignore: its lines between two marks, which it writes again whole; the lines around it are the player's and stay as they are.
|
|
2
|
+
const begin = "# rpg-engine: begin (written by rpg-engine; your own lines go outside this block)";
|
|
3
|
+
const end = "# rpg-engine: end";
|
|
4
|
+
/** The text of a .gitignore, or none, with the engine's block holding `lines`: in place of the block it had, else after its own lines. */
|
|
5
|
+
export function withIgnoreBlock(text, lines) {
|
|
6
|
+
const newline = text?.includes("\r\n") === true ? "\r\n" : "\n";
|
|
7
|
+
const block = [begin, ...lines, end].join(newline);
|
|
8
|
+
const kept = (text ?? "").split(/\r?\n/);
|
|
9
|
+
const from = kept.indexOf(begin);
|
|
10
|
+
const to = kept.indexOf(end, from);
|
|
11
|
+
if (from !== -1 && to !== -1) {
|
|
12
|
+
return [...kept.slice(0, from), block, ...kept.slice(to + 1)].join(newline);
|
|
13
|
+
}
|
|
14
|
+
const before = (text ?? "").replace(/(\r?\n)*$/, "");
|
|
15
|
+
return before === "" ? `${block}${newline}` : `${before}${newline}${newline}${block}${newline}`;
|
|
16
|
+
}
|
package/dist/importer/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { beginOpening, claimImport, clearOpening, doneImports, dropDocumentText, dropImport, finishAdventure, hasImport, importAge, importDate, importedPages, type ImportedText, importFile, importFolder, importPiece, type ImportStart, importStarts, type ImportState, importStyle, isOwnOpening, markOpening, openImport, type OpeningImport, openingImport, openLicense, pieceName, prepareImport, readImportState, releaseImport, runElsewhere, writeImportState, } from "./work.ts";
|
|
1
|
+
export { beginOpening, claimImport, clearOpening, doneImports, dropDocumentText, dropImport, finishAdventure, hasImport, importAge, importDate, importedPages, type ImportedText, importFile, importFolder, importPiece, importsFolderName, type ImportStart, importStarts, type ImportState, importStyle, isOwnOpening, markOpening, openImport, type OpeningImport, openingImport, openLicense, pieceName, prepareImport, readImportState, releaseImport, runElsewhere, writeImportState, } from "./work.ts";
|
package/dist/importer/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// The importer's folder (D-489): the player's document in pieces, how far the import is, and the adventure the helper writes. Depends on nothing else in
|
|
2
2
|
// rpg-engine.
|
|
3
|
-
export { beginOpening, claimImport, clearOpening, doneImports, dropDocumentText, dropImport, finishAdventure, hasImport, importAge, importDate, importedPages, importFile, importFolder, importPiece, importStarts, importStyle, isOwnOpening, markOpening, openImport, openingImport, openLicense, pieceName, prepareImport, readImportState, releaseImport, runElsewhere, writeImportState, } from "./work.js";
|
|
3
|
+
export { beginOpening, claimImport, clearOpening, doneImports, dropDocumentText, dropImport, finishAdventure, hasImport, importAge, importDate, importedPages, importFile, importFolder, importPiece, importsFolderName, importStarts, importStyle, isOwnOpening, markOpening, openImport, openingImport, openLicense, pieceName, prepareImport, readImportState, releaseImport, runElsewhere, writeImportState, } from "./work.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { installedLanguages, type LanguagePack, languagePackFor, languagePackProblems, packGuide, packPhrases, packSystemFolder, readLanguagePack } from "./pack.ts";
|
|
1
|
+
export { installedLanguages, languageFileName, type LanguagePack, languagePackFor, languagePackProblems, packGuide, packPhrases, packSystemFolder, readLanguagePack } from "./pack.ts";
|
package/dist/languages/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Languages as packages (D-485 (3)): a translation made by hand of the dashboard's phrases, its Guide and a game system's words, which comes before the
|
|
2
2
|
// translation on the fly. Depends on nothing else in rpg-engine but the core.
|
|
3
|
-
export { installedLanguages, languagePackFor, languagePackProblems, packGuide, packPhrases, packSystemFolder, readLanguagePack } from "./pack.js";
|
|
3
|
+
export { installedLanguages, languageFileName, languagePackFor, languagePackProblems, packGuide, packPhrases, packSystemFolder, readLanguagePack } from "./pack.js";
|
package/dist/languages/pack.d.ts
CHANGED
|
@@ -14,7 +14,10 @@ export interface LanguagePack {
|
|
|
14
14
|
export declare function installedLanguages(folders: string[]): LanguagePack[];
|
|
15
15
|
/** The package for a language: its own code, else its base language's (pt for pt-BR); undefined when none is installed. */
|
|
16
16
|
export declare function languagePackFor(folders: string[], code: string): LanguagePack | undefined;
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* A language package from its folder; it throws, saying what is wrong, when it does not read. One of data alone, without a package.json, is named by its
|
|
19
|
+
* code, language-de, with the version its language.yaml gives.
|
|
20
|
+
*/
|
|
18
21
|
export declare function readLanguagePack(folder: string): LanguagePack;
|
|
19
22
|
/** The dashboard's phrases the package translates, by their English; none when it has none that reads. */
|
|
20
23
|
export declare function packPhrases(pack: LanguagePack): Record<string, string>;
|
package/dist/languages/pack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { packageFoldersIn } from "../core/files.js";
|
|
4
4
|
import { codeAndBase } from "../core/language.js";
|
|
@@ -10,7 +10,10 @@ const codePattern = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
|
|
|
10
10
|
const languageSchema = z.object({
|
|
11
11
|
code: z.string().regex(codePattern, "a language's code, such as de or pt-PT").refine((code) => code.split("-")[0] !== "en", "English is the page's own"),
|
|
12
12
|
name: z.string().trim().min(1),
|
|
13
|
-
engine:
|
|
13
|
+
// The lowest rpg-engine that reads it, such as "0.22": checked as one of data alone is installed.
|
|
14
|
+
engine: z.string({ error: 'engine is written in quotes, as engine: "0.22": without them YAML reads 0.30 as the number 0.3' }).regex(/^\d+(\.\d+){0,2}$/, 'engine is the lowest rpg-engine version, such as "0.22", not a range').optional(),
|
|
15
|
+
// Its version, for a package of data alone, which has no package.json to say it.
|
|
16
|
+
version: z.union([z.string(), z.number()]).transform(String).optional(),
|
|
14
17
|
}).strict();
|
|
15
18
|
const phrasesSchema = z.record(z.string(), z.string());
|
|
16
19
|
// Characters that turn the order of a text, which could make it read otherwise than it is.
|
|
@@ -36,14 +39,23 @@ export function languagePackFor(folders, code) {
|
|
|
36
39
|
const packs = installedLanguages(folders);
|
|
37
40
|
return codeAndBase(code).map((wanted) => packs.find((pack) => pack.code.toLowerCase() === wanted)).find((pack) => pack !== undefined);
|
|
38
41
|
}
|
|
39
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* A language package from its folder; it throws, saying what is wrong, when it does not read. One of data alone, without a package.json, is named by its
|
|
44
|
+
* code, language-de, with the version its language.yaml gives.
|
|
45
|
+
*/
|
|
40
46
|
export function readLanguagePack(folder) {
|
|
41
47
|
const manifest = JSON.parse(files().text(join(folder, "package.json")) ?? "{}");
|
|
42
48
|
const read = languageSchema.safeParse(readYamlValues(join(folder, languageFileName), 'a language package\'s code and name, such as "code: de"'));
|
|
43
49
|
if (!read.success) {
|
|
44
50
|
throw new Error(`${join(folder, languageFileName)}: ${read.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ")}.`);
|
|
45
51
|
}
|
|
46
|
-
return {
|
|
52
|
+
return {
|
|
53
|
+
package: String(manifest.name ?? `language-${read.data.code}`),
|
|
54
|
+
version: String(manifest.version ?? read.data.version ?? ""),
|
|
55
|
+
folder,
|
|
56
|
+
code: read.data.code,
|
|
57
|
+
name: read.data.name,
|
|
58
|
+
};
|
|
47
59
|
}
|
|
48
60
|
/** The dashboard's phrases the package translates, by their English; none when it has none that reads. */
|
|
49
61
|
export function packPhrases(pack) {
|
|
@@ -83,9 +95,9 @@ export function languagePackProblems(pack, english) {
|
|
|
83
95
|
}
|
|
84
96
|
return { problems: problems.slice(0, 10), missing: english.filter((phrase) => !(phrase in phrases)).length };
|
|
85
97
|
}
|
|
86
|
-
/** The folders of packages with a language.yaml in these folders, and in their scopes' folders. */
|
|
98
|
+
/** The folders of packages with a language.yaml in these folders, and in their scopes' folders; never one being unpacked, whose name starts with a dot. */
|
|
87
99
|
function packageFolders(folders) {
|
|
88
|
-
return packageFoldersIn(folders).filter((candidate) => files().exists(join(candidate, languageFileName)));
|
|
100
|
+
return packageFoldersIn(folders).filter((candidate) => !basename(candidate).startsWith(".") && files().exists(join(candidate, languageFileName)));
|
|
89
101
|
}
|
|
90
102
|
/** The package's phrases.json as JSON: undefined when it has none, the error when it does not read. */
|
|
91
103
|
function phrasesJson(pack) {
|
|
@@ -2,3 +2,10 @@ import type { EngineUpdater } from "../core/context.ts";
|
|
|
2
2
|
import { type NpmRun } from "./npm.ts";
|
|
3
3
|
/** rpg-engine on npm, for the engine in this folder, from src/ and dist/ alike its package's own; `run` runs npm, a fake in tests. */
|
|
4
4
|
export declare function npmEngine(folder?: string, run?: (args: string) => Promise<NpmRun>): EngineUpdater;
|
|
5
|
+
/** npm's latest rpg-engine as checked today and kept in the player's folder; none when older, from the future or unreadable. */
|
|
6
|
+
export declare function keptLatestEngine(home: string | undefined, now: number): {
|
|
7
|
+
checked: number;
|
|
8
|
+
version: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
/** Keeps npm's latest rpg-engine in the player's folder; a folder that cannot be written only means npm is asked again next time. */
|
|
11
|
+
export declare function keepLatestEngine(home: string | undefined, now: number, version: string): void;
|
package/dist/packages/engine.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// rpg-engine itself on npm (D-515 (3)): its latest version, how this one is installed, and its update with npm, globally as it was installed; a development
|
|
2
2
|
// link, or any other install, is told and never touched.
|
|
3
|
-
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { npmError, npmErrorCode, runNpm } from "./npm.js";
|
|
7
7
|
const registry = "https://registry.npmjs.org";
|
|
8
|
+
// npm's latest rpg-engine, kept in the player's folder for a day (T-219).
|
|
9
|
+
const latestFile = "engine-update.json";
|
|
10
|
+
const latestHolds = 24 * 60 * 60 * 1000;
|
|
8
11
|
/** rpg-engine on npm, for the engine in this folder, from src/ and dist/ alike its package's own; `run` runs npm, a fake in tests. */
|
|
9
12
|
export function npmEngine(folder = fileURLToPath(new URL("../../", import.meta.url)), run = runNpm) {
|
|
10
13
|
return {
|
|
@@ -36,6 +39,34 @@ export function npmEngine(folder = fileURLToPath(new URL("../../", import.meta.u
|
|
|
36
39
|
},
|
|
37
40
|
};
|
|
38
41
|
}
|
|
42
|
+
/** npm's latest rpg-engine as checked today and kept in the player's folder; none when older, from the future or unreadable. */
|
|
43
|
+
export function keptLatestEngine(home, now) {
|
|
44
|
+
if (home === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const read = JSON.parse(readFileSync(join(home, latestFile), "utf8"));
|
|
49
|
+
const checked = typeof read.checked === "string" ? Date.parse(read.checked) : Number.NaN;
|
|
50
|
+
const fresh = !Number.isNaN(checked) && now - checked >= 0 && now - checked < latestHolds;
|
|
51
|
+
return fresh && typeof read.latest === "string" ? { checked, version: read.latest } : undefined;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Keeps npm's latest rpg-engine in the player's folder; a folder that cannot be written only means npm is asked again next time. */
|
|
58
|
+
export function keepLatestEngine(home, now, version) {
|
|
59
|
+
if (home === undefined) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
mkdirSync(home, { recursive: true });
|
|
64
|
+
writeFileSync(join(home, latestFile), `${JSON.stringify({ checked: new Date(now).toISOString(), latest: version }, null, 2)}\n`);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Nothing to keep is no reason to stop.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
39
70
|
/** How the engine in this folder is installed, by npm's global folder: the package there, a link to this folder, or neither. */
|
|
40
71
|
function engineInstall(folder, root) {
|
|
41
72
|
const own = realFolder(folder);
|
package/dist/packages/index.d.ts
CHANGED
package/dist/packages/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// npm for every package, game systems and rpg-engine itself included (D-436, D-452, D-515): installed, updated, a .tgz read. Depends on nothing else in rpg-engine.
|
|
2
|
-
export { npmEngine } from "./engine.js";
|
|
2
|
+
export { keepLatestEngine, keptLatestEngine, npmEngine } from "./engine.js";
|
|
3
3
|
export { isLocalSpec, isPackageName, issuesPage, isVerified, npmPackages, verifiedScope } from "./npm.js";
|
|
4
4
|
export { isTarball } from "./tarball.js";
|
|
@@ -4,6 +4,7 @@ export declare const bellLine = "The player acted on the dashboard: call status
|
|
|
4
4
|
export declare function listenHere(): Promise<void>;
|
|
5
5
|
/**
|
|
6
6
|
* Waits at the dashboard of the hook's chat until the player says a sentence: true then; false when there is none to wait at, or it goes away. The chat's own
|
|
7
|
-
* server is the one with its session; after /clear, which gives the hook a new one, the only server of its campaign
|
|
7
|
+
* server is the one with its session; after /clear, which gives the hook a new one, the only server of its campaign, while no other chat waits there for the
|
|
8
|
+
* page (D-577): better no ring than one in a chat that cannot read the page.
|
|
8
9
|
*/
|
|
9
10
|
export declare function waitForBell(input: string, ports?: number[]): Promise<boolean>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Claude Code's doorbell for the player's sentences on the dashboard (D-495): `rpg --listen`, the Stop hook init writes, waits at the dashboard of its own
|
|
2
2
|
// chat and, when the player says a sentence, tells the chat to call status. It never carries the sentence, which reaches the master in that call.
|
|
3
|
-
import { get } from "node:http";
|
|
4
3
|
import { findCampaign } from "../campaign/index.js";
|
|
5
4
|
import { samePath } from "../library/index.js";
|
|
6
|
-
import { campaignPorts } from "./dashboard/ports.js";
|
|
5
|
+
import { askDashboard, campaignPorts, dashboardAt } from "./dashboard/ports.js";
|
|
7
6
|
/** What the chat hears from the doorbell: never the player's words, only where to read them. */
|
|
8
7
|
export const bellLine = "The player acted on the dashboard: call status to read what they did.";
|
|
9
8
|
/** Reads the hook's input, waits for the doorbell, and ends the process as Claude Code's asyncRewake reads it: 2 with the line to wake the chat, else 0. */
|
|
@@ -22,7 +21,8 @@ export async function listenHere() {
|
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* Waits at the dashboard of the hook's chat until the player says a sentence: true then; false when there is none to wait at, or it goes away. The chat's own
|
|
25
|
-
* server is the one with its session; after /clear, which gives the hook a new one, the only server of its campaign
|
|
24
|
+
* server is the one with its session; after /clear, which gives the hook a new one, the only server of its campaign, while no other chat waits there for the
|
|
25
|
+
* page (D-577): better no ring than one in a chat that cannot read the page.
|
|
26
26
|
*/
|
|
27
27
|
export async function waitForBell(input, ports) {
|
|
28
28
|
const hook = hookInput(input);
|
|
@@ -30,10 +30,13 @@ export async function waitForBell(input, ports) {
|
|
|
30
30
|
if (root === undefined) {
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
-
const probes = await Promise.all((ports ?? campaignPorts(root)).filter((port) => port !== 0).map(async (port) => ({ port, said: await
|
|
34
|
-
const ours = probes.
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const probes = await Promise.all((ports ?? campaignPorts(root)).filter((port) => port !== 0).map(async (port) => ({ port, said: await dashboardAt(port) })));
|
|
34
|
+
const ours = probes.flatMap((one) => (one.said !== undefined && one.said.root !== null && samePath(one.said.root, root) ? [{ port: one.port, said: one.said }] : []));
|
|
35
|
+
// The only page of the campaign, once nobody else waits for it: a chat that does could be this one, and a wrong chat cannot read the page. An older
|
|
36
|
+
// engine's page does not say who waits, so it is never taken as this chat's.
|
|
37
|
+
const only = ours.length === 1 && ours[0].said.others?.length === 0 ? ours[0] : undefined;
|
|
38
|
+
const port = (ours.find((one) => hook.session !== undefined && one.said.session === hook.session) ?? only)?.port;
|
|
39
|
+
return port === undefined ? false : (await askDashboard(port, "/api/bell")) === "ring";
|
|
37
40
|
}
|
|
38
41
|
function hookInput(input) {
|
|
39
42
|
try {
|
|
@@ -47,37 +50,3 @@ function hookInput(input) {
|
|
|
47
50
|
return {};
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
|
-
// How long a port may take to say whose dashboard it is: one of this computer answers at once.
|
|
51
|
-
const probeWait = 1000;
|
|
52
|
-
/** Whose dashboard answers at a port: its chat's session and campaign; undefined where none does. */
|
|
53
|
-
async function probe(port) {
|
|
54
|
-
const said = await body(port, "/api/bell?probe", probeWait);
|
|
55
|
-
try {
|
|
56
|
-
const parsed = said === undefined ? undefined : JSON.parse(said);
|
|
57
|
-
return parsed === undefined
|
|
58
|
-
? undefined
|
|
59
|
-
: { session: typeof parsed.session === "string" ? parsed.session : null, root: typeof parsed.root === "string" ? parsed.root : null };
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/** The body a dashboard of this computer answers with, once it ends; undefined when it does not answer, or not with 200. */
|
|
66
|
-
function body(port, path, wait) {
|
|
67
|
-
return new Promise((done) => {
|
|
68
|
-
// A connection of its own: Node's shared one ends a request idle for five seconds, and the doorbell waits for hours.
|
|
69
|
-
const request = get({ host: "127.0.0.1", port, path, agent: false, ...(wait === undefined ? {} : { timeout: wait }) }, (response) => {
|
|
70
|
-
let text = "";
|
|
71
|
-
response.setEncoding("utf8");
|
|
72
|
-
response.on("data", (chunk) => {
|
|
73
|
-
text += chunk;
|
|
74
|
-
});
|
|
75
|
-
response.on("end", () => done(response.statusCode === 200 ? text : undefined));
|
|
76
|
-
response.on("error", () => done(undefined));
|
|
77
|
-
});
|
|
78
|
-
if (wait !== undefined) {
|
|
79
|
-
request.on("timeout", () => request.destroy());
|
|
80
|
-
}
|
|
81
|
-
request.on("error", () => done(undefined));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EngineUpdater } from "../../core/context.ts";
|
|
2
|
+
import type { Served } from "./index.ts";
|
|
3
|
+
/** npm's latest version of rpg-engine, or why npm could not be asked. */
|
|
4
|
+
export type EngineLatest = {
|
|
5
|
+
version: string;
|
|
6
|
+
} | {
|
|
7
|
+
failed: string;
|
|
8
|
+
};
|
|
9
|
+
/** The last time this server asked npm: when, what it is answering, and whether it failed. */
|
|
10
|
+
export interface EngineAsked {
|
|
11
|
+
at: number;
|
|
12
|
+
latest: Promise<EngineLatest>;
|
|
13
|
+
failed: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** npm's latest rpg-engine as known today: asked by this server or kept from today's check, else asked now and kept. */
|
|
16
|
+
export declare function knownLatest(served: Served, updater: EngineUpdater): Promise<EngineLatest>;
|
|
17
|
+
/** Asks npm for its latest rpg-engine now, and keeps what it said for the page. */
|
|
18
|
+
export declare function askLatest(served: Served, updater: EngineUpdater): Promise<EngineLatest>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { keepLatestEngine, keptLatestEngine } from "../../packages/index.js";
|
|
2
|
+
const checkHolds = 24 * 60 * 60 * 1000;
|
|
3
|
+
const retryAfter = 60 * 60 * 1000;
|
|
4
|
+
/** npm's latest rpg-engine as known today: asked by this server or kept from today's check, else asked now and kept. */
|
|
5
|
+
export async function knownLatest(served, updater) {
|
|
6
|
+
const now = served.context.now().getTime();
|
|
7
|
+
const asked = served.engineLatest;
|
|
8
|
+
if (asked !== undefined && now - asked.at >= 0 && now - asked.at < (asked.failed ? retryAfter : checkHolds)) {
|
|
9
|
+
return await asked.latest;
|
|
10
|
+
}
|
|
11
|
+
const kept = keptLatestEngine(served.context.home, now);
|
|
12
|
+
if (kept !== undefined) {
|
|
13
|
+
served.engineLatest = { at: kept.checked, latest: Promise.resolve({ version: kept.version }), failed: false };
|
|
14
|
+
return { version: kept.version };
|
|
15
|
+
}
|
|
16
|
+
return await askLatest(served, updater);
|
|
17
|
+
}
|
|
18
|
+
/** Asks npm for its latest rpg-engine now, and keeps what it said for the page. */
|
|
19
|
+
export async function askLatest(served, updater) {
|
|
20
|
+
const now = served.context.now().getTime();
|
|
21
|
+
const asking = { at: now, latest: updater.latest(), failed: false };
|
|
22
|
+
served.engineLatest = asking;
|
|
23
|
+
const latest = await asking.latest;
|
|
24
|
+
if ("failed" in latest) {
|
|
25
|
+
asking.failed = true;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
keepLatestEngine(served.context.home, now, latest.version);
|
|
29
|
+
}
|
|
30
|
+
return latest;
|
|
31
|
+
}
|