diff --git a/website/app/src/App.tsx b/website/app/src/App.tsx index c04e9e44..df71c83f 100644 --- a/website/app/src/App.tsx +++ b/website/app/src/App.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Mgba, MgbaHandle } from "./mgba"; import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings"; import { styled } from "styled-components"; @@ -48,7 +48,7 @@ const StartButtonWrapper = styled.button` function App() { const [{ volume, bindings }, setState] = useLocalStorage( { volume: 1.0, bindings: DefaultBindingsSet() }, - "agbrswebplayer" + "agbrswebplayer", ); const setVolume = (newVolume: number) => @@ -66,6 +66,30 @@ function App() { setShowBindings(!showBindings); }); + useEffect(() => { + const buttonPress = (event: MessageEvent) => { + const data = event.data; + + const { isPressed, button, reset } = data; + + if (isPressed === true) { + mgbaRef.current?.buttonPress(button); + } else if (isPressed === false) { + mgbaRef.current?.buttonRelease(button); + } + + if (reset) { + mgbaRef.current?.restart(); + } + }; + + window.addEventListener("message", buttonPress); + + return () => { + window.removeEventListener("message", buttonPress); + }; + }, []); + useAvoidItchIoScrolling(); const gameUrl = window.location.hash.slice(1); diff --git a/website/app/src/mgba.tsx b/website/app/src/mgba.tsx index ee53f84b..e2b14a49 100644 --- a/website/app/src/mgba.tsx +++ b/website/app/src/mgba.tsx @@ -6,7 +6,7 @@ import { useState, } from "react"; import mGBA from "./vendor/mgba"; -import { KeyBindings } from "./bindings"; +import { GbaKey, KeyBindings } from "./bindings"; import { styled } from "styled-components"; type Module = any; @@ -36,6 +36,8 @@ const MgbaCanvas = styled.canvas` export interface MgbaHandle { restart: () => void; + buttonPress: (key: GbaKey) => void; + buttonRelease: (key: GbaKey) => void; } export const Mgba = forwardRef( @@ -70,7 +72,6 @@ export const Mgba = forwardRef( if (state !== MgbaState.Uninitialised) return; setState(MgbaState.Initialising); - mgbaModule.current = { canvas: canvas.current, }; @@ -124,9 +125,11 @@ export const Mgba = forwardRef( useImperativeHandle(ref, () => { return { restart: () => mgbaModule.current.quickReload(), + buttonPress: (key: GbaKey) => mgbaModule.current.buttonPress(key), + buttonRelease: (key: GbaKey) => mgbaModule.current.buttonUnpress(key), }; }); return ; - } + }, ); diff --git a/website/site/assets/L.png b/website/site/assets/L.png new file mode 100644 index 00000000..75a1aae4 Binary files /dev/null and b/website/site/assets/L.png differ diff --git a/website/site/assets/R.png b/website/site/assets/R.png new file mode 100644 index 00000000..4622cd75 Binary files /dev/null and b/website/site/assets/R.png differ diff --git a/website/site/assets/SELECT.png b/website/site/assets/SELECT.png new file mode 100644 index 00000000..c1e67f77 Binary files /dev/null and b/website/site/assets/SELECT.png differ diff --git a/website/site/assets/START.png b/website/site/assets/START.png new file mode 100644 index 00000000..55895537 Binary files /dev/null and b/website/site/assets/START.png differ diff --git a/website/site/assets/ab.png b/website/site/assets/ab.png new file mode 100644 index 00000000..ed9780b9 Binary files /dev/null and b/website/site/assets/ab.png differ diff --git a/website/site/assets/dpad.png b/website/site/assets/dpad.png new file mode 100644 index 00000000..6c5d140b Binary files /dev/null and b/website/site/assets/dpad.png differ diff --git a/website/site/crash/index.html b/website/site/crash/index.html index 6573f351..69f92245 100644 --- a/website/site/crash/index.html +++ b/website/site/crash/index.html @@ -1,6 +1,7 @@ + agbrs crash backtrace +

agb - a rust framework for making Game Boy Advance games

@@ -99,13 +145,31 @@
-
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+

Press escape to open the menu where you can view or change controls and restart the game. The game provided is a combination of multiple @@ -122,5 +186,152 @@ Docs

+ +