mirror of
https://github.com/italicsjenga/agb.git
synced 2025-02-23 22:58:18 +11:00
Only set settings when the game loads
This commit is contained in:
parent
845a4b9244
commit
a1c1671b0b
1 changed files with 9 additions and 7 deletions
|
@ -24,6 +24,7 @@ export const Mgba: FC<MgbaProps> = ({ gameUrl, volume, controls, paused }) => {
|
||||||
const mgbaModule = useRef<Module>({});
|
const mgbaModule = useRef<Module>({});
|
||||||
|
|
||||||
const [state, setState] = useState(MgbaState.Uninitialised);
|
const [state, setState] = useState(MgbaState.Uninitialised);
|
||||||
|
const [gameLoaded, setGameLoaded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state !== MgbaState.Initialised) return;
|
if (state !== MgbaState.Initialised) return;
|
||||||
|
@ -34,6 +35,7 @@ export const Mgba: FC<MgbaProps> = ({ gameUrl, volume, controls, paused }) => {
|
||||||
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);
|
||||||
|
setGameLoaded(true);
|
||||||
})();
|
})();
|
||||||
}, [state, gameUrl]);
|
}, [state, gameUrl]);
|
||||||
|
|
||||||
|
@ -72,7 +74,7 @@ export const Mgba: FC<MgbaProps> = ({ gameUrl, volume, controls, paused }) => {
|
||||||
}, [state]);
|
}, [state]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state !== MgbaState.Initialised) return;
|
if (!gameLoaded) return;
|
||||||
|
|
||||||
const controlEntries = Object.entries(controls);
|
const controlEntries = Object.entries(controls);
|
||||||
|
|
||||||
|
@ -86,22 +88,22 @@ export const Mgba: FC<MgbaProps> = ({ gameUrl, volume, controls, paused }) => {
|
||||||
|
|
||||||
mgbaModule.current.bindKey(binding, key);
|
mgbaModule.current.bindKey(binding, key);
|
||||||
}
|
}
|
||||||
}, [controls, state]);
|
}, [controls, gameLoaded]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state !== MgbaState.Initialised) return;
|
if (!gameLoaded) return;
|
||||||
mgbaModule.current.setVolume(volume ?? 1.0);
|
mgbaModule.current.setVolume(volume ?? 1.0);
|
||||||
}, [state, volume]);
|
}, [gameLoaded, volume]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (state !== MgbaState.Initialised) return;
|
if (!gameLoaded) return;
|
||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
mgbaModule.current.pauseGame();
|
mgbaModule.current.pauseGame();
|
||||||
} else {
|
} else {
|
||||||
mgbaModule.current.resumeGame();
|
mgbaModule.current.resumeGame();
|
||||||
}
|
}
|
||||||
}, [state, paused]);
|
}, [gameLoaded, paused]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Add table
Reference in a new issue