Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/SDKTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tabs } from 'nextra/components'

export function SDKTabs({ children }: { children: React.ReactNode }) {
return <Tabs items={["TypeScript", "Unity (C#)", "Defold (Lua)", "Haxe"]} storageKey='sdk-tabs'>
return <Tabs items={["TypeScript", "Unity (C#)", "Defold (Lua)", "Haxe", "Godot (GDScript)"]} storageKey='sdk-tabs'>
{children}
</Tabs>
}
6 changes: 6 additions & 0 deletions components/icons/platforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export const wechat = (props: IconProps = {}) => <Image
width={0} height={0} style={{ width: props.width || '32px', height: 'auto', display: 'inline-block', marginRight: props.marginRight || '0px' }}
alt="WeChat" />

export const godot = (props: IconProps = {}) => <Image
className="platform-icon"
src={require('../../images/icons/godot.png')}
width={0} height={0} style={{ width: props.width || '32px', height: 'auto', display: 'inline-block', marginRight: props.marginRight || '0px' }}
alt="Godot" />

/**
* BRANDS
*/
Expand Down
Binary file added images/icons/godot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion pages/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cards, Tabs, Steps } from 'nextra/components'
import { javascript, typescript, react, unity, defold, construct3, cocos, haxe, discord, wechat } from '../components/icons/platforms'
import { javascript, typescript, react, unity, defold, construct3, cocos, haxe, discord, wechat, godot } from '../components/icons/platforms'
import { SyncIcon, RowsIcon } from '@primer/octicons-react'

# Getting Started
Expand All @@ -13,6 +13,7 @@ Colyseus is unopinionated on the game engine or framework you use in the fronten
<Cards.Card icon={javascript()} title="JavaScript" href="/getting-started/javascript" />
<Cards.Card icon={react()} title="React" href="/getting-started/react" />
<Cards.Card icon={unity()} title="Unity" href="/getting-started/unity" />
<Cards.Card icon={godot()} title="Godot" href="/getting-started/godot" />
<Cards.Card icon={defold()} title="Defold Engine" href="/getting-started/defold" />
<Cards.Card icon={construct3()} title="Construct 3" href="/getting-started/construct3" />
<Cards.Card icon={cocos()} title="Cocos Creator" href="/getting-started/cocos" />
Expand Down
3 changes: 2 additions & 1 deletion pages/getting-started/_meta.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { javascript, typescript, react, unity, defold, construct3, cocos, haxe, discord, wechat } from '../../components/icons/platforms'
import { javascript, typescript, react, unity, defold, construct3, cocos, haxe, discord, wechat, godot } from '../../components/icons/platforms'

export default {
"typescript": { title: <span>{typescript({ width: '19px', marginRight: '2px' })} TypeScript</span> },
"javascript": { title: <span>{javascript({ width: '19px', marginRight: '2px' })} JavaScript</span> },
"react": { title: <span>{react({ width: '19px', marginRight: '2px' })} React</span> },
"unity": { title: <span>{unity({ width: '19px', marginRight: '2px' })} Unity</span> },
"godot": { title: <span>{godot({ width: '19px', marginRight: '2px' })} Godot</span> },
"defold": { title: <span>{defold({ width: '19px', marginRight: '2px' })} Defold</span> },
"construct3": { title: <span>{construct3({ width: '19px', marginRight: '2px' })} Construct 3</span> },
"cocos": { title: <span>{cocos({ width: '19px', marginRight: '2px' })} Cocos Creator</span> },
Expand Down
146 changes: 146 additions & 0 deletions pages/getting-started/godot.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
title: "Godot Engine"
---
import { Callout } from "nextra/components";
import { DevicesIcon } from '@primer/octicons-react'

# Godot Engine

<Callout type="warning">
The GDExtension is **very experimental**, and may not be stable. Please [report any issues you find](https://github.com/colyseus/native-sdk/issues/8).
</Callout>

We are experimenting with our shared [Colyseus Native SDK](https://github.com/colyseus/native-sdk) for cross-platform support for Colyseus across different engines. Godot is the first engine to support this. The work on Native SDK is still in progress, so expect some breaking changes as we go.

## Platforms

- Desktop (Windows, macOS, Linux)
- iOS
- Android
- Web (HTML5)

## Installation

- Download the latest Godot SDK from [GitHub Releases](https://github.com/colyseus/native-sdk/releases?q=godot+sdk&expanded=true)
- Extract the addons folder into your Godot project root
- Enable the plugin in **Project Settings** → **Plugins**

## Web Builds

When exporting your project via **Project** → **Export** → **Web (Runnable)**, make sure to enable **Extensions Support**.

![Settings](/getting-started/godot-web.png)

## SDK API

Navigate to the [<DevicesIcon/> Client SDK](/sdk) for API Reference, and select the **Godot** tab.

## Quick Example / Reference

This example shows how to connect to a room, listen for state changes, send messages and leave the room.

```gdscript filename="Network.gd"
extends Node

var client: ColyseusClient
var room: ColyseusRoom
var callbacks: ColyseusCallbacks

func _ready():
# Create and connect client
client = Colyseus.create_client()
client.set_endpoint("ws://localhost:2567")

print("Connecting to: ", client.get_endpoint())

# Join or create a room
room = client.join_or_create("test_room")

# Connect signals
if room:
room.joined.connect(_on_room_joined)
room.state_changed.connect(_on_state_changed)
room.message_received.connect(_on_message_received)
room.error.connect(_on_room_error)
room.left.connect(_on_room_left)

func _process(delta):
# Poll the client for messages
# (Only required for web builds)
ColyseusClient.poll()

func _on_room_joined():
print("✓ Joined room: ", room.get_id())
print(" Session ID: ", room.get_session_id())
print(" Room name: ", room.get_name())

# Get callbacks container for the room
callbacks = Colyseus.callbacks(room)

# Listen to root state property changes
callbacks.listen("currentTurn", _on_turn_change)

# Listen to collection additions/removals
callbacks.on_add("players", _on_player_add)
callbacks.on_remove("players", _on_player_remove)

# Send a message
var message = "Hello from Godot!".to_utf8_buffer()
room.send_message("add_item", {"name": "MY NEW ITEM"})

func _on_turn_change(current_value, previous_value):
print("↻ Turn changed: ", previous_value, " -> ", current_value)

func _on_player_add(player: Dictionary, key: String):
print("+ Player joined: ", key)
# Listen to nested schema properties
callbacks.listen(player, "hp", _on_player_hp_change)
# Listen to nested collections
callbacks.on_add(player, "items", _on_item_add)

func _on_player_remove(player: Dictionary, key: String):
print("- Player left: ", key)

func _on_player_hp_change(current_hp, previous_hp):
print(" HP changed: ", previous_hp, " -> ", current_hp)

func _on_item_add(item: Dictionary, index: int):
print(" Item added at index: ", index, " -> ", item)

callbacks.listen(item, "name", func(name, _prev):
print(" Item name: ", name))

func _on_state_changed():
print("↻ Room state changed")
# Access state as Dictionary
var state = room.get_state()
if state:
print(" State: ", state)

func _on_message_received(type: Variant, data: Variant):
# type is the message type (String or int for numeric types)
print("✉ Message received - type: ", type, " data: ", data)

func _on_room_error(code: int, message: String):
printerr("✗ Room error [", code, "]: ", message)

func _on_room_left(code: int, reason: String):
print("← Left room [", code, "]: ", reason)

func _exit_tree():
# Clean up when node is removed
if room and room.has_joined():
room.leave()
```

### State Schema Codegen

It is not required to use the State Schema Codegen, but it is recommended to use it to get type safety and autocomplete in your IDE.

```sh filename="Terminal"
npx schema-codegen src/rooms/schema/* --gdscript --bundle --output ../colyseus/schema/
```

<Callout type="info">
See the full [State Schema Codegen documentation](/sdk/state-sync-callbacks#frontend-schema-generation) for more options and details.
</Callout>
Loading