mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
prettier'd
This commit is contained in:
parent
f2e5bf432b
commit
4a630fe85b
1
website/.prettierrc.json
Normal file
1
website/.prettierrc.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{}
|
24
website/package-lock.json
generated
24
website/package-lock.json
generated
|
@ -20,6 +20,9 @@
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "2.8.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
|
@ -13679,6 +13682,21 @@
|
||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/prettier": {
|
||||||
|
"version": "2.8.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
|
||||||
|
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"prettier": "bin-prettier.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/pretty-bytes": {
|
"node_modules/pretty-bytes": {
|
||||||
"version": "5.6.0",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
|
||||||
|
@ -26594,6 +26612,12 @@
|
||||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
||||||
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="
|
"integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="
|
||||||
},
|
},
|
||||||
|
"prettier": {
|
||||||
|
"version": "2.8.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.7.tgz",
|
||||||
|
"integrity": "sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"pretty-bytes": {
|
"pretty-bytes": {
|
||||||
"version": "5.6.0",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
|
||||||
|
|
|
@ -39,5 +39,8 @@
|
||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"prettier": "2.8.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,28 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from "react";
|
||||||
import { Mgba } from './mgba';
|
import { Mgba } from "./mgba";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
const [onGame, setOnGame] = useState(false);
|
const [onGame, setOnGame] = useState(false);
|
||||||
const [volume, setVolume] = useState(1.0);
|
const [volume, setVolume] = useState(1.0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{onGame && (
|
||||||
onGame && <><Mgba gameUrl="/game.gba" volume={volume} />
|
<>
|
||||||
<input type="range" value={volume} min="0" max="1" step="0.05" onChange={(e) => setVolume(Number(e.target.value))}></input></>
|
<Mgba gameUrl="/game.gba" volume={volume} />
|
||||||
}
|
<input
|
||||||
<button onClick={() => setOnGame(!onGame)}>{onGame ? "End Game" : "Start Game"}</button>
|
type="range"
|
||||||
|
value={volume}
|
||||||
|
min="0"
|
||||||
|
max="1"
|
||||||
|
step="0.05"
|
||||||
|
onChange={(e) => setVolume(Number(e.target.value))}
|
||||||
|
></input>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<button onClick={() => setOnGame(!onGame)}>
|
||||||
|
{onGame ? "End Game" : "Start Game"}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from "react-dom/client";
|
||||||
import App from './App';
|
import App from "./App";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById("root") as HTMLElement
|
||||||
);
|
);
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|
|
@ -4,94 +4,102 @@ import mGBA from "./vendor/mgba";
|
||||||
type Module = any;
|
type Module = any;
|
||||||
|
|
||||||
interface MgbaProps {
|
interface MgbaProps {
|
||||||
gameUrl: string,
|
gameUrl: string;
|
||||||
volume?: Number,
|
volume?: Number;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MgbaState {
|
enum MgbaState {
|
||||||
Uninitialised,
|
Uninitialised,
|
||||||
Initialising,
|
Initialising,
|
||||||
Initialised,
|
Initialised,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MGBA_ROM_DIRECTORY = "/data/games";
|
const MGBA_ROM_DIRECTORY = "/data/games";
|
||||||
|
|
||||||
|
|
||||||
export const Mgba: FC<MgbaProps> = ({ gameUrl, volume }) => {
|
export const Mgba: FC<MgbaProps> = ({ gameUrl, volume }) => {
|
||||||
|
const canvas = useRef(null);
|
||||||
|
const mgbaModule = useRef<Module>({});
|
||||||
|
|
||||||
const canvas = useRef(null);
|
const [state, setState] = useState(MgbaState.Uninitialised);
|
||||||
const mgbaModule = useRef<Module>({});
|
|
||||||
|
|
||||||
const [state, setState] = useState(MgbaState.Uninitialised);
|
useEffect(() => {
|
||||||
|
if (state !== MgbaState.Initialised) return;
|
||||||
|
(async () => {
|
||||||
|
const game = await fetch(gameUrl);
|
||||||
|
const gameData = await game.arrayBuffer();
|
||||||
|
|
||||||
useEffect(() => {
|
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`;
|
||||||
if (state !== MgbaState.Initialised) return;
|
mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData));
|
||||||
(async () => {
|
mgbaModule.current.loadGame(gamePath);
|
||||||
const game = await fetch(gameUrl);
|
})();
|
||||||
const gameData = await game.arrayBuffer();
|
}, [state, gameUrl]);
|
||||||
|
|
||||||
const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`;
|
// init mgba
|
||||||
mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData));
|
useEffect(() => {
|
||||||
mgbaModule.current.loadGame(gamePath);
|
(async () => {
|
||||||
})()
|
if (canvas === null) return;
|
||||||
}, [state, gameUrl]);
|
if (state !== MgbaState.Uninitialised) return;
|
||||||
|
|
||||||
// init mgba
|
setState(MgbaState.Initialising);
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
|
||||||
|
|
||||||
if (canvas === null) return;
|
mgbaModule.current = {
|
||||||
if (state !== MgbaState.Uninitialised) return;
|
canvas: canvas.current,
|
||||||
|
locateFile: (file: string) => {
|
||||||
|
if (file === "mgba.wasm") {
|
||||||
|
return "/vendor/mgba.wasm";
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
setState(MgbaState.Initialising);
|
mGBA(mgbaModule.current).then((module: Module) => {
|
||||||
|
mgbaModule.current = module;
|
||||||
|
module.FSInit();
|
||||||
|
setState(MgbaState.Initialised);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
mgbaModule.current = {
|
if (state === MgbaState.Initialised)
|
||||||
canvas: canvas.current,
|
return () => {
|
||||||
locateFile: (file: string) => {
|
try {
|
||||||
if (file === "mgba.wasm") {
|
mgbaModule.current.quitGame();
|
||||||
return "/vendor/mgba.wasm";
|
mgbaModule.current.quitMgba();
|
||||||
}
|
} catch {}
|
||||||
return file;
|
};
|
||||||
}
|
}, [state]);
|
||||||
};
|
|
||||||
|
|
||||||
mGBA(mgbaModule.current).then((module: Module) => {
|
useEffect(() => {
|
||||||
mgbaModule.current = module;
|
if (state !== MgbaState.Initialised) return;
|
||||||
module.FSInit();
|
mgbaModule.current.setVolume(volume ?? 1.0);
|
||||||
setState(MgbaState.Initialised);
|
}, [state, volume]);
|
||||||
});
|
|
||||||
}
|
|
||||||
)();
|
|
||||||
|
|
||||||
if (state === MgbaState.Initialised)
|
return (
|
||||||
return () => {
|
<>
|
||||||
try {
|
<canvas ref={canvas}></canvas>
|
||||||
mgbaModule.current.quitGame();
|
<button
|
||||||
mgbaModule.current.quitMgba();
|
onClick={() => {
|
||||||
} catch { }
|
if (state !== MgbaState.Initialised) return;
|
||||||
};
|
mgbaModule.current.saveState(0);
|
||||||
}, [state]);
|
}}
|
||||||
|
>
|
||||||
useEffect(() => {
|
Save State
|
||||||
if (state !== MgbaState.Initialised) return;
|
</button>
|
||||||
mgbaModule.current.setVolume(volume ?? 1.0);
|
<button
|
||||||
}, [state, volume]);
|
onClick={() => {
|
||||||
|
if (state !== MgbaState.Initialised) return;
|
||||||
return <>
|
mgbaModule.current.loadState(0);
|
||||||
|
}}
|
||||||
<canvas ref={canvas}></canvas>
|
>
|
||||||
<button onClick={() => {
|
Load State
|
||||||
if (state !== MgbaState.Initialised) return;
|
</button>
|
||||||
mgbaModule.current.saveState(0);
|
<button
|
||||||
}}>Save State</button>
|
onClick={() => {
|
||||||
<button onClick={() => {
|
if (state !== MgbaState.Initialised) return;
|
||||||
if (state !== MgbaState.Initialised) return;
|
mgbaModule.current.quickReload();
|
||||||
mgbaModule.current.loadState(0);
|
}}
|
||||||
}}>Load State</button>
|
>
|
||||||
<button onClick={() => {
|
Restart
|
||||||
if (state !== MgbaState.Initialised) return;
|
</button>
|
||||||
mgbaModule.current.quickReload();
|
</>
|
||||||
}}>Restart</button>
|
);
|
||||||
|
};
|
||||||
</>;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in a new issue