Skip to content

Commit 63e725f

Browse files
authored
chore: update codegen docs (#17)
1 parent ae37ea0 commit 63e725f

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

docs/documentation/godot-js-scripts/auto-completion-and-codegen.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff 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

1549
For example, a `hmm.tres` file for a custom Resource whose script looks like:
1650

1751
```ts
1852
export default class LineCardLayout extends CardLayout {
53+
// ...
54+
}
1955
```
2056

2157
will have the following `hmm.tres.gen.d.ts` generated:

0 commit comments

Comments
 (0)