2023-04-13 21:44:00 +01:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { Mgba } from "./mgba";
|
2023-07-05 11:23:59 +01:00
|
|
|
import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings";
|
|
|
|
import { styled } from "styled-components";
|
|
|
|
import { useOnKeyUp } from "./useOnKeyUp.hook";
|
2023-07-05 11:39:14 +01:00
|
|
|
import { useLocalStorage } from "./useLocalStorage.hook";
|
2023-07-05 11:23:59 +01:00
|
|
|
|
|
|
|
const BindingsDialog = styled.dialog`
|
|
|
|
border-radius: 5px;
|
|
|
|
margin-top: 20px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const VolumeLabel = styled.label`
|
|
|
|
display: flex;
|
|
|
|
gap: 10px;
|
|
|
|
margin-bottom: 20px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CloseButton = styled.button`
|
|
|
|
width: 100%;
|
|
|
|
margin-top: 20px;
|
|
|
|
`;
|
2023-04-13 20:12:45 +01:00
|
|
|
|
|
|
|
function App() {
|
2023-07-05 11:39:14 +01:00
|
|
|
const [volumeState, setVolume] = useState(1.0);
|
|
|
|
const [bindingsState, setBindings] = useState(DefaultBindingsSet());
|
|
|
|
|
|
|
|
const { volume, bindings } = useLocalStorage(
|
|
|
|
{ volume: volumeState, bindings: bindingsState },
|
|
|
|
"agbrswebplayer"
|
|
|
|
);
|
|
|
|
|
2023-04-25 21:45:41 +01:00
|
|
|
const [paused, setPaused] = useState(false);
|
2023-04-13 21:32:40 +01:00
|
|
|
|
2023-07-05 11:23:59 +01:00
|
|
|
const [showBindings, setShowBindings] = useState(false);
|
|
|
|
|
|
|
|
useOnKeyUp("Escape", () => {
|
|
|
|
setShowBindings(!showBindings);
|
|
|
|
});
|
|
|
|
|
2023-04-13 20:12:45 +01:00
|
|
|
return (
|
2023-04-13 21:32:40 +01:00
|
|
|
<div>
|
2023-07-05 11:23:59 +01:00
|
|
|
{showBindings && (
|
|
|
|
<BindingsWindow
|
|
|
|
bindings={bindings}
|
|
|
|
setBindings={setBindings}
|
|
|
|
setPaused={setPaused}
|
|
|
|
volume={volume}
|
|
|
|
setVolume={setVolume}
|
|
|
|
hide={() => setShowBindings(false)}
|
|
|
|
/>
|
|
|
|
)}
|
2023-07-05 10:07:10 +01:00
|
|
|
<Mgba
|
|
|
|
gameUrl="/game.gba"
|
|
|
|
volume={volume}
|
|
|
|
controls={bindings.Actual}
|
|
|
|
paused={paused}
|
|
|
|
/>
|
2023-07-05 11:23:59 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-07-05 10:07:10 +01:00
|
|
|
|
2023-07-05 11:23:59 +01:00
|
|
|
function BindingsWindow({
|
|
|
|
bindings,
|
|
|
|
setBindings,
|
|
|
|
setPaused,
|
|
|
|
volume,
|
|
|
|
setVolume,
|
|
|
|
hide,
|
|
|
|
}: {
|
|
|
|
bindings: Bindings;
|
|
|
|
setBindings: (b: Bindings) => void;
|
|
|
|
setPaused: (paused: boolean) => void;
|
|
|
|
volume: number;
|
|
|
|
setVolume: (v: number) => void;
|
|
|
|
hide: () => void;
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<BindingsDialog open onClose={hide}>
|
|
|
|
<VolumeLabel>
|
|
|
|
Volume:
|
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
value={volume}
|
|
|
|
min="0"
|
|
|
|
max="1"
|
|
|
|
step="0.05"
|
|
|
|
onChange={(e) => {
|
|
|
|
console.log("e.target.value", e.target.value);
|
|
|
|
console.log("volume", volume);
|
|
|
|
setVolume(Number(e.target.value));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</VolumeLabel>
|
2023-04-25 21:45:41 +01:00
|
|
|
<BindingsControl
|
|
|
|
bindings={bindings}
|
|
|
|
setBindings={setBindings}
|
|
|
|
setPaused={setPaused}
|
|
|
|
/>
|
2023-07-05 11:23:59 +01:00
|
|
|
<CloseButton onClick={hide}>Close</CloseButton>
|
|
|
|
</BindingsDialog>
|
2023-04-13 20:12:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|