@nativewrappers/redm 0.0.158 → 0.0.160

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,18 @@
1
+ export declare enum State {
2
+ Uninitialized = 0,
3
+ Initialized = 1,
4
+ Enabled = 2
5
+ }
6
+ export declare class BaseScript {
7
+ private state;
8
+ private events;
9
+ private exports;
10
+ private ticks;
11
+ private statebags;
12
+ private convars;
13
+ get IsEnabled(): boolean;
14
+ start(): void;
15
+ stop(): void;
16
+ startTick(name: string): void;
17
+ stopTick(name: string): void;
18
+ }
@@ -0,0 +1,36 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ var State = /* @__PURE__ */ ((State2) => {
4
+ State2[State2["Uninitialized"] = 0] = "Uninitialized";
5
+ State2[State2["Initialized"] = 1] = "Initialized";
6
+ State2[State2["Enabled"] = 2] = "Enabled";
7
+ return State2;
8
+ })(State || {});
9
+ class BaseScript {
10
+ static {
11
+ __name(this, "BaseScript");
12
+ }
13
+ state = 0 /* Uninitialized */;
14
+ events = /* @__PURE__ */ new Map();
15
+ exports = /* @__PURE__ */ new Map();
16
+ ticks = /* @__PURE__ */ new Map();
17
+ statebags = /* @__PURE__ */ new Map();
18
+ convars = /* @__PURE__ */ new Map();
19
+ // TODO:
20
+ // Commands?
21
+ get IsEnabled() {
22
+ return (this.state & 2 /* Enabled */) !== 0;
23
+ }
24
+ start() {
25
+ }
26
+ stop() {
27
+ }
28
+ startTick(name) {
29
+ }
30
+ stopTick(name) {
31
+ }
32
+ }
33
+ export {
34
+ BaseScript,
35
+ State
36
+ };
@@ -1,10 +1,10 @@
1
1
  export type MessageTypeDecoder<T> = {
2
2
  decode: (input: Uint8Array) => T;
3
- name: string;
3
+ __proto_name__: string;
4
4
  };
5
5
  export type MessageTypeEncoder<T> = {
6
6
  encode: (message: T) => any;
7
- name: string;
7
+ __proto_name__: string;
8
8
  };
9
9
  type ProtoCallback<Message> = (message: Message) => Promise<void> | void;
10
10
  type NetProtoCallback<Message> = (message: Message, source: number) => Promise<void> | void;
@@ -7,7 +7,7 @@ function parseSource(source) {
7
7
  }
8
8
  __name(parseSource, "parseSource");
9
9
  function OnProto(messageType, eventName) {
10
- const event = eventName ?? `${messageType.name}`;
10
+ const event = eventName ?? `${messageType.__proto_name__}`;
11
11
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
12
12
  if (context.private) {
13
13
  throw new Error("OnProto does not work on private methods");
@@ -26,7 +26,7 @@ function OnProto(messageType, eventName) {
26
26
  }
27
27
  __name(OnProto, "OnProto");
28
28
  function OnProtoNet(messageType, eventName) {
29
- const event = eventName ?? `${messageType.name}`;
29
+ const event = eventName ?? `${messageType.__proto_name__}`;
30
30
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
31
31
  if (context.private) {
32
32
  throw new Error("OnProto does not work on private methods");
@@ -11,7 +11,9 @@ export declare class Net {
11
11
  export declare class NetServer extends Net {
12
12
  static emitNet(eventName: string, source: number, ...args: any[]): void;
13
13
  static emitProto<T>(source: number, message: MessageTypeEncoder<T>): void;
14
- static emitProtoToPlayers<T>(sources: number[], message: MessageTypeEncoder<T>): void;
14
+ static broadcastProto<T>(sources: Iterable<number>, message: MessageTypeEncoder<T>): void;
15
+ static broadcast(sources: Iterable<number>, eventName: string, ...args: any[]): void;
16
+ static broadcastRaw(sources: Iterable<number>, eventName: string, data: Uint8Array): void;
15
17
  static emitRawNet(eventName: string, source: number, data: Uint8Array): void;
16
18
  }
17
19
  export declare class NetClient extends Net {
package/common/net/Net.js CHANGED
@@ -31,12 +31,21 @@ class NetServer extends Net {
31
31
  }
32
32
  static emitProto(source, message) {
33
33
  const encoded = message.encode(message);
34
- NetServer.emitRawNet(message.name, source, encoded);
34
+ NetServer.emitRawNet(message.__proto_name__, source, encoded);
35
35
  }
36
- static emitProtoToPlayers(sources, message) {
36
+ static broadcastProto(sources, message) {
37
37
  const encoded = message.encode(message);
38
+ NetServer.broadcastRaw(sources, message.__proto_name__, encoded);
39
+ }
40
+ static broadcast(sources, eventName, ...args) {
41
+ const packed = msgpack_pack(...args);
42
+ for (const source of sources) {
43
+ TriggerClientEventInternal(eventName, source, packed, packed.length);
44
+ }
45
+ }
46
+ static broadcastRaw(sources, eventName, data) {
38
47
  for (const source of sources) {
39
- NetServer.emitRawNet(message.name, source, encoded);
48
+ NetServer.emitRawNet(eventName, source, data);
40
49
  }
41
50
  }
42
51
  static emitRawNet(eventName, source, data) {
@@ -52,7 +61,7 @@ class NetClient extends Net {
52
61
  }
53
62
  static emitProto(message) {
54
63
  const encoded = message.encode(message);
55
- NetClient.emitRawNet(message.name, encoded);
64
+ NetClient.emitRawNet(message.__proto_name__, encoded);
56
65
  }
57
66
  static emitRawNet(eventName, data) {
58
67
  TriggerServerEventInternal(eventName, data, data.byteLength);
@@ -1,6 +1,5 @@
1
1
  import type { MsgpackBuffer } from "../types";
2
2
  import { ClassTypes } from "./ClassTypes";
3
- declare const size: unique symbol;
4
3
  /**
5
4
  * Represents a 2-dimensional vector.
6
5
  */
@@ -211,7 +210,7 @@ declare abstract class Vector {
211
210
  */
212
211
  static Length<T extends VectorType, U extends VectorLike>(this: T, obj: U): number;
213
212
  type: unknown;
214
- [size]: number;
213
+ vec_size: number;
215
214
  x: number;
216
215
  y: number;
217
216
  z: number | undefined;
@@ -314,7 +313,7 @@ declare abstract class Vector {
314
313
  */
315
314
  export declare class Vector2 extends Vector {
316
315
  readonly type = ClassTypes.Vector2;
317
- readonly [size]: number;
316
+ readonly vec_size: number;
318
317
  static readonly Zero: Vector2;
319
318
  /**
320
319
  * Constructs a new 2D vector.
@@ -335,7 +334,7 @@ export declare class Vector2 extends Vector {
335
334
  */
336
335
  export declare class Vector3 extends Vector implements Vec3 {
337
336
  readonly type = ClassTypes.Vector3;
338
- readonly [size]: number;
337
+ readonly vec_size: number;
339
338
  z: number;
340
339
  static readonly Zero: Vector3;
341
340
  static readonly UnitX: Vector3;
@@ -384,7 +383,7 @@ export declare class Vector3 extends Vector implements Vec3 {
384
383
  */
385
384
  export declare class Vector4 extends Vector {
386
385
  readonly type = ClassTypes.Vector4;
387
- readonly [size]: number;
386
+ readonly vec_size: number;
388
387
  z: number;
389
388
  w: number;
390
389
  static readonly Zero: Vector4;
@@ -4,15 +4,14 @@ import { ClassTypes } from "./ClassTypes";
4
4
  const EXT_VECTOR2 = 20;
5
5
  const EXT_VECTOR3 = 21;
6
6
  const EXT_VECTOR4 = 22;
7
- const size = Symbol("size");
8
7
  class Vector {
9
8
  static {
10
9
  __name(this, "Vector");
11
10
  }
12
11
  static create(x, y = x, z, w) {
13
12
  if (typeof x === "object") ({ x, y, z, w } = x);
14
- const size2 = this instanceof Vector && this.size || [x, y, z, w].filter((arg) => arg !== void 0).length;
15
- switch (size2) {
13
+ const size = this instanceof Vector && this.size || [x, y, z, w].filter((arg) => arg !== void 0).length;
14
+ switch (size) {
16
15
  case 1:
17
16
  case 2:
18
17
  return new Vector2(x, y);
@@ -21,7 +20,7 @@ class Vector {
21
20
  case 4:
22
21
  return new Vector4(x, y, z, w);
23
22
  default:
24
- throw new Error(`Cannot instantiate Vector with size of ${size2}.`);
23
+ throw new Error(`Cannot instantiate Vector with size of ${size}.`);
25
24
  }
26
25
  }
27
26
  /**
@@ -263,7 +262,7 @@ class Vector {
263
262
  return Math.sqrt(sum);
264
263
  }
265
264
  type;
266
- [size] = 2;
265
+ vec_size = 2;
267
266
  x = 0;
268
267
  y = 0;
269
268
  z;
@@ -293,7 +292,7 @@ class Vector {
293
292
  if (this.w !== void 0) yield this.w;
294
293
  }
295
294
  get size() {
296
- return this[size];
295
+ return this.vec_size;
297
296
  }
298
297
  toString() {
299
298
  return `vector${this.size}(${this.toArray().join(", ")})`;
@@ -432,7 +431,7 @@ class Vector2 extends Vector {
432
431
  // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
433
432
  // TO EXIST, CHANGING IT WILL BREAK STUFF
434
433
  type = ClassTypes.Vector2;
435
- [size] = 2;
434
+ vec_size = 2;
436
435
  static Zero = new Vector2(0, 0);
437
436
  /**
438
437
  * Constructs a new 2D vector.
@@ -460,7 +459,7 @@ class Vector3 extends Vector {
460
459
  // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
461
460
  // TO EXIST, CHANGING IT WILL BREAK STUFF
462
461
  type = ClassTypes.Vector3;
463
- [size] = 3;
462
+ vec_size = 3;
464
463
  z = 0;
465
464
  static Zero = new Vector3(0, 0, 0);
466
465
  static UnitX = new Vector3(1, 0, 0);
@@ -523,7 +522,7 @@ class Vector4 extends Vector {
523
522
  // DO NOT USE, ONLY EXPOSED BECAUSE TS IS TRASH, THIS TYPE IS NOT GUARANTEED
524
523
  // TO EXIST, CHANGING IT WILL BREAK STUFF
525
524
  type = ClassTypes.Vector4;
526
- [size] = 4;
525
+ vec_size = 4;
527
526
  z = 0;
528
527
  w = 0;
529
528
  static Zero = new Vector4(0, 0, 0, 0);
package/index.d.ts CHANGED
@@ -75,6 +75,7 @@ export * from "./common-game/definitions/index.d";
75
75
  export * from "./common-game/definitions/redm.d";
76
76
  export * from "./common-game/cfx/StateBagChangeHandler";
77
77
  export * from "./common-game/cfx/cfx";
78
+ export * from "./common/BaseScript";
78
79
  export * from "./common/Command";
79
80
  export * from "./common/Convar";
80
81
  export * from "./common/GlobalData";
package/index.js CHANGED
@@ -75,6 +75,7 @@ export * from "./common-game/definitions/index.d";
75
75
  export * from "./common-game/definitions/redm.d";
76
76
  export * from "./common-game/cfx/StateBagChangeHandler";
77
77
  export * from "./common-game/cfx/cfx";
78
+ export * from "./common/BaseScript";
78
79
  export * from "./common/Command";
79
80
  export * from "./common/Convar";
80
81
  export * from "./common/GlobalData";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.158",
11
+ "version": "0.0.160",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"