@defold-typescript/types 0.16.0 → 0.16.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/package.json +1 -1
- package/src/core-types.ts +83 -10
- package/src/engine-globals.d.ts +29 -0
package/package.json
CHANGED
package/src/core-types.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/// <reference types="@typescript-to-lua/language-extensions" />
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A read-only numeric vector accessed by index; `length` is its component count.
|
|
5
|
+
*/
|
|
3
6
|
export interface Vector {
|
|
4
7
|
readonly [index: number]: number;
|
|
5
8
|
readonly length: number;
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A three-component vector with `x`, `y`, and `z` components.
|
|
13
|
+
*/
|
|
8
14
|
export interface Vector3 {
|
|
9
15
|
x: number;
|
|
10
16
|
y: number;
|
|
@@ -22,6 +28,9 @@ export interface Vector3 {
|
|
|
22
28
|
unm: LuaNegationMethod<Vector3>;
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
/**
|
|
32
|
+
* A four-component vector with `x`, `y`, `z`, and `w` components.
|
|
33
|
+
*/
|
|
25
34
|
export interface Vector4 {
|
|
26
35
|
x: number;
|
|
27
36
|
y: number;
|
|
@@ -40,6 +49,9 @@ export interface Vector4 {
|
|
|
40
49
|
unm: LuaNegationMethod<Vector4>;
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
/**
|
|
53
|
+
* A rotation quaternion with `x`, `y`, `z`, and `w` components.
|
|
54
|
+
*/
|
|
43
55
|
export interface Quaternion {
|
|
44
56
|
x: number;
|
|
45
57
|
y: number;
|
|
@@ -48,6 +60,9 @@ export interface Quaternion {
|
|
|
48
60
|
mul: LuaMultiplicationMethod<Quaternion, Quaternion>;
|
|
49
61
|
}
|
|
50
62
|
|
|
63
|
+
/**
|
|
64
|
+
* A 4x4 transformation matrix.
|
|
65
|
+
*/
|
|
51
66
|
export interface Matrix4 {
|
|
52
67
|
m00: number;
|
|
53
68
|
m01: number;
|
|
@@ -73,29 +88,87 @@ export interface Matrix4 {
|
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
declare const HashBrand: unique symbol;
|
|
91
|
+
/**
|
|
92
|
+
* An opaque, branded handle to a *hashed name*: hold it and pass it back to the
|
|
93
|
+
* engine API, but never inspect or construct it. Defold uses it in place of a
|
|
94
|
+
* string for game-object and component ids, resource paths, input-action names,
|
|
95
|
+
* material/animation/constant names, and the `socket`, `path`, and `fragment` of
|
|
96
|
+
* every {@link Url}; you obtain one from the global `hash(name)` function (or
|
|
97
|
+
* receive it back from the engine) and pass it straight to the API, never
|
|
98
|
+
* assembling its bits by hand.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* The brand is a phantom `unique symbol` property (`[HashBrand]: "Hash"`) that
|
|
102
|
+
* exists only in the type system and is erased at transpile — at runtime a
|
|
103
|
+
* `Hash` is the engine's opaque hash value, not an object carrying that key.
|
|
104
|
+
* Because the symbol is not exported, consumer code cannot fabricate a `Hash`;
|
|
105
|
+
* the only sources are `hash()` and the engine. That nominal branding is what
|
|
106
|
+
* stops a bare `string` or `number` from standing in where the API expects an
|
|
107
|
+
* already-hashed name. Many engine functions also accept a plain `string` and
|
|
108
|
+
* hash it for you, but a value already typed `Hash` is passed through as-is.
|
|
109
|
+
*
|
|
110
|
+
* Hashing is one-way: the original string cannot be recovered from a `Hash`.
|
|
111
|
+
* `hash_to_hex(h)` renders it as a hexadecimal string for logging, and `pprint`
|
|
112
|
+
* shows it as `hash: [0x…]`. Two hashes are equal exactly when they name the
|
|
113
|
+
* same thing, so a `Hash` is safe to compare, store, and use as a table key.
|
|
114
|
+
*/
|
|
76
115
|
export interface Hash {
|
|
77
116
|
readonly [HashBrand]: "Hash";
|
|
78
117
|
}
|
|
79
118
|
|
|
80
119
|
declare const OpaqueBrand: unique symbol;
|
|
81
120
|
/**
|
|
82
|
-
* A nominal handle to
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
121
|
+
* A nominal, branded handle to a value the engine owns and manages — a GUI node,
|
|
122
|
+
* a texture, a render target, a physics body, a socket, and so on: hold it and
|
|
123
|
+
* pass it back to the API, but never inspect or construct it. You get one back
|
|
124
|
+
* from an engine function, keep it in a variable, and pass it to the other
|
|
125
|
+
* functions that act on that resource; treat it as an opaque ticket, meaningful
|
|
126
|
+
* to the engine, not a value you read or assemble yourself.
|
|
87
127
|
*
|
|
88
128
|
* @remarks
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
129
|
+
* Why a dedicated type? Each kind of handle is its own brand, so the compiler
|
|
130
|
+
* keeps them apart: `Opaque<"node">` and `Opaque<"texture">` are different
|
|
131
|
+
* types, and passing a texture where a node is expected is a compile error,
|
|
132
|
+
* exactly as a wrong primitive would be. The brand is a phantom `unique symbol`
|
|
133
|
+
* property that lives only in the type system and is erased at transpile — at
|
|
134
|
+
* runtime the value is just the engine's userdata. Because the symbol is never
|
|
135
|
+
* exported, your code cannot fabricate a handle or inspect or construct one; the
|
|
136
|
+
* engine API is the only source.
|
|
137
|
+
*
|
|
138
|
+
* The handle kinds modeled today:
|
|
139
|
+
* - GUI & rendering: `Opaque<"node">`, `Opaque<"texture">`,
|
|
140
|
+
* `Opaque<"render_target">`, `Opaque<"constant">`, `Opaque<"constant_buffer">`
|
|
141
|
+
* - Resources & buffers: `Opaque<"resource">`, `Opaque<"buffer">`,
|
|
142
|
+
* `Opaque<"bufferstream">`
|
|
143
|
+
* - Sockets: `Opaque<"client">`, `Opaque<"server">`, `Opaque<"master">`,
|
|
144
|
+
* `Opaque<"connected">`, `Opaque<"unconnected">`
|
|
145
|
+
* - Box2D physics: `Opaque<"b2Body">`, `Opaque<"b2World">`
|
|
146
|
+
* - Generic: `Opaque<"userdata">`
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* Handles always come back from the engine — for instance:
|
|
150
|
+
* ```ts
|
|
151
|
+
* const node = gui.get_node("button"); // Opaque<"node">
|
|
152
|
+
* const rt = render.render_target("rt", opts); // Opaque<"render_target">
|
|
153
|
+
* const cb = render.constant_buffer(); // Opaque<"constant_buffer">
|
|
154
|
+
* const buf = resource.load_buffer(path); // Opaque<"buffer">
|
|
155
|
+
* const stream = buffer.get_stream(buf, "rgb"); // Opaque<"bufferstream">
|
|
156
|
+
* const world = b2d.get_world(); // Opaque<"b2World">
|
|
157
|
+
* const [conn] = socket.tcp(); // a "master" socket handle
|
|
158
|
+
* function update(self: ...) {} // self is Opaque<"userdata">
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* Contrast with a `LuaTable` alias, which says the opposite — "inspect freely,
|
|
162
|
+
* the shape just isn't modeled." An `Opaque` says "do not look inside; this
|
|
163
|
+
* value is meaningful only to the engine."
|
|
94
164
|
*/
|
|
95
165
|
export interface Opaque<Name extends string> {
|
|
96
166
|
readonly [OpaqueBrand]: Name;
|
|
97
167
|
}
|
|
98
168
|
|
|
169
|
+
/**
|
|
170
|
+
* A message-passing address with `socket`, `path`, and `fragment` components.
|
|
171
|
+
*/
|
|
99
172
|
export interface Url {
|
|
100
173
|
readonly socket: Hash;
|
|
101
174
|
readonly path: Hash;
|
package/src/engine-globals.d.ts
CHANGED
|
@@ -6,15 +6,44 @@ import type * as Core from "./core-types";
|
|
|
6
6
|
// reference and mirror the change in fixtures/globals_doc.json — the
|
|
7
7
|
// engine-globals test fails if the two fall out of sync.
|
|
8
8
|
declare global {
|
|
9
|
+
/** An opaque, branded handle to a hashed name; see {@link Core.Hash}. */
|
|
9
10
|
type Hash = Core.Hash;
|
|
11
|
+
/** Hash a string into the engine's `Hash` handle. */
|
|
10
12
|
function hash(s: string): Core.Hash;
|
|
13
|
+
/** Render a `Hash` handle as its hexadecimal string. */
|
|
11
14
|
function hash_to_hex(h: Core.Hash): string;
|
|
15
|
+
/** Pretty-print any value to the console for debugging. */
|
|
12
16
|
function pprint(v: unknown): void;
|
|
17
|
+
/**
|
|
18
|
+
* A typed handle to a resource the engine owns — a GUI node, a texture, a
|
|
19
|
+
* render target, a physics body, a socket, and so on. You get one back from an
|
|
20
|
+
* engine function, keep it in a variable, and pass it to the functions that
|
|
21
|
+
* act on that resource; you never inspect or construct one yourself.
|
|
22
|
+
*
|
|
23
|
+
* Each kind of handle is its own brand, so `Opaque<"node">` and
|
|
24
|
+
* `Opaque<"texture">` are different types and the compiler rejects passing one
|
|
25
|
+
* where the other is expected. The brand is a phantom `unique symbol` property
|
|
26
|
+
* that lives only in the type system and is erased at transpile; because the
|
|
27
|
+
* symbol is not exported, consumer code cannot fabricate one. The kinds
|
|
28
|
+
* modeled: `node`, `texture`, `render_target`, `constant`, `constant_buffer`,
|
|
29
|
+
* `resource`, `buffer`, `bufferstream`, `client`, `server`, `master`,
|
|
30
|
+
* `connected`, `unconnected`, `b2Body`, `b2World`, `userdata`. You obtain them
|
|
31
|
+
* from the engine, e.g. `gui.get_node("id")`, `render.render_target(...)`,
|
|
32
|
+
* `render.constant_buffer()`, `resource.load_buffer(path)`, `b2d.get_world()`,
|
|
33
|
+
* or `socket.tcp()`. See {@link Core.Opaque} for the full explanation, the per
|
|
34
|
+
* -kind obtain examples, and the contrast with a `LuaTable` alias.
|
|
35
|
+
*/
|
|
13
36
|
type Opaque<Name extends string> = Core.Opaque<Name>;
|
|
37
|
+
/** A message-passing address with `socket`, `path`, and `fragment`; see {@link Core.Url}. */
|
|
14
38
|
type Url = Core.Url;
|
|
39
|
+
/** A read-only numeric vector accessed by index; see {@link Core.Vector}. */
|
|
15
40
|
type Vector = Core.Vector;
|
|
41
|
+
/** A three-component vector with `x`, `y`, `z`; see {@link Core.Vector3}. */
|
|
16
42
|
type Vector3 = Core.Vector3;
|
|
43
|
+
/** A four-component vector with `x`, `y`, `z`, `w`; see {@link Core.Vector4}. */
|
|
17
44
|
type Vector4 = Core.Vector4;
|
|
45
|
+
/** A rotation quaternion with `x`, `y`, `z`, `w`; see {@link Core.Quaternion}. */
|
|
18
46
|
type Quaternion = Core.Quaternion;
|
|
47
|
+
/** A 4x4 transformation matrix; see {@link Core.Matrix4}. */
|
|
19
48
|
type Matrix4 = Core.Matrix4;
|
|
20
49
|
}
|