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