Skip to content

Commit 41ff7ad

Browse files
authored
Add documentation for Callable + misc improvements (#715)
* Improve doc + add Callable
1 parent ae036ed commit 41ff7ad

19 files changed

+308
-176
lines changed

docs/mkdocs.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ theme:
3232
- navigation.tabs
3333
- navigation.expand
3434
- navigation.top
35-
35+
- content.code.copy
36+
- toc.integrate
3637

3738
extra:
3839
social:
@@ -43,9 +44,9 @@ markdown_extensions:
4344
- pymdownx.highlight:
4445
linenums: true
4546
- pymdownx.inlinehilite
46-
- pymdownx.highlight
4747
- pymdownx.superfences
48-
- pymdownx.tabbed
48+
- pymdownx.blocks.tab:
49+
alternate_style: true
4950
- pymdownx.details
5051
- admonition
5152
- meta
@@ -62,19 +63,17 @@ nav:
6263
- Requirements: getting-started/requirements.md
6364
- Setting-up: getting-started/setting-up.md
6465
- Your first Kotlin class: getting-started/your-first-class.md
66+
- Compiling your project: getting-started/compiling-your-project.md
6567
- User guide:
6668
- API differences: user-guide/api-differences.md
6769
- Classes: user-guide/classes.md
68-
- Compiling your project: user-guide/compiling-your-project.md
6970
- Properties: user-guide/properties.md
70-
- Signals: user-guide/signals.md
71+
- Signals and Callables: user-guide/signals_and_callables.md
7172
- Functions: user-guide/functions.md
72-
- Exporting: user-guide/exporting.md
7373
- Coroutines: user-guide/coroutines.md
74+
- Exporting: user-guide/exporting.md
7475
- Debugging: user-guide/debugging.md
7576
- Consuming libraries: user-guide/consuming-libraries.md
76-
- Versioning: user-guide/versioning.md
77-
- Supported platforms: user-guide/supported-platforms.md
7877
- Advanced:
7978
- Abstract classes: user-guide/advanced/abstract-classes.md
8079
- Cleanup operations: user-guide/advanced/cleanup-operations.md

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
mkdocs-material==9.1.18
2-
mkdocs==1.4.3
2+
mkdocs==1.6.1
30.1 KB
Loading
Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
To compile your project, run a classic *Gradle build*. By default this creates a `debug` version of your code.
22

3-
Example:
3+
Using the Godot editor:
4+
5+
![Build button](../assets/img/editor-plugin/build_button.png)
6+
7+
Using your IDE:
8+
9+
![Gradle task](../assets/img/build_ide.png)
410

11+
Using command-line:
12+
13+
/// tab | Windows
14+
```shell
15+
gradlew build
16+
```
17+
///
18+
19+
/// tab | Unix
520
```bash
621
./gradlew build
722
```
23+
///
24+
825

926
## Targets
1027

@@ -13,22 +30,18 @@ In order to build in release, you should add `release` parameter to your Gradle
1330

1431
Example:
1532

33+
/// tab | Windows
34+
```shell
35+
gradlew build -Prelease
36+
```
37+
///
38+
39+
/// tab | Unix
1640
```bash
1741
./gradlew build -Prelease
1842
```
43+
///
1944

2045
Using debug builds is recommended when developing. It adds some sanity checks that are cut off in `release`.
2146

22-
Release builds are recommended when distributing to retail.
23-
24-
## Write debug code
25-
26-
You can add code only for debug version of your project, by using `GodotJvmDefinitions`.
27-
28-
Example:
29-
30-
```kotlin
31-
if (GodotJvmDefinitions.DEBUG) {
32-
// ...
33-
}
34-
```
47+
Release builds are recommended when distributing to retail.

docs/src/doc/getting-started/setting-up.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ or [manually](#setting-up-manually).
88

99
You can simply create a regular new Godot project.
1010
Once done, you can go to `Project/Tools/Kotlin/JVM/Generate JVM Project`.
11+
1112
![Godot menu](../assets/img/editor-plugin/generation_menu.png)
1213

1314
The following choice will appear:
1415
![Project dialog](../assets/img/editor-plugin/generation_choice.png)
1516

16-
After this action, all required files should be generated, and you can safely build the project using the `Build` button at the top-right of the editor window.
17-
![Build button](../assets/img/editor-plugin/build_button.png)
17+
After this action, all required files should be generated, and you can safely import your project in your IDE.
18+
1819
## Setting-up using IntelliJ IDEA project wizard
1920

2021
This is the recommended solution as it creates the entire project in one action and import it in your IDE.
@@ -88,17 +89,19 @@ If the user does not want to use our IntelliJ IDEA plugin, then they can follow
8889
Firstly, you need to setup a Gradle [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html).
8990
The wrapper will ensure that anyone who wants to build your project from source will use the same Gradle version.
9091

91-
=== "Windows"
92-
```shell
93-
fsutil file createnew build.gradle.kts 0
94-
fsutil file createnew gradle.properties 0
95-
fsutil file createnew settings.gradle.kts 0
96-
```
92+
/// tab | Windows
93+
```shell
94+
fsutil file createnew build.gradle.kts 0
95+
fsutil file createnew gradle.properties 0
96+
fsutil file createnew settings.gradle.kts 0
97+
```
98+
///
9799

98-
=== "Unix"
99-
```shell
100-
touch build.gradle.kts gradle.properties settings.gradle.kts
101-
```
100+
/// tab | Unix
101+
```shell
102+
touch build.gradle.kts gradle.properties settings.gradle.kts
103+
```
104+
///
102105

103106
The above command(s) will create three empty files. As next step, type the following
104107
command on the terminal:
@@ -111,17 +114,18 @@ After running the above command, the user should have the wrapper setup ready to
111114
Up next is setting-up the Gradle build. Now, open the `build.gradle.kts` file
112115
and paste the following content:
113116

114-
=== "`build.gradle.kts`"
115-
```kotlin
116-
plugins {
117-
kotlin("jvm") version "$kotlinVersion"
118-
id("com.utopia-rise.godot-kotlin-jvm") version "$godotKotlinVersion"
119-
}
120-
121-
repositories {
122-
mavenCentral()
123-
}
124-
```
117+
/// tab | `build.gradle.kts`
118+
```kotlin
119+
plugins {
120+
kotlin("jvm") version "$kotlinVersion"
121+
id("com.utopia-rise.godot-kotlin-jvm") version "$godotKotlinVersion"
122+
}
123+
124+
repositories {
125+
mavenCentral()
126+
}
127+
```
128+
///
125129

126130
!!! note
127131
Please replace `$kotlinVersion` and `$godotkotlinVersion` to the appropriate version you want to use.

docs/src/doc/index.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,25 @@ If you don't have Discord or you don't want to use it, please file an issue on G
3939

4040
The main language supported is Kotlin. We do however support Java experimentally. It should be possible to support other JVM-based languages as well but this is not the focus of this project. If you want to have support for other languages, have a look at [support for other JVM-based languages](contribution/support-for-other-jvm-based-languages.md).
4141

42-
## Supported Kotlin version
42+
## Supported platforms
43+
44+
While Kotlin and Godot supports a wide range of platforms, this module for the moment only supports the following:
45+
46+
- Windows X64
47+
- Linux X64
48+
- MacOS X64 / arm64
49+
- Android (arm64v8)
50+
- iOS (arm64v8)
51+
52+
## Versioning
53+
54+
The module uses semantic versioning for its own versions but adds a suffix for the supported Godot version:
55+
56+
Full version: `0.10.0-4.3.0`
57+
58+
Module Version: `0.10.0`
59+
60+
Supported Godot Version: `4.3.0`
4361

4462
This module relies on a Kotlin *compiler plugin* for registering your classes and members to Godot. As the compiler API from Kotlin is not stable yet, at the moment we can only support specific Kotlin version per release.
4563

docs/src/doc/user-guide/advanced/cleanup-operations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ fun foo() {
1818

1919

2020
Sometimes you need to store some Godot objects or references in a Kotlin singleton.
21-
This can cause some leaks when the program ends because you have to manually free objects and have the references collected.
22-
This issue is fixed by using the delegate `godotStatic` on singleton properties. Those properties will be freed once the running JVM ends.
23-
They automatically handle `Object` and `Reference`. You can also freely set a new value and the previous one will be immediatly freed.
21+
This can cause some memory leak warnings when the program ends because they are kept alive by the singleton.
22+
This issue is fixed by using the method `asStatic()` on singleton properties. Those properties will be freed once the running JVM ends.
23+
They automatically handle `Object` and `Reference`.
2424

2525
!!! warning
2626
Only use it on a singleton, otherwise all the properties of all instances are going to be kept alive until the end of the JVM.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
To be able to use custom source directories, you modify your Gradle build file as it follows:
22

3-
=== "build.gradle.kts"
4-
```kt
5-
kotlin.sourceSets.main {
6-
kotlin.srcDirs("scripts")
7-
}
8-
```
3+
/// tab | build.gradle.kts
4+
```kt
5+
kotlin.sourceSets.main {
6+
kotlin.srcDirs("scripts")
7+
}
8+
```
9+
///

docs/src/doc/user-guide/advanced/gradle-plugin-configuration.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ This is due to the fact that the Kotlin compiler plugin API is not stable yet. T
66
But if you are familiar with the quirks of compiler plugins and their compatibility and you need to use another Kotlin version than we officially support,
77
you can disable the version checks we have in place in our Gradle plugin. To do this you have to set `godot.jvm.suppressKotlinIncompatibility` to `true` in the `gradle.properties` file:
88

9-
=== "gradle.properties"
10-
```
11-
godot.jvm.suppressKotlinIncompatibility=true
12-
```
9+
/// tab | gradle.properties
10+
```kotlin
11+
godot.jvm.suppressKotlinIncompatibility=true
12+
```
13+
///
1314

1415
!!! warning
1516
This is an advanced feature! Only use it if you know what you're doing. We cannot guarantee that our compiler plugin is compatible with other kotlin versions than the one we build it for. Setting this property to true can lead to build and/or runtime errors.

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ dictionary.get("foo") {
125125

126126
Godot enums are mapped to Kotlin enums, the generated enum exposes a `value` property that represents the value in Godot. Constants in Godot classes that represent an enum value (such as `Node.PAUSE_MODE_INHERIT`) are not present in this module, please use the generated enum instead (`Node.PauseMode.INHERIT`).
127127

128-
## Signals and exposed methods
129-
130-
In GDScript, signals can have any number of arguments, this is not possible in Kotlin as it is a statically typed language.
131-
At the moment, you can create signals and expose them to Godot with at most 10 parameters.
132-
133-
If you need more than 10 parameters, you can either use the not typesafe function `connect(signalAsString, targetObject, targetMethodAsString)` and the corresponding emit function or you can write your own typesafe extension functions like we did, to further increase the supported arg count. Keep in mind that you pass in the converted function and signal names (snake_case) to the above mentioned functions.
134-
135128
## Renamed symbols
136129

137130
To avoid confusion and conflict with Kotlin types, the following Godot symbol is renamed.
@@ -166,33 +159,45 @@ override fun _notification() = godotNotification {
166159
```
167160
Currently this feature except abstract classes.
168161

169-
## Caching
162+
## StringName and NodePath
170163

171164
Several Godot functions take `StringName` or `NodePath` as a parameter.
172-
It's often more convenient to directly use a String that need to be converted.
165+
It's often more convenient to directly use a String and convert it.
173166

174-
This operation can be costly so we provide extension functions which cache the result of the conversion for later calls:
175-
176-
- `String.asCachedStringName()`
177-
- `String.asCachedNodePath()`
178-
- `StringName.asCachedNodePath()`
167+
This kind of operation can be costly so we provide extension functions which cache the result of the conversion for later calls:
179168

169+
/// tab | Kotlin
180170
```kotlin
181-
// This first call to the extension function creates the cache entry.
182-
val firstCall = "Test".asCachedStringName()
183-
184-
// This second call for the same String value, will return the previously cached instance.
185-
val secondCall = "Test".asCachedStringName()
171+
val stringName = "myString".asCachedStringName() // Cache the string for faster future calls.
172+
val nodePath = "myNode/myChildNode".asCachedNodePath() // Cache the string for faster future calls.
173+
val snakeCaseStringName = "myString".toGodotName() // Convert the string to snake_case and cache it for faster future calls.
174+
```
175+
///
186176

187-
// This third call will create a second entry in the cache due to the different key value.
188-
val thirdCall = "OtherTest".asCachedStringName()
177+
/// tab | Java
178+
```java
179+
StringName stringName = StringNames.asCachedStringName("myString");
180+
NodePath nodePath = NodePaths.asCachedNodePath("myNode/myChildNode");
181+
StringName snakeCaseStringName = StringNames.toGodotName("myString");
189182
```
183+
///
190184

191185
You can also use the non-cached version of them if you simply want ease of conversion:
192186

193-
- `String.asStringName()`
194-
- `String.asNodePath()`
195-
- `StringName.asNodePath()`
187+
/// tab | Kotlin
188+
```kotlin
189+
val stringName = "myString".asStringName()
190+
val nodePath = "myNode/myChildNode".asNodePath()
191+
```
192+
///
193+
194+
/// tab | Java
195+
```java
196+
StringName stringName = StringNames.asStringName("myString");
197+
NodePath nodePath = NodePaths.asNodePath("myNode/myChildNode");
198+
```
199+
///
200+
196201

197202
## Logging
198203

0 commit comments

Comments
 (0)