rpg-engine 0.9.0 → 0.10.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/source.js +6 -5
- package/dist/commands/find.d.ts +1 -0
- package/dist/commands/find.js +3 -2
- package/dist/commands/package.d.ts +3 -3
- package/dist/commands/package.js +72 -35
- package/dist/commands/rules.js +4 -2
- package/dist/commands/shared/adventures.js +20 -11
- package/dist/commands/shared/library.js +13 -5
- package/dist/commands/shared/packages/catalog.d.ts +2 -0
- package/dist/commands/shared/packages/catalog.js +1 -0
- package/dist/commands/shared/rules.js +29 -5
- package/dist/commands/view/place.d.ts +2 -0
- package/dist/commands/view/place.js +8 -2
- package/dist/core/context.d.ts +2 -0
- package/dist/core/refusal.d.ts +12 -0
- package/dist/core/refusal.js +17 -0
- package/dist/dashboard/api.js +37 -81
- package/dist/dashboard/app.js +10 -3
- package/dist/dashboard/asked.js +6 -3
- package/dist/dashboard/assets/master.svg +1 -2
- package/dist/dashboard/card.js +1 -1
- package/dist/dashboard/dice/load.js +6 -1
- package/dist/dashboard/dice/throw.js +5 -1
- package/dist/dashboard/dice/tray.js +5 -1
- package/dist/dashboard/footer.js +2 -2
- package/dist/dashboard/game-words.js +32 -32
- package/dist/dashboard/guide/ar.md +5 -5
- package/dist/dashboard/guide/cs.md +7 -7
- package/dist/dashboard/guide/da.md +5 -5
- package/dist/dashboard/guide/de.md +5 -5
- package/dist/dashboard/guide/el.md +7 -7
- package/dist/dashboard/guide/en.md +2 -2
- package/dist/dashboard/guide/es.md +6 -6
- package/dist/dashboard/guide/fi.md +5 -5
- package/dist/dashboard/guide/fr.md +6 -6
- package/dist/dashboard/guide/he.md +7 -7
- package/dist/dashboard/guide/hi.md +6 -6
- package/dist/dashboard/guide/hu.md +7 -7
- package/dist/dashboard/guide/is.md +7 -7
- package/dist/dashboard/guide/it.md +5 -5
- package/dist/dashboard/guide/ja.md +7 -7
- package/dist/dashboard/guide/ko.md +9 -9
- package/dist/dashboard/guide/nb.md +6 -6
- package/dist/dashboard/guide/nl.md +7 -7
- package/dist/dashboard/guide/pl.md +7 -7
- package/dist/dashboard/guide/pt.md +5 -5
- package/dist/dashboard/guide/ro.md +8 -8
- package/dist/dashboard/guide/ru.md +7 -7
- package/dist/dashboard/guide/sv.md +6 -6
- package/dist/dashboard/guide/tr.md +8 -8
- package/dist/dashboard/guide/uk.md +6 -6
- package/dist/dashboard/guide/zh.md +8 -8
- package/dist/dashboard/help/blocks.js +6 -0
- package/dist/dashboard/help/help.js +15 -3
- package/dist/dashboard/help/markdown.js +2 -1
- package/dist/dashboard/i18n/ar.json +53 -1
- package/dist/dashboard/i18n/cs.json +53 -1
- package/dist/dashboard/i18n/da.json +53 -1
- package/dist/dashboard/i18n/de.json +53 -1
- package/dist/dashboard/i18n/el.json +53 -1
- package/dist/dashboard/i18n/es.json +53 -1
- package/dist/dashboard/i18n/fi.json +53 -1
- package/dist/dashboard/i18n/fr.json +53 -1
- package/dist/dashboard/i18n/he.json +53 -1
- package/dist/dashboard/i18n/hi.json +53 -1
- package/dist/dashboard/i18n/hu.json +53 -1
- package/dist/dashboard/i18n/is.json +53 -1
- package/dist/dashboard/i18n/it.json +56 -4
- package/dist/dashboard/i18n/ja.json +53 -1
- package/dist/dashboard/i18n/ko.json +53 -1
- package/dist/dashboard/i18n/nb.json +53 -1
- package/dist/dashboard/i18n/nl.json +53 -1
- package/dist/dashboard/i18n/pl.json +53 -1
- package/dist/dashboard/i18n/pt.json +53 -1
- package/dist/dashboard/i18n/ro.json +53 -1
- package/dist/dashboard/i18n/ru.json +53 -1
- package/dist/dashboard/i18n/sv.json +53 -1
- package/dist/dashboard/i18n/tr.json +53 -1
- package/dist/dashboard/i18n/uk.json +53 -1
- package/dist/dashboard/i18n/zh.json +53 -1
- package/dist/dashboard/icons.js +2 -2
- package/dist/dashboard/journal.js +9 -4
- package/dist/dashboard/labels.js +5 -4
- package/dist/dashboard/language-choice.js +3 -3
- package/dist/dashboard/markdown.js +11 -4
- package/dist/dashboard/notes.js +4 -2
- package/dist/dashboard/notices.js +2 -2
- package/dist/dashboard/packages/ask-card.js +1 -1
- package/dist/dashboard/packages/packages.js +14 -10
- package/dist/dashboard/packages/page-code.js +11 -3
- package/dist/dashboard/packages/widgets.js +5 -5
- package/dist/dashboard/pages.js +3 -3
- package/dist/dashboard/place/map-sheet.js +4 -3
- package/dist/dashboard/place/map-view.js +17 -5
- package/dist/dashboard/refusals.js +61 -0
- package/dist/dashboard/rolls.js +3 -3
- package/dist/dashboard/settings.js +19 -5
- package/dist/dashboard/sheet.js +26 -7
- package/dist/dashboard/status.js +19 -13
- package/dist/dashboard/style.css +113 -16
- package/dist/dashboard/text.js +6 -2
- package/dist/dashboard/top.js +7 -9
- package/dist/dashboard/turns.js +7 -2
- package/dist/dashboard/world/lore.js +16 -15
- package/dist/dashboard/world/map.js +43 -1
- package/dist/dashboard/world/world.js +50 -15
- package/dist/extensions/extension.js +4 -1
- package/dist/packages/npm.js +4 -2
- package/dist/packages/tarball.js +8 -4
- package/dist/rules/rule-book.d.ts +2 -0
- package/dist/rules/search.d.ts +4 -1
- package/dist/rules/search.js +8 -2
- package/dist/server/dashboard/writes.js +22 -13
- package/dist/systems/system-code.js +5 -0
- package/package.json +1 -1
|
@@ -61,13 +61,18 @@ export function WorldView({ version, lead, players, tab, item }) {
|
|
|
61
61
|
const shown = world === null ? ["map"] : worldTabs;
|
|
62
62
|
const chosen = shown.find((one) => one === tab) ?? "map";
|
|
63
63
|
const names = { map: t("Map"), lore: t("Lore"), documents: t("Documents"), calendar: t("Calendar") };
|
|
64
|
-
// A page of the lore that is
|
|
64
|
+
// A page of the lore that is on the map, a place, a region or a way, leads there; a place on the map to all the character knows of it.
|
|
65
65
|
const onMap = (places) => {
|
|
66
|
-
const spot = places.find((place) => map?.places.some((one) => one.name === place && one.x !== undefined
|
|
66
|
+
const spot = places.find((place) => map?.places.some((one) => one.name === place && one.x !== undefined) || map?.roads.some((road) => road.name === place));
|
|
67
67
|
return spot === undefined ? undefined : sectionAddress("world", "map", spot);
|
|
68
68
|
};
|
|
69
|
+
// What a region or a way is, by its name, as the map's list says it, for the lore (D-548).
|
|
70
|
+
const kinds = useMemo(() => new Map([
|
|
71
|
+
...(map?.places ?? []).filter((one) => one.radius !== undefined).map((one) => [one.name, [t("Region"), biomeLabel(one.biome)].filter((part) => part !== undefined).join(" · ")]),
|
|
72
|
+
...(map?.roads ?? []).map((road) => [road.name, wayLabel(road.kind)]),
|
|
73
|
+
]), [map]);
|
|
69
74
|
const readMore = (place) => world?.known.some((entry) => entry.name === place) ? sectionAddress("world", "lore", place) : undefined;
|
|
70
|
-
return (_jsxs("section", { class: "world", "aria-labelledby": "world-title", children: [_jsx(PageHead, { section: "world", id: "world-title" }), shown.length > 1 && _jsx(PageTabs, { section: "world", label: t("World"), chosen: chosen, tabs: shown.map((key) => ({ key, name: names[key] })) }), _jsxs("div", { class: "world-panel", id: "world-panel", ...(shown.length > 1 ? { role: "tabpanel", "aria-labelledby": `world-tab-${chosen}` } : {}), children: [chosen === "map" && _jsx(MapTab, { map: map, problem: problem, lead: lead, place: item, readMore: readMore }), chosen !== "map" && world === undefined && _jsx("p", { class: "browse-none", children: worldProblem ?? t("Reading…") }), chosen === "lore" && world && _jsx(LoreTab, { world: world, version: version, open: item, onMap: onMap, ...(players === undefined ? {} : { players }) }), chosen === "documents" && world && _jsx(DocumentsTab, { world: world, open: item, ...(players === undefined ? {} : { players }) }), chosen === "calendar" && world && _jsx(CalendarTab, { calendar: world.calendar })] }), _jsx(WidgetCards, { place: "page", page: "world" })] }));
|
|
75
|
+
return (_jsxs("section", { class: "world", "aria-labelledby": "world-title", children: [_jsx(PageHead, { section: "world", id: "world-title" }), shown.length > 1 && _jsx(PageTabs, { section: "world", label: t("World"), chosen: chosen, tabs: shown.map((key) => ({ key, name: names[key] })) }), _jsxs("div", { class: "world-panel", id: "world-panel", ...(shown.length > 1 ? { role: "tabpanel", "aria-labelledby": `world-tab-${chosen}` } : {}), children: [chosen === "map" && _jsx(MapTab, { map: map, problem: problem, lead: lead, place: item, readMore: readMore }), chosen !== "map" && world === undefined && _jsx("p", { class: "browse-none", children: worldProblem ?? t("Reading…") }), chosen === "lore" && world && _jsx(LoreTab, { world: world, version: version, open: item, onMap: onMap, kinds: kinds, ...(players === undefined ? {} : { players }) }), chosen === "documents" && world && _jsx(DocumentsTab, { world: world, open: item, ...(players === undefined ? {} : { players }) }), chosen === "calendar" && world && _jsx(CalendarTab, { calendar: world.calendar })] }), _jsx(WidgetCards, { place: "page", page: "world" })] }));
|
|
71
76
|
}
|
|
72
77
|
/** The world map's tab: the map's card, and the places as a list, its twin; `place` opens one on its own map, as the lore's Show on the map. */
|
|
73
78
|
function MapTab({ map, problem, lead, place, readMore }) {
|
|
@@ -90,11 +95,11 @@ function MapTab({ map, problem, lead, place, readMore }) {
|
|
|
90
95
|
setFocus((before) => ({ name: to, count: before.count + 1 }));
|
|
91
96
|
}
|
|
92
97
|
};
|
|
93
|
-
// A place the address names, on its own map
|
|
98
|
+
// A place, a region or a way the address names, on its own map: a place with its card open, a region or a way marked.
|
|
94
99
|
useEffect(() => {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
goTo(
|
|
100
|
+
const there = map === undefined || place === undefined ? undefined : mapHolding(map, place);
|
|
101
|
+
if (there !== undefined && place !== undefined) {
|
|
102
|
+
goTo(there, place);
|
|
98
103
|
// The map in sight, wherever the page was scrolled to in the lore.
|
|
99
104
|
requestAnimationFrame(() => document.querySelector(".map-card")?.scrollIntoView({ block: "start" }));
|
|
100
105
|
}
|
|
@@ -112,7 +117,7 @@ function MapTab({ map, problem, lead, place, readMore }) {
|
|
|
112
117
|
location.replace(sectionAddress("world"));
|
|
113
118
|
}
|
|
114
119
|
};
|
|
115
|
-
return (_jsxs("div", { class: "world-map", children: [_jsx(MapCard, { map: drawn, full: map, part: part, layout: layout, lead: lead, chosen: chosen, focus: focus, onChoose: choose, onGo: goTo, readMore: readMore }, part.name), _jsx(PlacesList, { map: drawn, layout: layout, onChoose: choose })] }));
|
|
120
|
+
return (_jsxs("div", { class: "world-map", children: [_jsx(MapCard, { map: drawn, full: map, part: part, layout: layout, lead: lead, chosen: chosen, focus: focus, onChoose: choose, onGo: goTo, readMore: readMore }, part.name), _jsx(PlacesList, { map: drawn, full: map, layout: layout, onChoose: choose })] }));
|
|
116
121
|
}
|
|
117
122
|
/**
|
|
118
123
|
* The map's card: its head, with the maps the character knows as tabs; the map with its tools and the card of the chosen place; the key under it. `map` is what
|
|
@@ -151,15 +156,17 @@ function MapCard({ map, full, part, layout, lead, chosen, focus, onChoose, onGo,
|
|
|
151
156
|
observer.observe(element);
|
|
152
157
|
return () => observer.disconnect();
|
|
153
158
|
}, []);
|
|
154
|
-
// The first view: all the character knows; on a phone, the land around the party.
|
|
159
|
+
// The first view: all the character knows; on a phone, the land around the party; with a place already chosen, as from the Lore's Show on the map, that place.
|
|
155
160
|
useEffect(() => {
|
|
156
161
|
if (size !== undefined && view === undefined) {
|
|
157
|
-
|
|
162
|
+
const spot = shownPoint(map, layout, focus.name);
|
|
163
|
+
const start = startView(map, lifted, size);
|
|
164
|
+
setView(spot === undefined ? start : roomFor(spot, start, size, size.width < 600));
|
|
158
165
|
}
|
|
159
166
|
}, [size]);
|
|
160
167
|
// A place chosen: the map brings it where the card leaves room, right of it on a wide screen, above it on a phone.
|
|
161
168
|
useEffect(() => {
|
|
162
|
-
const spot =
|
|
169
|
+
const spot = shownPoint(map, layout, focus.name);
|
|
163
170
|
if (spot !== undefined && size !== undefined && view !== undefined) {
|
|
164
171
|
setView(roomFor(spot, view, size, narrow));
|
|
165
172
|
}
|
|
@@ -304,7 +311,7 @@ function Drawing({ map, layout, ways, trails, lifted, ghost, passages, lead, vie
|
|
|
304
311
|
const big = isParty || (placeKinds[spot.kind ?? ""]?.size ?? 0) >= 2;
|
|
305
312
|
return { text: spot.name, x: X(spot.x), y: Y(spot.y), r: isParty ? 19 : symbolOf(spot).r + 1, size: big ? 16 : 13.5, weight: weightOf(spot, layout) };
|
|
306
313
|
}), markBoxes, [...reserved, ...regionBoxes], width, height);
|
|
307
|
-
return (_jsxs("svg", { class: "map-svg", viewBox: `0 0 ${width} ${height}`, "aria-hidden": "true", children: [_jsxs("defs", { children: [_jsx(GlassDefs, { prefix: "map" }), _jsxs("filter", { id: "map-grain", x: "0", y: "0", width: "100%", height: "100%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.9", numOctaves: 3, seed: 2 }), _jsx("feColorMatrix", { values: "0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.12 0 0 0 0.09 0" }), _jsx("feComposite", { in2: "SourceGraphic", operator: "in" })] }), _jsxs("filter", { id: "map-ink", x: "-5%", y: "-5%", width: "110%", height: "110%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.05", numOctaves: 2, seed: 4 }), _jsx("feDisplacementMap", { in: "SourceGraphic", scale: 2.2 })] }), _jsxs("radialGradient", { id: "map-age", cx: "50%", cy: "50%", r: "72%", children: [_jsx("stop", { offset: "0.62", "stop-color": "#6e5028", "stop-opacity": "0" }), _jsx("stop", { offset: "1", "stop-color": "#6e5028", "stop-opacity": "0.3" })] }), _jsx("clipPath", { id: "map-token", children: _jsx("circle", { r: 13 }) }), wayNames.map((run, index) => run === undefined ? null : _jsx("path", { id: `world-way-name-${index}`, d: pathOf(run) }, index))] }), _jsx("rect", { class: "map-fog", width: width, height: height }), hexes.map((hex, index) => (_jsx("polygon", { class: hex.lit ? `hex lit ${biomeLook(hex.biome)}` : "hex fogged", "fill-opacity": hex.lit ? (0.8 + hex.tone * 0.2).toFixed(2) : undefined, points: hexCorners(hex, across).map((corner) => `${X(corner.x).toFixed(1)},${Y(corner.y).toFixed(1)}`).join(" ") }, index))), hexPixels >= 24 && (_jsx("g", { class: "tufts", children: hexes.filter((hex) => hex.lit && hex.biome !== undefined && biomes[hex.biome] !== undefined).flatMap((hex, index) => marksOf(hex, hexPixels).map((mark, at) => (_jsx("path", { class: `tuft ${hex.biome}`, transform: `translate(${(X(hex.x) + mark.x).toFixed(1)} ${(Y(hex.y) + mark.y).toFixed(1)}) scale(${mark.scale.toFixed(2)})`, d: biomes[hex.biome ?? ""].mark }, `${index} ${at}`)))) })), [...edges].map(([region, segments]) => (_jsx("path", { class: `region-edge ${biomeLook(layout.regions.find((one) => one.name === region)?.biome)}`, d: segments.map(([from, to]) => `M${X(from.x).toFixed(1)} ${Y(from.y).toFixed(1)}L${X(to.x).toFixed(1)} ${Y(to.y).toFixed(1)}`).join(""), filter: "url(#map-ink)" }, region))), _jsx("rect", { class: "map-grain", width: width, height: height, filter: "url(#map-grain)" }), trails.map((run, index) => _jsx("path", { class: "trail", d: line(run) }, index)), ghost !== undefined && (_jsxs("g", { class: "ghost", children: [ghost.ways.map((way) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, way.name)), ghost.spots.map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: false }, spot.name))] })), drawn.map((way) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, way.name)), drawn.map((way, index) => wayNames[index] === undefined ? null : (_jsx("text", { class: `way-label ${wayLook(way.kind)}`, dy: wayLook(way.kind) === "river" ? -16 : -6, children: _jsx("textPath", { href: `#world-way-name-${index}`, startOffset: "50%", "text-anchor": "middle", children: way.name }) }, way.name))), _jsx("rect", { class: "map-age", width: width, height: height, fill: "url(#map-age)" }), layout.spots.filter((spot) => passages.includes(spot.name)).map((spot) => _jsx("circle", { class: "passage-ring", cx: X(spot.x), cy: Y(spot.y), r: symbolOf(spot).r + 5 }, spot.name)), layout.spots.filter((spot) => spot !== layout.partySpot).map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: spot.name === chosen }, spot.name)), party !== undefined && (_jsxs("g", { class: layout.partySpot !== undefined && layout.partySpot.name === chosen ? "party-mark selected" : "party-mark", transform: `translate(${X(party.x).toFixed(1)} ${Y(party.y).toFixed(1)})`, "data-place": layout.partySpot?.name, children: [_jsx("circle", { class: "party-pulse", r: 17 }), _jsxs("g", { filter: "url(#map-drop)", children: [_jsx("circle", { class: "party-ring", r: 17 }), _jsx("circle", { class: "party-disc", r: 14.5 }), image !== undefined && _jsx("image", { href: image, x: -13, y: -13, width: 26, height: 26, "clip-path": "url(#map-token)" }), _jsx(Glass, { r: 14.5, prefix: "map" })] })] })), _jsxs("g", { class: "labels", children: [layout.regions.map((region, index) => {
|
|
314
|
+
return (_jsxs("svg", { class: "map-svg", viewBox: `0 0 ${width} ${height}`, "aria-hidden": "true", children: [_jsxs("defs", { children: [_jsx(GlassDefs, { prefix: "map" }), _jsxs("filter", { id: "map-grain", x: "0", y: "0", width: "100%", height: "100%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.9", numOctaves: 3, seed: 2 }), _jsx("feColorMatrix", { values: "0 0 0 0 0.35 0 0 0 0 0.25 0 0 0 0 0.12 0 0 0 0.09 0" }), _jsx("feComposite", { in2: "SourceGraphic", operator: "in" })] }), _jsxs("filter", { id: "map-ink", x: "-5%", y: "-5%", width: "110%", height: "110%", children: [_jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.05", numOctaves: 2, seed: 4 }), _jsx("feDisplacementMap", { in: "SourceGraphic", scale: 2.2 })] }), _jsxs("radialGradient", { id: "map-age", cx: "50%", cy: "50%", r: "72%", children: [_jsx("stop", { offset: "0.62", "stop-color": "#6e5028", "stop-opacity": "0" }), _jsx("stop", { offset: "1", "stop-color": "#6e5028", "stop-opacity": "0.3" })] }), _jsx("clipPath", { id: "map-token", children: _jsx("circle", { r: 13 }) }), wayNames.map((run, index) => run === undefined ? null : _jsx("path", { id: `world-way-name-${index}`, d: pathOf(run) }, index))] }), _jsx("rect", { class: "map-fog", width: width, height: height }), hexes.map((hex, index) => (_jsx("polygon", { class: hex.lit ? `hex lit ${biomeLook(hex.biome)}` : "hex fogged", "fill-opacity": hex.lit ? (0.8 + hex.tone * 0.2).toFixed(2) : undefined, points: hexCorners(hex, across).map((corner) => `${X(corner.x).toFixed(1)},${Y(corner.y).toFixed(1)}`).join(" ") }, index))), hexPixels >= 24 && (_jsx("g", { class: "tufts", children: hexes.filter((hex) => hex.lit && hex.biome !== undefined && biomes[hex.biome] !== undefined).flatMap((hex, index) => marksOf(hex, hexPixels).map((mark, at) => (_jsx("path", { class: `tuft ${hex.biome}`, transform: `translate(${(X(hex.x) + mark.x).toFixed(1)} ${(Y(hex.y) + mark.y).toFixed(1)}) scale(${mark.scale.toFixed(2)})`, d: biomes[hex.biome ?? ""].mark }, `${index} ${at}`)))) })), [...edges].map(([region, segments]) => (_jsx("path", { class: `region-edge ${biomeLook(layout.regions.find((one) => one.name === region)?.biome)}${region === chosen ? " selected" : ""}`, d: segments.map(([from, to]) => `M${X(from.x).toFixed(1)} ${Y(from.y).toFixed(1)}L${X(to.x).toFixed(1)} ${Y(to.y).toFixed(1)}`).join(""), filter: "url(#map-ink)" }, region))), _jsx("rect", { class: "map-grain", width: width, height: height, filter: "url(#map-grain)" }), trails.map((run, index) => _jsx("path", { class: "trail", d: line(run) }, index)), drawn.filter((way) => way.name === chosen).map((way, index) => _jsx("path", { class: "chosen-way", d: line(way.course) }, index)), ghost !== undefined && (_jsxs("g", { class: "ghost", children: [ghost.ways.map((way, index) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, `${way.name} ${index}`)), ghost.spots.map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: false }, spot.name))] })), drawn.map((way, index) => _jsx(WayDrawing, { way: way, look: wayLook(way.kind), screen: screen, weight: weight }, `${way.name} ${index}`)), drawn.map((way, index) => wayNames[index] === undefined ? null : (_jsx("text", { class: `way-label ${wayLook(way.kind)}`, dy: wayLook(way.kind) === "river" ? -16 : -6, children: _jsx("textPath", { href: `#world-way-name-${index}`, startOffset: "50%", "text-anchor": "middle", children: way.name }) }, `${way.name} ${index}`))), _jsx("rect", { class: "map-age", width: width, height: height, fill: "url(#map-age)" }), layout.spots.filter((spot) => passages.includes(spot.name)).map((spot) => _jsx("circle", { class: "passage-ring", cx: X(spot.x), cy: Y(spot.y), r: symbolOf(spot).r + 5 }, spot.name)), layout.spots.filter((spot) => spot !== layout.partySpot).map((spot) => _jsx(PlaceSymbol, { spot: spot, x: X(spot.x), y: Y(spot.y), chosen: spot.name === chosen }, spot.name)), party !== undefined && (_jsxs("g", { class: layout.partySpot !== undefined && layout.partySpot.name === chosen ? "party-mark selected" : "party-mark", transform: `translate(${X(party.x).toFixed(1)} ${Y(party.y).toFixed(1)})`, "data-place": layout.partySpot?.name, children: [_jsx("circle", { class: "party-pulse", r: 17 }), _jsxs("g", { filter: "url(#map-drop)", children: [_jsx("circle", { class: "party-ring", r: 17 }), _jsx("circle", { class: "party-disc", r: 14.5 }), image !== undefined && _jsx("image", { href: image, x: -13, y: -13, width: 26, height: 26, "clip-path": "url(#map-token)" }), _jsx(Glass, { r: 14.5, prefix: "map" })] })] })), _jsxs("g", { class: "labels", children: [layout.regions.map((region, index) => {
|
|
308
315
|
const placed = regionLabels[index];
|
|
309
316
|
return placed === undefined ? null : (_jsxs("g", { children: [_jsx("text", { class: "label region-label", x: placed.x, y: placed.y, "text-anchor": "middle", children: region.name }), region.terrain !== undefined && _jsx("text", { class: "label region-note", x: placed.x, y: placed.y + 15, "text-anchor": "middle", children: terrainLabel(region.terrain) })] }, region.name));
|
|
310
317
|
}), layout.spots.map((spot, index) => {
|
|
@@ -338,9 +345,14 @@ function PlaceCard({ place, map, layout, narrow, onClose, onGo, readMore }) {
|
|
|
338
345
|
const closer = useRef(null);
|
|
339
346
|
// Its text, read when the card opens: the first lines as the character knows them.
|
|
340
347
|
useEffect(() => {
|
|
348
|
+
// Only this place's: an answer for the one opened before, which came late, is left.
|
|
349
|
+
let live = true;
|
|
341
350
|
setText(undefined);
|
|
342
|
-
readView(place.name).then((page) => setText(page.kind === "page" ? plainLine(page.text) : undefined), () => setText(undefined));
|
|
351
|
+
readView(place.name).then((page) => live && setText(page.kind === "page" ? plainLine(page.text) : undefined), () => live && setText(undefined));
|
|
343
352
|
closer.current?.focus({ preventScroll: true });
|
|
353
|
+
return () => {
|
|
354
|
+
live = false;
|
|
355
|
+
};
|
|
344
356
|
}, [place.name]);
|
|
345
357
|
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);
|
|
346
358
|
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) => [
|
|
@@ -357,12 +369,12 @@ function Key({ map, layout, narrow, trail, passages }) {
|
|
|
357
369
|
return (_jsxs("details", { class: "map-key", open: !narrow, children: [_jsx("summary", { children: t("Key") }), _jsxs("div", { class: "key-groups", children: [_jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Ways") }), _jsxs("ul", { children: [ways.map((look) => (_jsxs("li", { children: [_jsxs("svg", { class: "key-way", viewBox: "0 0 30 16", "aria-hidden": "true", children: [look === "river" && _jsx("path", { class: "river-water", d: "M2 9.6Q8 5.8 15 8.2T28 6.6L28 9.6Q22 12 15 10.4T2 10.8Z" }), look === "road" && (_jsxs(_Fragment, { children: [_jsx("path", { class: "road-ink", d: "M2 9q7-4 13-1t13-1", "stroke-width": 3.8 }), _jsx("path", { class: "road-paper", d: "M2 9q7-4 13-1t13-1", "stroke-width": 1.5 })] })), (look === "path" || look === "other") && _jsx("path", { class: `${look}-ink`, d: "M2 9q7-4 13-1t13-1", "stroke-width": 1.4 })] }), wayLabel(look)] }, look))), trail && (_jsxs("li", { children: [_jsx("svg", { class: "key-way", viewBox: "0 0 30 16", "aria-hidden": "true", children: _jsx("path", { class: "trail", d: "M4 8h22" }) }), t("Your trail")] })), _jsxs("li", { children: [_jsxs("svg", { class: "key-symbol", viewBox: "-9 -9 18 18", "aria-hidden": "true", children: [_jsx("circle", { class: "party-ring", r: 7.5 }), _jsx("circle", { class: "party-disc", r: 5.5 })] }), t("Your party")] }), passages && (_jsxs("li", { children: [_jsx("svg", { class: "key-symbol", viewBox: "-12 -12 24 24", "aria-hidden": "true", children: _jsx("circle", { class: "passage-ring", r: 9 }) }), t("Passage to another map")] }))] })] }), _jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Land") }), _jsxs("ul", { children: [lands.map((look) => (_jsxs("li", { children: [_jsx(BiomeSwatch, { look: look }), biomeLabel(look) ?? t("Other land")] }, look))), _jsxs("li", { children: [_jsx("svg", { class: "key-swatch", viewBox: "0 0 22 16", "aria-hidden": "true", children: _jsx("rect", { class: "hex fogged", x: 1, y: 1, width: 20, height: 14, rx: 3 }) }), t("Not found yet")] })] })] }), _jsxs("div", { class: "key-group", children: [_jsx("h4", { class: "eyebrow key-title", children: t("Places") }), _jsx("ul", { children: kinds.map((kind) => (_jsxs("li", { children: [_jsx("svg", { class: "key-symbol", viewBox: "-17 -17 34 34", "aria-hidden": "true", children: _jsx(PlaceSymbol, { spot: { name: kind, x: 0, y: 0, within: [], ...(kind === "other" ? {} : { kind }) }, x: 0, y: 0, chosen: false }) }), placeKindLabel(kind) ?? t("Other place")] }, kind))) })] })] })] }));
|
|
358
370
|
}
|
|
359
371
|
/** The map's twin: every place the character knows, nearest the party first, with how far and which way; then the regions and the ways. */
|
|
360
|
-
function PlacesList({ map, layout, onChoose }) {
|
|
372
|
+
function PlacesList({ map, full, layout, onChoose }) {
|
|
361
373
|
const choose = (name) => {
|
|
362
374
|
onChoose(name);
|
|
363
375
|
document.querySelector(".map")?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
364
376
|
};
|
|
365
|
-
return (_jsxs("section", { class: "card map-list", "aria-labelledby": "places-title", children: [_jsxs("header", { class: "map-head", children: [_jsx("h3", { id: "places-title", children: t("Places you know") }), _jsx("span", { class: "map-sub", children: map.party === undefined ? t("on the map") : t("from your party, as the crow flies") })] }), _jsx("ol", { class: "places", children: layout.spots.map((spot) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "place-row", onClick: () => choose(spot.name), children: [_jsx("span", { class: "pr-name", children: spot.name }), _jsx("span", { class: "pr-kind", children: [placeKindLabel(spot.kind) ?? t("Place"), ...(layout.inside(spot.name).length > 0 ? [t("{count} inside", { count: layout.inside(spot.name).length })] : [])].join(" · ") }), _jsx("span", { class: "pr-far num", dir: "auto", children: spot.from === undefined ? "" : fromLabel(spot.from, (km) => lengthText(km, map.unit)) })] }) }, spot.name))) }), (layout.regions.length > 0 || map.roads.length > 0) && _jsx("h4", { class: "eyebrow pc-sub", children: t("Regions and ways") }), _jsxs("ul", { class: "places", children: [layout.regions.map((region) => _jsx(RegionRow, { region: region, unit: map.unit }, region.name)), map.roads.map((road) => (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: road.name }), _jsx("span", { class: "pr-kind", children: wayLabel(road.kind) }), _jsx("span", { class: "pr-far num", children: lengthText(road.
|
|
377
|
+
return (_jsxs("section", { class: "card map-list", "aria-labelledby": "places-title", children: [_jsxs("header", { class: "map-head", children: [_jsx("h3", { id: "places-title", children: t("Places you know") }), _jsx("span", { class: "map-sub", children: map.party === undefined ? t("on the map") : t("from your party, as the crow flies") })] }), _jsx("ol", { class: "places", children: layout.spots.map((spot) => (_jsx("li", { children: _jsxs("button", { type: "button", class: "place-row", onClick: () => choose(spot.name), children: [_jsx("span", { class: "pr-name", children: spot.name }), _jsx("span", { class: "pr-kind", children: [placeKindLabel(spot.kind) ?? t("Place"), ...(layout.inside(spot.name).length > 0 ? [t("{count} inside", { count: layout.inside(spot.name).length })] : [])].join(" · ") }), _jsx("span", { class: "pr-far num", dir: "auto", children: spot.from === undefined ? "" : fromLabel(spot.from, (km) => lengthText(km, map.unit)) })] }) }, spot.name))) }), (layout.regions.length > 0 || map.roads.length > 0) && _jsx("h4", { class: "eyebrow pc-sub", children: t("Regions and ways") }), _jsxs("ul", { class: "places", children: [layout.regions.map((region) => _jsx(RegionRow, { region: region, unit: map.unit }, region.name)), waysListed(map.roads, full.roads).map((road) => (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: road.name }), _jsx("span", { class: "pr-kind", children: wayLabel(road.kind) }), _jsx("span", { class: "pr-far num", children: lengthText(road.km, map.unit) })] }) }, road.name)))] })] }));
|
|
366
378
|
}
|
|
367
379
|
function RegionRow({ region, unit }) {
|
|
368
380
|
return (_jsx("li", { children: _jsxs("span", { class: "place-row static", children: [_jsx("span", { class: "pr-name", children: region.name }), _jsxs("span", { class: "pr-kind", children: [region.biome !== undefined && biomes[region.biome] !== undefined && _jsx(BiomeSwatch, { look: region.biome }), [t("Region"), biomeLabel(region.biome), region.terrain === undefined ? undefined : terrainLabel(region.terrain)].filter((part) => part !== undefined).join(" · ")] }), _jsx("span", { class: "pr-far num", dir: "auto", children: t("{length} across", { length: lengthText(region.radius * 2, unit) }) })] }) }));
|
|
@@ -413,3 +425,26 @@ function wayLabel(kind) {
|
|
|
413
425
|
const labels = { river: t("River"), road: t("Road"), path: t("Path"), portal: t("Portal"), other: t("Other way") };
|
|
414
426
|
return labels[kind] ?? `${kind[0]?.toUpperCase() ?? ""}${kind.slice(1)}`;
|
|
415
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* The ways of a map as its list names them: each once, with its whole length, on this map and the others it leads to, its pieces together; a portal, which
|
|
430
|
+
* has none, left out.
|
|
431
|
+
*/
|
|
432
|
+
function waysListed(roads, whole) {
|
|
433
|
+
const names = [...new Set(roads.filter((road) => road.kind !== "portal").map((road) => road.name))];
|
|
434
|
+
return names.map((name) => {
|
|
435
|
+
const pieces = whole.filter((road) => road.name === name);
|
|
436
|
+
const km = pieces.reduce((sum, road) => sum + road.points.slice(1).reduce((length, point) => length + point.km, 0), 0);
|
|
437
|
+
return { name, kind: pieces[0]?.kind ?? "other", km };
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/** The map that draws a name: a place's or a region's own, the middle of a way's; none for a name it does not draw. */
|
|
441
|
+
function mapHolding(map, name) {
|
|
442
|
+
const points = map.roads.find((road) => road.name === name)?.points;
|
|
443
|
+
const point = map.places.find((one) => one.name === name && one.x !== undefined) ?? points?.[Math.floor(points.length / 2)];
|
|
444
|
+
return point === undefined ? undefined : mapNameOf(map, point);
|
|
445
|
+
}
|
|
446
|
+
/** Where the map brings a name chosen: a place, the middle of a region, or the middle of a way; none for a name it does not draw. */
|
|
447
|
+
function shownPoint(map, layout, name) {
|
|
448
|
+
const points = map.roads.find((road) => road.name === name)?.points;
|
|
449
|
+
return layout.spots.find((one) => one.name === name) ?? layout.regions.find((one) => one.name === name) ?? points?.[Math.floor((points?.length ?? 0) / 2)];
|
|
450
|
+
}
|
|
@@ -83,10 +83,13 @@ export function readExtension(folder) {
|
|
|
83
83
|
throw new Error(`${owner} cannot be read, because its ${extensionFileName} is not valid: ${z.prettifyError(declared.error).replace(/\s+/g, " ")}`);
|
|
84
84
|
}
|
|
85
85
|
const { title, about, language, attribution, needs, calendar, icons, widgets, figures } = declared.data;
|
|
86
|
-
// Its page code is a file of its own, by real paths, links included (D-510).
|
|
86
|
+
// Its page code is a file of its own, by real paths, links included (D-510); its code too, as the player's yes covers only its own files (T-63).
|
|
87
87
|
if (marker.page !== undefined && !isInside(realPath(folder), realPath(resolve(folder, marker.page)))) {
|
|
88
88
|
throw new Error(`${owner} cannot be used, because its page, ${marker.page}, is not inside its package: name a file of its own, such as dist/page.js.`);
|
|
89
89
|
}
|
|
90
|
+
if (manifest.data.main !== undefined && !isInside(realPath(folder), realPath(resolve(folder, manifest.data.main)))) {
|
|
91
|
+
throw new Error(`${owner} cannot be used, because its code, ${manifest.data.main}, is not inside its package: name a file of its own as its main, such as dist/index.js.`);
|
|
92
|
+
}
|
|
90
93
|
const adds = Object.fromEntries(systemAdditionNames.flatMap((key) => (declared.data[key] === undefined ? [] : [[key, declared.data[key]]])));
|
|
91
94
|
const parts = readParts(folder, owner);
|
|
92
95
|
// What the master reads of it in every chat, kept short (D-441).
|
package/dist/packages/npm.js
CHANGED
|
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { isAbsolute, join, resolve } from "node:path";
|
|
5
5
|
import { ourScope } from "../core/consents.js";
|
|
6
6
|
import { packageApi, readsApi } from "../core/package-declarations.js";
|
|
7
|
+
import { Refusal } from "../core/refusal.js";
|
|
7
8
|
import { isNewerVersion } from "../core/version.js";
|
|
8
9
|
import { isTarball, tarballText, unpackTarball } from "./tarball.js";
|
|
9
10
|
/** The keyword of the packages for rpg-engine on npm, by which they are found (D-439). */
|
|
@@ -358,6 +359,7 @@ function infoOf(read) {
|
|
|
358
359
|
version: read.version ?? "",
|
|
359
360
|
...(typeof marker?.kind === "string" ? { kind: marker.kind } : {}),
|
|
360
361
|
...(typeof marker?.api === "number" ? { api: marker.api } : {}),
|
|
362
|
+
...(typeof marker?.system === "string" ? { system: marker.system } : {}),
|
|
361
363
|
...(read.description === undefined ? {} : { description: read.description }),
|
|
362
364
|
...(authorOf(read) === undefined ? {} : { author: authorOf(read) }),
|
|
363
365
|
// What runs: a main, exports or a command; a package of texts alone has none.
|
|
@@ -382,7 +384,7 @@ async function json(url) {
|
|
|
382
384
|
}
|
|
383
385
|
function checkedSpec(spec) {
|
|
384
386
|
if (!npmSpec.test(spec)) {
|
|
385
|
-
throw new
|
|
387
|
+
throw new Refusal(`"${spec}" is not the name of an npm package, with its version if wanted, such as @rpgengine/weather or @rpgengine/weather@0.1.0.`, "not-a-name", { name: spec });
|
|
386
388
|
}
|
|
387
389
|
return spec;
|
|
388
390
|
}
|
|
@@ -390,7 +392,7 @@ function checkedSpec(spec) {
|
|
|
390
392
|
function quotedFolder(folder) {
|
|
391
393
|
const path = resolve(folder);
|
|
392
394
|
if (/["%$`!&]/.test(path)) {
|
|
393
|
-
throw new
|
|
395
|
+
throw new Refusal(`The folder ${path} has characters npm cannot be given safely ("%$\`!&): move it to another path.`, "folder-characters", { name: path });
|
|
394
396
|
}
|
|
395
397
|
return `"${path}"`;
|
|
396
398
|
}
|
package/dist/packages/tarball.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// A package's .tgz as npm pack makes it (D-452): a gzipped tar with its files under package/. Read with Node alone and checked whole before anything is
|
|
2
2
|
// written: a path that would leave the folder or that Windows reads otherwise, a link, a device, a duplicate or an archive cut short refuse it.
|
|
3
3
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { resolve } from "node:path";
|
|
4
|
+
import { basename, resolve } from "node:path";
|
|
5
5
|
import { gunzipSync } from "node:zlib";
|
|
6
6
|
import { archivePathParts, insideFolder, refuseTwice } from "../core/archive-paths.js";
|
|
7
|
+
import { Refusal } from "../core/refusal.js";
|
|
7
8
|
// The most an archive may unpack to: a package is never this big, a malicious archive could be.
|
|
8
9
|
const largest = 512 * 1024 * 1024;
|
|
9
10
|
const block = 512;
|
|
@@ -38,7 +39,10 @@ function entries(archive) {
|
|
|
38
39
|
}
|
|
39
40
|
catch (error) {
|
|
40
41
|
const big = error instanceof RangeError || (error instanceof Error && /larger than|maxOutputLength/i.test(error.message));
|
|
41
|
-
|
|
42
|
+
const name = basename(archive);
|
|
43
|
+
throw big
|
|
44
|
+
? new Refusal(`${archive} unpacks to more than ${largest / 1024 / 1024} MB, more than a package may.`, "archive-big", { name, size: String(largest / 1024 / 1024) })
|
|
45
|
+
: new Refusal(`${archive} is not a package's .tgz that reads: ${error instanceof Error ? error.message : String(error)}`, "archive-unread", { name });
|
|
42
46
|
}
|
|
43
47
|
const found = [];
|
|
44
48
|
let longName;
|
|
@@ -50,7 +54,7 @@ function entries(archive) {
|
|
|
50
54
|
const sizeField = text(header, 124, 12).trim();
|
|
51
55
|
const size = /^[0-7]*$/.test(sizeField) ? Number.parseInt(sizeField || "0", 8) : Number.NaN;
|
|
52
56
|
if (!Number.isSafeInteger(size) || at + block + size > tar.length) {
|
|
53
|
-
throw new
|
|
57
|
+
throw new Refusal(`${archive} is cut short, or is not a .tgz npm pack made: it is refused whole.`, "archive-unread", { name: basename(archive) });
|
|
54
58
|
}
|
|
55
59
|
const type = String.fromCharCode(header[156] || 48);
|
|
56
60
|
const data = tar.subarray(at + block, at + block + size);
|
|
@@ -67,7 +71,7 @@ function entries(archive) {
|
|
|
67
71
|
continue;
|
|
68
72
|
}
|
|
69
73
|
if (type !== "0" && type !== "5") {
|
|
70
|
-
throw new
|
|
74
|
+
throw new Refusal(`${archive} holds ${name}, which is not a plain file or folder (a link or a device): it is refused whole.`, "archive-link", { name: basename(archive), entry: name });
|
|
71
75
|
}
|
|
72
76
|
found.push({ path: packagePath(archive, name), directory: type === "5", data });
|
|
73
77
|
}
|
|
@@ -17,6 +17,8 @@ export interface RuleSection {
|
|
|
17
17
|
ownText: string;
|
|
18
18
|
/** The titles of its parts, one level below. */
|
|
19
19
|
parts: string[];
|
|
20
|
+
/** Its path in the book it is translated from, by which it is found too, as Death Saving Throws for Tiri salvezza contro morte (D-542). */
|
|
21
|
+
alias?: string[];
|
|
20
22
|
}
|
|
21
23
|
/** The sections of the markdown files in a folder and its folders, file by file in order of path; none when there is no such folder. */
|
|
22
24
|
export declare function readRuleBook(folder: string, source: string): RuleSection[];
|
package/dist/rules/search.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export interface RuleFinding {
|
|
|
12
12
|
* After sections it names, the others are found by the words of its last title alone: "Combat › Grappling" looks for grappling.
|
|
13
13
|
*/
|
|
14
14
|
export declare function findRules(sections: RuleSection[], text: string): RuleFinding[];
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Whether a section is the one a text names: its title, or titles of its path ending with its own, as in "Combat › Grappling"; a translated section by the
|
|
17
|
+
* path it has in its book's own language too (D-542).
|
|
18
|
+
*/
|
|
16
19
|
export declare function isTitled(section: RuleSection, text: string): boolean;
|
|
17
20
|
/** Whether a text holds every word of a search, as search compares words: what finds a precedent. */
|
|
18
21
|
export declare function hasAllWords(text: string, search: string): boolean;
|
package/dist/rules/search.js
CHANGED
|
@@ -22,10 +22,16 @@ export function findRules(sections, text) {
|
|
|
22
22
|
scored.sort((first, second) => second.score - first.score || titleLength(first.entry.section) - titleLength(second.entry.section) || first.entry.index - second.entry.index);
|
|
23
23
|
return [...named, ...scored.map(({ entry, score }) => ({ section: entry.section, titled: false, score }))];
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Whether a section is the one a text names: its title, or titles of its path ending with its own, as in "Combat › Grappling"; a translated section by the
|
|
27
|
+
* path it has in its book's own language too (D-542).
|
|
28
|
+
*/
|
|
26
29
|
export function isTitled(section, text) {
|
|
30
|
+
return pathTitled(section.path, text) || (section.alias !== undefined && pathTitled(section.alias, text));
|
|
31
|
+
}
|
|
32
|
+
function pathTitled(sectionPath, text) {
|
|
27
33
|
const titles = titlesIn(text).map(comparableText);
|
|
28
|
-
const path =
|
|
34
|
+
const path = sectionPath.map(comparableText);
|
|
29
35
|
if (titles.length === 0 || titles.at(-1) !== path.at(-1)) {
|
|
30
36
|
return false;
|
|
31
37
|
}
|
|
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import { readAdventureZip } from "../../adventures/index.js";
|
|
4
4
|
import { findCampaign, readSettings, readTextSetting, requireCampaign, settingNames } from "../../campaign/index.js";
|
|
5
5
|
import { config, playerSettingNamed, playerSettings, setupSettingNamed } from "../../commands/config.js";
|
|
6
|
-
import { adventureText, isInstalledPackage, packageCommand
|
|
6
|
+
import { adventureText, isInstalledPackage, packageCommand } from "../../commands/package.js";
|
|
7
7
|
import { playerSaveNews, save } from "../../commands/save.js";
|
|
8
8
|
import { installAdventure } from "../../commands/shared/adventures.js";
|
|
9
9
|
import { libraryContents, libraryEntries, startLibraryReading, unquoted } from "../../commands/shared/library.js";
|
|
@@ -13,6 +13,7 @@ import { packageCommands } from "../../commands/shared/packages/code.js";
|
|
|
13
13
|
import { exportsFolderName, resetPoints } from "../../commands/shared/saves.js";
|
|
14
14
|
import { campaignSystem, campaignWorld } from "../../commands/shared/world.js";
|
|
15
15
|
import { packagesFolder } from "../../core/context.js";
|
|
16
|
+
import { Refusal, refusalBody } from "../../core/refusal.js";
|
|
16
17
|
import { files, withFiles } from "../../core/store.js";
|
|
17
18
|
import { comparableText } from "../../core/text.js";
|
|
18
19
|
import { getVersion, isNewerVersion } from "../../core/version.js";
|
|
@@ -208,7 +209,7 @@ export async function changePackage(request, response, served) {
|
|
|
208
209
|
const { action, name } = parsed.data;
|
|
209
210
|
// The page updates or takes away only what this computer has: it never brings a package new to it, nor its window, by these (D-510).
|
|
210
211
|
if (!isInstalledPackage(served.context, name)) {
|
|
211
|
-
sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it
|
|
212
|
+
sendJson(response, 400, { error: `${name} is not installed on this computer: add a package from the Packages page, where you choose it.`, code: "not-here", values: { name } });
|
|
212
213
|
return;
|
|
213
214
|
}
|
|
214
215
|
const done = action === "update" ? "updated" : action === "remove" ? "took out of the campaign" : "uninstalled";
|
|
@@ -231,11 +232,15 @@ export async function addPackage(request, response, served) {
|
|
|
231
232
|
return;
|
|
232
233
|
}
|
|
233
234
|
if (!json && bytes === undefined) {
|
|
234
|
-
sendJson(response, 413, { error: `The file is more than ${largestUpload / 1024 / 1024} MB: no package is that big
|
|
235
|
+
sendJson(response, 413, { error: `The file is more than ${largestUpload / 1024 / 1024} MB: no package is that big.`, code: "file-big", values: { size: String(largestUpload / 1024 / 1024) } });
|
|
235
236
|
return;
|
|
236
237
|
}
|
|
237
238
|
if (bytes !== undefined && !/\.(zip|tgz|tar\.gz)$/i.test(file)) {
|
|
238
|
-
sendJson(response, 400, {
|
|
239
|
+
sendJson(response, 400, {
|
|
240
|
+
error: `${file} is neither a .zip nor a .tgz: an adventure comes as a .zip, an extension, a game system or a language as a .tgz.`,
|
|
241
|
+
code: "file-kind",
|
|
242
|
+
values: { name: file },
|
|
243
|
+
});
|
|
239
244
|
return;
|
|
240
245
|
}
|
|
241
246
|
const source = given?.success === true ? given.data.source : file;
|
|
@@ -339,20 +344,24 @@ export async function engineNow(request, response, served) {
|
|
|
339
344
|
await packageWork(response, served, "rpg-engine", "engine", async () => {
|
|
340
345
|
const latest = await updater.latest();
|
|
341
346
|
if ("failed" in latest) {
|
|
342
|
-
throw new
|
|
347
|
+
throw new Refusal(`${latest.failed}: update it once this computer is online. Nothing changed.`, "engine-offline", { why: latest.failed });
|
|
343
348
|
}
|
|
344
349
|
if (!isNewerVersion(latest.version, onDisk)) {
|
|
345
|
-
throw
|
|
350
|
+
throw onDisk === version
|
|
351
|
+
? new Refusal(`rpg-engine ${version} is npm's latest: there is nothing to update.`, "engine-latest", { version })
|
|
352
|
+
: new Refusal(`rpg-engine ${onDisk} is installed already: it comes with a new chat.`, "engine-installed", { version: onDisk });
|
|
346
353
|
}
|
|
347
354
|
const installed = await updater.installed();
|
|
348
355
|
if (installed.how !== "global") {
|
|
349
|
-
throw
|
|
350
|
-
? `rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed
|
|
351
|
-
: `rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed
|
|
356
|
+
throw installed.how === "link"
|
|
357
|
+
? new Refusal(`rpg-engine here is a link to the folder ${installed.folder}, made by npm link for its development: update it there, with git pull and npm run build. Nothing changed.`, "engine-link", { name: installed.folder })
|
|
358
|
+
: new Refusal(`rpg-engine runs from ${installed.folder}, not from npm's global folder: update it the way it was installed. Nothing changed.`, "engine-elsewhere", {
|
|
359
|
+
name: installed.folder,
|
|
360
|
+
});
|
|
352
361
|
}
|
|
353
362
|
const why = await updater.update(latest.version);
|
|
354
363
|
if (why !== undefined) {
|
|
355
|
-
throw new
|
|
364
|
+
throw new Refusal(`rpg-engine could not be updated: ${why}. Nothing changed.`, "engine-failed", { why });
|
|
356
365
|
}
|
|
357
366
|
// The chat goes on with the server it started, and so does this page: the new engine comes with a new chat, or the app opened again.
|
|
358
367
|
const host = served.context.host?.() ?? "";
|
|
@@ -394,7 +403,7 @@ export async function exportCampaign(request, response, served) {
|
|
|
394
403
|
sendJson(response, 200, result.kind === "exported" ? { file: basename(result.file), pages: result.pages } : {});
|
|
395
404
|
}
|
|
396
405
|
catch (error) {
|
|
397
|
-
sendJson(response, 400,
|
|
406
|
+
sendJson(response, 400, refusalBody(error));
|
|
398
407
|
}
|
|
399
408
|
}
|
|
400
409
|
/** A zip of the campaign's exports/ folder, for the browser to save: by its name alone, never a path. */
|
|
@@ -436,7 +445,7 @@ function inLanguage(installed, served, language) {
|
|
|
436
445
|
*/
|
|
437
446
|
async function packageWork(response, served, name, action, work) {
|
|
438
447
|
if (served.packageWork !== undefined) {
|
|
439
|
-
sendJson(response, 409, { error: `${served.packageWork.name} is still being worked on: wait for it, then try again.`, code: "busy" });
|
|
448
|
+
sendJson(response, 409, { error: `${served.packageWork.name} is still being worked on: wait for it, then try again.`, code: "busy", values: { name: served.packageWork.name } });
|
|
440
449
|
return;
|
|
441
450
|
}
|
|
442
451
|
served.packageWork = { name, action, phase: "working" };
|
|
@@ -475,7 +484,7 @@ async function packageWork(response, served, name, action, work) {
|
|
|
475
484
|
sendJson(response, 202, { kind: done.kind, ...done.answer });
|
|
476
485
|
}
|
|
477
486
|
catch (error) {
|
|
478
|
-
sendJson(response, 400,
|
|
487
|
+
sendJson(response, 400, refusalBody(error));
|
|
479
488
|
}
|
|
480
489
|
finally {
|
|
481
490
|
served.packageWork = undefined;
|
|
@@ -85,6 +85,11 @@ export async function loadSystemCode(folders) {
|
|
|
85
85
|
loaded[name] = { refused: unread.replace(/^it /, ""), version };
|
|
86
86
|
continue;
|
|
87
87
|
}
|
|
88
|
+
// Its code is a file of its own, as the player's yes covers only its own files (T-63).
|
|
89
|
+
if (!isInside(realPath(own), realPath(resolve(own, main)))) {
|
|
90
|
+
loaded[name] = { refused: `has its code, ${main}, outside its package: name a file of its own as its main, such as dist/index.js`, version };
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
88
93
|
// Another's code runs only after the player's yes, for this version and these files (D-478, D-511).
|
|
89
94
|
if (!packageCodeMayRun(own)) {
|
|
90
95
|
loaded[name] = { refused: `is not ours, and the player has not said yes to it as it is installed: install it again with package install, for their yes`, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpg-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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": {
|