Skip to content

Commit

Permalink
feat: Add support for generating RPC methods
Browse files Browse the repository at this point in the history
Add networking demo.
  • Loading branch information
fuzzybinary committed Nov 24, 2024
1 parent 598cd82 commit 9907d28
Show file tree
Hide file tree
Showing 27 changed files with 979 additions and 12 deletions.
10 changes: 5 additions & 5 deletions example/2d_tutorial/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="simple"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"

[display]
Expand All @@ -25,21 +25,21 @@ window/stretch/mode="canvas_items"

move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-3,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-3,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-3,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-3,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
1 change: 1 addition & 0 deletions example/2d_tutorial/src/lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Player extends Area2D {
setPosition(position);
}

@GodotRpc()
void start(Vector2 pos) {
setPosition(pos);
show();
Expand Down
6 changes: 3 additions & 3 deletions example/2d_tutorial/src/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ packages:
path: "../../../src/dart/godot_dart"
relative: true
source: path
version: "0.3.0"
version: "0.6.2"
godot_dart_build:
dependency: "direct dev"
description:
path: "../../../src/dart/godot_dart_build"
relative: true
source: path
version: "0.2.0"
version: "0.4.0"
graphs:
dependency: transitive
description:
Expand Down Expand Up @@ -480,4 +480,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.5.0-259.0.dev <4.0.0"
dart: ">=3.5.0 <4.0.0"
4 changes: 4 additions & 0 deletions example/networking-demo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*]
charset = utf-8
2 changes: 2 additions & 0 deletions example/networking-demo/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf
10 changes: 10 additions & 0 deletions example/networking-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Godot 4+ specific ignores
.godot/
/android/

# Ignore built libraries
*.dll
*.lib
*.dylib
*.pdb
*.exp
15 changes: 15 additions & 0 deletions example/networking-demo/godot_dart.gdextension
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[configuration]

entry_symbol = "godot_dart_init"
compatibility_minimum = 4.2

[icons]

DartScript = "res://logo_dart.svg"

[libraries]

windows.x86_64 = "godot_dart.dll"
linux.x86_64 = "libgodot_dart.so"
macos.arm64 = "libgodot_dart.dylib"

1 change: 1 addition & 0 deletions example/networking-demo/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions example/networking-demo/icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b0g1bchdfioi2"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
23 changes: 23 additions & 0 deletions example/networking-demo/logo_dart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions example/networking-demo/logo_dart.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bvvbwm6rscs1r"
path="res://.godot/imported/logo_dart.svg-7d78e4990ae1b9cb0a988a5863e5eb62.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://logo_dart.svg"
dest_files=["res://.godot/imported/logo_dart.svg-7d78e4990ae1b9cb0a988a5863e5eb62.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
16 changes: 16 additions & 0 deletions example/networking-demo/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=5

[application]

config/name="Networking Demo"
run/main_scene="res://world.tscn"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"
9 changes: 9 additions & 0 deletions example/networking-demo/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/

# Don't check in generated files
*.g.dart
16 changes: 16 additions & 0 deletions example/networking-demo/src/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

analyzer:
exclude:
- lib/src/gdextension_bindings.dart
language:
strict-casts: true
strict-raw-types: true

linter:
rules:
prefer_single_quotes: true
prefer_relative_imports: true
unawaited_futures: true
68 changes: 68 additions & 0 deletions example/networking-demo/src/lib/world.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:godot_dart/godot_dart.dart';

part 'world.g.dart';

@GodotScript()
class World extends Node2D {
static TypeInfo get sTypeInfo => _$WorldTypeInfo();
@override
TypeInfo get typeInfo => sTypeInfo;

World() : super();

World.withNonNullOwner(super.owner) : super.withNonNullOwner();

static const port = 12912;

final enetPeer = ENetMultiplayerPeer();
late TextEdit _messages;
late LineEdit _userNameBox;
late LineEdit _line;

String username = 'Unknown';

@override
void vReady() {
_line = getNodeT<LineEdit>('Line')!;
_messages = getNodeT<TextEdit>('Messages')!;
_userNameBox = getNodeT<LineEdit>('Username')!;
}

@GodotExport()
void onHostPressed() {
enetPeer.createServer(port);

getMultiplayer()!.setMultiplayerPeer(enetPeer);
_joined();
}

@GodotExport()
void onJoinPressed() {
enetPeer.createClient('127.0.0.1', port);
getMultiplayer()!.setMultiplayerPeer(enetPeer);
_joined();
}

@GodotRpc(mode: MultiplayerAPIRPCMode.rpcModeAnyPeer, callLocal: true)
void messageRpc(String username, String data) {
final newText = _messages.getText() + '$username: $data\n';
_messages.setText(newText);
}

@GodotExport()
void onSendPressed() {
final line = _line.getText();
_line.setText('');
$rpc.messageRpc(username, line);
}

void _joined() {
username = _userNameBox.getText();
if (username.isEmpty) {
username = 'Unknown';
}
getNodeT<Button>('Host')?.hide();
getNodeT<Button>('Join')?.hide();
getNodeT<Control>('Username')?.hide();
}
}
5 changes: 5 additions & 0 deletions example/networking-demo/src/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'godot_dart_scripts.g.dart';

void main() {
attachScriptResolver();
}
Loading

0 comments on commit 9907d28

Please sign in to comment.