Skip to content

Commit 31525a5

Browse files
committed
chore: update docs how to use new annotations
1 parent 8b5cba8 commit 31525a5

File tree

5 files changed

+90
-53
lines changed

5 files changed

+90
-53
lines changed

docs/documentation/godot-js-scripts/code-in-editor.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
> **NOTE:** Read [Godot Docs](https://docs.godotengine.org/en/stable/tutorials/plugins/running_code_in_the_editor.html#what-is-tool) for more details about `@tool`.
55
66

7-
If a GodotJS class is annotated with `@Tool()`, it'll be instantiated in the editor.
7+
If a GodotJS class is annotated with `@bind.tool()`, it'll be instantiated in the editor.
88
Call `Engine.is_editor_hint()` in the script to check if it's running in the editor.
99
It's also possible to show warnings on a `Node` on `Scene` panel with `_get_configuration_warnings` defined. Here is a simple example:
1010

1111
```ts
1212
import { Engine, PackedStringArray, Sprite2D, Variant } from "godot";
13-
import { Export, Tool } from "godot.annotations";
13+
import { createClassBinder } from "godot.annotations";
1414

15-
@Tool()
15+
const bind = createClassBinder();
16+
17+
@bind()
18+
@bind.tool()
1619
export default class MyEditorSprite extends Sprite2D {
1720

1821
/**
1922
* get/set property for `export` (both must be defined)
2023
*/
21-
@Export(Variant.Type.TYPE_FLOAT)
24+
@bind.export(Variant.Type.TYPE_FLOAT)
2225
get speed(): number { return this._speed; }
2326
set speed(value: number) {
2427
if (this._speed != value) {
@@ -30,8 +33,8 @@ export default class MyEditorSprite extends Sprite2D {
3033
/**
3134
* plain field for `export`
3235
*/
33-
@Export(Variant.Type.TYPE_INT)
34-
unused_int = 0;
36+
@bind.export(Variant.Type.TYPE_INT)
37+
accessor unused_int = 0;
3538

3639
private _clockwise = false;
3740
private _speed = 0;
@@ -82,9 +85,12 @@ This is available in Godot by extending `EditorScript` in a script. This provide
8285

8386
```ts
8487
import { EditorScript } from "godot";
85-
import { Tool } from "godot.annotations";
88+
import { createClassBinder } from "godot.annotations";
89+
90+
const bind = createClassBinder();
8691

87-
@Tool()
92+
@bind()
93+
@bind.tool()
8894
export default class MyEditorScript1 extends EditorScript {
8995
_run() {
9096
console.log("my editor script run");

docs/documentation/godot-js-scripts/decorators.md

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,45 @@
22

33
There are several decorators to help you define properties, signals, and other metadata for Godot objects.
44

5+
All decorators are accessed through the `createClassBinder` function:
6+
7+
```ts
8+
import { createClassBinder } from "godot.annotations";
9+
10+
const bind = createClassBinder();
11+
```
12+
513
## Signal annotation
614

7-
You can define signals in your script using the `@ExportSignal` annotation:
15+
You can define signals in your script using the `@bind.signal()` decorator:
816

917
```ts
1018
import { Node, Signal } from "godot";
11-
import { ExportSignal } from "godot.annotations";
19+
import { createClassBinder } from "godot.annotations";
1220

21+
const bind = createClassBinder();
22+
23+
@bind()
1324
export default class MyJSNode extends Node {
14-
@ExportSignal()
15-
test!: Signal<(param1: string) => void>;
25+
@bind.signal()
26+
accessor test!: Signal<(param1: string) => void>;
1627
}
1728
```
1829

1930
For more information about signals, check this [link](signals.md).
2031

2132
## Tool annotation
2233

23-
If a GodotJS class is annotated with `tool()`, it'll be instantiated in the editor.
34+
If a GodotJS class is annotated with `@bind.tool()`, it'll be instantiated in the editor.
2435

2536
```ts
2637
import { Node } from "godot";
27-
import { Tool } from "godot.annotations";
38+
import { createClassBinder } from "godot.annotations";
39+
40+
const bind = createClassBinder();
2841

29-
@Tool()
42+
@bind()
43+
@bind.tool()
3044
export default class MyTool extends Node {
3145
_ready() {
3246
// This code will run in the editor
@@ -39,13 +53,16 @@ For more information about running code in editor, check this [link](code-in-edi
3953

4054
## Icon annotation
4155

42-
An icon can be used as node icon in the editor scene hierarchy with the annotation `@icon`.
56+
An icon can be used as node icon in the editor scene hierarchy with the annotation `@bind.icon()`.
4357

4458
```ts
4559
import { Sprite2D } from "godot";
46-
import { Icon } from "godot.annotations";
60+
import { createClassBinder } from "godot.annotations";
4761

48-
@Icon("res://icon/affiliate.svg")
62+
const bind = createClassBinder();
63+
64+
@bind()
65+
@bind.icon("res://icon/affiliate.svg")
4966
export default class MySprite extends Sprite2D {}
5067
```
5168

@@ -57,16 +74,18 @@ In `GodotJS`, class member properties/variables can be exported.
5774
This means their value gets saved along with the resource
5875
(such as the scene) they're attached to.
5976
They will also be available for editing in the property editor.
60-
Exporting is done by using the `@Export` annotation.
77+
Exporting is done by using the `@bind.export()` decorator.
6178

6279
```ts
63-
import { Export } from "godot.annotations";
80+
import { Variant } from "godot";
81+
import { createClassBinder } from "godot.annotations";
82+
83+
const bind = createClassBinder();
6484

85+
@bind()
6586
export default class Shooter extends Sprite2D {
66-
// type must be explicitly provided as the first parameter of @Export
67-
// cuz static type is actually a phantom in typescript
68-
@Export(Variant.Type.TYPE_FLOAT)
69-
speed: number = 0;
87+
@bind.export(Variant.Type.TYPE_FLOAT)
88+
accessor speed: number = 0;
7089

7190
// ...
7291
}
@@ -84,18 +103,18 @@ The retrieval of default value is implemented through `Class Default Object (CDO
84103
### Basic Use
85104

86105
```ts
87-
@Export(Variant.Type.TYPE_STRING)
88-
address: string = "somewhere"; // `:string` can be omitted here
106+
@bind.export(Variant.Type.TYPE_STRING)
107+
accessor address: string = "somewhere";
89108

90-
@Export(Variant.Type.TYPE_INT)
91-
age: number = 0; // `:number` can be omitted here
109+
@bind.export(Variant.Type.TYPE_INT)
110+
accessor age: number = 0;
92111
```
93112

94-
If there's no default value, `default value` of the give type will be used (`0` in this case).
113+
If there's no default value, `default value` of the given type will be used (`0` in this case).
95114

96115
```ts
97-
@Export(Variant.Type.TYPE_INT)
98-
age: number;
116+
@bind.export(Variant.Type.TYPE_INT)
117+
accessor age: number;
99118
```
100119

101120
### Exported Enum Properties
@@ -105,8 +124,8 @@ Enum value properties can be exported with the built-in support in the property
105124
> **NOTE:** So far, only `int` is supported as enum value.
106125
107126
```ts
108-
@ExportEnum(MyColor)
109-
color: MyColor = MyColor.White;
127+
@bind.exportEnum(MyColor)
128+
accessor color: MyColor = MyColor.White;
110129
```
111130

112131
The value can be easily chosen from a dropdown list in the editor.

docs/documentation/godot-js-scripts/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ Check out [decorators](decorators.md) for more information.
7070
## Auto-Completion and Codegen
7171

7272
By default, GodotJS wil auto generate some TypeScript files based on you project.
73-
Check out [auto-completion](auto-completion.md) for more information.
73+
Check out [auto-completion](auto-completion-and-codegen.md) for more information.

docs/documentation/godot-js-scripts/signals.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ You can define signals based on the amount of arguments you want to pass:
44

55
```ts
66
import { Node, Signal } from "godot";
7-
import { ExportSignal } from "godot.annotations";
7+
import { createClassBinder } from "godot.annotations";
88

9+
const bind = createClassBinder();
10+
11+
@bind()
912
export default class MyNode extends Node {
10-
@ExportSignal()
11-
declare no_arg!: Signal<() => void>;
13+
@bind.signal()
14+
accessor no_arg!: Signal<() => void>;
1215

13-
@ExportSignal()
14-
declare one_arg!: Signal<(param1: string) => void>;
16+
@bind.signal()
17+
accessor one_arg!: Signal<(param1: string) => void>;
1518

16-
@ExportSignal()
17-
declare two_args!: Signal<(param1: number, param2: string) => void>;
19+
@bind.signal()
20+
accessor two_args!: Signal<(param1: number, param2: string) => void>;
1821
}
1922
```
2023

@@ -75,12 +78,15 @@ export default class MyClass extends Node {
7578
A `Signal` can be awaitable in javascript by calling `as_promise()`:
7679

7780
```ts
78-
import { Node, Signal1 } from "godot";
79-
import { signal } from "godot.annotations";
81+
import { Node, Signal } from "godot";
82+
import { createClassBinder } from "godot.annotations";
83+
84+
const bind = createClassBinder();
8085

86+
@bind()
8187
class ExampleClass extends Node {
82-
@signal()
83-
declare test_signal!: Signal1<number>;
88+
@bind.signal()
89+
accessor test_signal!: Signal<(value: number) => void>;
8490

8591
_ready() {
8692
test();

docs/examples/reuse-custom-resources.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ This example shows how to create a custom resource and reuse it with different s
77
We create a new file `character-attributes.ts` and add this code to it:
88

99
```ts title="character-attributes.ts"
10-
import { Export } from "godot.annotations";
10+
import { createClassBinder } from "godot.annotations";
1111
import { Resource, Variant } from "godot";
1212

13+
const bind = createClassBinder();
14+
15+
@bind()
1316
export default class CharacterAttributes extends Resource {
14-
@Export(Variant.Type.TYPE_INT)
15-
health: number = 5;
17+
@bind.export(Variant.Type.TYPE_INT)
18+
accessor health: number = 5;
1619
}
1720
```
1821

@@ -33,15 +36,18 @@ Create a new file `index.ts` and add this code to it:
3336

3437
```ts title="index.ts"
3538
import { Node, Variant } from "godot";
36-
import { Export } from "godot.annotations";
39+
import { createClassBinder } from "godot.annotations";
3740
import CharacterAttributes from "./character-attributes";
3841

42+
const bind = createClassBinder();
43+
44+
@bind()
3945
export default class ResourceExample extends Node {
40-
@Export(Variant.Type.TYPE_OBJECT)
41-
warriorAttributes: CharacterAttributes | undefined = undefined;
46+
@bind.export(Variant.Type.TYPE_OBJECT)
47+
accessor warriorAttributes: CharacterAttributes | undefined = undefined;
4248

43-
@Export(Variant.Type.TYPE_OBJECT)
44-
mageAttributes: CharacterAttributes | undefined = undefined;
49+
@bind.export(Variant.Type.TYPE_OBJECT)
50+
accessor mageAttributes: CharacterAttributes | undefined = undefined;
4551

4652
_ready(): void {
4753
console.log("warrior health", this.warriorAttributes?.health);

0 commit comments

Comments
 (0)