@defold-typescript/library-types 0.24.0 → 0.25.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.
@@ -78,28 +78,28 @@ declare module 'proto.proto' {
78
78
  package(): void;
79
79
  "import"(): void;
80
80
  message(): void;
81
- enum(): void;
81
+ "enum"(): void;
82
82
  option(): void;
83
83
  extend(): void;
84
84
  service(): void;
85
85
  package(): void;
86
86
  "import"(): void;
87
87
  message(): void;
88
- enum(): void;
88
+ "enum"(): void;
89
89
  option(): void;
90
90
  extend(): void;
91
91
  service(): void;
92
92
  }
93
93
  interface msg_body {
94
94
  message(): void;
95
- enum(): void;
95
+ "enum"(): void;
96
96
  extend(): void;
97
97
  extensions(): void;
98
98
  reserved(): void;
99
99
  oneof(): void;
100
100
  option(): void;
101
101
  message(): void;
102
- enum(): void;
102
+ "enum"(): void;
103
103
  extend(): void;
104
104
  extensions(): void;
105
105
  reserved(): void;
@@ -0,0 +1,183 @@
1
+ /** @noSelfInFile **/
2
+
3
+ /**
4
+ * @see {@link https://github.com/Klaleus/defold-shutter|Github Source}
5
+ * @noResolution
6
+ * @example `import * as shutter from 'shutter.shutter'`
7
+ */
8
+ declare module 'shutter.shutter' {
9
+ /**
10
+ * One camera's state, created by the shutter.script game object in its `init` and
11
+ * removed again in its `final`. The first eight properties mirror the script's
12
+ * `go.property()` declarations; the rest are recalculated every frame and should be
13
+ * read rather than written.
14
+ */
15
+ interface ShutterCamera {
16
+ /** One of `center_behavior`, `expand_behavior` or `stretch_behavior`. */
17
+ behavior: Hash;
18
+ viewport_x: number;
19
+ viewport_y: number;
20
+ viewport_width: number;
21
+ viewport_height: number;
22
+ near: number;
23
+ far: number;
24
+ zoom: number;
25
+ /** Viewport left edge after the window scale and any letterboxing margin. */
26
+ viewport_x_adjusted: number;
27
+ /** Viewport bottom edge after the window scale and any pillarboxing margin. */
28
+ viewport_y_adjusted: number;
29
+ viewport_width_adjusted: number;
30
+ viewport_height_adjusted: number;
31
+ view: Matrix4;
32
+ projection: Matrix4;
33
+ /** Where the shaken object sat before the shake began, and `nil` while no shake
34
+ * is running. `cancel_shake` restores the object to it. */
35
+ shake_origin?: Vector3;
36
+ }
37
+
38
+ /**
39
+ * Every live camera, keyed by the id of the game object it lives on. The
40
+ * shutter.script file writes to it; read from it rather than manipulating it
41
+ * directly.
42
+ */
43
+ const camera_table: LuaMap<Hash, ShutterCamera>;
44
+
45
+ /**
46
+ * Keeps the projection fixed and shrinks the viewport to preserve the display
47
+ * ratio, letterboxing or pillarboxing the remainder.
48
+ */
49
+ const center_behavior: Hash;
50
+
51
+ /**
52
+ * Keeps the viewport filling the window and widens the projection as the window
53
+ * grows, showing more of the game world rather than scaling it.
54
+ */
55
+ const expand_behavior: Hash;
56
+
57
+ /**
58
+ * Keeps both the viewport and the projection filling the window, so the game world
59
+ * distorts with the window ratio.
60
+ */
61
+ const stretch_behavior: Hash;
62
+
63
+ /**
64
+ * Installs a camera's viewport, view matrix and projection matrix into the render
65
+ * context. Call it from a render script before drawing the world.
66
+ * @param object The game object the camera lives on.
67
+ * @returns The camera's frustum, for passing to `render.draw`.
68
+ */
69
+ function activate(object: Hash): Matrix4;
70
+
71
+ /**
72
+ * Restores the viewport and matrices Defold's GUI system expects, sized to the
73
+ * current window. Call it before drawing GUI.
74
+ * @returns The frustum matching the restored matrices.
75
+ */
76
+ function deactivate(): Matrix4;
77
+
78
+ /**
79
+ * Recalculates a camera's viewport, view matrix and projection matrix immediately.
80
+ * The shutter.script game object already does this once per frame; call it directly
81
+ * only after changing a camera property mid-frame.
82
+ * @param object The game object the camera lives on.
83
+ */
84
+ function force_update(object: Hash): void;
85
+
86
+ /**
87
+ * Calculates the camera's viewport in window coordinates, scaled from the
88
+ * game.project display size and, under center behavior, shrunk and centered to
89
+ * preserve the display ratio.
90
+ * @param object The game object the camera lives on.
91
+ * @returns The viewport's x, y, width and height.
92
+ */
93
+ function get_viewport(object: Hash): LuaMultiReturn<[number, number, number, number]>;
94
+
95
+ /**
96
+ * Calculates the camera's view matrix from the inverse of its game object's world
97
+ * transform.
98
+ * @param object The game object the camera lives on.
99
+ */
100
+ function get_view(object: Hash): Matrix4;
101
+
102
+ /**
103
+ * Calculates the camera's orthographic projection matrix, sized from the display
104
+ * under center and stretch behavior and from the window under expand behavior.
105
+ * @param object The game object the camera lives on.
106
+ */
107
+ function get_projection(object: Hash): Matrix4;
108
+
109
+ /**
110
+ * Returns the camera's frustum, the product of its last calculated projection and
111
+ * view matrices.
112
+ * @param object The game object the camera lives on.
113
+ */
114
+ function get_frustum(object: Hash): Matrix4;
115
+
116
+ /**
117
+ * Converts a screen distance into the world distance an object must travel to cover
118
+ * it, accounting for the camera's zoom and, under center and stretch behavior, for
119
+ * the viewport no longer mapping to physical screen coordinates.
120
+ * @param object The game object the camera lives on.
121
+ * @param distance The screen distance to convert.
122
+ * @param absolute Skip rotating the result by the camera's rotation.
123
+ */
124
+ function get_distance(object: Hash, distance: Vector3, absolute?: boolean): Vector3;
125
+
126
+ /**
127
+ * Starts a camera shake animation, cancelling and restarting any shake already
128
+ * running on this camera.
129
+ * @param object The game object the camera lives on.
130
+ * @param parent Shake the camera object's parent instead of the camera itself.
131
+ * @param count How many times to displace the camera before stopping.
132
+ * @param duration Seconds each displacement takes.
133
+ * @param radius How far each displacement moves the camera.
134
+ * @param duration_scalar Multiplies the duration after each displacement. Defaults to 1.
135
+ * @param radius_scalar Multiplies the radius after each displacement. Defaults to 1.
136
+ */
137
+ function shake(
138
+ object: Hash,
139
+ parent: boolean,
140
+ count: number,
141
+ duration: number,
142
+ radius: number,
143
+ duration_scalar?: number,
144
+ radius_scalar?: number,
145
+ ): void;
146
+
147
+ /**
148
+ * Stops a running camera shake and returns the shaken object to where it started.
149
+ * Does nothing if no shake is running.
150
+ * @param object The game object the camera lives on.
151
+ * @param parent Whether the shake was started against the camera object's parent.
152
+ */
153
+ function cancel_shake(object: Hash, parent?: boolean): void;
154
+
155
+ /**
156
+ * Converts a screen position to its world position through the inverse of the
157
+ * camera's frustum.
158
+ * @param object The game object the camera lives on.
159
+ * @param x The screen position's x coordinate.
160
+ * @param y The screen position's y coordinate.
161
+ * @param visible Return `nil` instead when the position falls outside the camera's view.
162
+ * @returns The world position, or `nil` if `visible` filtered it out.
163
+ */
164
+ function screen_to_world(
165
+ object: Hash,
166
+ x: number,
167
+ y: number,
168
+ visible?: boolean,
169
+ ): Vector3 | undefined;
170
+
171
+ /**
172
+ * Converts a world position to its screen position through the camera's frustum.
173
+ * @param object The game object the camera lives on.
174
+ * @param position The world position to convert.
175
+ * @param visible Return `nil` instead when the position falls outside the camera's view.
176
+ * @returns The screen position, or `nil` if `visible` filtered it out.
177
+ */
178
+ function world_to_screen(
179
+ object: Hash,
180
+ position: Vector3,
181
+ visible?: boolean,
182
+ ): Vector3 | undefined;
183
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/library-types",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Vendored TypeScript types for popular Defold Lua libraries, core-type-renamed against @defold-typescript/types.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -97,7 +97,7 @@
97
97
  "parity": "bun scripts/authored-parity.ts"
98
98
  },
99
99
  "dependencies": {
100
- "@defold-typescript/types": "0.24.0"
100
+ "@defold-typescript/types": "0.25.0"
101
101
  },
102
102
  "devDependencies": {
103
103
  "@typescript-to-lua/language-extensions": "1.19.0",
@@ -3,15 +3,19 @@ import ts from "typescript";
3
3
  const printer = ts.createPrinter({ removeComments: true });
4
4
 
5
5
  /**
6
- * A type node's text as a single comment-free line. The printer re-emits the
7
- * AST (so a `//`/`/*` inside a string-literal type is never mistaken for a
6
+ * Any node's text as a single comment-free line. The printer re-emits the AST
7
+ * (so a `//`/`/*` inside a string-literal type is never mistaken for a
8
8
  * comment), then interior whitespace is collapsed so multi-line object literals
9
9
  * and wrapped unions no longer leak newlines or member JSDoc into `/api`.
10
10
  */
11
- function typeText(node: ts.TypeNode, sf: ts.SourceFile): string {
11
+ function oneLineText(node: ts.Node, sf: ts.SourceFile): string {
12
12
  return printer.printNode(ts.EmitHint.Unspecified, node, sf).replace(/\s+/g, " ").trim();
13
13
  }
14
14
 
15
+ function typeText(node: ts.TypeNode, sf: ts.SourceFile): string {
16
+ return oneLineText(node, sf);
17
+ }
18
+
15
19
  interface Field {
16
20
  name: string;
17
21
  doc: string;
@@ -80,7 +84,7 @@ export function extractApiDoc(source: string, moduleName: string): unknown {
80
84
  // vendors both `export function` and bare `function` for the same intent
81
85
  // (`rendy.rendy`, `in.onscreen`). With an `export =`, the bare declarations
82
86
  // are internal plumbing behind the re-exported value, so they stay unemitted
83
- // and the value's interface drives the surface instead (`squid`, `starly`).
87
+ // and the value's interface drives the surface instead (`squid`).
84
88
  const emitBare = !statements.some(ts.isExportAssignment);
85
89
 
86
90
  const elements: Record<string, unknown>[] = [];
@@ -250,6 +254,21 @@ export function extractApiDoc(source: string, moduleName: string): unknown {
250
254
  };
251
255
  }
252
256
 
257
+ /**
258
+ * A declaration's type parameter list as the pre-rendered string the sibling
259
+ * `lower-api-doc` lane emits (`<T>`, `<T = unknown>`, `<A, B extends A>`), or
260
+ * `""` when there is none — absence of the key, not an empty string, is how the
261
+ * model encodes "takes no type arguments".
262
+ */
263
+ function genericClause(
264
+ decl: ts.FunctionDeclaration | ts.MethodSignature,
265
+ sf: ts.SourceFile,
266
+ ): string {
267
+ const params = decl.typeParameters;
268
+ if (!params || params.length === 0) return "";
269
+ return `<${params.map((p) => oneLineText(p, sf)).join(", ")}>`;
270
+ }
271
+
253
272
  function functionElement(
254
273
  decl: ts.FunctionDeclaration | ts.MethodSignature,
255
274
  name: string,
@@ -284,11 +303,13 @@ function functionElement(
284
303
  ];
285
304
 
286
305
  const example = exampleText(decl);
306
+ const generics = genericClause(decl, sf);
287
307
  return {
288
308
  type: "FUNCTION",
289
309
  name,
290
310
  brief: briefOf(summary),
291
311
  description: summary,
312
+ ...(generics === "" ? {} : { generics }),
292
313
  parameters,
293
314
  returnvalues,
294
315
  ...(example === "" ? {} : { examples: example }),