mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
Force interaction to start
This commit is contained in:
parent
f944f35b61
commit
3323d6a4e7
|
@ -25,6 +25,23 @@ const ActionButton = styled.button`
|
||||||
const AppContainer = styled.main`
|
const AppContainer = styled.main`
|
||||||
height: calc(100vh - 20px);
|
height: calc(100vh - 20px);
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
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() {
|
function App() {
|
||||||
|
@ -50,6 +67,8 @@ function App() {
|
||||||
|
|
||||||
useAvoidItchIoScrolling();
|
useAvoidItchIoScrolling();
|
||||||
|
|
||||||
|
const [isPlaying, setIsPlaying] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppContainer>
|
<AppContainer>
|
||||||
{showBindings && (
|
{showBindings && (
|
||||||
|
@ -63,6 +82,7 @@ function App() {
|
||||||
restart={() => mgbaRef.current?.restart()}
|
restart={() => mgbaRef.current?.restart()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{isPlaying ? (
|
||||||
<Mgba
|
<Mgba
|
||||||
ref={mgbaRef}
|
ref={mgbaRef}
|
||||||
gameUrl="/game.gba"
|
gameUrl="/game.gba"
|
||||||
|
@ -70,6 +90,9 @@ function App() {
|
||||||
controls={bindings.Actual}
|
controls={bindings.Actual}
|
||||||
paused={paused}
|
paused={paused}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<StartButton onClick={() => setIsPlaying(true)} />
|
||||||
|
)}
|
||||||
</AppContainer>
|
</AppContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -101,11 +124,7 @@ function BindingsWindow({
|
||||||
min="0"
|
min="0"
|
||||||
max="1"
|
max="1"
|
||||||
step="0.05"
|
step="0.05"
|
||||||
onChange={(e) => {
|
onChange={(e) => setVolume(Number(e.target.value))}
|
||||||
console.log("e.target.value", e.target.value);
|
|
||||||
console.log("volume", volume);
|
|
||||||
setVolume(Number(e.target.value));
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</VolumeLabel>
|
</VolumeLabel>
|
||||||
<BindingsControl
|
<BindingsControl
|
||||||
|
@ -119,4 +138,10 @@ function BindingsWindow({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function StartButton({ onClick }: { onClick: () => void }) {
|
||||||
|
return (
|
||||||
|
<StartButtonWrapper onClick={onClick}>Press to start</StartButtonWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
|
@ -56,6 +56,8 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
||||||
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`;
|
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`;
|
||||||
mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData));
|
mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData));
|
||||||
mgbaModule.current.loadGame(gamePath);
|
mgbaModule.current.loadGame(gamePath);
|
||||||
|
mgbaModule.current.setVolume(0.1); // for some reason you have to do this or you get no sound
|
||||||
|
console.log(mgbaModule.current.getVolume());
|
||||||
setGameLoaded(true);
|
setGameLoaded(true);
|
||||||
})();
|
})();
|
||||||
}, [state, gameUrl]);
|
}, [state, gameUrl]);
|
||||||
|
@ -63,7 +65,7 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
||||||
// init mgba
|
// init mgba
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (canvas === null) return;
|
if (canvas.current === null) return;
|
||||||
if (state !== MgbaState.Uninitialised) return;
|
if (state !== MgbaState.Uninitialised) return;
|
||||||
|
|
||||||
setState(MgbaState.Initialising);
|
setState(MgbaState.Initialising);
|
||||||
|
@ -111,7 +113,9 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!gameLoaded) return;
|
if (!gameLoaded) return;
|
||||||
|
console.log("before", mgbaModule.current.getVolume());
|
||||||
mgbaModule.current.setVolume(volume ?? 1.0);
|
mgbaModule.current.setVolume(volume ?? 1.0);
|
||||||
|
console.log("after", mgbaModule.current.getVolume());
|
||||||
}, [gameLoaded, volume]);
|
}, [gameLoaded, volume]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in a new issue