Add map support #10

Closed
opened 2026-10-14 09:49:40 +00:00 by Syndria98 · 4 comments
Owner

Can you make on dragonroll, on the sidebar, add a button that also lists maps? For creating a map, you should be able to upload a photo, set its grid size, offset and scale. When a map is selected from the sidebar, you should be able to view it, pan by dragging the mouse and zoom in and out with the mouse wheel.

Can you make on dragonroll, on the sidebar, add a button that also lists maps? For creating a map, you should be able to upload a photo, set its grid size, offset and scale. When a map is selected from the sidebar, you should be able to view it, pan by dragging the mouse and zoom in and out with the mouse wheel.
Syndria98 added the ai-ready label 2026-10-14 09:49:40 +00:00
Collaborator

Now let me write the backend pieces.

Now let me write the backend pieces.
Collaborator

Now the sidebar:

Now the sidebar:
Collaborator

Implementation complete. Here's what I did for Syndria98/dragonroll#10 — Add map support.

Backend

backend/src/models/Map.js (new) — name*, image (filename in src/uploads, served at /api/public/<file>), gridSize (cell size in image px, default 50), offsetX/offsetY (grid origin in image px, default 0), scale (distance one cell stands for, default 5), campaign*, date.

backend/src/routes/map.js (new) — same envelope + duplicated userOwnsCampaign style as actor.js/item.js:

  • GET /api/map/list?campaign= → {status:'ok',maps}
  • POST /api/map/create — multipart (image field) or JSON, grid values parsed with a toNumber(value, fallback) helper (multipart fields arrive as strings)
  • POST /api/map/update — partial, ownership checked; an image file replaces the photo, JSON-only bodies keep it
  • POST /api/map/delete — ownership checked

backend/src/index.js — mounted /api/map after the JWT guard (and dropped the now-real // app.use('/maps', …) line from the commented block).

Frontend

  • ContentSidebar.vue — new map button (/icons/iconoir/regular/map.svg) + maps section that lists maps (name, grid summary, hint when no image). Click / Enter opens the viewer; right-click gives Edit / Delete. The existing actor/item entry plumbing was generalised into entryEntityType() + an entryLists lookup instead of entityType === 'actor' ? actors : items ternaries, so all three entity types share one code path.
  • CreateMapWindow.vue (new, window create_map) — name, photo picker with preview, grid size, offset X/Y and scale. Creates and edits (pass entry); posts FormData, then emits campaign-entry-created / campaign-entry-updated with entityType: 'map' so the sidebar and any open viewer update.
  • MapViewerWindow.vue (new, window map_viewer) — image at natural size in a transformed layer: drag to pan (pointer events + capture), mouse wheel to zoom towards the cursor, plus zoom in/out buttons, zoom %, fit-to-window, grid toggle and an edit shortcut. The grid overlay is drawn in screen space from gridSize/offsetX/offsetY (lines stay 1px at any zoom, themed with var(--color-link)), and it re-fits when a new photo lands.
  • WindowDefinitions.js — registered create_map and map_viewer.
  • i18n — new strings in campaigns.json (sections.maps, states.empty-maps, a map block) and windows.json (create-map, map-viewer) for en / es / ca; verified every campaigns.* / windows.* key used by the new and touched components resolves in all three locales.
  • AGENTS.md — documented the Map model, the map routes and the data-model entry.

Verification

  • npm --prefix frontend run build → succeeds (both new windows emitted as chunks; only the repo's pre-existing warnings).
  • Backend: ran the real Express app against an in-memory MongoDB and exercised the API end to end (script kept outside the tree at /tmp/drtest/verify-maps.js, since the repo has no test harness and adding one would mean new dev dependencies). All 14 checks passed: create with photo + grid values, defaults when grid fields are omitted, errors.missing-data without a campaign, list ordering, JSON update keeping the image, multipart update replacing the photo and keeping the grid, /api/public/<file> serving the upload, delete, plus cross-user list/edit/delete rejected as unauthorized and anonymous requests getting 401.
  • Not run: no click-through of the pan/zoom UI in a browser (no screenshots per instructions) — the transform/zoom math is screen = pan + zoom × imagePoint, with wheel zoom keeping the point under the cursor fixed.

Nothing committed or pushed, as requested.

Implementation complete. Here's what I did for **Syndria98/dragonroll#10 — Add map support**. ## Backend **`backend/src/models/Map.js`** (new) — `name*`, `image` (filename in `src/uploads`, served at `/api/public/<file>`), `gridSize` (cell size in image px, default 50), `offsetX`/`offsetY` (grid origin in image px, default 0), `scale` (distance one cell stands for, default 5), `campaign*`, `date`. **`backend/src/routes/map.js`** (new) — same envelope + duplicated `userOwnsCampaign` style as `actor.js`/`item.js`: - `GET /api/map/list?campaign=` → `{status:'ok',maps}` - `POST /api/map/create` — multipart (`image` field) **or** JSON, grid values parsed with a `toNumber(value, fallback)` helper (multipart fields arrive as strings) - `POST /api/map/update` — partial, ownership checked; an `image` file replaces the photo, JSON-only bodies keep it - `POST /api/map/delete` — ownership checked **`backend/src/index.js`** — mounted `/api/map` after the JWT guard (and dropped the now-real `// app.use('/maps', …)` line from the commented block). ## Frontend - **`ContentSidebar.vue`** — new map button (`/icons/iconoir/regular/map.svg`) + `maps` section that lists maps (name, grid summary, hint when no image). Click / Enter opens the viewer; right-click gives Edit / Delete. The existing actor/item entry plumbing was generalised into `entryEntityType()` + an `entryLists` lookup instead of `entityType === 'actor' ? actors : items` ternaries, so all three entity types share one code path. - **`CreateMapWindow.vue`** (new, window `create_map`) — name, photo picker with preview, grid size, offset X/Y and scale. Creates and edits (pass `entry`); posts `FormData`, then emits `campaign-entry-created` / `campaign-entry-updated` with `entityType: 'map'` so the sidebar and any open viewer update. - **`MapViewerWindow.vue`** (new, window `map_viewer`) — image at natural size in a transformed layer: **drag to pan** (pointer events + capture), **mouse wheel to zoom towards the cursor**, plus zoom in/out buttons, zoom %, fit-to-window, grid toggle and an edit shortcut. The grid overlay is drawn in screen space from `gridSize`/`offsetX`/`offsetY` (lines stay 1px at any zoom, themed with `var(--color-link)`), and it re-fits when a new photo lands. - **`WindowDefinitions.js`** — registered `create_map` and `map_viewer`. - **i18n** — new strings in `campaigns.json` (`sections.maps`, `states.empty-maps`, a `map` block) and `windows.json` (`create-map`, `map-viewer`) for **en / es / ca**; verified every `campaigns.*` / `windows.*` key used by the new and touched components resolves in all three locales. - **`AGENTS.md`** — documented the `Map` model, the map routes and the data-model entry. ## Verification - `npm --prefix frontend run build` → **succeeds** (both new windows emitted as chunks; only the repo's pre-existing warnings). - Backend: ran the **real Express app against an in-memory MongoDB** and exercised the API end to end (script kept outside the tree at `/tmp/drtest/verify-maps.js`, since the repo has no test harness and adding one would mean new dev dependencies). All 14 checks passed: create with photo + grid values, defaults when grid fields are omitted, `errors.missing-data` without a campaign, list ordering, JSON update keeping the image, multipart update replacing the photo and keeping the grid, `/api/public/<file>` serving the upload, delete, plus cross-user list/edit/delete rejected as `unauthorized` and anonymous requests getting 401. - Not run: no click-through of the pan/zoom UI in a browser (no screenshots per instructions) — the transform/zoom math is `screen = pan + zoom × imagePoint`, with wheel zoom keeping the point under the cursor fixed. Nothing committed or pushed, as requested.
Collaborator

Implementation is ready for review: #11

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/11
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#10