diff --git a/website/src/App.tsx b/website/src/App.tsx index 746cc5db..1ba14cd7 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -6,6 +6,7 @@ function App() { const [onGame, setOnGame] = useState(false); const [volume, setVolume] = useState(1.0); const [bindings, setBindings] = useState(DefaultBindingsSet()); + const [paused, setPaused] = useState(false); return (
@@ -15,6 +16,7 @@ function App() { gameUrl="/game.gba" volume={volume} controls={bindings.Actual} + paused={paused} /> setOnGame(!onGame)}> {onGame ? "End Game" : "Start Game"} - +
); } diff --git a/website/src/bindings.tsx b/website/src/bindings.tsx index 027f573a..ce285ece 100644 --- a/website/src/bindings.tsx +++ b/website/src/bindings.tsx @@ -75,7 +75,8 @@ const toHumanName = (keyName: string) => { export const BindingsControl: FC<{ bindings: Bindings; setBindings: (a: Bindings) => void; -}> = ({ bindings, setBindings }) => { + setPaused: (pause: boolean) => void; +}> = ({ bindings, setBindings, setPaused }) => { const [buttonToChange, setButtonToChange] = useState(null); const setKey = (key: string) => { @@ -91,13 +92,19 @@ export const BindingsControl: FC<{ setButtonToChange(null); setBindings(nextBindings); + setPaused(false); + }; + + const onSelectButtonClick = (key: GbaKey) => { + setPaused(true); + setButtonToChange(key); }; return ( - setKey(evt.key)}> + setKey(evt.key)}> {BindingsOrder.map((x) => ( setButtonToChange(x)} + onClick={() => onSelectButtonClick(x)} key={x} selected={buttonToChange === x} > diff --git a/website/src/mgba.tsx b/website/src/mgba.tsx index cf7a85bd..45cdbea9 100644 --- a/website/src/mgba.tsx +++ b/website/src/mgba.tsx @@ -8,6 +8,7 @@ interface MgbaProps { gameUrl: string; volume?: Number; controls: KeyBindings; + paused: boolean; } enum MgbaState { @@ -18,7 +19,7 @@ enum MgbaState { const MGBA_ROM_DIRECTORY = "/data/games"; -export const Mgba: FC = ({ gameUrl, volume, controls }) => { +export const Mgba: FC = ({ gameUrl, volume, controls, paused }) => { const canvas = useRef(null); const mgbaModule = useRef({}); @@ -92,6 +93,16 @@ export const Mgba: FC = ({ gameUrl, volume, controls }) => { mgbaModule.current.setVolume(volume ?? 1.0); }, [state, volume]); + useEffect(() => { + if (state !== MgbaState.Initialised) return; + + if (paused) { + mgbaModule.current.pauseGame(); + } else { + mgbaModule.current.resumeGame(); + } + }, [state, paused]); + return ( <> diff --git a/website/tsconfig.json b/website/tsconfig.json index a273b0cf..9d379a3c 100644 --- a/website/tsconfig.json +++ b/website/tsconfig.json @@ -1,11 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, @@ -20,7 +16,5 @@ "noEmit": true, "jsx": "react-jsx" }, - "include": [ - "src" - ] + "include": ["src"] }