# GB Studio

Export Game Boy games built in GB Studio to the web and ship them to Wavedash.

Source: https://docs.wavedash.com/engines/gbstudio

<GithubLink href="https://github.com/wvdsh/examples/tree/main/example-gbstudio" />
<PlaytestLink href="https://wavedash.com/playtest/gb-studio-example/182447db-f933-4c54-8ab1-c4925deee175" />

[GB Studio](https://www.gbstudio.dev/) builds Game Boy ROMs and bundles them with the [binjgb](https://github.com/binji/binjgb) emulator for web export, producing a self-contained `build/web/` folder you can ship to Wavedash.

## Export the game

1. Open your `.gbsproj` file in GB Studio.
2. **Game → Export As → Export Web**
3. GB Studio writes the export to `build/web/` inside your project, containing `index.html`, `binjgb.js`, `binjgb.wasm`, the compiled `rom`, and supporting JS/CSS.

Point `upload_dir` at `./build/web`.

## SDK integration

GB Studio's `.gb` ROMs can't call JavaScript directly — the SDK has to live in the web shell that hosts the emulator. GB Studio has a **Custom HTML Head** field in project settings that gets embedded into every web export, which is exactly what we want.

1. In GB Studio, open **Project Settings → Custom HTML Head** (or edit `project/settings.gbsres` and set `customHead`).
2. Paste:

    <Urgent>
    **Calling `Wavedash.init()` is required.** Your game stays hidden behind the Wavedash loading screen until you do. Call it once your game is ready to play.
    </Urgent>

    ```html
    <script>
      try {
        const Wavedash = window.Wavedash;
        Wavedash.updateLoadProgressZeroToOne(0.3);  // shell parsed
        Wavedash.updateLoadProgressZeroToOne(0.7);  // emulator ready
        Wavedash.updateLoadProgressZeroToOne(1.0);
        Wavedash.init({ debug: true });
      } catch (e) { console.warn("[wavedash] init failed:", e); }
    </script>
    ```

3. Re-export. GB Studio will now inline the script inside `<head>` of `build/web/index.html`, and it'll stick across future exports.

<Note>
GB Studio caches the project in memory. If you edit `settings.gbsres` directly on disk while GB Studio is open, close and reopen the project before exporting so it picks up the change.
</Note>

## wavedash.toml

```toml
game_id = "YOUR_GAME_ID_HERE"
upload_dir = "./build/web"
entrypoint = "index.html"
```

## Controls

GB Studio's web export maps Game Boy buttons to the keyboard by default:

| Game Boy button | Keyboard |
|---|---|
| A | `Z` / `Alt` / `J` |
| B | `X` / `Control` / `K` |
| Start | `Enter` |
| Select | `Shift` |
| D-pad | Arrow keys or `WASD` |

You can override these in **Project Settings → Custom Controls**.
