gtac-types 0.0.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.
@@ -0,0 +1,594 @@
1
+ /**
2
+ * GTAC Vector, Matrix, and Colour Type Definitions
3
+ *
4
+ * Defines mathematical types used throughout GTA Connected: 2D and 3D vectors
5
+ * (`Vec2`, `Vec3`), 4x4 transformation matrices (`Matrix4x4`), colour tuples
6
+ * (`RGB`, `RGBA`), and network synchronisation flags (`NetFlags`).
7
+ *
8
+ * Vectors support common operations: addition, subtraction, multiplication,
9
+ * division (all component-wise), dot product, cross product (Vec3 only),
10
+ * normalization, length/magnitude, distance, and linear interpolation.
11
+ * Static helper objects (`vec2`, `vec3`, `matrix4x4`) provide functional-style
12
+ * alternatives to the class instance methods.
13
+ *
14
+ * All declarations are global — no import required.
15
+ *
16
+ * @module types/vec
17
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
18
+ *
19
+ * @example
20
+ * // Create positions and calculate distance
21
+ * const pos1 = new Vec3(0, 0, 10);
22
+ * const pos2 = new Vec3(100, 50, 10);
23
+ * const dist = pos1.distance(pos2);
24
+ * message("Distance: " + dist + " units");
25
+ *
26
+ * @example
27
+ * // Linear interpolation for smooth movement
28
+ * const start = vec3.create(0, 0, 0);
29
+ * const end = vec3.create(100, 0, 0);
30
+ * const mid = vec3.lerp(start, end, 0.5); // (50, 0, 0)
31
+ */
32
+
33
+ // ===== Primitives =====
34
+
35
+ /**
36
+ * Red-Green-Blue colour tuple.
37
+ * Each component is in the range 0–255.
38
+ *
39
+ * @example
40
+ * const red: RGB = [255, 0, 0];
41
+ */
42
+ type RGB = [number, number, number];
43
+
44
+ /**
45
+ * Red-Green-Blue-Alpha colour tuple.
46
+ * Each component is in the range 0–255, where alpha 0 = fully transparent
47
+ * and alpha 255 = fully opaque.
48
+ *
49
+ * @example
50
+ * const semiTransparentRed: RGBA = [255, 0, 0, 128];
51
+ */
52
+ type RGBA = [number, number, number, number];
53
+
54
+ // ===== Vec2 =====
55
+
56
+ /**
57
+ * 2D vector with `x` and `y` components.
58
+ *
59
+ * Represents a point or direction in 2D space. Provides instance methods for
60
+ * arithmetic operations, magnitude calculation, normalization, and dot product.
61
+ * Use `vec2.create()` or `new Vec2(x, y)` to construct.
62
+ *
63
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
64
+ *
65
+ * @example
66
+ * // Add two 2D vectors
67
+ * const a = new Vec2(10, 20);
68
+ * const b = new Vec2(5, 15);
69
+ * const result = a.add(b); // Vec2(15, 35)
70
+ */
71
+ declare class Vec2 {
72
+ /** Horizontal component. */
73
+ x: number;
74
+
75
+ /** Vertical component. */
76
+ y: number;
77
+
78
+ /**
79
+ * Constructs a new 2D vector.
80
+ *
81
+ * @param x - Horizontal component.
82
+ * @param y - Vertical component.
83
+ */
84
+ constructor(x: number, y: number);
85
+
86
+ /**
87
+ * Adds another Vec2 to this one, component-wise.
88
+ *
89
+ * @param other - The vector to add.
90
+ * @returns A new `Vec2` representing the sum.
91
+ */
92
+ add(other: Vec2): Vec2;
93
+
94
+ /**
95
+ * Subtracts another Vec2 from this one, component-wise.
96
+ *
97
+ * @param other - The vector to subtract.
98
+ * @returns A new `Vec2` representing the difference.
99
+ */
100
+ sub(other: Vec2): Vec2;
101
+
102
+ /**
103
+ * Multiplies this Vec2 by another, component-wise (Hadamard product).
104
+ * For scalar multiplication, use `mul(new Vec2(scalar, scalar))`.
105
+ *
106
+ * @param other - The vector to multiply by.
107
+ * @returns A new `Vec2` representing the product.
108
+ */
109
+ mul(other: Vec2): Vec2;
110
+
111
+ /**
112
+ * Divides this Vec2 by another, component-wise.
113
+ *
114
+ * @param other - The vector to divide by.
115
+ * @returns A new `Vec2` representing the quotient.
116
+ */
117
+ div(other: Vec2): Vec2;
118
+
119
+ /**
120
+ * Computes the Euclidean magnitude (length) of this vector.
121
+ *
122
+ * @returns The length: `sqrt(x*x + y*y)`.
123
+ */
124
+ length(): number;
125
+
126
+ /**
127
+ * Returns a normalized copy of this vector (unit length = 1).
128
+ * The direction is preserved; only the magnitude changes.
129
+ *
130
+ * @returns A new `Vec2` with the same direction and length 1.
131
+ */
132
+ normalize(): Vec2;
133
+
134
+ /**
135
+ * Computes the dot (scalar) product of this vector and another.
136
+ * Dot product is positive if vectors point in similar directions,
137
+ * zero if perpendicular, negative if opposite.
138
+ *
139
+ * @param other - The other vector.
140
+ * @returns The dot product: `x*other.x + y*other.y`.
141
+ */
142
+ dot(other: Vec2): number;
143
+ }
144
+
145
+ /**
146
+ * Static helper functions for `Vec2` operations.
147
+ *
148
+ * Provides functional-style alternatives to the `Vec2` instance methods.
149
+ * Pass two vectors to operate on, or one vector for unary operations.
150
+ *
151
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
152
+ *
153
+ * @example
154
+ * const result = vec2.add(vec2.create(1, 2), vec2.create(3, 4));
155
+ */
156
+ declare var vec2: {
157
+ /**
158
+ * Creates a new `Vec2` with the given components.
159
+ * Equivalent to `new Vec2(x, y)`.
160
+ *
161
+ * @param x - Horizontal component.
162
+ * @param y - Vertical component.
163
+ * @returns A new `Vec2`.
164
+ */
165
+ create(x: number, y: number): Vec2;
166
+
167
+ /**
168
+ * Adds two Vec2s component-wise.
169
+ *
170
+ * @param a - First vector.
171
+ * @param b - Second vector.
172
+ * @returns A new `Vec2` representing `a + b`.
173
+ */
174
+ add(a: Vec2, b: Vec2): Vec2;
175
+
176
+ /**
177
+ * Subtracts `b` from `a` component-wise.
178
+ *
179
+ * @param a - First vector.
180
+ * @param b - Vector to subtract.
181
+ * @returns A new `Vec2` representing `a - b`.
182
+ */
183
+ sub(a: Vec2, b: Vec2): Vec2;
184
+
185
+ /**
186
+ * Multiplies two Vec2s component-wise.
187
+ *
188
+ * @param a - First vector.
189
+ * @param b - Second vector.
190
+ * @returns A new `Vec2` representing the Hadamard product.
191
+ */
192
+ mul(a: Vec2, b: Vec2): Vec2;
193
+
194
+ /**
195
+ * Divides `a` by `b` component-wise.
196
+ *
197
+ * @param a - Numerator vector.
198
+ * @param b - Denominator vector.
199
+ * @returns A new `Vec2` representing `a / b`.
200
+ */
201
+ div(a: Vec2, b: Vec2): Vec2;
202
+
203
+ /**
204
+ * Computes the Euclidean magnitude of a Vec2.
205
+ *
206
+ * @param v - The input vector.
207
+ * @returns The length: `sqrt(v.x*v.x + v.y*v.y)`.
208
+ */
209
+ length(v: Vec2): number;
210
+
211
+ /**
212
+ * Normalizes a Vec2 to unit length.
213
+ *
214
+ * @param v - The input vector.
215
+ * @returns A new `Vec2` with magnitude 1 and the same direction.
216
+ */
217
+ normalize(v: Vec2): Vec2;
218
+
219
+ /**
220
+ * Computes the dot product of two Vec2s.
221
+ *
222
+ * @param a - First vector.
223
+ * @param b - Second vector.
224
+ * @returns The dot product scalar.
225
+ */
226
+ dot(a: Vec2, b: Vec2): number;
227
+ };
228
+
229
+ // ===== Vec3 =====
230
+
231
+ /**
232
+ * 3D vector with `x`, `y`, and `z` components.
233
+ *
234
+ * Represents a point, direction, or offset in 3D space. Supports all Vec2
235
+ * operations plus cross product, Euclidean distance, and linear interpolation.
236
+ * Accessible via numeric index as well as named properties.
237
+ *
238
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
239
+ *
240
+ * @example
241
+ * // Calculate cross product for surface normals
242
+ * const up = new Vec3(0, 0, 1);
243
+ * const forward = new Vec3(1, 0, 0);
244
+ * const right = up.cross(forward); // (0, 1, 0)
245
+ *
246
+ * @example
247
+ * // Smoothly interpolate between two positions
248
+ * const from = new Vec3(0, 0, 10);
249
+ * const to = new Vec3(100, 0, 10);
250
+ * // Move 30% of the way
251
+ * const step = from.lerp(to, 0.3);
252
+ */
253
+ declare class Vec3 {
254
+ /**
255
+ * Numeric index access: `vec[0]` = x, `vec[1]` = y, `vec[2]` = z.
256
+ */
257
+ [index: number]: number;
258
+
259
+ /** Horizontal (east-west) component. */
260
+ x: number;
261
+
262
+ /** Vertical (north-south) component. */
263
+ y: number;
264
+
265
+ /** Elevation (up-down) component. */
266
+ z: number;
267
+
268
+ /**
269
+ * Constructs a new 3D vector.
270
+ *
271
+ * @param x - Horizontal component.
272
+ * @param y - Vertical component.
273
+ * @param z - Elevation component.
274
+ */
275
+ constructor(x: number, y: number, z: number);
276
+
277
+ /**
278
+ * Adds another Vec3 to this one, component-wise.
279
+ *
280
+ * @param other - The vector to add.
281
+ * @returns A new `Vec3` representing the sum.
282
+ */
283
+ add(other: Vec3): Vec3;
284
+
285
+ /**
286
+ * Subtracts another Vec3 from this one, component-wise.
287
+ *
288
+ * @param other - The vector to subtract.
289
+ * @returns A new `Vec3` representing the difference.
290
+ */
291
+ sub(other: Vec3): Vec3;
292
+
293
+ /**
294
+ * Multiplies this Vec3 by another, component-wise (Hadamard product).
295
+ *
296
+ * @param other - The vector to multiply by.
297
+ * @returns A new `Vec3` representing the product.
298
+ */
299
+ mul(other: Vec3): Vec3;
300
+
301
+ /**
302
+ * Divides this Vec3 by another, component-wise.
303
+ *
304
+ * @param other - The vector to divide by.
305
+ * @returns A new `Vec3` representing the quotient.
306
+ */
307
+ div(other: Vec3): Vec3;
308
+
309
+ /**
310
+ * Computes the Euclidean magnitude (length) of this vector.
311
+ *
312
+ * @returns The length: `sqrt(x*x + y*y + z*z)`.
313
+ */
314
+ length(): number;
315
+
316
+ /**
317
+ * Returns a normalized copy of this vector (unit length = 1).
318
+ *
319
+ * @returns A new `Vec3` with the same direction and magnitude 1.
320
+ */
321
+ normalize(): Vec3;
322
+
323
+ /**
324
+ * Computes the dot (scalar) product of this vector and another.
325
+ *
326
+ * @param other - The other vector.
327
+ * @returns The dot product: `x*other.x + y*other.y + z*other.z`.
328
+ */
329
+ dot(other: Vec3): number;
330
+
331
+ /**
332
+ * Computes the cross product of this vector and another.
333
+ * The result is perpendicular to both input vectors.
334
+ *
335
+ * @param other - The other vector.
336
+ * @returns A new `Vec3` perpendicular to both inputs.
337
+ */
338
+ cross(other: Vec3): Vec3;
339
+
340
+ /**
341
+ * Computes the Euclidean distance between this vector and another.
342
+ *
343
+ * @param other - The target vector to measure distance to.
344
+ * @returns The distance between the two vectors.
345
+ */
346
+ distance(other: Vec3): number;
347
+
348
+ /**
349
+ * Linearly interpolates towards another vector by a given factor.
350
+ *
351
+ * @param other - The target vector.
352
+ * @param t - Interpolation factor (0.0 = this vector, 1.0 = other vector).
353
+ * @returns A new `Vec3` representing the interpolated position.
354
+ */
355
+ lerp(other: Vec3, t: number): Vec3;
356
+ }
357
+
358
+ /**
359
+ * Static helper functions for `Vec3` operations.
360
+ *
361
+ * Provides functional-style alternatives to the `Vec3` instance methods.
362
+ *
363
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
364
+ *
365
+ * @example
366
+ * const midpoint = vec3.lerp(posA, posB, 0.5);
367
+ */
368
+ declare var vec3: {
369
+ /**
370
+ * Creates a new `Vec3` with the given components.
371
+ * Equivalent to `new Vec3(x, y, z)`.
372
+ *
373
+ * @param x - Horizontal component.
374
+ * @param y - Vertical component.
375
+ * @param z - Elevation component.
376
+ * @returns A new `Vec3`.
377
+ */
378
+ create(x: number, y: number, z: number): Vec3;
379
+
380
+ /**
381
+ * Adds two Vec3s component-wise.
382
+ *
383
+ * @param a - First vector.
384
+ * @param b - Second vector.
385
+ * @returns A new `Vec3` representing `a + b`.
386
+ */
387
+ add(a: Vec3, b: Vec3): Vec3;
388
+
389
+ /**
390
+ * Subtracts `b` from `a` component-wise.
391
+ *
392
+ * @param a - First vector.
393
+ * @param b - Vector to subtract.
394
+ * @returns A new `Vec3` representing `a - b`.
395
+ */
396
+ sub(a: Vec3, b: Vec3): Vec3;
397
+
398
+ /**
399
+ * Multiplies two Vec3s component-wise.
400
+ *
401
+ * @param a - First vector.
402
+ * @param b - Second vector.
403
+ * @returns A new `Vec3` representing the Hadamard product.
404
+ */
405
+ mul(a: Vec3, b: Vec3): Vec3;
406
+
407
+ /**
408
+ * Divides `a` by `b` component-wise.
409
+ *
410
+ * @param a - Numerator vector.
411
+ * @param b - Denominator vector.
412
+ * @returns A new `Vec3` representing `a / b`.
413
+ */
414
+ div(a: Vec3, b: Vec3): Vec3;
415
+
416
+ /**
417
+ * Computes the Euclidean magnitude of a Vec3.
418
+ *
419
+ * @param v - The input vector.
420
+ * @returns The length.
421
+ */
422
+ length(v: Vec3): number;
423
+
424
+ /**
425
+ * Normalizes a Vec3 to unit length.
426
+ *
427
+ * @param v - The input vector.
428
+ * @returns A new `Vec3` with magnitude 1.
429
+ */
430
+ normalize(v: Vec3): Vec3;
431
+
432
+ /**
433
+ * Computes the dot product of two Vec3s.
434
+ *
435
+ * @param a - First vector.
436
+ * @param b - Second vector.
437
+ * @returns The dot product scalar.
438
+ */
439
+ dot(a: Vec3, b: Vec3): number;
440
+
441
+ /**
442
+ * Computes the cross product of two Vec3s.
443
+ *
444
+ * @param a - First vector.
445
+ * @param b - Second vector.
446
+ * @returns A new `Vec3` perpendicular to both inputs.
447
+ */
448
+ cross(a: Vec3, b: Vec3): Vec3;
449
+
450
+ /**
451
+ * Computes the Euclidean distance between two Vec3s.
452
+ *
453
+ * @param a - First vector.
454
+ * @param b - Second vector.
455
+ * @returns The distance between `a` and `b`.
456
+ */
457
+ distance(a: Vec3, b: Vec3): number;
458
+
459
+ /**
460
+ * Linearly interpolates between two Vec3s by factor `t`.
461
+ *
462
+ * @param a - Start vector (t = 0).
463
+ * @param b - End vector (t = 1).
464
+ * @param t - Interpolation factor (0.0 to 1.0).
465
+ * @returns A new `Vec3` representing the interpolated position.
466
+ */
467
+ lerp(a: Vec3, b: Vec3, t: number): Vec3;
468
+ };
469
+
470
+ // ===== Matrix4x4 =====
471
+
472
+ /**
473
+ * 4x4 transformation matrix for 3D transformations.
474
+ *
475
+ * Used to represent combined translation, rotation, and scaling in a single
476
+ * mathematical structure. The internal representation is engine-defined (opaque).
477
+ * Use `matrix4x4` static helpers to create and manipulate matrices.
478
+ *
479
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
480
+ */
481
+ type Matrix4x4 = {}
482
+
483
+ /**
484
+ * Static helper functions for `Matrix4x4` creation and manipulation.
485
+ *
486
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
487
+ *
488
+ * @example
489
+ * // Create a translation matrix and apply it
490
+ * const trans = matrix4x4.translation(10, 0, 0);
491
+ * const rot = matrix4x4.rotation(0, 0, 90);
492
+ * const combined = matrix4x4.mul(rot, trans);
493
+ */
494
+ declare var matrix4x4: {
495
+ /**
496
+ * Creates a new identity matrix (no transformation).
497
+ * An identity matrix has 1s on the diagonal and 0s elsewhere.
498
+ *
499
+ * @returns A new identity `Matrix4x4`.
500
+ */
501
+ create(): Matrix4x4;
502
+
503
+ /**
504
+ * Creates a rotation matrix from Euler angles (in degrees).
505
+ *
506
+ * @param x - Rotation around the X axis (pitch) in degrees.
507
+ * @param y - Rotation around the Y axis (yaw) in degrees.
508
+ * @param z - Rotation around the Z axis (roll) in degrees.
509
+ * @returns A new rotation `Matrix4x4`.
510
+ */
511
+ rotation(x: number, y: number, z: number): Matrix4x4;
512
+
513
+ /**
514
+ * Creates a translation (position offset) matrix.
515
+ *
516
+ * @param x - X-axis translation.
517
+ * @param y - Y-axis translation.
518
+ * @param z - Z-axis translation.
519
+ * @returns A new translation `Matrix4x4`.
520
+ */
521
+ translation(x: number, y: number, z: number): Matrix4x4;
522
+
523
+ /**
524
+ * Multiplies two matrices (applies `m2` after `m1`).
525
+ * Order matters: `mul(m1, m2)` = `m2 * m1` in standard math notation.
526
+ *
527
+ * @param m1 - First matrix (applied first).
528
+ * @param m2 - Second matrix (applied second).
529
+ * @returns A new `Matrix4x4` representing the product.
530
+ */
531
+ mul(m1: Matrix4x4, m2: Matrix4x4): Matrix4x4;
532
+
533
+ /**
534
+ * Computes the inverse of a matrix.
535
+ * Multiplying a matrix by its inverse yields the identity matrix.
536
+ *
537
+ * @param m - The matrix to invert.
538
+ * @returns The inverse `Matrix4x4`.
539
+ */
540
+ inverse(m: Matrix4x4): Matrix4x4;
541
+
542
+ /**
543
+ * Computes the transpose of a matrix (flips rows and columns).
544
+ *
545
+ * @param m - The matrix to transpose.
546
+ * @returns The transposed `Matrix4x4`.
547
+ */
548
+ transpose(m: Matrix4x4): Matrix4x4;
549
+
550
+ /**
551
+ * Creates a new identity matrix (same as `create()`).
552
+ *
553
+ * @returns A new identity `Matrix4x4`.
554
+ */
555
+ identity(): Matrix4x4;
556
+ };
557
+
558
+ // ===== NetFlags =====
559
+
560
+ /**
561
+ * Network synchronisation flags for elements.
562
+ *
563
+ * Controls how an element's position, rotation, and state are synchronised
564
+ * between the server and connected clients. Adjust interpolation mode and
565
+ * sync rate to balance network bandwidth against visual smoothness.
566
+ *
567
+ * @see https://wiki.gtaconnected.com — GTA Connected Wiki
568
+ *
569
+ * @example
570
+ * // Configure an element to sync at 50ms intervals
571
+ * element.netFlags.syncRate = 50;
572
+ * element.netFlags.interpolation = 1; // Linear interpolation
573
+ */
574
+ interface NetFlags {
575
+ /**
576
+ * Bitfield of synchronisation flags.
577
+ * Each bit enables or disables a specific sync feature (position, rotation,
578
+ * velocity, etc.).
579
+ */
580
+ syncFlags: number;
581
+
582
+ /**
583
+ * Interpolation mode determining how positions between sync updates are smoothed.
584
+ * 0 = no interpolation (snap), 1 = linear interpolation, etc.
585
+ */
586
+ interpolation: number;
587
+
588
+ /**
589
+ * Synchronisation rate in milliseconds.
590
+ * Lower values = more frequent updates = smoother but more bandwidth.
591
+ * Higher values = less frequent = more bandwidth-efficient but potentially jittery.
592
+ */
593
+ syncRate: number;
594
+ }