4456eb0277
Re-enable users-branch UI, snap session tokens to square/hex grid from the control preview, refine inactive/open-info NPC menus, block marker actions while an effect brush is active, and dim materials/NPC overlays only when they are open. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
981 B
TypeScript
34 lines
981 B
TypeScript
import { useCallback, useEffect, useState } from 'react';
|
|
|
|
import { ipcChannels } from '../../../shared/ipc/contracts';
|
|
import { getDndApi } from '../dndApi';
|
|
|
|
export function useTokenGridSnapSession(): [
|
|
boolean,
|
|
{ setEnabled: (enabled: boolean) => Promise<boolean> },
|
|
] {
|
|
const api = getDndApi();
|
|
const [enabled, setEnabledState] = useState(false);
|
|
|
|
useEffect(() => {
|
|
void api.invoke(ipcChannels.tokenGridSnap.getState, {}).then((res) => {
|
|
setEnabledState(Boolean(res.enabled));
|
|
});
|
|
return api.on(ipcChannels.tokenGridSnap.stateChanged, ({ enabled: next }) => {
|
|
setEnabledState(Boolean(next));
|
|
});
|
|
}, [api]);
|
|
|
|
const setEnabled = useCallback(
|
|
async (next: boolean) => {
|
|
setEnabledState(next);
|
|
const res = await api.invoke(ipcChannels.tokenGridSnap.setEnabled, { enabled: next });
|
|
setEnabledState(Boolean(res.enabled));
|
|
return Boolean(res.enabled);
|
|
},
|
|
[api],
|
|
);
|
|
|
|
return [enabled, { setEnabled }];
|
|
}
|