@nativewrappers/common 0.0.77 → 0.0.81
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/Command.js +111 -0
- package/Convar.js +58 -0
- package/GlobalData.js +16 -0
- package/Kvp.js +137 -0
- package/Resource.js +54 -0
- package/decors/Events.js +170 -0
- package/net/NetworkedMap.js +225 -0
- package/package.json +3 -3
- package/types.js +0 -0
- package/utils/ClassTypes.js +15 -0
- package/utils/Color.js +33 -0
- package/utils/Delay.d.ts +1 -0
- package/utils/Delay.js +6 -0
- package/utils/Maths.js +18 -0
- package/utils/Point.d.ts +9 -0
- package/utils/Point.js +36 -0
- package/utils/PointF.d.ts +1 -1
- package/utils/PointF.js +18 -0
- package/utils/Quaternion.d.ts +1 -1
- package/utils/Quaternion.js +33 -0
- package/utils/Vector.js +589 -0
- package/utils/cleanPlayerName.js +17 -0
- package/utils/enumValues.js +20 -0
- package/utils/getStringFromUInt8Array.js +6 -0
- package/utils/getUInt32FromUint8Array.js +6 -0
- package/index.d.ts +0 -8
- package/index.js +0 -1480
- package/utils/Vector2.d.ts +0 -1
- package/utils/Vector3.d.ts +0 -1
- package/utils/Vector4.d.ts +0 -1
- package/utils/index.d.ts +0 -12
package/Command.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const commands = [];
|
|
4
|
+
$SERVER: {
|
|
5
|
+
on("playerJoining", () => emitNet("chat:addSuggestions", source, commands));
|
|
6
|
+
}
|
|
7
|
+
function registerCommand(name, commandHandler, restricted) {
|
|
8
|
+
if (Array.isArray(name)) {
|
|
9
|
+
for (const command of name) {
|
|
10
|
+
registerCommand(command, commandHandler, restricted);
|
|
11
|
+
}
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
RegisterCommand(name, commandHandler, !!restricted);
|
|
15
|
+
$SERVER: {
|
|
16
|
+
const ace = `command.${name}`;
|
|
17
|
+
if (typeof restricted === "string") {
|
|
18
|
+
if (IsPrincipalAceAllowed(restricted, ace)) return;
|
|
19
|
+
return ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(restricted)) {
|
|
22
|
+
for (const principal of restricted) {
|
|
23
|
+
if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
__name(registerCommand, "registerCommand");
|
|
29
|
+
class Command {
|
|
30
|
+
constructor(name, help, handler, params, restricted = true) {
|
|
31
|
+
this.name = name;
|
|
32
|
+
this.help = help;
|
|
33
|
+
this.params = params;
|
|
34
|
+
this.#handler = handler;
|
|
35
|
+
this.name = `/${name}`;
|
|
36
|
+
registerCommand(name, (source2, args, raw) => this.call(source2, args, raw), restricted);
|
|
37
|
+
if (params) {
|
|
38
|
+
for (const parameter of params) {
|
|
39
|
+
if (parameter.type) {
|
|
40
|
+
parameter.help = parameter.help ? `${parameter.help} (type: ${parameter.type})` : `(type: ${parameter.type})`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
$SERVER: {
|
|
45
|
+
commands.push(this);
|
|
46
|
+
emitNet("chat:addSuggestions", -1, this);
|
|
47
|
+
}
|
|
48
|
+
$CLIENT: {
|
|
49
|
+
emit("chat:addSuggestion", this);
|
|
50
|
+
}
|
|
51
|
+
}, 100);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static {
|
|
55
|
+
__name(this, "Command");
|
|
56
|
+
}
|
|
57
|
+
#handler;
|
|
58
|
+
mapArguments(source2, args, raw) {
|
|
59
|
+
const mapped = {
|
|
60
|
+
source: source2,
|
|
61
|
+
raw
|
|
62
|
+
};
|
|
63
|
+
if (!this.params) return mapped;
|
|
64
|
+
const result = this.params.every((param, index) => {
|
|
65
|
+
const arg = args[index];
|
|
66
|
+
let value = arg;
|
|
67
|
+
switch (param.type) {
|
|
68
|
+
case "number":
|
|
69
|
+
value = +arg;
|
|
70
|
+
break;
|
|
71
|
+
case "string":
|
|
72
|
+
value = !Number(arg) ? arg : false;
|
|
73
|
+
break;
|
|
74
|
+
case "playerId":
|
|
75
|
+
$SERVER: {
|
|
76
|
+
value = arg === "me" ? source2 : +arg;
|
|
77
|
+
if (!value || !DoesPlayerExist(value.toString())) value = void 0;
|
|
78
|
+
}
|
|
79
|
+
$CLIENT: {
|
|
80
|
+
value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
|
|
81
|
+
if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
case "longString":
|
|
85
|
+
value = raw.substring(raw.indexOf(arg));
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (value === void 0 && (!param.optional || param.optional && arg)) {
|
|
89
|
+
return Citizen.trace(
|
|
90
|
+
`^1command '${raw.split(" ")[0] || raw}' received an invalid ${param.type} for argument ${index + 1} (${param.name}), received '${arg}'^0`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
mapped[param.name] = value;
|
|
94
|
+
return true;
|
|
95
|
+
});
|
|
96
|
+
return result ? mapped : null;
|
|
97
|
+
}
|
|
98
|
+
async call(source2, args, raw = args.join(" ")) {
|
|
99
|
+
const parsed = this.mapArguments(source2, args, raw);
|
|
100
|
+
if (!parsed) return;
|
|
101
|
+
try {
|
|
102
|
+
await this.#handler(parsed);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
Citizen.trace(`^1command '${raw.split(" ")[0] || raw}' failed to execute!^0
|
|
105
|
+
${err.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
Command
|
|
111
|
+
};
|
package/Convar.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "./GlobalData";
|
|
4
|
+
class Convar {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "Convar");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @returns the current console buffer
|
|
10
|
+
*/
|
|
11
|
+
buffer() {
|
|
12
|
+
$CLIENT: {
|
|
13
|
+
if (GlobalData.IS_CLIENT) {
|
|
14
|
+
throw new Error("This function isn't available on the client");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return GetConsoleBuffer();
|
|
18
|
+
}
|
|
19
|
+
get(variable, defaultVar) {
|
|
20
|
+
return GetConvar(variable, defaultVar);
|
|
21
|
+
}
|
|
22
|
+
getInt(variable, defaultVar) {
|
|
23
|
+
return GetConvarInt(variable, defaultVar);
|
|
24
|
+
}
|
|
25
|
+
getFloat(varName, defaultVar) {
|
|
26
|
+
return GetConvarFloat(varName, defaultVar);
|
|
27
|
+
}
|
|
28
|
+
getBool(varName, defaultVar) {
|
|
29
|
+
return GetConvarBool(varName, defaultVar);
|
|
30
|
+
}
|
|
31
|
+
set(variable, value) {
|
|
32
|
+
$CLIENT: {
|
|
33
|
+
if (GlobalData.IS_CLIENT) {
|
|
34
|
+
throw new Error("This function isn't available on the client");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
SetConvar(variable, value);
|
|
38
|
+
}
|
|
39
|
+
setReplicated(variable, value) {
|
|
40
|
+
$CLIENT: {
|
|
41
|
+
if (GlobalData.IS_CLIENT) {
|
|
42
|
+
throw new Error("This function isn't available on the client");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
SetConvarReplicated(variable, value);
|
|
46
|
+
}
|
|
47
|
+
setServerInfo(variable, value) {
|
|
48
|
+
$CLIENT: {
|
|
49
|
+
if (GlobalData.IS_CLIENT) {
|
|
50
|
+
throw new Error("This function isn't available on the client");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
SetConvarServerInfo(variable, value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
Convar
|
|
58
|
+
};
|
package/GlobalData.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class GlobalData {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "GlobalData");
|
|
6
|
+
}
|
|
7
|
+
static CurrentResource = GetCurrentResourceName();
|
|
8
|
+
static IS_SERVER = IsDuplicityVersion();
|
|
9
|
+
static IS_CLIENT = !GlobalData.IS_SERVER;
|
|
10
|
+
static NetworkTick = null;
|
|
11
|
+
static NetworkedTicks = [];
|
|
12
|
+
static EnablePrettyPrint = true;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
GlobalData
|
|
16
|
+
};
|
package/Kvp.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class Kvp {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "Kvp");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the value associated with a key as a number.
|
|
9
|
+
*/
|
|
10
|
+
getNumber(key) {
|
|
11
|
+
return GetResourceKvpInt(key);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the value associated with a key as a float.
|
|
15
|
+
*/
|
|
16
|
+
getFloat(key) {
|
|
17
|
+
return GetResourceKvpFloat(key);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns the value associated with a key as a string.
|
|
21
|
+
*/
|
|
22
|
+
getString(key) {
|
|
23
|
+
return GetResourceKvpString(key);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the value associated with a key as a parsed JSON string.
|
|
27
|
+
*/
|
|
28
|
+
getJson(key) {
|
|
29
|
+
const str = GetResourceKvpString(key);
|
|
30
|
+
return str ? JSON.parse(str) : null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the value associated with a key as a number.
|
|
34
|
+
* @param async set the value using an async operation.
|
|
35
|
+
*/
|
|
36
|
+
setNumber(key, value, async = false) {
|
|
37
|
+
return async ? SetResourceKvpIntNoSync(key, value) : SetResourceKvpInt(key, value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the value associated with a key as a float.
|
|
41
|
+
* @param async set the value using an async operation.
|
|
42
|
+
*/
|
|
43
|
+
setFloat(key, value, async = false) {
|
|
44
|
+
return async ? SetResourceKvpFloatNoSync(key, value) : SetResourceKvpFloat(key, value);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the value associated with a key as a string.
|
|
48
|
+
* @param async set the value using an async operation.
|
|
49
|
+
*/
|
|
50
|
+
setString(key, value, async = false) {
|
|
51
|
+
return async ? SetResourceKvpNoSync(key, value) : SetResourceKvp(key, value);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets the value associated with a key as a JSON string.
|
|
55
|
+
* @param async set the value using an async operation.
|
|
56
|
+
*/
|
|
57
|
+
setJson(key, value, async = false) {
|
|
58
|
+
const str = JSON.stringify(value);
|
|
59
|
+
return async ? SetResourceKvpNoSync(key, str) : SetResourceKvp(key, str);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the value associated with a key as a JSON string.
|
|
63
|
+
* @param async set the value using an async operation.
|
|
64
|
+
*/
|
|
65
|
+
set(key, value, async = false) {
|
|
66
|
+
switch (typeof value) {
|
|
67
|
+
case "function":
|
|
68
|
+
case "symbol":
|
|
69
|
+
throw new Error(`Failed to set Kvp for invalid type '${typeof value}'`);
|
|
70
|
+
case "undefined":
|
|
71
|
+
return this.delete(key, async);
|
|
72
|
+
case "object":
|
|
73
|
+
return this.setJson(key, value, async);
|
|
74
|
+
case "boolean":
|
|
75
|
+
value = value ? 1 : 0;
|
|
76
|
+
case "number":
|
|
77
|
+
return Number.isInteger(value) ? this.setNumber(key, value, async) : this.setFloat(key, value, async);
|
|
78
|
+
default:
|
|
79
|
+
value = String(value);
|
|
80
|
+
return this.setString(key, value, async);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Deletes the specified value for key.
|
|
85
|
+
* @param async remove the value using an async operation
|
|
86
|
+
*/
|
|
87
|
+
delete(key, async = false) {
|
|
88
|
+
return async ? DeleteResourceKvpNoSync(key) : DeleteResourceKvp(key);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Commits pending asynchronous operations to disk, ensuring data consistency.
|
|
92
|
+
*
|
|
93
|
+
* Should be called after calling set methods using the async flag.
|
|
94
|
+
*/
|
|
95
|
+
flush() {
|
|
96
|
+
FlushResourceKvp();
|
|
97
|
+
}
|
|
98
|
+
getAllKeys(prefix) {
|
|
99
|
+
const keys = [];
|
|
100
|
+
const handle = StartFindKvp(prefix);
|
|
101
|
+
if (handle === -1) return keys;
|
|
102
|
+
let key;
|
|
103
|
+
do {
|
|
104
|
+
key = FindKvp(handle);
|
|
105
|
+
if (key) keys.push(key);
|
|
106
|
+
} while (key);
|
|
107
|
+
EndFindKvp(handle);
|
|
108
|
+
return keys;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns an array of keys which match or contain the given keys.
|
|
112
|
+
*/
|
|
113
|
+
getKeys(prefix) {
|
|
114
|
+
return typeof prefix === "string" ? this.getAllKeys(prefix) : prefix.flatMap((key) => this.getAllKeys(key));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get all values from keys in an array as the specified type.
|
|
118
|
+
*/
|
|
119
|
+
getValuesAsType(prefix, type) {
|
|
120
|
+
const values = this.getKeys(prefix);
|
|
121
|
+
return values.map((key) => {
|
|
122
|
+
switch (type) {
|
|
123
|
+
case "number":
|
|
124
|
+
return this.getNumber(key);
|
|
125
|
+
case "float":
|
|
126
|
+
return this.getFloat(key);
|
|
127
|
+
case "string":
|
|
128
|
+
return this.getString(key);
|
|
129
|
+
default:
|
|
130
|
+
return this.getJson(key);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
Kvp
|
|
137
|
+
};
|
package/Resource.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "./GlobalData";
|
|
4
|
+
class Resource {
|
|
5
|
+
constructor(name) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
}
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "Resource");
|
|
10
|
+
}
|
|
11
|
+
getMetadata(metadataKey, index) {
|
|
12
|
+
return GetResourceMetadata(this.name, metadataKey, index);
|
|
13
|
+
}
|
|
14
|
+
getPath() {
|
|
15
|
+
return GetResourcePath(this.name);
|
|
16
|
+
}
|
|
17
|
+
loadFile(fileName) {
|
|
18
|
+
return LoadResourceFile(this.name, fileName);
|
|
19
|
+
}
|
|
20
|
+
saveFile(fileName, data, length) {
|
|
21
|
+
$CLIENT: {
|
|
22
|
+
if (GlobalData.IS_CLIENT) {
|
|
23
|
+
throw new Error("This function isn't available on the client");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return SaveResourceFile(this.name, fileName, data, length);
|
|
27
|
+
}
|
|
28
|
+
scheduleTick() {
|
|
29
|
+
$CLIENT: {
|
|
30
|
+
if (GlobalData.IS_CLIENT) {
|
|
31
|
+
throw new Error("This function isn't available on the client");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return ScheduleResourceTick(this.name);
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
StartResource(this.name);
|
|
38
|
+
}
|
|
39
|
+
stop() {
|
|
40
|
+
StopResource(this.name);
|
|
41
|
+
}
|
|
42
|
+
static startResource(name) {
|
|
43
|
+
StartResource(name);
|
|
44
|
+
}
|
|
45
|
+
static stopResource(name) {
|
|
46
|
+
StopResource(name);
|
|
47
|
+
}
|
|
48
|
+
static resourceCount() {
|
|
49
|
+
return GetNumResources();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
Resource
|
|
54
|
+
};
|
package/decors/Events.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "../GlobalData";
|
|
4
|
+
var ConVarType = /* @__PURE__ */ ((ConVarType2) => {
|
|
5
|
+
ConVarType2[ConVarType2["String"] = 0] = "String";
|
|
6
|
+
ConVarType2[ConVarType2["Integer"] = 1] = "Integer";
|
|
7
|
+
ConVarType2[ConVarType2["Float"] = 2] = "Float";
|
|
8
|
+
ConVarType2[ConVarType2["Boolean"] = 3] = "Boolean";
|
|
9
|
+
return ConVarType2;
|
|
10
|
+
})(ConVarType || {});
|
|
11
|
+
const DisablePrettyPrint = /* @__PURE__ */ __name(() => GlobalData.EnablePrettyPrint = false, "DisablePrettyPrint");
|
|
12
|
+
function Exports(exportName) {
|
|
13
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
14
|
+
if (context.private) {
|
|
15
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
16
|
+
}
|
|
17
|
+
context.addInitializer(function() {
|
|
18
|
+
exports(exportName, (...args) => {
|
|
19
|
+
return originalMethod.call(this, ...args);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}, "actualDecorator");
|
|
23
|
+
}
|
|
24
|
+
__name(Exports, "Exports");
|
|
25
|
+
function Event(eventName) {
|
|
26
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
27
|
+
if (context.private) {
|
|
28
|
+
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
29
|
+
}
|
|
30
|
+
context.addInitializer(function() {
|
|
31
|
+
on(eventName, (...args) => {
|
|
32
|
+
try {
|
|
33
|
+
return originalMethod.call(this, ...args);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
REMOVE_EVENT_LOG: {
|
|
36
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
37
|
+
console.error("------- EVENT ERROR --------");
|
|
38
|
+
console.error(`Call to ${eventName} errored`);
|
|
39
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
40
|
+
console.error(`Error: ${e}`);
|
|
41
|
+
console.error("------- END EVENT ERROR --------");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}, "actualDecorator");
|
|
47
|
+
}
|
|
48
|
+
__name(Event, "Event");
|
|
49
|
+
function NetEvent(eventName, remoteOnly = true) {
|
|
50
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
51
|
+
if (context.private) {
|
|
52
|
+
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
53
|
+
}
|
|
54
|
+
context.addInitializer(function() {
|
|
55
|
+
onNet(eventName, (...args) => {
|
|
56
|
+
const src = source;
|
|
57
|
+
try {
|
|
58
|
+
$CLIENT: {
|
|
59
|
+
if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return originalMethod.call(this, ...args);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
REMOVE_NET_EVENT_LOG: {
|
|
66
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
67
|
+
console.error("------- NET EVENT ERROR --------");
|
|
68
|
+
console.error(`Call to ${eventName} errored`);
|
|
69
|
+
console.error(`Caller: ${src}`);
|
|
70
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
71
|
+
console.error(`Error: ${e}`);
|
|
72
|
+
console.error("------- END NET EVENT ERROR --------");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}, "actualDecorator");
|
|
78
|
+
}
|
|
79
|
+
__name(NetEvent, "NetEvent");
|
|
80
|
+
function NuiEvent(eventName) {
|
|
81
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
82
|
+
if (context.private) {
|
|
83
|
+
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
84
|
+
}
|
|
85
|
+
context.addInitializer(function() {
|
|
86
|
+
RegisterNuiCallback(eventName, (...args) => {
|
|
87
|
+
return originalMethod.call(this, ...args);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}, "actualDecorator");
|
|
91
|
+
}
|
|
92
|
+
__name(NuiEvent, "NuiEvent");
|
|
93
|
+
const get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
|
|
94
|
+
switch (con_var_type) {
|
|
95
|
+
case 0 /* String */:
|
|
96
|
+
return GetConvar;
|
|
97
|
+
case 1 /* Integer */:
|
|
98
|
+
return GetConvarInt;
|
|
99
|
+
case 2 /* Float */:
|
|
100
|
+
return GetConvarFloat;
|
|
101
|
+
case 3 /* Boolean */:
|
|
102
|
+
return GetConvarBool;
|
|
103
|
+
// needed so typescript wont complain about "unreachable code" for the error below
|
|
104
|
+
default:
|
|
105
|
+
}
|
|
106
|
+
throw new Error("Got invalid ConVarType");
|
|
107
|
+
}, "get_convar_fn");
|
|
108
|
+
function ConVar(name, is_floating_point, deserialize) {
|
|
109
|
+
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
110
|
+
if (context.private) {
|
|
111
|
+
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
112
|
+
}
|
|
113
|
+
context.addInitializer(function() {
|
|
114
|
+
const t = this;
|
|
115
|
+
const default_value = Reflect.get(t, context.name);
|
|
116
|
+
const default_type = typeof default_value;
|
|
117
|
+
let con_var_type = null;
|
|
118
|
+
if (default_type === "number") {
|
|
119
|
+
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
120
|
+
con_var_type = 2 /* Float */;
|
|
121
|
+
} else {
|
|
122
|
+
con_var_type = 1 /* Integer */;
|
|
123
|
+
}
|
|
124
|
+
} else if (default_type === "boolean") {
|
|
125
|
+
con_var_type = 3 /* Boolean */;
|
|
126
|
+
} else if (default_value === "string") {
|
|
127
|
+
con_var_type = 0 /* String */;
|
|
128
|
+
}
|
|
129
|
+
if (!deserialize && con_var_type === null) {
|
|
130
|
+
throw new Error("You should provide a deserialize function if you want to convert this to an object type");
|
|
131
|
+
}
|
|
132
|
+
if (con_var_type === null) {
|
|
133
|
+
con_var_type = 0 /* String */;
|
|
134
|
+
}
|
|
135
|
+
const con_var_fn = get_convar_fn(con_var_type);
|
|
136
|
+
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
137
|
+
const data = con_var_fn(name, default_value);
|
|
138
|
+
return deserialize ? deserialize(data) : data;
|
|
139
|
+
}, "get_convar_value");
|
|
140
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
141
|
+
AddConvarChangeListener(name, () => {
|
|
142
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}, "actualDecorator");
|
|
146
|
+
}
|
|
147
|
+
__name(ConVar, "ConVar");
|
|
148
|
+
function SetTick() {
|
|
149
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
150
|
+
if (context.private) {
|
|
151
|
+
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
152
|
+
}
|
|
153
|
+
context.addInitializer(function() {
|
|
154
|
+
setTick(async () => {
|
|
155
|
+
await originalMethod.call(this);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}, "actualDecorator");
|
|
159
|
+
}
|
|
160
|
+
__name(SetTick, "SetTick");
|
|
161
|
+
export {
|
|
162
|
+
ConVar,
|
|
163
|
+
ConVarType,
|
|
164
|
+
DisablePrettyPrint,
|
|
165
|
+
Event,
|
|
166
|
+
Exports,
|
|
167
|
+
NetEvent,
|
|
168
|
+
NuiEvent,
|
|
169
|
+
SetTick
|
|
170
|
+
};
|