rpg-engine 0.23.1 → 0.24.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.
Files changed (124) hide show
  1. package/README.md +2 -2
  2. package/dist/campaign/create-campaign.d.ts +1 -1
  3. package/dist/campaign/create-campaign.js +1 -1
  4. package/dist/campaign/find-campaign.js +11 -1
  5. package/dist/campaign/host-files.d.ts +5 -6
  6. package/dist/campaign/host-files.js +100 -60
  7. package/dist/campaign/settings.d.ts +3 -3
  8. package/dist/campaign/settings.js +5 -4
  9. package/dist/cli/cli.js +11 -2
  10. package/dist/commands/config/config.js +1 -1
  11. package/dist/commands/config/dashboard.js +23 -6
  12. package/dist/commands/config/words.js +1 -0
  13. package/dist/commands/image.js +3 -3
  14. package/dist/commands/import/import.d.ts +3 -1
  15. package/dist/commands/import/import.js +13 -5
  16. package/dist/commands/instructions.js +1 -1
  17. package/dist/commands/shared/campaign/images.js +3 -2
  18. package/dist/commands/shared/campaign/mode.js +1 -1
  19. package/dist/commands/shared/characters/voices.d.ts +2 -2
  20. package/dist/commands/shared/characters/voices.js +9 -9
  21. package/dist/commands/shared/sheet/sheet.d.ts +2 -2
  22. package/dist/commands/shared/sheet/sheet.js +3 -3
  23. package/dist/core/context.d.ts +8 -2
  24. package/dist/dashboard/acts/acts.js +39 -11
  25. package/dist/dashboard/acts/head.js +7 -0
  26. package/dist/dashboard/acts/names.js +4 -2
  27. package/dist/dashboard/acts/sending.js +23 -22
  28. package/dist/dashboard/acts/sheet.js +7 -149
  29. package/dist/dashboard/acts/strip.js +10 -14
  30. package/dist/dashboard/acts/talk.js +51 -0
  31. package/dist/dashboard/acts/thing.js +169 -0
  32. package/dist/dashboard/app.js +3 -3
  33. package/dist/dashboard/guide/ar.md +13 -13
  34. package/dist/dashboard/guide/cs.md +12 -12
  35. package/dist/dashboard/guide/da.md +12 -12
  36. package/dist/dashboard/guide/de.md +11 -11
  37. package/dist/dashboard/guide/el.md +11 -11
  38. package/dist/dashboard/guide/en.md +10 -10
  39. package/dist/dashboard/guide/es.md +11 -11
  40. package/dist/dashboard/guide/fi.md +11 -11
  41. package/dist/dashboard/guide/fr.md +12 -12
  42. package/dist/dashboard/guide/he.md +11 -11
  43. package/dist/dashboard/guide/hi.md +11 -11
  44. package/dist/dashboard/guide/hu.md +11 -11
  45. package/dist/dashboard/guide/is.md +11 -11
  46. package/dist/dashboard/guide/it.md +38 -38
  47. package/dist/dashboard/guide/ja.md +11 -11
  48. package/dist/dashboard/guide/ko.md +12 -12
  49. package/dist/dashboard/guide/nb.md +11 -11
  50. package/dist/dashboard/guide/nl.md +11 -11
  51. package/dist/dashboard/guide/pl.md +11 -11
  52. package/dist/dashboard/guide/pt.md +11 -11
  53. package/dist/dashboard/guide/ro.md +12 -12
  54. package/dist/dashboard/guide/ru.md +12 -12
  55. package/dist/dashboard/guide/sv.md +12 -12
  56. package/dist/dashboard/guide/tr.md +12 -12
  57. package/dist/dashboard/guide/uk.md +11 -11
  58. package/dist/dashboard/guide/zh.md +12 -12
  59. package/dist/dashboard/i18n/ar.json +24 -10
  60. package/dist/dashboard/i18n/cs.json +24 -10
  61. package/dist/dashboard/i18n/da.json +24 -10
  62. package/dist/dashboard/i18n/de.json +24 -10
  63. package/dist/dashboard/i18n/el.json +24 -10
  64. package/dist/dashboard/i18n/es.json +24 -10
  65. package/dist/dashboard/i18n/fi.json +24 -10
  66. package/dist/dashboard/i18n/fr.json +24 -10
  67. package/dist/dashboard/i18n/he.json +24 -10
  68. package/dist/dashboard/i18n/hi.json +24 -10
  69. package/dist/dashboard/i18n/hu.json +24 -10
  70. package/dist/dashboard/i18n/is.json +24 -10
  71. package/dist/dashboard/i18n/it.json +102 -88
  72. package/dist/dashboard/i18n/ja.json +24 -10
  73. package/dist/dashboard/i18n/ko.json +24 -10
  74. package/dist/dashboard/i18n/nb.json +24 -10
  75. package/dist/dashboard/i18n/nl.json +24 -10
  76. package/dist/dashboard/i18n/pl.json +24 -10
  77. package/dist/dashboard/i18n/pt.json +24 -10
  78. package/dist/dashboard/i18n/ro.json +24 -10
  79. package/dist/dashboard/i18n/ru.json +24 -10
  80. package/dist/dashboard/i18n/sv.json +24 -10
  81. package/dist/dashboard/i18n/tr.json +24 -10
  82. package/dist/dashboard/i18n/uk.json +24 -10
  83. package/dist/dashboard/i18n/zh.json +24 -10
  84. package/dist/dashboard/packages/packages.js +1 -1
  85. package/dist/dashboard/parts/icons.js +2 -0
  86. package/dist/dashboard/parts/labels.js +1 -0
  87. package/dist/dashboard/parts/layout.js +34 -0
  88. package/dist/dashboard/parts/widgets.js +6 -2
  89. package/dist/dashboard/settings/language-choice.js +1 -1
  90. package/dist/dashboard/settings/settings.js +61 -36
  91. package/dist/dashboard/settings/tabs.js +14 -0
  92. package/dist/dashboard/sheet/sheet.js +54 -33
  93. package/dist/dashboard/shell/notices.js +2 -2
  94. package/dist/dashboard/style.css +122 -47
  95. package/dist/helpers/antigravity.d.ts +47 -0
  96. package/dist/helpers/antigravity.js +434 -0
  97. package/dist/helpers/chosen.d.ts +11 -7
  98. package/dist/helpers/chosen.js +64 -37
  99. package/dist/helpers/index.d.ts +1 -0
  100. package/dist/helpers/index.js +2 -1
  101. package/dist/helpers/opencode.js +117 -24
  102. package/dist/helpers/programs.d.ts +8 -0
  103. package/dist/helpers/programs.js +35 -2
  104. package/dist/helpers/stop.d.ts +2 -0
  105. package/dist/helpers/stop.js +20 -1
  106. package/dist/helpers/svg.d.ts +4 -1
  107. package/dist/helpers/svg.js +16 -4
  108. package/dist/instructions/index.d.ts +4 -2
  109. package/dist/instructions/index.js +6 -3
  110. package/dist/server/bell/antigravity.d.ts +7 -2
  111. package/dist/server/bell/antigravity.js +24 -6
  112. package/dist/server/bell/index.d.ts +1 -1
  113. package/dist/server/bell/index.js +1 -1
  114. package/dist/server/bell/listener.js +6 -1
  115. package/dist/server/fence.d.ts +21 -0
  116. package/dist/server/fence.js +69 -0
  117. package/dist/server/mcp.js +26 -0
  118. package/dist/server/player-acts.js +1 -1
  119. package/dist/server/subagent.d.ts +4 -0
  120. package/dist/server/subagent.js +30 -0
  121. package/instructions/voices-antigravity.md +1 -0
  122. package/instructions/voices-codex.md +1 -0
  123. package/instructions/voices-opencode.md +1 -1
  124. package/package.json +1 -1
@@ -139,8 +139,8 @@ export declare function sheetHeadline(world: World, system: GameSystem | undefin
139
139
  */
140
140
  export declare function statBlock(world: World, system: GameSystem | undefined, page: Page): SheetGroupData[];
141
141
  /**
142
- * What a thing's page says of it as data, for its card on the dashboard (D-573): the fields the system declares, of its own and of the pages it derives from,
143
- * as damage and weight; never the formulas it gives who holds it, as an attack, nor a bonus of 0. None for a page that is not an item.
142
+ * What a thing's or a topic's page says of it as data, for its card on the dashboard (D-573, D-581): the fields the system declares, of its own and of the
143
+ * pages it derives from, as damage and weight or a spell's range; never the formulas it gives who holds it, as an attack, nor a bonus of 0. None for any other page.
144
144
  */
145
145
  export declare function thingBlock(world: World, system: GameSystem | undefined, page: Page): SheetGroupData[];
146
146
  /** "Abilities: str 14 (+2) · dex 12 (+1)…": the sheet as the chat gives it, a line for each group. */
@@ -188,11 +188,11 @@ export function statBlock(world, system, page) {
188
188
  return values.length === 0 ? [] : [{ name: creature.name, values }];
189
189
  }
190
190
  /**
191
- * What a thing's page says of it as data, for its card on the dashboard (D-573): the fields the system declares, of its own and of the pages it derives from,
192
- * as damage and weight; never the formulas it gives who holds it, as an attack, nor a bonus of 0. None for a page that is not an item.
191
+ * What a thing's or a topic's page says of it as data, for its card on the dashboard (D-573, D-581): the fields the system declares, of its own and of the
192
+ * pages it derives from, as damage and weight or a spell's range; never the formulas it gives who holds it, as an attack, nor a bonus of 0. None for any other page.
193
193
  */
194
194
  export function thingBlock(world, system, page) {
195
- if (system === undefined || page.type !== "item") {
195
+ if (system === undefined || (page.type !== "item" && page.type !== "topic")) {
196
196
  return [];
197
197
  }
198
198
  const fields = effectiveFields(world, page);
@@ -61,10 +61,12 @@ export interface Context {
61
61
  files?: FileStore;
62
62
  /** The parts of the instructions already given in this chat, which the MCP server keeps until instructions starts over (D-97); without it, every call gives them. */
63
63
  told?: Set<string>;
64
- /** Whether the campaign had the character agent as the MCP server started, as Claude Code's agent and as OpenCode's subagent (D-490): the chat of that host then gets Voices. */
64
+ /** Whether the campaign had the character agent as the MCP server started, in each host that has agents (D-490, D-580): the chat of that host then gets Voices. */
65
65
  characterAgents?: {
66
66
  claudeCode?: boolean;
67
67
  openCode?: boolean;
68
+ codex?: boolean;
69
+ antigravity?: boolean;
68
70
  };
69
71
  /** The link of the player's dashboard, when the MCP server serves one (D-270); status gives it. */
70
72
  dashboard?: string;
@@ -254,7 +256,11 @@ export interface TextWriter {
254
256
  export interface DocumentReader {
255
257
  ready(): boolean;
256
258
  /** The program that would read now, which the player is told the document goes to (D-493). */
257
- program?(): "Claude Code" | "Codex" | "OpenCode" | undefined;
259
+ program?(): "Claude Code" | "Codex" | "OpenCode" | "Antigravity" | undefined;
260
+ /** The model it reads with, where the player chose it in the program, as in OpenCode, which may be paid by the call. */
261
+ model?(): string | undefined;
262
+ /** Takes away what a run stopped from outside left, as the importer's own process killed by a cancel. */
263
+ clean?(): void;
258
264
  /** One run: the brief on its input, reading only in `folder` and writing only in its `writable` subfolders; its last words, or why it stopped. Stopped by `signal`. */
259
265
  read(folder: string, brief: string, writable: string[], signal?: AbortSignal): Promise<{
260
266
  said: string;
@@ -101,6 +101,36 @@ export function itemVerbs(actions, item) {
101
101
  }
102
102
  return (item.equipped === true ? actions?.equipped : undefined) ?? actions?.inventory;
103
103
  }
104
+ /**
105
+ * The verbs of each thing of a sheet, by its page's name in any case (D-581 (D)): those every place of the sheet gives it, its lines by itemVerbs and the items
106
+ * of the lists the system names, in the order they first come in the groups, without repeats; the same verbs wherever the thing is clicked.
107
+ */
108
+ export function thingVerbs(actions, sheet) {
109
+ const verbs = new Map();
110
+ const add = (page, more) => {
111
+ const key = thingKey(page);
112
+ const before = verbs.get(key) ?? [];
113
+ verbs.set(key, [...before, ...(more ?? []).filter((verb) => !before.includes(verb))]);
114
+ };
115
+ for (const group of sheet) {
116
+ for (const value of group.values) {
117
+ const named = actions?.[value.field];
118
+ if (named !== undefined && named.length > 0) {
119
+ [...(value.items ?? []), ...(value.always?.items ?? [])].forEach((item) => add(item, named));
120
+ }
121
+ }
122
+ (group.items ?? []).forEach((item) => add(item.item, itemVerbs(actions, item)));
123
+ }
124
+ return verbs;
125
+ }
126
+ /** How thingVerbs keys a thing's page: its name trimmed, in any case. */
127
+ export function thingKey(page) {
128
+ return page.trim().toLocaleLowerCase();
129
+ }
130
+ /** A sentence as a button's label says it: without its final full stop. */
131
+ export function withoutFullStop(sentence) {
132
+ return sentence.trimEnd().replace(/[.。]$/u, "");
133
+ }
104
134
  /**
105
135
  * Who the player may name in a sentence: the other player characters there, the party's companions, then those at the place, as the map has them or else
106
136
  * the scene or the place, by the page's labels, as Hooded Bandit 1, never a name the character does not know; never the one acting, `self`, which is Myself,
@@ -121,23 +151,21 @@ export function actPeople(place, scene, companions, self) {
121
151
  }
122
152
  /**
123
153
  * Each sentence said on this page with how it stands, as the server tells it: waiting while it is pending, called once the doorbell rang for it, heard once
124
- * the master's call took it; while the game is away, and after, what was not heard is lost, to say again in the chat. One the server no longer knows of,
125
- * heard long ago, is left out; one copied stays so, in its place.
154
+ * the master's call took it; while the game is away, and after, what was not heard is lost, to say again. One the server no longer knows of, heard long
155
+ * ago, is left out.
126
156
  */
127
157
  export function saidStates(said, shown, live) {
128
158
  return said.flatMap((act) => {
129
159
  const pending = shown?.pending.find((one) => one.id === act.id);
130
160
  const heard = shown?.heard.includes(act.id) === true;
131
161
  const waiting = pending?.rung === true ? "called" : "said";
132
- const state = act.copied === true
133
- ? "copied"
134
- : heard
135
- ? "heard"
136
- : pending !== undefined && live
137
- ? waiting
138
- : !live || act.lost === true
139
- ? "lost"
140
- : undefined;
162
+ const state = heard
163
+ ? "heard"
164
+ : pending !== undefined && live
165
+ ? waiting
166
+ : !live || act.lost === true
167
+ ? "lost"
168
+ : undefined;
141
169
  return state === undefined ? [] : [{ act, state }];
142
170
  });
143
171
  }
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ import { Icon } from "../parts/icons.js";
3
+ import { t } from "../text.js";
4
+ /** The head of an action's card: `facts` under the title, as ×5 · in Backpack; `onBack`, when there is a step to go back to. */
5
+ export function ActHead({ title, facts = [], closer, onBack, onClose }) {
6
+ return (_jsxs("header", { class: "map-sheet-head act-head", children: [onBack !== undefined && (_jsx("button", { type: "button", class: "icon-button tip-right act-back", "aria-label": t("Back"), "data-tip": t("Back"), onClick: onBack, children: _jsx(Icon, { name: "fold" }) })), _jsxs("div", { class: "act-heading", children: [_jsx("h2", { id: "act-sheet-title", children: title }), facts.length > 0 && _jsx("p", { id: "act-facts", class: "act-facts", children: facts.join(" · ") })] }), _jsx("button", { ref: closer, type: "button", class: "icon-button tip-left", "aria-label": t("Close"), "data-tip": t("Close"), onClick: onClose, children: _jsx(Icon, { name: "close" }) })] }));
7
+ }
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "preact/jsx-runtime";
2
2
  // What starts the player's action (D-495): a thing's name of the sheet, or someone's, as a button where the page has the player's actions; else as it was.
3
3
  import { createContext } from "preact";
4
4
  import { useContext } from "preact/hooks";
@@ -6,6 +6,8 @@ import { t } from "../text.js";
6
6
  import { verbLabel } from "./acts.js";
7
7
  /** The player's actions where the page has them: none for a system that names none, and the page is as it was. */
8
8
  export const PlayerActsContext = createContext(undefined);
9
+ /** The verbs of each thing of the sheet shown, by thingVerbs (D-581 (D)): none outside a sheet, where a name keeps the verbs of its own list. */
10
+ export const ThingVerbsContext = createContext(undefined);
9
11
  /** The player's actions, when the page has them. */
10
12
  export function usePlayerActs() {
11
13
  return useContext(PlayerActsContext);
@@ -19,7 +21,7 @@ export function ActName({ verbs, item, page, facts, document, said = "", childre
19
21
  // The click opens the card: the tooltip names what can be done there, a screen reader the thing and what the sheet says of it.
20
22
  const title = verbs.length === 0 ? undefined : verbs.map(verbLabel).join(" · ");
21
23
  const start = { verbs, item, ...(page === undefined ? {} : { page }), ...(facts === undefined ? {} : { facts }), ...(document === undefined ? {} : { document }) };
22
- return (_jsxs("button", { type: "button", class: verbs.length === 0 ? "act reads" : "act", "data-tip": title, "aria-label": `${item}${said}`, onClick: (event) => acts?.start(start, event.currentTarget), children: [children, verbs.length > 0 && _jsx("span", { class: "act-mark", "aria-hidden": "true", children: "\u203A" })] }));
24
+ return (_jsx("button", { type: "button", class: verbs.length === 0 ? "act reads" : "act", "data-tip": title, "aria-label": `${item}${said}`, onClick: (event) => acts?.start(start, event.currentTarget), children: children }));
23
25
  }
24
26
  /** Someone's name that starts talking to them (D-495), where the page has the player's actions; else the name as it is. */
25
27
  export function TalkName({ name, children }) {
@@ -1,14 +1,14 @@
1
- // The player's sentences to the master (D-495), as the page holds them: the verbs of the sheet, the sentence being written, those said or copied and how the
2
- // server holds them, sent, taken back, copied and gone from the strip after a while. The page's read() sets the acts and the verbs it reads, by their setters.
1
+ // The player's sentences to the master (D-495), as the page holds them: the verbs of the sheet, the sentence being written, those said and how the
2
+ // server holds them, sent, taken back, said again and gone from the strip after a while. The page's read() sets the acts and the verbs it reads, by their setters.
3
3
  import { useEffect, useState } from "preact/hooks";
4
4
  import { answer, readView, sayAct, withdrawAct } from "../api.js";
5
5
  import { t } from "../text.js";
6
6
  import { saidStates } from "./acts.js";
7
- // How long a sentence the master heard, or one copied for the chat, stays in the strip (D-495).
7
+ // How long a sentence the master heard stays in the strip (D-495).
8
8
  const heardTime = 6000;
9
9
  /** The player's sentences to the master and what the page does with them (D-495). */
10
10
  export function useActs({ read, live, asked, foreground, version, players, member, several }) {
11
- // The verbs of the player character's sheet, the sentences said or copied and how the server holds them, and the action the player is writing, with
11
+ // The verbs of the player character's sheet, the sentences said and how the server holds them, and the action the player is writing, with
12
12
  // what started it, which has the focus back.
13
13
  const [actions, setActions] = useState();
14
14
  const [acts, setActs] = useState();
@@ -39,8 +39,8 @@ export function useActs({ read, live, asked, foreground, version, players, membe
39
39
  }
40
40
  }, [live]);
41
41
  const strip = saidStates(said, acts, live);
42
- const leaving = strip.filter((entry) => entry.state === "heard" || entry.state === "copied").map((entry) => entry.act.id).join();
43
- // A sentence heard, or copied, goes from the strip after a while.
42
+ const leaving = strip.filter((entry) => entry.state === "heard").map((entry) => entry.act.id).join();
43
+ // A sentence heard goes from the strip after a while.
44
44
  useEffect(() => {
45
45
  if (leaving === "") {
46
46
  return;
@@ -52,9 +52,9 @@ export function useActs({ read, live, asked, foreground, version, players, membe
52
52
  setSaid((before) => before.filter((one) => !ids.includes(one.id)));
53
53
  setActProblem(undefined);
54
54
  };
55
- // With a question of the master's open, the sentence answers it (ASK-10); else it rings the master, or, in a chat that hears nothing by itself, is copied.
55
+ // With a question of the master's open, the sentence answers it (ASK-10); else it goes to the master, who reads it at once with a doorbell, else at their next call.
56
56
  const question = asked !== undefined && asked.spend === undefined && asked.forced !== true ? asked : undefined;
57
- const reply = question !== undefined ? "answer" : acts?.bell === true ? "tell" : "copy";
57
+ const reply = question !== undefined ? "answer" : "tell";
58
58
  const answering = question === undefined ? undefined : { question: question.question, buttons: question.labels.length > 0 };
59
59
  const sendAct = async (text) => {
60
60
  setActProblem(undefined);
@@ -63,31 +63,32 @@ export function useActs({ read, live, asked, foreground, version, players, membe
63
63
  void read();
64
64
  return taken ? undefined : t("The answer did not reach the game: try again.");
65
65
  }
66
- if (reply === "copy") {
67
- return await copyAct(text) ? undefined : t("Copy did not work: select the words and copy them yourself.");
68
- }
69
66
  // The thing it starts from, for the master to hear what the character already knows of it (T-218).
70
67
  const item = acting !== undefined && "verbs" in acting.start ? acting.start.page ?? acting.start.item : undefined;
68
+ return await say(text, item);
69
+ };
70
+ // Sends a sentence to the master and puts it in the strip: undefined when done, else what went wrong.
71
+ const say = async (text, item, instead) => {
71
72
  const result = await sayAct(text, item);
72
73
  if ("error" in result) {
73
74
  return result.error;
74
75
  }
75
- setSaid((before) => [...before, { id: result.id, text }]);
76
+ setSaid((before) => [...before.filter((one) => one.id !== instead), { id: result.id, text, ...(item === undefined ? {} : { item }) }]);
76
77
  setActs(result.shown);
77
78
  return undefined;
78
79
  };
79
- const copyAct = async (text) => {
80
- try {
81
- await navigator.clipboard.writeText(text);
82
- setSaid((before) => [...before.filter((one) => one.copied !== true || one.text !== text), { id: `copied ${Date.now()}`, text, copied: true }]);
83
- return true;
80
+ // A sentence lost with the chat, said again with the same words, in place of the lost one.
81
+ const sayAgain = async (id) => {
82
+ const lost = said.find((one) => one.id === id);
83
+ if (lost === undefined) {
84
+ return;
84
85
  }
85
- catch {
86
- return false;
86
+ setActProblem(undefined);
87
+ const failed = await say(lost.text, lost.item, id);
88
+ if (failed !== undefined) {
89
+ setActProblem(failed);
87
90
  }
88
91
  };
89
- // A sentence copied again from the strip goes from it; one that would not copy says so.
90
- const copyFromStrip = (id, text) => void copyAct(text).then((done) => (done ? dismissAct(id) : setActProblem(t("Copy did not work: select the words and copy them yourself."))));
91
92
  const withdraw = async (id) => {
92
93
  const result = await withdrawAct(id);
93
94
  if (result === "heard") {
@@ -109,5 +110,5 @@ export function useActs({ read, live, asked, foreground, version, players, membe
109
110
  requestAnimationFrame(() => opener?.isConnected === true && opener.focus());
110
111
  };
111
112
  const playerActs = actions === undefined || players.length === 0 ? undefined : { actions, start: (start, opener) => setActing({ start, opener }) };
112
- return { setActs, setActions, playerActs, acting, actsElsewhere, actPlace, reply, answering, strip, actProblem, sendAct, closeAct, withdraw, copyFromStrip, dismissAct };
113
+ return { setActs, setActions, playerActs, acting, actsElsewhere, actPlace, reply, bell: acts?.bell === true, answering, strip, actProblem, sendAct, closeAct, withdraw, sayAgain, dismissAct };
113
114
  }
@@ -1,151 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
- import { useEffect, useRef, useState } from "preact/hooks";
3
- import { sectionAddress } from "../address.js";
4
- import { readView } from "../api.js";
5
- import { Icon } from "../parts/icons.js";
6
- import { fieldLabel, phraseLabel, shownText } from "../parts/labels.js";
7
- import { Markdown } from "../parts/markdown.js";
8
- import { PlaceMap } from "../place/view.js";
9
- import { t } from "../text.js";
10
- import { actPeople, actSentence, actTitle, spokenBy, talkSentence, targetMode, verbLabel } from "./acts.js";
11
- // How many characters a sentence may have, as the server takes them.
12
- const mostWords = 500;
13
- /**
14
- * The card of an action (D-495, D-573): a thing first, its page's text and its verbs; a verb chosen, on whom as chips and on the place's map,
15
- * then the sentence in a field, which Enter sends and Escape closes. A card in the middle, wider with the map; a sheet from the foot on a phone.
16
- */
1
+ import { jsx as _jsx } from "preact/jsx-runtime";
2
+ import { TalkSheet } from "./talk.js";
3
+ import { ThingSheet } from "./thing.js";
4
+ /** The card of an action: a thing's (D-573) or talking to someone's. A card in the middle, wider with the map; a sheet from the foot on a phone. */
17
5
  export function ActSheet({ start, self, place, scene, companions, reply, asked, onSend, onClose }) {
18
- const dialog = useRef(null);
19
- const field = useRef(null);
20
- const list = useRef(null);
21
- const verbsBar = useRef(null);
22
- const closer = useRef(null);
23
- const thing = "verbs" in start;
24
- // A thing opens on itself until a verb is chosen; talking goes straight to the words.
25
- const [verb, setVerb] = useState();
26
- const acting = !thing || verb !== undefined;
27
- const mode = verb === undefined ? "none" : targetMode(verb);
28
- const [target, setTarget] = useState();
29
- const [square, setSquare] = useState("");
30
- const map = place?.map;
31
- // With a map at the place, on whom is chosen on it too, by a click.
32
- const mapShown = map !== undefined && place !== undefined && mode !== "none";
33
- const people = actPeople(place, scene, companions, self);
34
- const shownTarget = target === undefined ? "none" : target === "square" ? (square.trim() === "" ? "none" : { square: square.trim().toUpperCase() }) : target;
35
- // With more than one player character the sentence starts with who acts (D-480 (8)).
36
- const composed = spokenBy("talk" in start ? talkSentence(start.talk) : actSentence(verb ?? "use", start.item, shownTarget), self);
37
- const [text, setText] = useState(composed);
38
- // What the page wrote last: changed by the player, the sentence is theirs and a new target leaves it as it is; a new verb writes it again.
39
- const written = useRef(composed);
40
- const writtenFor = useRef(verb);
41
- const [problem, setProblem] = useState();
42
- const [sending, setSending] = useState(false);
43
- // The text of the thing's page: undefined while it is read, empty for a page of data alone, null when the character knows no page of it.
44
- const [about, setAbout] = useState();
45
- // What the page says of the thing as data, as damage and weight (D-573).
46
- const [data, setData] = useState([]);
47
- const title = "talk" in start ? t("Talk to {name}", { name: start.talk }) : verb === undefined ? start.item : actTitle(verb, start.item);
48
- useEffect(() => {
49
- if (text === written.current || writtenFor.current !== verb) {
50
- setText(composed);
51
- }
52
- written.current = composed;
53
- writtenFor.current = verb;
54
- }, [composed, verb]);
55
- // A modal dialog lies over everything on the page and closes with Escape by itself; a thing's page is read once, when it opens.
56
- useEffect(() => {
57
- dialog.current?.showModal();
58
- if (!thing) {
59
- focusEnd(field.current);
60
- return;
61
- }
62
- (verbsBar.current?.querySelector("a, button") ?? closer.current)?.focus();
63
- let live = true;
64
- readView(start.page ?? start.item).then((page) => {
65
- if (live) {
66
- setAbout(page.kind === "page" ? page.text.trim() : null);
67
- setData(page.kind === "page" ? page.sheet.flatMap((group) => group.values) : []);
68
- }
69
- }, () => live && setAbout(null));
70
- return () => {
71
- live = false;
72
- };
73
- }, []);
74
- // The focus goes where the player chooses next: on whom, for a verb that needs someone; else the sentence, the cursor at its end.
75
- useEffect(() => {
76
- if (verb === undefined) {
77
- return;
78
- }
79
- if (mode === "asks") {
80
- list.current?.querySelector("input[type=radio]")?.focus();
81
- }
82
- else {
83
- focusEnd(field.current);
84
- }
85
- }, [verb]);
86
- const pick = (chosen) => {
87
- setVerb(chosen);
88
- setTarget(targetMode(chosen) === "lets" ? "none" : undefined);
89
- setProblem(undefined);
90
- };
91
- // Back to the thing, the focus on the verb that was chosen.
92
- const back = () => {
93
- const was = verb;
94
- setVerb(undefined);
95
- setProblem(undefined);
96
- requestAnimationFrame(() => verbsBar.current?.querySelector(`button[data-verb="${was ?? ""}"]`)?.focus());
97
- };
98
- const choose = (chosen) => {
99
- setTarget(chosen);
100
- setProblem(undefined);
101
- };
102
- const send = async (event) => {
103
- event.preventDefault();
104
- const words = text.trim();
105
- if (words === "" || sending) {
106
- return;
107
- }
108
- setSending(true);
109
- const failed = await onSend(words);
110
- setSending(false);
111
- if (failed === undefined) {
112
- dialog.current?.close();
113
- }
114
- else {
115
- setProblem(failed);
116
- }
117
- };
118
- // Enter sends, Shift+Enter starts a new line; never while an input method composes a word.
119
- const keys = (event) => {
120
- if (event.key === "Enter" && !event.shiftKey && !event.isComposing) {
121
- void send(event);
122
- }
123
- };
124
- // Enter on a choice of the list takes the player to the sentence.
125
- const toSentence = (event) => {
126
- if (event.key === "Enter") {
127
- event.preventDefault();
128
- focusEnd(field.current);
129
- }
130
- };
131
- const close = () => dialog.current?.close();
132
- const personChosen = typeof target === "object" && "person" in target ? target.person : undefined;
133
- const option = (key, chosen, label, kind = "") => (_jsxs("label", { class: ["act-who-one", kind].filter((name) => name !== "").join(" "), children: [_jsx("input", { type: "radio", name: "act-who", checked: sameTarget(target, chosen), onChange: () => choose(chosen), onKeyDown: toSentence }), label] }, key));
134
- const button = reply === "copy" ? t("Copy") : reply === "answer" ? t("Answer the master") : t("Tell the master");
135
- const facts = thing ? start.facts ?? [] : [];
136
- return (_jsxs("dialog", { ref: dialog, class: mapShown ? "map-sheet act-sheet wide" : "map-sheet act-sheet", "aria-labelledby": "act-sheet-title", "aria-describedby": !acting && facts.length > 0 ? "act-facts" : undefined, onClose: onClose, children: [_jsxs("header", { class: "map-sheet-head act-head", children: [thing && acting && (_jsx("button", { type: "button", class: "icon-button tip-right act-back", "aria-label": t("Back"), "data-tip": t("Back"), onClick: back, children: _jsx(Icon, { name: "fold" }) })), _jsxs("div", { class: "act-heading", children: [_jsx("h2", { id: "act-sheet-title", children: title }), !acting && facts.length > 0 && _jsx("p", { id: "act-facts", class: "act-facts", children: facts.join(" · ") })] }), _jsx("button", { ref: closer, type: "button", class: "icon-button tip-left", "aria-label": t("Close"), "data-tip": t("Close"), onClick: close, children: _jsx(Icon, { name: "close" }) })] }), thing && !acting && (_jsxs(_Fragment, { children: [data.length > 0 && (_jsx("dl", { class: "act-data", children: data.map((value) => (_jsxs("div", { children: [_jsx("dt", { children: phraseLabel(fieldLabel(value.field)) }), _jsx("dd", { children: shownText(value.text, value.kind) })] }, value.field))) })), about !== undefined && about !== "" && (about !== null || data.length === 0) && (_jsx("div", { class: "act-about", children: about === null ? _jsx("p", { class: "browse-none", children: t("Your character knows its name, and nothing more yet.") }) : _jsx(Markdown, { text: about }) })), (start.verbs.length > 0 || start.document === true) && (_jsxs("div", { ref: verbsBar, class: "act-buttons act-verbs", role: "group", "aria-label": t("What you do"), children: [start.document === true && (_jsx("a", { class: "map-sheet-go act-go", href: sectionAddress("world", "documents", start.page ?? start.item), onClick: close, children: t("Read it") })), start.verbs.map((one, index) => (_jsx("button", { type: "button", "data-verb": one, class: index === 0 && start.document !== true ? "map-sheet-go act-go" : "act-cancel", onClick: () => pick(one), children: verbLabel(one) }, one)))] }))] })), acting && mode !== "none" && (_jsxs("div", { class: "act-body", children: [_jsxs("fieldset", { ref: list, class: "act-who", children: [_jsx("legend", { class: "eyebrow", children: t("On whom") }), people.map((person, index) => option(`person ${index}`, { person: person.name }, _jsxs(_Fragment, { children: [_jsxs("span", { class: "act-who-name", children: [person.name, person.count !== undefined && _jsx("span", { class: "count", children: ` ×${person.count}` })] }), person.square !== undefined && _jsx("span", { class: "lm-key-square", children: person.square })] }), [person.role, person.hostile === true ? "hostile" : ""].filter((name) => name !== "").join(" "))), option("self", "self", _jsx("span", { class: "act-who-name", children: t("Myself") }), "plain"), option("none", "none", _jsx("span", { class: "act-who-name", children: t("No one in particular") }), "plain"), mapShown && option("square", "square", _jsx("span", { class: "act-who-name", children: t("A square…") }), "plain"), target === "square" && mapShown && (_jsx("input", { type: "text", class: "act-square", value: square, maxLength: 5, placeholder: "E4", "aria-label": t("The square, such as E4"), onInput: (event) => setSquare(event.currentTarget.value), onKeyDown: toSentence }))] }), mapShown && (_jsx(PlaceMap, { map: map, place: place.name, bare: true, self: self, choosing: { selected: personChosen, onChoose: (name) => choose(name === undefined ? "self" : { person: name }) }, ...(target === "square" ? { picking: { selected: square.trim().toUpperCase(), onSelect: setSquare } } : {}) }))] })), acting && (_jsxs("form", { class: "act-bar", onSubmit: (event) => void send(event), children: [reply === "answer" && (_jsxs("p", { id: "act-note", class: "act-note act-answer", children: [_jsx(Icon, { name: "bell" }), asked?.buttons === true
137
- ? t("These words answer the master instead of a roll or a button: {question}", { question: asked.question })
138
- : t("These words answer the master's question: {question}", { question: asked?.question ?? "" })] })), _jsxs("label", { for: "act-words", class: "eyebrow act-words-label", children: [_jsx(Icon, { name: "chat" }), t("Your words to the master")] }), _jsx("textarea", { ref: field, id: "act-words", class: "act-words", value: text, rows: 2, maxLength: mostWords, "aria-describedby": reply === "tell" ? undefined : "act-note", onInput: (event) => setText(event.currentTarget.value), onKeyDown: keys }), reply === "copy" && (_jsxs("p", { id: "act-note", class: "act-note", children: [_jsx(Icon, { name: "info" }), t("This chat does not hear it by itself: copy it, then paste it in the chat.")] })), problem && _jsx("p", { class: "act-problem", role: "alert", children: problem }), _jsxs("div", { class: "act-buttons", children: [_jsx("button", { type: "button", class: "act-cancel", onClick: close, children: t("Cancel") }), _jsxs("button", { type: "submit", class: "map-sheet-go act-go", disabled: sending || text.trim() === "", children: [button, _jsx(Icon, { name: reply === "copy" ? "copy" : "send" })] })] })] }))] }));
139
- }
140
- /** Whether two choices of the list are the same. */
141
- function sameTarget(target, other) {
142
- if (typeof target === "object" && typeof other === "object") {
143
- return "person" in target && "person" in other && target.person === other.person;
144
- }
145
- return target === other;
146
- }
147
- /** Focuses a field with its cursor at the end of what it holds. */
148
- function focusEnd(field) {
149
- field?.focus();
150
- field?.setSelectionRange(field.value.length, field.value.length);
6
+ return "talk" in start
7
+ ? _jsx(TalkSheet, { name: start.talk, self: self, reply: reply, asked: asked, onSend: onSend, onClose: onClose })
8
+ : _jsx(ThingSheet, { start: start, self: self, place: place, scene: scene, companions: companions, reply: reply, onSend: onSend, onClose: onClose });
151
9
  }
@@ -1,35 +1,33 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
2
- // The player's sentences after they go (D-495), in words and with a sign: said, with a button to take it back while it waits; called, the doorbell rang;
3
- // heard; or never heard, the chat gone, to say again there. A screen reader hears only the change of state.
2
+ // The player's sentences after they go (D-495), in words and with a sign: said, with a button to take it back while it waits, and without a doorbell when the
3
+ // master reads it; called, the doorbell rang; heard; or never heard, the chat gone, to say again. A screen reader hears only the change of state.
4
4
  import { useEffect, useRef, useState } from "preact/hooks";
5
5
  import { Icon } from "../parts/icons.js";
6
6
  import { t } from "../text.js";
7
- export function ActStrip({ entries, problem, onWithdraw, onCopy, onDismiss }) {
7
+ export function ActStrip({ entries, problem, bell, live, onWithdraw, onSayAgain, onDismiss }) {
8
8
  const before = useRef(new Map());
9
9
  const [told, setTold] = useState("");
10
- // Only what changed is told, the newest change last: a sentence said, heard, lost or copied.
10
+ // Only what changed is told, the newest change last: a sentence said, heard or lost.
11
11
  useEffect(() => {
12
12
  const changed = entries.filter(({ act, state }) => before.current.get(act.id) !== state).at(-1);
13
13
  before.current = new Map(entries.map(({ act, state }) => [act.id, state]));
14
14
  if (changed !== undefined) {
15
- setTold(stateWords(changed.state));
15
+ setTold(stateWords(changed.state, bell));
16
16
  }
17
17
  }, [entries.map(({ act, state }) => `${act.id} ${state}`).join()]);
18
- return (_jsxs(_Fragment, { children: [_jsx("p", { class: "visually-hidden", role: "status", children: told }), (entries.length > 0 || problem !== undefined) && (_jsxs("section", { class: "act-strip", "aria-label": t("Your sentences"), children: [entries.map(({ act, state }) => (_jsxs("p", { class: `act-line ${state}`, children: [_jsx("span", { class: "act-sign", children: _jsx(Icon, { name: stateIcon(state) }) }), _jsxs("span", { class: "act-said", children: [_jsx("q", { children: act.text }), _jsx("span", { class: "act-state", children: stateWords(state) })] }), state === "said" && _jsx("button", { type: "button", class: "act-small", "aria-label": t("Take it back from the master"), onClick: () => onWithdraw(act.id), children: t("Take back") }), state === "lost" && _jsx("button", { type: "button", class: "act-small", onClick: () => onCopy(act.id, act.text), children: t("Copy") }), state !== "said" && (_jsx("button", { type: "button", class: "icon-button act-close tip-left", "aria-label": t("Close"), "data-tip": t("Close"), onClick: () => onDismiss(act.id), children: _jsx(Icon, { name: "close" }) }))] }, act.id))), problem !== undefined && _jsx("p", { class: "act-problem", role: "alert", children: problem })] }))] }));
18
+ return (_jsxs(_Fragment, { children: [_jsx("p", { class: "visually-hidden", role: "status", children: told }), (entries.length > 0 || problem !== undefined) && (_jsxs("section", { class: "act-strip", "aria-label": t("Your sentences"), children: [entries.map(({ act, state }) => (_jsxs("p", { class: `act-line ${state}`, children: [_jsx("span", { class: "act-sign", children: _jsx(Icon, { name: stateIcon(state) }) }), _jsxs("span", { class: "act-said", children: [_jsx("q", { children: act.text }), _jsx("span", { class: "act-state", children: stateWords(state, bell) })] }), state === "said" && _jsx("button", { type: "button", class: "act-small", "aria-label": t("Take it back from the master"), onClick: () => onWithdraw(act.id), children: t("Take back") }), state === "lost" && _jsx("button", { type: "button", class: "act-small", disabled: !live, onClick: () => onSayAgain(act.id), children: t("Say it again") }), state !== "said" && (_jsx("button", { type: "button", class: "icon-button act-close tip-left", "aria-label": t("Close"), "data-tip": t("Close"), onClick: () => onDismiss(act.id), children: _jsx(Icon, { name: "close" }) }))] }, act.id))), problem !== undefined && _jsx("p", { class: "act-problem", role: "alert", children: problem })] }))] }));
19
19
  }
20
- /** How a sentence stands, in words. */
21
- function stateWords(state) {
20
+ /** How a sentence stands, in words; said without a doorbell, when the master reads it. */
21
+ function stateWords(state, bell) {
22
22
  switch (state) {
23
23
  case "said":
24
- return t("Said to the master");
24
+ return bell ? t("Said to the master") : t("Said to the master: they read it as soon as you write in the chat");
25
25
  case "called":
26
26
  return t("The master is about to read it");
27
27
  case "heard":
28
28
  return t("The master is reading it");
29
29
  case "lost":
30
- return t("Not heard: say it again in the chat");
31
- case "copied":
32
- return t("Copied: paste it in the chat");
30
+ return t("Not heard: the chat was closed");
33
31
  }
34
32
  }
35
33
  /** How a sentence stands, as a sign beside its words. */
@@ -43,7 +41,5 @@ function stateIcon(state) {
43
41
  return "check";
44
42
  case "lost":
45
43
  return "offline";
46
- case "copied":
47
- return "copy";
48
44
  }
49
45
  }
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
+ // Talking to someone from the page (D-495): the start of the sentence in a field, which the player goes on and sends; Enter sends, Escape closes.
3
+ import { useEffect, useRef, useState } from "preact/hooks";
4
+ import { Icon } from "../parts/icons.js";
5
+ import { t } from "../text.js";
6
+ import { spokenBy, talkSentence } from "./acts.js";
7
+ import { ActHead } from "./head.js";
8
+ // How many characters a sentence may have, as the server takes them.
9
+ const mostWords = 500;
10
+ /** The card of talking to someone: the player's words under a visible label, and how they go, told or as the answer to the master's question (ASK-10). */
11
+ export function TalkSheet({ name, self, reply, asked, onSend, onClose }) {
12
+ const dialog = useRef(null);
13
+ const field = useRef(null);
14
+ // With more than one player character the sentence starts with who acts (D-480 (8)).
15
+ const [text, setText] = useState(spokenBy(talkSentence(name), self));
16
+ const [problem, setProblem] = useState();
17
+ const [sending, setSending] = useState(false);
18
+ // A modal dialog lies over everything on the page and closes with Escape by itself; the cursor waits at the end of the words.
19
+ useEffect(() => {
20
+ dialog.current?.showModal();
21
+ field.current?.focus();
22
+ field.current?.setSelectionRange(field.current.value.length, field.current.value.length);
23
+ }, []);
24
+ const send = async (event) => {
25
+ event.preventDefault();
26
+ const words = text.trim();
27
+ if (words === "" || sending) {
28
+ return;
29
+ }
30
+ setSending(true);
31
+ const failed = await onSend(words);
32
+ setSending(false);
33
+ if (failed === undefined) {
34
+ dialog.current?.close();
35
+ }
36
+ else {
37
+ setProblem(failed);
38
+ }
39
+ };
40
+ // Enter sends, Shift+Enter starts a new line; never while an input method composes a word.
41
+ const keys = (event) => {
42
+ if (event.key === "Enter" && !event.shiftKey && !event.isComposing) {
43
+ void send(event);
44
+ }
45
+ };
46
+ const close = () => dialog.current?.close();
47
+ const button = reply === "answer" ? t("Answer the master") : t("Tell the master");
48
+ return (_jsxs("dialog", { ref: dialog, class: "map-sheet act-sheet", "aria-labelledby": "act-sheet-title", onClose: onClose, children: [_jsx(ActHead, { title: t("Talk to {name}", { name }), onClose: close }), _jsxs("form", { class: "act-bar", onSubmit: (event) => void send(event), children: [reply === "answer" && (_jsxs("p", { id: "act-note", class: "act-note act-answer", children: [_jsx(Icon, { name: "bell" }), asked?.buttons === true
49
+ ? t("These words answer the master instead of a roll or a button: {question}", { question: asked.question })
50
+ : t("These words answer the master's question: {question}", { question: asked?.question ?? "" })] })), _jsxs("label", { for: "act-words", class: "eyebrow act-words-label", children: [_jsx(Icon, { name: "chat" }), t("Your words to the master")] }), _jsx("textarea", { ref: field, id: "act-words", class: "act-words", value: text, rows: 2, maxLength: mostWords, "aria-describedby": reply === "tell" ? undefined : "act-note", onInput: (event) => setText(event.currentTarget.value), onKeyDown: keys }), problem && _jsx("p", { class: "act-problem", role: "alert", children: problem }), _jsxs("div", { class: "act-buttons", children: [_jsx("button", { type: "button", class: "act-cancel", onClick: close, children: t("Cancel") }), _jsxs("button", { type: "submit", class: "map-sheet-go act-go", disabled: sending || text.trim() === "", children: [button, _jsx(Icon, { name: "send" })] })] })] })] }));
51
+ }