BlueGit

timfa questward

Add dialogue Simulate mode in the world editor.

Walk a draft tree with a default player look, choice triggers, free branch picking, and preview reward notices without leaving the editor.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
b8a32f87cba055c7a6e5fe3076690e1fa90e970e
Parent
e5110e10
4 files changed +445 −2
client/editor.html +11 −0
@@ -130,10 +130,21 @@
130 130 </div>
131 131 <footer>
132 132 <button id="dialogues-delete" type="button" disabled>Delete</button>
133 <button id="dialogues-simulate" type="button" disabled>Simulate</button>
133 134 <button id="dialogues-save" type="button" disabled>Save</button>
134 135 </footer>
135 136 </div>
136 137
138 <div id="dialogue-simulate-backdrop" hidden></div>
139 <aside id="dialogue-simulate-panel" hidden>
140 <header>
141 <strong id="dialogue-simulate-title">Simulate</strong>
142 <button id="dialogue-simulate-close" type="button">Close</button>
143 </header>
144 <div id="dialogue-simulate-lines"></div>
145 <div id="dialogue-simulate-actions"></div>
146 </aside>
147
137 148 <div id="gifts-backdrop" hidden></div>
138 149 <div id="gifts-modal" hidden>
139 150 <header>
@@ -130,10 +130,21 @@
130 </div>
130 </div>
131 <footer>
131 <footer>
132 <button id="dialogues-delete" type="button" disabled>Delete</button>
132 <button id="dialogues-delete" type="button" disabled>Delete</button>
133 <button id="dialogues-simulate" type="button" disabled>Simulate</button>
133 <button id="dialogues-save" type="button" disabled>Save</button>
134 <button id="dialogues-save" type="button" disabled>Save</button>
134 </footer>
135 </footer>
135 </div>
136 </div>
136
137
138 <div id="dialogue-simulate-backdrop" hidden></div>
139 <aside id="dialogue-simulate-panel" hidden>
140 <header>
141 <strong id="dialogue-simulate-title">Simulate</strong>
142 <button id="dialogue-simulate-close" type="button">Close</button>
143 </header>
144 <div id="dialogue-simulate-lines"></div>
145 <div id="dialogue-simulate-actions"></div>
146 </aside>
147
137 <div id="gifts-backdrop" hidden></div>
148 <div id="gifts-backdrop" hidden></div>
138 <div id="gifts-modal" hidden>
149 <div id="gifts-modal" hidden>
139 <header>
150 <header>
client/src/editor/dialogueSimulate.js added +344 −0
@@ -0,0 +1,344 @@
1 /**
2 * Client-only dialogue tree walk for the world editor.
3 * Default player look; triggers use the same choice flow; branches are freely selectable.
4 */
5 import { itemDefinition } from "/shared/definitions/items.js";
6 import { evaluateConditionSet } from "/shared/quests/conditions.js";
7 import {
8 formatDialogueRewardMessage,
9 formatDialogueQuestRewardMessage
10 } from "/shared/quests/dialogueRewards.js";
11
12 const ICON = 48;
13
14 /**
15 * @param {{
16 * getTree: () => object | null,
17 * getQuestTitle?: (questId: string) => string
18 * }} options
19 */
20 export function initDialogueSimulate ({ getTree, getQuestTitle = null } = {})
21 {
22 const backdrop = document.getElementById("dialogue-simulate-backdrop");
23 const panel = document.getElementById("dialogue-simulate-panel");
24 const titleEl = document.getElementById("dialogue-simulate-title");
25 const linesEl = document.getElementById("dialogue-simulate-lines");
26 const actionsEl = document.getElementById("dialogue-simulate-actions");
27 const closeBtn = document.getElementById("dialogue-simulate-close");
28
29 /** @type {null | {
30 * tree: object,
31 * stepId: string,
32 * lineIndex: number,
33 * rewardMessages: string[]|null,
34 * rewardIndex: number
35 * }} */
36 let session = null;
37
38 function show (visible)
39 {
40 if (backdrop)
41 { backdrop.hidden = !visible; }
42 if (panel)
43 { panel.hidden = !visible; }
44 if (!visible)
45 { session = null; }
46 }
47
48 function speakerIcon (speaker)
49 {
50 const canvas = document.createElement("canvas");
51 canvas.className = "dialogue-simulate-icon";
52 canvas.width = ICON;
53 canvas.height = ICON;
54 const ctx = canvas.getContext("2d");
55 if (speaker === "player")
56 {
57 // Default player look stand-in (soft blue body + hair).
58 ctx.fillStyle = "#5b7ea6";
59 ctx.fillRect(8, 14, 32, 28);
60 ctx.fillStyle = "#c9a06a";
61 ctx.fillRect(12, 8, 24, 14);
62 ctx.fillStyle = "#2a3340";
63 ctx.fillRect(12, 6, 24, 8);
64 }
65 else
66 {
67 ctx.fillStyle = "#8a6a4a";
68 ctx.fillRect(8, 14, 32, 28);
69 ctx.fillStyle = "#d4b896";
70 ctx.fillRect(12, 8, 24, 14);
71 ctx.fillStyle = "#3a2a1a";
72 ctx.fillRect(12, 4, 24, 10);
73 }
74 return canvas;
75 }
76
77 /** Permissive snapshot so authored trigger gates can still be previewed. */
78 function simulateCtx ()
79 {
80 return {
81 countItem: () => 999,
82 tileX: 0,
83 tileY: 0,
84 chunkX: 0,
85 chunkY: 0,
86 dimensionId: "overworld",
87 hasVisitedDimension: () => true,
88 questState: () => "completed",
89 dialogueHeard: () => true,
90 dialogueTriggerLatched: () => true,
91 hp: 999,
92 maxHp: 999,
93 stamina: 999,
94 maxStamina: 999,
95 skillLevel: () => 99,
96 killCount: () => 999,
97 interactBlockDone: () => true
98 };
99 }
100
101 function rewardMessagesForStep (step)
102 {
103 const messages = [];
104 const bagParts = [];
105 for (const reward of step?.itemRewards ?? [])
106 {
107 const def = itemDefinition(reward.itemId);
108 bagParts.push({
109 displayName: def?.displayName ?? `Item ${reward.itemId}`,
110 quantity: Math.max(1, reward.quantity | 0 || 1)
111 });
112 }
113 const bagMsg = formatDialogueRewardMessage(bagParts, "bag");
114 if (bagMsg)
115 { messages.push(bagMsg); }
116 const titles = [];
117 for (const questId of step?.questRewards ?? [])
118 {
119 titles.push(getQuestTitle?.(questId) || questId);
120 }
121 const questMsg = formatDialogueQuestRewardMessage(titles);
122 if (questMsg)
123 { messages.push(questMsg); }
124 return messages;
125 }
126
127 function enterStep (stepId)
128 {
129 if (!session)
130 { return; }
131 const step = session.tree.steps.find((s) => s.stepId === stepId);
132 if (!step)
133 {
134 show(false);
135 return;
136 }
137 session.stepId = stepId;
138 session.lineIndex = 0;
139 session.rewardMessages = null;
140 session.rewardIndex = 0;
141 render();
142 }
143
144 function resolveExit ()
145 {
146 if (!session)
147 { return; }
148 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
149 const exit = step?.exit ?? { kind: "end" };
150 if (exit.kind === "triggers")
151 {
152 const ctx = simulateCtx();
153 const triggers = (exit.triggers ?? []).filter((t) => evaluateConditionSet(t.when, ctx));
154 renderTriggerChoices(triggers);
155 return;
156 }
157 if (exit.kind === "branches")
158 {
159 renderBranchChoices(exit.branches ?? []);
160 return;
161 }
162 show(false);
163 }
164
165 function afterLines ()
166 {
167 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
168 const messages = rewardMessagesForStep(step);
169 if (messages.length)
170 {
171 session.rewardMessages = messages;
172 session.rewardIndex = 0;
173 render();
174 return;
175 }
176 resolveExit();
177 }
178
179 function renderTriggerChoices (triggers)
180 {
181 if (titleEl)
182 { titleEl.textContent = "Choices"; }
183 linesEl?.replaceChildren();
184 actionsEl?.replaceChildren();
185 if (!triggers.length)
186 {
187 const hint = document.createElement("p");
188 hint.className = "content-editor-hint";
189 hint.textContent = "No triggers matched (simulate uses a permissive player snapshot).";
190 linesEl?.append(hint);
191 const close = document.createElement("button");
192 close.type = "button";
193 close.textContent = "Close";
194 close.addEventListener("click", () => show(false));
195 actionsEl?.append(close);
196 return;
197 }
198 for (const trig of triggers)
199 {
200 const btn = document.createElement("button");
201 btn.type = "button";
202 btn.textContent = trig.text || trig.trigger || "…";
203 btn.addEventListener("click", () =>
204 {
205 if (trig.nextStepId)
206 { enterStep(trig.nextStepId); }
207 else
208 { show(false); }
209 });
210 actionsEl?.append(btn);
211 }
212 }
213
214 function renderBranchChoices (branches)
215 {
216 if (titleEl)
217 { titleEl.textContent = "Branches (pick any)"; }
218 linesEl?.replaceChildren();
219 actionsEl?.replaceChildren();
220 const hint = document.createElement("p");
221 hint.className = "content-editor-hint";
222 hint.textContent = "Simulate ignores branch conditions so you can walk every path.";
223 linesEl?.append(hint);
224 if (!branches.length)
225 {
226 const close = document.createElement("button");
227 close.type = "button";
228 close.textContent = "Close";
229 close.addEventListener("click", () => show(false));
230 actionsEl?.append(close);
231 return;
232 }
233 branches.forEach((branch, index) =>
234 {
235 const btn = document.createElement("button");
236 btn.type = "button";
237 btn.textContent = branch.nextStepId
238 ? `Branch ${index + 1} → ${branch.nextStepId}`
239 : `Branch ${index + 1} → end`;
240 btn.addEventListener("click", () =>
241 {
242 if (branch.nextStepId)
243 { enterStep(branch.nextStepId); }
244 else
245 { show(false); }
246 });
247 actionsEl?.append(btn);
248 });
249 }
250
251 function render ()
252 {
253 if (!session || !linesEl || !actionsEl)
254 { return; }
255 linesEl.replaceChildren();
256 actionsEl.replaceChildren();
257
258 if (session.rewardMessages?.length)
259 {
260 if (titleEl)
261 { titleEl.textContent = "Reward"; }
262 const row = document.createElement("div");
263 row.className = "dialogue-simulate-line dialogue-simulate-reward";
264 const text = document.createElement("span");
265 text.textContent = session.rewardMessages[session.rewardIndex] ?? "";
266 row.append(text);
267 linesEl.append(row);
268 const atLast = session.rewardIndex >= session.rewardMessages.length - 1;
269 const next = document.createElement("button");
270 next.type = "button";
271 next.textContent = atLast ? "Continue" : "Next";
272 next.addEventListener("click", () =>
273 {
274 if (!atLast)
275 {
276 session.rewardIndex += 1;
277 render();
278 return;
279 }
280 session.rewardMessages = null;
281 resolveExit();
282 });
283 actionsEl.append(next);
284 return;
285 }
286
287 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
288 const line = step?.lines?.[session.lineIndex];
289 const speaker = line?.speaker === "player" ? "player" : "npc";
290 if (titleEl)
291 { titleEl.textContent = speaker === "player" ? "You" : (session.tree.label || "NPC"); }
292 if (line)
293 {
294 const row = document.createElement("div");
295 row.className = `dialogue-simulate-line dialogue-simulate-${speaker}`;
296 row.append(speakerIcon(speaker));
297 const text = document.createElement("span");
298 text.textContent = line.text ?? "";
299 row.append(text);
300 linesEl.append(row);
301 }
302 const atLast = session.lineIndex >= (step?.lines?.length ?? 1) - 1;
303 const next = document.createElement("button");
304 next.type = "button";
305 next.textContent = atLast ? "Continue" : "Next";
306 next.addEventListener("click", () =>
307 {
308 if (!atLast)
309 {
310 session.lineIndex += 1;
311 render();
312 return;
313 }
314 afterLines();
315 });
316 actionsEl.append(next);
317 }
318
319 function start ()
320 {
321 const tree = getTree?.();
322 if (!tree?.steps?.length)
323 { return false; }
324 session = {
325 tree,
326 stepId: tree.entryStepId || tree.steps[0].stepId,
327 lineIndex: 0,
328 rewardMessages: null,
329 rewardIndex: 0
330 };
331 show(true);
332 enterStep(session.stepId);
333 return true;
334 }
335
336 closeBtn?.addEventListener("click", () => show(false));
337 backdrop?.addEventListener("click", () => show(false));
338
339 return {
340 start,
341 close: () => show(false),
342 isOpen: () => !!session && panel && !panel.hidden
343 };
344 }
@@ -0,0 +1,344 @@
1/**
2 * Client-only dialogue tree walk for the world editor.
3 * Default player look; triggers use the same choice flow; branches are freely selectable.
4 */
5import { itemDefinition } from "/shared/definitions/items.js";
6import { evaluateConditionSet } from "/shared/quests/conditions.js";
7import {
8 formatDialogueRewardMessage,
9 formatDialogueQuestRewardMessage
10} from "/shared/quests/dialogueRewards.js";
11
12const ICON = 48;
13
14/**
15 * @param {{
16 * getTree: () => object | null,
17 * getQuestTitle?: (questId: string) => string
18 * }} options
19 */
20export function initDialogueSimulate ({ getTree, getQuestTitle = null } = {})
21{
22 const backdrop = document.getElementById("dialogue-simulate-backdrop");
23 const panel = document.getElementById("dialogue-simulate-panel");
24 const titleEl = document.getElementById("dialogue-simulate-title");
25 const linesEl = document.getElementById("dialogue-simulate-lines");
26 const actionsEl = document.getElementById("dialogue-simulate-actions");
27 const closeBtn = document.getElementById("dialogue-simulate-close");
28
29 /** @type {null | {
30 * tree: object,
31 * stepId: string,
32 * lineIndex: number,
33 * rewardMessages: string[]|null,
34 * rewardIndex: number
35 * }} */
36 let session = null;
37
38 function show (visible)
39 {
40 if (backdrop)
41 { backdrop.hidden = !visible; }
42 if (panel)
43 { panel.hidden = !visible; }
44 if (!visible)
45 { session = null; }
46 }
47
48 function speakerIcon (speaker)
49 {
50 const canvas = document.createElement("canvas");
51 canvas.className = "dialogue-simulate-icon";
52 canvas.width = ICON;
53 canvas.height = ICON;
54 const ctx = canvas.getContext("2d");
55 if (speaker === "player")
56 {
57 // Default player look stand-in (soft blue body + hair).
58 ctx.fillStyle = "#5b7ea6";
59 ctx.fillRect(8, 14, 32, 28);
60 ctx.fillStyle = "#c9a06a";
61 ctx.fillRect(12, 8, 24, 14);
62 ctx.fillStyle = "#2a3340";
63 ctx.fillRect(12, 6, 24, 8);
64 }
65 else
66 {
67 ctx.fillStyle = "#8a6a4a";
68 ctx.fillRect(8, 14, 32, 28);
69 ctx.fillStyle = "#d4b896";
70 ctx.fillRect(12, 8, 24, 14);
71 ctx.fillStyle = "#3a2a1a";
72 ctx.fillRect(12, 4, 24, 10);
73 }
74 return canvas;
75 }
76
77 /** Permissive snapshot so authored trigger gates can still be previewed. */
78 function simulateCtx ()
79 {
80 return {
81 countItem: () => 999,
82 tileX: 0,
83 tileY: 0,
84 chunkX: 0,
85 chunkY: 0,
86 dimensionId: "overworld",
87 hasVisitedDimension: () => true,
88 questState: () => "completed",
89 dialogueHeard: () => true,
90 dialogueTriggerLatched: () => true,
91 hp: 999,
92 maxHp: 999,
93 stamina: 999,
94 maxStamina: 999,
95 skillLevel: () => 99,
96 killCount: () => 999,
97 interactBlockDone: () => true
98 };
99 }
100
101 function rewardMessagesForStep (step)
102 {
103 const messages = [];
104 const bagParts = [];
105 for (const reward of step?.itemRewards ?? [])
106 {
107 const def = itemDefinition(reward.itemId);
108 bagParts.push({
109 displayName: def?.displayName ?? `Item ${reward.itemId}`,
110 quantity: Math.max(1, reward.quantity | 0 || 1)
111 });
112 }
113 const bagMsg = formatDialogueRewardMessage(bagParts, "bag");
114 if (bagMsg)
115 { messages.push(bagMsg); }
116 const titles = [];
117 for (const questId of step?.questRewards ?? [])
118 {
119 titles.push(getQuestTitle?.(questId) || questId);
120 }
121 const questMsg = formatDialogueQuestRewardMessage(titles);
122 if (questMsg)
123 { messages.push(questMsg); }
124 return messages;
125 }
126
127 function enterStep (stepId)
128 {
129 if (!session)
130 { return; }
131 const step = session.tree.steps.find((s) => s.stepId === stepId);
132 if (!step)
133 {
134 show(false);
135 return;
136 }
137 session.stepId = stepId;
138 session.lineIndex = 0;
139 session.rewardMessages = null;
140 session.rewardIndex = 0;
141 render();
142 }
143
144 function resolveExit ()
145 {
146 if (!session)
147 { return; }
148 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
149 const exit = step?.exit ?? { kind: "end" };
150 if (exit.kind === "triggers")
151 {
152 const ctx = simulateCtx();
153 const triggers = (exit.triggers ?? []).filter((t) => evaluateConditionSet(t.when, ctx));
154 renderTriggerChoices(triggers);
155 return;
156 }
157 if (exit.kind === "branches")
158 {
159 renderBranchChoices(exit.branches ?? []);
160 return;
161 }
162 show(false);
163 }
164
165 function afterLines ()
166 {
167 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
168 const messages = rewardMessagesForStep(step);
169 if (messages.length)
170 {
171 session.rewardMessages = messages;
172 session.rewardIndex = 0;
173 render();
174 return;
175 }
176 resolveExit();
177 }
178
179 function renderTriggerChoices (triggers)
180 {
181 if (titleEl)
182 { titleEl.textContent = "Choices"; }
183 linesEl?.replaceChildren();
184 actionsEl?.replaceChildren();
185 if (!triggers.length)
186 {
187 const hint = document.createElement("p");
188 hint.className = "content-editor-hint";
189 hint.textContent = "No triggers matched (simulate uses a permissive player snapshot).";
190 linesEl?.append(hint);
191 const close = document.createElement("button");
192 close.type = "button";
193 close.textContent = "Close";
194 close.addEventListener("click", () => show(false));
195 actionsEl?.append(close);
196 return;
197 }
198 for (const trig of triggers)
199 {
200 const btn = document.createElement("button");
201 btn.type = "button";
202 btn.textContent = trig.text || trig.trigger || "…";
203 btn.addEventListener("click", () =>
204 {
205 if (trig.nextStepId)
206 { enterStep(trig.nextStepId); }
207 else
208 { show(false); }
209 });
210 actionsEl?.append(btn);
211 }
212 }
213
214 function renderBranchChoices (branches)
215 {
216 if (titleEl)
217 { titleEl.textContent = "Branches (pick any)"; }
218 linesEl?.replaceChildren();
219 actionsEl?.replaceChildren();
220 const hint = document.createElement("p");
221 hint.className = "content-editor-hint";
222 hint.textContent = "Simulate ignores branch conditions so you can walk every path.";
223 linesEl?.append(hint);
224 if (!branches.length)
225 {
226 const close = document.createElement("button");
227 close.type = "button";
228 close.textContent = "Close";
229 close.addEventListener("click", () => show(false));
230 actionsEl?.append(close);
231 return;
232 }
233 branches.forEach((branch, index) =>
234 {
235 const btn = document.createElement("button");
236 btn.type = "button";
237 btn.textContent = branch.nextStepId
238 ? `Branch ${index + 1} → ${branch.nextStepId}`
239 : `Branch ${index + 1} → end`;
240 btn.addEventListener("click", () =>
241 {
242 if (branch.nextStepId)
243 { enterStep(branch.nextStepId); }
244 else
245 { show(false); }
246 });
247 actionsEl?.append(btn);
248 });
249 }
250
251 function render ()
252 {
253 if (!session || !linesEl || !actionsEl)
254 { return; }
255 linesEl.replaceChildren();
256 actionsEl.replaceChildren();
257
258 if (session.rewardMessages?.length)
259 {
260 if (titleEl)
261 { titleEl.textContent = "Reward"; }
262 const row = document.createElement("div");
263 row.className = "dialogue-simulate-line dialogue-simulate-reward";
264 const text = document.createElement("span");
265 text.textContent = session.rewardMessages[session.rewardIndex] ?? "";
266 row.append(text);
267 linesEl.append(row);
268 const atLast = session.rewardIndex >= session.rewardMessages.length - 1;
269 const next = document.createElement("button");
270 next.type = "button";
271 next.textContent = atLast ? "Continue" : "Next";
272 next.addEventListener("click", () =>
273 {
274 if (!atLast)
275 {
276 session.rewardIndex += 1;
277 render();
278 return;
279 }
280 session.rewardMessages = null;
281 resolveExit();
282 });
283 actionsEl.append(next);
284 return;
285 }
286
287 const step = session.tree.steps.find((s) => s.stepId === session.stepId);
288 const line = step?.lines?.[session.lineIndex];
289 const speaker = line?.speaker === "player" ? "player" : "npc";
290 if (titleEl)
291 { titleEl.textContent = speaker === "player" ? "You" : (session.tree.label || "NPC"); }
292 if (line)
293 {
294 const row = document.createElement("div");
295 row.className = `dialogue-simulate-line dialogue-simulate-${speaker}`;
296 row.append(speakerIcon(speaker));
297 const text = document.createElement("span");
298 text.textContent = line.text ?? "";
299 row.append(text);
300 linesEl.append(row);
301 }
302 const atLast = session.lineIndex >= (step?.lines?.length ?? 1) - 1;
303 const next = document.createElement("button");
304 next.type = "button";
305 next.textContent = atLast ? "Continue" : "Next";
306 next.addEventListener("click", () =>
307 {
308 if (!atLast)
309 {
310 session.lineIndex += 1;
311 render();
312 return;
313 }
314 afterLines();
315 });
316 actionsEl.append(next);
317 }
318
319 function start ()
320 {
321 const tree = getTree?.();
322 if (!tree?.steps?.length)
323 { return false; }
324 session = {
325 tree,
326 stepId: tree.entryStepId || tree.steps[0].stepId,
327 lineIndex: 0,
328 rewardMessages: null,
329 rewardIndex: 0
330 };
331 show(true);
332 enterStep(session.stepId);
333 return true;
334 }
335
336 closeBtn?.addEventListener("click", () => show(false));
337 backdrop?.addEventListener("click", () => show(false));
338
339 return {
340 start,
341 close: () => show(false),
342 isOpen: () => !!session && panel && !panel.hidden
343 };
344}
client/src/editor/dialoguesModal.js +22 −2
@@ -2,6 +2,7 @@ import { normalizeDialogueTree, normalizeQuestDef } from "/shared/quests/normali
2 2 import { emptyConditionSet } from "/shared/quests/conditions.js";
3 3 import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4 4 import { renderConditionSet } from "./conditionSetEditor.js";
5 import { initDialogueSimulate } from "./dialogueSimulate.js";
5 6
6 7 export function initDialoguesModal ({
7 8 socket,
@@ -17,15 +18,25 @@ export function initDialoguesModal ({
17 18 const editorEl = document.getElementById("dialogues-editor");
18 19 const saveBtn = document.getElementById("dialogues-save");
19 20 const deleteBtn = document.getElementById("dialogues-delete");
21 const simulateBtn = document.getElementById("dialogues-simulate");
20 22 let open = false;
21 23 /** @type {any[]} */
22 24 let dialogues = [];
23 /** @type {{ questId: string, title: string }[]} */
25 /** @type {ReturnType<typeof normalizeQuestDef>[]} */
24 26 let questCatalog = [];
25 27 /** @type {any|null} */
26 28 let draft = null;
27 29 let selectedId = null;
28 30
31 const simulate = initDialogueSimulate({
32 getTree: () => (draft ? normalizeDialogueTree(draft) : null),
33 getQuestTitle (questId)
34 {
35 const quest = questCatalog.find((q) => q.questId === questId);
36 return quest?.title || questId;
37 }
38 });
39
29 40 function show (visible)
30 41 {
31 42 open = visible;
@@ -36,6 +47,7 @@ export function initDialoguesModal ({
36 47 draft = null;
37 48 selectedId = null;
38 49 closeInlineItemSearch();
50 simulate.close();
39 51 }
40 52 }
41 53
@@ -155,6 +167,8 @@ export function initDialoguesModal ({
155 167 editorEl.replaceChildren();
156 168 saveBtn.disabled = !draft;
157 169 deleteBtn.disabled = !draft;
170 if (simulateBtn)
171 { simulateBtn.disabled = !draft; }
158 172 if (!draft)
159 173 {
160 174 const hint = document.createElement("p");
@@ -534,6 +548,12 @@ export function initDialoguesModal ({
534 548 });
535 549 document.getElementById("dialogues-close").addEventListener("click", () => show(false));
536 550 backdrop.addEventListener("click", () => show(false));
551 simulateBtn?.addEventListener("click", () =>
552 {
553 if (!draft)
554 { return; }
555 simulate.start();
556 });
537 557 document.getElementById("dialogues-new").addEventListener("click", () =>
538 558 {
539 559 const base = normalizeDialogueTree({
@@ -561,7 +581,7 @@ export function initDialoguesModal ({
561 581 });
562 582
563 583 return {
564 isOpen: () => open,
584 isOpen: () => open || simulate.isOpen(),
565 585 getDialogues: () => dialogues,
566 586 handleMessage (message)
567 587 {
@@ -2,6 +2,7 @@ import { normalizeDialogueTree, normalizeQuestDef } from "/shared/quests/normali
2import { emptyConditionSet } from "/shared/quests/conditions.js";
2import { emptyConditionSet } from "/shared/quests/conditions.js";
3import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
3import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4import { renderConditionSet } from "./conditionSetEditor.js";
4import { renderConditionSet } from "./conditionSetEditor.js";
5import { initDialogueSimulate } from "./dialogueSimulate.js";
5
6
6export function initDialoguesModal ({
7export function initDialoguesModal ({
7 socket,
8 socket,
@@ -17,15 +18,25 @@ export function initDialoguesModal ({
17 const editorEl = document.getElementById("dialogues-editor");
18 const editorEl = document.getElementById("dialogues-editor");
18 const saveBtn = document.getElementById("dialogues-save");
19 const saveBtn = document.getElementById("dialogues-save");
19 const deleteBtn = document.getElementById("dialogues-delete");
20 const deleteBtn = document.getElementById("dialogues-delete");
21 const simulateBtn = document.getElementById("dialogues-simulate");
20 let open = false;
22 let open = false;
21 /** @type {any[]} */
23 /** @type {any[]} */
22 let dialogues = [];
24 let dialogues = [];
23 /** @type {{ questId: string, title: string }[]} */
25 /** @type {ReturnType<typeof normalizeQuestDef>[]} */
24 let questCatalog = [];
26 let questCatalog = [];
25 /** @type {any|null} */
27 /** @type {any|null} */
26 let draft = null;
28 let draft = null;
27 let selectedId = null;
29 let selectedId = null;
28
30
31 const simulate = initDialogueSimulate({
32 getTree: () => (draft ? normalizeDialogueTree(draft) : null),
33 getQuestTitle (questId)
34 {
35 const quest = questCatalog.find((q) => q.questId === questId);
36 return quest?.title || questId;
37 }
38 });
39
29 function show (visible)
40 function show (visible)
30 {
41 {
31 open = visible;
42 open = visible;
@@ -36,6 +47,7 @@ export function initDialoguesModal ({
36 draft = null;
47 draft = null;
37 selectedId = null;
48 selectedId = null;
38 closeInlineItemSearch();
49 closeInlineItemSearch();
50 simulate.close();
39 }
51 }
40 }
52 }
41
53
@@ -155,6 +167,8 @@ export function initDialoguesModal ({
155 editorEl.replaceChildren();
167 editorEl.replaceChildren();
156 saveBtn.disabled = !draft;
168 saveBtn.disabled = !draft;
157 deleteBtn.disabled = !draft;
169 deleteBtn.disabled = !draft;
170 if (simulateBtn)
171 { simulateBtn.disabled = !draft; }
158 if (!draft)
172 if (!draft)
159 {
173 {
160 const hint = document.createElement("p");
174 const hint = document.createElement("p");
@@ -534,6 +548,12 @@ export function initDialoguesModal ({
534 });
548 });
535 document.getElementById("dialogues-close").addEventListener("click", () => show(false));
549 document.getElementById("dialogues-close").addEventListener("click", () => show(false));
536 backdrop.addEventListener("click", () => show(false));
550 backdrop.addEventListener("click", () => show(false));
551 simulateBtn?.addEventListener("click", () =>
552 {
553 if (!draft)
554 { return; }
555 simulate.start();
556 });
537 document.getElementById("dialogues-new").addEventListener("click", () =>
557 document.getElementById("dialogues-new").addEventListener("click", () =>
538 {
558 {
539 const base = normalizeDialogueTree({
559 const base = normalizeDialogueTree({
@@ -561,7 +581,7 @@ export function initDialoguesModal ({
561 });
581 });
562
582
563 return {
583 return {
564 isOpen: () => open,
584 isOpen: () => open || simulate.isOpen(),
565 getDialogues: () => dialogues,
585 getDialogues: () => dialogues,
566 handleMessage (message)
586 handleMessage (message)
567 {
587 {
client/ui/editor.css +68 −0
@@ -1567,6 +1567,74 @@ label {
1567 1567 margin: 0.25rem 0 0.5rem;
1568 1568 }
1569 1569
1570 #dialogue-simulate-backdrop {
1571 position: fixed;
1572 inset: 0;
1573 z-index: 80;
1574 background: rgba(0, 0, 0, 0.45);
1575 }
1576
1577 #dialogue-simulate-panel {
1578 position: fixed;
1579 z-index: 81;
1580 left: 50%;
1581 top: 50%;
1582 transform: translate(-50%, -50%);
1583 width: min(420px, calc(100vw - 2rem));
1584 max-height: min(70vh, 560px);
1585 display: flex;
1586 flex-direction: column;
1587 gap: 0.65rem;
1588 padding: 0.85rem 1rem 1rem;
1589 border-radius: 10px;
1590 background: #161a22;
1591 border: 1px solid #3a4250;
1592 box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
1593 color: #e8ecf4;
1594 }
1595
1596 #dialogue-simulate-panel[hidden],
1597 #dialogue-simulate-backdrop[hidden] {
1598 display: none;
1599 }
1600
1601 #dialogue-simulate-panel > header {
1602 display: flex;
1603 align-items: center;
1604 justify-content: space-between;
1605 gap: 0.5rem;
1606 }
1607
1608 #dialogue-simulate-lines {
1609 min-height: 4rem;
1610 display: flex;
1611 flex-direction: column;
1612 gap: 0.5rem;
1613 overflow: auto;
1614 }
1615
1616 .dialogue-simulate-line {
1617 display: flex;
1618 gap: 0.55rem;
1619 align-items: flex-start;
1620 }
1621
1622 .dialogue-simulate-icon {
1623 flex: 0 0 auto;
1624 border-radius: 6px;
1625 image-rendering: pixelated;
1626 }
1627
1628 .dialogue-simulate-player {
1629 flex-direction: row-reverse;
1630 }
1631
1632 #dialogue-simulate-actions {
1633 display: flex;
1634 flex-wrap: wrap;
1635 gap: 0.4rem;
1636 }
1637
1570 1638 .quest-condition-item-picker {
1571 1639 display: flex;
1572 1640 flex-direction: column;
@@ -1567,6 +1567,74 @@ label {
1567 margin: 0.25rem 0 0.5rem;
1567 margin: 0.25rem 0 0.5rem;
1568}
1568}
1569
1569
1570#dialogue-simulate-backdrop {
1571 position: fixed;
1572 inset: 0;
1573 z-index: 80;
1574 background: rgba(0, 0, 0, 0.45);
1575}
1576
1577#dialogue-simulate-panel {
1578 position: fixed;
1579 z-index: 81;
1580 left: 50%;
1581 top: 50%;
1582 transform: translate(-50%, -50%);
1583 width: min(420px, calc(100vw - 2rem));
1584 max-height: min(70vh, 560px);
1585 display: flex;
1586 flex-direction: column;
1587 gap: 0.65rem;
1588 padding: 0.85rem 1rem 1rem;
1589 border-radius: 10px;
1590 background: #161a22;
1591 border: 1px solid #3a4250;
1592 box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
1593 color: #e8ecf4;
1594}
1595
1596#dialogue-simulate-panel[hidden],
1597#dialogue-simulate-backdrop[hidden] {
1598 display: none;
1599}
1600
1601#dialogue-simulate-panel > header {
1602 display: flex;
1603 align-items: center;
1604 justify-content: space-between;
1605 gap: 0.5rem;
1606}
1607
1608#dialogue-simulate-lines {
1609 min-height: 4rem;
1610 display: flex;
1611 flex-direction: column;
1612 gap: 0.5rem;
1613 overflow: auto;
1614}
1615
1616.dialogue-simulate-line {
1617 display: flex;
1618 gap: 0.55rem;
1619 align-items: flex-start;
1620}
1621
1622.dialogue-simulate-icon {
1623 flex: 0 0 auto;
1624 border-radius: 6px;
1625 image-rendering: pixelated;
1626}
1627
1628.dialogue-simulate-player {
1629 flex-direction: row-reverse;
1630}
1631
1632#dialogue-simulate-actions {
1633 display: flex;
1634 flex-wrap: wrap;
1635 gap: 0.4rem;
1636}
1637
1570.quest-condition-item-picker {
1638.quest-condition-item-picker {
1571 display: flex;
1639 display: flex;
1572 flex-direction: column;
1640 flex-direction: column;