This commit is contained in:
@@ -1,3 +1,17 @@
|
|||||||
|
import { Control } from "godot"
|
||||||
|
import { Node } from "react-godot-renderer"
|
||||||
|
|
||||||
|
|
||||||
export function TestUi1Component() {
|
export function TestUi1Component() {
|
||||||
return <node2D />
|
return (
|
||||||
|
<Node
|
||||||
|
class={Control}
|
||||||
|
anchor_left={0}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node({
|
||||||
|
class: Control,
|
||||||
|
|
||||||
|
})
|
||||||
|
|||||||
@@ -2,21 +2,21 @@ import type * as Godot from "godot"
|
|||||||
import type { PascalToCamel } from "./utils.js"
|
import type { PascalToCamel } from "./utils.js"
|
||||||
|
|
||||||
|
|
||||||
type NodeClass = {
|
export type NodeClass = {
|
||||||
[K in keyof typeof Godot]: typeof Godot[K] extends new (...args: any[]) => Godot.Node
|
[K in keyof typeof Godot]: typeof Godot[K] extends new (...args: any[]) => Godot.Node
|
||||||
? K
|
? K
|
||||||
: never
|
: never
|
||||||
}[keyof typeof Godot]
|
}[keyof typeof Godot]
|
||||||
|
|
||||||
type GodotIntrinsicElements = {
|
export type GodotIntrinsicElements = {
|
||||||
[K in NodeClass as PascalToCamel<K>]: PropsFromInstance<InstanceType<(typeof Godot)[K]>>
|
[K in NodeClass as PascalToCamel<K>]: PropsFromInstance<InstanceType<(typeof Godot)[K]>>
|
||||||
} & {
|
} & {
|
||||||
custom: {
|
element: {
|
||||||
class: new (...args: any[]) => Godot.Node
|
class: new (...args: any[]) => Godot.Node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PropsFromInstance<T> = {
|
export type PropsFromInstance<T> = {
|
||||||
// biome-ignore lint/complexity/noBannedTypes: it's completely fine
|
// biome-ignore lint/complexity/noBannedTypes: it's completely fine
|
||||||
[K in keyof T as T[K] extends Function ? never : K]?: T[K]
|
[K in keyof T as T[K] extends Function ? never : K]?: T[K]
|
||||||
}
|
}
|
||||||
|
|||||||
14
packages/react-godot-renderer/src/Node.ts
Normal file
14
packages/react-godot-renderer/src/Node.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type * as Godot from "godot"
|
||||||
|
import * as React from "react"
|
||||||
|
import type * as JSX from "./JSX.js"
|
||||||
|
|
||||||
|
|
||||||
|
export type NodeProps<T extends Godot.Node> = {
|
||||||
|
readonly class: new (...args: any[]) => T
|
||||||
|
} & JSX.PropsFromInstance<NoInfer<T>>
|
||||||
|
|
||||||
|
export function Node<T extends Godot.Node>(
|
||||||
|
props: NodeProps<T>
|
||||||
|
): React.JSX.Element {
|
||||||
|
return React.createElement("element", props)
|
||||||
|
}
|
||||||
@@ -29,9 +29,9 @@ export const make = () => {
|
|||||||
|
|
||||||
createInstance(type, props) {
|
createInstance(type, props) {
|
||||||
let instance: Node
|
let instance: Node
|
||||||
if (type === "custom") {
|
if (type === "element") {
|
||||||
if (!hasProperty(props, "class"))
|
if (!hasProperty(props, "class"))
|
||||||
throw new Error("Property 'class' required when using the 'custom' intrinsic type")
|
throw new Error("Property 'class' required when using the 'element' intrinsic type")
|
||||||
instance = new (props.class as any)()
|
instance = new (props.class as any)()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export * as JSX from "./JSX.js"
|
export * as JSX from "./JSX.js"
|
||||||
|
export * from "./Node.js"
|
||||||
export * as Reconciler from "./Reconciler.js"
|
export * as Reconciler from "./Reconciler.js"
|
||||||
export * as Renderer from "./Renderer.js"
|
export * as Renderer from "./Renderer.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user