mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-22 07:06:41 +11:00
commit
17b3bd08f9
31 changed files with 28119 additions and 13 deletions
61
.github/workflows/build-site.yml
vendored
Normal file
61
.github/workflows/build-site.yml
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
name: Build and Deploy Website
|
||||
|
||||
on:
|
||||
merge_group:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build website
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: gacts/install-podman@v1
|
||||
- name: Set CARGO_TARGET_DIR
|
||||
run: echo "CARGO_TARGET_DIR=$HOME/target" >> $GITHUB_ENV
|
||||
- name: Install build tools
|
||||
run: sudo apt-get update && sudo apt-get install build-essential libelf-dev zip -y
|
||||
- uses: actions/checkout@v4
|
||||
- name: Cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
~/target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}--npm--${{ hashFiles('**/package-lock.json') }}
|
||||
- uses: extractions/setup-just@v2
|
||||
- name: Setup mdBook
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
with:
|
||||
mdbook-version: "0.4.13"
|
||||
- name: Build website
|
||||
run: just build-site
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: "website/build"
|
||||
deploy:
|
||||
name: Deploy website
|
||||
if: github.event_name != 'pull_request'
|
||||
# Add a dependency to the build job
|
||||
needs: build
|
||||
|
||||
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
|
||||
permissions:
|
||||
pages: write # to deploy to Pages
|
||||
id-token: write # to verify the deployment originates from an appropriate source
|
||||
|
||||
# Deploy to the github-pages environment
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
||||
# Specify runner + deployment step
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
13
.github/workflows/publish-agb.yml
vendored
13
.github/workflows/publish-agb.yml
vendored
|
@ -5,7 +5,6 @@ on:
|
|||
tags:
|
||||
- v*
|
||||
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-22.04
|
||||
|
@ -40,15 +39,3 @@ jobs:
|
|||
asset_name: examples.zip
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
|
||||
- name: Setup mdBook
|
||||
uses: peaceiris/actions-mdbook@v1
|
||||
with:
|
||||
mdbook-version: '0.4.13'
|
||||
- name: Build the book
|
||||
run: just build-book
|
||||
- name: Deploy the book
|
||||
uses: JamesIves/github-pages-deploy-action@v4
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: book/book
|
||||
|
|
19
justfile
19
justfile
|
@ -92,6 +92,25 @@ release +args: (_run-tool "release" args)
|
|||
miri:
|
||||
(cd agb-hashmap && cargo miri test)
|
||||
|
||||
build-mgba-wasm:
|
||||
rm -rf website/app/src/vendor
|
||||
mkdir website/app/src/vendor
|
||||
podman build --file website/mgba-wasm/BuildMgbaWasm --output=website/app/src/vendor .
|
||||
|
||||
build-combo-rom-site:
|
||||
just _build-rom "examples/combo" "AGBGAMES"
|
||||
|
||||
build-site-mgba-wrapper: build-mgba-wasm
|
||||
(cd website/app && npm install --no-save --prefer-offline --no-audit)
|
||||
(cd website/app && npm run build)
|
||||
|
||||
build-site: build-combo-rom-site build-site-mgba-wrapper build-book
|
||||
rm -rf website/build
|
||||
cp website/site website/build -r
|
||||
cp book/book website/build/book -r
|
||||
cp website/app/build website/build/mgba -r
|
||||
cp examples/target/examples/combo.gba website/build/assets/combo.gba
|
||||
|
||||
_run-tool +tool:
|
||||
(cd tools && cargo build)
|
||||
"$CARGO_TARGET_DIR/debug/tools" {{tool}}
|
||||
|
|
1
website/.gitignore
vendored
Normal file
1
website/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build
|
1
website/app/.eslintignore
Normal file
1
website/app/.eslintignore
Normal file
|
@ -0,0 +1 @@
|
|||
**/vendor/*.js
|
26
website/app/.gitignore
vendored
Normal file
26
website/app/.gitignore
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
|
||||
src/vendor
|
1
website/app/.prettierrc.json
Normal file
1
website/app/.prettierrc.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
46
website/app/README.md
Normal file
46
website/app/README.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
27062
website/app/package-lock.json
generated
Normal file
27062
website/app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
52
website/app/package.json
Normal file
52
website/app/package.json
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"name": "website",
|
||||
"version": "0.1.0",
|
||||
"homepage": "./",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^14.0.0",
|
||||
"@testing-library/user-event": "^14.4.3",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.3",
|
||||
"@types/react": "^18.2.14",
|
||||
"@types/react-dom": "^18.2.6",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"styled-components": "^6.0.2",
|
||||
"typescript": "^5.1.6",
|
||||
"web-vitals": "^3.3.2"
|
||||
},
|
||||
"overrides": {
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/styled-components": "^5.1.26",
|
||||
"prettier": "2.8.8"
|
||||
}
|
||||
}
|
BIN
website/app/public/favicon.ico
Normal file
BIN
website/app/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
43
website/app/public/index.html
Normal file
43
website/app/public/index.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
BIN
website/app/public/logo192.png
Normal file
BIN
website/app/public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
website/app/public/logo512.png
Normal file
BIN
website/app/public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
website/app/public/manifest.json
Normal file
25
website/app/public/manifest.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
website/app/public/robots.txt
Normal file
3
website/app/public/robots.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
145
website/app/src/App.tsx
Normal file
145
website/app/src/App.tsx
Normal file
|
@ -0,0 +1,145 @@
|
|||
import { useRef, useState } from "react";
|
||||
import { Mgba, MgbaHandle } from "./mgba";
|
||||
import { BindingsControl, DefaultBindingsSet, Bindings } from "./bindings";
|
||||
import { styled } from "styled-components";
|
||||
import { useOnKeyUp } from "./useOnKeyUp.hook";
|
||||
import { useLocalStorage } from "./useLocalStorage.hook";
|
||||
import { useAvoidItchIoScrolling } from "./useAvoidItchIoScrolling";
|
||||
import { Slider } from "./Slider";
|
||||
|
||||
const BindingsDialog = styled.dialog`
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
overflow-y: auto;
|
||||
max-height: calc(100vh - 100px);
|
||||
`;
|
||||
|
||||
const VolumeLabel = styled.label`
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
`;
|
||||
|
||||
const ActionButton = styled.button`
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
`;
|
||||
|
||||
const AppContainer = styled.main`
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
`;
|
||||
|
||||
const StartButtonWrapper = styled.button`
|
||||
margin: auto;
|
||||
font-size: 5em;
|
||||
padding: 1em;
|
||||
text-transform: uppercase;
|
||||
background-color: black;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 0.5em;
|
||||
|
||||
&:hover {
|
||||
background-color: #222;
|
||||
cursor: pointer;
|
||||
}
|
||||
`;
|
||||
|
||||
function App() {
|
||||
const [{ volume, bindings }, setState] = useLocalStorage(
|
||||
{ volume: 1.0, bindings: DefaultBindingsSet() },
|
||||
"agbrswebplayer"
|
||||
);
|
||||
|
||||
const setVolume = (newVolume: number) =>
|
||||
setState({ volume: newVolume, bindings });
|
||||
const setBindings = (newBindings: Bindings) =>
|
||||
setState({ volume, bindings: newBindings });
|
||||
|
||||
const [paused, setPaused] = useState(false);
|
||||
|
||||
const [showBindings, setShowBindings] = useState(false);
|
||||
|
||||
const mgbaRef = useRef<MgbaHandle>(null);
|
||||
|
||||
useOnKeyUp("Escape", () => {
|
||||
setShowBindings(!showBindings);
|
||||
});
|
||||
|
||||
useAvoidItchIoScrolling();
|
||||
|
||||
const gameUrl = window.location.hash.slice(1);
|
||||
|
||||
const [isPlaying, setIsPlaying] = useState(true);
|
||||
|
||||
return (
|
||||
<AppContainer>
|
||||
{showBindings && (
|
||||
<BindingsWindow
|
||||
bindings={bindings}
|
||||
setBindings={setBindings}
|
||||
setPaused={setPaused}
|
||||
volume={volume}
|
||||
setVolume={setVolume}
|
||||
hide={() => setShowBindings(false)}
|
||||
restart={() => mgbaRef.current?.restart()}
|
||||
/>
|
||||
)}
|
||||
{isPlaying ? (
|
||||
<Mgba
|
||||
ref={mgbaRef}
|
||||
gameUrl={gameUrl}
|
||||
volume={volume}
|
||||
controls={bindings.Actual}
|
||||
paused={paused}
|
||||
/>
|
||||
) : (
|
||||
<StartButton onClick={() => setIsPlaying(true)} />
|
||||
)}
|
||||
</AppContainer>
|
||||
);
|
||||
}
|
||||
|
||||
function BindingsWindow({
|
||||
bindings,
|
||||
setBindings,
|
||||
setPaused,
|
||||
volume,
|
||||
setVolume,
|
||||
hide,
|
||||
restart,
|
||||
}: {
|
||||
bindings: Bindings;
|
||||
setBindings: (b: Bindings) => void;
|
||||
setPaused: (paused: boolean) => void;
|
||||
volume: number;
|
||||
setVolume: (v: number) => void;
|
||||
hide: () => void;
|
||||
restart: () => void;
|
||||
}) {
|
||||
return (
|
||||
<BindingsDialog open onClose={hide}>
|
||||
<VolumeLabel>
|
||||
Volume:
|
||||
<Slider value={volume} onChange={(e) => setVolume(e)} />
|
||||
</VolumeLabel>
|
||||
<ActionButton onClick={() => setVolume(0)}>Mute</ActionButton>
|
||||
|
||||
<BindingsControl
|
||||
bindings={bindings}
|
||||
setBindings={setBindings}
|
||||
setPaused={setPaused}
|
||||
/>
|
||||
<ActionButton onClick={restart}>Restart</ActionButton>
|
||||
<ActionButton onClick={hide}>Close</ActionButton>
|
||||
</BindingsDialog>
|
||||
);
|
||||
}
|
||||
|
||||
function StartButton({ onClick }: { onClick: () => void }) {
|
||||
return (
|
||||
<StartButtonWrapper onClick={onClick}>Press to start</StartButtonWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
73
website/app/src/Slider.tsx
Normal file
73
website/app/src/Slider.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { useRef } from "react";
|
||||
import { styled } from "styled-components";
|
||||
|
||||
const SliderWrapper = styled.div`
|
||||
padding: 1ex 0;
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
const SliderContainer = styled.div`
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 0.25ex;
|
||||
background-color: black;
|
||||
margin: auto;
|
||||
min-width: 10ex;
|
||||
`;
|
||||
|
||||
const SliderBox = styled.div<{ $proportion: number }>`
|
||||
position: absolute;
|
||||
width: 1ex;
|
||||
height: 1ex;
|
||||
top: -0.3ex;
|
||||
background-color: black;
|
||||
left: ${(props) => props.$proportion * 90}%;
|
||||
`;
|
||||
|
||||
export function Slider({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: number;
|
||||
onChange: (newValue: number) => void;
|
||||
}) {
|
||||
const slider = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||
onChange(
|
||||
event.nativeEvent.offsetX / (event.target as HTMLDivElement).offsetWidth
|
||||
);
|
||||
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
const handleDrag = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||
const sliderRef = slider.current;
|
||||
|
||||
if (!sliderRef || event.buttons !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const relativePosition =
|
||||
event.clientX - sliderRef.getBoundingClientRect().left;
|
||||
const proportion = relativePosition / sliderRef.offsetWidth;
|
||||
|
||||
const clamped = Math.min(1, Math.max(0, proportion));
|
||||
|
||||
onChange(clamped);
|
||||
};
|
||||
|
||||
return (
|
||||
<SliderWrapper ref={slider} onClick={handleClick} onMouseMove={handleDrag}>
|
||||
<SliderContainer>
|
||||
<SliderBox
|
||||
$proportion={value}
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
/>
|
||||
</SliderContainer>
|
||||
</SliderWrapper>
|
||||
);
|
||||
}
|
119
website/app/src/bindings.tsx
Normal file
119
website/app/src/bindings.tsx
Normal file
|
@ -0,0 +1,119 @@
|
|||
import { FC, useState } from "react";
|
||||
import styled from "styled-components";
|
||||
|
||||
const DefaultBindings = (): KeyBindings => {
|
||||
return {
|
||||
A: "Z",
|
||||
B: "X",
|
||||
L: "A",
|
||||
R: "S",
|
||||
Start: "ENTER",
|
||||
Select: "SHIFT",
|
||||
Up: "UP",
|
||||
Down: "DOWN",
|
||||
Left: "LEFT",
|
||||
Right: "RIGHT",
|
||||
};
|
||||
};
|
||||
|
||||
export const DefaultBindingsSet = (): Bindings => ({
|
||||
Actual: DefaultBindings(),
|
||||
Displayed: DefaultBindings(),
|
||||
});
|
||||
|
||||
export enum GbaKey {
|
||||
A = "A",
|
||||
B = "B",
|
||||
L = "L",
|
||||
R = "R",
|
||||
Up = "Up",
|
||||
Down = "Down",
|
||||
Left = "Left",
|
||||
Right = "Right",
|
||||
Start = "Start",
|
||||
Select = "Select",
|
||||
}
|
||||
|
||||
const BindingsOrder = [
|
||||
GbaKey.A,
|
||||
GbaKey.B,
|
||||
GbaKey.L,
|
||||
GbaKey.R,
|
||||
GbaKey.Up,
|
||||
GbaKey.Down,
|
||||
GbaKey.Left,
|
||||
GbaKey.Right,
|
||||
GbaKey.Start,
|
||||
GbaKey.Select,
|
||||
];
|
||||
|
||||
interface SelectButtonProps {
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
const SelectButton = styled.button<SelectButtonProps>`
|
||||
grid-column: 1;
|
||||
`;
|
||||
|
||||
const ButtonWrapper = styled.div`
|
||||
display: grid;
|
||||
margin-top: 10px;
|
||||
`;
|
||||
|
||||
export type KeyBindings = {
|
||||
[key in GbaKey]: string;
|
||||
};
|
||||
|
||||
export interface Bindings {
|
||||
Displayed: KeyBindings;
|
||||
Actual: KeyBindings;
|
||||
}
|
||||
|
||||
const toHumanName = (keyName: string) => {
|
||||
return keyName.replace("Arrow", "");
|
||||
};
|
||||
|
||||
export const BindingsControl: FC<{
|
||||
bindings: Bindings;
|
||||
setBindings: (a: Bindings) => void;
|
||||
setPaused: (pause: boolean) => void;
|
||||
}> = ({ bindings, setBindings, setPaused }) => {
|
||||
const [buttonToChange, setButtonToChange] = useState<GbaKey | null>(null);
|
||||
|
||||
const setKey = (key: string) => {
|
||||
if (buttonToChange === null) return;
|
||||
|
||||
const nextBindings = {
|
||||
Displayed: { ...bindings.Displayed },
|
||||
Actual: { ...bindings.Actual },
|
||||
};
|
||||
|
||||
nextBindings.Displayed[buttonToChange] = toHumanName(key).toUpperCase();
|
||||
nextBindings.Actual[buttonToChange] = key;
|
||||
|
||||
setButtonToChange(null);
|
||||
setBindings(nextBindings);
|
||||
setPaused(false);
|
||||
};
|
||||
|
||||
const onSelectButtonClick = (key: GbaKey) => {
|
||||
setPaused(true);
|
||||
setButtonToChange(key);
|
||||
};
|
||||
|
||||
return (
|
||||
<ButtonWrapper onKeyUp={(evt: React.KeyboardEvent) => setKey(evt.key)}>
|
||||
{BindingsOrder.map((x) => (
|
||||
<SelectButton
|
||||
onClick={() => onSelectButtonClick(x)}
|
||||
key={x}
|
||||
selected={buttonToChange === x}
|
||||
>
|
||||
{buttonToChange === x
|
||||
? `Change ${x}`
|
||||
: `${x}: ${bindings.Displayed[x]}`}
|
||||
</SelectButton>
|
||||
))}
|
||||
</ButtonWrapper>
|
||||
);
|
||||
};
|
8
website/app/src/globalStyles.ts
Normal file
8
website/app/src/globalStyles.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { createGlobalStyle } from "styled-components";
|
||||
|
||||
export const GlobalStyle = createGlobalStyle`
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
`;
|
15
website/app/src/index.tsx
Normal file
15
website/app/src/index.tsx
Normal file
|
@ -0,0 +1,15 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import { GlobalStyle } from "./globalStyles";
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById("root") as HTMLElement
|
||||
);
|
||||
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<GlobalStyle />
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
132
website/app/src/mgba.tsx
Normal file
132
website/app/src/mgba.tsx
Normal file
|
@ -0,0 +1,132 @@
|
|||
import {
|
||||
forwardRef,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import mGBA from "./vendor/mgba";
|
||||
import { KeyBindings } from "./bindings";
|
||||
import { styled } from "styled-components";
|
||||
|
||||
type Module = any;
|
||||
|
||||
interface MgbaProps {
|
||||
gameUrl: string;
|
||||
volume?: Number;
|
||||
controls: KeyBindings;
|
||||
paused: boolean;
|
||||
}
|
||||
|
||||
enum MgbaState {
|
||||
Uninitialised,
|
||||
Initialising,
|
||||
Initialised,
|
||||
}
|
||||
|
||||
const MGBA_ROM_DIRECTORY = "/data/games";
|
||||
|
||||
const MgbaCanvas = styled.canvas`
|
||||
image-rendering: pixelated;
|
||||
aspect-ratio: 240 / 160;
|
||||
width: 100%;
|
||||
object-fit: contain;
|
||||
max-height: 100%;
|
||||
`;
|
||||
|
||||
export interface MgbaHandle {
|
||||
restart: () => void;
|
||||
}
|
||||
|
||||
export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
|
||||
({ gameUrl, volume, controls, paused }, ref) => {
|
||||
const canvas = useRef(null);
|
||||
const mgbaModule = useRef<Module>({});
|
||||
|
||||
const [state, setState] = useState(MgbaState.Uninitialised);
|
||||
const [gameLoaded, setGameLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (state !== MgbaState.Initialised) return;
|
||||
(async () => {
|
||||
const game = await fetch(gameUrl);
|
||||
const gameData = await game.arrayBuffer();
|
||||
|
||||
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.loadGame(gamePath);
|
||||
mgbaModule.current.setVolume(0.1); // for some reason you have to do this or you get no sound
|
||||
setGameLoaded(true);
|
||||
})();
|
||||
}, [state, gameUrl]);
|
||||
|
||||
// init mgba
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (canvas.current === null) return;
|
||||
if (state !== MgbaState.Uninitialised) return;
|
||||
|
||||
setState(MgbaState.Initialising);
|
||||
|
||||
mgbaModule.current = {
|
||||
canvas: canvas.current,
|
||||
};
|
||||
|
||||
mGBA(mgbaModule.current).then((module: Module) => {
|
||||
mgbaModule.current = module;
|
||||
module.FSInit();
|
||||
setState(MgbaState.Initialised);
|
||||
});
|
||||
})();
|
||||
|
||||
if (state === MgbaState.Initialised)
|
||||
return () => {
|
||||
try {
|
||||
mgbaModule.current.quitGame();
|
||||
mgbaModule.current.quitMgba();
|
||||
} catch {}
|
||||
};
|
||||
}, [state]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!gameLoaded) return;
|
||||
|
||||
const controlEntries = Object.entries(controls);
|
||||
|
||||
for (const [key, value] of controlEntries) {
|
||||
const binding =
|
||||
value === "Enter"
|
||||
? "Return"
|
||||
: value.toLowerCase().replace("arrow", "").replace("key", "");
|
||||
|
||||
mgbaModule.current.bindKey(binding, key);
|
||||
}
|
||||
}, [controls, gameLoaded]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!gameLoaded) return;
|
||||
mgbaModule.current.setVolume(volume ?? 1.0);
|
||||
}, [gameLoaded, volume]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!gameLoaded) return;
|
||||
|
||||
if (paused) {
|
||||
mgbaModule.current.pauseGame();
|
||||
} else {
|
||||
mgbaModule.current.resumeGame();
|
||||
}
|
||||
}, [gameLoaded, paused]);
|
||||
|
||||
useImperativeHandle(ref, () => {
|
||||
return {
|
||||
restart: () => mgbaModule.current.quickReload(),
|
||||
};
|
||||
});
|
||||
|
||||
return <MgbaCanvas ref={canvas} />;
|
||||
}
|
||||
);
|
17
website/app/src/useAvoidItchIoScrolling.ts
Normal file
17
website/app/src/useAvoidItchIoScrolling.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { useEffect } from "react";
|
||||
|
||||
export const useAvoidItchIoScrolling = () => {
|
||||
useEffect(() => {
|
||||
const eventHandler = (e: KeyboardEvent) => {
|
||||
if ([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", eventHandler, false);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keydown", eventHandler, false);
|
||||
};
|
||||
}, []);
|
||||
};
|
29
website/app/src/useLocalStorage.hook.ts
Normal file
29
website/app/src/useLocalStorage.hook.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { useCallback, useState } from "react";
|
||||
|
||||
export const useLocalStorage = <T>(
|
||||
defaultValue: T,
|
||||
appName: string
|
||||
): [T, (newValue: T) => void] => {
|
||||
const [value, setValue] = useState(() => {
|
||||
try {
|
||||
const storageValue = localStorage.getItem(appName);
|
||||
if (storageValue) {
|
||||
return JSON.parse(storageValue);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} catch {
|
||||
return defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
const setStoredValue = useCallback((newValue: T) => {
|
||||
setValue(newValue);
|
||||
try {
|
||||
localStorage.setItem(appName, JSON.stringify(newValue));
|
||||
} catch { }
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return [value, setStoredValue];
|
||||
};
|
17
website/app/src/useOnKeyUp.hook.ts
Normal file
17
website/app/src/useOnKeyUp.hook.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { useEffect } from "react";
|
||||
|
||||
export const useOnKeyUp = (targetKey: string, callback: () => void) => {
|
||||
useEffect(() => {
|
||||
const downHandler = (evnt: KeyboardEvent) => {
|
||||
if (evnt.key === targetKey) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keyup", downHandler);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("keyup", downHandler);
|
||||
};
|
||||
}, [callback, targetKey]);
|
||||
};
|
20
website/app/tsconfig.json
Normal file
20
website/app/tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
25
website/mgba-wasm/BuildMgbaWasm
Normal file
25
website/mgba-wasm/BuildMgbaWasm
Normal file
|
@ -0,0 +1,25 @@
|
|||
FROM docker.io/emscripten/emsdk:3.1.46 as builder
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends make cmake git && \
|
||||
apt-get autoremove -y && apt-get clean
|
||||
|
||||
RUN userdel emscripten -r
|
||||
USER root
|
||||
ENV BUILD_DIR=build-wasm
|
||||
|
||||
WORKDIR /
|
||||
|
||||
RUN git clone https://github.com/thenick775/mgba.git --filter=tree:0 -b feature/wasm
|
||||
RUN mkdir /mgba/build-wasm
|
||||
WORKDIR /mgba/build-wasm
|
||||
RUN git checkout 27dede256b6de36303a87d0886f81505a0f30c28
|
||||
|
||||
|
||||
RUN emcmake cmake .. && make install DESTDIR=install
|
||||
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /mgba/build-wasm/wasm/mgba.js .
|
||||
COPY --from=builder /mgba/build-wasm/wasm/mgba.wasm .
|
||||
COPY --from=builder /mgba/build-wasm/wasm/mgba.d.ts .
|
BIN
website/site/assets/left.png
Normal file
BIN
website/site/assets/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 181 B |
BIN
website/site/assets/right.png
Normal file
BIN
website/site/assets/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 B |
54
website/site/crash/index.html
Normal file
54
website/site/crash/index.html
Normal file
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>agbrs crash backtrace</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 1em auto;
|
||||
max-width: 40em;
|
||||
padding: 0 0.62em 3.24em;
|
||||
font: 1.2em/1.62 sans-serif;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
.backtrace {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>agbrs crash backtrace viewer</h1>
|
||||
<p>This page will eventually let you view backtraces in the browser.</p>
|
||||
<p>
|
||||
For now you can copy the backtrace code here and use it with
|
||||
<code>agb-addr2line</code>
|
||||
</p>
|
||||
<p class="backtrace">
|
||||
<label for="backtrace">Backtrace:</label>
|
||||
<input id="backtrace" type="text" />
|
||||
<button id="backtraceCopy">Copy</button>
|
||||
</p>
|
||||
|
||||
<script>
|
||||
const updateBacktrace = () => {
|
||||
if (window.location.hash.length > 1) {
|
||||
backtrace.value = window.location.hash.slice(1);
|
||||
}
|
||||
};
|
||||
|
||||
updateBacktrace();
|
||||
|
||||
window.addEventListener("hashchange", updateBacktrace);
|
||||
|
||||
backtraceCopy.addEventListener("click", (evt) => {
|
||||
evt.preventDefault();
|
||||
navigator.clipboard.writeText(backtrace.value);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
125
website/site/index.html
Normal file
125
website/site/index.html
Normal file
|
@ -0,0 +1,125 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>agb - a rust framework for making Game Boy Advance games</title>
|
||||
<style>
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font: 1.2em/1.62 sans-serif;
|
||||
background-color: white;
|
||||
font-size: 1.5rem;
|
||||
line-height: 1.6;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 0;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3 {
|
||||
line-height: 1.2;
|
||||
}
|
||||
.gameDisplay > div {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.gameDisplay {
|
||||
height: calc(min(480px, 40vh, calc(100vw / 3)));
|
||||
max-width: 100vw;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.gameDisplay .imageWrapper {
|
||||
aspect-ratio: 15 / 31;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.gameDisplay .imageWrapper > img {
|
||||
height: 100%;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
|
||||
.gameDisplay iframe {
|
||||
border: 0;
|
||||
height: 100%;
|
||||
max-width: 100vw;
|
||||
aspect-ratio: 240 / 160;
|
||||
}
|
||||
|
||||
header,
|
||||
.help {
|
||||
max-width: 60%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
margin-block-end: 40px;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: #f5755e;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.links {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 40px;
|
||||
margin-bottom: 40px;
|
||||
max-width: 40rem;
|
||||
}
|
||||
|
||||
.links > a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
background-color: #fad288;
|
||||
border: solid #fad288 2px;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.links > a:hover {
|
||||
border: solid black 2px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>agb - a rust framework for making Game Boy Advance games</h1>
|
||||
</header>
|
||||
<section>
|
||||
<div class="gameDisplay">
|
||||
<div>
|
||||
<div class="imageWrapper"><img src="assets/left.png" /></div>
|
||||
<iframe
|
||||
onload="this.contentWindow.focus()"
|
||||
src="mgba/index.html#/assets/combo.gba"
|
||||
></iframe>
|
||||
<div class="imageWrapper"><img src="assets/right.png" /></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="help">
|
||||
<p>
|
||||
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
|
||||
Game Boy Advance games made using agb, you can press left or right on
|
||||
the main menu to switch game.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="red">
|
||||
<div class="links">
|
||||
<a href="https://github.com/agbrs/agb">GitHub</a>
|
||||
<a href="book/">Book</a>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue