BlueGit

timfa questward

Fix creation clothing preview alignment and clear world on leave.

Pivot-align wider equip sprites in the character preview, and wipe local entities when returning to the menu so a ghost character does not linger.

timfa Tim Falken · pushed by timfa

Authored 2026-08-27 · 2 months ago

Hash
4cfa1b02ff6d5cef3668c35ff33fdceb1886f9f8
Parent
08fdf3cc
5 files changed +41 −15
client/index.html +1 −1
@@ -567,7 +567,7 @@
567 567 </section>
568 568 <section class="create-pane" data-create-pane="clothing" hidden>
569 569 <div id="create-clothing" class="create-clothing">
570 <canvas id="create-clothing-preview" data-clothing-preview width="64" height="96" aria-label="Clothing preview"></canvas>
570 <canvas id="create-clothing-preview" data-clothing-preview width="80" height="96" aria-label="Clothing preview"></canvas>
571 571 <div class="create-clothing-fields">
572 572 <label>Legs
573 573 <select data-create-legs></select>
@@ -567,7 +567,7 @@
567 </section>
567 </section>
568 <section class="create-pane" data-create-pane="clothing" hidden>
568 <section class="create-pane" data-create-pane="clothing" hidden>
569 <div id="create-clothing" class="create-clothing">
569 <div id="create-clothing" class="create-clothing">
570 <canvas id="create-clothing-preview" data-clothing-preview width="64" height="96" aria-label="Clothing preview"></canvas>
570 <canvas id="create-clothing-preview" data-clothing-preview width="80" height="96" aria-label="Clothing preview"></canvas>
571 <div class="create-clothing-fields">
571 <div class="create-clothing-fields">
572 <label>Legs
572 <label>Legs
573 <select data-create-legs></select>
573 <select data-create-legs></select>
client/src/play/characterPreview.js +22 −5
@@ -1,9 +1,12 @@
1 1 import { applyMagentaTintToImageData, applyDualChannelTintToImageData } from "/shared/render/tint.js";
2 2 import { layersForHairPreview } from "/shared/appearance/hair.js";
3 import { PIVOT_FROM_BOTTOM_PX } from "/shared/protocol/constants.js";
3 4
4 5 /**
5 6 * Draw stacked character layers (body + hair + optional gear) onto a canvas.
6 7 * Magenta hair/gear tints applied in 2D for UI previews.
8 * Layers may differ in size (e.g. body 16×24, shirt equip 20×24); they share
9 * the world pivot (horizontal centre, `PIVOT_FROM_BOTTOM_PX` from the bottom).
7 10 */
8 11 export async function paintCharacterPreview (canvas, {
9 12 sex,
@@ -28,17 +31,31 @@ export async function paintCharacterPreview (canvas, {
28 31 }
29 32 if (!images.length)
30 33 { return; }
31 const w = images[0].img.naturalWidth || images[0].img.width;
32 const h = images[0].img.naturalHeight || images[0].img.height;
33 canvas.width = w * scale;
34 canvas.height = h * scale;
34
35 let maxW = 1;
36 let maxH = 1;
37 for (const entry of images)
38 {
39 maxW = Math.max(maxW, entry.img.naturalWidth || entry.img.width || 1);
40 maxH = Math.max(maxH, entry.img.naturalHeight || entry.img.height || 1);
41 }
42
43 canvas.width = maxW * scale;
44 canvas.height = maxH * scale;
35 45 const ctx = canvas.getContext("2d");
36 46 ctx.imageSmoothingEnabled = false;
37 47 ctx.clearRect(0, 0, canvas.width, canvas.height);
48
49 const pivotX = maxW * 0.5;
50 const pivotY = maxH - PIVOT_FROM_BOTTOM_PX;
38 51 for (const entry of images)
39 52 {
40 53 const source = entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img;
41 ctx.drawImage(source, 0, 0, canvas.width, canvas.height);
54 const sw = source.naturalWidth || source.width || 1;
55 const sh = source.naturalHeight || source.height || 1;
56 const ox = (pivotX - sw * 0.5) * scale;
57 const oy = (pivotY - (sh - PIVOT_FROM_BOTTOM_PX)) * scale;
58 ctx.drawImage(source, ox, oy, sw * scale, sh * scale);
42 59 }
43 60 }
44 61
@@ -1,9 +1,12 @@
1import { applyMagentaTintToImageData, applyDualChannelTintToImageData } from "/shared/render/tint.js";
1import { applyMagentaTintToImageData, applyDualChannelTintToImageData } from "/shared/render/tint.js";
2import { layersForHairPreview } from "/shared/appearance/hair.js";
2import { layersForHairPreview } from "/shared/appearance/hair.js";
3import { PIVOT_FROM_BOTTOM_PX } from "/shared/protocol/constants.js";
3
4
4/**
5/**
5 * Draw stacked character layers (body + hair + optional gear) onto a canvas.
6 * Draw stacked character layers (body + hair + optional gear) onto a canvas.
6 * Magenta hair/gear tints applied in 2D for UI previews.
7 * Magenta hair/gear tints applied in 2D for UI previews.
8 * Layers may differ in size (e.g. body 16×24, shirt equip 20×24); they share
9 * the world pivot (horizontal centre, `PIVOT_FROM_BOTTOM_PX` from the bottom).
7 */
10 */
8export async function paintCharacterPreview (canvas, {
11export async function paintCharacterPreview (canvas, {
9 sex,
12 sex,
@@ -28,17 +31,31 @@ export async function paintCharacterPreview (canvas, {
28 }
31 }
29 if (!images.length)
32 if (!images.length)
30 { return; }
33 { return; }
31 const w = images[0].img.naturalWidth || images[0].img.width;
34
32 const h = images[0].img.naturalHeight || images[0].img.height;
35 let maxW = 1;
33 canvas.width = w * scale;
36 let maxH = 1;
34 canvas.height = h * scale;
37 for (const entry of images)
38 {
39 maxW = Math.max(maxW, entry.img.naturalWidth || entry.img.width || 1);
40 maxH = Math.max(maxH, entry.img.naturalHeight || entry.img.height || 1);
41 }
42
43 canvas.width = maxW * scale;
44 canvas.height = maxH * scale;
35 const ctx = canvas.getContext("2d");
45 const ctx = canvas.getContext("2d");
36 ctx.imageSmoothingEnabled = false;
46 ctx.imageSmoothingEnabled = false;
37 ctx.clearRect(0, 0, canvas.width, canvas.height);
47 ctx.clearRect(0, 0, canvas.width, canvas.height);
48
49 const pivotX = maxW * 0.5;
50 const pivotY = maxH - PIVOT_FROM_BOTTOM_PX;
38 for (const entry of images)
51 for (const entry of images)
39 {
52 {
40 const source = entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img;
53 const source = entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img;
41 ctx.drawImage(source, 0, 0, canvas.width, canvas.height);
54 const sw = source.naturalWidth || source.width || 1;
55 const sh = source.naturalHeight || source.height || 1;
56 const ox = (pivotX - sw * 0.5) * scale;
57 const oy = (pivotY - (sh - PIVOT_FROM_BOTTOM_PX)) * scale;
58 ctx.drawImage(source, ox, oy, sw * scale, sh * scale);
42 }
59 }
43}
60}
44
61
client/src/play/main.js +1 −7
@@ -1525,13 +1525,7 @@ function returnToMenu (reason = "")
1525 1525 dialogueUi?.reset();
1526 1526 hideWorldTooltip();
1527 1527 if (view)
1528 {
1529 for (const key of [...(view.chunks?.keys?.() ?? [])])
1530 {
1531 const [chunkX, chunkY] = key.split(",").map(Number);
1532 view.removeChunk(chunkX, chunkY);
1533 }
1534 }
1528 { view.clearPlaySession(); }
1535 1529 overlay.hidden = false;
1536 1530 hud.hidden = true;
1537 1531 const settingsToggle = document.getElementById("settings-toggle");
@@ -1525,13 +1525,7 @@ function returnToMenu (reason = "")
1525 dialogueUi?.reset();
1525 dialogueUi?.reset();
1526 hideWorldTooltip();
1526 hideWorldTooltip();
1527 if (view)
1527 if (view)
1528 {
1528 { view.clearPlaySession(); }
1529 for (const key of [...(view.chunks?.keys?.() ?? [])])
1530 {
1531 const [chunkX, chunkY] = key.split(",").map(Number);
1532 view.removeChunk(chunkX, chunkY);
1533 }
1534 }
1535 overlay.hidden = false;
1529 overlay.hidden = false;
1536 hud.hidden = true;
1530 hud.hidden = true;
1537 const settingsToggle = document.getElementById("settings-toggle");
1531 const settingsToggle = document.getElementById("settings-toggle");
client/src/render/worldView.js +15 −0
@@ -504,6 +504,21 @@ export class WorldView
504 504 { this.despawnGroundItem(id); }
505 505 }
506 506
507 /** Full client wipe when leaving the world (menu / disconnect). Includes the local player. */
508 clearPlaySession ()
509 {
510 this.localEntityId = null;
511 for (const key of [...this.chunks.keys()])
512 {
513 const [chunkX, chunkY] = key.split(",").map(Number);
514 this.removeChunk(chunkX, chunkY);
515 }
516 for (const [id] of [...this.entities.entries()])
517 { this.despawnEntity(id); }
518 for (const [id] of [...this.groundItems.entries()])
519 { this.despawnGroundItem(id); }
520 }
521
507 522 applySnapshot (snapshot)
508 523 {
509 524 const snapDim = normalizeDimensionId(snapshot.dimensionId ?? OVERWORLD_ID);
@@ -504,6 +504,21 @@ export class WorldView
504 { this.despawnGroundItem(id); }
504 { this.despawnGroundItem(id); }
505 }
505 }
506
506
507 /** Full client wipe when leaving the world (menu / disconnect). Includes the local player. */
508 clearPlaySession ()
509 {
510 this.localEntityId = null;
511 for (const key of [...this.chunks.keys()])
512 {
513 const [chunkX, chunkY] = key.split(",").map(Number);
514 this.removeChunk(chunkX, chunkY);
515 }
516 for (const [id] of [...this.entities.entries()])
517 { this.despawnEntity(id); }
518 for (const [id] of [...this.groundItems.entries()])
519 { this.despawnGroundItem(id); }
520 }
521
507 applySnapshot (snapshot)
522 applySnapshot (snapshot)
508 {
523 {
509 const snapDim = normalizeDimensionId(snapshot.dimensionId ?? OVERWORLD_ID);
524 const snapDim = normalizeDimensionId(snapshot.dimensionId ?? OVERWORLD_ID);
client/ui/play.css +2 −2
@@ -267,12 +267,12 @@ html, body {
267 267 }
268 268 .create-clothing {
269 269 display: grid;
270 grid-template-columns: 72px 1fr;
270 grid-template-columns: 88px 1fr;
271 271 gap: 0.65rem 0.75rem;
272 272 align-items: start;
273 273 }
274 274 .create-clothing canvas {
275 width: 64px;
275 width: 80px;
276 276 height: 96px;
277 277 image-rendering: pixelated;
278 278 background: #0e1116;
@@ -267,12 +267,12 @@ html, body {
267}
267}
268.create-clothing {
268.create-clothing {
269 display: grid;
269 display: grid;
270 grid-template-columns: 72px 1fr;
270 grid-template-columns: 88px 1fr;
271 gap: 0.65rem 0.75rem;
271 gap: 0.65rem 0.75rem;
272 align-items: start;
272 align-items: start;
273}
273}
274.create-clothing canvas {
274.create-clothing canvas {
275 width: 64px;
275 width: 80px;
276 height: 96px;
276 height: 96px;
277 image-rendering: pixelated;
277 image-rendering: pixelated;
278 background: #0e1116;
278 background: #0e1116;