Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/web/src/lib/components/SelectionPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ const status = $derived(session.error !== "" ? session.error : session.message);
<div class="actions">
<button class="ore-btn ore-btn--dark ore-type-ui" class:ore-btn--touch={touch} onclick={() => session.placeAt([at[0], at[1], at[2]], session.block)} data-testid="at-set">Set to chosen block</button>
<button class="ore-btn ore-btn--secondary ore-type-ui" class:ore-btn--touch={touch} onclick={() => session.eraseAt([at[0], at[1], at[2]])} data-testid="at-erase">Erase</button>
<button class="ore-btn ore-btn--secondary ore-type-ui" class:ore-btn--touch={touch} onclick={() => session.inspectAt([at[0], at[1], at[2]])} data-testid="at-inspect">Inspect</button>
</div>
<p class="hint ore-type-ui-small">Works with the keyboard alone. {span} The block state panel then shows that block.</p>
<p class="hint ore-type-ui-small">Works with the keyboard alone. {span} Set or Inspect shows that block in the block state panel.</p>
</div>
</section>
{/snippet}
Expand Down Expand Up @@ -217,7 +218,7 @@ const status = $derived(session.error !== "" ? session.error : session.message);
<label class="check ore-choice__row">
<input type="checkbox" class="ore-choice__input" bind:checked={session.skipAir} />
<span class="ore-box" aria-hidden="true"><svg viewBox="0 0 12 12" width="14" height="14" aria-hidden="true" focusable="false" shape-rendering="crispEdges"><path d="M2 6.5l3 3 5-6.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="butt" stroke-linejoin="miter" /></svg></span>
<span class="ore-choice__text ore-type-ui">leave the target alone where there is air (paste and move)</span>
<span class="ore-choice__text ore-type-ui">leave the target alone where there is air (paste, move and rotate)</span>
</label>

<h3 class="ore-type-ui-strong">Corners, typed</h3>
Expand Down Expand Up @@ -300,7 +301,7 @@ const status = $derived(session.error !== "" ? session.error : session.message);
<label class="check ore-choice__row">
<input type="checkbox" class="ore-choice__input" bind:checked={session.skipAir} />
<span class="ore-box" aria-hidden="true"><svg viewBox="0 0 12 12" width="14" height="14" aria-hidden="true" focusable="false" shape-rendering="crispEdges"><path d="M2 6.5l3 3 5-6.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="butt" stroke-linejoin="miter" /></svg></span>
<span class="ore-choice__text ore-type-ui">leave the target alone where there is air (paste and move)</span>
<span class="ore-choice__text ore-type-ui">leave the target alone where there is air (paste, move and rotate)</span>
</label>
</div>
</div>
Expand Down
63 changes: 57 additions & 6 deletions apps/web/src/lib/editor-session.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// cells. After every change the sections core marked dirty go to the renderer to be re-meshed.

import {
AIR,
type Box,
type Clipboard,
type Command,
Expand Down Expand Up @@ -279,7 +280,7 @@ export class EditSession {
const p = this.inspected;
if (p === null) return null;
const b = this.volume.get(p[0], p[1], p[2]);
return b === undefined ? null : b;
return b === undefined || b === AIR ? null : b;
}

get paletteBlocks(): ReturnType<typeof paletteEntries> {
Expand Down Expand Up @@ -439,7 +440,9 @@ export class EditSession {
this.canvas.focus({ preventScroll: true });
this.canvas.setPointerCapture(e.pointerId);
this.error = "";
this.begin(this.pick(e.clientX, e.clientY), e.clientX, e.clientY);
const hit = this.pick(e.clientX, e.clientY);
this.applyHover(hit);
this.begin(hit, e.clientX, e.clientY);
}

private begin(hit: Hover | null, x: number, y: number): void {
Expand Down Expand Up @@ -593,14 +596,16 @@ export class EditSession {
this.applyHover(this.pick(x, y));
}

/** Make a pick the hover, redrawing only if it names another cell. */
/** Make a pick the hover, redrawing only if it names another cell or block. */
private applyHover(hit: Hover | null): void {
const same =
hit === null
? this.hover === null
: this.hover !== null &&
keyOf(hit.position) === keyOf(this.hover.position) &&
keyOf(hit.adjacent) === keyOf(this.hover.adjacent);
keyOf(hit.adjacent) === keyOf(this.hover.adjacent) &&
keyOf(hit.normal) === keyOf(this.hover.normal) &&
hit.block === this.hover.block;
if (same) return;
this.hover = hit;
if (hit !== null) this.inspected = hit.position;
Expand All @@ -615,10 +620,10 @@ export class EditSession {
const hit = this.pick(
x,
y,
drag.tool === "erase" ? undefined : (cx, cy, cz) => drag.touched.has(`${cx},${cy},${cz}`),
drag.tool === "place" ? (cx, cy, cz) => drag.touched.has(`${cx},${cy},${cz}`) : undefined,
);
if (hit !== null) this.brushTo(drag, hit);
this.hover = hit;
if (hit !== null) this.brushTo(drag, hit);
break;
}
case "line": {
Expand Down Expand Up @@ -783,6 +788,7 @@ export class EditSession {
const hit = this.pick(x, ry);
if (hit === null) return;
this.error = "";
this.hover = hit;
this.begin(hit, x, ry);
this.schedule();
}
Expand Down Expand Up @@ -1360,6 +1366,7 @@ export class EditSession {
if (drag.kind === "brush") {
drag.stroke.cancel();
this.flush();
this.syncHover();
} else if (drag.kind === "select") this.selection = drag.before;
this.refreshHighlight();
}
Expand Down Expand Up @@ -1444,6 +1451,7 @@ export class EditSession {
this.error = "";
this.flush();
this.revision++;
this.syncHover();
this.refreshHighlight();
}

Expand All @@ -1470,6 +1478,19 @@ export class EditSession {
this.onEvent?.(event);
}

/** Keep `hover` matching the volume after an edit or history step; returns whether it cleared to `null`. */
private syncHover(): boolean {
const h = this.hover;
if (h === null) return false;
const b = this.volume.get(h.position[0], h.position[1], h.position[2]);
if (b === undefined || b === AIR) {
this.hover = null;
return true;
}
if (b !== h.block) this.hover = { ...h, block: b };
return false;
}

/** Tell the renderer which sections to rebuild, keep the pick bounds covering the volume, and refresh the panels. */
private afterChange(command: Command): void {
forEachChange(command, (x, y, z, _before, after) => {
Expand All @@ -1492,6 +1513,15 @@ export class EditSession {
});
this.flush();
this.revision++;
if (
this.syncHover() ||
(this.drag === null &&
this.pending === null &&
this.inspected !== null &&
this.inspectedBlock === null)
) {
this.refreshHighlight();
}
}

private flush(): void {
Expand Down Expand Up @@ -1601,6 +1631,27 @@ export class EditSession {
return done;
}

/** Point the block-state panel at a cell without editing it. Returns whether a block was there. */
inspectAt(pos: Vec3): boolean {
if (pos.length !== 3 || !pos.every((n) => Number.isInteger(n) && Math.abs(n) <= 0x7fffffff)) {
this.error = "position must be integer coordinates";
this.message = "";
return false;
}
const cell: Vec3 = [pos[0] || 0, pos[1] || 0, pos[2] || 0];
const b = this.volume.get(cell[0], cell[1], cell[2]);
if (b === undefined || b === AIR) {
this.inspected = null;
this.say(`No block at ${cellText(cell)}.`);
this.refreshHighlight();
return false;
}
this.inspected = cell;
this.say(`${withoutNbt(b)} at ${cellText(cell)}`);
this.refreshHighlight();
return true;
}

/** Make a cell the one the block-state panel shows, as if the pointer were over it. */
private pointAt(pos: Vec3): void {
this.inspected = pos;
Expand Down
Loading
Loading