@nativewrappers/redm 0.0.80 → 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/Attribute.js +143 -0
- package/Controls.js +22 -0
- package/Game.d.ts +2 -2
- package/Game.js +18 -0
- package/GameConstants.d.ts +1 -1
- package/GameConstants.js +24 -0
- package/Model.js +153 -0
- package/RawControls.d.ts +1 -1
- package/RawControls.js +22 -0
- package/RelationshipGroup.js +72 -0
- package/Volume.d.ts +1 -1
- package/Volume.js +32 -0
- package/common/Command.js +111 -0
- package/common/Convar.js +58 -0
- package/common/GlobalData.js +16 -0
- package/common/Kvp.js +137 -0
- package/common/Resource.js +54 -0
- package/common/decors/Events.js +170 -0
- package/common/net/NetworkedMap.js +225 -0
- package/common/utils/ClassTypes.js +15 -0
- package/common/utils/Color.js +33 -0
- package/common/utils/Delay.d.ts +1 -0
- package/common/utils/Delay.js +6 -0
- package/common/utils/Maths.js +18 -0
- package/common/utils/Point.d.ts +9 -0
- package/common/utils/Point.js +36 -0
- package/common/utils/PointF.d.ts +1 -1
- package/common/utils/PointF.js +18 -0
- package/common/utils/Quaternion.d.ts +1 -1
- package/common/utils/Quaternion.js +33 -0
- package/common/utils/Vector.js +589 -0
- package/common/utils/cleanPlayerName.js +17 -0
- package/common/utils/enumValues.js +20 -0
- package/common/utils/getStringFromUInt8Array.js +6 -0
- package/common/utils/getUInt32FromUint8Array.js +6 -0
- package/definitions/Citizen.d.js +0 -0
- package/definitions/index.d.js +0 -0
- package/definitions/redm.d.js +0 -0
- package/entities/BaseEntity.d.ts +1 -1
- package/entities/BaseEntity.js +99 -0
- package/entities/Entity.d.ts +1 -1
- package/entities/Entity.js +99 -0
- package/entities/Ped.d.ts +1 -1
- package/entities/Ped.js +336 -0
- package/entities/Pickup.d.ts +4 -0
- package/entities/Pickup.js +14 -0
- package/entities/Player.js +57 -0
- package/entities/Prop.js +11 -0
- package/entities/Vehicle.d.ts +1 -1
- package/entities/Vehicle.js +23 -0
- package/enums/Attributes.js +56 -0
- package/enums/Entity.js +20 -0
- package/enums/Keys.js +809 -0
- package/enums/Ped.js +31 -0
- package/enums/RawKeys.js +234 -0
- package/enums/Relationship.js +13 -0
- package/enums/VehicleSeat.js +17 -0
- package/interfaces/Dimensions.d.ts +1 -1
- package/interfaces/Dimensions.js +0 -0
- package/package.json +2 -2
- package/types/Throwable.js +0 -0
- package/utils/Native.js +8 -0
- package/world/createDraftVehicle.d.ts +2 -2
- package/world/createDraftVehicle.js +32 -0
- package/world/createPed.d.ts +2 -2
- package/world/createPed.js +28 -0
- package/world/createProp.d.ts +1 -1
- package/world/createProp.js +28 -0
- package/world/createVehicle.d.ts +2 -2
- package/world/createVehicle.js +28 -0
- package/common/index.d.ts +0 -8
- package/common/utils/Vector2.d.ts +0 -1
- package/common/utils/Vector3.d.ts +0 -1
- package/common/utils/Vector4.d.ts +0 -1
- package/common/utils/index.d.ts +0 -12
- package/entities/index.d.ts +0 -4
- package/enums/index.d.ts +0 -6
- package/index.d.ts +0 -12
- package/index.js +0 -3762
- package/utils/index.d.ts +0 -2
- package/world/index.d.ts +0 -4
- /package/{game/index.d.ts → common/types.js} +0 -0
|
@@ -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/common/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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "../GlobalData";
|
|
4
|
+
class NetworkedMapEventManager {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "NetworkedMapEventManager");
|
|
7
|
+
}
|
|
8
|
+
#syncedCalls = /* @__PURE__ */ new Map();
|
|
9
|
+
constructor() {
|
|
10
|
+
$SERVER: if (GlobalData.IS_SERVER) {
|
|
11
|
+
on("playerDropped", () => {
|
|
12
|
+
const src = source;
|
|
13
|
+
for (const [_k, map] of this.#syncedCalls) {
|
|
14
|
+
map.removeSubscriber(src);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
$CLIENT: {
|
|
20
|
+
RegisterResourceAsEventHandler(`${GlobalData.CurrentResource}:syncChanges`);
|
|
21
|
+
addRawEventListener(`${GlobalData.CurrentResource}:syncChanges`, (msgpack_data) => {
|
|
22
|
+
const data = msgpack_unpack(msgpack_data);
|
|
23
|
+
const syncName = data[0];
|
|
24
|
+
const syncData = data[1];
|
|
25
|
+
const map = this.#syncedCalls.get(syncName);
|
|
26
|
+
if (!map) {
|
|
27
|
+
throw new Error(`Tried to sync changes for a networked map but ${syncName} does't exist.`);
|
|
28
|
+
}
|
|
29
|
+
map.handleSync(syncData);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
addNetworkedMap(map) {
|
|
34
|
+
this.#syncedCalls.set(map.SyncName, map);
|
|
35
|
+
}
|
|
36
|
+
removeNetworkedMap(syncName) {
|
|
37
|
+
this.#syncedCalls.delete(syncName);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const netManager = new NetworkedMapEventManager();
|
|
41
|
+
class NetworkedMap extends Map {
|
|
42
|
+
static {
|
|
43
|
+
__name(this, "NetworkedMap");
|
|
44
|
+
}
|
|
45
|
+
#syncName;
|
|
46
|
+
#queuedChanges = [];
|
|
47
|
+
#changeListeners = /* @__PURE__ */ new Map();
|
|
48
|
+
#subscribers = /* @__PURE__ */ new Set();
|
|
49
|
+
constructor(syncName, initialValue) {
|
|
50
|
+
super(initialValue);
|
|
51
|
+
this.#syncName = syncName;
|
|
52
|
+
GlobalData.NetworkedTicks.push(this);
|
|
53
|
+
netManager.addNetworkedMap(this);
|
|
54
|
+
$SERVER: {
|
|
55
|
+
if (!GlobalData.NetworkTick && GlobalData.IS_SERVER) {
|
|
56
|
+
GlobalData.NetworkTick = setTick(() => {
|
|
57
|
+
for (const networkedThis of GlobalData.NetworkedTicks) {
|
|
58
|
+
networkedThis.networkTick();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
get SyncName() {
|
|
65
|
+
return this.#syncName;
|
|
66
|
+
}
|
|
67
|
+
// handles removing the player from the map whenever they're dropped
|
|
68
|
+
onPlayerDropped() {
|
|
69
|
+
this.removeSubscriber(source);
|
|
70
|
+
}
|
|
71
|
+
/*
|
|
72
|
+
* 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)
|
|
73
|
+
*
|
|
74
|
+
* 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
|
|
75
|
+
*/
|
|
76
|
+
resync(source2) {
|
|
77
|
+
const packed_data = msgpack_pack([this.#syncName, [[4 /* Init */, this.size === 0 ? [] : Array.from(this)]]]);
|
|
78
|
+
TriggerClientEventInternal(
|
|
79
|
+
`${GlobalData.CurrentResource}:syncChanges`,
|
|
80
|
+
source2,
|
|
81
|
+
packed_data,
|
|
82
|
+
packed_data.length
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
/*
|
|
86
|
+
* Adds a new subscriber to the map
|
|
87
|
+
*/
|
|
88
|
+
addSubscriber(source2) {
|
|
89
|
+
this.#subscribers.add(source2);
|
|
90
|
+
this.resync(source2);
|
|
91
|
+
}
|
|
92
|
+
removeSubscriber(sub) {
|
|
93
|
+
return this.#subscribers.delete(sub);
|
|
94
|
+
}
|
|
95
|
+
hasSubscriber(sub) {
|
|
96
|
+
return this.#subscribers.has(sub);
|
|
97
|
+
}
|
|
98
|
+
subscriberCount() {
|
|
99
|
+
return this.#subscribers.size;
|
|
100
|
+
}
|
|
101
|
+
handleSync(data) {
|
|
102
|
+
for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
|
|
103
|
+
switch (change_type) {
|
|
104
|
+
case 1 /* Add */: {
|
|
105
|
+
this.set(key, value);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
case 2 /* Remove */: {
|
|
109
|
+
super.delete(key);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
case 3 /* Reset */: {
|
|
113
|
+
super.clear();
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
case 4 /* Init */: {
|
|
117
|
+
super.clear();
|
|
118
|
+
const key_value = key;
|
|
119
|
+
for (const [k, v] of key_value) {
|
|
120
|
+
this.set(k, v);
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
case 0 /* SubValueChanged */: {
|
|
125
|
+
const data2 = this.get(key);
|
|
126
|
+
data2[value] = possibly_undefined_subvalue;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/*
|
|
133
|
+
* Listens for the change on the specified key, it will get the resulting
|
|
134
|
+
* value on the change
|
|
135
|
+
*/
|
|
136
|
+
listenForChange(key, fn) {
|
|
137
|
+
const listener = this.#changeListeners.get(key);
|
|
138
|
+
listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
|
|
139
|
+
}
|
|
140
|
+
#triggerEventForSubscribers(data) {
|
|
141
|
+
const packed_data = msgpack_pack([this.#syncName, data]);
|
|
142
|
+
for (const sub of this.#subscribers) {
|
|
143
|
+
TriggerClientEventInternal(
|
|
144
|
+
`${GlobalData.CurrentResource}:syncChanges`,
|
|
145
|
+
sub,
|
|
146
|
+
packed_data,
|
|
147
|
+
packed_data.length
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
#pushChangeForListener(key, value) {
|
|
152
|
+
const listener = this.#changeListeners.get(key);
|
|
153
|
+
if (!listener) return;
|
|
154
|
+
for (const ln of listener) {
|
|
155
|
+
ln(value);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
set(key, value) {
|
|
159
|
+
let v = value;
|
|
160
|
+
if (value instanceof Object) {
|
|
161
|
+
const curMap = this;
|
|
162
|
+
const objectChangeHandler = {
|
|
163
|
+
get(target, prop, reciever) {
|
|
164
|
+
return Reflect.get(target, prop, reciever);
|
|
165
|
+
},
|
|
166
|
+
set(target, p, newValue, receiver) {
|
|
167
|
+
const success = Reflect.set(target, p, newValue, receiver);
|
|
168
|
+
if (success) {
|
|
169
|
+
curMap.#pushChangeForListener(key, target);
|
|
170
|
+
$SERVER: {
|
|
171
|
+
curMap.#queuedChanges.push([0 /* SubValueChanged */, key, p, newValue]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return success;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
v = new Proxy(v, objectChangeHandler);
|
|
178
|
+
}
|
|
179
|
+
super.set(key, v);
|
|
180
|
+
this.#pushChangeForListener(key, v);
|
|
181
|
+
$SERVER: {
|
|
182
|
+
this.#queuedChanges.push([1 /* Add */, key, v]);
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/*
|
|
187
|
+
* Resets the map to its default state
|
|
188
|
+
*/
|
|
189
|
+
clear() {
|
|
190
|
+
$CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'clear' on client`);
|
|
191
|
+
this.#queuedChanges = [];
|
|
192
|
+
this.#queuedChanges.push([3 /* Reset */]);
|
|
193
|
+
super.clear();
|
|
194
|
+
}
|
|
195
|
+
delete(key) {
|
|
196
|
+
$CLIENT: if (GlobalData.IS_CLIENT) throw new Error(`Cannot call 'delete' on client`);
|
|
197
|
+
this.#queuedChanges.push([2 /* Remove */, key]);
|
|
198
|
+
return super.delete(key);
|
|
199
|
+
}
|
|
200
|
+
networkTick() {
|
|
201
|
+
if (this.#queuedChanges.length !== 0) {
|
|
202
|
+
this.#triggerEventForSubscribers(this.#queuedChanges);
|
|
203
|
+
this.#queuedChanges = [];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
[Symbol.dispose]() {
|
|
207
|
+
this.#subscribers.clear();
|
|
208
|
+
this.#changeListeners.clear();
|
|
209
|
+
this.#queuedChanges = [];
|
|
210
|
+
netManager.removeNetworkedMap(this.#syncName);
|
|
211
|
+
GlobalData.NetworkedTicks.filter((v) => v !== this);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Unregisters from the tick handler and removes the event listener
|
|
215
|
+
*/
|
|
216
|
+
dispose() {
|
|
217
|
+
this[Symbol.dispose]();
|
|
218
|
+
}
|
|
219
|
+
get [Symbol.toStringTag]() {
|
|
220
|
+
return "NetworkedMap";
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
NetworkedMap
|
|
225
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var ClassTypes = /* @__PURE__ */ ((ClassTypes2) => {
|
|
2
|
+
ClassTypes2[ClassTypes2["Ped"] = 0] = "Ped";
|
|
3
|
+
ClassTypes2[ClassTypes2["Prop"] = 1] = "Prop";
|
|
4
|
+
ClassTypes2[ClassTypes2["Vehicle"] = 2] = "Vehicle";
|
|
5
|
+
ClassTypes2[ClassTypes2["Entity"] = 3] = "Entity";
|
|
6
|
+
ClassTypes2[ClassTypes2["Player"] = 4] = "Player";
|
|
7
|
+
ClassTypes2[ClassTypes2["Vector2"] = 5] = "Vector2";
|
|
8
|
+
ClassTypes2[ClassTypes2["Vector3"] = 6] = "Vector3";
|
|
9
|
+
ClassTypes2[ClassTypes2["Vector4"] = 7] = "Vector4";
|
|
10
|
+
ClassTypes2[ClassTypes2["Quanterion"] = 8] = "Quanterion";
|
|
11
|
+
return ClassTypes2;
|
|
12
|
+
})(ClassTypes || {});
|
|
13
|
+
export {
|
|
14
|
+
ClassTypes
|
|
15
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class Color {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "Color");
|
|
6
|
+
}
|
|
7
|
+
static Transparent = new Color(0, 0, 0, 0);
|
|
8
|
+
static Black = new Color(0, 0, 0);
|
|
9
|
+
static White = new Color(255, 255, 255);
|
|
10
|
+
static WhiteSmoke = new Color(245, 245, 245);
|
|
11
|
+
static fromArgb(a, r, g, b) {
|
|
12
|
+
return new Color(r, g, b, a);
|
|
13
|
+
}
|
|
14
|
+
static fromRgb(r, g, b) {
|
|
15
|
+
return new Color(r, g, b);
|
|
16
|
+
}
|
|
17
|
+
static fromArray(primitive) {
|
|
18
|
+
return new Color(primitive[0], primitive[1], primitive[2], 255);
|
|
19
|
+
}
|
|
20
|
+
a;
|
|
21
|
+
r;
|
|
22
|
+
g;
|
|
23
|
+
b;
|
|
24
|
+
constructor(r, g, b, a = 255) {
|
|
25
|
+
this.r = r;
|
|
26
|
+
this.g = g;
|
|
27
|
+
this.b = b;
|
|
28
|
+
this.a = a;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
Color
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Delay: (ms: number) => Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class Maths {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "Maths");
|
|
6
|
+
}
|
|
7
|
+
static clamp(num, min, max) {
|
|
8
|
+
return num <= min ? min : num >= max ? max : num;
|
|
9
|
+
}
|
|
10
|
+
static getRandomInt(min, max) {
|
|
11
|
+
min = Math.ceil(min);
|
|
12
|
+
max = Math.floor(max);
|
|
13
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
Maths
|
|
18
|
+
};
|