Add Component.fromScene
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2026-01-02 03:24:30 +01:00
parent 99007ec462
commit 54c6466127
7 changed files with 21 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ const VFlowContainer = Component.make(Godot.VFlowContainer)
const Label = Component.make(Godot.Label)
const TextEdit = Component.make(Godot.TextEdit)
const Button = Component.make(Godot.Button)
const Test = Component.
export function TestUi1Component() {
const [text, setText] = useState("Default text")

View File

@@ -1,5 +0,0 @@
declare module "godot" {
interface SceneNodes {
"src/TestUi1.tscn": {};
}
}

View File

@@ -1,6 +0,0 @@
import TestUi1 from "../../../src/TestUi1";
declare module "godot" {
interface ResourceTypes {
"res://src/TestUi1.tscn": PackedScene<TestUi1>;
}
}

View File

@@ -1,5 +0,0 @@
declare module "godot" {
interface SceneNodes {
"src/TestUi2.tscn": {};
}
}

View File

@@ -1,6 +0,0 @@
import TestUi2 from "../../../src/TestUi2";
declare module "godot" {
interface ResourceTypes {
"res://src/TestUi2.tscn": PackedScene<TestUi2>;
}
}

View File

@@ -37,6 +37,22 @@ export const make = <T extends Godot.Node<Godot.NodePathMap>>(
Prototype,
)
export declare namespace fromScene {
export type SceneNames = {
[K in keyof Godot.ResourceTypes]: Godot.ResourceTypes[K] extends Godot.PackedScene ? K : never
}[keyof Godot.ResourceTypes]
}
export const fromScene = <A extends fromScene.SceneNames>(
name: A
): Component<Godot.ResourceTypes[A]> => Object.setPrototypeOf(
Object.assign(
(props: Props<Godot.ResourceTypes[A]>) => React.createElement("element", { ...props }),
{ displayName: name },
),
Prototype,
)
export declare namespace useSignal {
export type SignalNames<T extends Godot.Node<Godot.NodePathMap>> = {
[K in keyof T & string]: T[K] extends Godot.Signal ? K : never
@@ -49,10 +65,10 @@ export declare namespace useSignal {
)
}
export const useSignal = <T extends Godot.Node<Godot.NodePathMap>, N extends useSignal.SignalNames<T>>(
export const useSignal = <T extends Godot.Node<Godot.NodePathMap>, A extends useSignal.SignalNames<T>>(
ref: React.RefObject<T | null>,
name: N,
f: useSignal.Function<T, N>,
name: A,
f: useSignal.Function<T, A>,
// biome-ignore lint/correctness/useExhaustiveDependencies: "f" is non-reactive
): void => React.useEffect(() => {
if (!ref.current) return

View File

@@ -31,5 +31,5 @@
"sourceMap": true
},
"include": ["./src", "./typings"]
"include": ["./src", "./typings", "./gen"]
}