Skip to content

Commit 9907d28

Browse files
committed
feat: Add support for generating RPC methods
Add networking demo.
1 parent 598cd82 commit 9907d28

27 files changed

+979
-12
lines changed

example/2d_tutorial/project.godot

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="simple"
1414
run/main_scene="res://main.tscn"
15-
config/features=PackedStringArray("4.3", "Forward Plus")
15+
config/features=PackedStringArray("4.4", "Forward Plus")
1616
config/icon="res://icon.svg"
1717

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

2626
move_right={
2727
"deadzone": 0.5,
28-
"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)
28+
"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)
2929
]
3030
}
3131
move_left={
3232
"deadzone": 0.5,
33-
"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)
33+
"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)
3434
]
3535
}
3636
move_up={
3737
"deadzone": 0.5,
38-
"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)
38+
"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)
3939
]
4040
}
4141
move_down={
4242
"deadzone": 0.5,
43-
"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)
43+
"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)
4444
]
4545
}

example/2d_tutorial/src/lib/player.dart

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Player extends Area2D {
7171
setPosition(position);
7272
}
7373

74+
@GodotRpc()
7475
void start(Vector2 pos) {
7576
setPosition(pos);
7677
show();

example/2d_tutorial/src/pubspec.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ packages:
199199
path: "../../../src/dart/godot_dart"
200200
relative: true
201201
source: path
202-
version: "0.3.0"
202+
version: "0.6.2"
203203
godot_dart_build:
204204
dependency: "direct dev"
205205
description:
206206
path: "../../../src/dart/godot_dart_build"
207207
relative: true
208208
source: path
209-
version: "0.2.0"
209+
version: "0.4.0"
210210
graphs:
211211
dependency: transitive
212212
description:
@@ -480,4 +480,4 @@ packages:
480480
source: hosted
481481
version: "3.1.2"
482482
sdks:
483-
dart: ">=3.5.0-259.0.dev <4.0.0"
483+
dart: ">=3.5.0 <4.0.0"

example/networking-demo/.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

example/networking-demo/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Godot 4+ specific ignores
2+
.godot/
3+
/android/
4+
5+
# Ignore built libraries
6+
*.dll
7+
*.lib
8+
*.dylib
9+
*.pdb
10+
*.exp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[configuration]
2+
3+
entry_symbol = "godot_dart_init"
4+
compatibility_minimum = 4.2
5+
6+
[icons]
7+
8+
DartScript = "res://logo_dart.svg"
9+
10+
[libraries]
11+
12+
windows.x86_64 = "godot_dart.dll"
13+
linux.x86_64 = "libgodot_dart.so"
14+
macos.arm64 = "libgodot_dart.dylib"
15+

example/networking-demo/icon.svg

+1
Loading
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://b0g1bchdfioi2"
6+
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://icon.svg"
14+
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

example/networking-demo/logo_dart.svg

+23
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://bvvbwm6rscs1r"
6+
path="res://.godot/imported/logo_dart.svg-7d78e4990ae1b9cb0a988a5863e5eb62.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://logo_dart.svg"
14+
dest_files=["res://.godot/imported/logo_dart.svg-7d78e4990ae1b9cb0a988a5863e5eb62.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

example/networking-demo/project.godot

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="Networking Demo"
14+
run/main_scene="res://world.tscn"
15+
config/features=PackedStringArray("4.4", "Forward Plus")
16+
config/icon="res://icon.svg"
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build output.
6+
build/
7+
8+
# Don't check in generated files
9+
*.g.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include: package:lints/recommended.yaml
2+
3+
# Uncomment the following section to specify additional rules.
4+
5+
analyzer:
6+
exclude:
7+
- lib/src/gdextension_bindings.dart
8+
language:
9+
strict-casts: true
10+
strict-raw-types: true
11+
12+
linter:
13+
rules:
14+
prefer_single_quotes: true
15+
prefer_relative_imports: true
16+
unawaited_futures: true
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:godot_dart/godot_dart.dart';
2+
3+
part 'world.g.dart';
4+
5+
@GodotScript()
6+
class World extends Node2D {
7+
static TypeInfo get sTypeInfo => _$WorldTypeInfo();
8+
@override
9+
TypeInfo get typeInfo => sTypeInfo;
10+
11+
World() : super();
12+
13+
World.withNonNullOwner(super.owner) : super.withNonNullOwner();
14+
15+
static const port = 12912;
16+
17+
final enetPeer = ENetMultiplayerPeer();
18+
late TextEdit _messages;
19+
late LineEdit _userNameBox;
20+
late LineEdit _line;
21+
22+
String username = 'Unknown';
23+
24+
@override
25+
void vReady() {
26+
_line = getNodeT<LineEdit>('Line')!;
27+
_messages = getNodeT<TextEdit>('Messages')!;
28+
_userNameBox = getNodeT<LineEdit>('Username')!;
29+
}
30+
31+
@GodotExport()
32+
void onHostPressed() {
33+
enetPeer.createServer(port);
34+
35+
getMultiplayer()!.setMultiplayerPeer(enetPeer);
36+
_joined();
37+
}
38+
39+
@GodotExport()
40+
void onJoinPressed() {
41+
enetPeer.createClient('127.0.0.1', port);
42+
getMultiplayer()!.setMultiplayerPeer(enetPeer);
43+
_joined();
44+
}
45+
46+
@GodotRpc(mode: MultiplayerAPIRPCMode.rpcModeAnyPeer, callLocal: true)
47+
void messageRpc(String username, String data) {
48+
final newText = _messages.getText() + '$username: $data\n';
49+
_messages.setText(newText);
50+
}
51+
52+
@GodotExport()
53+
void onSendPressed() {
54+
final line = _line.getText();
55+
_line.setText('');
56+
$rpc.messageRpc(username, line);
57+
}
58+
59+
void _joined() {
60+
username = _userNameBox.getText();
61+
if (username.isEmpty) {
62+
username = 'Unknown';
63+
}
64+
getNodeT<Button>('Host')?.hide();
65+
getNodeT<Button>('Join')?.hide();
66+
getNodeT<Control>('Username')?.hide();
67+
}
68+
}

example/networking-demo/src/main.dart

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'godot_dart_scripts.g.dart';
2+
3+
void main() {
4+
attachScriptResolver();
5+
}

0 commit comments

Comments
 (0)