load game based on path hash

This commit is contained in:
Corwin 2024-04-04 17:57:06 +01:00
parent 3574253df8
commit 713fc168ae
No known key found for this signature in database
5 changed files with 9 additions and 5 deletions

View file

@ -99,7 +99,6 @@ build-mgba-wasm:
build-combo-rom-site: build-combo-rom-site:
just _build-rom "examples/combo" "AGBGAMES" just _build-rom "examples/combo" "AGBGAMES"
cp examples/target/examples/combo.gba website/app/public/game.gba
build-site-mgba-wrapper: build-mgba-wasm build-site-mgba-wrapper: build-mgba-wasm
(cd website/app && npm run build) (cd website/app && npm run build)
@ -109,6 +108,7 @@ build-site: build-combo-rom-site build-site-mgba-wrapper build-book
cp website/site website/build -r cp website/site website/build -r
cp book/book website/build/book -r cp book/book website/build/book -r
cp website/app/build website/build/mgba -r cp website/app/build website/build/mgba -r
cp examples/target/examples/combo.gba website/build/assets/combo.gba
_run-tool +tool: _run-tool +tool:
(cd tools && cargo build) (cd tools && cargo build)

View file

@ -24,4 +24,3 @@ yarn-error.log*
src/vendor src/vendor
public/game.gba

View file

@ -68,6 +68,8 @@ function App() {
useAvoidItchIoScrolling(); useAvoidItchIoScrolling();
const gameUrl = window.location.hash.slice(1);
const [isPlaying, setIsPlaying] = useState(true); const [isPlaying, setIsPlaying] = useState(true);
return ( return (
@ -86,7 +88,7 @@ function App() {
{isPlaying ? ( {isPlaying ? (
<Mgba <Mgba
ref={mgbaRef} ref={mgbaRef}
gameUrl="./game.gba" gameUrl={gameUrl}
volume={volume} volume={volume}
controls={bindings.Actual} controls={bindings.Actual}
paused={paused} paused={paused}

View file

@ -52,7 +52,10 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
const game = await fetch(gameUrl); const game = await fetch(gameUrl);
const gameData = await game.arrayBuffer(); const gameData = await game.arrayBuffer();
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`; const gameSplit = gameUrl.split("/");
const gameBaseName = gameSplit[gameSplit.length - 1];
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameBaseName}`;
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 mgbaModule.current.setVolume(0.1); // for some reason you have to do this or you get no sound

View file

@ -100,7 +100,7 @@
<div class="imageWrapper"><img src="assets/left.png" /></div> <div class="imageWrapper"><img src="assets/left.png" /></div>
<iframe <iframe
onload="this.contentWindow.focus()" onload="this.contentWindow.focus()"
src="mgba/index.html" src="mgba/index.html#/assets/combo.gba"
></iframe> ></iframe>
<div class="imageWrapper"><img src="assets/right.png" /></div> <div class="imageWrapper"><img src="assets/right.png" /></div>
</div> </div>