Skip to content

Commit f06097d

Browse files
committed
Update documentation, CHANGELOG, and versions.
Also update template.
1 parent d99bf6c commit f06097d

File tree

7 files changed

+52
-24
lines changed

7 files changed

+52
-24
lines changed

README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ And I want to use it in Godot.
1010

1111
> [!NOTE]
1212
> This extension is compatible with Godot 4.2+. Global Classes require Godot 4.3
13+
>
14+
> There are major changes to the entire library starting in `godot_dart` 0.10.0, which uses Dart 3.8.
15+
> Previously, `godot_dart` upgraded to 0.9.0 without these changes and is therefore broken.
1316
1417

1518
Here's a list of planned features and work still to be done ( ✅ - Seems to be
@@ -68,6 +71,7 @@ part 'simple_script.g.dart';
6871
@GodotScript()
6972
class SimpleScript extends Sprite2D {
7073
// Return the type info that was generated...
74+
@pragma('vm:entry-point')
7175
static TypeInfo get sTypeInfo => _$SimpleScriptTypeInfo();
7276
// And provide an instance method to get the type info
7377
@override
@@ -159,29 +163,34 @@ These signal connections are automatically cleaned up if the target supplied to
159163

160164
## Dart classes as Extensions
161165

162-
Here's a Simple example class that can be used as an extension.
166+
Dart classes as extensions have had major changes in `godot_dart` 0.10.0, and are currently a work in progress. Their setup is basically the same as Scripts, except all of the type registration must be done manually.
163167

164168
```dart
165-
class Simple extends Sprite2D {
169+
class SimpleTestNode extends Sprite2D {
166170
// Create a static `sTypeInfo`. This is required for various Dart methods
167171
// implemented in C++ to gather information about your type.
168-
static late TypeInfo sTypeInfo = TypeInfo(
169-
Simple,
170-
StringName.fromString('Simple'),
171-
parentClass: StringName.fromString('Sprite2D'),
172-
// a vTable getter is required for classes that will be used from extensions.
173-
// If you are not adding any virtual functions, just return the base class's vTable.
174-
vTable: Sprite2D.sTypeInfo.vTable;
172+
static final sTypeInfo = ExtensionTypeInfo<SimpleTestNode>(
173+
className: StringName.fromString('SimpleTestNode'),
174+
parentTypeInfo: Node.sTypeInfo,
175+
nativeTypeName: StringName.fromString('Node'),
176+
isRefCounted: Node.sTypeInfo.isRefCounted,
177+
constructObjectDefault: () => SimpleTestNode(),
178+
constructFromGodotObject: (owner) => SimpleTestNode.withNonNullOwner(owner),
175179
);
176180
// An override of [typeInfo] is required. This is how
177181
// the bindings understand the what types it's looking at.
178182
@override
179-
TypeInfo get typeInfo => sTypeInfo;
180-
181-
double _timePassed = 0.0;
183+
ExtensionTypeInfo<SimpleTestNode> get typeInfo => SimpleTestNode.sTypeInfo;
182184
183185
// Parameterless constructor is required and must call super()
184186
Simple() : super();
187+
188+
// Required to create with an owner, though this is not called for Extension classes
189+
SimpleTestNode.withNonNullOwner(super.owner) : super.withNonNullOwner();
190+
191+
double _timePassed = 0.0;
192+
193+
int maxSpeed = 12559;
185194
186195
// All virtual functions from Godot should be available, and start
187196
// with a v instead of an underscore.
@@ -196,10 +205,18 @@ class Simple extends Sprite2D {
196205
setPosition(newPosition);
197206
}
198207
199-
// The simplest way to bind your class it to create a static function to
200-
// bind it to Godot. The name doesn't matter
201-
static void bind() {
202-
GDNativeInterface.bindClass(Simple);
208+
// The simplest way to bind your class it to create a static function to bind all properties to Godot, and make sure to add it to the type resolver
209+
static void bind(TypeResolver typeResolver) {
210+
typeResolver.addType(sTypeInfo);
211+
GDNativeInterface.bindClass(SimpleTestNode.sTypeInfo);
212+
GDNativeInterface.addProperty(
213+
SimpleTestNode.sTypeInfo,
214+
DartPropertyInfo<SimpleTestNode, int>(
215+
typeInfo: PrimitiveTypeInfo.forType(int)!,
216+
name: 'maxSpeed',
217+
getter: (self) => self.maxSpeed,
218+
setter: (self, value) => self.maxSpeed = value),
219+
);
203220
}
204221
}
205222
```
@@ -212,7 +229,9 @@ These classes need to be registered to Godot in `main.dart`:
212229

213230
```dart
214231
void main() {
215-
Simple.bind();
232+
attachScriptResolver();
233+
234+
SimpleTestNode.bind(TypeResolver.instance);
216235
}
217236
```
218237

src/assets/src/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ environment:
88

99
dependencies:
1010
ffi: ^2.0.1
11-
godot_dart: ^0.9.0
11+
godot_dart: ^0.10.0
1212
collection: ^1.17.2
1313

1414
dev_dependencies:
1515
lints: ^2.0.0
1616
build_runner: ^2.3.3
17-
godot_dart_build: ^0.7.0
17+
godot_dart_build: ^0.8.0

src/cpp/editor/dart_templates.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ const char *git_ignore_template = "# Files and directories created by pub\n"
3838
"*.g.dart\n"
3939
"\n";
4040

41-
4241
const char *dart_script = "import 'package:godot_dart/godot_dart.dart';\n"
4342
"\n"
4443
"part '__FILE_NAME__.g.dart';\n"
4544
"\n"
4645
"@GodotScript()\n"
4746
"class __CLASS_NAME__ extends __BASE_CLASS__ {\n"
47+
" @pragma('vm:entry-point')"
4848
" static TypeInfo get sTypeInfo => _$__CLASS_NAME__TypeInfo();\n"
4949
" @override\n"
5050
" TypeInfo get typeInfo => sTypeInfo;\n"
5151
"\n"
5252
" __CLASS_NAME__() : super();\n"
5353
"\n"
54-
" @pragma('vm:entry-point')"
5554
" __CLASS_NAME__.withNonNullOwner(super.owner)\n"
5655
" :super.withNonNullOwner();\n"
5756
"\n"

src/dart/godot_dart/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.10.0
2+
3+
- BREAKING: Fix extension to work with more restrictive native calls in Dart 3.8.
4+
- For scripts, `godot_dart_build` should do most migration for you, but you need to add `@pragma('vm:entry-point')` onto your declaration for `sTypeInfo` in all script classes
5+
- Extension classes very different, and it is recommended to avoid using them for now.
6+
17
## 0.9.0
28

39
- Add type safe `SignalX` objects supporting automatic registering / deregistering.

src/dart/godot_dart/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: godot_dart
22
description: Dart bindings for the Godot game engine
33
repository: https://github.com/fuzzybinary/godot_dart
4-
version: 0.9.0
4+
version: 0.10.0
55

66
environment:
77
sdk: '>=3.6.0 <4.0.0'

src/dart/godot_dart_build/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.0
2+
3+
- BREAKING: Major changes to support more restrictive native calls in Dart 3.8.
4+
15
## 0.7.0
26

37
- Add the ability to use @GodotProperty on getters.

src/dart/godot_dart_build/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: godot_dart_build
22
description: build_runner interface for simplifying binding to Godot
33
repository: https://github.com/fuzzybinary/godot_dart
4-
version: 0.7.0
4+
version: 0.8.0
55

66
environment:
77
sdk: '>=3.6.0 <4.0.0'
@@ -14,7 +14,7 @@ dependencies:
1414
build: ^2.0.0
1515
build_config: ^1.1.1
1616
source_gen: ^1.3.2
17-
godot_dart: '>=0.9.0<1.0.0'
17+
godot_dart: '>=0.10.0<1.0.0'
1818
code_builder: ^4.5.0
1919
dart_style: ^2.3.1
2020
glob: ^2.1.2

0 commit comments

Comments
 (0)