Add dialogue+step pickers for dialogueHeard objectives.
Load dialogue trees in the quests editor and choose heard steps from the selected tree.
@@ -1270,6 +1270,7 @@ async function main ()
1270
1270
{
1271
1271
dialoguesModal?.handleMessage(message);
1272
1272
tileConfigModal?.handleMessage(message);
1273
questsModal?.handleMessage(message);
1273
1274
}
1274
1275
else if (message.type === MessageType.editorGiftCharacters
1275
1276
|| message.type === MessageType.editorGiftSent)
@@ -1270,6 +1270,7 @@ async function main ()1270
{1270
{1271
dialoguesModal?.handleMessage(message);1271
dialoguesModal?.handleMessage(message);1272
tileConfigModal?.handleMessage(message);1272
tileConfigModal?.handleMessage(message);1273
questsModal?.handleMessage(message);1273
}1274
}1274
else if (message.type === MessageType.editorGiftCharacters1275
else if (message.type === MessageType.editorGiftCharacters1275
|| message.type === MessageType.editorGiftSent)1276
|| message.type === MessageType.editorGiftSent)@@ -1,4 +1,4 @@
1
import { normalizeQuestDef } from "/shared/quests/normalize.js";
1
import { normalizeQuestDef, normalizeDialogueTree } from "/shared/quests/normalize.js";
2
2
import { ConditionKind, emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";
3
3
import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4
4
@@ -23,6 +23,8 @@ export function initQuestsModal ({ socket, MessageType })
23
23
let open = false;
24
24
/** @type {ReturnType<typeof normalizeQuestDef>[]} */
25
25
let quests = [];
26
/** @type {ReturnType<typeof normalizeDialogueTree>[]} */
27
let dialogues = [];
26
28
/** @type {ReturnType<typeof normalizeQuestDef>|null} */
27
29
let draft = null;
28
30
let selectedId = null;
@@ -168,7 +170,7 @@ export function initQuestsModal ({ socket, MessageType })
168
170
obj.when = next;
169
171
if (remount)
170
172
{ renderEditor(); }
171
}, { quests }));
173
}, { quests, dialogues }));
172
174
box.append(objBox);
173
175
});
174
176
editorEl.append(box);
@@ -184,6 +186,7 @@ export function initQuestsModal ({ socket, MessageType })
184
186
document.getElementById("open-quests").addEventListener("click", () =>
185
187
{
186
188
socket.send({ type: MessageType.editorLoadQuests });
189
socket.send({ type: MessageType.editorLoadDialogues });
187
190
show(true);
188
191
render();
189
192
});
@@ -219,6 +222,13 @@ export function initQuestsModal ({ socket, MessageType })
219
222
isOpen: () => open,
220
223
handleMessage (message)
221
224
{
225
if (message.type === MessageType.editorDialogues)
226
{
227
dialogues = (message.dialogues ?? []).map((d) => normalizeDialogueTree(d));
228
if (open)
229
{ render(); }
230
return;
231
}
222
232
if (message.type !== MessageType.editorQuests)
223
233
{ return; }
224
234
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));
@@ -304,6 +314,7 @@ function renderConditionSet (when, onChange, ctx = {})
304
314
const set = normalizeConditionSet(when);
305
315
const bump = (remount = true) => onChange(set, { remount });
306
316
const questList = Array.isArray(ctx.quests) ? ctx.quests : [];
317
const dialogueList = Array.isArray(ctx.dialogues) ? ctx.dialogues : [];
307
318
const title = document.createElement("strong");
308
319
title.textContent = "When (all of)";
309
320
wrap.append(title);
@@ -374,15 +385,8 @@ function renderConditionSet (when, onChange, ctx = {})
374
385
}
375
386
else if (cond.kind === ConditionKind.dialogueHeard)
376
387
{
377
row.append(miniField("dialogueId", cond.dialogueId ?? "", (v) =>
388
row.append(dialogueHeardConditionFields(cond, dialogueList, () =>
378
389
{
379
cond.dialogueId = v;
380
set.all[index].condition = cond;
381
bump(false);
382
}));
383
row.append(miniField("stepId", cond.stepId ?? "", (v) =>
384
{
385
cond.stepId = v;
386
390
set.all[index].condition = cond;
387
391
bump(false);
388
392
}));
@@ -495,6 +499,97 @@ function renderConditionSet (when, onChange, ctx = {})
495
499
return wrap;
496
500
}
497
501
502
/** Dialogue picker + step-id dropdown from that tree. */
503
function dialogueHeardConditionFields (cond, dialogueList, onChanged)
504
{
505
const wrap = document.createElement("div");
506
wrap.className = "quest-condition-pair";
507
const dialogueSelect = document.createElement("select");
508
const blank = document.createElement("option");
509
blank.value = "";
510
blank.textContent = "Select dialogue…";
511
dialogueSelect.append(blank);
512
for (const tree of dialogueList)
513
{
514
const opt = document.createElement("option");
515
opt.value = tree.dialogueId;
516
opt.textContent = tree.label ? `${tree.label} (${tree.dialogueId})` : tree.dialogueId;
517
if (tree.dialogueId === cond.dialogueId)
518
{ opt.selected = true; }
519
dialogueSelect.append(opt);
520
}
521
if (cond.dialogueId && !dialogueList.some((d) => d.dialogueId === cond.dialogueId))
522
{
523
const missing = document.createElement("option");
524
missing.value = cond.dialogueId;
525
missing.textContent = `${cond.dialogueId} (missing)`;
526
missing.selected = true;
527
dialogueSelect.append(missing);
528
}
529
530
const stepSelect = document.createElement("select");
531
const fillSteps = () =>
532
{
533
const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId) ?? null;
534
stepSelect.replaceChildren();
535
const steps = tree?.steps ?? [];
536
if (!steps.length)
537
{
538
const empty = document.createElement("option");
539
empty.value = cond.stepId ?? "";
540
empty.textContent = cond.stepId ? String(cond.stepId) : "No steps";
541
empty.selected = true;
542
stepSelect.append(empty);
543
return;
544
}
545
let matched = false;
546
for (const step of steps)
547
{
548
const opt = document.createElement("option");
549
opt.value = step.stepId;
550
opt.textContent = step.label
551
? `${step.label} (${step.stepId})`
552
: step.stepId;
553
if (step.stepId === cond.stepId)
554
{
555
opt.selected = true;
556
matched = true;
557
}
558
stepSelect.append(opt);
559
}
560
if (!matched && cond.stepId)
561
{
562
const fallback = document.createElement("option");
563
fallback.value = cond.stepId;
564
fallback.textContent = `${cond.stepId} (missing)`;
565
fallback.selected = true;
566
stepSelect.append(fallback);
567
}
568
else if (!matched)
569
{
570
cond.stepId = steps[0].stepId;
571
stepSelect.options[0].selected = true;
572
}
573
};
574
fillSteps();
575
576
dialogueSelect.addEventListener("change", () =>
577
{
578
cond.dialogueId = dialogueSelect.value;
579
const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId);
580
cond.stepId = tree?.steps?.[0]?.stepId ?? "";
581
fillSteps();
582
onChanged();
583
});
584
stepSelect.addEventListener("change", () =>
585
{
586
cond.stepId = stepSelect.value;
587
onChanged();
588
});
589
wrap.append(dialogueSelect, stepSelect);
590
return wrap;
591
}
592
498
593
/** Quest picker + state dropdown from that quest's steps. */
499
594
function questStateConditionFields (cond, questList, onChanged)
500
595
{
@@ -1,4 +1,4 @@1
import { normalizeQuestDef } from "/shared/quests/normalize.js";1
import { normalizeQuestDef, normalizeDialogueTree } from "/shared/quests/normalize.js";2
import { ConditionKind, emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";2
import { ConditionKind, emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";3
import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";3
import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";4
4
@@ -23,6 +23,8 @@ export function initQuestsModal ({ socket, MessageType })23
let open = false;23
let open = false;24
/** @type {ReturnType<typeof normalizeQuestDef>[]} */24
/** @type {ReturnType<typeof normalizeQuestDef>[]} */25
let quests = [];25
let quests = [];26
/** @type {ReturnType<typeof normalizeDialogueTree>[]} */27
let dialogues = [];26
/** @type {ReturnType<typeof normalizeQuestDef>|null} */28
/** @type {ReturnType<typeof normalizeQuestDef>|null} */27
let draft = null;29
let draft = null;28
let selectedId = null;30
let selectedId = null;@@ -168,7 +170,7 @@ export function initQuestsModal ({ socket, MessageType })168
obj.when = next;170
obj.when = next;169
if (remount)171
if (remount)170
{ renderEditor(); }172
{ renderEditor(); }171
}, { quests }));173
}, { quests, dialogues }));172
box.append(objBox);174
box.append(objBox);173
});175
});174
editorEl.append(box);176
editorEl.append(box);@@ -184,6 +186,7 @@ export function initQuestsModal ({ socket, MessageType })184
document.getElementById("open-quests").addEventListener("click", () =>186
document.getElementById("open-quests").addEventListener("click", () =>185
{187
{186
socket.send({ type: MessageType.editorLoadQuests });188
socket.send({ type: MessageType.editorLoadQuests });189
socket.send({ type: MessageType.editorLoadDialogues });187
show(true);190
show(true);188
render();191
render();189
});192
});@@ -219,6 +222,13 @@ export function initQuestsModal ({ socket, MessageType })219
isOpen: () => open,222
isOpen: () => open,220
handleMessage (message)223
handleMessage (message)221
{224
{225
if (message.type === MessageType.editorDialogues)226
{227
dialogues = (message.dialogues ?? []).map((d) => normalizeDialogueTree(d));228
if (open)229
{ render(); }230
return;231
}222
if (message.type !== MessageType.editorQuests)232
if (message.type !== MessageType.editorQuests)223
{ return; }233
{ return; }224
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));234
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));@@ -304,6 +314,7 @@ function renderConditionSet (when, onChange, ctx = {})304
const set = normalizeConditionSet(when);314
const set = normalizeConditionSet(when);305
const bump = (remount = true) => onChange(set, { remount });315
const bump = (remount = true) => onChange(set, { remount });306
const questList = Array.isArray(ctx.quests) ? ctx.quests : [];316
const questList = Array.isArray(ctx.quests) ? ctx.quests : [];317
const dialogueList = Array.isArray(ctx.dialogues) ? ctx.dialogues : [];307
const title = document.createElement("strong");318
const title = document.createElement("strong");308
title.textContent = "When (all of)";319
title.textContent = "When (all of)";309
wrap.append(title);320
wrap.append(title);@@ -374,15 +385,8 @@ function renderConditionSet (when, onChange, ctx = {})374
}385
}375
else if (cond.kind === ConditionKind.dialogueHeard)386
else if (cond.kind === ConditionKind.dialogueHeard)376
{387
{377
row.append(miniField("dialogueId", cond.dialogueId ?? "", (v) =>388
row.append(dialogueHeardConditionFields(cond, dialogueList, () =>378
{389
{379
cond.dialogueId = v;380
set.all[index].condition = cond;381
bump(false);382
}));383
row.append(miniField("stepId", cond.stepId ?? "", (v) =>384
{385
cond.stepId = v;386
set.all[index].condition = cond;390
set.all[index].condition = cond;387
bump(false);391
bump(false);388
}));392
}));@@ -495,6 +499,97 @@ function renderConditionSet (when, onChange, ctx = {})495
return wrap;499
return wrap;496
}500
}497
501
502
/** Dialogue picker + step-id dropdown from that tree. */503
function dialogueHeardConditionFields (cond, dialogueList, onChanged)504
{505
const wrap = document.createElement("div");506
wrap.className = "quest-condition-pair";507
const dialogueSelect = document.createElement("select");508
const blank = document.createElement("option");509
blank.value = "";510
blank.textContent = "Select dialogue…";511
dialogueSelect.append(blank);512
for (const tree of dialogueList)513
{514
const opt = document.createElement("option");515
opt.value = tree.dialogueId;516
opt.textContent = tree.label ? `${tree.label} (${tree.dialogueId})` : tree.dialogueId;517
if (tree.dialogueId === cond.dialogueId)518
{ opt.selected = true; }519
dialogueSelect.append(opt);520
}521
if (cond.dialogueId && !dialogueList.some((d) => d.dialogueId === cond.dialogueId))522
{523
const missing = document.createElement("option");524
missing.value = cond.dialogueId;525
missing.textContent = `${cond.dialogueId} (missing)`;526
missing.selected = true;527
dialogueSelect.append(missing);528
}529
530
const stepSelect = document.createElement("select");531
const fillSteps = () =>532
{533
const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId) ?? null;534
stepSelect.replaceChildren();535
const steps = tree?.steps ?? [];536
if (!steps.length)537
{538
const empty = document.createElement("option");539
empty.value = cond.stepId ?? "";540
empty.textContent = cond.stepId ? String(cond.stepId) : "No steps";541
empty.selected = true;542
stepSelect.append(empty);543
return;544
}545
let matched = false;546
for (const step of steps)547
{548
const opt = document.createElement("option");549
opt.value = step.stepId;550
opt.textContent = step.label551
? `${step.label} (${step.stepId})`552
: step.stepId;553
if (step.stepId === cond.stepId)554
{555
opt.selected = true;556
matched = true;557
}558
stepSelect.append(opt);559
}560
if (!matched && cond.stepId)561
{562
const fallback = document.createElement("option");563
fallback.value = cond.stepId;564
fallback.textContent = `${cond.stepId} (missing)`;565
fallback.selected = true;566
stepSelect.append(fallback);567
}568
else if (!matched)569
{570
cond.stepId = steps[0].stepId;571
stepSelect.options[0].selected = true;572
}573
};574
fillSteps();575
576
dialogueSelect.addEventListener("change", () =>577
{578
cond.dialogueId = dialogueSelect.value;579
const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId);580
cond.stepId = tree?.steps?.[0]?.stepId ?? "";581
fillSteps();582
onChanged();583
});584
stepSelect.addEventListener("change", () =>585
{586
cond.stepId = stepSelect.value;587
onChanged();588
});589
wrap.append(dialogueSelect, stepSelect);590
return wrap;591
}592
498
/** Quest picker + state dropdown from that quest's steps. */593
/** Quest picker + state dropdown from that quest's steps. */499
function questStateConditionFields (cond, questList, onChanged)594
function questStateConditionFields (cond, questList, onChanged)500
{595
{