Skip to content

Commit 07f81af

Browse files
committed
Add Sprite Creator canvas grid modes
1 parent 178646a commit 07f81af

7 files changed

Lines changed: 378 additions & 106 deletions

File tree

assets/theme-v2/css/gamefoundrystudio.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,48 @@ body.tool-focus-mode .tool-column:last-of-type {
11531153
grid-row: 1 / span 2
11541154
}
11551155

1156+
.sprite-canvas-shell {
1157+
display: flex;
1158+
justify-content: center;
1159+
padding: 16px;
1160+
border: 1px solid var(--line);
1161+
border-radius: var(--radius-md);
1162+
background: var(--panel-soft)
1163+
}
1164+
1165+
.sprite-canvas-grid {
1166+
--sprite-grid-size: 16;
1167+
display: grid;
1168+
grid-template-columns: repeat(var(--sprite-grid-size), minmax(0, 1fr));
1169+
width: min(100%, 520px);
1170+
aspect-ratio: 1;
1171+
border: 1px solid var(--line);
1172+
background: var(--panel)
1173+
}
1174+
1175+
.sprite-canvas-grid[data-sprites-grid-size="16"] {
1176+
--sprite-grid-size: 16
1177+
}
1178+
1179+
.sprite-canvas-grid[data-sprites-grid-size="32"] {
1180+
--sprite-grid-size: 32
1181+
}
1182+
1183+
.sprite-canvas-cell {
1184+
min-width: 0;
1185+
min-height: 0;
1186+
padding: 0;
1187+
border: 0;
1188+
border-right: 1px solid var(--line);
1189+
border-bottom: 1px solid var(--line);
1190+
background: var(--card-background);
1191+
cursor: default
1192+
}
1193+
1194+
.sprite-canvas-cell:disabled {
1195+
opacity: 1
1196+
}
1197+
11561198
@media(max-width:980px) {
11571199

11581200
.grid.cols-4,

assets/toolbox/sprites/js/index.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const DEFAULT_GRID_SIZE = 16;
2+
const SUPPORTED_GRID_SIZES = Object.freeze([16, 32]);
3+
4+
function gridLabel(size) {
5+
return `Sprite Creator ${size} by ${size} pixel canvas`;
6+
}
7+
8+
function buttonForSize(size) {
9+
return document.querySelector(`[data-sprites-grid-size="${size}"]`);
10+
}
11+
12+
function setGridSize(size) {
13+
const grid = document.querySelector("[data-sprites-pixel-grid]");
14+
const status = document.querySelector("[data-sprites-grid-status]");
15+
if (!grid || !SUPPORTED_GRID_SIZES.includes(size)) {
16+
return;
17+
}
18+
19+
grid.replaceChildren();
20+
grid.dataset.spritesGridSize = String(size);
21+
grid.setAttribute("aria-label", gridLabel(size));
22+
23+
for (let index = 0; index < size * size; index += 1) {
24+
const row = Math.floor(index / size) + 1;
25+
const column = (index % size) + 1;
26+
const cell = document.createElement("button");
27+
cell.className = "sprite-canvas-cell";
28+
cell.type = "button";
29+
cell.disabled = true;
30+
cell.setAttribute("role", "gridcell");
31+
cell.setAttribute("aria-label", `Pixel row ${row}, column ${column}`);
32+
cell.dataset.spritePixelRow = String(row);
33+
cell.dataset.spritePixelColumn = String(column);
34+
grid.append(cell);
35+
}
36+
37+
document.querySelectorAll("[data-sprites-grid-size]").forEach((button) => {
38+
const isActive = button.dataset.spritesGridSize === String(size);
39+
button.classList.toggle("primary", isActive);
40+
button.setAttribute("aria-pressed", String(isActive));
41+
});
42+
43+
if (status) {
44+
status.textContent = `Canvas display mode: ${size}x${size}. No pixel data is saved.`;
45+
}
46+
}
47+
48+
function wireGridControls() {
49+
SUPPORTED_GRID_SIZES.forEach((size) => {
50+
const button = buttonForSize(size);
51+
if (!button) {
52+
return;
53+
}
54+
button.addEventListener("click", () => setGridSize(size));
55+
});
56+
}
57+
58+
wireGridControls();
59+
setGridSize(DEFAULT_GRID_SIZE);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ test("Sprite Creator shell loads with visible tool, canvas, details, and status
233233
}
234234
await expect(page.locator("main")).toContainText("Toolbar placeholders only");
235235
await expect(page.locator("[data-sprites-pixel-grid]")).toBeVisible();
236+
await expect(page.locator("[data-sprites-pixel-grid] [role='gridcell']")).toHaveCount(256);
237+
await expect(page.locator("[data-sprites-grid-status]")).toContainText("Canvas display mode: 16x16");
238+
await page.getByRole("button", { name: "32x32" }).click();
239+
await expect(page.locator("[data-sprites-pixel-grid]")).toHaveAttribute("aria-label", "Sprite Creator 32 by 32 pixel canvas");
240+
await expect(page.locator("[data-sprites-pixel-grid] [role='gridcell']")).toHaveCount(1024);
241+
await expect(page.locator("[data-sprites-grid-status]")).toContainText("Canvas display mode: 32x32");
242+
await expect(page.getByRole("button", { name: "32x32" })).toHaveAttribute("aria-pressed", "true");
236243
await expect(page.locator("[data-sprites-shell-status]")).toContainText("Shell ready");
237244
await expect(page.locator("main")).toContainText("Palette/Colors keys only");
238245
await expect(page.locator("main")).not.toContainText(/Not implemented yet|future rebuild work|Static wireframe only|Plan sprite creation/i);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# PR_26179_CHARLIE_024-sprites-canvas-grid
2+
3+
Team: CHARLIE
4+
Workflow: stacked feature workflow
5+
Base branch: PR_26179_CHARLIE_023-sprites-toolbar-placeholders
6+
Canonical ZIP path: dev/workspace/zip/PR_26179_CHARLIE_024-sprites-canvas-grid_delta.zip
7+
8+
## Summary
9+
10+
Added a visible Sprite Creator pixel canvas grid with 16x16 and 32x32 display modes. The grid is rendered by external JavaScript and styled through Theme V2 CSS. This PR adds display behavior only; no persistence, drawing, API, DB, schema, or authoritative browser product data was added.
11+
12+
## Branch Validation
13+
14+
PASS
15+
16+
- Current branch: PR_26179_CHARLIE_024-sprites-canvas-grid
17+
- Based on: PR_26179_CHARLIE_023-sprites-toolbar-placeholders
18+
- No start_of_day files changed
19+
- No DB/API/schema files changed
20+
- No stale PR #219-#228 code copied
21+
22+
## Requirement Checklist
23+
24+
| Requirement | Status | Notes |
25+
| --- | --- | --- |
26+
| Add visible pixel canvas grid | PASS | Grid renders on page load. |
27+
| Support 16x16 display mode | PASS | Default grid has 256 cells. |
28+
| Support 32x32 display mode | PASS | Toggle renders 1024 cells. |
29+
| No persistence | PASS | No storage/API/database writes. |
30+
| No drawing behavior | PASS | Pixel cells are disabled display cells. |
31+
| Theme V2 compliant | PASS | CSS added to shared Theme V2 stylesheet; no inline styles. |
32+
| No DB/API/schema changes | PASS | Only shell, CSS, JS, test, reports changed. |
33+
34+
## Validation Lane Report
35+
36+
Commands:
37+
38+
```text
39+
node --check assets/toolbox/sprites/js/index.js
40+
node --check dev/tests/playwright/tools/SpritesToolShell.spec.mjs
41+
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
42+
rg --pcre2 -n -i "<style|style=|<script(?![^>]+src=)|on(click|change|submit|input|load|error)=|imageDataUrl|local-mem|fake-login|MEM DB" toolbox/sprites/index.html assets/toolbox/sprites/js/index.js dev/tests/playwright/tools/SpritesToolShell.spec.mjs
43+
npx playwright test dev/tests/playwright/tools/SpritesToolShell.spec.mjs --workers=1 --reporter=list --output=<temp>
44+
```
45+
46+
Results:
47+
48+
- Node syntax checks: PASS
49+
- `git diff --check`: PASS
50+
- Guard scan: PASS, no matches
51+
- Targeted Playwright: PASS, 1 test passed
52+
53+
## Manual Validation Notes
54+
55+
1. Open `/toolbox/sprites/index.html` from the stacked branch.
56+
2. Confirm the Pixel Grid renders in 16x16 mode by default.
57+
3. Click 32x32 and confirm the grid updates and the status text changes.
58+
4. Confirm no pixel drawing or save/load behavior exists yet.
59+
60+
## ZIP Path
61+
62+
`dev/workspace/zip/PR_26179_CHARLIE_024-sprites-canvas-grid_delta.zip`
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
toolbox/sprites/index.html
2+
assets/toolbox/sprites/js/index.js
3+
assets/theme-v2/css/gamefoundrystudio.css
24
dev/tests/playwright/tools/SpritesToolShell.spec.mjs
3-
docs_build/dev/reports/PR_26179_CHARLIE_023-sprites-toolbar-placeholders.md
5+
docs_build/dev/reports/PR_26179_CHARLIE_024-sprites-canvas-grid.md
46
docs_build/dev/reports/codex_changed_files.txt
57
docs_build/dev/reports/codex_review.diff

0 commit comments

Comments
 (0)