Files
DndGamePlayer/app/renderer/shared/tokens/useTokenPathSession.ts
T
Ivan Fontosh 1ab6ffd593 feat(tokens): animated paths for scene and NPC tokens
Add path editor window, session playback on control/presentation, and RMB controls. Fix live pose clock so motion no longer freezes after ~250ms.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-14 08:48:41 +08:00

35 lines
1015 B
TypeScript

import { useEffect, useMemo, useState } from 'react';
import { ipcChannels } from '../../../shared/ipc/contracts';
import type { TokenPathSessionEvent, TokenPathSessionState } from '../../../shared/types';
import { getDndApi } from '../dndApi';
export function useTokenPathSession(): [
TokenPathSessionState | null,
{ dispatch: (event: TokenPathSessionEvent) => Promise<void> },
] {
const api = getDndApi();
const [state, setState] = useState<TokenPathSessionState | null>(null);
useEffect(() => {
void api.invoke(ipcChannels.tokenPathSession.getState, {}).then(({ state: s }) => {
setState(s);
});
return api.on(ipcChannels.tokenPathSession.stateChanged, ({ state: s }) => {
setState(s);
});
}, [api]);
const apiWrap = useMemo(
() => ({
dispatch: async (event: TokenPathSessionEvent) => {
const res = await api.invoke(ipcChannels.tokenPathSession.dispatch, { event });
void res;
},
}),
[api],
);
return [state, apiWrap];
}