mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
format ts files
This commit is contained in:
parent
c29a9a4a2b
commit
4e4e323002
|
@ -6,17 +6,14 @@ export function useController(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
useEffect(() => {
|
||||
let stopped = false;
|
||||
|
||||
|
||||
let previouslyPressedButtons = new Set<GbaKey>();
|
||||
|
||||
function raf(time: DOMHighResTimeStamp) {
|
||||
|
||||
const controllers = navigator.getGamepads();
|
||||
const currentlyPressed = new Set<GbaKey>();
|
||||
for (let controller of controllers) {
|
||||
if (!controller) continue;
|
||||
|
||||
|
||||
if (controller.buttons[1].pressed) {
|
||||
currentlyPressed.add(GbaKey.A);
|
||||
}
|
||||
|
@ -51,20 +48,18 @@ export function useController(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
currentlyPressed.add(GbaKey.Right);
|
||||
}
|
||||
|
||||
if (controller.axes[0] < -.5) {
|
||||
if (controller.axes[0] < -0.5) {
|
||||
currentlyPressed.add(GbaKey.Left);
|
||||
}
|
||||
if (controller.axes[0] > .5) {
|
||||
if (controller.axes[0] > 0.5) {
|
||||
currentlyPressed.add(GbaKey.Right);
|
||||
}
|
||||
if (controller.axes[1] < -.5) {
|
||||
if (controller.axes[1] < -0.5) {
|
||||
currentlyPressed.add(GbaKey.Up);
|
||||
}
|
||||
if (controller.axes[1] > .5) {
|
||||
if (controller.axes[1] > 0.5) {
|
||||
currentlyPressed.add(GbaKey.Down);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for (let oldButton of previouslyPressedButtons) {
|
||||
|
@ -86,13 +81,14 @@ export function useController(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
}
|
||||
}
|
||||
|
||||
function gamepadConnectedEvent() {
|
||||
|
||||
}
|
||||
function gamepadConnectedEvent() {}
|
||||
|
||||
window.addEventListener("gamepadconnected", gamepadConnectedEvent);
|
||||
|
||||
window.requestAnimationFrame(raf);
|
||||
return () => { stopped = true; window.removeEventListener("gamepadconnected", gamepadConnectedEvent); };
|
||||
return () => {
|
||||
stopped = true;
|
||||
window.removeEventListener("gamepadconnected", gamepadConnectedEvent);
|
||||
};
|
||||
}, [mgbaModule]);
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
import { MutableRefObject, useEffect } from "react";
|
||||
import { mGBAEmulator } from "./vendor/mgba";
|
||||
|
||||
|
||||
export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||
useEffect(() => {
|
||||
let previous: number | undefined = undefined;
|
||||
|
@ -19,7 +18,6 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
|
||||
const smoothedFrameRate = Math.round(1 / (smoothedFrameTime / 1000));
|
||||
|
||||
|
||||
totalTime += 1 / smoothedFrameRate;
|
||||
|
||||
if (totalTime >= 1 / 60) {
|
||||
|
@ -34,8 +32,6 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
previous = time;
|
||||
|
||||
|
@ -45,9 +41,8 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
|||
}
|
||||
|
||||
window.requestAnimationFrame(raf);
|
||||
return () => { stopped = true; };
|
||||
return () => {
|
||||
stopped = true;
|
||||
};
|
||||
}, [mgbaModule]);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import { useCallback, useState } from "react";
|
||||
|
||||
export function useLocalStorage<T>(defaultValue: T,
|
||||
appName: string): [T, (newValue: T) => void] {
|
||||
export function useLocalStorage<T>(
|
||||
defaultValue: T,
|
||||
appName: string
|
||||
): [T, (newValue: T) => void] {
|
||||
const [value, setValue] = useState(() => {
|
||||
try {
|
||||
const storageValue = localStorage.getItem(appName);
|
||||
|
@ -19,7 +21,7 @@ export function useLocalStorage<T>(defaultValue: T,
|
|||
setValue(newValue);
|
||||
try {
|
||||
localStorage.setItem(appName, JSON.stringify(newValue));
|
||||
} catch { }
|
||||
} catch {}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
|
|
Loading…
Reference in a new issue