@defold-typescript/types 0.5.0 → 0.5.2
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/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/engine-globals.d.ts +12 -0
- package/src/lifecycle.ts +19 -11
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as Core from "./core-types";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
type Hash = Core.Hash;
|
|
5
|
+
type Opaque<Name extends string> = Core.Opaque<Name>;
|
|
6
|
+
type Url = Core.Url;
|
|
7
|
+
type Vector = Core.Vector;
|
|
8
|
+
type Vector3 = Core.Vector3;
|
|
9
|
+
type Vector4 = Core.Vector4;
|
|
10
|
+
type Quaternion = Core.Quaternion;
|
|
11
|
+
type Matrix4 = Core.Matrix4;
|
|
12
|
+
}
|
package/src/lifecycle.ts
CHANGED
|
@@ -40,27 +40,31 @@ export interface InputAction {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export interface ScriptHooks<TSelf> {
|
|
43
|
-
init
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// `init` returns the script's initial state; it is the sole site TypeScript
|
|
44
|
+
// solves `TSelf` from. The engine owns `self` (a userdata-backed table), so
|
|
45
|
+
// every other hook wraps it in `NoInfer<TSelf>` — otherwise their `self`
|
|
46
|
+
// competes as a second inference site and `TSelf` collapses to `{}`.
|
|
47
|
+
init?(): TSelf;
|
|
48
|
+
update?(self: NoInfer<TSelf>, dt: number): void;
|
|
49
|
+
fixed_update?(self: NoInfer<TSelf>, dt: number): void;
|
|
50
|
+
late_update?(self: NoInfer<TSelf>, dt: number): void;
|
|
47
51
|
// Defold delivers message_id as a pre-hashed `hash`, so handlers must compare
|
|
48
52
|
// it against `hash("...")` constants — a string literal never matches. Sender-
|
|
49
53
|
// side payload narrowing by message id lives on `msg.post` (msg-overloads.d.ts).
|
|
50
54
|
on_message?(
|
|
51
|
-
self: TSelf
|
|
55
|
+
self: NoInfer<TSelf>,
|
|
52
56
|
message_id: Hash,
|
|
53
57
|
message: Record<string | number, unknown>,
|
|
54
58
|
sender: Url,
|
|
55
59
|
): void;
|
|
56
60
|
on_input?(
|
|
57
|
-
self: TSelf
|
|
61
|
+
self: NoInfer<TSelf>,
|
|
58
62
|
action_id: Hash | undefined,
|
|
59
63
|
action: InputAction,
|
|
60
64
|
// biome-ignore lint/suspicious/noConfusingVoidType: Defold lets handlers omit the return; `void` is the right shape for "may return boolean or nothing".
|
|
61
65
|
): boolean | void;
|
|
62
|
-
final?(self: TSelf): void;
|
|
63
|
-
on_reload?(self: TSelf): void;
|
|
66
|
+
final?(self: NoInfer<TSelf>): void;
|
|
67
|
+
on_reload?(self: NoInfer<TSelf>): void;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
export const SCRIPT_HOOK_NAMES = [
|
|
@@ -87,15 +91,19 @@ export type GuiScriptHooks<TSelf> = ScriptHooks<TSelf>;
|
|
|
87
91
|
|
|
88
92
|
export type RenderScriptHooks<TSelf> = Omit<ScriptHooks<TSelf>, "on_input">;
|
|
89
93
|
|
|
90
|
-
export function defineScript<TSelf
|
|
94
|
+
export function defineScript<TSelf = Record<never, never>>(
|
|
95
|
+
hooks: ScriptHooks<TSelf>,
|
|
96
|
+
): ScriptHooks<TSelf> {
|
|
91
97
|
return hooks;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
export function defineGuiScript<TSelf
|
|
100
|
+
export function defineGuiScript<TSelf = Record<never, never>>(
|
|
101
|
+
hooks: GuiScriptHooks<TSelf>,
|
|
102
|
+
): GuiScriptHooks<TSelf> {
|
|
95
103
|
return hooks;
|
|
96
104
|
}
|
|
97
105
|
|
|
98
|
-
export function defineRenderScript<TSelf
|
|
106
|
+
export function defineRenderScript<TSelf = Record<never, never>>(
|
|
99
107
|
hooks: RenderScriptHooks<TSelf>,
|
|
100
108
|
): RenderScriptHooks<TSelf> {
|
|
101
109
|
return hooks;
|