@nativewrappers/server 0.0.76 → 0.0.78
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/entities/BaseEntity.d.ts +3 -0
- package/enum/OrphanMode.d.ts +5 -0
- package/enum/index.d.ts +1 -0
- package/index.d.ts +1 -0
- package/index.js +68 -0
- package/package.json +1 -1
- package/common/index.js +0 -1481
package/common/index.js
DELETED
|
@@ -1,1481 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/common/utils/Vector.ts
|
|
5
|
-
var EXT_VECTOR2 = 20;
|
|
6
|
-
var EXT_VECTOR3 = 21;
|
|
7
|
-
var EXT_VECTOR4 = 22;
|
|
8
|
-
var size = Symbol("size");
|
|
9
|
-
var Vector = class _Vector {
|
|
10
|
-
static {
|
|
11
|
-
__name(this, "Vector");
|
|
12
|
-
}
|
|
13
|
-
static create(x, y = x, z, w) {
|
|
14
|
-
if (typeof x === "object") ({ x, y, z, w } = x);
|
|
15
|
-
const size2 = this instanceof _Vector && this.size || [x, y, z, w].filter((arg) => arg !== void 0).length;
|
|
16
|
-
switch (size2) {
|
|
17
|
-
case 1:
|
|
18
|
-
case 2:
|
|
19
|
-
return new Vector2(x, y);
|
|
20
|
-
case 3:
|
|
21
|
-
return new Vector3(x, y, z);
|
|
22
|
-
case 4:
|
|
23
|
-
return new Vector4(x, y, z, w);
|
|
24
|
-
default:
|
|
25
|
-
throw new Error(`Cannot instantiate Vector with size of ${size2}.`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a deep copy of the provided vector.
|
|
30
|
-
* @param obj The vector to clone.
|
|
31
|
-
* @returns A new vector instance that is a copy of the provided vector.
|
|
32
|
-
*/
|
|
33
|
-
static clone(obj) {
|
|
34
|
-
return this.create(obj);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Creates a vector from binary data in a MsgpackBuffer.
|
|
38
|
-
* @param msgpackBuffer The buffer containing binary data.
|
|
39
|
-
* @returns A new vector instance.
|
|
40
|
-
*/
|
|
41
|
-
static fromBuffer({ buffer, type }) {
|
|
42
|
-
if (type !== EXT_VECTOR2 && type !== EXT_VECTOR3 && type !== EXT_VECTOR4)
|
|
43
|
-
throw new Error("Buffer type is not a valid Vector.");
|
|
44
|
-
const arr = new Array(buffer.length / 4);
|
|
45
|
-
for (let i = 0; i < arr.length; i++) arr[i] = Number(buffer.readFloatLE(i * 4).toPrecision(7));
|
|
46
|
-
return this.fromArray(arr);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Performs an operation between a vector and either another vector or scalar value.
|
|
50
|
-
* @param a - The first vector.
|
|
51
|
-
* @param b - The second vector or scalar value.
|
|
52
|
-
* @param operator - The function defining the operation to perform.
|
|
53
|
-
* @returns A new vector resulting from the operation.
|
|
54
|
-
*/
|
|
55
|
-
static operate(a, b, operator) {
|
|
56
|
-
let { x, y, z, w } = a;
|
|
57
|
-
const isNumber = typeof b === "number";
|
|
58
|
-
x = operator(x, isNumber ? b : b.x ?? 0);
|
|
59
|
-
y = operator(y, isNumber ? b : b.y ?? 0);
|
|
60
|
-
if (z !== void 0) z = operator(z, isNumber ? b : b.z ?? 0);
|
|
61
|
-
if (w !== void 0) w = operator(w, isNumber ? b : b.w ?? 0);
|
|
62
|
-
return this.create(x, y, z, w);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Adds two vectors or a scalar value to a vector.
|
|
66
|
-
* @param a - The first vector or scalar value.
|
|
67
|
-
* @param b - The second vector or scalar value.
|
|
68
|
-
* @returns A new vector with incremented components.
|
|
69
|
-
*/
|
|
70
|
-
static add(a, b) {
|
|
71
|
-
return this.operate(a, b, (x, y) => x + y);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Adds a scalar value to the x-component of a vector.
|
|
75
|
-
* @param obj - The vector.
|
|
76
|
-
* @param x - The value to add to the x-component.
|
|
77
|
-
* @returns A new vector with the x-component incremented.
|
|
78
|
-
*/
|
|
79
|
-
static addX(obj, x) {
|
|
80
|
-
return this.create(obj.x + x, obj.y, obj.z, obj.w);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Adds a scalar value to the y-component of a vector.
|
|
84
|
-
* @param obj - The vector.
|
|
85
|
-
* @param y - The value to add to the y-component.
|
|
86
|
-
* @returns A new vector with the y-component incremented.
|
|
87
|
-
*/
|
|
88
|
-
static addY(obj, y) {
|
|
89
|
-
return this.create(obj.x, obj.y + y, obj.z, obj.w);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Adds a scalar value to the z-component of a vector.
|
|
93
|
-
* @param obj - The vector.
|
|
94
|
-
* @param z - The value to add to the z-component.
|
|
95
|
-
* @returns A new vector with the z-component incremented.
|
|
96
|
-
*/
|
|
97
|
-
static addZ(obj, z) {
|
|
98
|
-
return this.create(obj.x, obj.y, obj.z + z, obj.w);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Adds a scalar value to the w-component of a vector.
|
|
102
|
-
* @param obj - The vector.
|
|
103
|
-
* @param w - The value to add to the w-component.
|
|
104
|
-
* @returns A new vector with the w-component incremented.
|
|
105
|
-
*/
|
|
106
|
-
static addW(obj, w) {
|
|
107
|
-
return this.create(obj.x, obj.y, obj.z, obj.w + w);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
111
|
-
* @param a - The vector.
|
|
112
|
-
* @param b - The second vector or scalar value.
|
|
113
|
-
* @returns A new vector with subtracted components.
|
|
114
|
-
*/
|
|
115
|
-
static subtract(a, b) {
|
|
116
|
-
return this.operate(a, b, (x, y) => x - y);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
120
|
-
* @param a - The vector.
|
|
121
|
-
* @param b - The second vector or scalar value.
|
|
122
|
-
* @returns A new vector with multiplied components.
|
|
123
|
-
*/
|
|
124
|
-
static multiply(a, b) {
|
|
125
|
-
return this.operate(a, b, (x, y) => x * y);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Divides two vectors by their components, or divides a vector by a scalar value.
|
|
129
|
-
* @param a - The vector.
|
|
130
|
-
* @param b - The second vector or scalar vector.
|
|
131
|
-
* @returns A new vector with divided components.
|
|
132
|
-
*/
|
|
133
|
-
static divide(a, b) {
|
|
134
|
-
return this.operate(a, b, (x, y) => x / y);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Performs an operation between a vector and either another vector or scalar value converting the vector into absolute values.
|
|
138
|
-
* @param a - The first vector.
|
|
139
|
-
* @param b - The second vector or scalar value.
|
|
140
|
-
* @param operator - The function defining the operation to perform.
|
|
141
|
-
* @returns A new vector resulting from the operation.
|
|
142
|
-
*/
|
|
143
|
-
static operateAbsolute(a, b, operator) {
|
|
144
|
-
let { x, y, z, w } = a;
|
|
145
|
-
const isNumber = typeof b === "number";
|
|
146
|
-
x = operator(Math.abs(x), isNumber ? b : Math.abs(b.x ?? 0));
|
|
147
|
-
y = operator(Math.abs(y), isNumber ? b : Math.abs(b.y ?? 0));
|
|
148
|
-
if (z !== void 0) z = operator(Math.abs(z), isNumber ? b : Math.abs(b.z ?? 0));
|
|
149
|
-
if (w !== void 0) w = operator(Math.abs(w), isNumber ? b : Math.abs(b.w ?? 0));
|
|
150
|
-
return this.create(x, y, z, w);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Adds two vectors or a scalar value to a vector.
|
|
154
|
-
* @param a - The first vector or scalar value.
|
|
155
|
-
* @param b - The second vector or scalar value.
|
|
156
|
-
* @returns A new vector with incremented components.
|
|
157
|
-
*/
|
|
158
|
-
static addAbsolute(a, b) {
|
|
159
|
-
return this.operateAbsolute(a, b, (x, y) => x + y);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Subtracts one vector from another or subtracts a scalar value from a vector.
|
|
163
|
-
* @param a - The vector.
|
|
164
|
-
* @param b - The second vector or scalar value.
|
|
165
|
-
* @returns A new vector with subtracted components.
|
|
166
|
-
*/
|
|
167
|
-
static subtractAbsolute(a, b) {
|
|
168
|
-
return this.operateAbsolute(a, b, (x, y) => x - y);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Multiplies two vectors by their components, or multiplies a vector by a scalar value.
|
|
172
|
-
* @param a - The vector.
|
|
173
|
-
* @param b - The second vector or scalar value.
|
|
174
|
-
* @returns A new vector with multiplied components.
|
|
175
|
-
*/
|
|
176
|
-
static multiplyAbsolute(a, b) {
|
|
177
|
-
return this.operateAbsolute(a, b, (x, y) => x * y);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Divides two vectors by their components, or divides a vector by a scalar value
|
|
181
|
-
* @param a - The vector.
|
|
182
|
-
* @param b - The second vector or scalar vector.
|
|
183
|
-
* @returns A new vector with divided components.
|
|
184
|
-
*/
|
|
185
|
-
static divideAbsolute(a, b) {
|
|
186
|
-
return this.operateAbsolute(a, b, (x, y) => x / y);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Calculates the dot product of two vectors.
|
|
190
|
-
* @param a - The first vector.
|
|
191
|
-
* @param b - The second vector.
|
|
192
|
-
* @returns A scalar value representing the degree of alignment between the input vectors.
|
|
193
|
-
*/
|
|
194
|
-
static dotProduct(a, b) {
|
|
195
|
-
let result = 0;
|
|
196
|
-
for (const key of ["x", "y", "z", "w"]) {
|
|
197
|
-
const x = a[key];
|
|
198
|
-
const y = b[key];
|
|
199
|
-
if (!!x && !!y) result += x * y;
|
|
200
|
-
else if (x || y) throw new Error("Vectors must have the same dimensions.");
|
|
201
|
-
}
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Calculates the cross product of two vectors in three-dimensional space.
|
|
206
|
-
* @param a - The first vector.
|
|
207
|
-
* @param b - The second vector.
|
|
208
|
-
* @returns A new vector perpendicular to both input vectors.
|
|
209
|
-
*/
|
|
210
|
-
static crossProduct(a, b) {
|
|
211
|
-
const { x: ax, y: ay, z: az, w: aw } = a;
|
|
212
|
-
const { x: bx, y: by, z: bz } = b;
|
|
213
|
-
if (ax === void 0 || ay === void 0 || az === void 0 || bx === void 0 || by === void 0 || bz === void 0)
|
|
214
|
-
throw new Error("Vector.crossProduct requires two three-dimensional vectors.");
|
|
215
|
-
return this.create(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx, aw);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Normalizes a vector, producing a new vector with the same direction but with a magnitude of 1.
|
|
219
|
-
* @param vector - The vector to be normalized.
|
|
220
|
-
* @returns The new normalized vector.
|
|
221
|
-
*/
|
|
222
|
-
static normalize(a) {
|
|
223
|
-
const length = a instanceof _Vector ? a.Length : this.Length(a);
|
|
224
|
-
return this.divide(a, length);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Creates a vector from an array of numbers.
|
|
228
|
-
* @param primitive An array of numbers (usually returned by a native).
|
|
229
|
-
*/
|
|
230
|
-
static fromArray(primitive) {
|
|
231
|
-
const [x, y, z, w] = primitive;
|
|
232
|
-
return this.create(x, y, z, w);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Creates a vector from an array or object containing vector components.
|
|
236
|
-
* @param primitive The object to use as a vector.
|
|
237
|
-
*/
|
|
238
|
-
static fromObject(primitive) {
|
|
239
|
-
if (Array.isArray(primitive)) return this.fromArray(primitive);
|
|
240
|
-
if ("buffer" in primitive) return this.fromBuffer(primitive);
|
|
241
|
-
const { x, y, z, w } = primitive;
|
|
242
|
-
return this.create(x, y, z, w);
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Creates an array of vectors from an array of number arrays
|
|
246
|
-
* @param primitives A multi-dimensional array of number arrays
|
|
247
|
-
*/
|
|
248
|
-
static fromArrays(primitives) {
|
|
249
|
-
return primitives.map(this.fromArray);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Calculates the length (magnitude) of a vector.
|
|
253
|
-
* @param obj - The vector for which to calculate the length.
|
|
254
|
-
* @returns The magnitude of the vector.
|
|
255
|
-
*/
|
|
256
|
-
static Length(obj) {
|
|
257
|
-
let sum = 0;
|
|
258
|
-
for (const key of ["x", "y", "z", "w"]) {
|
|
259
|
-
if (key in obj) {
|
|
260
|
-
const value = obj[key];
|
|
261
|
-
sum += value * value;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return Math.sqrt(sum);
|
|
265
|
-
}
|
|
266
|
-
type;
|
|
267
|
-
[size] = 2;
|
|
268
|
-
x = 0;
|
|
269
|
-
y = 0;
|
|
270
|
-
z;
|
|
271
|
-
w;
|
|
272
|
-
/**
|
|
273
|
-
* Constructs a new vector.
|
|
274
|
-
* @param x The x-component of the vector.
|
|
275
|
-
* @param y The y-component of the vector (optional, defaults to x).
|
|
276
|
-
* @param z The z-component of the vector (optional).
|
|
277
|
-
* @param w The w-component of the vector (optional).
|
|
278
|
-
*/
|
|
279
|
-
constructor(x, y = x, z, w) {
|
|
280
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
281
|
-
if (typeof arguments[i] !== "number") {
|
|
282
|
-
throw new TypeError(
|
|
283
|
-
`${this.constructor.name} argument at index ${i} must be a number, but got ${typeof arguments[i]}`
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
this.x = x;
|
|
288
|
-
this.y = y;
|
|
289
|
-
}
|
|
290
|
-
*[Symbol.iterator]() {
|
|
291
|
-
yield this.x;
|
|
292
|
-
yield this.y;
|
|
293
|
-
if (this.z !== void 0) yield this.z;
|
|
294
|
-
if (this.w !== void 0) yield this.w;
|
|
295
|
-
}
|
|
296
|
-
get size() {
|
|
297
|
-
return this[size];
|
|
298
|
-
}
|
|
299
|
-
toString() {
|
|
300
|
-
return `vector${this.size}(${this.toArray().join(", ")})`;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* @see Vector.clone
|
|
304
|
-
*/
|
|
305
|
-
clone() {
|
|
306
|
-
return _Vector.clone(this);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* The product of the Euclidean magnitudes of this and another Vector.
|
|
310
|
-
*
|
|
311
|
-
* @param v Vector to find Euclidean magnitude between.
|
|
312
|
-
* @returns Euclidean magnitude with another vector.
|
|
313
|
-
*/
|
|
314
|
-
distanceSquared(v) {
|
|
315
|
-
const w = this.subtract(v);
|
|
316
|
-
return _Vector.dotProduct(w, w);
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* The distance between two Vectors.
|
|
320
|
-
*
|
|
321
|
-
* @param v Vector to find distance between.
|
|
322
|
-
* @returns Distance between this and another vector.
|
|
323
|
-
*/
|
|
324
|
-
distance(v) {
|
|
325
|
-
return Math.sqrt(this.distanceSquared(v));
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* @see Vector.normalize
|
|
329
|
-
*/
|
|
330
|
-
normalize() {
|
|
331
|
-
return _Vector.normalize(this);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* @see Vector.dotProduct
|
|
335
|
-
*/
|
|
336
|
-
dotProduct(v) {
|
|
337
|
-
return _Vector.dotProduct(this, v);
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* @see Vector.add
|
|
341
|
-
*/
|
|
342
|
-
add(v) {
|
|
343
|
-
return _Vector.add(this, v);
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* @see Vector.addX
|
|
347
|
-
*/
|
|
348
|
-
addX(x) {
|
|
349
|
-
return _Vector.addX(this, x);
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* @see Vector.addY
|
|
353
|
-
*/
|
|
354
|
-
addY(y) {
|
|
355
|
-
return _Vector.addY(this, y);
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* @see Vector.subtract
|
|
359
|
-
*/
|
|
360
|
-
subtract(v) {
|
|
361
|
-
return _Vector.subtract(this, v);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* @see Vector.multiply
|
|
365
|
-
*/
|
|
366
|
-
multiply(v) {
|
|
367
|
-
return _Vector.multiply(this, v);
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* @see Vector.divide
|
|
371
|
-
*/
|
|
372
|
-
divide(v) {
|
|
373
|
-
return _Vector.divide(this, v);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* @see Vector.addAbsolute
|
|
377
|
-
*/
|
|
378
|
-
addAbsolute(v) {
|
|
379
|
-
return _Vector.addAbsolute(this, v);
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* @see Vector.subtractAbsolute
|
|
383
|
-
*/
|
|
384
|
-
subtractAbsolute(v) {
|
|
385
|
-
return _Vector.subtractAbsolute(this, v);
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* @see Vector.multiply
|
|
389
|
-
*/
|
|
390
|
-
multiplyAbsolute(v) {
|
|
391
|
-
return _Vector.multiplyAbsolute(this, v);
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* @see Vector.divide
|
|
395
|
-
*/
|
|
396
|
-
divideAbsolute(v) {
|
|
397
|
-
return _Vector.divideAbsolute(this, v);
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Converts the vector to an array of its components.
|
|
401
|
-
*/
|
|
402
|
-
toArray() {
|
|
403
|
-
return [...this];
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Replaces the components of the vector with the components of another vector object.
|
|
407
|
-
* @param v - The object whose components will replace the current vector's components.
|
|
408
|
-
*/
|
|
409
|
-
replace(v) {
|
|
410
|
-
for (const key of ["x", "y", "z", "w"]) {
|
|
411
|
-
if (key in this && key in v) this[key] = v[key];
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Calculates the length (magnitude) of a vector.
|
|
416
|
-
* @returns The magnitude of the vector.
|
|
417
|
-
*/
|
|
418
|
-
get Length() {
|
|
419
|
-
let sum = 0;
|
|
420
|
-
for (const value of this) sum += value * value;
|
|
421
|
-
return Math.sqrt(sum);
|
|
422
|
-
}
|
|
423
|
-
swizzle(components) {
|
|
424
|
-
if (!/^[xyzw]+$/.test(components)) throw new Error(`Invalid key in swizzle components (${components}).`);
|
|
425
|
-
const arr = components.split("").map((char) => this[char] ?? 0);
|
|
426
|
-
return _Vector.create(...arr);
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
var Vector2 = class _Vector2 extends Vector {
|
|
430
|
-
static {
|
|
431
|
-
__name(this, "Vector2");
|
|
432
|
-
}
|
|
433
|
-
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
434
|
-
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
435
|
-
type = 5 /* Vector2 */;
|
|
436
|
-
[size] = 2;
|
|
437
|
-
static Zero = new _Vector2(0, 0);
|
|
438
|
-
/**
|
|
439
|
-
* Constructs a new 2D vector.
|
|
440
|
-
* @param x The x-component of the vector.
|
|
441
|
-
* @param y The y-component of the vector (optional, defaults to x).
|
|
442
|
-
*/
|
|
443
|
-
constructor(x, y = x) {
|
|
444
|
-
super(x, y);
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Creates a new vector based on the provided parameters.
|
|
448
|
-
* @param x The x-component of the vector.
|
|
449
|
-
* @param y The y-component of the vector (optional, defaults to the value of x).
|
|
450
|
-
* @returns A new vector instance.
|
|
451
|
-
*/
|
|
452
|
-
static create(x, y = x) {
|
|
453
|
-
if (typeof x === "object") ({ x, y } = x);
|
|
454
|
-
return new this(x, y);
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
var Vector3 = class _Vector3 extends Vector {
|
|
458
|
-
static {
|
|
459
|
-
__name(this, "Vector3");
|
|
460
|
-
}
|
|
461
|
-
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
462
|
-
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
463
|
-
type = 6 /* Vector3 */;
|
|
464
|
-
[size] = 3;
|
|
465
|
-
z = 0;
|
|
466
|
-
static Zero = new _Vector3(0, 0, 0);
|
|
467
|
-
static UnitX = new _Vector3(1, 0, 0);
|
|
468
|
-
static UnitY = new _Vector3(0, 1, 0);
|
|
469
|
-
static UnitZ = new _Vector3(0, 0, 1);
|
|
470
|
-
static One = new _Vector3(1, 1, 1);
|
|
471
|
-
static Up = new _Vector3(0, 0, 1);
|
|
472
|
-
static Down = new _Vector3(0, 0, -1);
|
|
473
|
-
static Left = new _Vector3(-1, 0, 0);
|
|
474
|
-
static Right = new _Vector3(1, 0, 0);
|
|
475
|
-
static ForwardRH = new _Vector3(0, 1, 0);
|
|
476
|
-
static ForwardLH = new _Vector3(0, -1, 0);
|
|
477
|
-
static BackwardRH = new _Vector3(0, -1, 0);
|
|
478
|
-
static BackwardLH = new _Vector3(0, 1, 0);
|
|
479
|
-
static Backward = _Vector3.BackwardRH;
|
|
480
|
-
/**
|
|
481
|
-
* Constructs a new 3D vector.
|
|
482
|
-
* @param x The x-component of the vector.
|
|
483
|
-
* @param y The y-component of the vector (optional, defaults to x).
|
|
484
|
-
* @param z The z-component of the vector (optional, defaults to y).
|
|
485
|
-
*/
|
|
486
|
-
constructor(x, y = x, z = y) {
|
|
487
|
-
super(x, y, z);
|
|
488
|
-
this.z = z;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Creates a new vector based on the provided parameters.
|
|
492
|
-
* @param x The x-component of the vector.
|
|
493
|
-
* @param y The y-component of the vector (optional, defaults to the value of x).
|
|
494
|
-
* @param z The z-component of the vector (optional, defaults to the value of y).
|
|
495
|
-
* @returns A new vector instance.
|
|
496
|
-
*/
|
|
497
|
-
static create(x, y = x, z = y) {
|
|
498
|
-
if (typeof x === "object") ({ x, y, z = y } = x);
|
|
499
|
-
return new this(x, y, z);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* @see Vector.addZ
|
|
503
|
-
*/
|
|
504
|
-
addZ(z) {
|
|
505
|
-
return Vector.addZ(this, z);
|
|
506
|
-
}
|
|
507
|
-
/**
|
|
508
|
-
* @see Vector.crossProduct
|
|
509
|
-
*/
|
|
510
|
-
crossProduct(v) {
|
|
511
|
-
return Vector.crossProduct(this, v);
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* @returns the x and y values as Vec2
|
|
515
|
-
*/
|
|
516
|
-
toVec2() {
|
|
517
|
-
return new Vector2(this.x, this.y);
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
var Vector4 = class _Vector4 extends Vector {
|
|
521
|
-
static {
|
|
522
|
-
__name(this, "Vector4");
|
|
523
|
-
}
|
|
524
|
-
// DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
|
|
525
|
-
// TO EXIST, CHANGING IT WILL BREAK STUFF
|
|
526
|
-
type = 7 /* Vector4 */;
|
|
527
|
-
[size] = 4;
|
|
528
|
-
z = 0;
|
|
529
|
-
w = 0;
|
|
530
|
-
static Zero = new _Vector4(0, 0, 0, 0);
|
|
531
|
-
/**
|
|
532
|
-
* Constructs a new 4D vector.
|
|
533
|
-
* @param x The x-component of the vector.
|
|
534
|
-
* @param y The y-component of the vector (optional, defaults to x).
|
|
535
|
-
* @param z The z-component of the vector (optional, defaults to y).
|
|
536
|
-
* @param w The w-component of the vector (optional, defaults to z).
|
|
537
|
-
*/
|
|
538
|
-
constructor(x, y = x, z = y, w = z) {
|
|
539
|
-
super(x, y, z, w);
|
|
540
|
-
this.z = z;
|
|
541
|
-
this.w = w;
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Creates a new vector based on the provided parameters.
|
|
545
|
-
* @param x The x-component of the vector.
|
|
546
|
-
* @param y The y-component of the vector (optional, defaults to the value of x).
|
|
547
|
-
* @param z The z-component of the vector (optional, defaults to the value of y).
|
|
548
|
-
* @param w The w-component of the vector (optional, defaults to the value of z).
|
|
549
|
-
* @returns A new vector instance.
|
|
550
|
-
*/
|
|
551
|
-
static create(x, y = x, z = y, w = z) {
|
|
552
|
-
if (typeof x === "object") ({ x, y, z = y, w = z } = x);
|
|
553
|
-
return new this(x, y, z, w);
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* @see Vector.addZ
|
|
557
|
-
*/
|
|
558
|
-
addZ(z) {
|
|
559
|
-
return Vector.addZ(this, z);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* @see Vector.addW
|
|
563
|
-
*/
|
|
564
|
-
addW(w) {
|
|
565
|
-
return Vector.addW(this, w);
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* @see Vector.crossProduct
|
|
569
|
-
*/
|
|
570
|
-
crossProduct(v) {
|
|
571
|
-
return Vector.crossProduct(this, v);
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* @returns the x and y values as Vec2
|
|
575
|
-
*/
|
|
576
|
-
toVec2() {
|
|
577
|
-
return new Vector2(this.x, this.y);
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* @returns the x and y values as Vec3
|
|
581
|
-
*/
|
|
582
|
-
toVec3() {
|
|
583
|
-
return new Vector3(this.x, this.y, this.z);
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
// src/common/utils/PointF.ts
|
|
588
|
-
var PointF = class _PointF {
|
|
589
|
-
constructor(x, y, z) {
|
|
590
|
-
this.x = x;
|
|
591
|
-
this.y = y;
|
|
592
|
-
this.z = z;
|
|
593
|
-
}
|
|
594
|
-
static {
|
|
595
|
-
__name(this, "PointF");
|
|
596
|
-
}
|
|
597
|
-
static empty() {
|
|
598
|
-
return new _PointF(0, 0, 0);
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
// src/common/utils/Maths.ts
|
|
603
|
-
var Maths = class {
|
|
604
|
-
static {
|
|
605
|
-
__name(this, "Maths");
|
|
606
|
-
}
|
|
607
|
-
static clamp(num, min, max) {
|
|
608
|
-
return num <= min ? min : num >= max ? max : num;
|
|
609
|
-
}
|
|
610
|
-
static getRandomInt(min, max) {
|
|
611
|
-
min = Math.ceil(min);
|
|
612
|
-
max = Math.floor(max);
|
|
613
|
-
return Math.floor(Math.random() * (max - min)) + min;
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
// src/common/utils/Quaternion.ts
|
|
618
|
-
var Quaternion = class {
|
|
619
|
-
static {
|
|
620
|
-
__name(this, "Quaternion");
|
|
621
|
-
}
|
|
622
|
-
x;
|
|
623
|
-
y;
|
|
624
|
-
z;
|
|
625
|
-
w;
|
|
626
|
-
constructor(valueXOrVector, yOrW, z, w) {
|
|
627
|
-
if (valueXOrVector instanceof Vector3) {
|
|
628
|
-
this.x = valueXOrVector.x;
|
|
629
|
-
this.y = valueXOrVector.y;
|
|
630
|
-
this.z = valueXOrVector.z;
|
|
631
|
-
this.w = yOrW ?? 0;
|
|
632
|
-
} else if (yOrW === void 0) {
|
|
633
|
-
this.x = valueXOrVector;
|
|
634
|
-
this.y = valueXOrVector;
|
|
635
|
-
this.z = valueXOrVector;
|
|
636
|
-
this.w = valueXOrVector;
|
|
637
|
-
} else {
|
|
638
|
-
this.x = valueXOrVector;
|
|
639
|
-
this.y = yOrW;
|
|
640
|
-
this.z = z ?? 0;
|
|
641
|
-
this.w = w ?? 0;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
// src/common/utils/Color.ts
|
|
647
|
-
var Color = class _Color {
|
|
648
|
-
static {
|
|
649
|
-
__name(this, "Color");
|
|
650
|
-
}
|
|
651
|
-
static Transparent = new _Color(0, 0, 0, 0);
|
|
652
|
-
static Black = new _Color(0, 0, 0);
|
|
653
|
-
static White = new _Color(255, 255, 255);
|
|
654
|
-
static WhiteSmoke = new _Color(245, 245, 245);
|
|
655
|
-
static fromArgb(a, r, g, b) {
|
|
656
|
-
return new _Color(r, g, b, a);
|
|
657
|
-
}
|
|
658
|
-
static fromRgb(r, g, b) {
|
|
659
|
-
return new _Color(r, g, b);
|
|
660
|
-
}
|
|
661
|
-
static fromArray(primitive) {
|
|
662
|
-
return new _Color(primitive[0], primitive[1], primitive[2], 255);
|
|
663
|
-
}
|
|
664
|
-
a;
|
|
665
|
-
r;
|
|
666
|
-
g;
|
|
667
|
-
b;
|
|
668
|
-
constructor(r, g, b, a = 255) {
|
|
669
|
-
this.r = r;
|
|
670
|
-
this.g = g;
|
|
671
|
-
this.b = b;
|
|
672
|
-
this.a = a;
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
// src/common/utils/cleanPlayerName.ts
|
|
677
|
-
var cleanPlayerName = /* @__PURE__ */ __name((original) => {
|
|
678
|
-
let displayName = original.substring(0, 75).replace(
|
|
679
|
-
// biome-ignore lint/suspicious/noMisleadingCharacterClass: <explanation>
|
|
680
|
-
/[\u0000-\u001F\u007F-\u009F\u200B-\u200D\uFEFF\u200E\uA9C1-\uA9C5\u239B-\u23AD]/g,
|
|
681
|
-
""
|
|
682
|
-
).replace(
|
|
683
|
-
/~(HUD_\S+|HC_\S+|[a-z]|[a1]_\d+|bold|italic|ws|wanted_star|nrt|EX_R\*|BLIP_\S+|ACCEPT|CANCEL|PAD_\S+|INPUT_\S+|INPUTGROUP_\S+)~/gi,
|
|
684
|
-
""
|
|
685
|
-
).replace(/\^\d/gi, "").replace(/\p{Mark}{2,}/gu, "").replace(/\s+/g, " ").trim();
|
|
686
|
-
if (!displayName.length) displayName = "empty name";
|
|
687
|
-
return displayName;
|
|
688
|
-
}, "cleanPlayerName");
|
|
689
|
-
|
|
690
|
-
// src/common/utils/enumValues.ts
|
|
691
|
-
function* enumValues(enumObj) {
|
|
692
|
-
let isStringEnum = true;
|
|
693
|
-
for (const property in enumObj) {
|
|
694
|
-
if (typeof enumObj[property] === "number") {
|
|
695
|
-
isStringEnum = false;
|
|
696
|
-
break;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
for (const property in enumObj) {
|
|
700
|
-
if (isStringEnum || typeof enumObj[property] === "number") {
|
|
701
|
-
yield enumObj[property];
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
__name(enumValues, "enumValues");
|
|
706
|
-
|
|
707
|
-
// src/common/utils/getStringFromUInt8Array.ts
|
|
708
|
-
var getStringFromUInt8Array = /* @__PURE__ */ __name((buffer, start, end) => String.fromCharCode(...buffer.slice(start, end)).replace(/\u0000/g, ""), "getStringFromUInt8Array");
|
|
709
|
-
|
|
710
|
-
// src/common/utils/getUInt32FromUint8Array.ts
|
|
711
|
-
var getUInt32FromUint8Array = /* @__PURE__ */ __name((buffer, start, end) => new Uint32Array(buffer.slice(start, end).buffer)[0], "getUInt32FromUint8Array");
|
|
712
|
-
|
|
713
|
-
// src/common/utils/index.ts
|
|
714
|
-
var Delay = /* @__PURE__ */ __name((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)), "Delay");
|
|
715
|
-
|
|
716
|
-
// src/common/GlobalData.ts
|
|
717
|
-
var GlobalData = class _GlobalData {
|
|
718
|
-
static {
|
|
719
|
-
__name(this, "GlobalData");
|
|
720
|
-
}
|
|
721
|
-
static CurrentResource = GetCurrentResourceName();
|
|
722
|
-
static IS_SERVER = IsDuplicityVersion();
|
|
723
|
-
static IS_CLIENT = !_GlobalData.IS_SERVER;
|
|
724
|
-
static NetworkTick = null;
|
|
725
|
-
static NetworkedTicks = [];
|
|
726
|
-
static EnablePrettyPrint = true;
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
// src/common/net/NetworkedMap.ts
|
|
730
|
-
var NetworkedMapEventManager = class {
|
|
731
|
-
static {
|
|
732
|
-
__name(this, "NetworkedMapEventManager");
|
|
733
|
-
}
|
|
734
|
-
#syncedCalls = /* @__PURE__ */ new Map();
|
|
735
|
-
constructor() {
|
|
736
|
-
$SERVER: if (GlobalData.IS_SERVER) {
|
|
737
|
-
on("playerDropped", () => {
|
|
738
|
-
const src = source;
|
|
739
|
-
for (const [_k, map] of this.#syncedCalls) {
|
|
740
|
-
map.removeSubscriber(src);
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
$CLIENT: {
|
|
746
|
-
RegisterResourceAsEventHandler(`${GlobalData.CurrentResource}:syncChanges`);
|
|
747
|
-
addRawEventListener(`${GlobalData.CurrentResource}:syncChanges`, (msgpack_data) => {
|
|
748
|
-
const data = msgpack_unpack(msgpack_data);
|
|
749
|
-
const syncName = data[0];
|
|
750
|
-
const syncData = data[1];
|
|
751
|
-
const map = this.#syncedCalls.get(syncName);
|
|
752
|
-
if (!map) {
|
|
753
|
-
throw new Error(`Tried to sync changes for a networked map but ${syncName} does't exist.`);
|
|
754
|
-
}
|
|
755
|
-
map.handleSync(syncData);
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
addNetworkedMap(map) {
|
|
760
|
-
this.#syncedCalls.set(map.SyncName, map);
|
|
761
|
-
}
|
|
762
|
-
removeNetworkedMap(syncName) {
|
|
763
|
-
this.#syncedCalls.delete(syncName);
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
var netManager = new NetworkedMapEventManager();
|
|
767
|
-
var NetworkedMap = class extends Map {
|
|
768
|
-
static {
|
|
769
|
-
__name(this, "NetworkedMap");
|
|
770
|
-
}
|
|
771
|
-
#syncName;
|
|
772
|
-
#queuedChanges = [];
|
|
773
|
-
#changeListeners = /* @__PURE__ */ new Map();
|
|
774
|
-
#subscribers = /* @__PURE__ */ new Set();
|
|
775
|
-
constructor(syncName, initialValue) {
|
|
776
|
-
super(initialValue);
|
|
777
|
-
this.#syncName = syncName;
|
|
778
|
-
GlobalData.NetworkedTicks.push(this);
|
|
779
|
-
netManager.addNetworkedMap(this);
|
|
780
|
-
$SERVER: {
|
|
781
|
-
if (!GlobalData.NetworkTick && GlobalData.IS_SERVER) {
|
|
782
|
-
GlobalData.NetworkTick = setTick(() => {
|
|
783
|
-
for (const networkedThis of GlobalData.NetworkedTicks) {
|
|
784
|
-
networkedThis.networkTick();
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
get SyncName() {
|
|
791
|
-
return this.#syncName;
|
|
792
|
-
}
|
|
793
|
-
// handles removing the player from the map whenever they're dropped
|
|
794
|
-
onPlayerDropped() {
|
|
795
|
-
this.removeSubscriber(source);
|
|
796
|
-
}
|
|
797
|
-
/*
|
|
798
|
-
* Resyncs the entire map to the client, useful for if there's a mismatch in the clients map (when multiple players change things, in cases like inventories)
|
|
799
|
-
*
|
|
800
|
-
* NOTE: This doesn't check that the player is already subscribed to the map, you should do your own due-diligence to only call this for players already subscribed
|
|
801
|
-
*/
|
|
802
|
-
resync(source2) {
|
|
803
|
-
const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
|
|
804
|
-
TriggerClientEventInternal(
|
|
805
|
-
`${GlobalData.CurrentResource}:syncChanges`,
|
|
806
|
-
source2,
|
|
807
|
-
packed_data,
|
|
808
|
-
packed_data.length
|
|
809
|
-
);
|
|
810
|
-
}
|
|
811
|
-
/*
|
|
812
|
-
* Adds a new subscriber to the map
|
|
813
|
-
*/
|
|
814
|
-
addSubscriber(source2) {
|
|
815
|
-
this.#subscribers.add(source2);
|
|
816
|
-
this.resync(source2);
|
|
817
|
-
}
|
|
818
|
-
removeSubscriber(sub) {
|
|
819
|
-
return this.#subscribers.delete(sub);
|
|
820
|
-
}
|
|
821
|
-
hasSubscriber(sub) {
|
|
822
|
-
return this.#subscribers.has(sub);
|
|
823
|
-
}
|
|
824
|
-
subscriberCount() {
|
|
825
|
-
return this.#subscribers.size;
|
|
826
|
-
}
|
|
827
|
-
handleSync(data) {
|
|
828
|
-
for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
|
|
829
|
-
switch (change_type) {
|
|
830
|
-
case 1 /* Add */: {
|
|
831
|
-
this.set(key, value);
|
|
832
|
-
continue;
|
|
833
|
-
}
|
|
834
|
-
case 2 /* Remove */: {
|
|
835
|
-
super.delete(key);
|
|
836
|
-
continue;
|
|
837
|
-
}
|
|
838
|
-
case 3 /* Reset */: {
|
|
839
|
-
super.clear();
|
|
840
|
-
continue;
|
|
841
|
-
}
|
|
842
|
-
case 4 /* Init */: {
|
|
843
|
-
super.clear();
|
|
844
|
-
const key_value = key;
|
|
845
|
-
for (const [k, v] of key_value) {
|
|
846
|
-
this.set(k, v);
|
|
847
|
-
}
|
|
848
|
-
continue;
|
|
849
|
-
}
|
|
850
|
-
case 0 /* SubValueChanged */: {
|
|
851
|
-
const data2 = this.get(key);
|
|
852
|
-
data2[value] = possibly_undefined_subvalue;
|
|
853
|
-
continue;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
/*
|
|
859
|
-
* Listens for the change on the specified key, it will get the resulting
|
|
860
|
-
* value on the change
|
|
861
|
-
*/
|
|
862
|
-
listenForChange(key, fn) {
|
|
863
|
-
const listener = this.#changeListeners.get(key);
|
|
864
|
-
listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
|
|
865
|
-
}
|
|
866
|
-
#triggerEventForSubscribers(data) {
|
|
867
|
-
const packed_data = msgpack_pack([this.#syncName, data]);
|
|
868
|
-
for (const sub of this.#subscribers) {
|
|
869
|
-
TriggerClientEventInternal(
|
|
870
|
-
`${GlobalData.CurrentResource}:syncChanges`,
|
|
871
|
-
sub,
|
|
872
|
-
packed_data,
|
|
873
|
-
packed_data.length
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
#pushChangeForListener(key, value) {
|
|
878
|
-
const listener = this.#changeListeners.get(key);
|
|
879
|
-
if (!listener) return;
|
|
880
|
-
for (const ln of listener) {
|
|
881
|
-
ln(value);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
set(key, value) {
|
|
885
|
-
let v = value;
|
|
886
|
-
if (value instanceof Object) {
|
|
887
|
-
const curMap = this;
|
|
888
|
-
const objectChangeHandler = {
|
|
889
|
-
get(target, prop, reciever) {
|
|
890
|
-
return Reflect.get(target, prop, reciever);
|
|
891
|
-
},
|
|
892
|
-
set(target, p, newValue, receiver) {
|
|
893
|
-
const success = Reflect.set(target, p, newValue, receiver);
|
|
894
|
-
if (success) {
|
|
895
|
-
curMap.#pushChangeForListener(key, target);
|
|
896
|
-
$SERVER: {
|
|
897
|
-
curMap.#queuedChanges.push([0 /* SubValueChanged */, key, p, newValue]);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return success;
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
v = new Proxy(v, objectChangeHandler);
|
|
904
|
-
}
|
|
905
|
-
super.set(key, v);
|
|
906
|
-
this.#pushChangeForListener(key, v);
|
|
907
|
-
$SERVER: {
|
|
908
|
-
this.#queuedChanges.push([1 /* Add */, key, v]);
|
|
909
|
-
}
|
|
910
|
-
return this;
|
|
911
|
-
}
|
|
912
|
-
/*
|
|
913
|
-
* Resets the map to its default state
|
|
914
|
-
*/
|
|
915
|
-
clear() {
|
|
916
|
-
$CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'clear' on client`);
|
|
917
|
-
this.#queuedChanges = [];
|
|
918
|
-
this.#queuedChanges.push([3 /* Reset */]);
|
|
919
|
-
super.clear();
|
|
920
|
-
}
|
|
921
|
-
delete(key) {
|
|
922
|
-
$CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'delete' on client`);
|
|
923
|
-
this.#queuedChanges.push([2 /* Remove */, key]);
|
|
924
|
-
return super.delete(key);
|
|
925
|
-
}
|
|
926
|
-
networkTick() {
|
|
927
|
-
if (this.#queuedChanges.length !== 0) {
|
|
928
|
-
this.#triggerEventForSubscribers(this.#queuedChanges);
|
|
929
|
-
this.#queuedChanges = [];
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
[Symbol.dispose]() {
|
|
933
|
-
this.#subscribers.clear();
|
|
934
|
-
this.#changeListeners.clear();
|
|
935
|
-
this.#queuedChanges = [];
|
|
936
|
-
netManager.removeNetworkedMap(this.#syncName);
|
|
937
|
-
GlobalData.NetworkedTicks.filter((v) => v !== this);
|
|
938
|
-
}
|
|
939
|
-
/**
|
|
940
|
-
* Unregisters from the tick handler and removes the event listener
|
|
941
|
-
*/
|
|
942
|
-
dispose() {
|
|
943
|
-
this[Symbol.dispose]();
|
|
944
|
-
}
|
|
945
|
-
get [Symbol.toStringTag]() {
|
|
946
|
-
return "NetworkedMap";
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
|
|
950
|
-
// src/common/decors/Events.ts
|
|
951
|
-
var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
|
|
952
|
-
ConVarType2[ConVarType2["String"] = 0] = "String";
|
|
953
|
-
ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
|
|
954
|
-
ConVarType2[ConVarType2["Float"] = 2] = "Float";
|
|
955
|
-
ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
|
|
956
|
-
return ConVarType2;
|
|
957
|
-
})(ConVarType || {});
|
|
958
|
-
var DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
|
|
959
|
-
function Exports(exportName) {
|
|
960
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
961
|
-
if (context.private) {
|
|
962
|
-
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
963
|
-
}
|
|
964
|
-
context.addInitializer(function() {
|
|
965
|
-
exports(exportName, (...args) => {
|
|
966
|
-
return originalMethod.call(this, ...args);
|
|
967
|
-
});
|
|
968
|
-
});
|
|
969
|
-
}, "actualDecorator");
|
|
970
|
-
}
|
|
971
|
-
__name(Exports, "Exports");
|
|
972
|
-
function Event(eventName) {
|
|
973
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
974
|
-
if (context.private) {
|
|
975
|
-
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
976
|
-
}
|
|
977
|
-
context.addInitializer(function() {
|
|
978
|
-
on(eventName, (...args) => {
|
|
979
|
-
try {
|
|
980
|
-
return originalMethod.call(this, ...args);
|
|
981
|
-
} catch (e) {
|
|
982
|
-
REMOVE_EVENT_LOG: {
|
|
983
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
984
|
-
console.error("------- EVENT ERROR --------");
|
|
985
|
-
console.error(`Call to ${eventName} errored`);
|
|
986
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
987
|
-
console.error(`Error: ${e}`);
|
|
988
|
-
console.error("------- END EVENT ERROR --------");
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
}, "actualDecorator");
|
|
994
|
-
}
|
|
995
|
-
__name(Event, "Event");
|
|
996
|
-
function NetEvent(eventName, remoteOnly = true) {
|
|
997
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
998
|
-
if (context.private) {
|
|
999
|
-
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
1000
|
-
}
|
|
1001
|
-
context.addInitializer(function() {
|
|
1002
|
-
const t = this;
|
|
1003
|
-
onNet(eventName, (...args) => {
|
|
1004
|
-
const src = source;
|
|
1005
|
-
try {
|
|
1006
|
-
$CLIENT: {
|
|
1007
|
-
if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
|
|
1008
|
-
return;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
return originalMethod.call(t, ...args);
|
|
1012
|
-
} catch (e) {
|
|
1013
|
-
REMOVE_NET_EVENT_LOG: {
|
|
1014
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
1015
|
-
console.error("------- NET EVENT ERROR --------");
|
|
1016
|
-
console.error(`Call to ${eventName} errored`);
|
|
1017
|
-
console.error(`Caller: ${src}`);
|
|
1018
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
1019
|
-
console.error(`Error: ${e}`);
|
|
1020
|
-
console.error("------- END NET EVENT ERROR --------");
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
});
|
|
1025
|
-
}, "actualDecorator");
|
|
1026
|
-
}
|
|
1027
|
-
__name(NetEvent, "NetEvent");
|
|
1028
|
-
function NuiEvent(eventName) {
|
|
1029
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1030
|
-
if (context.private) {
|
|
1031
|
-
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
1032
|
-
}
|
|
1033
|
-
context.addInitializer(function() {
|
|
1034
|
-
RegisterNuiCallback(eventName, (...args) => {
|
|
1035
|
-
return originalMethod.call(this, ...args);
|
|
1036
|
-
});
|
|
1037
|
-
});
|
|
1038
|
-
}, "actualDecorator");
|
|
1039
|
-
}
|
|
1040
|
-
__name(NuiEvent, "NuiEvent");
|
|
1041
|
-
var get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
|
|
1042
|
-
switch (con_var_type) {
|
|
1043
|
-
case 0 /* String */:
|
|
1044
|
-
return GetConvar;
|
|
1045
|
-
case 1 /* Integer */:
|
|
1046
|
-
return GetConvarInt;
|
|
1047
|
-
case 2 /* Float */:
|
|
1048
|
-
return GetConvarFloat;
|
|
1049
|
-
case 3 /* Boolean */:
|
|
1050
|
-
return GetConvarBool;
|
|
1051
|
-
// needed so typescript wont complain about "unreachable code" for the error below
|
|
1052
|
-
default:
|
|
1053
|
-
}
|
|
1054
|
-
throw new Error("Got invalid ConVarType");
|
|
1055
|
-
}, "get_convar_fn");
|
|
1056
|
-
function ConVar(name, is_floating_point, deserialize) {
|
|
1057
|
-
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
1058
|
-
if (context.private) {
|
|
1059
|
-
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
1060
|
-
}
|
|
1061
|
-
context.addInitializer(function() {
|
|
1062
|
-
const t = this;
|
|
1063
|
-
const default_value = Reflect.get(t, context.name);
|
|
1064
|
-
const default_type = typeof default_value;
|
|
1065
|
-
let con_var_type = null;
|
|
1066
|
-
if (default_type === "number") {
|
|
1067
|
-
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
1068
|
-
con_var_type = 2 /* Float */;
|
|
1069
|
-
} else {
|
|
1070
|
-
con_var_type = 1 /* Integer */;
|
|
1071
|
-
}
|
|
1072
|
-
} else if (default_type === "boolean") {
|
|
1073
|
-
con_var_type = 3 /* Boolean */;
|
|
1074
|
-
} else if (default_value === "string") {
|
|
1075
|
-
con_var_type = 0 /* String */;
|
|
1076
|
-
}
|
|
1077
|
-
if (!deserialize && con_var_type === null) {
|
|
1078
|
-
throw new Error("You should provide a deserialize function if you want to convert this to an object type");
|
|
1079
|
-
}
|
|
1080
|
-
if (con_var_type === null) {
|
|
1081
|
-
con_var_type = 0 /* String */;
|
|
1082
|
-
}
|
|
1083
|
-
const con_var_fn = get_convar_fn(con_var_type);
|
|
1084
|
-
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
1085
|
-
const data = con_var_fn(name, default_value);
|
|
1086
|
-
return deserialize ? deserialize(data) : data;
|
|
1087
|
-
}, "get_convar_value");
|
|
1088
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
1089
|
-
AddConvarChangeListener(name, () => {
|
|
1090
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
}, "actualDecorator");
|
|
1094
|
-
}
|
|
1095
|
-
__name(ConVar, "ConVar");
|
|
1096
|
-
function SetTick() {
|
|
1097
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
1098
|
-
if (context.private) {
|
|
1099
|
-
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
1100
|
-
}
|
|
1101
|
-
context.addInitializer(function() {
|
|
1102
|
-
setTick(async () => {
|
|
1103
|
-
await originalMethod.call(this);
|
|
1104
|
-
});
|
|
1105
|
-
});
|
|
1106
|
-
}, "actualDecorator");
|
|
1107
|
-
}
|
|
1108
|
-
__name(SetTick, "SetTick");
|
|
1109
|
-
|
|
1110
|
-
// src/common/Convar.ts
|
|
1111
|
-
var Convar = class {
|
|
1112
|
-
static {
|
|
1113
|
-
__name(this, "Convar");
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* @returns the current console buffer
|
|
1117
|
-
*/
|
|
1118
|
-
buffer() {
|
|
1119
|
-
$CLIENT: {
|
|
1120
|
-
if (GlobalData.IS_CLIENT) {
|
|
1121
|
-
throw new Error("This function isn't available on the client");
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
return GetConsoleBuffer();
|
|
1125
|
-
}
|
|
1126
|
-
get(variable, defaultVar) {
|
|
1127
|
-
return GetConvar(variable, defaultVar);
|
|
1128
|
-
}
|
|
1129
|
-
getInt(variable, defaultVar) {
|
|
1130
|
-
return GetConvarInt(variable, defaultVar);
|
|
1131
|
-
}
|
|
1132
|
-
getFloat(varName, defaultVar) {
|
|
1133
|
-
return GetConvarFloat(varName, defaultVar);
|
|
1134
|
-
}
|
|
1135
|
-
getBool(varName, defaultVar) {
|
|
1136
|
-
return GetConvarBool(varName, defaultVar);
|
|
1137
|
-
}
|
|
1138
|
-
set(variable, value) {
|
|
1139
|
-
$CLIENT: {
|
|
1140
|
-
if (GlobalData.IS_CLIENT) {
|
|
1141
|
-
throw new Error("This function isn't available on the client");
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
SetConvar(variable, value);
|
|
1145
|
-
}
|
|
1146
|
-
setReplicated(variable, value) {
|
|
1147
|
-
$CLIENT: {
|
|
1148
|
-
if (GlobalData.IS_CLIENT) {
|
|
1149
|
-
throw new Error("This function isn't available on the client");
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
SetConvarReplicated(variable, value);
|
|
1153
|
-
}
|
|
1154
|
-
setServerInfo(variable, value) {
|
|
1155
|
-
$CLIENT: {
|
|
1156
|
-
if (GlobalData.IS_CLIENT) {
|
|
1157
|
-
throw new Error("This function isn't available on the client");
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
SetConvarServerInfo(variable, value);
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
|
|
1164
|
-
// src/common/Command.ts
|
|
1165
|
-
var commands = [];
|
|
1166
|
-
$SERVER: {
|
|
1167
|
-
on("playerJoining", () => emitNet("chat:addSuggestions", source, commands));
|
|
1168
|
-
}
|
|
1169
|
-
function registerCommand(name, commandHandler, restricted) {
|
|
1170
|
-
if (Array.isArray(name)) {
|
|
1171
|
-
for (const command of name) {
|
|
1172
|
-
registerCommand(command, commandHandler, restricted);
|
|
1173
|
-
}
|
|
1174
|
-
return;
|
|
1175
|
-
}
|
|
1176
|
-
RegisterCommand(name, commandHandler, !!restricted);
|
|
1177
|
-
$SERVER: {
|
|
1178
|
-
const ace = `command.${name}`;
|
|
1179
|
-
if (typeof restricted === "string") {
|
|
1180
|
-
if (IsPrincipalAceAllowed(restricted, ace)) return;
|
|
1181
|
-
return ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
1182
|
-
}
|
|
1183
|
-
if (Array.isArray(restricted)) {
|
|
1184
|
-
for (const principal of restricted) {
|
|
1185
|
-
if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
__name(registerCommand, "registerCommand");
|
|
1191
|
-
var Command = class {
|
|
1192
|
-
constructor(name, help, handler, params, restricted = true) {
|
|
1193
|
-
this.name = name;
|
|
1194
|
-
this.help = help;
|
|
1195
|
-
this.params = params;
|
|
1196
|
-
this.#handler = handler;
|
|
1197
|
-
this.name = `/${name}`;
|
|
1198
|
-
registerCommand(name, (source2, args, raw) => this.call(source2, args, raw), restricted);
|
|
1199
|
-
if (params) {
|
|
1200
|
-
for (const parameter of params) {
|
|
1201
|
-
if (parameter.type) {
|
|
1202
|
-
parameter.help = parameter.help ? `${parameter.help} (type: ${parameter.type})` : `(type: ${parameter.type})`;
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
setTimeout(() => {
|
|
1206
|
-
$SERVER: {
|
|
1207
|
-
commands.push(this);
|
|
1208
|
-
emitNet("chat:addSuggestions", -1, this);
|
|
1209
|
-
}
|
|
1210
|
-
$CLIENT: {
|
|
1211
|
-
emit("chat:addSuggestion", this);
|
|
1212
|
-
}
|
|
1213
|
-
}, 100);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
static {
|
|
1217
|
-
__name(this, "Command");
|
|
1218
|
-
}
|
|
1219
|
-
#handler;
|
|
1220
|
-
mapArguments(source2, args, raw) {
|
|
1221
|
-
const mapped = {
|
|
1222
|
-
source: source2,
|
|
1223
|
-
raw
|
|
1224
|
-
};
|
|
1225
|
-
if (!this.params) return mapped;
|
|
1226
|
-
const result = this.params.every((param, index) => {
|
|
1227
|
-
const arg = args[index];
|
|
1228
|
-
let value = arg;
|
|
1229
|
-
switch (param.type) {
|
|
1230
|
-
case "number":
|
|
1231
|
-
value = +arg;
|
|
1232
|
-
break;
|
|
1233
|
-
case "string":
|
|
1234
|
-
value = !Number(arg) ? arg : false;
|
|
1235
|
-
break;
|
|
1236
|
-
case "playerId":
|
|
1237
|
-
$SERVER: {
|
|
1238
|
-
value = arg === "me" ? source2 : +arg;
|
|
1239
|
-
if (!value || !DoesPlayerExist(value.toString())) value = void 0;
|
|
1240
|
-
}
|
|
1241
|
-
$CLIENT: {
|
|
1242
|
-
value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
|
|
1243
|
-
if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
|
|
1244
|
-
}
|
|
1245
|
-
break;
|
|
1246
|
-
case "longString":
|
|
1247
|
-
value = raw.substring(raw.indexOf(arg));
|
|
1248
|
-
break;
|
|
1249
|
-
}
|
|
1250
|
-
if (value === void 0 && (!param.optional || param.optional && arg)) {
|
|
1251
|
-
return Citizen.trace(
|
|
1252
|
-
`^1command '${raw.split(" ")[0] || raw}' received an invalid ${param.type} for argument ${index + 1} (${param.name}), received '${arg}'^0`
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1255
|
-
mapped[param.name] = value;
|
|
1256
|
-
return true;
|
|
1257
|
-
});
|
|
1258
|
-
return result ? mapped : null;
|
|
1259
|
-
}
|
|
1260
|
-
async call(source2, args, raw = args.join(" ")) {
|
|
1261
|
-
const parsed = this.mapArguments(source2, args, raw);
|
|
1262
|
-
if (!parsed) return;
|
|
1263
|
-
try {
|
|
1264
|
-
await this.#handler(parsed);
|
|
1265
|
-
} catch (err) {
|
|
1266
|
-
Citizen.trace(`^1command '${raw.split(" ")[0] || raw}' failed to execute!^0
|
|
1267
|
-
${err.message}`);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
|
-
// src/common/Kvp.ts
|
|
1273
|
-
var Kvp = class {
|
|
1274
|
-
static {
|
|
1275
|
-
__name(this, "Kvp");
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Returns the value associated with a key as a number.
|
|
1279
|
-
*/
|
|
1280
|
-
getNumber(key) {
|
|
1281
|
-
return GetResourceKvpInt(key);
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* Returns the value associated with a key as a float.
|
|
1285
|
-
*/
|
|
1286
|
-
getFloat(key) {
|
|
1287
|
-
return GetResourceKvpFloat(key);
|
|
1288
|
-
}
|
|
1289
|
-
/**
|
|
1290
|
-
* Returns the value associated with a key as a string.
|
|
1291
|
-
*/
|
|
1292
|
-
getString(key) {
|
|
1293
|
-
return GetResourceKvpString(key);
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Returns the value associated with a key as a parsed JSON string.
|
|
1297
|
-
*/
|
|
1298
|
-
getJson(key) {
|
|
1299
|
-
const str = GetResourceKvpString(key);
|
|
1300
|
-
return str ? JSON.parse(str) : null;
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Sets the value associated with a key as a number.
|
|
1304
|
-
* @param async set the value using an async operation.
|
|
1305
|
-
*/
|
|
1306
|
-
setNumber(key, value, async = false) {
|
|
1307
|
-
return async ? SetResourceKvpIntNoSync(key, value) : SetResourceKvpInt(key, value);
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Sets the value associated with a key as a float.
|
|
1311
|
-
* @param async set the value using an async operation.
|
|
1312
|
-
*/
|
|
1313
|
-
setFloat(key, value, async = false) {
|
|
1314
|
-
return async ? SetResourceKvpFloatNoSync(key, value) : SetResourceKvpFloat(key, value);
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Sets the value associated with a key as a string.
|
|
1318
|
-
* @param async set the value using an async operation.
|
|
1319
|
-
*/
|
|
1320
|
-
setString(key, value, async = false) {
|
|
1321
|
-
return async ? SetResourceKvpNoSync(key, value) : SetResourceKvp(key, value);
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* Sets the value associated with a key as a JSON string.
|
|
1325
|
-
* @param async set the value using an async operation.
|
|
1326
|
-
*/
|
|
1327
|
-
setJson(key, value, async = false) {
|
|
1328
|
-
const str = JSON.stringify(value);
|
|
1329
|
-
return async ? SetResourceKvpNoSync(key, str) : SetResourceKvp(key, str);
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* Sets the value associated with a key as a JSON string.
|
|
1333
|
-
* @param async set the value using an async operation.
|
|
1334
|
-
*/
|
|
1335
|
-
set(key, value, async = false) {
|
|
1336
|
-
switch (typeof value) {
|
|
1337
|
-
case "function":
|
|
1338
|
-
case "symbol":
|
|
1339
|
-
throw new Error(`Failed to set Kvp for invalid type '${typeof value}'`);
|
|
1340
|
-
case "undefined":
|
|
1341
|
-
return this.delete(key, async);
|
|
1342
|
-
case "object":
|
|
1343
|
-
return this.setJson(key, value, async);
|
|
1344
|
-
case "boolean":
|
|
1345
|
-
value = value ? 1 : 0;
|
|
1346
|
-
case "number":
|
|
1347
|
-
return Number.isInteger(value) ? this.setNumber(key, value, async) : this.setFloat(key, value, async);
|
|
1348
|
-
default:
|
|
1349
|
-
value = String(value);
|
|
1350
|
-
return this.setString(key, value, async);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Deletes the specified value for key.
|
|
1355
|
-
* @param async remove the value using an async operation
|
|
1356
|
-
*/
|
|
1357
|
-
delete(key, async = false) {
|
|
1358
|
-
return async ? DeleteResourceKvpNoSync(key) : DeleteResourceKvp(key);
|
|
1359
|
-
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Commits pending asynchronous operations to disk, ensuring data consistency.
|
|
1362
|
-
*
|
|
1363
|
-
* Should be called after calling set methods using the async flag.
|
|
1364
|
-
*/
|
|
1365
|
-
flush() {
|
|
1366
|
-
FlushResourceKvp();
|
|
1367
|
-
}
|
|
1368
|
-
getAllKeys(prefix) {
|
|
1369
|
-
const keys = [];
|
|
1370
|
-
const handle = StartFindKvp(prefix);
|
|
1371
|
-
if (handle === -1) return keys;
|
|
1372
|
-
let key;
|
|
1373
|
-
do {
|
|
1374
|
-
key = FindKvp(handle);
|
|
1375
|
-
if (key) keys.push(key);
|
|
1376
|
-
} while (key);
|
|
1377
|
-
EndFindKvp(handle);
|
|
1378
|
-
return keys;
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Returns an array of keys which match or contain the given keys.
|
|
1382
|
-
*/
|
|
1383
|
-
getKeys(prefix) {
|
|
1384
|
-
return typeof prefix === "string" ? this.getAllKeys(prefix) : prefix.flatMap((key) => this.getAllKeys(key));
|
|
1385
|
-
}
|
|
1386
|
-
/**
|
|
1387
|
-
* Get all values from keys in an array as the specified type.
|
|
1388
|
-
*/
|
|
1389
|
-
getValuesAsType(prefix, type) {
|
|
1390
|
-
const values = this.getKeys(prefix);
|
|
1391
|
-
return values.map((key) => {
|
|
1392
|
-
switch (type) {
|
|
1393
|
-
case "number":
|
|
1394
|
-
return this.getNumber(key);
|
|
1395
|
-
case "float":
|
|
1396
|
-
return this.getFloat(key);
|
|
1397
|
-
case "string":
|
|
1398
|
-
return this.getString(key);
|
|
1399
|
-
default:
|
|
1400
|
-
return this.getJson(key);
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
|
|
1406
|
-
// src/common/Resource.ts
|
|
1407
|
-
var Resource = class {
|
|
1408
|
-
constructor(name) {
|
|
1409
|
-
this.name = name;
|
|
1410
|
-
}
|
|
1411
|
-
static {
|
|
1412
|
-
__name(this, "Resource");
|
|
1413
|
-
}
|
|
1414
|
-
getMetadata(metadataKey, index) {
|
|
1415
|
-
return GetResourceMetadata(this.name, metadataKey, index);
|
|
1416
|
-
}
|
|
1417
|
-
getPath() {
|
|
1418
|
-
return GetResourcePath(this.name);
|
|
1419
|
-
}
|
|
1420
|
-
loadFile(fileName) {
|
|
1421
|
-
return LoadResourceFile(this.name, fileName);
|
|
1422
|
-
}
|
|
1423
|
-
saveFile(fileName, data, length) {
|
|
1424
|
-
$CLIENT: {
|
|
1425
|
-
if (GlobalData.IS_CLIENT) {
|
|
1426
|
-
throw new Error("This function isn't available on the client");
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
return SaveResourceFile(this.name, fileName, data, length);
|
|
1430
|
-
}
|
|
1431
|
-
scheduleTick() {
|
|
1432
|
-
$CLIENT: {
|
|
1433
|
-
if (GlobalData.IS_CLIENT) {
|
|
1434
|
-
throw new Error("This function isn't available on the client");
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
return ScheduleResourceTick(this.name);
|
|
1438
|
-
}
|
|
1439
|
-
start() {
|
|
1440
|
-
StartResource(this.name);
|
|
1441
|
-
}
|
|
1442
|
-
stop() {
|
|
1443
|
-
StopResource(this.name);
|
|
1444
|
-
}
|
|
1445
|
-
static startResource(name) {
|
|
1446
|
-
StartResource(name);
|
|
1447
|
-
}
|
|
1448
|
-
static stopResource(name) {
|
|
1449
|
-
StopResource(name);
|
|
1450
|
-
}
|
|
1451
|
-
static resourceCount() {
|
|
1452
|
-
return GetNumResources();
|
|
1453
|
-
}
|
|
1454
|
-
};
|
|
1455
|
-
export {
|
|
1456
|
-
Color,
|
|
1457
|
-
Command,
|
|
1458
|
-
ConVar,
|
|
1459
|
-
ConVarType,
|
|
1460
|
-
Convar,
|
|
1461
|
-
Delay,
|
|
1462
|
-
DisablePrettyPrint,
|
|
1463
|
-
Event,
|
|
1464
|
-
Exports,
|
|
1465
|
-
Kvp,
|
|
1466
|
-
Maths,
|
|
1467
|
-
NetEvent,
|
|
1468
|
-
NetworkedMap,
|
|
1469
|
-
NuiEvent,
|
|
1470
|
-
PointF,
|
|
1471
|
-
Quaternion,
|
|
1472
|
-
Resource,
|
|
1473
|
-
SetTick,
|
|
1474
|
-
Vector2,
|
|
1475
|
-
Vector3,
|
|
1476
|
-
Vector4,
|
|
1477
|
-
cleanPlayerName,
|
|
1478
|
-
enumValues,
|
|
1479
|
-
getStringFromUInt8Array,
|
|
1480
|
-
getUInt32FromUint8Array
|
|
1481
|
-
};
|