BlueGit

timfa questward

Files

questward / client / src / editor / conditionSetEditor.js

conditionSetEditor.js

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