@nativewrappers/common-game 0.0.125 → 0.0.127
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/CommonModel.js +2 -2
- package/CommonTasks.d.ts +1 -1
- package/CommonTasks.js +2 -2
- package/common/Command.d.ts +77 -0
- package/common/Command.js +152 -0
- package/common/Convar.d.ts +13 -0
- package/common/Convar.js +58 -0
- package/common/GlobalData.d.ts +12 -0
- package/common/GlobalData.js +20 -0
- package/common/Kvp.d.ts +69 -0
- package/common/Kvp.js +137 -0
- package/common/Resource.d.ts +14 -0
- package/common/Resource.js +54 -0
- package/common/decors/ConVar.d.ts +14 -0
- package/common/decors/ConVar.js +70 -0
- package/common/decors/Events.d.ts +66 -0
- package/common/decors/Events.js +163 -0
- package/common/decors/Exports.d.ts +1 -0
- package/common/decors/Exports.js +53 -0
- package/common/decors/Permissions.d.ts +3 -0
- package/common/decors/Permissions.js +49 -0
- package/common/decors/Resources.d.ts +8 -0
- package/common/decors/Resources.js +94 -0
- package/common/decors/Ticks.d.ts +9 -0
- package/common/decors/Ticks.js +32 -0
- package/common/net/NetworkedMap.d.ts +28 -0
- package/common/net/NetworkedMap.js +225 -0
- package/common/types.d.ts +5 -0
- package/common/types.js +0 -0
- package/common/utils/ClassTypes.d.ts +11 -0
- package/common/utils/ClassTypes.js +15 -0
- package/common/utils/Color.d.ts +14 -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.d.ts +4 -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 +7 -0
- package/common/utils/PointF.js +18 -0
- package/common/utils/Quaternion.d.ts +10 -0
- package/common/utils/Quaternion.js +33 -0
- package/common/utils/Vector.d.ts +429 -0
- package/common/utils/Vector.js +589 -0
- package/common/utils/cleanPlayerName.d.ts +6 -0
- package/common/utils/cleanPlayerName.js +17 -0
- package/common/utils/enumValues.d.ts +12 -0
- package/common/utils/enumValues.js +20 -0
- package/common/utils/getStringFromUInt8Array.d.ts +8 -0
- package/common/utils/getStringFromUInt8Array.js +6 -0
- package/common/utils/getUInt32FromUint8Array.d.ts +8 -0
- package/common/utils/getUInt32FromUint8Array.js +6 -0
- package/common/utils/randomInt.d.ts +1 -0
- package/common/utils/randomInt.js +9 -0
- package/entities/CommonBaseEntity.d.ts +3 -3
- package/entities/CommonBaseEntity.js +2 -2
- package/entities/CommonBaseEntityBone.d.ts +1 -1
- package/entities/CommonBaseEntityBone.js +1 -1
- package/entities/CommonPed.d.ts +1 -1
- package/entities/CommonPed.js +1 -1
- package/entities/CommonPlayer.js +1 -1
- package/entities/CommonProp.d.ts +1 -1
- package/entities/CommonProp.js +1 -1
- package/entities/CommonVehicle.d.ts +1 -1
- package/entities/CommonVehicle.js +1 -1
- package/index.d.ts +26 -0
- package/index.js +26 -0
- package/interfaces/Dimension.d.ts +1 -1
- package/package.json +1 -1
- package/utils/Animations.js +1 -1
|
@@ -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
|
+
};
|
package/common/types.js
ADDED
|
File without changes
|
|
@@ -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,14 @@
|
|
|
1
|
+
export declare class Color {
|
|
2
|
+
static Transparent: Color;
|
|
3
|
+
static Black: Color;
|
|
4
|
+
static White: Color;
|
|
5
|
+
static WhiteSmoke: Color;
|
|
6
|
+
static fromArgb(a: number, r: number, g: number, b: number): Color;
|
|
7
|
+
static fromRgb(r: number, g: number, b: number): Color;
|
|
8
|
+
static fromArray(primitive: [number, number, number] | number[]): Color;
|
|
9
|
+
a: number;
|
|
10
|
+
r: number;
|
|
11
|
+
g: number;
|
|
12
|
+
b: number;
|
|
13
|
+
constructor(r: number, g: number, b: number, a?: number);
|
|
14
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class Point {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "Point");
|
|
6
|
+
}
|
|
7
|
+
static parse(arg) {
|
|
8
|
+
let point = new Point();
|
|
9
|
+
if (arg) {
|
|
10
|
+
if (typeof arg === "object") {
|
|
11
|
+
if (Array.isArray(arg)) {
|
|
12
|
+
if (arg.length === 2) {
|
|
13
|
+
point = new Point(arg[0], arg[1]);
|
|
14
|
+
}
|
|
15
|
+
} else if (arg.X && arg.Y) {
|
|
16
|
+
point = new Point(arg.X, arg.Y);
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
if (arg.indexOf(",") !== -1) {
|
|
20
|
+
const arr = arg.split(",");
|
|
21
|
+
point = new Point(Number.parseFloat(arr[0]), Number.parseFloat(arr[1]));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return point;
|
|
26
|
+
}
|
|
27
|
+
X;
|
|
28
|
+
Y;
|
|
29
|
+
constructor(x = 0, y = 0) {
|
|
30
|
+
this.X = x;
|
|
31
|
+
this.Y = y;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
Point
|
|
36
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class PointF {
|
|
4
|
+
constructor(x, y, z) {
|
|
5
|
+
this.x = x;
|
|
6
|
+
this.y = y;
|
|
7
|
+
this.z = z;
|
|
8
|
+
}
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "PointF");
|
|
11
|
+
}
|
|
12
|
+
static empty() {
|
|
13
|
+
return new PointF(0, 0, 0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
PointF
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Vector3 } from "./Vector";
|
|
4
|
+
class Quaternion {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "Quaternion");
|
|
7
|
+
}
|
|
8
|
+
x;
|
|
9
|
+
y;
|
|
10
|
+
z;
|
|
11
|
+
w;
|
|
12
|
+
constructor(valueXOrVector, yOrW, z, w) {
|
|
13
|
+
if (valueXOrVector instanceof Vector3) {
|
|
14
|
+
this.x = valueXOrVector.x;
|
|
15
|
+
this.y = valueXOrVector.y;
|
|
16
|
+
this.z = valueXOrVector.z;
|
|
17
|
+
this.w = yOrW ?? 0;
|
|
18
|
+
} else if (yOrW === void 0) {
|
|
19
|
+
this.x = valueXOrVector;
|
|
20
|
+
this.y = valueXOrVector;
|
|
21
|
+
this.z = valueXOrVector;
|
|
22
|
+
this.w = valueXOrVector;
|
|
23
|
+
} else {
|
|
24
|
+
this.x = valueXOrVector;
|
|
25
|
+
this.y = yOrW;
|
|
26
|
+
this.z = z ?? 0;
|
|
27
|
+
this.w = w ?? 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
Quaternion
|
|
33
|
+
};
|