import { useRef, useState } from "react"; import { Mgba, MgbaHandle } from "./mgba"; import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings"; import { styled } from "styled-components"; import { useOnKeyUp } from "./useOnKeyUp.hook"; import { useLocalStorage } from "./useLocalStorage.hook"; import { useAvoidItchIoScrolling } from "./useAvoidItchIoScrolling"; import { Slider } from "./Slider"; const BindingsDialog = styled.dialog` border-radius: 5px; margin-top: 20px; overflow-y: auto; max-height: calc(100vh - 100px); `; const VolumeLabel = styled.label` display: flex; gap: 10px; `; const ActionButton = styled.button` width: 100%; margin-top: 20px; `; const AppContainer = styled.main` height: 100vh; display: flex; `; const StartButtonWrapper = styled.button` margin: auto; font-size: 5em; padding: 1em; text-transform: uppercase; background-color: black; color: white; border: none; border-radius: 0.5em; &:hover { background-color: #222; cursor: pointer; } `; function App() { const [{ volume, bindings }, setState] = useLocalStorage( { volume: 1.0, bindings: DefaultBindingsSet() }, "agbrswebplayer" ); const setVolume = (newVolume: number) => setState({ volume: newVolume, bindings }); const setBindings = (newBindings: Bindings) => setState({ volume, bindings: newBindings }); const [paused, setPaused] = useState(false); const [showBindings, setShowBindings] = useState(false); const mgbaRef = useRef(null); useOnKeyUp("Escape", () => { setShowBindings(!showBindings); }); useAvoidItchIoScrolling(); const [isPlaying, setIsPlaying] = useState(true); return ( {showBindings && ( setShowBindings(false)} restart={() => mgbaRef.current?.restart()} /> )} {isPlaying ? ( ) : ( setIsPlaying(true)} /> )} ); } function BindingsWindow({ bindings, setBindings, setPaused, volume, setVolume, hide, restart, }: { bindings: Bindings; setBindings: (b: Bindings) => void; setPaused: (paused: boolean) => void; volume: number; setVolume: (v: number) => void; hide: () => void; restart: () => void; }) { return ( Volume: setVolume(e)} /> setVolume(0)}>Mute Restart Close ); } function StartButton({ onClick }: { onClick: () => void }) { return ( Press to start ); } export default App;