Add mob selector and quantity for killCount objectives.
Replace free-text mob ids with the spawnable mob dropdown and a numeric kill count.
@@ -1,6 +1,7 @@
1
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
import { listSpawnableMobTypes } from "/shared/definitions/mobs.js";
4
5
5
6
const SIMPLE_KINDS = [
6
7
ConditionKind.hasItem,
@@ -393,15 +394,8 @@ function renderConditionSet (when, onChange, ctx = {})
393
394
}
394
395
else if (cond.kind === ConditionKind.killCount)
395
396
{
396
row.append(miniField("mobTypeId", cond.mobTypeId ?? "", (v) =>
397
row.append(killCountConditionFields(cond, () =>
397
398
{
398
cond.mobTypeId = v || undefined;
399
set.all[index].condition = cond;
400
bump(false);
401
}));
402
row.append(miniField("count", cond.count ?? 1, (v) =>
403
{
404
cond.count = Number(v) || 1;
405
399
set.all[index].condition = cond;
406
400
bump(false);
407
401
}));
@@ -499,6 +493,55 @@ function renderConditionSet (when, onChange, ctx = {})
499
493
return wrap;
500
494
}
501
495
496
/** Mob selector + kill quantity for killCount conditions. */
497
function 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
502
545
/** Dialogue picker + step-id dropdown from that tree. */
503
546
function dialogueHeardConditionFields (cond, dialogueList, onChanged)
504
547
{
@@ -1,6 +1,7 @@1
import { normalizeQuestDef, normalizeDialogueTree } 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
import { listSpawnableMobTypes } from "/shared/definitions/mobs.js";4
5
5
const SIMPLE_KINDS = [6
const SIMPLE_KINDS = [6
ConditionKind.hasItem,7
ConditionKind.hasItem,@@ -393,15 +394,8 @@ function renderConditionSet (when, onChange, ctx = {})393
}394
}394
else if (cond.kind === ConditionKind.killCount)395
else if (cond.kind === ConditionKind.killCount)395
{396
{396
row.append(miniField("mobTypeId", cond.mobTypeId ?? "", (v) =>397
row.append(killCountConditionFields(cond, () =>397
{398
{398
cond.mobTypeId = v || undefined;399
set.all[index].condition = cond;400
bump(false);401
}));402
row.append(miniField("count", cond.count ?? 1, (v) =>403
{404
cond.count = Number(v) || 1;405
set.all[index].condition = cond;399
set.all[index].condition = cond;406
bump(false);400
bump(false);407
}));401
}));@@ -499,6 +493,55 @@ function renderConditionSet (when, onChange, ctx = {})499
return wrap;493
return wrap;500
}494
}501
495
496
/** Mob selector + kill quantity for killCount conditions. */497
function 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
502
/** Dialogue picker + step-id dropdown from that tree. */545
/** Dialogue picker + step-id dropdown from that tree. */503
function dialogueHeardConditionFields (cond, dialogueList, onChanged)546
function dialogueHeardConditionFields (cond, dialogueList, onChanged)504
{547
{