@ringozz/react-godot 4.7.2-585 → 4.7.2-592
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 +6 -5
- package/package.json +2 -2
- package/src/react-hooks.ts +39 -24
package/README.md
CHANGED
|
@@ -284,7 +284,7 @@ export function App() {
|
|
|
284
284
|
| `createPortal(children, container)` | Function | Renders children into a target Godot `Node` (e.g. `CanvasLayer` or `SubViewport`). |
|
|
285
285
|
| `useSignal(signal, callback)` | Hook | Connects a callback to a Godot object signal (e.g. `tree.processFrame`, `node.treeEntered`). Disconnects on unmount. |
|
|
286
286
|
| `useMutableCallback(fn)` | Hook | Returns a `RefObject` whose `.current` always points to the latest callback implementation. |
|
|
287
|
-
| `useTween(create, deps)` | Hook | Reactive tween-as-prop-value. Returns `[spring, tweenRef]` — spread `spring` onto a node; `tweenRef.current` is the live native `Tween`. |
|
|
287
|
+
| `useTween<NodeT>(create, deps)` | Hook | Reactive tween-as-prop-value. Returns `[spring, tweenRef]` — spread `spring` onto a node; `tweenRef.current` is the live native `Tween`. The optional node type (`useTween<Node3D>`) types `to`/`from` array goals as that node's value-type tuples. |
|
|
288
288
|
| `ComponentProps<T>` | Type | Utility type to infer valid React JSX props for any Godot node class `T`. |
|
|
289
289
|
|
|
290
290
|
## Animating props with `useTween`
|
|
@@ -292,9 +292,9 @@ export function App() {
|
|
|
292
292
|
`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.
|
|
293
293
|
|
|
294
294
|
```tsx
|
|
295
|
-
const [spring, tweenRef] = useTween(() => ({
|
|
296
|
-
from: { position: [0, 0, 0] },
|
|
297
|
-
to: { position: [0, 2, 0], globalRotation: [0, 90, 0] },
|
|
295
|
+
const [spring, tweenRef] = useTween<Node3D>(() => ({
|
|
296
|
+
from: { position: [0, 0, 0] },
|
|
297
|
+
to: { position: [0, 2, 0], globalRotation: [0, 90, 0] },
|
|
298
298
|
config: { duration: 0.6, transition: TransitionType.TRANS_QUAD, ease: EaseType.EASE_IN_OUT },
|
|
299
299
|
delay: 0, loops: 1, immediate: false,
|
|
300
300
|
onFinished: () => {},
|
|
@@ -303,7 +303,8 @@ const [spring, tweenRef] = useTween(() => ({
|
|
|
303
303
|
return <Node3D {...spring} />;
|
|
304
304
|
```
|
|
305
305
|
|
|
306
|
-
- **`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.
|
|
306
|
+
- **`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.
|
|
307
|
+
- **Node-typed goals**: call `useTween<Node3D>(...)` so `to`/`from` are typed against that node's props — `position: [0, 2, 0]` and nested `basis: [[…]]` infer as `Vector3`/`Basis`, with no `as Vector3` casts. A bare `useTween(...)` keeps array goals loose (`number[]`).
|
|
307
308
|
- **`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`…
|
|
308
309
|
- **`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`.
|
|
309
310
|
- **`onStart`** fires when the tween is created/bound (on mount or when `deps` change), before it starts stepping.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ringozz/react-godot",
|
|
3
3
|
"author": "Vladimir Davidovich",
|
|
4
|
-
"version": "4.7.2-
|
|
4
|
+
"version": "4.7.2-592",
|
|
5
5
|
"description": "A React renderer for Godot Engine via @ringozz/godot",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"*.md"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ringozz/godot": "^4.7.2-
|
|
26
|
+
"@ringozz/godot": "^4.7.2-592",
|
|
27
27
|
"@types/react-reconciler": "^0.33.0",
|
|
28
28
|
"react-reconciler": "^0.33.0"
|
|
29
29
|
},
|
package/src/react-hooks.ts
CHANGED
|
@@ -47,9 +47,21 @@ export function useSignal<T extends (...args: any[]) => any>(signal: Signal<T>,
|
|
|
47
47
|
// identity diff drops them, so nothing restarts); changing deps creates a new
|
|
48
48
|
// tween (the previous one is killed).
|
|
49
49
|
|
|
50
|
-
// Value-type goals are named tuples on the JS side — flat ones are `number[]`,
|
|
51
|
-
// nested ones (Transform2D/Basis/Transform3D/Projection/AABB) are `number[][]`.
|
|
52
|
-
|
|
50
|
+
// Value-type goals are named tuples on the JS side — flat ones are `number[]`,
|
|
51
|
+
// nested ones (Transform2D/Basis/Transform3D/Projection/AABB) are `number[][]`.
|
|
52
|
+
//
|
|
53
|
+
// When the caller passes a node instance type (e.g. `useTween<Node3D>`), `to`
|
|
54
|
+
// /`from` are contextually typed against that node's settable props, so each
|
|
55
|
+
// array goal infers as the property's value-type tuple (Vector3, Basis, …). A
|
|
56
|
+
// bare `useTween(...)` call keeps the loose behavior below (`number[]` goals).
|
|
57
|
+
export type TweenValue = number | number[] | number[][] | GodotVar;
|
|
58
|
+
|
|
59
|
+
// Settable props whose value is tween-compatible (numeric, value-type tuples,
|
|
60
|
+
// GodotVar); excludes bool/string/signal/container/method props. Mapping over
|
|
61
|
+
// `keyof N` lets `to` be contextually typed with the node's value-type tuples.
|
|
62
|
+
type TweenableProps<T> = {
|
|
63
|
+
[K in keyof T as T[K] extends TweenValue ? K : never]: T[K];
|
|
64
|
+
};
|
|
53
65
|
|
|
54
66
|
export interface TweenConfig {
|
|
55
67
|
/** Seconds (default 1). */
|
|
@@ -64,11 +76,11 @@ export interface TweenConfig {
|
|
|
64
76
|
speedScale?: number;
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
export interface TweenProps<
|
|
68
|
-
/** Start values, applied on the first build (mount) before animating to `to`. */
|
|
69
|
-
from?: Partial<
|
|
70
|
-
/** Target values — one assigner is returned per key. */
|
|
71
|
-
to:
|
|
79
|
+
export interface TweenProps<P extends Record<string, unknown> = Record<string, TweenValue>> {
|
|
80
|
+
/** Start values, applied on the first build (mount) before animating to `to`. */
|
|
81
|
+
from?: Partial<P>;
|
|
82
|
+
/** Target values — one assigner is returned per key. */
|
|
83
|
+
to: P;
|
|
72
84
|
config?: TweenConfig;
|
|
73
85
|
/** Seconds; per-tweener PropertyTweener.setDelay. */
|
|
74
86
|
delay?: number;
|
|
@@ -81,19 +93,19 @@ export interface TweenProps<T extends Record<string, TweenValue> = Record<string
|
|
|
81
93
|
onFinished?: () => void;
|
|
82
94
|
}
|
|
83
95
|
|
|
84
|
-
export type Spring<
|
|
96
|
+
export type Spring<P extends Record<string, unknown>> = { [K in keyof P]: P[K] };
|
|
85
97
|
|
|
86
98
|
// tweenProperty/set reject generic JS arrays, so array goals are reconstructed
|
|
87
99
|
// as the property's value type by `toValueType` (resolves the node's
|
|
88
100
|
// property type and returns a GodotVar carrier the `_C` tween path unwraps;
|
|
89
101
|
// non-array goals pass through unchanged).
|
|
90
102
|
|
|
91
|
-
function makeSpring<
|
|
92
|
-
tweenRef: { current: Tween | null },
|
|
93
|
-
props: TweenProps<
|
|
94
|
-
): Spring<
|
|
95
|
-
const config = props.config ?? {};
|
|
96
|
-
const spring = {} as Spring<
|
|
103
|
+
function makeSpring<P extends Record<string, unknown>>(
|
|
104
|
+
tweenRef: { current: Tween | null },
|
|
105
|
+
props: TweenProps<P>,
|
|
106
|
+
): Spring<P> {
|
|
107
|
+
const config = props.config ?? {};
|
|
108
|
+
const spring = {} as Spring<P>;
|
|
97
109
|
let started = false;
|
|
98
110
|
let applyFrom = false;
|
|
99
111
|
|
|
@@ -126,15 +138,18 @@ function makeSpring<T extends Record<string, TweenValue>>(
|
|
|
126
138
|
if (props.delay !== undefined) tw.setDelay(props.delay);
|
|
127
139
|
if (config.easing) tw.setCustomInterpolator(config.easing);
|
|
128
140
|
};
|
|
129
|
-
spring[key as keyof
|
|
130
|
-
}
|
|
131
|
-
return spring;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function useTween<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
spring[key as keyof P] = assigner as unknown as P[keyof P];
|
|
142
|
+
}
|
|
143
|
+
return spring;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function useTween<
|
|
147
|
+
T extends Instance = any,
|
|
148
|
+
P extends Partial<TweenableProps<T>> = Partial<TweenableProps<T>>,
|
|
149
|
+
>(
|
|
150
|
+
create: () => TweenProps<P>,
|
|
151
|
+
deps: unknown[] = [],
|
|
152
|
+
): [Spring<P>, React.RefObject<Tween | null>] {
|
|
138
153
|
const tweenRef = useRef<Tween | null>(null);
|
|
139
154
|
// 'create' is intentionally re-evaluated via `deps`, not listed here.
|
|
140
155
|
/* oxlint-disable-next-line react-hooks/exhaustive-deps */
|