This commit is contained in:
@@ -37,6 +37,16 @@ export const fromClass = <T extends Godot.Node<Godot.NodePathMap>>(
|
||||
Prototype,
|
||||
)
|
||||
|
||||
export const fromSceneUnsafe = <T extends Godot.Node<Godot.NodePathMap> = Godot.Node<Godot.NodePathMap>>(
|
||||
path: string
|
||||
): Component<T> => Object.setPrototypeOf(
|
||||
Object.assign(
|
||||
(props: Props<T>) => React.createElement("scene", { ...props, path }),
|
||||
{ displayName: path },
|
||||
),
|
||||
Prototype,
|
||||
)
|
||||
|
||||
export declare namespace fromScene {
|
||||
export type SceneNames = {
|
||||
[K in keyof Godot.ResourceTypes]: Godot.ResourceTypes[K] extends Godot.PackedScene ? K : never
|
||||
@@ -45,13 +55,7 @@ export declare namespace fromScene {
|
||||
|
||||
export const fromScene = <A extends fromScene.SceneNames>(
|
||||
path: A
|
||||
): Component<Godot.ResourceTypes[A] extends Godot.PackedScene<infer T> ? T : never> => Object.setPrototypeOf(
|
||||
Object.assign(
|
||||
(props: Props<Godot.ResourceTypes[A]>) => React.createElement("scene", { ...props, path }),
|
||||
{ displayName: path },
|
||||
),
|
||||
Prototype,
|
||||
)
|
||||
): Component<Godot.ResourceTypes[A] extends Godot.PackedScene<infer T> ? T : never> => fromSceneUnsafe(path)
|
||||
|
||||
export declare namespace useSignal {
|
||||
export type SignalNames<T extends Godot.Node<Godot.NodePathMap>> = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Node, type NodePathMap, type PackedScene, ResourceLoader } from "godot"
|
||||
import { Node, type NodePathMap, PackedScene, ResourceLoader } from "godot"
|
||||
import ReactReconciler, { type HostConfig } from "react-reconciler"
|
||||
import { hasProperty } from "./utils.js"
|
||||
|
||||
@@ -39,7 +39,10 @@ export const make = () => {
|
||||
throw new Error("Property 'path' required when using the 'scene' intrinsic type")
|
||||
if (typeof props.path !== "string")
|
||||
throw new Error("Property 'path' is not a string")
|
||||
instance = (ResourceLoader.load(props.path) as PackedScene<Node<NodePathMap>>).instantiate()
|
||||
const res = ResourceLoader.load(props.path)
|
||||
if (!(res instanceof PackedScene))
|
||||
throw new Error(`Resource at 'path' is not a PackedScene`)
|
||||
instance = res.instantiate()
|
||||
}
|
||||
else {
|
||||
// const className = snakeToPascal(camelToSnake(type))
|
||||
|
||||
Reference in New Issue
Block a user