@defold-typescript/types 0.5.5 → 0.6.0
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/api-targets.json +1 -1
- package/generated/b2d.d.ts +3 -0
- package/generated/buffer.d.ts +44 -38
- package/generated/builtin-messages.d.ts +1 -1
- package/generated/camera.d.ts +3 -0
- package/generated/collectionfactory.d.ts +47 -40
- package/generated/collectionproxy.d.ts +23 -18
- package/generated/crash.d.ts +3 -0
- package/generated/factory.d.ts +32 -24
- package/generated/go.d.ts +123 -124
- package/generated/graphics.d.ts +3 -0
- package/generated/gui.d.ts +303 -283
- package/generated/http.d.ts +26 -16
- package/generated/iac.d.ts +3 -0
- package/generated/iap.d.ts +6 -3
- package/generated/image.d.ts +30 -26
- package/generated/json.d.ts +36 -32
- package/generated/kinds/gui-script.d.ts +7 -5
- package/generated/kinds/render-script.d.ts +7 -5
- package/generated/kinds/script.d.ts +7 -5
- package/generated/label.d.ts +16 -9
- package/generated/liveupdate.d.ts +29 -26
- package/generated/model.d.ts +57 -45
- package/generated/msg.d.ts +3 -0
- package/generated/particlefx.d.ts +50 -34
- package/generated/physics.d.ts +153 -133
- package/generated/profiler.d.ts +45 -41
- package/generated/push.d.ts +5 -2
- package/generated/render.d.ts +410 -349
- package/generated/resource.d.ts +619 -572
- package/generated/socket.d.ts +49 -33
- package/generated/sound.d.ts +83 -72
- package/generated/sprite.d.ts +3 -0
- package/generated/sys.d.ts +198 -189
- package/generated/tilemap.d.ts +43 -39
- package/generated/timer.d.ts +42 -36
- package/generated/vmath.d.ts +22 -0
- package/generated/webview.d.ts +3 -0
- package/generated/window.d.ts +23 -17
- package/generated/zlib.d.ts +15 -12
- package/index.d.ts +3 -1
- package/package.json +6 -2
- package/scripts/fidelity-audit.ts +61 -1
- package/scripts/fidelity-baseline.json +10 -10
- package/scripts/ref-doc-delta.ts +143 -0
- package/scripts/regen.ts +18 -9
- package/src/core-types.ts +14 -0
- package/src/emit-dts.ts +219 -13
- package/src/engine-globals.d.ts +2 -0
- package/src/go-overloads.d.ts +43 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +157 -16
- package/src/publish-dts.ts +1 -1
package/src/lifecycle.ts
CHANGED
|
@@ -39,12 +39,32 @@ export interface InputAction {
|
|
|
39
39
|
marked_text?: string;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Phantom type carried by `go.property()` descriptors.
|
|
44
|
+
*
|
|
45
|
+
* @deprecated Declare properties with the value-keyed `properties` field inside
|
|
46
|
+
* `defineScript({ properties })` — that form types them onto `self` directly and
|
|
47
|
+
* needs no descriptor. The `go.property` escape hatch still returns this for
|
|
48
|
+
* backward compatibility.
|
|
49
|
+
*/
|
|
50
|
+
export interface ScriptProperty<TValue> {
|
|
51
|
+
readonly __defoldScriptProperty: TValue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use the value-keyed `properties` field of `defineScript`; the
|
|
56
|
+
* descriptor-plus-`ScriptProperties` extraction is no longer needed.
|
|
57
|
+
*/
|
|
58
|
+
export type ScriptProperties<T extends Record<string, ScriptProperty<unknown>>> = {
|
|
59
|
+
[K in keyof T]: T[K] extends ScriptProperty<infer TValue> ? TValue : never;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export interface ScriptHooks<TSelf, TInitState = TSelf> {
|
|
43
63
|
// `init` returns the script's initial state; it is the sole site TypeScript
|
|
44
|
-
// solves `
|
|
45
|
-
// every other hook wraps it in `NoInfer<TSelf>` — otherwise their `self`
|
|
64
|
+
// solves `TInitState` from. The engine owns `self` (a userdata-backed table),
|
|
65
|
+
// so every other hook wraps it in `NoInfer<TSelf>` — otherwise their `self`
|
|
46
66
|
// competes as a second inference site and `TSelf` collapses to `{}`.
|
|
47
|
-
init?():
|
|
67
|
+
init?(): TInitState;
|
|
48
68
|
update?(self: NoInfer<TSelf>, dt: number): void;
|
|
49
69
|
fixed_update?(self: NoInfer<TSelf>, dt: number): void;
|
|
50
70
|
late_update?(self: NoInfer<TSelf>, dt: number): void;
|
|
@@ -84,27 +104,148 @@ type Equal<A, B> =
|
|
|
84
104
|
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
85
105
|
|
|
86
106
|
// drift-pin: SCRIPT_HOOK_NAMES must list exactly the ScriptHooks members
|
|
87
|
-
const _hookNamesPinnedToInterface: Equal<ScriptHookName, keyof ScriptHooks<unknown>> =
|
|
107
|
+
const _hookNamesPinnedToInterface: Equal<ScriptHookName, keyof ScriptHooks<unknown, unknown>> =
|
|
108
|
+
true;
|
|
88
109
|
void _hookNamesPinnedToInterface;
|
|
89
110
|
|
|
90
|
-
export type GuiScriptHooks<TSelf> = ScriptHooks<TSelf>;
|
|
111
|
+
export type GuiScriptHooks<TSelf, TInitState = TSelf> = ScriptHooks<TSelf, TInitState>;
|
|
112
|
+
|
|
113
|
+
export type RenderScriptHooks<TSelf, TInitState = TSelf> = Omit<
|
|
114
|
+
ScriptHooks<TSelf, TInitState>,
|
|
115
|
+
"on_input"
|
|
116
|
+
>;
|
|
117
|
+
|
|
118
|
+
// The factory hook table plus the value-keyed `properties` field. `TProps` is
|
|
119
|
+
// the property channel (raw default values), `TSelf` the merged `self` the
|
|
120
|
+
// callbacks see (`NoInfer`-wrapped inside the hook set), and `TInitState` what
|
|
121
|
+
// `init` returns. `ScriptHooks` itself stays callback-only so the
|
|
122
|
+
// `SCRIPT_HOOK_NAMES` drift pin remains valid.
|
|
123
|
+
export type ScriptHooksWithProperties<TProps, TSelf, TInitState> = ScriptHooks<
|
|
124
|
+
TSelf,
|
|
125
|
+
TInitState
|
|
126
|
+
> & {
|
|
127
|
+
properties?: TProps;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type GuiScriptHooksWithProperties<TProps, TSelf, TInitState> = GuiScriptHooks<
|
|
131
|
+
TSelf,
|
|
132
|
+
TInitState
|
|
133
|
+
> & {
|
|
134
|
+
properties?: TProps;
|
|
135
|
+
};
|
|
91
136
|
|
|
92
|
-
export type
|
|
137
|
+
export type RenderScriptHooksWithProperties<TProps, TSelf, TInitState> = RenderScriptHooks<
|
|
138
|
+
TSelf,
|
|
139
|
+
TInitState
|
|
140
|
+
> & {
|
|
141
|
+
properties?: TProps;
|
|
142
|
+
};
|
|
93
143
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Type a `.script` component's hook table. At runtime this is an identity
|
|
146
|
+
* function — it returns `hooks` unchanged; its only job is typing. It infers
|
|
147
|
+
* `TSelf` from `init`'s return so every other hook's `self` is typed. Declare
|
|
148
|
+
* editor properties with the value-keyed `properties` field — the key is the
|
|
149
|
+
* property name and the value its default, so the value's type threads onto
|
|
150
|
+
* `self` alongside `init`'s state. The transpiler's `lifecycle-erasure` pass
|
|
151
|
+
* rewrites the top-level call into the flat `function init(self) … end` Defold
|
|
152
|
+
* chunk shape and synthesizes the `go.property(...)` registrations — zero
|
|
153
|
+
* runtime cost, nothing the engine sees changes.
|
|
154
|
+
*
|
|
155
|
+
* Accepts the full `ScriptHooks` set, all optional: `init`, `update`,
|
|
156
|
+
* `fixed_update`, `late_update`, `on_message`, `on_input`, `final`,
|
|
157
|
+
* `on_reload`.
|
|
158
|
+
*
|
|
159
|
+
* Scaffold it with the `defold-script` / `defold-script-typed` VSCode snippets
|
|
160
|
+
* from `defold-typescript init`.
|
|
161
|
+
*
|
|
162
|
+
* @param hooks - the `.script` lifecycle hook table to type and return.
|
|
163
|
+
* @returns the same `hooks` object, now typed (identity at runtime).
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* export default defineScript({
|
|
167
|
+
* init() {
|
|
168
|
+
* return { hits: 0 };
|
|
169
|
+
* },
|
|
170
|
+
* update(self, dt) {
|
|
171
|
+
* self.hits += 1;
|
|
172
|
+
* },
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export function defineScript<TProps extends object = Record<never, never>, TInitState = TProps>(
|
|
177
|
+
hooks: ScriptHooksWithProperties<TProps, TProps & TInitState, TInitState>,
|
|
178
|
+
): ScriptHooksWithProperties<TProps, TProps & TInitState, TInitState> {
|
|
97
179
|
return hooks;
|
|
98
180
|
}
|
|
99
181
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Type a `.gui_script` component's hook table. Like {@link defineScript} it is
|
|
184
|
+
* an identity function at runtime, infers `TSelf` from `init`'s return by
|
|
185
|
+
* default, accepts the same value-keyed `properties` field as
|
|
186
|
+
* {@link defineScript}, and is erased by the transpiler's `lifecycle-erasure`
|
|
187
|
+
* pass into the flat Defold chunk shape.
|
|
188
|
+
*
|
|
189
|
+
* `GuiScriptHooks` is an alias of the `.script` hook set, so it accepts the same
|
|
190
|
+
* full set, all optional: `init`, `update`, `fixed_update`, `late_update`,
|
|
191
|
+
* `on_message`, `on_input`, `final`, `on_reload`.
|
|
192
|
+
*
|
|
193
|
+
* Scaffold it with the `defold-gui` / `defold-gui-typed` VSCode snippets from
|
|
194
|
+
* `defold-typescript init`.
|
|
195
|
+
*
|
|
196
|
+
* @param hooks - the `.gui_script` lifecycle hook table to type and return.
|
|
197
|
+
* @returns the same `hooks` object, now typed (identity at runtime).
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* export default defineGuiScript({
|
|
201
|
+
* init() {
|
|
202
|
+
* return { node: gui.get_node("score") };
|
|
203
|
+
* },
|
|
204
|
+
* on_input(self, action_id, action) {
|
|
205
|
+
* return false;
|
|
206
|
+
* },
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export function defineGuiScript<TProps extends object = Record<never, never>, TInitState = TProps>(
|
|
211
|
+
hooks: GuiScriptHooksWithProperties<TProps, TProps & TInitState, TInitState>,
|
|
212
|
+
): GuiScriptHooksWithProperties<TProps, TProps & TInitState, TInitState> {
|
|
103
213
|
return hooks;
|
|
104
214
|
}
|
|
105
215
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Type a `.render_script` component's hook table. Like {@link defineScript} it
|
|
218
|
+
* is an identity function at runtime, infers `TSelf` from `init`'s return by
|
|
219
|
+
* default, accepts the same value-keyed `properties` field as
|
|
220
|
+
* {@link defineScript}, and is erased by the transpiler's `lifecycle-erasure`
|
|
221
|
+
* pass into the flat Defold chunk shape.
|
|
222
|
+
*
|
|
223
|
+
* `RenderScriptHooks` is `Omit<ScriptHooks, "on_input">` — render scripts do not
|
|
224
|
+
* receive input. It accepts the rest of the set, all optional: `init`,
|
|
225
|
+
* `update`, `fixed_update`, `late_update`, `on_message`, `final`, `on_reload`.
|
|
226
|
+
*
|
|
227
|
+
* Scaffold it with the `defold-render` / `defold-render-typed` VSCode snippets
|
|
228
|
+
* from `defold-typescript init`.
|
|
229
|
+
*
|
|
230
|
+
* @param hooks - the `.render_script` lifecycle hook table to type and return.
|
|
231
|
+
* @returns the same `hooks` object, now typed (identity at runtime).
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* export default defineRenderScript({
|
|
235
|
+
* init() {
|
|
236
|
+
* return { clear: vmath.vector4(0, 0, 0, 1) };
|
|
237
|
+
* },
|
|
238
|
+
* update(self, dt) {
|
|
239
|
+
* render.set_render_target(render.RENDER_TARGET_DEFAULT);
|
|
240
|
+
* },
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export function defineRenderScript<
|
|
245
|
+
TProps extends object = Record<never, never>,
|
|
246
|
+
TInitState = TProps,
|
|
247
|
+
>(
|
|
248
|
+
hooks: RenderScriptHooksWithProperties<TProps, TProps & TInitState, TInitState>,
|
|
249
|
+
): RenderScriptHooksWithProperties<TProps, TProps & TInitState, TInitState> {
|
|
109
250
|
return hooks;
|
|
110
251
|
}
|
package/src/publish-dts.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function wrapAsAmbientGlobal(opts: WrapOptions): string {
|
|
|
20
20
|
const used = collectEngineTypes(opts.emitted);
|
|
21
21
|
const importLine =
|
|
22
22
|
used.length === 0 ? "" : `import type { ${used.join(", ")} } from "${opts.importsFrom}";\n\n`;
|
|
23
|
-
const inner = opts.emitted.replace(
|
|
23
|
+
const inner = opts.emitted.replace(/(^|\n)declare\s+namespace\s+/, "$1namespace ").trimEnd();
|
|
24
24
|
const indented = inner
|
|
25
25
|
.split("\n")
|
|
26
26
|
.map((l) => (l.length === 0 ? l : ` ${l}`))
|