Implement tokens on maps #38
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On the dragonroll frontend (and backend), can you add that you can add actors to maps by dragging them and then make them tokens that you can move through the grid?
I'll start by exploring the map-related code to understand the existing patterns.
Now let me look at how actors are surfaced in the frontend, and how the sidebar works.
Now I'll implement. Starting with the backend:
Now the token routes in the backend:
Now the main work in
MapViewerPane.vue:Now update the existing pin test's module stubs (map.js now requires the Actor model) and add a token test file:
Let me review the full diff and update the docs that describe these routes:
Implementation complete for #38 — Implement tokens on maps. Here's what landed:
Backend
backend/src/models/Map.js— newtokens: [{ actor→Actor, x, y }]array next topins. Coordinates are image pixels of the token's centre, so a token keeps its cell whatever the zoom or grid settings are.backend/src/routes/map.js— two routes in the existing pin style (same envelope, ownership check, same-campaign rule):POST /map/place-token{id, actor, x, y}— only an actor of the map's own campaign can stand on it; an actor is placed once per map, so placing it again moves the token. Coordinates are snapped to the centre of the grid cell (gridSize/offsetX/offsetY).POST /map/remove-token{id, token}— removes by the token's own_id, keeping the others.backend/src/routes/actor.js— deleting an actor pulls its tokens off every map, exactly like a deleted note pulls its pins.Frontend
app/services/MapTokens.js(new) — the pure rules: the actor drag payload (application/x-dragonroll-actor, so a note or file dropped on a map is never taken for an actor),CellCentre(snapping, identical to the route so a token does not jump when a drag lands),MoveByCells(whole-cell steps) andTokenSize(a token covers its cell, never smaller than an icon).app/components/partials/ContentSidebar.vue— actor rows are draggable (:titlesays so), carrying the actor id.app/components/viewer/map/MapViewerPane.vue— drops an actor on the visible cell, shows a hint while carrying one, and draws tokens in screen space sized by their cell with the actor portrait (initials when there is none or it fails to load). A token drags with the pointer, snapping cell to cell, saving once per move instead of once per mouse move; arrow keys walk a focused token, Delete takes it off, and right-click offers Open character sheet / Remove token. The sharedupdateMaphelper keeps the sidebar entry and the anchored map in step (it now serves pins and tokens alike). Works in both the anchored pane and the detachedmap_viewerwindow.campaigns.map.tokensadded to en, es and ca;AGENTS.mdupdated for the new model field, routes, service and behaviour.Tests
tests/map-tokens.test.js(new, 25 checks): snapping and offsets in the routes, ownership, same-campaign actors, one-token-per-actor, removal, the actor-delete pull, the service helpers, and viewer/sidebar wiring — including that the viewer and the route agree on where a token stands.npm test→ 99 tests, 99 pass, 0 fail (I also added theActormodel stub thattests/map-pins.test.jsneeds now thatmap.jsrequires it). The changed SFCs compile with@vue/compiler-sfcand the three locale files parse as JSON; I did not run the dev server (no dependencies installed in this tree), so the drag flow itself is not exercised end-to-end.One known edge I left alone: actors removed by the Foundry sync prune (
routes/foundry-link.js) can leave a token that renders as a placeholder until right-click → Remove token; cleaning that up means touching the sync router, which this change otherwise does not. Say the word if you want that included.Implementation is ready for review: #40