mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-20 16:46:07 -08:00
- Add createControllerHintVisibility: use the dialog window's pad, else ask main which controller the overlay is reading, at most once per second while a dialog is open - Hide shortcut tags when controller support is on but no controller is present - Update the Anki integration docs and changelog fragments to match
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
const OVERLAY_CONTROLLER_REFRESH_MS = 1_000;
|
|
|
|
/**
|
|
* Decides whether dialogs show their controller shortcut tags. A fresh dialog window cannot
|
|
* see a pad until a button is pressed in it, so an open dialog also asks main which controller
|
|
* the overlay is reading. Called every frame; requests are limited to one per refresh interval.
|
|
*/
|
|
export function createControllerHintVisibility(options: {
|
|
getOverlayControllerId: () => Promise<string | null>;
|
|
}) {
|
|
let overlayHasController = false;
|
|
let nextRefreshAt = Number.NEGATIVE_INFINITY;
|
|
|
|
function refreshOverlayController(now: number): void {
|
|
if (now < nextRefreshAt) return;
|
|
nextRefreshAt = now + OVERLAY_CONTROLLER_REFRESH_MS;
|
|
options.getOverlayControllerId().then(
|
|
(gamepadId) => {
|
|
overlayHasController = gamepadId !== null;
|
|
},
|
|
() => {
|
|
// Keep the last answer; the next refresh tries again.
|
|
},
|
|
);
|
|
}
|
|
|
|
return {
|
|
update(state: {
|
|
enabled: boolean;
|
|
dialogOpen: boolean;
|
|
activeGamepadId: string | null;
|
|
now: number;
|
|
}): boolean {
|
|
if (!state.enabled) return false;
|
|
if (state.activeGamepadId !== null) return true;
|
|
if (state.dialogOpen) refreshOverlayController(state.now);
|
|
return overlayHasController;
|
|
},
|
|
};
|
|
}
|