Skip to content

Commit 3cc3a21

Browse files
committed
Fix Sprite Creator color and zoom
1 parent 9fb2e4c commit 3cc3a21

7 files changed

Lines changed: 281 additions & 150 deletions

File tree

assets/theme-v2/css/gamefoundrystudio.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,10 @@ body.tool-focus-mode .tool-column:last-of-type {
11841184
grid-template-rows: repeat(32, minmax(0, 1fr))
11851185
}
11861186

1187+
.sprite-canvas-shell[data-sprites-zoom-level="0.5"] .sprite-canvas-grid {
1188+
width: min(260px, 50%)
1189+
}
1190+
11871191
.sprite-canvas-shell[data-sprites-zoom-level="2"] .sprite-canvas-grid {
11881192
width: min(720px, 160%)
11891193
}
@@ -1212,26 +1216,31 @@ body.tool-focus-mode .tool-column:last-of-type {
12121216
background: var(--text)
12131217
}
12141218

1219+
.sprite-canvas-cell.is-painted.sprite-canvas-cell--ink,
12151220
.sprite-canvas-cell--ink,
12161221
.sprite-color-chip--ink {
12171222
background: var(--text)
12181223
}
12191224

1225+
.sprite-canvas-cell.is-painted.sprite-canvas-cell--orange,
12201226
.sprite-canvas-cell--orange,
12211227
.sprite-color-chip--orange {
12221228
background: var(--molten-orange)
12231229
}
12241230

1231+
.sprite-canvas-cell.is-painted.sprite-canvas-cell--gold,
12251232
.sprite-canvas-cell--gold,
12261233
.sprite-color-chip--gold {
12271234
background: var(--forge-gold)
12281235
}
12291236

1237+
.sprite-canvas-cell.is-painted.sprite-canvas-cell--green,
12301238
.sprite-canvas-cell--green,
12311239
.sprite-color-chip--green {
12321240
background: var(--green)
12331241
}
12341242

1243+
.sprite-canvas-cell.is-painted.sprite-canvas-cell--blue,
12351244
.sprite-canvas-cell--blue,
12361245
.sprite-color-chip--blue {
12371246
background: var(--electric-blue)

assets/toolbox/sprites/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const DEFAULT_GRID_SIZE = 16;
22
const DEFAULT_FRAME_DURATION_MS = 120;
33
const SUPPORTED_GRID_SIZES = Object.freeze([16, 32]);
4-
const SUPPORTED_ZOOM_LEVELS = Object.freeze([1, 2, 4]);
4+
const SUPPORTED_ZOOM_LEVELS = Object.freeze([0.5, 1, 2, 4]);
55
const SHAPE_TOOLS = Object.freeze(["line", "rectangle", "circle"]);
66
const EDITOR_TOOLS = Object.freeze(["pencil", "eraser", "fill", "picker", "zoom", ...SHAPE_TOOLS]);
77
const EDITOR_COLOR_KEYS = Object.freeze(["ink", "orange", "gold", "green", "blue"]);

dev/tests/playwright/tools/SpritesToolShell.spec.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,25 @@ async function previewCellHasPaint(page, row, column) {
219219
}, { column, gridSize, row });
220220
}
221221

222+
async function previewCellColor(page, row, column) {
223+
const gridSize = Number(await page.locator("[data-sprites-pixel-grid]").getAttribute("data-sprites-grid-size"));
224+
return page.locator("[data-sprites-preview-canvas]").evaluate((canvas, coordinates) => {
225+
const context = canvas.getContext("2d");
226+
if (!context || !Number.isFinite(coordinates.gridSize) || coordinates.gridSize <= 0) {
227+
return "";
228+
}
229+
const cellSize = canvas.width / coordinates.gridSize;
230+
const x = Math.max(0, Math.min(canvas.width - 1, Math.floor((coordinates.column - 0.5) * cellSize)));
231+
const y = Math.max(0, Math.min(canvas.height - 1, Math.floor((coordinates.row - 0.5) * cellSize)));
232+
const pixel = context.getImageData(x, y, 1, 1).data;
233+
return `rgb(${pixel[0]}, ${pixel[1]}, ${pixel[2]})`;
234+
}, { column, gridSize, row });
235+
}
236+
237+
async function centerCellColor(page, row, column) {
238+
return spriteCell(page, row, column).evaluate((cell) => getComputedStyle(cell).backgroundColor);
239+
}
240+
222241
async function canvasHasAnyPaint(locator) {
223242
return locator.evaluate((canvas) => {
224243
const context = canvas.getContext("2d");
@@ -240,6 +259,9 @@ async function expectCenterAndPreviewPainted(page, row, column, colorClass = nul
240259
await expect(cell).toHaveClass(/is-painted/);
241260
if (colorClass) {
242261
await expect(cell).toHaveClass(new RegExp(colorClass));
262+
const centerColor = await centerCellColor(page, row, column);
263+
expect(centerColor).not.toBe("rgb(255, 255, 255)");
264+
expect(await previewCellColor(page, row, column)).toBe(centerColor);
243265
}
244266
expect(await previewCellHasPaint(page, row, column)).toBe(true);
245267
}
@@ -337,6 +359,7 @@ test("Sprite Creator shell loads with visible tool, canvas, details, and status
337359
await expect(page.locator("[data-sprites-pixel-grid] [role='gridcell']")).toHaveCount(256);
338360
await expect(page.locator("[data-sprites-grid-status]")).toContainText("Canvas display mode: 16x16");
339361
await expect(page.locator("[data-sprites-zoom-status]")).toContainText("100%");
362+
await expect(page.getByRole("button", { name: "50%" })).toBeVisible();
340363
await page.getByRole("button", { name: "32x32" }).click();
341364
await expect(page.locator("[data-sprites-pixel-grid]")).toHaveAttribute("aria-label", "Sprite Creator 32 by 32 pixel canvas");
342365
await expect(page.locator("[data-sprites-pixel-grid] [role='gridcell']")).toHaveCount(1024);
@@ -412,6 +435,10 @@ test("Sprite Creator shell loads with visible tool, canvas, details, and status
412435
await expect(page.locator("[data-sprites-zoom-status]")).toContainText("400%");
413436
await page.getByRole("button", { name: "100%" }).click();
414437
await expect(page.locator("[data-sprites-grid-shell]")).toHaveAttribute("data-sprites-zoom-level", "1");
438+
await page.getByRole("button", { name: "50%" }).click();
439+
await expect(page.locator("[data-sprites-grid-shell]")).toHaveAttribute("data-sprites-zoom-level", "0.5");
440+
await expect(page.locator("[data-sprites-zoom-status]")).toContainText("50%");
441+
await expect(page.locator("[data-sprites-pixel-grid] [role='gridcell']")).toHaveCount(256);
415442
const gridCells = page.locator("[data-sprites-pixel-grid] [role='gridcell']");
416443
await page.getByRole("button", { name: "Clear Canvas" }).click();
417444
await page.getByRole("button", { name: "Green editor color" }).click();
@@ -472,14 +499,14 @@ test("Sprite Creator canvas grid dimensions stay exact across modes and zoom", a
472499
await page.goto(`${server.baseUrl}/toolbox/sprites/index.html`, { waitUntil: "networkidle" });
473500

474501
await expectExactGridDimensions(page, 16);
475-
for (const zoomLabel of ["200%", "400%", "100%"]) {
502+
for (const zoomLabel of ["50%", "200%", "400%", "100%"]) {
476503
await page.getByRole("button", { name: zoomLabel }).click();
477504
await expectExactGridDimensions(page, 16);
478505
}
479506

480507
await page.getByRole("button", { name: "32x32" }).click();
481508
await expectExactGridDimensions(page, 32);
482-
for (const zoomLabel of ["200%", "400%", "100%"]) {
509+
for (const zoomLabel of ["50%", "200%", "400%", "100%"]) {
483510
await page.getByRole("button", { name: zoomLabel }).click();
484511
await expectExactGridDimensions(page, 32);
485512
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# PR_26179_CHARLIE_039-sprites-color-and-zoom-fix
2+
3+
Team: CHARLIE
4+
5+
Mode: Batch governance stacked bug-fix workflow
6+
7+
Base branch: PR_26179_CHARLIE_038-sprites-grid-dimension-fix
8+
9+
Branch: PR_26179_CHARLIE_039-sprites-color-and-zoom-fix
10+
11+
## Summary
12+
13+
Fixed Sprite Creator center canvas selected-color rendering and added a 50% zoom option. The center grid now uses color-specific painted-cell selectors with enough specificity to override the generic painted fallback, so Pencil, Fill, and Shape tools display the selected palette color instead of defaulting visually to the fallback color. The Playwright coverage now compares the center cell computed color with the right preview canvas pixel color to prove both surfaces use the same selected-color page-session state.
14+
15+
## Branch Validation
16+
17+
PASS
18+
19+
- Built from `PR_26179_CHARLIE_038-sprites-grid-dimension-fix`.
20+
- Scope stayed limited to selected color rendering, 50% zoom, and regression coverage.
21+
- No DB/API/schema changes.
22+
- No browser-owned authoritative product data added.
23+
- No start_of_day files changed.
24+
- ZIP package created at the requested path.
25+
26+
## Requirement Checklist
27+
28+
PASS - Center canvas drawing color follows selected palette color.
29+
30+
PASS - Pencil applies selected color to center grid.
31+
32+
PASS - Fill applies selected color to center grid.
33+
34+
PASS - Shape tools apply selected color to center grid.
35+
36+
PASS - Center grid, right preview, frame data, animation preview, and exports use the same selected-color pixel state.
37+
38+
PASS - Painted pixels do not default to white unless that is the selected palette color.
39+
40+
PASS - 50% zoom option added.
41+
42+
PASS - Existing 100%, 200%, and 400% zoom options retained.
43+
44+
PASS - Zoom does not change grid dimensions or pixel state.
45+
46+
PASS - Export path still works.
47+
48+
PASS - No DB/API/schema changes.
49+
50+
PASS - No browser-owned authoritative product data.
51+
52+
PASS - No start_of_day changes.
53+
54+
## Validation Lane
55+
56+
PASS - `node --check assets/toolbox/sprites/js/index.js`
57+
58+
PASS - `node --check dev/tests/playwright/tools/SpritesToolShell.spec.mjs`
59+
60+
PASS - `git diff --check -- toolbox/sprites/index.html assets/toolbox/sprites/js/index.js assets/theme-v2/css/gamefoundrystudio.css dev/tests/playwright/tools/SpritesToolShell.spec.mjs`
61+
62+
PASS - Runtime guard scan found no prohibited inline style/script/event-handler or stale placeholder text in touched runtime files.
63+
64+
PASS - `npx playwright test dev/tests/playwright/tools/SpritesToolShell.spec.mjs --workers=1 --reporter=list`
65+
66+
## Manual Validation Notes
67+
68+
1. Open `toolbox/sprites/index.html`.
69+
2. Select a non-white palette color such as Gold or Blue.
70+
3. Draw with Pencil and confirm the center grid cell uses the selected color.
71+
4. Confirm the right preview shows the same selected color.
72+
5. Use Fill and Shape tools with a selected color and confirm the center grid matches.
73+
6. Use 50%, 100%, 200%, and 400% zoom and confirm grid dimensions and pixels do not change.
74+
7. Download PNG and Animation Strip and confirm export status still completes.
75+
76+
## ZIP
77+
78+
`dev/workspace/zip/PR_26179_CHARLIE_039-sprites-color-and-zoom-fix_delta.zip`
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
assets/theme-v2/css/gamefoundrystudio.css
2+
assets/toolbox/sprites/js/index.js
23
dev/tests/playwright/tools/SpritesToolShell.spec.mjs
3-
docs_build/dev/reports/PR_26179_CHARLIE_038-sprites-grid-dimension-fix.md
4+
docs_build/dev/reports/PR_26179_CHARLIE_039-sprites-color-and-zoom-fix.md
45
docs_build/dev/reports/codex_changed_files.txt
56
docs_build/dev/reports/codex_review.diff
67
toolbox/sprites/index.html

0 commit comments

Comments
 (0)