BlueGit

timfa questward

Add quest+state pickers for questState objectives.

Authors pick a quest first, then choose not-started, a step index, or completed from that quest's steps.

timfa Tim Falken · pushed by timfa

Authored 2026-09-06 · 2 months ago

Hash
44f2feeabe8d8e884eba0da240f365df7480c7ae
Parent
f4b81e10
2 files changed +105 −11
client/src/editor/questsModal.js +93 −11
@@ -168,7 +168,7 @@ export function initQuestsModal ({ socket, MessageType })
168 168 obj.when = next;
169 169 if (remount)
170 170 { renderEditor(); }
171 }));
171 }, { quests }));
172 172 box.append(objBox);
173 173 });
174 174 editorEl.append(box);
@@ -298,11 +298,12 @@ function sectionHeader (title, onAdd, onRemove)
298 298 return head;
299 299 }
300 300
301 function renderConditionSet (when, onChange)
301 function renderConditionSet (when, onChange, ctx = {})
302 302 {
303 303 const wrap = document.createElement("div");
304 304 const set = normalizeConditionSet(when);
305 305 const bump = (remount = true) => onChange(set, { remount });
306 const questList = Array.isArray(ctx.quests) ? ctx.quests : [];
306 307 const title = document.createElement("strong");
307 308 title.textContent = "When (all of)";
308 309 wrap.append(title);
@@ -365,16 +366,8 @@ function renderConditionSet (when, onChange)
365 366 }
366 367 else if (cond.kind === ConditionKind.questState)
367 368 {
368 row.append(miniField("questId", cond.questId ?? "", (v) =>
369 row.append(questStateConditionFields(cond, questList, () =>
369 370 {
370 cond.questId = v;
371 set.all[index].condition = cond;
372 bump(false);
373 }));
374 row.append(miniField("state", cond.state ?? "not-started", (v) =>
375 {
376 const n = Number(v);
377 cond.state = Number.isFinite(n) && String(n) === String(v).trim() ? n : v;
378 371 set.all[index].condition = cond;
379 372 bump(false);
380 373 }));
@@ -502,6 +495,95 @@ function renderConditionSet (when, onChange)
502 495 return wrap;
503 496 }
504 497
498 /** Quest picker + state dropdown from that quest's steps. */
499 function questStateConditionFields (cond, questList, onChanged)
500 {
501 const wrap = document.createElement("div");
502 wrap.className = "quest-condition-pair";
503 const questSelect = document.createElement("select");
504 const blank = document.createElement("option");
505 blank.value = "";
506 blank.textContent = "Select quest…";
507 questSelect.append(blank);
508 for (const quest of questList)
509 {
510 const opt = document.createElement("option");
511 opt.value = quest.questId;
512 opt.textContent = quest.title ? `${quest.title} (${quest.questId})` : quest.questId;
513 if (quest.questId === cond.questId)
514 { opt.selected = true; }
515 questSelect.append(opt);
516 }
517 if (cond.questId && !questList.some((q) => q.questId === cond.questId))
518 {
519 const missing = document.createElement("option");
520 missing.value = cond.questId;
521 missing.textContent = `${cond.questId} (missing)`;
522 missing.selected = true;
523 questSelect.append(missing);
524 }
525
526 const stateSelect = document.createElement("select");
527 const fillStates = () =>
528 {
529 const quest = questList.find((q) => q.questId === cond.questId) ?? null;
530 stateSelect.replaceChildren();
531 const options = [
532 { value: "not-started", label: "not-started" },
533 ...((quest?.steps ?? []).map((step, index) => ({
534 value: String(index + 1),
535 label: `Step ${index + 1}: ${step.title || step.stepId}`
536 }))),
537 { value: "completed", label: "completed" }
538 ];
539 let matched = false;
540 for (const entry of options)
541 {
542 const opt = document.createElement("option");
543 opt.value = entry.value;
544 opt.textContent = entry.label;
545 const current = cond.state ?? "not-started";
546 const currentKey = current === "not-started" || current === "completed"
547 ? current
548 : String(Number(current) || current);
549 if (entry.value === currentKey)
550 {
551 opt.selected = true;
552 matched = true;
553 }
554 stateSelect.append(opt);
555 }
556 if (!matched)
557 {
558 const fallback = document.createElement("option");
559 fallback.value = String(cond.state ?? "not-started");
560 fallback.textContent = String(cond.state ?? "not-started");
561 fallback.selected = true;
562 stateSelect.append(fallback);
563 }
564 };
565 fillStates();
566
567 questSelect.addEventListener("change", () =>
568 {
569 cond.questId = questSelect.value;
570 cond.state = "not-started";
571 fillStates();
572 onChanged();
573 });
574 stateSelect.addEventListener("change", () =>
575 {
576 const raw = stateSelect.value;
577 if (raw === "not-started" || raw === "completed")
578 { cond.state = raw; }
579 else
580 { cond.state = Math.max(1, Number(raw) | 0); }
581 onChanged();
582 });
583 wrap.append(questSelect, stateSelect);
584 return wrap;
585 }
586
505 587 /** Compact searchable item picker for hasItem conditions. */
506 588 function itemConditionPicker (cond, onPicked)
507 589 {
@@ -168,7 +168,7 @@ export function initQuestsModal ({ socket, MessageType })
168 obj.when = next;
168 obj.when = next;
169 if (remount)
169 if (remount)
170 { renderEditor(); }
170 { renderEditor(); }
171 }));
171 }, { quests }));
172 box.append(objBox);
172 box.append(objBox);
173 });
173 });
174 editorEl.append(box);
174 editorEl.append(box);
@@ -298,11 +298,12 @@ function sectionHeader (title, onAdd, onRemove)
298 return head;
298 return head;
299}
299}
300
300
301function renderConditionSet (when, onChange)
301function renderConditionSet (when, onChange, ctx = {})
302{
302{
303 const wrap = document.createElement("div");
303 const wrap = document.createElement("div");
304 const set = normalizeConditionSet(when);
304 const set = normalizeConditionSet(when);
305 const bump = (remount = true) => onChange(set, { remount });
305 const bump = (remount = true) => onChange(set, { remount });
306 const questList = Array.isArray(ctx.quests) ? ctx.quests : [];
306 const title = document.createElement("strong");
307 const title = document.createElement("strong");
307 title.textContent = "When (all of)";
308 title.textContent = "When (all of)";
308 wrap.append(title);
309 wrap.append(title);
@@ -365,16 +366,8 @@ function renderConditionSet (when, onChange)
365 }
366 }
366 else if (cond.kind === ConditionKind.questState)
367 else if (cond.kind === ConditionKind.questState)
367 {
368 {
368 row.append(miniField("questId", cond.questId ?? "", (v) =>
369 row.append(questStateConditionFields(cond, questList, () =>
369 {
370 {
370 cond.questId = v;
371 set.all[index].condition = cond;
372 bump(false);
373 }));
374 row.append(miniField("state", cond.state ?? "not-started", (v) =>
375 {
376 const n = Number(v);
377 cond.state = Number.isFinite(n) && String(n) === String(v).trim() ? n : v;
378 set.all[index].condition = cond;
371 set.all[index].condition = cond;
379 bump(false);
372 bump(false);
380 }));
373 }));
@@ -502,6 +495,95 @@ function renderConditionSet (when, onChange)
502 return wrap;
495 return wrap;
503}
496}
504
497
498/** Quest picker + state dropdown from that quest's steps. */
499function questStateConditionFields (cond, questList, onChanged)
500{
501 const wrap = document.createElement("div");
502 wrap.className = "quest-condition-pair";
503 const questSelect = document.createElement("select");
504 const blank = document.createElement("option");
505 blank.value = "";
506 blank.textContent = "Select quest…";
507 questSelect.append(blank);
508 for (const quest of questList)
509 {
510 const opt = document.createElement("option");
511 opt.value = quest.questId;
512 opt.textContent = quest.title ? `${quest.title} (${quest.questId})` : quest.questId;
513 if (quest.questId === cond.questId)
514 { opt.selected = true; }
515 questSelect.append(opt);
516 }
517 if (cond.questId && !questList.some((q) => q.questId === cond.questId))
518 {
519 const missing = document.createElement("option");
520 missing.value = cond.questId;
521 missing.textContent = `${cond.questId} (missing)`;
522 missing.selected = true;
523 questSelect.append(missing);
524 }
525
526 const stateSelect = document.createElement("select");
527 const fillStates = () =>
528 {
529 const quest = questList.find((q) => q.questId === cond.questId) ?? null;
530 stateSelect.replaceChildren();
531 const options = [
532 { value: "not-started", label: "not-started" },
533 ...((quest?.steps ?? []).map((step, index) => ({
534 value: String(index + 1),
535 label: `Step ${index + 1}: ${step.title || step.stepId}`
536 }))),
537 { value: "completed", label: "completed" }
538 ];
539 let matched = false;
540 for (const entry of options)
541 {
542 const opt = document.createElement("option");
543 opt.value = entry.value;
544 opt.textContent = entry.label;
545 const current = cond.state ?? "not-started";
546 const currentKey = current === "not-started" || current === "completed"
547 ? current
548 : String(Number(current) || current);
549 if (entry.value === currentKey)
550 {
551 opt.selected = true;
552 matched = true;
553 }
554 stateSelect.append(opt);
555 }
556 if (!matched)
557 {
558 const fallback = document.createElement("option");
559 fallback.value = String(cond.state ?? "not-started");
560 fallback.textContent = String(cond.state ?? "not-started");
561 fallback.selected = true;
562 stateSelect.append(fallback);
563 }
564 };
565 fillStates();
566
567 questSelect.addEventListener("change", () =>
568 {
569 cond.questId = questSelect.value;
570 cond.state = "not-started";
571 fillStates();
572 onChanged();
573 });
574 stateSelect.addEventListener("change", () =>
575 {
576 const raw = stateSelect.value;
577 if (raw === "not-started" || raw === "completed")
578 { cond.state = raw; }
579 else
580 { cond.state = Math.max(1, Number(raw) | 0); }
581 onChanged();
582 });
583 wrap.append(questSelect, stateSelect);
584 return wrap;
585}
586
505/** Compact searchable item picker for hasItem conditions. */
587/** Compact searchable item picker for hasItem conditions. */
506function itemConditionPicker (cond, onPicked)
588function itemConditionPicker (cond, onPicked)
507{
589{
client/ui/editor.css +12 −0
@@ -1556,6 +1556,18 @@ label {
1556 1556 min-width: 12rem;
1557 1557 }
1558 1558
1559 .quest-condition-pair {
1560 display: flex;
1561 flex-wrap: wrap;
1562 gap: 0.35rem;
1563 align-items: center;
1564 }
1565
1566 .quest-condition-pair select {
1567 min-width: 10rem;
1568 max-width: 18rem;
1569 }
1570
1559 1571 .dialogue-reward-item-search {
1560 1572 display: flex;
1561 1573 flex-direction: column;
@@ -1556,6 +1556,18 @@ label {
1556 min-width: 12rem;
1556 min-width: 12rem;
1557}
1557}
1558
1558
1559.quest-condition-pair {
1560 display: flex;
1561 flex-wrap: wrap;
1562 gap: 0.35rem;
1563 align-items: center;
1564}
1565
1566.quest-condition-pair select {
1567 min-width: 10rem;
1568 max-width: 18rem;
1569}
1570
1559.dialogue-reward-item-search {
1571.dialogue-reward-item-search {
1560 display: flex;
1572 display: flex;
1561 flex-direction: column;
1573 flex-direction: column;