File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed
docs/documentation/godot-js-scripts Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,50 @@ Example given `ResourceLoader.load()` will autocomplete like this:
88
99![ Resource Loader load auto complete] ( images/codegen/resource-loader.png )
1010
11+ ## SceneNodes
12+
13+ For every scene node, a generated ` *.nodes.gen.d.ts ` file will be created in the ` /gen/godot ` subdirectory.
14+
15+ Example given a ` Main.tscn ` file with a ` Button ` and ` Label ` child node will look like this:
16+
17+ ``` ts
18+ declare module " godot" {
19+ interface SceneNodes {
20+ " scenes/Main.tscn" : {
21+ Button: Button <{}>;
22+ Label: Label <{}>;
23+ };
24+ }
25+ }
26+ ```
27+
28+ If you want to use this scene node inside you script you can do it like this:
29+
30+ ``` ts
31+ // src/scenes/main.ts
32+ import { Label , Node , SceneNodes } from " godot" ;
33+
34+ export default class Main extends Node <SceneNodes [" scenes/Main.tscn" ]> {
35+ label: Label | undefined ;
36+
37+ _ready(): void {
38+ this .label = this .get_node (" Label" );
39+ }
40+ }
41+ ```
42+
43+ With this, ` this.label ` will be correctly typed as ` Label ` , no need for ` as Label ` or ` <Label> ` conversion.
44+
1145## .gen.d.ts files
1246
13- Similarly to scenes, each resource has a generated ` .gen.d.ts file ` in the ` /generated/typings/ ` subdirectory.
47+ Similarly to scenes, each resource has a generated ` .gen.d.ts file ` in the ` /gen/godot ` subdirectory.
1448
1549For example, a ` hmm.tres ` file for a custom Resource whose script looks like:
1650
1751``` ts
1852export default class LineCardLayout extends CardLayout {
53+ // ...
54+ }
1955```
2056
2157will have the following ` hmm.tres.gen.d.ts ` generated:
You can’t perform that action at this time.
0 commit comments