From 4a630fe85b590f45c993b8d2650420b19b7999af Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 13 Apr 2023 21:44:00 +0100 Subject: [PATCH] prettier'd --- website/.prettierrc.json | 1 + website/package-lock.json | 24 ++++++ website/package.json | 3 + website/src/App.tsx | 26 +++++-- website/src/index.tsx | 8 +- website/src/mgba.tsx | 154 ++++++++++++++++++++------------------ 6 files changed, 131 insertions(+), 85 deletions(-) create mode 100644 website/.prettierrc.json diff --git a/website/.prettierrc.json b/website/.prettierrc.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/website/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/website/package-lock.json b/website/package-lock.json index 011d81b0..00d2d3c6 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -20,6 +20,9 @@ "react-scripts": "5.0.1", "typescript": "^4.9.5", "web-vitals": "^2.1.4" + }, + "devDependencies": { + "prettier": "2.8.7" } }, "node_modules/@adobe/css-tools": { @@ -13679,6 +13682,21 @@ "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": { "version": "5.6.0", "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", "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": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/website/package.json b/website/package.json index 5fa45700..c03ef1eb 100644 --- a/website/package.json +++ b/website/package.json @@ -39,5 +39,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "prettier": "2.8.7" } } diff --git a/website/src/App.tsx b/website/src/App.tsx index db147174..1ac691d0 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -1,18 +1,28 @@ -import React, { useState } from 'react'; -import { Mgba } from './mgba'; +import React, { useState } from "react"; +import { Mgba } from "./mgba"; function App() { - const [onGame, setOnGame] = useState(false); const [volume, setVolume] = useState(1.0); return (
- { - onGame && <> - setVolume(Number(e.target.value))}> - } - + {onGame && ( + <> + + setVolume(Number(e.target.value))} + > + + )} +
); } diff --git a/website/src/index.tsx b/website/src/index.tsx index 88e8a31a..153cce06 100644 --- a/website/src/index.tsx +++ b/website/src/index.tsx @@ -1,9 +1,9 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import App from './App'; +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App"; const root = ReactDOM.createRoot( - document.getElementById('root') as HTMLElement + document.getElementById("root") as HTMLElement ); root.render( diff --git a/website/src/mgba.tsx b/website/src/mgba.tsx index 1c598e20..0f4b3764 100644 --- a/website/src/mgba.tsx +++ b/website/src/mgba.tsx @@ -4,94 +4,102 @@ import mGBA from "./vendor/mgba"; type Module = any; interface MgbaProps { - gameUrl: string, - volume?: Number, + gameUrl: string; + volume?: Number; } enum MgbaState { - Uninitialised, - Initialising, - Initialised, + Uninitialised, + Initialising, + Initialised, } const MGBA_ROM_DIRECTORY = "/data/games"; - export const Mgba: FC = ({ gameUrl, volume }) => { + const canvas = useRef(null); + const mgbaModule = useRef({}); - const canvas = useRef(null); - const mgbaModule = useRef({}); + const [state, setState] = useState(MgbaState.Uninitialised); - const [state, setState] = useState(MgbaState.Uninitialised); + useEffect(() => { + if (state !== MgbaState.Initialised) return; + (async () => { + const game = await fetch(gameUrl); + const gameData = await game.arrayBuffer(); - useEffect(() => { - if (state !== MgbaState.Initialised) return; - (async () => { - const game = await fetch(gameUrl); - const gameData = await game.arrayBuffer(); + const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`; + mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData)); + mgbaModule.current.loadGame(gamePath); + })(); + }, [state, gameUrl]); - const gamePath = `${MGBA_ROM_DIRECTORY}/${gameUrl}`; - mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData)); - mgbaModule.current.loadGame(gamePath); - })() - }, [state, gameUrl]); + // init mgba + useEffect(() => { + (async () => { + if (canvas === null) return; + if (state !== MgbaState.Uninitialised) return; - // init mgba - useEffect(() => { - (async () => { + setState(MgbaState.Initialising); - if (canvas === null) return; - if (state !== MgbaState.Uninitialised) return; + mgbaModule.current = { + 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 = { - canvas: canvas.current, - locateFile: (file: string) => { - if (file === "mgba.wasm") { - return "/vendor/mgba.wasm"; - } - return file; - } - }; + if (state === MgbaState.Initialised) + return () => { + try { + mgbaModule.current.quitGame(); + mgbaModule.current.quitMgba(); + } catch {} + }; + }, [state]); - mGBA(mgbaModule.current).then((module: Module) => { - mgbaModule.current = module; - module.FSInit(); - setState(MgbaState.Initialised); - }); - } - )(); + useEffect(() => { + if (state !== MgbaState.Initialised) return; + mgbaModule.current.setVolume(volume ?? 1.0); + }, [state, volume]); - if (state === MgbaState.Initialised) - return () => { - try { - mgbaModule.current.quitGame(); - mgbaModule.current.quitMgba(); - } catch { } - }; - }, [state]); - - useEffect(() => { - if (state !== MgbaState.Initialised) return; - mgbaModule.current.setVolume(volume ?? 1.0); - }, [state, volume]); - - return <> - - - - - - - ; -}; \ No newline at end of file + return ( + <> + + + + + + ); +};