feat(scene): keep map tokens with preview rotation

When previewRotationDeg changes, remap non-player, NPC and trap
markers (plus live session token overrides) so they stay on the art.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-08-11 12:29:20 +08:00
parent 7362a36fe5
commit 46bec1a86a
11 changed files with 312 additions and 1 deletions
+20
View File
@@ -20,6 +20,7 @@ import type {
} from '../../../shared/types';
import { getDndApi } from '../../shared/dndApi';
import { invalidateAssetUrlCache } from '../../shared/useAssetImageUrl';
import { applyPreviewRotationToSceneMarkers } from '../../../shared/types/scenePreviewRotation';
type ProjectSummary = { id: ProjectId; name: string; updatedAt: string; fileName: string };
@@ -600,6 +601,25 @@ export function useProjectState(licenseActive: boolean, opts?: ProjectStateOpts)
...(patch.media ? { media: { ...scene.media, ...patch.media } } : null),
layout: patch.layout ? { ...scene.layout, ...patch.layout } : scene.layout,
};
if (patch.previewRotationDeg !== undefined) {
const remapped = applyPreviewRotationToSceneMarkers(
{
previewRotationDeg: scene.previewRotationDeg ?? 0,
tokens: scene.tokens ?? [],
npcTokens: scene.npcTokens ?? [],
traps: scene.traps ?? [],
},
patch.previewRotationDeg,
{
tokensProvided: patch.tokens !== undefined,
npcTokensProvided: patch.npcTokens !== undefined,
trapsProvided: patch.traps !== undefined,
},
);
if (patch.tokens === undefined) next.tokens = remapped.tokens;
if (patch.npcTokens === undefined) next.npcTokens = remapped.npcTokens;
if (patch.traps === undefined) next.traps = remapped.traps;
}
const scenes = { ...p.scenes, [sceneId]: next };
const project: Project = { ...p, scenes };
return { ...s, project };