mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-09 08:31: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(() => {
|
useEffect(() => {
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
|
|
||||||
|
|
||||||
let previouslyPressedButtons = new Set<GbaKey>();
|
let previouslyPressedButtons = new Set<GbaKey>();
|
||||||
|
|
||||||
function raf(time: DOMHighResTimeStamp) {
|
function raf(time: DOMHighResTimeStamp) {
|
||||||
|
|
||||||
const controllers = navigator.getGamepads();
|
const controllers = navigator.getGamepads();
|
||||||
const currentlyPressed = new Set<GbaKey>();
|
const currentlyPressed = new Set<GbaKey>();
|
||||||
for (let controller of controllers) {
|
for (let controller of controllers) {
|
||||||
if (!controller) continue;
|
if (!controller) continue;
|
||||||
|
|
||||||
|
|
||||||
if (controller.buttons[1].pressed) {
|
if (controller.buttons[1].pressed) {
|
||||||
currentlyPressed.add(GbaKey.A);
|
currentlyPressed.add(GbaKey.A);
|
||||||
}
|
}
|
||||||
|
@ -51,20 +48,18 @@ export function useController(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
currentlyPressed.add(GbaKey.Right);
|
currentlyPressed.add(GbaKey.Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller.axes[0] < -.5) {
|
if (controller.axes[0] < -0.5) {
|
||||||
currentlyPressed.add(GbaKey.Left);
|
currentlyPressed.add(GbaKey.Left);
|
||||||
}
|
}
|
||||||
if (controller.axes[0] > .5) {
|
if (controller.axes[0] > 0.5) {
|
||||||
currentlyPressed.add(GbaKey.Right);
|
currentlyPressed.add(GbaKey.Right);
|
||||||
}
|
}
|
||||||
if (controller.axes[1] < -.5) {
|
if (controller.axes[1] < -0.5) {
|
||||||
currentlyPressed.add(GbaKey.Up);
|
currentlyPressed.add(GbaKey.Up);
|
||||||
}
|
}
|
||||||
if (controller.axes[1] > .5) {
|
if (controller.axes[1] > 0.5) {
|
||||||
currentlyPressed.add(GbaKey.Down);
|
currentlyPressed.add(GbaKey.Down);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let oldButton of previouslyPressedButtons) {
|
for (let oldButton of previouslyPressedButtons) {
|
||||||
|
@ -86,13 +81,14 @@ export function useController(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function gamepadConnectedEvent() {
|
function gamepadConnectedEvent() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener("gamepadconnected", gamepadConnectedEvent);
|
window.addEventListener("gamepadconnected", gamepadConnectedEvent);
|
||||||
|
|
||||||
window.requestAnimationFrame(raf);
|
window.requestAnimationFrame(raf);
|
||||||
return () => { stopped = true; window.removeEventListener("gamepadconnected", gamepadConnectedEvent); };
|
return () => {
|
||||||
|
stopped = true;
|
||||||
|
window.removeEventListener("gamepadconnected", gamepadConnectedEvent);
|
||||||
|
};
|
||||||
}, [mgbaModule]);
|
}, [mgbaModule]);
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
import { MutableRefObject, useEffect } from "react";
|
import { MutableRefObject, useEffect } from "react";
|
||||||
import { mGBAEmulator } from "./vendor/mgba";
|
import { mGBAEmulator } from "./vendor/mgba";
|
||||||
|
|
||||||
|
|
||||||
export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let previous: number | undefined = undefined;
|
let previous: number | undefined = undefined;
|
||||||
|
@ -19,7 +18,6 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
|
|
||||||
const smoothedFrameRate = Math.round(1 / (smoothedFrameTime / 1000));
|
const smoothedFrameRate = Math.round(1 / (smoothedFrameTime / 1000));
|
||||||
|
|
||||||
|
|
||||||
totalTime += 1 / smoothedFrameRate;
|
totalTime += 1 / smoothedFrameRate;
|
||||||
|
|
||||||
if (totalTime >= 1 / 60) {
|
if (totalTime >= 1 / 60) {
|
||||||
|
@ -34,8 +32,6 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
previous = time;
|
previous = time;
|
||||||
|
|
||||||
|
@ -45,9 +41,8 @@ export function useFrameSkip(mgbaModule: MutableRefObject<mGBAEmulator>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.requestAnimationFrame(raf);
|
window.requestAnimationFrame(raf);
|
||||||
return () => { stopped = true; };
|
return () => {
|
||||||
|
stopped = true;
|
||||||
|
};
|
||||||
}, [mgbaModule]);
|
}, [mgbaModule]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
export function useLocalStorage<T>(defaultValue: T,
|
export function useLocalStorage<T>(
|
||||||
appName: string): [T, (newValue: T) => void] {
|
defaultValue: T,
|
||||||
|
appName: string
|
||||||
|
): [T, (newValue: T) => void] {
|
||||||
const [value, setValue] = useState(() => {
|
const [value, setValue] = useState(() => {
|
||||||
try {
|
try {
|
||||||
const storageValue = localStorage.getItem(appName);
|
const storageValue = localStorage.getItem(appName);
|
||||||
|
|
Loading…
Reference in a new issue