# Godot

Drop the Wavedash add-on into your Godot project and export for web.

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

Copy the Godot SDK into your project, register an autoload, and export for web. GDScript calls mirror the JavaScript SDK through the built-in JavaScriptBridge.

<GithubLink href="https://github.com/wvdsh/sdk-godot" label="View the SDK on GitHub" />
<PlaytestLink href="https://wavedash.com/playtest/godot-example/b1931c79-6fc3-4f6b-94ee-8e918d7f3f11" />

## Install the SDK

<Tabs>
  <Tab title="AssetStore (Recommended)">
    1. Open the project you want to add the SDK to.
    2. In the **AssetStore** tab at the top of the editor (labeled **AssetLib** in Godot 4.4 and earlier), search for **"Wavedash SDK"**, then click **Install**.
    3. Enable the plugin in **Project > Project Settings > Plugins** by ticking **WavedashGodot**.
  </Tab>
  <Tab title="Manual (GitHub)">
    1. Download the [`addons/wavedash`](https://github.com/wvdsh/sdk-godot) folder from GitHub.
    2. Copy it to `res://addons/wavedash/` in your project.
    3. Enable the plugin in **Project > Project Settings > Plugins** by ticking **WavedashGodot**.
  </Tab>
</Tabs>

<Note>
Enabling the plugin registers `WavedashSDK` as an autoload singleton automatically. Autoload ordering matters: If any of your own autoloads use `WavedashSDK` at startup, open **Project > Project Settings > Globals > Autoload** and drag **WavedashSDK** above them so it loads first.
</Note>

## Web export settings

1. Add a **Web** export preset in **Project > Export...**
2. Enable **Threads support** and **VRAM texture compression** as needed
3. Export to the folder you reference as `upload_dir`

## Use the SDK from GDScript

<Urgent>
**Calling `init()` is required.** It opts your game into Wavedash platform features and is how the SDK confirms you're set up. Call it once your game is ready to play.
</Urgent>

```gdscript
func _ready():
    WavedashSDK.backend_connected.connect(_on_connected)
    WavedashSDK.init({"debug": true})

func _on_connected(_payload):
    print("Playing as: ", WavedashSDK.get_username())
```

### Async calls: `await` or callbacks

Every async `WavedashSDK.*` function returns the response and also emits a matching signal (e.g. `post_leaderboard_score` → `posted_leaderboard_score`). Pick whichever style suits your code — use `await` for straight-line flow, or connect a callback to the signal.

Responses come back as a `Dictionary` with `success`, `data`, and `message` keys:

```gdscript
# Option A: await the return value
func post_score_awaited(leaderboard_id: String, value: int):
    var response = await WavedashSDK.post_leaderboard_score(leaderboard_id, value, true)
    if response.success:
        print("Rank: ", response.data.globalRank)

# Option B: connect once, handle responses in a callback
func _ready():
    WavedashSDK.posted_leaderboard_score.connect(_on_score_posted)

func post_score(leaderboard_id: String, value: int):
    WavedashSDK.post_leaderboard_score(leaderboard_id, value, true)

func _on_score_posted(response):
    if response.success:
        print("Rank: ", response.data.globalRank)
```

## wavedash.toml

```toml
game_id = "YOUR_GAME_ID_HERE"
upload_dir = "./exports/web"

[godot]
version = "4.5-stable"
```
