Files
Ivan Fontosh 02d73ddf81 feat: scene traps, material legends, and scene editor window
Add trap overlays with session state, material legend editor/panel, and a dedicated scene editor window wired through IPC and project persistence.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 16:29:43 +08:00

32 lines
871 B
TypeScript

import { useEffect, useState } from 'react';
import { ipcChannels } from '../../../shared/ipc/contracts';
import type { SceneTrapsEvent, SceneTrapsState } from '../../../shared/types';
import { getDndApi } from '../dndApi';
export function useSceneTrapsState(): readonly [
SceneTrapsState | null,
{ dispatch: (event: SceneTrapsEvent) => Promise<void> },
] {
const api = getDndApi();
const [state, setState] = useState<SceneTrapsState | null>(null);
useEffect(() => {
void api.invoke(ipcChannels.sceneTraps.getState, {}).then((r) => {
setState(r.state);
});
return api.on(ipcChannels.sceneTraps.stateChanged, ({ state: next }) => {
setState(next);
});
}, [api]);
return [
state,
{
dispatch: async (event) => {
await api.invoke(ipcChannels.sceneTraps.dispatch, { event });
},
},
] as const;
}