@defold-typescript/types 0.5.0 → 0.5.1

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  import "./generated/builtin-messages";
2
2
  import "./src/msg-overloads";
3
3
  import "./src/go-overloads";
4
+ import "./src/engine-globals";
4
5
  import "./generated/b2d";
5
6
  import "./generated/buffer";
6
7
  import "./generated/camera";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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?(self: TSelf): void;
44
- update?(self: TSelf, dt: number): void;
45
- fixed_update?(self: TSelf, dt: number): void;
46
- late_update?(self: TSelf, dt: number): void;
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>(hooks: ScriptHooks<TSelf>): ScriptHooks<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>(hooks: GuiScriptHooks<TSelf>): GuiScriptHooks<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;