BlueGit

timfa questward

Files

questward / client / src / editor / questsModal.js

questsModal.js

questsModal.js 22.6 KiB Download Raw
1import { normalizeQuestDef, normalizeDialogueTree } from "/shared/quests/normalize.js";
2import { ConditionKind, emptyConditionSet, normalizeConditionSet } from "/shared/quests/conditions.js";
3import { itemDefinition, listAllItemPickerEntries } from "/shared/definitions/items.js";
4import { listSpawnableMobTypes } from "/shared/definitions/mobs.js";
5
6const SIMPLE_KINDS = [
7 ConditionKind.hasItem,
8 ConditionKind.questState,
9 ConditionKind.dialogueHeard,
10 ConditionKind.killCount,
11 ConditionKind.atTile,
12 ConditionKind.inDimension,
13 ConditionKind.hasVisitedDimension
14];
15
16export function initQuestsModal ({ socket, MessageType })
17{
18 const backdrop = document.getElementById("quests-backdrop");
19 const modal = document.getElementById("quests-modal");
20 const listEl = document.getElementById("quests-list");
21 const editorEl = document.getElementById("quests-editor");
22 const saveBtn = document.getElementById("quests-save");
23 const deleteBtn = document.getElementById("quests-delete");
24 let open = false;
25 /** @type {ReturnType<typeof normalizeQuestDef>[]} */
26 let quests = [];
27 /** @type {ReturnType<typeof normalizeDialogueTree>[]} */
28 let dialogues = [];
29 /** @type {ReturnType<typeof normalizeQuestDef>|null} */
30 let draft = null;
31 let selectedId = null;
32
33 function show (visible)
34 {
35 open = visible;
36 backdrop.hidden = !visible;
37 modal.hidden = !visible;
38 if (!visible)
39 {
40 draft = null;
41 selectedId = null;
42 }
43 }
44
45 function selectQuest (questId)
46 {
47 const found = quests.find((q) => q.questId === questId);
48 if (!found)
49 {
50 draft = null;
51 selectedId = null;
52 render();
53 return;
54 }
55 selectedId = found.questId;
56 draft = structuredClone(found);
57 render();
58 }
59
60 function renderList ()
61 {
62 listEl.replaceChildren();
63 for (const quest of quests)
64 {
65 const btn = document.createElement("button");
66 btn.type = "button";
67 btn.textContent = quest.title || quest.questId;
68 if (quest.questId === selectedId)
69 { btn.classList.add("active"); }
70 btn.addEventListener("click", () => selectQuest(quest.questId));
71 listEl.append(btn);
72 }
73 }
74
75 function renderEditor ()
76 {
77 editorEl.replaceChildren();
78 saveBtn.disabled = !draft;
79 deleteBtn.disabled = !draft;
80 if (!draft)
81 {
82 const hint = document.createElement("p");
83 hint.className = "content-editor-hint";
84 hint.textContent = "Select a quest or create a new one.";
85 editorEl.append(hint);
86 return;
87 }
88
89 editorEl.append(
90 field("Quest id", textInput(draft.questId, (v) => { draft.questId = v; })),
91 field("Title", textInput(draft.title, (v) => { draft.title = v; })),
92 field("Description", textArea(draft.description, (v) => { draft.description = v; }, 3))
93 );
94
95 const stepsHeader = sectionHeader("Steps", () =>
96 {
97 draft.steps.push({
98 stepId: `step-${draft.steps.length + 1}`,
99 title: "New step",
100 description: "",
101 completionJournalText: "",
102 objectives: [{
103 objectiveId: "obj-1",
104 text: "Complete this step",
105 when: emptyConditionSet()
106 }],
107 onEnter: [],
108 onComplete: []
109 });
110 renderEditor();
111 });
112 editorEl.append(stepsHeader);
113
114 draft.steps.forEach((step, stepIndex) =>
115 {
116 const box = document.createElement("div");
117 box.className = "content-editor-section";
118 const head = sectionHeader(`Step ${stepIndex + 1}`, null, () =>
119 {
120 draft.steps.splice(stepIndex, 1);
121 if (draft.steps.length === 0)
122 {
123 draft.steps.push(normalizeQuestDef({ questId: draft.questId }).steps[0]);
124 }
125 renderEditor();
126 });
127 box.append(head);
128 box.append(
129 field("stepId", textInput(step.stepId, (v) => { step.stepId = v; })),
130 field("Title", textInput(step.title, (v) => { step.title = v; })),
131 field("Description", textArea(step.description, (v) => { step.description = v; }, 2)),
132 field("Completion journal", textArea(step.completionJournalText, (v) =>
133 {
134 step.completionJournalText = v;
135 }, 2))
136 );
137
138 const objHead = sectionHeader("Objectives", () =>
139 {
140 step.objectives.push({
141 objectiveId: `obj-${step.objectives.length + 1}`,
142 text: "New objective",
143 when: emptyConditionSet()
144 });
145 renderEditor();
146 });
147 box.append(objHead);
148
149 step.objectives.forEach((obj, objIndex) =>
150 {
151 const objBox = document.createElement("div");
152 objBox.className = "content-editor-section";
153 objBox.append(
154 sectionHeader(`Objective ${objIndex + 1}`, null, () =>
155 {
156 step.objectives.splice(objIndex, 1);
157 if (step.objectives.length === 0)
158 {
159 step.objectives.push({
160 objectiveId: "obj-1",
161 text: "Complete this step",
162 when: emptyConditionSet()
163 });
164 }
165 renderEditor();
166 }),
167 field("Text", textInput(obj.text, (v) => { obj.text = v; }))
168 );
169 objBox.append(renderConditionSet(obj.when, (next, { remount = true } = {}) =>
170 {
171 obj.when = next;
172 if (remount)
173 { renderEditor(); }
174 }, { quests, dialogues }));
175 box.append(objBox);
176 });
177 editorEl.append(box);
178 });
179 }
180
181 function render ()
182 {
183 renderList();
184 renderEditor();
185 }
186
187 document.getElementById("open-quests").addEventListener("click", () =>
188 {
189 socket.send({ type: MessageType.editorLoadQuests });
190 socket.send({ type: MessageType.editorLoadDialogues });
191 show(true);
192 render();
193 });
194 document.getElementById("quests-close").addEventListener("click", () => show(false));
195 backdrop.addEventListener("click", () => show(false));
196 document.getElementById("quests-new").addEventListener("click", () =>
197 {
198 const base = normalizeQuestDef({
199 questId: `quest-${quests.length + 1}`,
200 title: "New quest",
201 description: ""
202 });
203 draft = structuredClone(base);
204 selectedId = null;
205 render();
206 });
207 saveBtn.addEventListener("click", () =>
208 {
209 if (!draft)
210 { return; }
211 socket.send({ type: MessageType.editorSaveQuest, quest: draft });
212 });
213 deleteBtn.addEventListener("click", () =>
214 {
215 if (!draft?.questId)
216 { return; }
217 if (!window.confirm(`Delete quest "${draft.questId}"?`))
218 { return; }
219 socket.send({ type: MessageType.editorDeleteQuest, questId: draft.questId });
220 });
221
222 return {
223 isOpen: () => open,
224 handleMessage (message)
225 {
226 if (message.type === MessageType.editorDialogues)
227 {
228 dialogues = (message.dialogues ?? []).map((d) => normalizeDialogueTree(d));
229 if (open)
230 { render(); }
231 return;
232 }
233 if (message.type !== MessageType.editorQuests)
234 { return; }
235 quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));
236 if (draft)
237 {
238 const still = quests.find((q) => q.questId === draft.questId);
239 if (still)
240 {
241 selectedId = still.questId;
242 draft = structuredClone(still);
243 }
244 else if (selectedId)
245 {
246 draft = null;
247 selectedId = null;
248 }
249 }
250 if (open)
251 { render(); }
252 }
253 };
254}
255
256function field (label, input)
257{
258 const wrap = document.createElement("label");
259 wrap.append(document.createTextNode(label), input);
260 return wrap;
261}
262
263function textInput (value, onChange)
264{
265 const input = document.createElement("input");
266 input.type = "text";
267 input.value = value ?? "";
268 input.addEventListener("input", () => onChange(input.value));
269 return input;
270}
271
272function textArea (value, onChange, rows = 3)
273{
274 const input = document.createElement("textarea");
275 input.rows = rows;
276 input.value = value ?? "";
277 input.addEventListener("input", () => onChange(input.value));
278 return input;
279}
280
281function sectionHeader (title, onAdd, onRemove)
282{
283 const head = document.createElement("div");
284 head.className = "content-editor-section-header";
285 const strong = document.createElement("strong");
286 strong.textContent = title;
287 head.append(strong);
288 const actions = document.createElement("div");
289 actions.className = "content-editor-row";
290 if (onAdd)
291 {
292 const add = document.createElement("button");
293 add.type = "button";
294 add.textContent = "+";
295 add.title = "Add";
296 add.addEventListener("click", onAdd);
297 actions.append(add);
298 }
299 if (onRemove)
300 {
301 const remove = document.createElement("button");
302 remove.type = "button";
303 remove.textContent = "×";
304 remove.title = "Remove";
305 remove.addEventListener("click", onRemove);
306 actions.append(remove);
307 }
308 head.append(actions);
309 return head;
310}
311
312function renderConditionSet (when, onChange, ctx = {})
313{
314 const wrap = document.createElement("div");
315 const set = normalizeConditionSet(when);
316 const bump = (remount = true) => onChange(set, { remount });
317 const questList = Array.isArray(ctx.quests) ? ctx.quests : [];
318 const dialogueList = Array.isArray(ctx.dialogues) ? ctx.dialogues : [];
319 const title = document.createElement("strong");
320 title.textContent = "When (all of)";
321 wrap.append(title);
322
323 set.all.forEach((clause, index) =>
324 {
325 const row = document.createElement("div");
326 row.className = "content-editor-clause";
327 const notLabel = document.createElement("label");
328 const notBox = document.createElement("input");
329 notBox.type = "checkbox";
330 notBox.checked = !!clause.not;
331 notBox.addEventListener("change", () =>
332 {
333 set.all[index].not = notBox.checked;
334 bump(false);
335 });
336 notLabel.append(notBox, document.createTextNode(" NOT"));
337 row.append(notLabel);
338
339 const kind = document.createElement("select");
340 for (const k of SIMPLE_KINDS)
341 {
342 const opt = document.createElement("option");
343 opt.value = k;
344 opt.textContent = k;
345 if ((clause.condition?.kind ?? "") === k)
346 { opt.selected = true; }
347 kind.append(opt);
348 }
349 const otherOpt = document.createElement("option");
350 otherOpt.value = "__other__";
351 otherOpt.textContent = "(other / JSON)";
352 if (!SIMPLE_KINDS.includes(clause.condition?.kind))
353 { otherOpt.selected = true; }
354 kind.append(otherOpt);
355 kind.addEventListener("change", () =>
356 {
357 if (kind.value === "__other__")
358 { return; }
359 set.all[index].condition = defaultCondition(kind.value);
360 bump(true);
361 });
362 row.append(kind);
363
364 const cond = clause.condition ?? { kind: ConditionKind.hasItem };
365 if (cond.kind === ConditionKind.hasItem)
366 {
367 row.append(itemConditionPicker(cond, () =>
368 {
369 set.all[index].condition = cond;
370 bump(false);
371 }));
372 row.append(miniField("qty", cond.quantity ?? 1, (v) =>
373 {
374 cond.quantity = Number(v) || 1;
375 set.all[index].condition = cond;
376 bump(false);
377 }));
378 }
379 else if (cond.kind === ConditionKind.questState)
380 {
381 row.append(questStateConditionFields(cond, questList, () =>
382 {
383 set.all[index].condition = cond;
384 bump(false);
385 }));
386 }
387 else if (cond.kind === ConditionKind.dialogueHeard)
388 {
389 row.append(dialogueHeardConditionFields(cond, dialogueList, () =>
390 {
391 set.all[index].condition = cond;
392 bump(false);
393 }));
394 }
395 else if (cond.kind === ConditionKind.killCount)
396 {
397 row.append(killCountConditionFields(cond, () =>
398 {
399 set.all[index].condition = cond;
400 bump(false);
401 }));
402 }
403 else if (cond.kind === ConditionKind.atTile)
404 {
405 row.append(miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>
406 {
407 cond.dimensionId = String(v || "overworld");
408 set.all[index].condition = cond;
409 bump(false);
410 }));
411 row.append(miniField("tileX", cond.tileX ?? 0, (v) =>
412 {
413 cond.tileX = Number(v) | 0;
414 set.all[index].condition = cond;
415 bump(false);
416 }));
417 row.append(miniField("tileY", cond.tileY ?? 0, (v) =>
418 {
419 cond.tileY = Number(v) | 0;
420 set.all[index].condition = cond;
421 bump(false);
422 }));
423 }
424 else if (
425 cond.kind === ConditionKind.inDimension
426 || cond.kind === ConditionKind.hasVisitedDimension
427 )
428 {
429 row.append(miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>
430 {
431 cond.dimensionId = String(v || "overworld");
432 set.all[index].condition = cond;
433 bump(false);
434 }));
435 }
436 else
437 {
438 const json = document.createElement("textarea");
439 json.rows = 3;
440 json.value = JSON.stringify(cond, null, 2);
441 json.addEventListener("change", () =>
442 {
443 try
444 {
445 set.all[index].condition = JSON.parse(json.value);
446 bump(false);
447 }
448 catch
449 { /* keep typing */ }
450 });
451 row.append(json);
452 }
453
454 const remove = document.createElement("button");
455 remove.type = "button";
456 remove.textContent = "×";
457 remove.addEventListener("click", () =>
458 {
459 set.all.splice(index, 1);
460 bump(true);
461 });
462 row.append(remove);
463 wrap.append(row);
464 });
465
466 const add = document.createElement("button");
467 add.type = "button";
468 add.textContent = "Add clause";
469 add.addEventListener("click", () =>
470 {
471 set.all.push({ not: false, condition: defaultCondition(ConditionKind.hasItem) });
472 bump(true);
473 });
474 wrap.append(add);
475
476 const jsonFallback = document.createElement("details");
477 const summary = document.createElement("summary");
478 summary.textContent = "Edit condition set as JSON";
479 const area = document.createElement("textarea");
480 area.rows = 5;
481 area.value = JSON.stringify(set, null, 2);
482 area.addEventListener("change", () =>
483 {
484 try
485 {
486 onChange(normalizeConditionSet(JSON.parse(area.value)), { remount: true });
487 }
488 catch
489 { /* ignore */ }
490 });
491 jsonFallback.append(summary, area);
492 wrap.append(jsonFallback);
493 return wrap;
494}
495
496/** Mob selector + kill quantity for killCount conditions. */
497function killCountConditionFields (cond, onChanged)
498{
499 const wrap = document.createElement("div");
500 wrap.className = "quest-condition-pair";
501 const mobSelect = document.createElement("select");
502 for (const def of listSpawnableMobTypes())
503 {
504 const opt = document.createElement("option");
505 opt.value = def.mobTypeId;
506 opt.textContent = def.displayName ?? def.mobTypeId;
507 if (def.mobTypeId === cond.mobTypeId)
508 { opt.selected = true; }
509 mobSelect.append(opt);
510 }
511 if (cond.mobTypeId && ![...mobSelect.options].some((o) => o.value === cond.mobTypeId))
512 {
513 const missing = document.createElement("option");
514 missing.value = cond.mobTypeId;
515 missing.textContent = `${cond.mobTypeId} (missing)`;
516 missing.selected = true;
517 mobSelect.append(missing);
518 }
519 if (!cond.mobTypeId && mobSelect.options.length)
520 {
521 cond.mobTypeId = mobSelect.options[0].value;
522 mobSelect.options[0].selected = true;
523 }
524 const qty = document.createElement("input");
525 qty.type = "number";
526 qty.min = "1";
527 qty.step = "1";
528 qty.style.width = "5rem";
529 qty.value = String(Math.max(1, Number(cond.count) || 1));
530 qty.title = "Kill count";
531 mobSelect.addEventListener("change", () =>
532 {
533 cond.mobTypeId = mobSelect.value || undefined;
534 onChanged();
535 });
536 qty.addEventListener("input", () =>
537 {
538 cond.count = Math.max(1, Number(qty.value) || 1);
539 onChanged();
540 });
541 wrap.append(mobSelect, qty);
542 return wrap;
543}
544
545/** Dialogue picker + step-id dropdown from that tree. */
546function dialogueHeardConditionFields (cond, dialogueList, onChanged)
547{
548 const wrap = document.createElement("div");
549 wrap.className = "quest-condition-pair";
550 const dialogueSelect = document.createElement("select");
551 const blank = document.createElement("option");
552 blank.value = "";
553 blank.textContent = "Select dialogue…";
554 dialogueSelect.append(blank);
555 for (const tree of dialogueList)
556 {
557 const opt = document.createElement("option");
558 opt.value = tree.dialogueId;
559 opt.textContent = tree.label ? `${tree.label} (${tree.dialogueId})` : tree.dialogueId;
560 if (tree.dialogueId === cond.dialogueId)
561 { opt.selected = true; }
562 dialogueSelect.append(opt);
563 }
564 if (cond.dialogueId && !dialogueList.some((d) => d.dialogueId === cond.dialogueId))
565 {
566 const missing = document.createElement("option");
567 missing.value = cond.dialogueId;
568 missing.textContent = `${cond.dialogueId} (missing)`;
569 missing.selected = true;
570 dialogueSelect.append(missing);
571 }
572
573 const stepSelect = document.createElement("select");
574 const fillSteps = () =>
575 {
576 const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId) ?? null;
577 stepSelect.replaceChildren();
578 const steps = tree?.steps ?? [];
579 if (!steps.length)
580 {
581 const empty = document.createElement("option");
582 empty.value = cond.stepId ?? "";
583 empty.textContent = cond.stepId ? String(cond.stepId) : "No steps";
584 empty.selected = true;
585 stepSelect.append(empty);
586 return;
587 }
588 let matched = false;
589 for (const step of steps)
590 {
591 const opt = document.createElement("option");
592 opt.value = step.stepId;
593 opt.textContent = step.label
594 ? `${step.label} (${step.stepId})`
595 : step.stepId;
596 if (step.stepId === cond.stepId)
597 {
598 opt.selected = true;
599 matched = true;
600 }
601 stepSelect.append(opt);
602 }
603 if (!matched && cond.stepId)
604 {
605 const fallback = document.createElement("option");
606 fallback.value = cond.stepId;
607 fallback.textContent = `${cond.stepId} (missing)`;
608 fallback.selected = true;
609 stepSelect.append(fallback);
610 }
611 else if (!matched)
612 {
613 cond.stepId = steps[0].stepId;
614 stepSelect.options[0].selected = true;
615 }
616 };
617 fillSteps();
618
619 dialogueSelect.addEventListener("change", () =>
620 {
621 cond.dialogueId = dialogueSelect.value;
622 const tree = dialogueList.find((d) => d.dialogueId === cond.dialogueId);
623 cond.stepId = tree?.steps?.[0]?.stepId ?? "";
624 fillSteps();
625 onChanged();
626 });
627 stepSelect.addEventListener("change", () =>
628 {
629 cond.stepId = stepSelect.value;
630 onChanged();
631 });
632 wrap.append(dialogueSelect, stepSelect);
633 return wrap;
634}
635
636/** Quest picker + state dropdown from that quest's steps. */
637function questStateConditionFields (cond, questList, onChanged)
638{
639 const wrap = document.createElement("div");
640 wrap.className = "quest-condition-pair";
641 const questSelect = document.createElement("select");
642 const blank = document.createElement("option");
643 blank.value = "";
644 blank.textContent = "Select quest…";
645 questSelect.append(blank);
646 for (const quest of questList)
647 {
648 const opt = document.createElement("option");
649 opt.value = quest.questId;
650 opt.textContent = quest.title ? `${quest.title} (${quest.questId})` : quest.questId;
651 if (quest.questId === cond.questId)
652 { opt.selected = true; }
653 questSelect.append(opt);
654 }
655 if (cond.questId && !questList.some((q) => q.questId === cond.questId))
656 {
657 const missing = document.createElement("option");
658 missing.value = cond.questId;
659 missing.textContent = `${cond.questId} (missing)`;
660 missing.selected = true;
661 questSelect.append(missing);
662 }
663
664 const stateSelect = document.createElement("select");
665 const fillStates = () =>
666 {
667 const quest = questList.find((q) => q.questId === cond.questId) ?? null;
668 stateSelect.replaceChildren();
669 const options = [
670 { value: "not-started", label: "not-started" },
671 ...((quest?.steps ?? []).map((step, index) => ({
672 value: String(index + 1),
673 label: `Step ${index + 1}: ${step.title || step.stepId}`
674 }))),
675 { value: "completed", label: "completed" }
676 ];
677 let matched = false;
678 for (const entry of options)
679 {
680 const opt = document.createElement("option");
681 opt.value = entry.value;
682 opt.textContent = entry.label;
683 const current = cond.state ?? "not-started";
684 const currentKey = current === "not-started" || current === "completed"
685 ? current
686 : String(Number(current) || current);
687 if (entry.value === currentKey)
688 {
689 opt.selected = true;
690 matched = true;
691 }
692 stateSelect.append(opt);
693 }
694 if (!matched)
695 {
696 const fallback = document.createElement("option");
697 fallback.value = String(cond.state ?? "not-started");
698 fallback.textContent = String(cond.state ?? "not-started");
699 fallback.selected = true;
700 stateSelect.append(fallback);
701 }
702 };
703 fillStates();
704
705 questSelect.addEventListener("change", () =>
706 {
707 cond.questId = questSelect.value;
708 cond.state = "not-started";
709 fillStates();
710 onChanged();
711 });
712 stateSelect.addEventListener("change", () =>
713 {
714 const raw = stateSelect.value;
715 if (raw === "not-started" || raw === "completed")
716 { cond.state = raw; }
717 else
718 { cond.state = Math.max(1, Number(raw) | 0); }
719 onChanged();
720 });
721 wrap.append(questSelect, stateSelect);
722 return wrap;
723}
724
725/** Compact searchable item picker for hasItem conditions. */
726function itemConditionPicker (cond, onPicked)
727{
728 const wrap = document.createElement("div");
729 wrap.className = "quest-condition-item-picker";
730 const pickBtn = document.createElement("button");
731 pickBtn.type = "button";
732 const refreshLabel = () =>
733 {
734 const def = itemDefinition(cond.itemId);
735 pickBtn.textContent = def?.displayName
736 ?? (cond.itemId ? `Item #${cond.itemId}` : "Pick item…");
737 pickBtn.title = cond.itemId
738 ? `${def?.key ?? "item"} · #${cond.itemId}`
739 : "Choose an item";
740 };
741 refreshLabel();
742 const searchWrap = document.createElement("div");
743 searchWrap.className = "dialogue-reward-item-search";
744 searchWrap.hidden = true;
745 const searchInput = document.createElement("input");
746 searchInput.type = "search";
747 searchInput.placeholder = "Search items…";
748 searchInput.autocomplete = "off";
749 const searchResults = document.createElement("div");
750 searchResults.className = "dialogue-reward-item-results";
751
752 const renderMatches = (query) =>
753 {
754 searchResults.replaceChildren();
755 const q = String(query ?? "").trim().toLowerCase();
756 const matches = listAllItemPickerEntries().filter((item) =>
757 {
758 if (!q)
759 { return true; }
760 return item.displayName.toLowerCase().includes(q)
761 || item.key.toLowerCase().includes(q)
762 || String(item.itemId).includes(q);
763 }).slice(0, 40);
764 if (!matches.length)
765 {
766 searchResults.textContent = "No matching items.";
767 return;
768 }
769 for (const item of matches)
770 {
771 const row = document.createElement("button");
772 row.type = "button";
773 row.className = "shop-item-search-row";
774 const name = document.createElement("span");
775 name.className = "shop-item-search-row-name";
776 name.textContent = item.displayName;
777 const key = document.createElement("span");
778 key.className = "shop-item-search-row-key";
779 key.textContent = `${item.key} · #${item.itemId}`;
780 row.append(name, key);
781 row.addEventListener("click", () =>
782 {
783 cond.itemId = item.itemId;
784 refreshLabel();
785 searchWrap.hidden = true;
786 onPicked();
787 });
788 searchResults.append(row);
789 }
790 };
791
792 pickBtn.addEventListener("click", () =>
793 {
794 searchWrap.hidden = !searchWrap.hidden;
795 if (!searchWrap.hidden)
796 {
797 searchInput.value = "";
798 renderMatches("");
799 searchInput.focus();
800 }
801 });
802 searchInput.addEventListener("input", () => renderMatches(searchInput.value));
803 searchWrap.append(searchInput, searchResults);
804 wrap.append(pickBtn, searchWrap);
805 return wrap;
806}
807
808function miniField (label, value, onChange)
809{
810 const wrap = document.createElement("label");
811 wrap.textContent = `${label} `;
812 const input = document.createElement("input");
813 input.type = "text";
814 input.value = String(value ?? "");
815 input.style.width = "7rem";
816 input.addEventListener("input", () => onChange(input.value));
817 wrap.append(input);
818 return wrap;
819}
820
821function defaultCondition (kind)
822{
823 switch (kind)
824 {
825 case ConditionKind.hasItem:
826 return { kind, itemId: 1, quantity: 1 };
827 case ConditionKind.questState:
828 return { kind, questId: "", state: "not-started" };
829 case ConditionKind.dialogueHeard:
830 return { kind, dialogueId: "", stepId: "" };
831 case ConditionKind.killCount:
832 return { kind, mobTypeId: "deer", count: 1 };
833 case ConditionKind.atTile:
834 return { kind, dimensionId: "overworld", tileX: 0, tileY: 0 };
835 case ConditionKind.inDimension:
836 case ConditionKind.hasVisitedDimension:
837 return { kind, dimensionId: "overworld" };
838 default:
839 return { kind };
840 }
841}