@nativewrappers/fivem 0.0.140 → 0.0.142

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.
@@ -4,9 +4,18 @@ export declare enum ErrorType {
4
4
  Export = 2,
5
5
  Nui = 3,
6
6
  Tick = 4,
7
- Immediate = 5
7
+ Immediate = 5,
8
+ ConVar = 6
8
9
  }
9
10
  export type NativeWrapperErrorType = (type: ErrorType, err: Error) => void;
11
+ export interface ErrorData {
12
+ name?: string;
13
+ source?: number;
14
+ args?: any | any[];
15
+ }
16
+ /**
17
+ * A static class containing useful
18
+ */
10
19
  export declare class GlobalData {
11
20
  static CurrentResource: string;
12
21
  static GameName: string;
@@ -17,6 +26,5 @@ export declare class GlobalData {
17
26
  static IS_CLIENT: boolean;
18
27
  static NetworkTick: number | null;
19
28
  static NetworkedTicks: any[];
20
- static EnablePrettyPrint: boolean;
21
- static OnError: (type: ErrorType, err: Error) => void;
29
+ static OnError: (type: ErrorType, err: Error, errorData: ErrorData) => void;
22
30
  }
@@ -7,9 +7,53 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
7
7
  ErrorType2[ErrorType2["Nui"] = 3] = "Nui";
8
8
  ErrorType2[ErrorType2["Tick"] = 4] = "Tick";
9
9
  ErrorType2[ErrorType2["Immediate"] = 5] = "Immediate";
10
+ ErrorType2[ErrorType2["ConVar"] = 6] = "ConVar";
10
11
  return ErrorType2;
11
12
  })(ErrorType || {});
12
- globalThis.OnError = (type, err) => {
13
+ function convertErrorTypeToName(errorType) {
14
+ switch (errorType) {
15
+ case 0 /* Event */:
16
+ return "Event";
17
+ case 1 /* NetEvent */:
18
+ return "Net Event";
19
+ case 2 /* Export */:
20
+ return "Export";
21
+ case 3 /* Nui */:
22
+ return "Nui";
23
+ case 4 /* Tick */:
24
+ return "Tick";
25
+ case 5 /* Immediate */:
26
+ return "Immediate";
27
+ case 6 /* ConVar */:
28
+ return "ConVar";
29
+ }
30
+ }
31
+ __name(convertErrorTypeToName, "convertErrorTypeToName");
32
+ globalThis.ShouldParseErrorArgs = true;
33
+ globalThis.FormatError = (errorType, err, errorData) => {
34
+ const errorName = convertErrorTypeToName(errorType);
35
+ console.error(`------- ${errorName} EVENT ERROR --------`);
36
+ const { name, source, args } = errorData;
37
+ if (name) {
38
+ console.error(`Call to ${name} errored`);
39
+ }
40
+ if (source) {
41
+ console.error(`Caller: ${source}`);
42
+ }
43
+ if (args && globalThis.ShouldParseErrorArgs) {
44
+ let jsonData;
45
+ try {
46
+ jsonData = JSON.stringify(args);
47
+ } catch {
48
+ jsonData = "Failed to convert args to JSON";
49
+ }
50
+ console.error(`Data: ${jsonData}`);
51
+ }
52
+ globalThis.printError(errorName, err);
53
+ console.error(`------- END ${errorName} EVENT ERROR --------`);
54
+ };
55
+ globalThis.OnError = (type, err, errorData) => {
56
+ globalThis.FormatError(type, err, errorData);
13
57
  };
14
58
  class GlobalData {
15
59
  static {
@@ -24,12 +68,11 @@ class GlobalData {
24
68
  static IS_CLIENT = !GlobalData.IS_SERVER;
25
69
  static NetworkTick = null;
26
70
  static NetworkedTicks = [];
27
- static EnablePrettyPrint = true;
28
71
  /*
29
72
  * Called when one of the decors errors
30
73
  */
31
- static OnError = /* @__PURE__ */ __name((type, err) => {
32
- globalThis.OnError(type, err);
74
+ static OnError = /* @__PURE__ */ __name((type, err, errorData) => {
75
+ globalThis.OnError(type, err, errorData);
33
76
  }, "OnError");
34
77
  }
35
78
  export {
@@ -4,11 +4,48 @@ export declare enum ConVarType {
4
4
  Float = 2,
5
5
  Boolean = 3
6
6
  }
7
- type DeserializeFn<T> = (data: T) => unknown;
7
+ export type DeserializeFn = (data: unknown) => unknown;
8
8
  /**
9
- * Gets the specified `ConVar`s value, this will bind to the param.
10
- * @param name the convar name
11
- * @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
9
+ * Gets the specified `ConVar`s value, this will bind to the parameter of the current class
10
+ * updating it whenever the ConVar value changes.
11
+ *
12
+ * Whatever the initial data value is will be the default value
13
+ *
14
+ * @param name - the convar name that we will read from
15
+ * @param convarType - the type of the convar
16
+ * @param deserialize - when using a string we can use this to automatically convert the value to a different structure,
17
+ this can also be used to know when a value gets changed, just make sure the value returns itself.
18
+ * @example
19
+ * ```typescript
20
+ * type Vec3 = [number, number, number];
21
+ * const deserializeToVec3Array = (data: string) => {
22
+ * // convert a semicolon separate listed into a vector 3 array
23
+ * const dataArray = data.split(";");
24
+ * if (dataArray.length !== 3) {
25
+ * throw new Error("ConVars data didn't have three numbers!");
26
+ * }
27
+ *
28
+ * return dataArray.map((v, i) => {
29
+ * const converted = parseFloat(v.trim());
30
+ * if (Number.isNaN(converted)) {
31
+ * throw new Error(`Value at index ${i} was not an actual float!`);
32
+ * }
33
+ *
34
+ * return converted;
35
+ * }) as Vec3;
36
+ * };
37
+ * class ConVar {
38
+ * \@ConVar("nativeWrappers", ConVarType.Boolean)
39
+ * private nativeWrappers = false; // false will be the default value
40
+ *
41
+ * \@ConVar("engineDamageModifier", ConVarType.Float)
42
+ * private engineDamageModifier = 1.0;
43
+ *
44
+ * // If we `setr spawnPos "155.23;154.44;25.88"` this will convert the string into
45
+ * // the specified type
46
+ * \@ConVar("spawnPos", ConVarType.String, deserializeToVec3Array)
47
+ * private vectorPos: Vec3 = [123.12, 123.22, 55];
48
+ * }
49
+ * ```
12
50
  */
13
- export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
14
- export {};
51
+ export declare function ConVar(name: string, convarType: ConVarType, deserialize?: DeserializeFn): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
@@ -1,5 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { ErrorType, GlobalData } from "../GlobalData";
3
4
  var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
4
5
  ConVarType2[ConVarType2["String"] = 0] = "String";
5
6
  ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
@@ -7,7 +8,7 @@ var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
7
8
  ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
8
9
  return ConVarType2;
9
10
  })(ConVarType || {});
10
- const get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
11
+ const getConvarFunction = /* @__PURE__ */ __name((con_var_type) => {
11
12
  switch (con_var_type) {
12
13
  case 0 /* String */:
13
14
  return GetConvar;
@@ -21,44 +22,46 @@ const get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
21
22
  default:
22
23
  }
23
24
  throw new Error("Got invalid ConVarType");
24
- }, "get_convar_fn");
25
- function ConVar(name, is_floating_point, deserialize) {
25
+ }, "getConvarFunction");
26
+ function ConVar(name, convarType, deserialize) {
26
27
  return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
27
28
  if (context.private) {
28
29
  throw new Error("ConVar does not work on private types, please mark the field as public");
29
30
  }
30
31
  context.addInitializer(function() {
31
32
  const t = this;
32
- const default_value = Reflect.get(t, context.name);
33
- const default_type = typeof default_value;
34
- let con_var_type = null;
35
- if (default_type === "number") {
36
- if (is_floating_point || !Number.isInteger(default_value)) {
37
- con_var_type = 2 /* Float */;
38
- } else {
39
- con_var_type = 1 /* Integer */;
33
+ const defaultValue = Reflect.get(t, context.name);
34
+ const conVarFunction = getConvarFunction(convarType);
35
+ const defaultType = typeof defaultValue;
36
+ if (defaultType !== "number" && defaultType !== "boolean" && defaultType !== "string") {
37
+ if (defaultType === "function") {
38
+ const error = new Error(
39
+ `${name} has a type of function, which isn't allowed for a ConVar. If you need to know when the data changes you can define a pass a deserializer.`
40
+ );
41
+ GlobalData.OnError(ErrorType.ConVar, error, { name });
42
+ return;
43
+ }
44
+ if (!deserialize) {
45
+ const error = new Error(
46
+ `${name} has a type of ${defaultType} which isn't allowed unless you define a deserializer.`
47
+ );
48
+ GlobalData.OnError(ErrorType.ConVar, error, { name });
49
+ return;
40
50
  }
41
- } else if (default_type === "boolean") {
42
- con_var_type = 3 /* Boolean */;
43
- } else if (default_type === "string") {
44
- con_var_type = 0 /* String */;
45
- }
46
- if (!deserialize && con_var_type === null) {
47
- throw new Error(
48
- `Failed to determine what to use to deserialize '${name}' was for var had type '${default_type}' which can't be deserialized without providing your own deserialize function.`
49
- );
50
- }
51
- if (con_var_type === null) {
52
- con_var_type = 0 /* String */;
53
51
  }
54
- const con_var_fn = get_convar_fn(con_var_type);
55
- const get_convar_value = /* @__PURE__ */ __name(() => {
56
- const data = con_var_fn(name, default_value);
57
- return deserialize ? deserialize(data) : data;
58
- }, "get_convar_value");
59
- Reflect.set(t, context.name, get_convar_value());
52
+ const getConvarValue = /* @__PURE__ */ __name(() => {
53
+ const value = conVarFunction(name, defaultValue);
54
+ try {
55
+ const returnData = deserialize ? deserialize(value) : value;
56
+ return returnData;
57
+ } catch (e) {
58
+ GlobalData.OnError(ErrorType.ConVar, e, { name: `${name}:DeserializeFn` });
59
+ throw e;
60
+ }
61
+ }, "getConvarValue");
62
+ Reflect.set(t, context.name, getConvarValue());
60
63
  AddConvarChangeListener(name, () => {
61
- Reflect.set(t, context.name, get_convar_value());
64
+ Reflect.set(t, context.name, getConvarValue());
62
65
  });
63
66
  });
64
67
  }, "actualDecorator");
@@ -1,41 +1,64 @@
1
- /**
2
- * Disables pretty printing in error messages
3
- */
4
- export declare const DisablePrettyPrint: () => boolean;
5
1
  /**
6
2
  * Registers the Event call for {@link eventName} to this method.
7
3
  *
8
- * This has internal pretty-printing to make errors easier to track, if
9
- * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
10
- * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
4
+ * All errors that happen inside of the event will automatically be caught, these will still
5
+ * output a FiveM stack trace.
6
+ *
7
+ * @note With all decors you can overwrite `globalThis.OnError` in order to hook into these errors to get more information or log them out to an external service, or to just disable the pretty printing.
11
8
  *
12
- * @param eventName the event to bind to
9
+ * @param eventName - the event to bind to
13
10
  */
14
11
  export declare function OnEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
12
+ /**
13
+ * @deprecated use OnEvent instead, this will be removed upon 2.0
14
+ */
15
15
  export declare const Event: typeof OnEvent;
16
16
  /**
17
17
  * Registers the Net Event call for {@link eventName} to this method
18
18
  *
19
+ * All errors that happen inside of the event will automatically be caught, these will still
20
+ * output a FiveM stack trace.
19
21
  *
20
- * This has internal pretty-printing to make errors easier to track, if
21
- * you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
22
- * using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
23
- *
22
+ * @note With all decors you can overwrite `globalThis.OnError` in order to hook into these errors to get more information or log them out to an external service, or to just disable the pretty printing.
24
23
  * @param eventName the event to bind this net event to
25
24
  * @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
26
25
  */
27
26
  export declare function OnNetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
27
+ /**
28
+ * @deprecated Use `OnNetEvent` instead this will be removed upon 2.0
29
+ */
28
30
  export declare const NetEvent: typeof OnNetEvent;
29
31
  export type NuiCallback = (data: string) => void;
30
32
  /**
31
- * Registers the NUI Event call for {eventName} to this method, the function signature
32
- * will always be (data: unknown, cb: (data?: any) => void) => void
33
+ * Registers the NUI Event call for {@link eventName} to this method, the function signature
34
+ * will always be `(data: unknown, cb: (data?: any) => void) => void`
33
35
  *
34
- * There's two valid ways to return data into a callback, returning in the method
35
- * you're currently using will automatically call the callback, or you can manually call the callback yourself
36
+ * There's two valid ways to return data into a callback
37
+ * 1. Returning in the method you're currently using will automatically call the callback
38
+ * 2. You can manually call the callback yourself
36
39
  *
40
+ * @note With all decors you can overwrite `globalThis.OnError` in order to hook into these errors to get more information or log them out to an external service, or to just disable the pretty printing.
37
41
  * @param eventName the event this will listen for
38
42
  * @param dontErrorWhenCbIsntInvoked this will just block the event fro merroring when the callback is never invoked.
43
+ * @throws This will throw if you don't call `cb` or return data in the method.
44
+ * If you move this call across task bounds and call the cb, this will still throw (say doing `setImmediate(() => cb("ok"));`)
45
+ * You can disable this by setting {@link dontErrorWhenCbIsntInvoked} to `true`
46
+ * @example
47
+ * ```typescript
48
+ * class NuiEventManager {
49
+ * #is_ui_ready = false;
50
+ * \@OnNuiEvent("ui_ready")
51
+ * on_ui_ready(data: unknown, cb: NuiCallback) {
52
+ * this.#is_ui_ready = true;
53
+ * // will invoke the callback itself
54
+ * return "ok";
55
+ * // cb("ok"); // you can use this too
56
+ * }
57
+ * }
58
+ * ```
39
59
  */
40
60
  export declare function OnNuiEvent(eventName: string, dontErrorWhenCbIsntInvoked?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
61
+ /**
62
+ * @deprecated use OnNuiEvent instead
63
+ */
41
64
  export declare const NuiEvent: typeof OnNuiEvent;
@@ -1,7 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { ErrorType, GlobalData } from "../GlobalData";
4
- const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
5
4
  const AsyncFunction = (async () => {
6
5
  }).constructor;
7
6
  function OnEvent(eventName) {
@@ -14,15 +13,10 @@ function OnEvent(eventName) {
14
13
  try {
15
14
  return await originalMethod.call(this, ...args);
16
15
  } catch (e) {
17
- GlobalData.OnError(ErrorType.Event, e);
18
- REMOVE_EVENT_LOG: {
19
- if (!GlobalData.EnablePrettyPrint) return;
20
- console.error("------- EVENT ERROR --------");
21
- console.error(`Call to ${eventName} errored`);
22
- console.error(`Data: ${JSON.stringify(args)}`);
23
- globalThis.printError("event", e);
24
- console.error("------- END EVENT ERROR --------");
25
- }
16
+ GlobalData.OnError(ErrorType.Event, e, {
17
+ name: eventName,
18
+ args
19
+ });
26
20
  }
27
21
  });
28
22
  });
@@ -63,16 +57,11 @@ function OnNetEvent(eventName, remoteOnly = true) {
63
57
  }
64
58
  return await originalMethod.call(this, ...args);
65
59
  } catch (e) {
66
- GlobalData.OnError(ErrorType.NetEvent, e);
67
- REMOVE_NET_EVENT_LOG: {
68
- if (!GlobalData.EnablePrettyPrint) return;
69
- console.error("------- NET EVENT ERROR --------");
70
- console.error(`Call to ${eventName} errored`);
71
- console.error(`Caller: ${src}`);
72
- console.error(`Data: ${JSON.stringify(args)}`);
73
- globalThis.printError("net event", e);
74
- console.error("------- END NET EVENT ERROR --------");
75
- }
60
+ GlobalData.OnError(ErrorType.NetEvent, e, {
61
+ name: eventName,
62
+ source: src,
63
+ args
64
+ });
76
65
  }
77
66
  });
78
67
  });
@@ -96,7 +85,7 @@ function OnNuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
96
85
  try {
97
86
  retData = await originalMethod.call(this, data, cbWrapper);
98
87
  } catch (e) {
99
- GlobalData.OnError(ErrorType.Nui, e);
88
+ GlobalData.OnError(ErrorType.Nui, e, { name: eventName });
100
89
  return;
101
90
  }
102
91
  if (!wasInvoked && !retData) {
@@ -115,7 +104,6 @@ function OnNuiEvent(eventName, dontErrorWhenCbIsntInvoked = false) {
115
104
  __name(OnNuiEvent, "OnNuiEvent");
116
105
  const NuiEvent = OnNuiEvent;
117
106
  export {
118
- DisablePrettyPrint,
119
107
  Event,
120
108
  NetEvent,
121
109
  NuiEvent,
@@ -1 +1,4 @@
1
+ /**
2
+ * Registers the export call for {@link exportName} to this method
3
+ */
1
4
  export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
@@ -15,15 +15,7 @@ function Exports(exportName) {
15
15
  try {
16
16
  return await originalMethod.call(this, ...args);
17
17
  } catch (err) {
18
- GlobalData.OnError(ErrorType.Export, err);
19
- REMOVE_EVENT_LOG: {
20
- if (!GlobalData.EnablePrettyPrint) return;
21
- console.error("------- EXPORT ERROR --------");
22
- console.error(`Call to ${exportName} errored`);
23
- console.error(`Data: ${JSON.stringify(args)}`);
24
- console.error(`Error: ${err}`);
25
- console.error("------- END EXPORT ERROR --------");
26
- }
18
+ GlobalData.OnError(ErrorType.Export, err, { name: exportName });
27
19
  throw err;
28
20
  }
29
21
  }, "exportCb");
@@ -32,15 +24,7 @@ function Exports(exportName) {
32
24
  try {
33
25
  return originalMethod.call(this, ...args);
34
26
  } catch (err) {
35
- GlobalData.OnError(ErrorType.Export, err);
36
- REMOVE_EVENT_LOG: {
37
- if (!GlobalData.EnablePrettyPrint) return;
38
- console.error("------- EXPORT ERROR --------");
39
- console.error(`Call to ${exportName} errored`);
40
- console.error(`Data: ${JSON.stringify(args)}`);
41
- console.error(`Error: ${err}`);
42
- console.error("------- END EXPORT ERROR --------");
43
- }
27
+ GlobalData.OnError(ErrorType.Export, err, { name: exportName });
44
28
  throw err;
45
29
  }
46
30
  }, "exportCb");
@@ -4,7 +4,8 @@ type FunctionCall = (resource_name?: string) => void;
4
4
  declare class ResourceWrapper {
5
5
  #private;
6
6
  /**
7
- * Adds a function to get called whenever a resource is started
7
+ * Adds a function to get called whenever a resource is started, if the current
8
+ * {@link resource_name} is started then it will immediately call the function.
8
9
  * @param resource_name The resource name to add to the start listener.
9
10
  * @param fn The function to call
10
11
  */
@@ -20,7 +20,8 @@ class ResourceWrapper {
20
20
  }
21
21
  }
22
22
  /**
23
- * Adds a function to get called whenever a resource is started
23
+ * Adds a function to get called whenever a resource is started, if the current
24
+ * {@link resource_name} is started then it will immediately call the function.
24
25
  * @param resource_name The resource name to add to the start listener.
25
26
  * @param fn The function to call
26
27
  */
@@ -28,6 +29,9 @@ class ResourceWrapper {
28
29
  if (resource_name === "global") {
29
30
  this.#global_on_resource_start.push(fn);
30
31
  } else {
32
+ if (GetResourceState(resource_name) === "started") {
33
+ setImmediate(() => fn(resource_name));
34
+ }
31
35
  this.#add_or_init(this.#on_resource_start, resource_name, fn);
32
36
  }
33
37
  }
@@ -80,22 +84,16 @@ const GetResourceWrapper = /* @__PURE__ */ __name(() => {
80
84
  }, "GetResourceWrapper");
81
85
  EnsureResourceWrapperInit();
82
86
  const RESOURCE_WRAPPER = globalThis.RESOURCE_WRAPPER;
83
- const onResourceStart = /* @__PURE__ */ __name((resource, originalMethod) => {
84
- if (resource !== "global" && GetResourceState(resource) === "started") {
85
- setImmediate(() => originalMethod.call());
86
- }
87
- RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
88
- }, "onResourceStart");
89
87
  function OnResourceStart(resource = GetCurrentResourceName()) {
90
88
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
91
89
  if (context.private) {
92
90
  throw new Error("OnResourceStart does not work on private types, please mark the field as public");
93
91
  }
94
92
  if (context.static) {
95
- onResourceStart(resource, originalMethod);
93
+ RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
96
94
  } else {
97
95
  context.addInitializer(function() {
98
- onResourceStart(resource, originalMethod.bind(this));
96
+ RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod.bind(this));
99
97
  });
100
98
  }
101
99
  }, "actualDecorator");
@@ -1,9 +1,16 @@
1
1
  /**
2
2
  * Gets called per server/client tick, this is asyncronous though, if you await
3
3
  * in it, it will not be called until whatever was being awaited resolves.
4
+ * @param contextName - used whenever the function errors, will provide context to the tick
4
5
  */
5
- export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
6
+ export declare function OnTick(contextName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
7
+ /**
8
+ * @see OnTick
9
+ */
10
+ export declare const SetTick: typeof OnTick;
6
11
  /**
7
12
  * Gets called on the frame after the class is initialized.
13
+ * @param contextName - used whenever the function errors, will provide context to the function
8
14
  */
9
- export declare function SetImmediate(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
15
+ export declare function OnInit(contextName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
16
+ export declare const SetImmediate: typeof OnInit;
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { ErrorType, GlobalData } from "../GlobalData";
4
- function SetTick() {
4
+ function OnTick(contextName) {
5
5
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
6
6
  if (context.private) {
7
7
  throw new Error("SetTick does not work on private types, please mark the field as public");
@@ -11,14 +11,15 @@ function SetTick() {
11
11
  try {
12
12
  await originalMethod.call(this);
13
13
  } catch (e) {
14
- GlobalData.OnError(ErrorType.Tick, e);
14
+ GlobalData.OnError(ErrorType.Tick, e, contextName ? { name: contextName } : {});
15
15
  }
16
16
  });
17
17
  });
18
18
  }, "actualDecorator");
19
19
  }
20
- __name(SetTick, "SetTick");
21
- function SetImmediate() {
20
+ __name(OnTick, "OnTick");
21
+ const SetTick = OnTick;
22
+ function OnInit(contextName) {
22
23
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
23
24
  if (context.private) {
24
25
  throw new Error("SetTick does not work on private types, please mark the field as public");
@@ -28,14 +29,17 @@ function SetImmediate() {
28
29
  try {
29
30
  await originalMethod.call(this);
30
31
  } catch (e) {
31
- GlobalData.OnError(ErrorType.Immediate, e);
32
+ GlobalData.OnError(ErrorType.Tick, e, contextName ? { name: contextName } : {});
32
33
  }
33
34
  });
34
35
  });
35
36
  }, "actualDecorator");
36
37
  }
37
- __name(SetImmediate, "SetImmediate");
38
+ __name(OnInit, "OnInit");
39
+ const SetImmediate = OnInit;
38
40
  export {
41
+ OnInit,
42
+ OnTick,
39
43
  SetImmediate,
40
44
  SetTick
41
45
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A basic bitset wrapper to make some bitset code reusable
3
+ */
4
+ export declare class BitSet {
5
+ private value;
6
+ /**
7
+ * Sets the bit at {@param position} to `1`
8
+ */
9
+ set(position: number): void;
10
+ /**
11
+ * Sets the bit at {@param position} to `0`
12
+ */
13
+ clear(position: number): void;
14
+ /**
15
+ * Toggles the bit at {@param position}
16
+ */
17
+ toggle(position: number): void;
18
+ /**
19
+ * @returns `true` if the bit at {@param position} is set.
20
+ */
21
+ test(position: number): number;
22
+ /**
23
+ * @returns `true` if no bits in the bitset are set, false otherwise.
24
+ */
25
+ isEmpty(): boolean;
26
+ }
@@ -0,0 +1,41 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class BitSet {
4
+ static {
5
+ __name(this, "BitSet");
6
+ }
7
+ value = 0;
8
+ /**
9
+ * Sets the bit at {@param position} to `1`
10
+ */
11
+ set(position) {
12
+ this.value |= 1 << position;
13
+ }
14
+ /**
15
+ * Sets the bit at {@param position} to `0`
16
+ */
17
+ clear(position) {
18
+ this.value &= ~(1 << position);
19
+ }
20
+ /**
21
+ * Toggles the bit at {@param position}
22
+ */
23
+ toggle(position) {
24
+ this.value ^= 1 << position;
25
+ }
26
+ /**
27
+ * @returns `true` if the bit at {@param position} is set.
28
+ */
29
+ test(position) {
30
+ return this.value & position;
31
+ }
32
+ /**
33
+ * @returns `true` if no bits in the bitset are set, false otherwise.
34
+ */
35
+ isEmpty() {
36
+ return this.value === 0;
37
+ }
38
+ }
39
+ export {
40
+ BitSet
41
+ };
package/index.d.ts CHANGED
@@ -179,6 +179,7 @@ export * from "./common/GlobalData";
179
179
  export * from "./common/Kvp";
180
180
  export * from "./common/Resource";
181
181
  export * from "./common/types";
182
+ export * from "./common/utils/BitSet";
182
183
  export * from "./common/utils/ClassTypes";
183
184
  export * from "./common/utils/Color";
184
185
  export * from "./common/utils/Delay";
package/index.js CHANGED
@@ -179,6 +179,7 @@ export * from "./common/GlobalData";
179
179
  export * from "./common/Kvp";
180
180
  export * from "./common/Resource";
181
181
  export * from "./common/types";
182
+ export * from "./common/utils/BitSet";
182
183
  export * from "./common/utils/ClassTypes";
183
184
  export * from "./common/utils/Color";
184
185
  export * from "./common/utils/Delay";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.140",
11
+ "version": "0.0.142",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"