feat(tokens): app-local non-player tokens with session moves and UI polish

Add token library/placements, keep play-time moves for the session, lock presentation interactions, and fix export/import modal layout plus freeform trap label.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-07-27 11:04:12 +08:00
parent bdeb64e356
commit f270812219
44 changed files with 2617 additions and 341 deletions
@@ -0,0 +1,50 @@
import { useEffect, useState } from 'react';
import { ipcChannels } from '../../../shared/ipc/contracts';
import type { TokenId } from '../../../shared/types';
import { getDndApi } from '../dndApi';
const cache = new Map<string, string | null>();
export function useTokenImageUrl(tokenId: TokenId | null | undefined): string | null {
const api = getDndApi();
const [url, setUrl] = useState<string | null>(() =>
tokenId ? (cache.get(tokenId) ?? null) : null,
);
useEffect(() => {
if (!tokenId) {
setUrl(null);
return;
}
const cached = cache.get(tokenId);
if (cached !== undefined) {
setUrl(cached);
return;
}
let cancelled = false;
void api.invoke(ipcChannels.tokens.imageUrl, { id: tokenId }).then(({ url: next }) => {
cache.set(tokenId, next);
if (!cancelled) setUrl(next);
});
return () => {
cancelled = true;
};
}, [api, tokenId]);
useEffect(() => {
return api.on(ipcChannels.tokens.stateChanged, ({ tokens }) => {
for (const t of tokens) {
cache.delete(t.id);
}
if (tokenId) {
void api.invoke(ipcChannels.tokens.imageUrl, { id: tokenId }).then(({ url: next }) => {
cache.set(tokenId, next);
setUrl(next);
});
}
});
}, [api, tokenId]);
return url;
}