Improve atTile objectives with tile info and center.
Show ground/block/spawner summary for the coords and pan the editor camera onto that tile without closing the quests UI.
@@ -339,6 +339,113 @@ function clearNeighborEditState ()
339
339
dirtyNeighborChunks.clear();
340
340
}
341
341
342
function groundAtWorld (tileX, tileY)
343
{
344
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);
345
const index = localY * CHUNK_SIZE + localX;
346
if (cx === chunkX && cy === chunkY && draft)
347
{ return draft.grounds[index] ?? null; }
348
const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy));
349
if (dirty)
350
{ return dirty.grounds[index] ?? null; }
351
const snapshot = view?.chunks.get(chunkKey(cx, cy));
352
return snapshot?.grounds?.[index] ?? null;
353
}
354
355
function spawnerAtWorld (tileX, tileY)
356
{
357
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);
358
if (cx === chunkX && cy === chunkY && draft)
359
{ return spawnerAt(localX, localY); }
360
const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy));
361
if (dirty)
362
{ return dirty.spawners?.find((entry) => entry.localX === localX && entry.localY === localY) ?? null; }
363
return (neighborSpawnersByChunk.get(chunkKey(cx, cy)) ?? [])
364
.find((entry) => entry.localX === localX && entry.localY === localY) ?? null;
365
}
366
367
/** Human-readable summary of authored ground/block/spawner on a world tile. */
368
function describeWorldTile (tileX, tileY, dimensionId = selectedDimensionId)
369
{
370
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);
371
if (dim !== selectedDimensionId)
372
{
373
return `Currently editing “${selectedDimensionId}”; switch to “${dim}” to inspect this tile.`;
374
}
375
const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);
376
const key = chunkKey(cx, cy);
377
const loaded = (cx === chunkX && cy === chunkY && draft)
378
|| dirtyNeighborChunks.has(key)
379
|| view?.chunks?.has(key);
380
if (!loaded)
381
{ return `Chunk (${cx}, ${cy}) not loaded — center on this tile to load it.`; }
382
383
const lines = [];
384
const ground = normalizeGround(groundAtWorld(tileX, tileY));
385
const groundDef = GROUND_DEFINITIONS[ground?.typeId];
386
lines.push(`Ground: ${groundDef?.displayName ?? `type ${ground?.typeId ?? "?"}`}`);
387
const block = normalizeBlock(blockAtWorld(tileX, tileY));
388
if (block)
389
{
390
const blockDef = BLOCK_DEFINITIONS[block.typeId];
391
lines.push(`Block: ${blockDef?.displayName ?? `type ${block.typeId}`}${block.state ? ` (${block.state})` : ""}`);
392
if (block.config && Object.keys(block.config).length)
393
{
394
for (const [keyName, value] of Object.entries(block.config))
395
{ lines.push(` ${keyName}: ${value}`); }
396
}
397
}
398
else
399
{ lines.push("Block: (none)"); }
400
const spawner = spawnerAtWorld(tileX, tileY);
401
if (spawner)
402
{
403
const config = normalizeSpawnerConfig(spawner.config, spawner.config?.spawnerId);
404
const mob = mobDefinition(config.mobTypeId);
405
lines.push(`Spawner: ${mob?.displayName ?? config.mobTypeId} (${config.spawnerId})`);
406
}
407
else
408
{ lines.push("Spawner: (none)"); }
409
return lines.join("\n");
410
}
411
412
/** Pan the editor to a world tile without closing other UI; loads its chunk neighborhood. */
413
function centerEditorOnTile (tileX, tileY, dimensionId = selectedDimensionId)
414
{
415
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);
416
const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX | 0, tileY | 0, CHUNK_SIZE);
417
if (dim !== selectedDimensionId)
418
{
419
if (isDraftDirty())
420
{
421
showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: dim });
422
return false;
423
}
424
selectedDimensionId = dim;
425
syncDimensionUi();
426
clearNeighborhoodView();
427
doLoadNeighborhood(cx, cy);
428
}
429
else if (cx !== chunkX || cy !== chunkY)
430
{
431
if (isDraftDirty())
432
{
433
showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: selectedDimensionId });
434
return false;
435
}
436
doLoadNeighborhood(cx, cy);
437
}
438
if (!view?.scene)
439
{ return true; }
440
const size = view.tileSize();
441
view.followPlayer = false;
442
view.scene.cameraPosition.x = view.scene.real_size.x / 2 - ((tileX | 0) + 0.5) * size;
443
view.scene.cameraPosition.y = view.scene.real_size.y / 2 - ((tileY | 0) + 0.5) * size;
444
view.refreshViewport();
445
updateSelectionBorder();
446
return true;
447
}
448
342
449
function blockAtWorld (tileX, tileY)
343
450
{
344
451
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);
@@ -1402,7 +1509,12 @@ async function main ()
1402
1509
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,
1403
1510
isOverworld
1404
1511
});
1405
questsModal = initQuestsModal({ socket, MessageType });
1512
questsModal = initQuestsModal({
1513
socket,
1514
MessageType,
1515
describeWorldTile,
1516
centerEditorOnTile
1517
});
1406
1518
dialoguesModal = initDialoguesModal({ socket, MessageType });
1407
1519
giftsModal = initGiftsModal({ socket, MessageType });
1408
1520
initSidePanelTabs();
@@ -339,6 +339,113 @@ function clearNeighborEditState ()339
dirtyNeighborChunks.clear();339
dirtyNeighborChunks.clear();340
}340
}341
341
342
function groundAtWorld (tileX, tileY)343
{344
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);345
const index = localY * CHUNK_SIZE + localX;346
if (cx === chunkX && cy === chunkY && draft)347
{ return draft.grounds[index] ?? null; }348
const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy));349
if (dirty)350
{ return dirty.grounds[index] ?? null; }351
const snapshot = view?.chunks.get(chunkKey(cx, cy));352
return snapshot?.grounds?.[index] ?? null;353
}354
355
function spawnerAtWorld (tileX, tileY)356
{357
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);358
if (cx === chunkX && cy === chunkY && draft)359
{ return spawnerAt(localX, localY); }360
const dirty = dirtyNeighborChunks.get(chunkKey(cx, cy));361
if (dirty)362
{ return dirty.spawners?.find((entry) => entry.localX === localX && entry.localY === localY) ?? null; }363
return (neighborSpawnersByChunk.get(chunkKey(cx, cy)) ?? [])364
.find((entry) => entry.localX === localX && entry.localY === localY) ?? null;365
}366
367
/** Human-readable summary of authored ground/block/spawner on a world tile. */368
function describeWorldTile (tileX, tileY, dimensionId = selectedDimensionId)369
{370
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);371
if (dim !== selectedDimensionId)372
{373
return `Currently editing “${selectedDimensionId}”; switch to “${dim}” to inspect this tile.`;374
}375
const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);376
const key = chunkKey(cx, cy);377
const loaded = (cx === chunkX && cy === chunkY && draft)378
|| dirtyNeighborChunks.has(key)379
|| view?.chunks?.has(key);380
if (!loaded)381
{ return `Chunk (${cx}, ${cy}) not loaded — center on this tile to load it.`; }382
383
const lines = [];384
const ground = normalizeGround(groundAtWorld(tileX, tileY));385
const groundDef = GROUND_DEFINITIONS[ground?.typeId];386
lines.push(`Ground: ${groundDef?.displayName ?? `type ${ground?.typeId ?? "?"}`}`);387
const block = normalizeBlock(blockAtWorld(tileX, tileY));388
if (block)389
{390
const blockDef = BLOCK_DEFINITIONS[block.typeId];391
lines.push(`Block: ${blockDef?.displayName ?? `type ${block.typeId}`}${block.state ? ` (${block.state})` : ""}`);392
if (block.config && Object.keys(block.config).length)393
{394
for (const [keyName, value] of Object.entries(block.config))395
{ lines.push(` ${keyName}: ${value}`); }396
}397
}398
else399
{ lines.push("Block: (none)"); }400
const spawner = spawnerAtWorld(tileX, tileY);401
if (spawner)402
{403
const config = normalizeSpawnerConfig(spawner.config, spawner.config?.spawnerId);404
const mob = mobDefinition(config.mobTypeId);405
lines.push(`Spawner: ${mob?.displayName ?? config.mobTypeId} (${config.spawnerId})`);406
}407
else408
{ lines.push("Spawner: (none)"); }409
return lines.join("\n");410
}411
412
/** Pan the editor to a world tile without closing other UI; loads its chunk neighborhood. */413
function centerEditorOnTile (tileX, tileY, dimensionId = selectedDimensionId)414
{415
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);416
const { chunkX: cx, chunkY: cy } = worldTileToChunkLocal(tileX | 0, tileY | 0, CHUNK_SIZE);417
if (dim !== selectedDimensionId)418
{419
if (isDraftDirty())420
{421
showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: dim });422
return false;423
}424
selectedDimensionId = dim;425
syncDimensionUi();426
clearNeighborhoodView();427
doLoadNeighborhood(cx, cy);428
}429
else if (cx !== chunkX || cy !== chunkY)430
{431
if (isDraftDirty())432
{433
showUnsavedModal({ chunkX: cx, chunkY: cy, dimensionId: selectedDimensionId });434
return false;435
}436
doLoadNeighborhood(cx, cy);437
}438
if (!view?.scene)439
{ return true; }440
const size = view.tileSize();441
view.followPlayer = false;442
view.scene.cameraPosition.x = view.scene.real_size.x / 2 - ((tileX | 0) + 0.5) * size;443
view.scene.cameraPosition.y = view.scene.real_size.y / 2 - ((tileY | 0) + 0.5) * size;444
view.refreshViewport();445
updateSelectionBorder();446
return true;447
}448
342
function blockAtWorld (tileX, tileY)449
function blockAtWorld (tileX, tileY)343
{450
{344
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);451
const { chunkX: cx, chunkY: cy, localX, localY } = worldTileToChunkLocal(tileX, tileY, CHUNK_SIZE);@@ -1402,7 +1509,12 @@ async function main ()1402
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,1509
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,1403
isOverworld1510
isOverworld1404
});1511
});1405
questsModal = initQuestsModal({ socket, MessageType });1512
questsModal = initQuestsModal({1513
socket,1514
MessageType,1515
describeWorldTile,1516
centerEditorOnTile1517
});1406
dialoguesModal = initDialoguesModal({ socket, MessageType });1518
dialoguesModal = initDialoguesModal({ socket, MessageType });1407
giftsModal = initGiftsModal({ socket, MessageType });1519
giftsModal = initGiftsModal({ socket, MessageType });1408
initSidePanelTabs();1520
initSidePanelTabs();@@ -13,7 +13,12 @@ const SIMPLE_KINDS = [
13
13
ConditionKind.hasVisitedDimension
14
14
];
15
15
16
export function initQuestsModal ({ socket, MessageType })
16
export function initQuestsModal ({
17
socket,
18
MessageType,
19
describeWorldTile = null,
20
centerEditorOnTile = null
21
})
17
22
{
18
23
const backdrop = document.getElementById("quests-backdrop");
19
24
const modal = document.getElementById("quests-modal");
@@ -171,7 +176,7 @@ export function initQuestsModal ({ socket, MessageType })
171
176
obj.when = next;
172
177
if (remount)
173
178
{ renderEditor(); }
174
}, { quests, dialogues }));
179
}, { quests, dialogues, describeWorldTile, centerEditorOnTile }));
175
180
box.append(objBox);
176
181
});
177
182
editorEl.append(box);
@@ -402,21 +407,8 @@ function renderConditionSet (when, onChange, ctx = {})
402
407
}
403
408
else if (cond.kind === ConditionKind.atTile)
404
409
{
405
row.append(miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>
410
row.append(atTileConditionFields(cond, ctx, () =>
406
411
{
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
412
set.all[index].condition = cond;
421
413
bump(false);
422
414
}));
@@ -493,6 +485,80 @@ function renderConditionSet (when, onChange, ctx = {})
493
485
return wrap;
494
486
}
495
487
488
/** X/Y inputs, tile summary, and center-editor control for atTile. */
489
function atTileConditionFields (cond, ctx, onChanged)
490
{
491
const wrap = document.createElement("div");
492
wrap.className = "quest-condition-attile";
493
const dimField = miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>
494
{
495
cond.dimensionId = String(v || "overworld");
496
refreshInfo();
497
onChanged();
498
});
499
const xInput = document.createElement("input");
500
xInput.type = "number";
501
xInput.step = "1";
502
xInput.style.width = "5rem";
503
xInput.value = String(cond.tileX ?? 0);
504
xInput.title = "Tile X";
505
const yInput = document.createElement("input");
506
yInput.type = "number";
507
yInput.step = "1";
508
yInput.style.width = "5rem";
509
yInput.value = String(cond.tileY ?? 0);
510
yInput.title = "Tile Y";
511
const xyRow = document.createElement("div");
512
xyRow.className = "quest-condition-pair";
513
const xLabel = document.createElement("label");
514
xLabel.append(document.createTextNode("X "), xInput);
515
const yLabel = document.createElement("label");
516
yLabel.append(document.createTextNode("Y "), yInput);
517
const centerBtn = document.createElement("button");
518
centerBtn.type = "button";
519
centerBtn.textContent = "Center editor";
520
centerBtn.title = "Pan the world editor to this tile (keeps this UI open)";
521
const info = document.createElement("pre");
522
info.className = "quest-condition-tile-info";
523
524
const refreshInfo = () =>
525
{
526
if (typeof ctx.describeWorldTile === "function")
527
{
528
info.textContent = ctx.describeWorldTile(
529
cond.tileX | 0,
530
cond.tileY | 0,
531
cond.dimensionId
532
);
533
}
534
else
535
{ info.textContent = "Tile inspection unavailable."; }
536
};
537
538
xInput.addEventListener("input", () =>
539
{
540
cond.tileX = Number(xInput.value) | 0;
541
refreshInfo();
542
onChanged();
543
});
544
yInput.addEventListener("input", () =>
545
{
546
cond.tileY = Number(yInput.value) | 0;
547
refreshInfo();
548
onChanged();
549
});
550
centerBtn.addEventListener("click", () =>
551
{
552
ctx.centerEditorOnTile?.(cond.tileX | 0, cond.tileY | 0, cond.dimensionId);
553
refreshInfo();
554
});
555
556
xyRow.append(xLabel, yLabel, centerBtn);
557
wrap.append(dimField, xyRow, info);
558
refreshInfo();
559
return wrap;
560
}
561
496
562
/** Mob selector + kill quantity for killCount conditions. */
497
563
function killCountConditionFields (cond, onChanged)
498
564
{
@@ -13,7 +13,12 @@ const SIMPLE_KINDS = [13
ConditionKind.hasVisitedDimension13
ConditionKind.hasVisitedDimension14
];14
];15
15
16
export function initQuestsModal ({ socket, MessageType })16
export function initQuestsModal ({17
socket,18
MessageType,19
describeWorldTile = null,20
centerEditorOnTile = null21
})17
{22
{18
const backdrop = document.getElementById("quests-backdrop");23
const backdrop = document.getElementById("quests-backdrop");19
const modal = document.getElementById("quests-modal");24
const modal = document.getElementById("quests-modal");@@ -171,7 +176,7 @@ export function initQuestsModal ({ socket, MessageType })171
obj.when = next;176
obj.when = next;172
if (remount)177
if (remount)173
{ renderEditor(); }178
{ renderEditor(); }174
}, { quests, dialogues }));179
}, { quests, dialogues, describeWorldTile, centerEditorOnTile }));175
box.append(objBox);180
box.append(objBox);176
});181
});177
editorEl.append(box);182
editorEl.append(box);@@ -402,21 +407,8 @@ function renderConditionSet (when, onChange, ctx = {})402
}407
}403
else if (cond.kind === ConditionKind.atTile)408
else if (cond.kind === ConditionKind.atTile)404
{409
{405
row.append(miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>410
row.append(atTileConditionFields(cond, ctx, () =>406
{411
{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;412
set.all[index].condition = cond;421
bump(false);413
bump(false);422
}));414
}));@@ -493,6 +485,80 @@ function renderConditionSet (when, onChange, ctx = {})493
return wrap;485
return wrap;494
}486
}495
487
488
/** X/Y inputs, tile summary, and center-editor control for atTile. */489
function atTileConditionFields (cond, ctx, onChanged)490
{491
const wrap = document.createElement("div");492
wrap.className = "quest-condition-attile";493
const dimField = miniField("dimensionId", cond.dimensionId ?? "overworld", (v) =>494
{495
cond.dimensionId = String(v || "overworld");496
refreshInfo();497
onChanged();498
});499
const xInput = document.createElement("input");500
xInput.type = "number";501
xInput.step = "1";502
xInput.style.width = "5rem";503
xInput.value = String(cond.tileX ?? 0);504
xInput.title = "Tile X";505
const yInput = document.createElement("input");506
yInput.type = "number";507
yInput.step = "1";508
yInput.style.width = "5rem";509
yInput.value = String(cond.tileY ?? 0);510
yInput.title = "Tile Y";511
const xyRow = document.createElement("div");512
xyRow.className = "quest-condition-pair";513
const xLabel = document.createElement("label");514
xLabel.append(document.createTextNode("X "), xInput);515
const yLabel = document.createElement("label");516
yLabel.append(document.createTextNode("Y "), yInput);517
const centerBtn = document.createElement("button");518
centerBtn.type = "button";519
centerBtn.textContent = "Center editor";520
centerBtn.title = "Pan the world editor to this tile (keeps this UI open)";521
const info = document.createElement("pre");522
info.className = "quest-condition-tile-info";523
524
const refreshInfo = () =>525
{526
if (typeof ctx.describeWorldTile === "function")527
{528
info.textContent = ctx.describeWorldTile(529
cond.tileX | 0,530
cond.tileY | 0,531
cond.dimensionId532
);533
}534
else535
{ info.textContent = "Tile inspection unavailable."; }536
};537
538
xInput.addEventListener("input", () =>539
{540
cond.tileX = Number(xInput.value) | 0;541
refreshInfo();542
onChanged();543
});544
yInput.addEventListener("input", () =>545
{546
cond.tileY = Number(yInput.value) | 0;547
refreshInfo();548
onChanged();549
});550
centerBtn.addEventListener("click", () =>551
{552
ctx.centerEditorOnTile?.(cond.tileX | 0, cond.tileY | 0, cond.dimensionId);553
refreshInfo();554
});555
556
xyRow.append(xLabel, yLabel, centerBtn);557
wrap.append(dimField, xyRow, info);558
refreshInfo();559
return wrap;560
}561
496
/** Mob selector + kill quantity for killCount conditions. */562
/** Mob selector + kill quantity for killCount conditions. */497
function killCountConditionFields (cond, onChanged)563
function killCountConditionFields (cond, onChanged)498
{564
{@@ -1568,6 +1568,26 @@ label {
1568
1568
max-width: 18rem;
1569
1569
}
1570
1570
1571
.quest-condition-attile {
1572
display: flex;
1573
flex-direction: column;
1574
gap: 0.35rem;
1575
min-width: 14rem;
1576
}
1577
1578
.quest-condition-tile-info {
1579
margin: 0;
1580
padding: 0.35rem 0.45rem;
1581
max-width: 28rem;
1582
white-space: pre-wrap;
1583
font-size: 0.8rem;
1584
line-height: 1.35;
1585
color: #c5d4e8;
1586
background: #12151c;
1587
border: 1px solid #3a4250;
1588
border-radius: 4px;
1589
}
1590
1571
1591
.dialogue-reward-item-search {
1572
1592
display: flex;
1573
1593
flex-direction: column;
@@ -1568,6 +1568,26 @@ label {1568
max-width: 18rem;1568
max-width: 18rem;1569
}1569
}1570
1570
1571
.quest-condition-attile {1572
display: flex;1573
flex-direction: column;1574
gap: 0.35rem;1575
min-width: 14rem;1576
}1577
1578
.quest-condition-tile-info {1579
margin: 0;1580
padding: 0.35rem 0.45rem;1581
max-width: 28rem;1582
white-space: pre-wrap;1583
font-size: 0.8rem;1584
line-height: 1.35;1585
color: #c5d4e8;1586
background: #12151c;1587
border: 1px solid #3a4250;1588
border-radius: 4px;1589
}1590
1571
.dialogue-reward-item-search {1591
.dialogue-reward-item-search {1572
display: flex;1592
display: flex;1573
flex-direction: column;1593
flex-direction: column;