@nativewrappers/common 0.0.65 → 0.0.75
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/README.md +45 -0
- package/index.js +1480 -8
- package/package.json +7 -2
- package/utils/PointF.d.ts +0 -5
- package/Command.js +0 -103
- package/Convar.js +0 -50
- package/GlobalData.js +0 -8
- package/Kvp.js +0 -141
- package/Resource.js +0 -47
- package/decors/Events.js +0 -217
- package/net/NetworkedMap.js +0 -243
- package/types.js +0 -1
- package/utils/ClassTypes.js +0 -12
- package/utils/Color.js +0 -25
- package/utils/Maths.js +0 -10
- package/utils/PointF.js +0 -14
- package/utils/Quaternion.js +0 -27
- package/utils/Vector.js +0 -606
- package/utils/Vector2.js +0 -1
- package/utils/Vector3.js +0 -1
- package/utils/Vector4.js +0 -1
- package/utils/cleanPlayerName.js +0 -27
- package/utils/enumValues.js +0 -14
- package/utils/getStringFromUInt8Array.js +0 -10
- package/utils/getUInt32FromUint8Array.js +0 -8
- package/utils/index.js +0 -12
package/net/NetworkedMap.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { GlobalData } from "../GlobalData";
|
|
2
|
-
var MapChangeType;
|
|
3
|
-
(function (MapChangeType) {
|
|
4
|
-
// whenever a value inside of the object changed
|
|
5
|
-
MapChangeType[MapChangeType["SubValueChanged"] = 0] = "SubValueChanged";
|
|
6
|
-
// whenever a new key was added, or overwrote
|
|
7
|
-
MapChangeType[MapChangeType["Add"] = 1] = "Add";
|
|
8
|
-
// whenever a key was removed from the map
|
|
9
|
-
MapChangeType[MapChangeType["Remove"] = 2] = "Remove";
|
|
10
|
-
// whenever reset() was called on the map
|
|
11
|
-
MapChangeType[MapChangeType["Reset"] = 3] = "Reset";
|
|
12
|
-
// Whenever they're subscribed initially and get the initial load of data
|
|
13
|
-
MapChangeType[MapChangeType["Init"] = 4] = "Init";
|
|
14
|
-
})(MapChangeType || (MapChangeType = {}));
|
|
15
|
-
// Used to not make a bunch of on/raw events, we just reuse the same one and look up the data in the map
|
|
16
|
-
class NetworkedMapEventManager {
|
|
17
|
-
#syncedCalls = new Map();
|
|
18
|
-
constructor() {
|
|
19
|
-
SERVER: if (GlobalData.IS_SERVER) {
|
|
20
|
-
on("playerDropped", () => {
|
|
21
|
-
const src = source;
|
|
22
|
-
// call the player dropped for each call
|
|
23
|
-
for (const [_k, map] of this.#syncedCalls) {
|
|
24
|
-
map.removeSubscriber(src);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
CLIENT: {
|
|
30
|
-
RegisterResourceAsEventHandler(`${GlobalData.CurrentResource}:syncChanges`);
|
|
31
|
-
addRawEventListener(`${GlobalData.CurrentResource}:syncChanges`, (msgpack_data) => {
|
|
32
|
-
const data = msgpack_unpack(msgpack_data);
|
|
33
|
-
const syncName = data[0];
|
|
34
|
-
const syncData = data[1];
|
|
35
|
-
const map = this.#syncedCalls.get(syncName);
|
|
36
|
-
if (!map) {
|
|
37
|
-
throw new Error(`Tried to sync changes for a networked map but ${syncName} does't exist.`);
|
|
38
|
-
}
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
map.handleSync(syncData);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
addNetworkedMap(map) {
|
|
45
|
-
// abuse typescript, we don't want the end user to use these calls but we still want it to be accessible internally.
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
this.#syncedCalls.set(map.SyncName, map);
|
|
48
|
-
}
|
|
49
|
-
removeNetworkedMap(syncName) {
|
|
50
|
-
this.#syncedCalls.delete(syncName);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const netManager = new NetworkedMapEventManager();
|
|
54
|
-
/**
|
|
55
|
-
* not ready to be used just thoughts right now
|
|
56
|
-
*/
|
|
57
|
-
export class NetworkedMap extends Map {
|
|
58
|
-
#syncName;
|
|
59
|
-
#queuedChanges = [];
|
|
60
|
-
#changeListeners = new Map();
|
|
61
|
-
#subscribers = new Set();
|
|
62
|
-
constructor(syncName, initialValue) {
|
|
63
|
-
super(initialValue);
|
|
64
|
-
this.#syncName = syncName;
|
|
65
|
-
GlobalData.NetworkedTicks.push(this);
|
|
66
|
-
netManager.addNetworkedMap(this);
|
|
67
|
-
// if we don't have a network tick then we want to register it.
|
|
68
|
-
SERVER: {
|
|
69
|
-
if (!GlobalData.NetworkTick && GlobalData.IS_SERVER) {
|
|
70
|
-
GlobalData.NetworkTick = setTick(() => {
|
|
71
|
-
for (const networkedThis of GlobalData.NetworkedTicks) {
|
|
72
|
-
networkedThis.networkTick();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
get SyncName() {
|
|
79
|
-
return this.#syncName;
|
|
80
|
-
}
|
|
81
|
-
// handles removing the player from the map whenever they're dropped
|
|
82
|
-
onPlayerDropped() {
|
|
83
|
-
this.removeSubscriber(source);
|
|
84
|
-
}
|
|
85
|
-
/*
|
|
86
|
-
* 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)
|
|
87
|
-
*
|
|
88
|
-
* 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
|
|
89
|
-
*/
|
|
90
|
-
resync(source) {
|
|
91
|
-
const packed_data = msgpack_pack([
|
|
92
|
-
this.#syncName,
|
|
93
|
-
[[MapChangeType.Init, this.size === 0 ? [] : Array.from(this)]],
|
|
94
|
-
]);
|
|
95
|
-
TriggerClientEventInternal(`${GlobalData.CurrentResource}:syncChanges`, source, packed_data, packed_data.length);
|
|
96
|
-
}
|
|
97
|
-
/*
|
|
98
|
-
* Adds a new subscriber to the map
|
|
99
|
-
*/
|
|
100
|
-
addSubscriber(source) {
|
|
101
|
-
this.#subscribers.add(source);
|
|
102
|
-
this.resync(source);
|
|
103
|
-
}
|
|
104
|
-
removeSubscriber(sub) {
|
|
105
|
-
return this.#subscribers.delete(sub);
|
|
106
|
-
}
|
|
107
|
-
hasSubscriber(sub) {
|
|
108
|
-
return this.#subscribers.has(sub);
|
|
109
|
-
}
|
|
110
|
-
subscriberCount() {
|
|
111
|
-
return this.#subscribers.size;
|
|
112
|
-
}
|
|
113
|
-
handleSync(data) {
|
|
114
|
-
for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
|
|
115
|
-
switch (change_type) {
|
|
116
|
-
case MapChangeType.Add: {
|
|
117
|
-
this.set(key, value);
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
case MapChangeType.Remove: {
|
|
121
|
-
super.delete(key);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
case MapChangeType.Reset: {
|
|
125
|
-
super.clear();
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
case MapChangeType.Init: {
|
|
129
|
-
// We also use this for whenever we want to resync a table
|
|
130
|
-
super.clear();
|
|
131
|
-
const key_value = key;
|
|
132
|
-
for (const [k, v] of key_value) {
|
|
133
|
-
this.set(k, v);
|
|
134
|
-
}
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
case MapChangeType.SubValueChanged: {
|
|
138
|
-
const data = this.get(key);
|
|
139
|
-
// @ts-ignore
|
|
140
|
-
data[value] = possibly_undefined_subvalue;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/*
|
|
147
|
-
* Listens for the change on the specified key, it will get the resulting
|
|
148
|
-
* value on the change
|
|
149
|
-
*/
|
|
150
|
-
listenForChange(key, fn) {
|
|
151
|
-
const listener = this.#changeListeners.get(key);
|
|
152
|
-
listener ? listener.push(fn) : this.#changeListeners.set(key, [fn]);
|
|
153
|
-
}
|
|
154
|
-
#triggerEventForSubscribers(data) {
|
|
155
|
-
const packed_data = msgpack_pack([this.#syncName, data]);
|
|
156
|
-
for (const sub of this.#subscribers) {
|
|
157
|
-
TriggerClientEventInternal(`${GlobalData.CurrentResource}:syncChanges`, sub, packed_data, packed_data.length);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
#pushChangeForListener(key, value) {
|
|
161
|
-
const listener = this.#changeListeners.get(key);
|
|
162
|
-
if (!listener)
|
|
163
|
-
return;
|
|
164
|
-
for (const ln of listener) {
|
|
165
|
-
ln(value);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
set(key, value) {
|
|
169
|
-
let v = value;
|
|
170
|
-
// if we're an object
|
|
171
|
-
if (value instanceof Object) {
|
|
172
|
-
// define `this` so we can use it in the internal scope without breaking
|
|
173
|
-
// any rules
|
|
174
|
-
const curMap = this;
|
|
175
|
-
// apply a proxy around any changes so if the fields
|
|
176
|
-
const objectChangeHandler = {
|
|
177
|
-
get(target, prop, reciever) {
|
|
178
|
-
return Reflect.get(target, prop, reciever);
|
|
179
|
-
},
|
|
180
|
-
set(target, p, newValue, receiver) {
|
|
181
|
-
const success = Reflect.set(target, p, newValue, receiver);
|
|
182
|
-
if (success) {
|
|
183
|
-
curMap.#pushChangeForListener(key, target);
|
|
184
|
-
SERVER: {
|
|
185
|
-
curMap.#queuedChanges.push([
|
|
186
|
-
MapChangeType.SubValueChanged,
|
|
187
|
-
key,
|
|
188
|
-
p,
|
|
189
|
-
newValue,
|
|
190
|
-
]);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return success;
|
|
194
|
-
},
|
|
195
|
-
};
|
|
196
|
-
v = new Proxy(v, objectChangeHandler);
|
|
197
|
-
}
|
|
198
|
-
super.set(key, v);
|
|
199
|
-
this.#pushChangeForListener(key, v);
|
|
200
|
-
SERVER: {
|
|
201
|
-
this.#queuedChanges.push([MapChangeType.Add, key, v]);
|
|
202
|
-
}
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
/*
|
|
206
|
-
* Resets the map to its default state
|
|
207
|
-
*/
|
|
208
|
-
clear() {
|
|
209
|
-
CLIENT: throw new Error(`Cannot call 'clear' on client`);
|
|
210
|
-
// if we're clearing our map then we want to remove all queued changes and
|
|
211
|
-
// just push a reset
|
|
212
|
-
this.#queuedChanges = [];
|
|
213
|
-
this.#queuedChanges.push([MapChangeType.Reset]);
|
|
214
|
-
super.clear();
|
|
215
|
-
}
|
|
216
|
-
delete(key) {
|
|
217
|
-
CLIENT: throw new Error(`Cannot call 'delete' on client`);
|
|
218
|
-
this.#queuedChanges.push([MapChangeType.Remove, key]);
|
|
219
|
-
return super.delete(key);
|
|
220
|
-
}
|
|
221
|
-
networkTick() {
|
|
222
|
-
if (this.#queuedChanges.length !== 0) {
|
|
223
|
-
this.#triggerEventForSubscribers(this.#queuedChanges);
|
|
224
|
-
this.#queuedChanges = [];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
[Symbol.dispose]() {
|
|
228
|
-
this.#subscribers.clear();
|
|
229
|
-
this.#changeListeners.clear();
|
|
230
|
-
this.#queuedChanges = [];
|
|
231
|
-
netManager.removeNetworkedMap(this.#syncName);
|
|
232
|
-
GlobalData.NetworkedTicks.filter((v) => v !== this);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Unregisters from the tick handler and removes the event listener
|
|
236
|
-
*/
|
|
237
|
-
dispose() {
|
|
238
|
-
this[Symbol.dispose]();
|
|
239
|
-
}
|
|
240
|
-
get [Symbol.toStringTag]() {
|
|
241
|
-
return "NetworkedMap";
|
|
242
|
-
}
|
|
243
|
-
}
|
package/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/utils/ClassTypes.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export var ClassTypes;
|
|
2
|
-
(function (ClassTypes) {
|
|
3
|
-
ClassTypes[ClassTypes["Ped"] = 0] = "Ped";
|
|
4
|
-
ClassTypes[ClassTypes["Prop"] = 1] = "Prop";
|
|
5
|
-
ClassTypes[ClassTypes["Vehicle"] = 2] = "Vehicle";
|
|
6
|
-
ClassTypes[ClassTypes["Entity"] = 3] = "Entity";
|
|
7
|
-
ClassTypes[ClassTypes["Player"] = 4] = "Player";
|
|
8
|
-
ClassTypes[ClassTypes["Vector2"] = 5] = "Vector2";
|
|
9
|
-
ClassTypes[ClassTypes["Vector3"] = 6] = "Vector3";
|
|
10
|
-
ClassTypes[ClassTypes["Vector4"] = 7] = "Vector4";
|
|
11
|
-
ClassTypes[ClassTypes["Quanterion"] = 8] = "Quanterion";
|
|
12
|
-
})(ClassTypes || (ClassTypes = {}));
|
package/utils/Color.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export class Color {
|
|
2
|
-
static Transparent = new Color(0, 0, 0, 0);
|
|
3
|
-
static Black = new Color(0, 0, 0);
|
|
4
|
-
static White = new Color(255, 255, 255);
|
|
5
|
-
static WhiteSmoke = new Color(245, 245, 245);
|
|
6
|
-
static fromArgb(a, r, g, b) {
|
|
7
|
-
return new Color(r, g, b, a);
|
|
8
|
-
}
|
|
9
|
-
static fromRgb(r, g, b) {
|
|
10
|
-
return new Color(r, g, b);
|
|
11
|
-
}
|
|
12
|
-
static fromArray(primitive) {
|
|
13
|
-
return new Color(primitive[0], primitive[1], primitive[2], 255);
|
|
14
|
-
}
|
|
15
|
-
a;
|
|
16
|
-
r;
|
|
17
|
-
g;
|
|
18
|
-
b;
|
|
19
|
-
constructor(r, g, b, a = 255) {
|
|
20
|
-
this.r = r;
|
|
21
|
-
this.g = g;
|
|
22
|
-
this.b = b;
|
|
23
|
-
this.a = a;
|
|
24
|
-
}
|
|
25
|
-
}
|
package/utils/Maths.js
DELETED
package/utils/PointF.js
DELETED
package/utils/Quaternion.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from "./Vector3";
|
|
2
|
-
export class Quaternion {
|
|
3
|
-
x;
|
|
4
|
-
y;
|
|
5
|
-
z;
|
|
6
|
-
w;
|
|
7
|
-
constructor(valueXOrVector, yOrW, z, w) {
|
|
8
|
-
if (valueXOrVector instanceof Vector3) {
|
|
9
|
-
this.x = valueXOrVector.x;
|
|
10
|
-
this.y = valueXOrVector.y;
|
|
11
|
-
this.z = valueXOrVector.z;
|
|
12
|
-
this.w = yOrW ?? 0;
|
|
13
|
-
}
|
|
14
|
-
else if (yOrW === undefined) {
|
|
15
|
-
this.x = valueXOrVector;
|
|
16
|
-
this.y = valueXOrVector;
|
|
17
|
-
this.z = valueXOrVector;
|
|
18
|
-
this.w = valueXOrVector;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
this.x = valueXOrVector;
|
|
22
|
-
this.y = yOrW;
|
|
23
|
-
this.z = z ?? 0;
|
|
24
|
-
this.w = w ?? 0;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|