Skip to content

Commit 55bd9c7

Browse files
committed
Update documentation and templates
1 parent c16626e commit 55bd9c7

File tree

22 files changed

+102
-154
lines changed

22 files changed

+102
-154
lines changed

docs/src/doc/getting-started/your-first-class.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ Let's create a file `src/main/kotlin/com/yourcompany/game/Simple.kt` with the fo
44
package com.yourcompany.game
55

66
import godot.Node3D
7-
import godot.annotation.RegisterClass
8-
import godot.annotation.RegisterFunction
7+
import godot.annotation.GodotScript
98
import godot.global.GD
109

11-
@RegisterClass
10+
@GodotScript
1211
class Simple: Node3D() {
1312

14-
@RegisterFunction
1513
override fun _ready() {
1614
GD.print("Hello world!")
1715
}
1816
}
1917
```
2018

21-
The [classes](../user-guide/classes.md) section covers in details what we did here, but for now `@RegisterClass` will register the class to Godot. Now we can trigger a build.
19+
The [classes](../user-guide/classes.md) section covers in details what we did here, but for now `@GodotScript` will register the class to Godot. Now we can trigger a build.
2220

2321
```shell
2422
./gradlew build

docs/src/doc/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Also consider the [API Differences](user-guide/api-differences.md) section for g
2626
and limitations which will not be or cannot be adressed in the near forseable future or ever.
2727

2828
- Each registered constructor must have a unique number of arguments, constructor overloading is not yet supported.
29-
- No tool mode (you can set it already in the `@RegisterClass` annotation but it has no effect yet).
29+
- No tool mode (you can already use the `@Tool` annotation, but it has no effect yet).
3030
- No addon support, you cannot use Godot Kotlin/JVM to write plugins and addons yet (you can however [write libraries](develop-libraries/introduction.md) with godot specific code).
3131
- Web is currently not supported. See [Supported platforms](#supported-platforms) to see what platforms we currently support
3232

docs/src/doc/user-guide/advanced/abstract-classes.md

+6-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You can define a abstract class and register it's members the same way as you do
77
Under the hood, we only register your normal classes, and let them register all members your abstract class defines.
88

99
!!! info
10-
For this reason, the `@RegisterClass` annotation is optional for abstract classes.
10+
For this reason, the `@GodotScript` annotation is optional for abstract classes.
1111

1212
!!! warning
1313
As in Kotlin, you cannot instantiate abstract classes directly from any other scripting language like GDScript! In fact, godot does not even know (or care) that your abstract class exists.
@@ -17,37 +17,32 @@ Under the hood, we only register your normal classes, and let them register all
1717
Abstract class definition:
1818

1919
```kotlin
20-
// register class annotation is optional for abstract classes
20+
// @GodotScript annotation is optional for abstract classes
2121
abstract class AbstractClassInheritanceParent: Node() {
2222

2323
@Export
24-
@RegisterProperty
2524
var registeredExportedPropertyInAbstractClass = false
2625

27-
@RegisterSignal
2826
val signalInAbstractClass by signal<String>("blubb")
2927

30-
@RegisterFunction
28+
@GodotMember
3129
fun functionInAbstractClassWithDefaultImplementation() {
3230
// some implementation
3331
}
3432

35-
@RegisterFunction
33+
@GodotMember
3634
abstract fun abstractFunction()
3735
}
3836
```
3937

4038
Child class definition:
4139

4240
```kotlin
43-
@RegisterClass
41+
@GodotScript
4442
class AbstractClassInheritanceChild: AbstractClassInheritanceParent() {
45-
@RegisterFunction
43+
// registered automatically as the abstract class already defines the annotation
4644
override fun abstractFunction() {
4745
// some implementation
4846
}
4947
}
5048
```
51-
52-
!!! warning "Registration of overridden members"
53-
As you can see in the example; you need to explicitly register any member in the child class which you override from the abstract parent class. Otherwise they will not be registered and thus are not known to godot.

docs/src/doc/user-guide/api-differences.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,11 @@ You can implement [_notification](https://docs.godotengine.org/en/stable/classes
152152
and have class hierarchy notification call without using `super` call, as in GDScript and C++. However, the syntax is a bit different:
153153

154154
```kotlin
155-
@RegisterFunction
156155
override fun _notification() = godotNotification {
157156
// ...
158157
}
159158
```
160-
Currently this feature except abstract classes.
159+
Currently, this feature does not work for abstract classes.
161160

162161
## StringName and NodePath
163162

docs/src/doc/user-guide/classes.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
To expose a class written in Kotlin it needs to extend `godot.Object` (or any of its subtype) and must be annotated with `@RegisterClass`.
1+
To expose a class written in Kotlin it needs to extend `godot.Object` (or any of its subtype) and must be annotated with `@GodotScript`.
22

33
```kt
4-
@RegisterClass
4+
@GodotScript
55
class RotatingCube: Node3D() {
66
// ...
77
}
@@ -13,7 +13,7 @@ Each registered classes will generate its own .gdj files. For more information,
1313

1414
Classes need to be registered with a unique name as Godot does not support namespaces (or packages in this case) for script classes.
1515

16-
By default, we register your classes with the name you give them. While beign a simple approach and enough in most cases,
16+
By default, we register your classes with the name you give them. While being a simple approach and enough in most cases,
1717
this can lead to naming conflicts if you have classes in different packages with the same name. For example:
1818

1919
- `com.package.a.MyClass`
@@ -25,7 +25,7 @@ So you are responsible for making sure that classes have a unique name.
2525
We do however provide you with some assistance:
2626

2727
- We have compile time checks in place which should let the *build fail* if classes would end up having the same name.
28-
- The `@RegisterClass` annotation lets you define a custom registration name: `@RegisterClass("CustomRegistrationName")`.
28+
- The `@GodotScript` annotation lets you define a custom registration name: `@GodotScript("CustomRegistrationName")`.
2929
- Register the class names with the fully qualified name: `com.mygame.MyClass` will be registered as: `com_mygame_MyClass`. This can be configured with:
3030
```kotlin
3131
godot {
@@ -93,7 +93,7 @@ If you want to be notified when initialization and destruction of your class' in
9393
and override the `_onDestroy` function respectively.
9494

9595
```kt
96-
@RegisterClass
96+
@GodotScript
9797
class RotatingCube: Node3D() {
9898
init {
9999
println("Initializing RotatingCube!")
@@ -110,7 +110,6 @@ class RotatingCube: Node3D() {
110110
Checking if an object is an instance of a particular type can be done via the `is` operator.
111111

112112
```kt
113-
@RegisterFunction
114113
override fun _ready() {
115114
val parent = getParent()
116115
if (parent is CollisionShape) {
@@ -128,7 +127,6 @@ This also works for any type you define.
128127
If you are sure that an object is always an instance of some type, then you can take advantage of Kotlin's [contracts](https://kotlinlang.org/docs/reference/whatsnew13.html#contracts) feature. This allows you to avoid having nested `if`s.
129128

130129
```kt
131-
@RegisterFunction
132130
override fun _ready() {
133131
val parent = getParent()
134132
require(parent is CollisionShape)
@@ -140,15 +138,15 @@ This also works for any type you define.
140138
## Constructors
141139

142140
Godot requires you to have a default constructor on your classes.
143-
You can define additional constructors but you have to register them by annothing them with `@RegisterConstructor`.
141+
You can define additional constructors, but you have to register them by annotating them with `@GodotMember`.
144142
Default constructors, on the other hand, are always registered automatically.
145143

146144
Constructors can also have **a maximum of 8 arguments** and must have a unique argument count as constructor overloading is not yet supported.
147145
This limitation is only for registered constructors.
148146

149147
### Instantiate Kotlin script classes in GDScript
150148

151-
From GDScript it is possible to create an instance of a Kotlin class using the default constructor:
149+
From GDScript, it is possible to create an instance of a Kotlin class using the default constructor:
152150

153151
```kt
154152
var instance := YourKotlinClass.new()
@@ -161,24 +159,24 @@ var instance := load("res://gdj/YourClass.gdj").new(oneArg, anotherArg)
161159
```
162160

163161
!!! info
164-
The limitation of max 16 arguments for constructors is arbitrary. We decided to introduce this limitation to prevent performance bottlenecks for creating objects as each argument passed to a constructor needs to be unpacked by the binding. The more arguments, the more unpacking is needed which means more overhead.
162+
The limitation of max 8 arguments for constructors is arbitrary. We decided to introduce this limitation to prevent performance bottlenecks for creating objects as each argument passed to a constructor needs to be unpacked by the binding. The more arguments, the more unpacking is needed which means more overhead.
165163

166164

167165
## Customization
168166

169167
You can customize to some extent how your class should be registered in Godot.
170168

171-
The `@RegisterClass` annotation takes only one argument:
169+
The `@GodotScript` annotation takes only one argument:
172170

173-
- **className**: If set, the class will be registered with the provided name.
171+
- **customName**: If set, the class will be registered with the provided name.
174172

175173
!!! warning "Unique class names"
176-
If you specify the `className` in the annotation, you have to make sure that this name is unique! We implemented compilation checks to make sure the compilation fails if more than two classes are registered with the same name, but we cannot check class names from other scripting languages like GDScript or C#! It is also recommended installing our intellij plugin as it shows duplicated registered class names in the editor as an error.
174+
If you specify the `customName` in the annotation, you have to make sure that this name is unique! We implemented compilation checks to make sure the compilation fails if more than two classes are registered with the same name, but we cannot check class names from other scripting languages like GDScript or C#! It is also recommended installing our intellij plugin as it shows duplicated registered class names in the editor as an error.
177175

178176

179177
## Tool Mode
180178

181-
Annotate your class with `@Tool` to make it a tool class (note that `@RegisterClass` is required for this annotation to take effect).
179+
Annotate your class with `@Tool` to make it a tool class.
182180

183181
!!! Caution
184182
This is currently not implemented.

docs/src/doc/user-guide/functions.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Any Kotlin function can be registered as long as its parameters and return type can be converted to a `Variant`.
2-
To register a function annotate it with `@RegisterFunction`.
2+
To register a function annotate it with `@GodotMember`.
33

44
```kotlin
5-
@RegisterClass
5+
@GodotScript
66
class RotatingCube: Node3D() {
7-
@RegisterFunction
8-
override fun _ready() {
9-
println("I am ready!")
7+
@GodotMember
8+
fun myFunction() {
9+
println("Hello")
1010
}
1111
}
1212
```
@@ -21,17 +21,11 @@ Therefore, a function called `doSomething()` in Kotlin is usable in GDScript as
2121

2222
Virtual functions (like `_ready`, `_process` and `_physics_process`) are declared as overridable functions.
2323
The default implementation throws a `NotImplementedException`, so you have to override it if you plan to expose
24-
a virtual function to Godot. Remember, just overriding is not enough to use that function - you have to explicitly
25-
register it as well with `@RegisterFunction`.
24+
a virtual function to Godot. Virtual functions are registered automatically and do not require an explicit `@GodotMember`
25+
annotation.
2626

2727
## Arguments count
2828

2929
Godot limits the allowed argument count of functions to `16`. Thus, this binding also has this limitation.
3030
If you want to pass more than 16 parameters in a function, you need to wrap them in a container
3131
(like a custom container class or a `VariantArray` or `Dictionary`).
32-
33-
## Customization
34-
35-
You can customize to some extent how your functions should be registered in Godot. The `@RegisterFunction` annotation takes one argument:
36-
37-
- **rpcMode**: Default: `RPCMode.DISABLED`

docs/src/doc/user-guide/properties.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Any property of a registered class can be registered as long as it is public, mutable and can be converted to a `Variant`.
2-
To register a property annotate it with `@RegisterProperty`.
2+
To register a property annotate it with `@GodotMember`.
33

44
```kotlin
5-
@RegisterClass
5+
@GodotScript
66
class RotatingCube: Node3D() {
7-
@RegisterProperty
7+
@GodotMember
88
var someString: String = "Hello there :-)"
99

10-
@RegisterProperty
10+
@GodotMember
1111
var propertyWithDefaultValue: Float = 2f
1212
}
1313
```
@@ -19,32 +19,30 @@ your properties are actually registered as `snake_case`. So a property `someFlag
1919

2020
## Core type specifics
2121

22-
Godot core type always need to have a value. Hence you cannot register properties of core types (like `Vector3`) with lateinit.
22+
Godot core type always need to have a value. Hence, you cannot register properties of core types (like `Vector3`) with lateinit.
2323

2424
## Exporting properties
2525

26-
A registered property can be exported (a.k.a make it visible in the Godot editor) by annotating it with `@Export`.
26+
A property can be exported (a.k.a. make it visible in the Godot editor) by annotating it with `@Export`.
2727
A property can be exported if it is a core type, a primitive or inherits from `godot.RefCounted`.
2828

2929
```kotlin
30-
@RegisterClass
30+
@GodotMember
3131
class RotatingCube: Node3D() {
3232
@Export
33-
@RegisterProperty
3433
var speed: Float = 2f
3534
}
3635
```
3736

3837
Exported properties can have default values (`2f` in the example above) which will be used as a default value by the `inspector`.
39-
A default value can **only** contain compile time constants and only references to compile time constants.
4038

4139
!!! danger
4240
If you set a default value in code and a different value in the `inspector` the value of the latter will override the value in code after `init` and before `_enter_tree`.
4341

4442
## Type hint registration
4543

4644
This module provides a plethora of annotations for defining property type hints.
47-
These annotations controls how Godot display the property in the inspector.
45+
These annotations control how Godot display the property in the inspector.
4846
Each property hint annotation can only be added to certain types of properties.
4947
Using the wrong annotation will make the compilation fail. These will only take effect if the property is exported.
5048

docs/src/doc/user-guide/signals_and_callables.md

+8-13
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@ In both case, you have to provide the name of the signal parameters as strings f
1414

1515
/// tab | Kotlin
1616
```kotlin
17-
@RegisterClass
17+
@GodotScript
1818
class MyScript: Node() {
19-
@RegisterSignal
2019
val mySignal by signal1<Boolean>("reverse")
2120

22-
@RegisterSignal
2321
val mySignal = Signal1<Boolean>("mySignal", "reverse")
2422
}
2523
```
2624
///
2725

2826
/// tab | Java
2927
```java
30-
@RegisterClass
28+
@GodotScript
3129
public MyScript extends Node {
32-
@RegisterSignal
3330
public Signal1<Boolean> mySignal = Signal1.create(this, "mySignal", "reverse"); // Only one way to do it in Java.
3431
}
3532
```
@@ -90,17 +87,16 @@ Note that the connected method has to be a registered to Godot.
9087

9188
/// tab | Kotlin
9289
```kotlin
93-
@RegisterClass
90+
@GodotScript
9491
class SomeObject: Object() {
95-
@RegisterFunction
92+
@GodotMember
9693
fun onReverseChanged(reverse: Boolean) {
9794
println("Value of reverse has changed: $reverse")
9895
}
9996
}
10097

101-
@RegisterClass
98+
@GodotScript
10299
class AnotherObject: Object() {
103-
@RegisterSignal
104100
val mySignal by signal1<Boolean>("reverse")
105101

106102
private val targetObject = SomeObject()
@@ -118,17 +114,16 @@ class AnotherObject: Object() {
118114

119115
/// tab | Java
120116
```java
121-
@RegisterClass
117+
@GodotScript
122118
public class SomeObject extends Object {
123-
@RegisterFunction
119+
@GodotMember
124120
public void onReverseChanged(boolean reverse) {
125121
System.out.println("Value of reverse has changed: " + reverse);
126122
}
127123
}
128124

129-
@RegisterClass
125+
@GodotScript
130126
public class AnotherObject extends Object {
131-
@RegisterSignal
132127
public Signal1<Boolean> mySignal = Signal1.create(this, "mySignal", "reverse");
133128

134129
private SomeObject targetObject = new SomeObject();

0 commit comments

Comments
 (0)