@ringozz/react-godot 1.0.0-0 → 1.0.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +308 -94
- package/package.json +8 -6
- package/src/index.ts +58 -58
- package/src/react-fiber.ts +315 -307
- package/src/react-hooks.ts +148 -22
- package/src/react-jsx.ts +45 -41
- package/src/react-types.ts +31 -15
package/README.md
CHANGED
|
@@ -1,94 +1,308 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
# `@ringozz/react-godot`
|
|
2
|
+
|
|
3
|
+
Declarative, component-driven **Godot 4** scene graph management in React. Built for high-performance applications using `@ringozz/godot`.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@ringozz/react-godot` brings a **React Three Fiber (R3F)**-like developer experience to Godot. It provides a custom React reconciler that renders React components directly into Godot's live engine scene tree (`SceneTree`).
|
|
8
|
+
|
|
9
|
+
If you are familiar with React Three Fiber, the core paradigms will feel instantly recognizable:
|
|
10
|
+
- **Declarative Nodes**: Godot 3D/2D nodes (e.g., `<RigidBody3D>`, `<Camera3D>`, `<DirectionalLight3D>`) map directly to JSX components.
|
|
11
|
+
- **Resource Attachment**: Use the `attach` prop to assign nested Godot resources (materials, shapes, meshes, environments) directly to parent properties.
|
|
12
|
+
- **Reactive Engine Loop**: Use hooks like `useSignal` to hook into Godot signals (`processFrame`, `windowInput`) without triggering React state re-renders.
|
|
13
|
+
|
|
14
|
+
## Installation & Setup
|
|
15
|
+
|
|
16
|
+
### 1. Dependencies
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @ringozz/react-godot react
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 2. TypeScript Configuration (`tsconfig.json`)
|
|
23
|
+
|
|
24
|
+
To enable custom JSX element resolution for Godot nodes, configure `jsxImportSource` and module settings in `tsconfig.json`:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"compilerOptions": {
|
|
29
|
+
"module": "esnext",
|
|
30
|
+
"target": "es2025",
|
|
31
|
+
"jsx": "react-jsx",
|
|
32
|
+
"jsxImportSource": "@ringozz/react-godot",
|
|
33
|
+
"rewriteRelativeImportExtensions": true,
|
|
34
|
+
"verbatimModuleSyntax": true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Application Entry & Portal Rendering
|
|
40
|
+
|
|
41
|
+
### 1. Mounting with `createRoot(parent: Node)`
|
|
42
|
+
`createRoot` is the primary entry point for mounting a React component tree into a Godot target `Node` (typically `SceneTree.root`).
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { Engine } from '@ringozz/godot/Engine';
|
|
46
|
+
import { SceneTree } from '@ringozz/godot/SceneTree';
|
|
47
|
+
import { createRoot } from '@ringozz/react-godot';
|
|
48
|
+
import { App } from './App';
|
|
49
|
+
|
|
50
|
+
const tree = Engine.getMainLoop() as SceneTree;
|
|
51
|
+
const { render } = createRoot(tree.root);
|
|
52
|
+
|
|
53
|
+
render(<App />);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- Returns `{ render, unmount }`.
|
|
57
|
+
- Enables React `StrictMode` automatically in development (`NODE_ENV === 'development'`).
|
|
58
|
+
|
|
59
|
+
### 2. Render Portals with `createPortal(children, container)`
|
|
60
|
+
`createPortal` allows rendering a React sub-tree into a different Godot `Node` in the hierarchy—such as a `CanvasLayer` for 2D UI overlays, a `SubViewport`, or an isolated container node.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { createPortal } from '@ringozz/react-godot';
|
|
64
|
+
import { Label } from '@ringozz/godot/Label';
|
|
65
|
+
|
|
66
|
+
function Overlay({ overlayNode }: { overlayNode: Node }) {
|
|
67
|
+
return createPortal(
|
|
68
|
+
<Label text="HUD Overlay" position={[20, 20]} />,
|
|
69
|
+
overlayNode
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- **Container Constraint**: The target `container` must be a Godot `Node` (it cannot target `Resource` instances).
|
|
75
|
+
- **Cleanup**: Unmounting the portal safely disposes of and frees its child Godot nodes.
|
|
76
|
+
|
|
77
|
+
## Core Concepts & Patterns
|
|
78
|
+
|
|
79
|
+
### 1. Existing Objects with `object` Prop
|
|
80
|
+
|
|
81
|
+
If you already have a pre-existing Godot `Node`, `Resource`, or `PackedScene` instance (e.g. instantiated from C++ or loaded from disk), pass it via the `object` prop to adopt it into the React component tree instead of letting the reconciler instantiate a new object:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
<Node object={myExistingGodotNode}>
|
|
85
|
+
{/* Children attached to existing node */}
|
|
86
|
+
</Node>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **`object` is immutable on a mounted instance.** It selects the host instance once, at creation. A re-render that changes `object` on an existing element throws (`Cannot change the \`object\` of a mounted instance`) because React cannot swap a fiber's Godot node — remount with a new `key` instead.
|
|
90
|
+
- **A `PackedScene` `object` is instantiated once per host mount** — each element gets a fresh node tree; the result is a plain `Node` (not `.reference()`'d) freed on unmount. The same `PackedScene` can feed multiple elements; give same-type siblings stable `key`s.
|
|
91
|
+
- **Dynamic same-type sibling lists need stable `key`s.** Godot host nodes are identity, not content: React reconciles keyless siblings by position, so deleting the *first* of two same-type siblings reuses its Godot node for the survivor. A plain state re-render does this too, and Bun's web dev server makes it especially likely — its React Fast Refresh re-renders the edited component **in place** (no app re-run), reusing the same fibers and Godot nodes, so a deleted sibling's node can survive on its neighbor and the neighbor's node is freed. Add `key="..."` to each dynamically toggled same-type sibling to keep nodes pinned to the right elements.
|
|
92
|
+
|
|
93
|
+
### 2. Resource Nesting with `attach`
|
|
94
|
+
|
|
95
|
+
In Godot, nodes often hold references to `Resource` objects (such as shapes, meshes, materials, or environments). Use the `attach` prop to automatically assign a child resource to a specific property on its parent:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
/* Attaching a shape to CollisionShape3D */
|
|
99
|
+
<CollisionShape3D>
|
|
100
|
+
<BoxShape3D attach="shape" size={[1, 1, 1]} />
|
|
101
|
+
</CollisionShape3D>
|
|
102
|
+
|
|
103
|
+
/* Attaching a material override to MeshInstance3D */
|
|
104
|
+
<MeshInstance3D>
|
|
105
|
+
<BoxMesh attach="mesh" />
|
|
106
|
+
<StandardMaterial3D attach="materialOverride" albedoColor={[1, 0, 0]} />
|
|
107
|
+
</MeshInstance3D>
|
|
108
|
+
|
|
109
|
+
/* Attaching physics material to RigidBody3D */
|
|
110
|
+
<RigidBody3D>
|
|
111
|
+
<PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
|
|
112
|
+
</RigidBody3D>
|
|
113
|
+
|
|
114
|
+
/* Attaching environment to WorldEnvironment */
|
|
115
|
+
<WorldEnvironment>
|
|
116
|
+
<Environment attach="environment" backgroundColor={[0.1, 0.1, 0.2]} />
|
|
117
|
+
</WorldEnvironment>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Note for physics bodies: `attach="shape"` goes on the shape **resource** element (e.g. `<BoxShape3D attach="shape" />`), never on the `CollisionShape3D` node itself — `Node.add_child` requires a `Node`, and shapes are `Resource`s, so an `attach` on `CollisionShape3D` adds the shape as a child node and fails. Likewise, mesh children of a physics body must be wrapped in a `MeshInstance3D` (a `RigidBody3D`/`StaticBody3D` has no `mesh`/`materialOverride` props to attach to).
|
|
121
|
+
|
|
122
|
+
### 3. Properties & Helper Types
|
|
123
|
+
|
|
124
|
+
Props map directly to Godot node setters and properties. Helper arrays are automatically cast to Godot types:
|
|
125
|
+
|
|
126
|
+
- **Vectors**: `position={[0, 1, 0]}`, `scale={[2, 2, 2]}`
|
|
127
|
+
- **Colors**: `albedoColor={[1, 0.2, 0.2]}` or `Color` objects
|
|
128
|
+
- **Sub-properties / Dash props**: Set individual vector/color components directly using dash syntax:
|
|
129
|
+
```tsx
|
|
130
|
+
<BoxMesh attach="mesh" size-x={0.5} size-y={1.0} size-z={0.5} />
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Text content**: text nodes are unsupported, but string/number children — and arrays of all-string/all-number children — are flattened into the node's `text` prop, so `<Label>Hello</Label>` works. Mixed children (containing elements) throw; use an explicit `text` prop instead, and never pass string children to a node without a `text` prop.
|
|
134
|
+
|
|
135
|
+
### 4. Engine Signals & Event Subscription (`useSignal`)
|
|
136
|
+
|
|
137
|
+
Subscribe to Godot engine signals cleanly with `useSignal`.
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { Engine } from '@ringozz/godot';
|
|
141
|
+
import { SceneTree } from '@ringozz/godot/SceneTree';
|
|
142
|
+
import { useSignal } from '@ringozz/react-godot';
|
|
143
|
+
|
|
144
|
+
const tree = Engine.getMainLoop() as SceneTree;
|
|
145
|
+
const root = tree.root;
|
|
146
|
+
|
|
147
|
+
// Subscribe to frame updates (process loop)
|
|
148
|
+
useSignal(tree.processFrame, () => {
|
|
149
|
+
// Update animations, camera matrix, physics targets, etc.
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Subscribe to window input events
|
|
153
|
+
useSignal(root.windowInput, (event) => {
|
|
154
|
+
if (event instanceof InputEventMouseMotion) {
|
|
155
|
+
// Handle mouse motion
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Signal **JSX props** (`pressed`, `toggled`, `valueChanged`, `textSubmitted`, ...) are typed as the signal's callback — pass a plain function, no cast needed:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
<Button text="Play" pressed={() => start()} />
|
|
164
|
+
<CheckButton text="Debug" toggled={(on) => setDebug(on)} />
|
|
165
|
+
<HSlider value={round} valueChanged={(v) => setRound(v)} />
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`ComponentProps` only exposes writable members: read-only props (e.g. `Node.multiplayer`) and methods are not settable props.
|
|
169
|
+
|
|
170
|
+
## Full Example
|
|
171
|
+
|
|
172
|
+
Below is a complete interactive 3D physics scene with custom camera controls and physics bodies:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
import { Color, Key, MouseButton, Vector3, Engine } from '@ringozz/godot';
|
|
176
|
+
import { BoxMesh } from '@ringozz/godot/BoxMesh';
|
|
177
|
+
import { BoxShape3D } from '@ringozz/godot/BoxShape3D';
|
|
178
|
+
import { Camera3D } from '@ringozz/godot/Camera3D';
|
|
179
|
+
import { CollisionShape3D } from '@ringozz/godot/CollisionShape3D';
|
|
180
|
+
import { DirectionalLight3D } from '@ringozz/godot/DirectionalLight3D';
|
|
181
|
+
import { BGMode, Environment, ToneMapper } from '@ringozz/godot/Environment';
|
|
182
|
+
import { InputEventMouseButton } from '@ringozz/godot/InputEventMouseButton';
|
|
183
|
+
import { InputEventMouseMotion } from '@ringozz/godot/InputEventMouseMotion';
|
|
184
|
+
import { MeshInstance3D } from '@ringozz/godot/MeshInstance3D';
|
|
185
|
+
import { PhysicsMaterial } from '@ringozz/godot/PhysicsMaterial';
|
|
186
|
+
import { RigidBody3D } from '@ringozz/godot/RigidBody3D';
|
|
187
|
+
import { SceneTree } from '@ringozz/godot/SceneTree';
|
|
188
|
+
import { SphereMesh } from '@ringozz/godot/SphereMesh';
|
|
189
|
+
import { SphereShape3D } from '@ringozz/godot/SphereShape3D';
|
|
190
|
+
import { StandardMaterial3D } from '@ringozz/godot/StandardMaterial3D';
|
|
191
|
+
import { StaticBody3D } from '@ringozz/godot/StaticBody3D';
|
|
192
|
+
import { WorldEnvironment } from '@ringozz/godot/WorldEnvironment';
|
|
193
|
+
import { useSignal, type ComponentProps } from '@ringozz/react-godot';
|
|
194
|
+
import { useRef, type ReactElement } from 'react';
|
|
195
|
+
|
|
196
|
+
const tree = Engine.getMainLoop() as SceneTree;
|
|
197
|
+
const root = tree.root;
|
|
198
|
+
|
|
199
|
+
function PhysBody({ color, shape, children, ...rest }: {
|
|
200
|
+
color: Color | number[];
|
|
201
|
+
shape: ReactElement;
|
|
202
|
+
} & ComponentProps<typeof RigidBody3D>) {
|
|
203
|
+
return (
|
|
204
|
+
<RigidBody3D {...rest}>
|
|
205
|
+
<MeshInstance3D>
|
|
206
|
+
{children}
|
|
207
|
+
<StandardMaterial3D attach="materialOverride" albedoColor={color} />
|
|
208
|
+
</MeshInstance3D>
|
|
209
|
+
<CollisionShape3D>{shape}</CollisionShape3D>
|
|
210
|
+
</RigidBody3D>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function App() {
|
|
215
|
+
const cameraRef = useRef<Camera3D>(null);
|
|
216
|
+
const isDragging = useRef(false);
|
|
217
|
+
const yaw = useRef(0.7);
|
|
218
|
+
const pitch = useRef(0.3);
|
|
219
|
+
const zoom = useRef(7);
|
|
220
|
+
|
|
221
|
+
useSignal(root.windowInput, (event) => {
|
|
222
|
+
if (event instanceof InputEventMouseMotion && isDragging.current) {
|
|
223
|
+
yaw.current -= event.relative.x * 0.005;
|
|
224
|
+
pitch.current = Math.max(-1.4, Math.min(1.4, pitch.current + event.relative.y * 0.005));
|
|
225
|
+
} else if (event instanceof InputEventMouseButton) {
|
|
226
|
+
if (event.buttonIndex === MouseButton.MOUSE_BUTTON_LEFT) {
|
|
227
|
+
isDragging.current = event.pressed;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
event.free();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
useSignal(tree.processFrame, () => {
|
|
234
|
+
const camera = cameraRef.current;
|
|
235
|
+
if (!camera) return;
|
|
236
|
+
|
|
237
|
+
const cx = zoom.current * Math.cos(pitch.current) * Math.sin(yaw.current);
|
|
238
|
+
const cy = zoom.current * Math.sin(pitch.current) + 1;
|
|
239
|
+
const cz = zoom.current * Math.cos(pitch.current) * Math.cos(yaw.current);
|
|
240
|
+
camera.position = new Vector3(cx, cy, cz);
|
|
241
|
+
camera.lookAt(new Vector3(0, 1, 0), new Vector3(0, 1, 0));
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return (
|
|
245
|
+
<>
|
|
246
|
+
<WorldEnvironment>
|
|
247
|
+
<Environment attach="environment" tonemapMode={ToneMapper.TONE_MAPPER_AGX} backgroundMode={BGMode.BG_COLOR} backgroundColor={[0.05, 0.1, 0.25]} />
|
|
248
|
+
</WorldEnvironment>
|
|
249
|
+
<DirectionalLight3D name="Sun" rotation={[-0.8, 0.5, 0]} />
|
|
250
|
+
<Camera3D name="Camera" ref={cameraRef} />
|
|
251
|
+
|
|
252
|
+
{/* Physics Sphere */}
|
|
253
|
+
<PhysBody name="BouncySphere" position={[0, 4, 0]} color={[0.2, 1, 0.2]}
|
|
254
|
+
shape={<SphereShape3D attach="shape" radius={0.5} />}>
|
|
255
|
+
<SphereMesh attach="mesh" radius={0.5} height={1} />
|
|
256
|
+
<PhysicsMaterial attach="physicsMaterialOverride" bounce={0.8} />
|
|
257
|
+
</PhysBody>
|
|
258
|
+
|
|
259
|
+
{/* Ground Plane */}
|
|
260
|
+
<StaticBody3D name="Ground">
|
|
261
|
+
<CollisionShape3D>
|
|
262
|
+
<BoxShape3D attach="shape" size={[10, 0.1, 10]} />
|
|
263
|
+
</CollisionShape3D>
|
|
264
|
+
<MeshInstance3D>
|
|
265
|
+
<BoxMesh attach="mesh" size-x={10} size-y={0.1} size-z={10} />
|
|
266
|
+
<StandardMaterial3D attach="materialOverride" albedoColor={[0.2, 0.2, 0.25]} />
|
|
267
|
+
</MeshInstance3D>
|
|
268
|
+
</StaticBody3D>
|
|
269
|
+
</>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## API Summary
|
|
275
|
+
|
|
276
|
+
| Export | Type | Description |
|
|
277
|
+
| :--- | :--- | :--- |
|
|
278
|
+
| `createRoot(parent)` | Function | Mounts a React component tree into a target Godot `Node` (e.g. `tree.root`). Returns `{ render, unmount }`. |
|
|
279
|
+
| `createPortal(children, container)` | Function | Renders children into a target Godot `Node` (e.g. `CanvasLayer` or `SubViewport`). |
|
|
280
|
+
| `useSignal(signal, callback)` | Hook | Connects a callback to a Godot object signal (e.g. `tree.processFrame`, `node.treeEntered`). Disconnects on unmount. |
|
|
281
|
+
| `useMutableCallback(fn)` | Hook | Returns a `RefObject` whose `.current` always points to the latest callback implementation. |
|
|
282
|
+
| `useTween(create, deps)` | Hook | Reactive tween-as-prop-value. Returns `[spring, tweenRef]` — spread `spring` onto a node; `tweenRef.current` is the live native `Tween`. |
|
|
283
|
+
| `ComponentProps<T>` | Type | Utility type to infer valid React JSX props for any Godot node class `T`. |
|
|
284
|
+
|
|
285
|
+
## Animating props with `useTween`
|
|
286
|
+
|
|
287
|
+
`useTween` animates a node's properties declaratively. You describe the target values once per `to` key; spreading the returned `spring` onto a node binds the tween to it. Re-rendering with the same `deps` keeps the same tween (nothing restarts); changing `deps` creates a new `Tween` and animates from the current values.
|
|
288
|
+
|
|
289
|
+
```tsx
|
|
290
|
+
const [spring, tweenRef] = useTween(() => ({
|
|
291
|
+
from: { position: [0, 0, 0] },
|
|
292
|
+
to: { position: [0, 2, 0], globalRotation: [0, 90, 0] },
|
|
293
|
+
config: { duration: 0.6, transition: TransitionType.TRANS_QUAD, ease: EaseType.EASE_IN_OUT },
|
|
294
|
+
delay: 0, loops: 1, immediate: false,
|
|
295
|
+
onFinished: () => {},
|
|
296
|
+
}), [x, z]);
|
|
297
|
+
|
|
298
|
+
return <Node3D {...spring} />;
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
- **`spring`** holds one function per `to` key (spread them all onto the node; each contributes its own prop's tweener to the shared `Tween`). Array values are converted to the property's value type.
|
|
302
|
+
- **`tweenRef.current`** is the **live native Godot `Tween`**, created when the node mounts (null before that): `tweenRef.current?.kill()`, `?.pause()`, `?.play()`, `?.setSpeedScale(n)`, `?.isRunning()`, `?.finished`…
|
|
303
|
+
- **`config`** maps to the Godot Tween API: `duration` (seconds), `transition`/`ease` (`TransitionType`/`EaseType` — the tween's defaults), `easing` (a `[0,1]→[0,1]` function → `setCustomInterpolator`), `speedScale`.
|
|
304
|
+
- **`onStart`** fires when the tween is created/bound (on mount or when `deps` change), before it starts stepping.
|
|
305
|
+
- **`onFinished`** fires on natural completion only (Godot's `finished` signal); `kill()`/unmount don't fire it, so no stale callbacks.
|
|
306
|
+
- **Unwrapping**: replacing a springed prop with a plain value (e.g. dropping `{...spring}` for `position={[9, 0, 0]}`) does not stop the running tween — it keeps animating to its target and the tween's value wins over the plain value. Stop it with `tweenRef.current?.kill()`.
|
|
307
|
+
|
|
308
|
+
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ringozz/react-godot",
|
|
3
3
|
"author": "Vladimir Davidovich",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-10",
|
|
5
5
|
"description": "A React renderer for Godot Engine via @ringozz/godot",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"godot"
|
|
9
|
+
],
|
|
6
10
|
"type": "module",
|
|
7
11
|
"main": "./src/index.ts",
|
|
8
12
|
"types": "./src/index.ts",
|
|
@@ -16,14 +20,12 @@
|
|
|
16
20
|
"*.md"
|
|
17
21
|
],
|
|
18
22
|
"dependencies": {
|
|
23
|
+
"@ringozz/godot": "^4.7.1-13",
|
|
24
|
+
"@types/react-reconciler": "^0.33.0",
|
|
19
25
|
"react-reconciler": "^0.33.0"
|
|
20
26
|
},
|
|
21
27
|
"peerDependencies": {
|
|
22
|
-
"@ringozz/godot": "^4.7.1-0",
|
|
23
|
-
"react": "^19.2.0"
|
|
24
|
-
},
|
|
25
|
-
"devDependencies": {
|
|
26
28
|
"@types/react": "^19.2.0",
|
|
27
|
-
"
|
|
29
|
+
"react": "^19.2.0"
|
|
28
30
|
}
|
|
29
31
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
/**********************************************************************
|
|
2
|
-
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
-
***********************************************************************/
|
|
4
|
-
|
|
5
|
-
import Reconciler from 'react-reconciler';
|
|
6
|
-
import Constants from 'react-reconciler/constants.js';
|
|
7
|
-
import type { Node } from '@ringozz/godot/Node';
|
|
8
|
-
import * as FiberConfig from './react-fiber.ts';
|
|
9
|
-
export * from './react-hooks.ts';
|
|
10
|
-
export type * from './react-types.ts';
|
|
11
|
-
|
|
12
|
-
const reconciler = Reconciler(FiberConfig);
|
|
13
|
-
reconciler.injectIntoDevTools(undefined as never);
|
|
14
|
-
|
|
15
|
-
export function createRoot(parent: Node) {
|
|
16
|
-
const isStrictMode = process.env.NODE_ENV === 'development';
|
|
17
|
-
const concurrentUpdatesByDefaultOverride = false;
|
|
18
|
-
const identifierPrefix = '';
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
20
|
-
const onUncaughtError = (reconciler as any).defaultOnUncaughtError;
|
|
21
|
-
const onCaughtError = (reconciler as any).defaultOnCaughtError;
|
|
22
|
-
const onRecoverableError = (reconciler as any).defaultOnRecoverableError;
|
|
23
|
-
const onDefaultTransitionIndicator = () => { };
|
|
24
|
-
const root = reconciler.createContainer(
|
|
25
|
-
parent,
|
|
26
|
-
Constants.ConcurrentRoot,
|
|
27
|
-
null,
|
|
28
|
-
isStrictMode,
|
|
29
|
-
concurrentUpdatesByDefaultOverride,
|
|
30
|
-
identifierPrefix,
|
|
31
|
-
onUncaughtError,
|
|
32
|
-
onCaughtError,
|
|
33
|
-
onRecoverableError,
|
|
34
|
-
onDefaultTransitionIndicator
|
|
35
|
-
);
|
|
36
|
-
return {
|
|
37
|
-
render: (component: React.ReactNode) => new Promise<void>((resolve, reject) => {
|
|
38
|
-
try {
|
|
39
|
-
reconciler.updateContainer(component, root, null, resolve);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
}),
|
|
44
|
-
unmount: () => {
|
|
45
|
-
try {
|
|
46
|
-
reconciler.updateContainerSync(null, root, null);
|
|
47
|
-
reconciler.flushSyncWork();
|
|
48
|
-
return Promise.resolve();
|
|
49
|
-
} catch (e) {
|
|
50
|
-
return Promise.reject(e);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function createPortal(children: React.ReactNode, container: Node, key?: string | null): React.ReactPortal {
|
|
57
|
-
return reconciler.createPortal(children, container, null, key) as unknown as React.ReactPortal;
|
|
58
|
-
}
|
|
1
|
+
/**********************************************************************
|
|
2
|
+
Copyright (c) Vladimir Davidovich. All rights reserved.
|
|
3
|
+
***********************************************************************/
|
|
4
|
+
|
|
5
|
+
import Reconciler from 'react-reconciler';
|
|
6
|
+
import Constants from 'react-reconciler/constants.js';
|
|
7
|
+
import type { Node } from '@ringozz/godot/Node';
|
|
8
|
+
import * as FiberConfig from './react-fiber.ts';
|
|
9
|
+
export * from './react-hooks.ts';
|
|
10
|
+
export type * from './react-types.ts';
|
|
11
|
+
|
|
12
|
+
const reconciler = Reconciler(FiberConfig);
|
|
13
|
+
reconciler.injectIntoDevTools(undefined as never);
|
|
14
|
+
|
|
15
|
+
export function createRoot(parent: Node) {
|
|
16
|
+
const isStrictMode = process.env.NODE_ENV === 'development';
|
|
17
|
+
const concurrentUpdatesByDefaultOverride = false;
|
|
18
|
+
const identifierPrefix = '';
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
20
|
+
const onUncaughtError = (reconciler as any).defaultOnUncaughtError;
|
|
21
|
+
const onCaughtError = (reconciler as any).defaultOnCaughtError;
|
|
22
|
+
const onRecoverableError = (reconciler as any).defaultOnRecoverableError;
|
|
23
|
+
const onDefaultTransitionIndicator = () => { };
|
|
24
|
+
const root = reconciler.createContainer(
|
|
25
|
+
parent,
|
|
26
|
+
Constants.ConcurrentRoot,
|
|
27
|
+
null,
|
|
28
|
+
isStrictMode,
|
|
29
|
+
concurrentUpdatesByDefaultOverride,
|
|
30
|
+
identifierPrefix,
|
|
31
|
+
onUncaughtError,
|
|
32
|
+
onCaughtError,
|
|
33
|
+
onRecoverableError,
|
|
34
|
+
onDefaultTransitionIndicator
|
|
35
|
+
);
|
|
36
|
+
return {
|
|
37
|
+
render: (component: React.ReactNode) => new Promise<void>((resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
reconciler.updateContainer(component, root, null, resolve);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
unmount: () => {
|
|
45
|
+
try {
|
|
46
|
+
reconciler.updateContainerSync(null, root, null);
|
|
47
|
+
reconciler.flushSyncWork();
|
|
48
|
+
return Promise.resolve();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return Promise.reject(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createPortal(children: React.ReactNode, container: Node, key?: string | null): React.ReactPortal {
|
|
57
|
+
return reconciler.createPortal(children, container, null, key) as unknown as React.ReactPortal;
|
|
58
|
+
}
|