@nativewrappers/common-game 0.0.122 → 0.0.124
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 +6 -5
- package/CommonTasks.js +4 -3
- package/entities/CommonBaseEntity.d.ts +62 -14
- package/entities/CommonBaseEntity.js +88 -36
- package/entities/CommonBaseEntityBone.d.ts +6 -6
- package/entities/CommonBaseEntityBone.js +7 -7
- package/entities/CommonBaseEntityBoneCollection.d.ts +3 -3
- package/entities/CommonEntityBone.d.ts +2 -2
- package/entities/CommonEntityBoneCollection.d.ts +2 -2
- package/entities/CommonPed.d.ts +1 -2
- package/entities/CommonPed.js +1 -4
- package/entities/CommonPedBone.d.ts +2 -2
- package/entities/CommonPedBoneCollection.d.ts +2 -2
- package/entities/CommonPlayer.js +1 -1
- package/entities/CommonProp.d.ts +1 -2
- package/entities/CommonProp.js +1 -4
- package/entities/CommonVehicle.d.ts +1 -2
- package/entities/CommonVehicle.js +1 -4
- package/entities/IHandle.d.ts +6 -0
- package/entities/IHandle.js +20 -0
- package/index.d.ts +1 -21
- package/index.js +1 -21
- package/interfaces/Dimension.d.ts +1 -1
- package/package.json +1 -1
- package/utils/Animations.js +1 -1
- package/common/Command.d.ts +0 -77
- package/common/Command.js +0 -152
- package/common/Convar.d.ts +0 -13
- package/common/Convar.js +0 -58
- package/common/GlobalData.d.ts +0 -12
- package/common/GlobalData.js +0 -20
- package/common/Kvp.d.ts +0 -69
- package/common/Kvp.js +0 -137
- package/common/Resource.d.ts +0 -14
- package/common/Resource.js +0 -54
- package/common/decors/Events.d.ts +0 -65
- package/common/decors/Events.js +0 -208
- package/common/net/NetworkedMap.d.ts +0 -28
- package/common/net/NetworkedMap.js +0 -225
- package/common/types.d.ts +0 -5
- package/common/types.js +0 -0
- package/common/utils/ClassTypes.d.ts +0 -11
- package/common/utils/ClassTypes.js +0 -15
- package/common/utils/Color.d.ts +0 -14
- package/common/utils/Color.js +0 -33
- package/common/utils/Delay.d.ts +0 -1
- package/common/utils/Delay.js +0 -6
- package/common/utils/Maths.d.ts +0 -4
- package/common/utils/Maths.js +0 -18
- package/common/utils/Point.d.ts +0 -9
- package/common/utils/Point.js +0 -36
- package/common/utils/PointF.d.ts +0 -7
- package/common/utils/PointF.js +0 -18
- package/common/utils/Quaternion.d.ts +0 -10
- package/common/utils/Quaternion.js +0 -33
- package/common/utils/Vector.d.ts +0 -429
- package/common/utils/Vector.js +0 -589
- package/common/utils/cleanPlayerName.d.ts +0 -6
- package/common/utils/cleanPlayerName.js +0 -17
- package/common/utils/enumValues.d.ts +0 -12
- package/common/utils/enumValues.js +0 -20
- package/common/utils/getStringFromUInt8Array.d.ts +0 -8
- package/common/utils/getStringFromUInt8Array.js +0 -6
- package/common/utils/getUInt32FromUint8Array.d.ts +0 -8
- package/common/utils/getUInt32FromUint8Array.js +0 -6
- package/common/utils/randomInt.d.ts +0 -1
- package/common/utils/randomInt.js +0 -9
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export declare enum ConVarType {
|
|
2
|
-
String = 0,
|
|
3
|
-
Integer = 1,
|
|
4
|
-
Float = 2,
|
|
5
|
-
Boolean = 3
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Disables pretty printing in error messages
|
|
9
|
-
*/
|
|
10
|
-
export declare const DisablePrettyPrint: () => boolean;
|
|
11
|
-
export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
12
|
-
/**
|
|
13
|
-
* Registers the Event call for {@link eventName} to this method.
|
|
14
|
-
*
|
|
15
|
-
* This has internal pretty-printing to make errors easier to track, if
|
|
16
|
-
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
17
|
-
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
18
|
-
*
|
|
19
|
-
* @param eventName the event to bind to
|
|
20
|
-
*/
|
|
21
|
-
export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
22
|
-
/**
|
|
23
|
-
* Registers the Event call for {@link eventName} to this method.
|
|
24
|
-
*
|
|
25
|
-
* This has internal pretty-printing to make errors easier to track, if
|
|
26
|
-
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
27
|
-
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
28
|
-
*
|
|
29
|
-
* This is the same thing as just using `Event` but this disambiguates the call from DOM
|
|
30
|
-
* @param eventName the event to bind to
|
|
31
|
-
*/
|
|
32
|
-
export declare const CfxEvent: typeof Event;
|
|
33
|
-
/**
|
|
34
|
-
* Registers the Net Event call for {@link eventName} to this method
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* This has internal pretty-printing to make errors easier to track, if
|
|
38
|
-
* you want to disable this you will need to call {@link DisablePrettyPrint}, or if you're
|
|
39
|
-
* using esbuild you can add `REMOVE_EVENT_LOG` to your drop label {@link https://esbuild.github.io/api/#drop-labels}
|
|
40
|
-
*
|
|
41
|
-
* @param eventName the event to bind this net event to
|
|
42
|
-
* @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
|
|
43
|
-
*/
|
|
44
|
-
export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Registers the NUI Event call for {eventName} to this method, the function signature
|
|
47
|
-
* should be (data: unknown, cb: (data?: any) => void) => void
|
|
48
|
-
* You shoud always execute `cb` with 'ok' if you don't want to send data back to
|
|
49
|
-
* the UI, otherwise you'll cause a network error for the `fetch` request
|
|
50
|
-
* @param eventName the event this will listen for
|
|
51
|
-
*/
|
|
52
|
-
export declare function NuiEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
53
|
-
type DeserializeFn<T> = (data: T) => unknown;
|
|
54
|
-
/**
|
|
55
|
-
* Gets the specified `ConVar`s value, this will bind to the param.
|
|
56
|
-
* @param name the convar name
|
|
57
|
-
* @param is_floating_point if the convar is floating point, this should be explicitly set to true if your convar will be a float
|
|
58
|
-
*/
|
|
59
|
-
export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ..._args: any[]) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Gets called per server/client tick, this is asyncronous though, if you await
|
|
62
|
-
* in it, it will not be called until whatever was being awaited resolves.
|
|
63
|
-
*/
|
|
64
|
-
export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
65
|
-
export {};
|
package/common/decors/Events.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
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
|
-
const AsyncFunction = (async () => {
|
|
13
|
-
}).constructor;
|
|
14
|
-
function Exports(exportName) {
|
|
15
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
16
|
-
if (context.private) {
|
|
17
|
-
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
18
|
-
}
|
|
19
|
-
context.addInitializer(function() {
|
|
20
|
-
let exportCb;
|
|
21
|
-
if (originalMethod instanceof AsyncFunction) {
|
|
22
|
-
exportCb = /* @__PURE__ */ __name(async (...args) => {
|
|
23
|
-
try {
|
|
24
|
-
return await originalMethod.call(this, ...args);
|
|
25
|
-
} catch (err) {
|
|
26
|
-
REMOVE_EVENT_LOG: {
|
|
27
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
28
|
-
console.error("------- EXPORT ERROR --------");
|
|
29
|
-
console.error(`Call to ${exportName} errored`);
|
|
30
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
31
|
-
console.error(`Error: ${err}`);
|
|
32
|
-
console.error("------- END EXPORT ERROR --------");
|
|
33
|
-
}
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}, "exportCb");
|
|
37
|
-
} else {
|
|
38
|
-
exportCb = /* @__PURE__ */ __name((...args) => {
|
|
39
|
-
try {
|
|
40
|
-
return originalMethod.call(this, ...args);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
REMOVE_EVENT_LOG: {
|
|
43
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
44
|
-
console.error("------- EXPORT ERROR --------");
|
|
45
|
-
console.error(`Call to ${exportName} errored`);
|
|
46
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
47
|
-
console.error(`Error: ${err}`);
|
|
48
|
-
console.error("------- END EXPORT ERROR --------");
|
|
49
|
-
}
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
}, "exportCb");
|
|
53
|
-
}
|
|
54
|
-
exports(exportName, exportCb);
|
|
55
|
-
});
|
|
56
|
-
}, "actualDecorator");
|
|
57
|
-
}
|
|
58
|
-
__name(Exports, "Exports");
|
|
59
|
-
function Event(eventName) {
|
|
60
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
61
|
-
if (context.private) {
|
|
62
|
-
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
63
|
-
}
|
|
64
|
-
context.addInitializer(function() {
|
|
65
|
-
on(eventName, async (...args) => {
|
|
66
|
-
try {
|
|
67
|
-
return await originalMethod.call(this, ...args);
|
|
68
|
-
} catch (e) {
|
|
69
|
-
REMOVE_EVENT_LOG: {
|
|
70
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
71
|
-
console.error("------- EVENT ERROR --------");
|
|
72
|
-
console.error(`Call to ${eventName} errored`);
|
|
73
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
74
|
-
console.error(`Error: ${e}`);
|
|
75
|
-
console.error("------- END EVENT ERROR --------");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}, "actualDecorator");
|
|
81
|
-
}
|
|
82
|
-
__name(Event, "Event");
|
|
83
|
-
const CfxEvent = Event;
|
|
84
|
-
function NetEvent(eventName, remoteOnly = true) {
|
|
85
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
86
|
-
if (context.private) {
|
|
87
|
-
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
88
|
-
}
|
|
89
|
-
context.addInitializer(function() {
|
|
90
|
-
onNet(eventName, async (...args) => {
|
|
91
|
-
const src = source;
|
|
92
|
-
try {
|
|
93
|
-
$CLIENT: {
|
|
94
|
-
if (GlobalData.IS_CLIENT && remoteOnly && source !== 65535) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return await originalMethod.call(this, ...args);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
REMOVE_NET_EVENT_LOG: {
|
|
101
|
-
if (!GlobalData.EnablePrettyPrint) return;
|
|
102
|
-
console.error("------- NET EVENT ERROR --------");
|
|
103
|
-
console.error(`Call to ${eventName} errored`);
|
|
104
|
-
console.error(`Caller: ${src}`);
|
|
105
|
-
console.error(`Data: ${JSON.stringify(args)}`);
|
|
106
|
-
console.error(`Error: ${e}`);
|
|
107
|
-
console.error("------- END NET EVENT ERROR --------");
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}, "actualDecorator");
|
|
113
|
-
}
|
|
114
|
-
__name(NetEvent, "NetEvent");
|
|
115
|
-
function NuiEvent(eventName) {
|
|
116
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
117
|
-
if (context.private) {
|
|
118
|
-
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
119
|
-
}
|
|
120
|
-
context.addInitializer(function() {
|
|
121
|
-
RegisterNuiCallback(eventName, (...args) => {
|
|
122
|
-
return originalMethod.call(this, ...args);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
}, "actualDecorator");
|
|
126
|
-
}
|
|
127
|
-
__name(NuiEvent, "NuiEvent");
|
|
128
|
-
const get_convar_fn = /* @__PURE__ */ __name((con_var_type) => {
|
|
129
|
-
switch (con_var_type) {
|
|
130
|
-
case 0 /* String */:
|
|
131
|
-
return GetConvar;
|
|
132
|
-
case 1 /* Integer */:
|
|
133
|
-
return GetConvarInt;
|
|
134
|
-
case 2 /* Float */:
|
|
135
|
-
return GetConvarFloat;
|
|
136
|
-
case 3 /* Boolean */:
|
|
137
|
-
return GetConvarBool;
|
|
138
|
-
// needed so typescript wont complain about "unreachable code" for the error below
|
|
139
|
-
default:
|
|
140
|
-
}
|
|
141
|
-
throw new Error("Got invalid ConVarType");
|
|
142
|
-
}, "get_convar_fn");
|
|
143
|
-
function ConVar(name, is_floating_point, deserialize) {
|
|
144
|
-
return /* @__PURE__ */ __name(function actualDecorator(_initialValue, context, ..._args) {
|
|
145
|
-
if (context.private) {
|
|
146
|
-
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
147
|
-
}
|
|
148
|
-
context.addInitializer(function() {
|
|
149
|
-
const t = this;
|
|
150
|
-
const default_value = Reflect.get(t, context.name);
|
|
151
|
-
const default_type = typeof default_value;
|
|
152
|
-
let con_var_type = null;
|
|
153
|
-
if (default_type === "number") {
|
|
154
|
-
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
155
|
-
con_var_type = 2 /* Float */;
|
|
156
|
-
} else {
|
|
157
|
-
con_var_type = 1 /* Integer */;
|
|
158
|
-
}
|
|
159
|
-
} else if (default_type === "boolean") {
|
|
160
|
-
con_var_type = 3 /* Boolean */;
|
|
161
|
-
} else if (default_type === "string") {
|
|
162
|
-
con_var_type = 0 /* String */;
|
|
163
|
-
}
|
|
164
|
-
if (!deserialize && con_var_type === null) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`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.`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
if (con_var_type === null) {
|
|
170
|
-
con_var_type = 0 /* String */;
|
|
171
|
-
}
|
|
172
|
-
const con_var_fn = get_convar_fn(con_var_type);
|
|
173
|
-
const get_convar_value = /* @__PURE__ */ __name(() => {
|
|
174
|
-
const data = con_var_fn(name, default_value);
|
|
175
|
-
return deserialize ? deserialize(data) : data;
|
|
176
|
-
}, "get_convar_value");
|
|
177
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
178
|
-
AddConvarChangeListener(name, () => {
|
|
179
|
-
Reflect.set(t, context.name, get_convar_value());
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}, "actualDecorator");
|
|
183
|
-
}
|
|
184
|
-
__name(ConVar, "ConVar");
|
|
185
|
-
function SetTick() {
|
|
186
|
-
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
187
|
-
if (context.private) {
|
|
188
|
-
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
189
|
-
}
|
|
190
|
-
context.addInitializer(function() {
|
|
191
|
-
setTick(async () => {
|
|
192
|
-
await originalMethod.call(this);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}, "actualDecorator");
|
|
196
|
-
}
|
|
197
|
-
__name(SetTick, "SetTick");
|
|
198
|
-
export {
|
|
199
|
-
CfxEvent,
|
|
200
|
-
ConVar,
|
|
201
|
-
ConVarType,
|
|
202
|
-
DisablePrettyPrint,
|
|
203
|
-
Event,
|
|
204
|
-
Exports,
|
|
205
|
-
NetEvent,
|
|
206
|
-
NuiEvent,
|
|
207
|
-
SetTick
|
|
208
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
type ChangeListener<V> = (value: V) => void;
|
|
2
|
-
/**
|
|
3
|
-
* not ready to be used just thoughts right now
|
|
4
|
-
*/
|
|
5
|
-
export declare class NetworkedMap<K, V> extends Map<K, V> {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(syncName: string, initialValue?: [K, V][]);
|
|
8
|
-
get SyncName(): string;
|
|
9
|
-
private onPlayerDropped;
|
|
10
|
-
resync(source: number): void;
|
|
11
|
-
addSubscriber(source: number): void;
|
|
12
|
-
removeSubscriber(sub: number): boolean;
|
|
13
|
-
hasSubscriber(sub: number): boolean;
|
|
14
|
-
subscriberCount(): number;
|
|
15
|
-
private handleSync;
|
|
16
|
-
listenForChange(key: K, fn: ChangeListener<V>): void;
|
|
17
|
-
set(key: K, value: V): this;
|
|
18
|
-
clear(): void;
|
|
19
|
-
delete(key: K): boolean;
|
|
20
|
-
networkTick(): void;
|
|
21
|
-
[Symbol.dispose](): void;
|
|
22
|
-
/**
|
|
23
|
-
* Unregisters from the tick handler and removes the event listener
|
|
24
|
-
*/
|
|
25
|
-
dispose(): void;
|
|
26
|
-
get [Symbol.toStringTag](): string;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
@@ -1,225 +0,0 @@
|
|
|
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.d.ts
DELETED
package/common/types.js
DELETED
|
File without changes
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
};
|
package/common/utils/Color.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
package/common/utils/Color.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
};
|
package/common/utils/Delay.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const Delay: (ms: number) => Promise<void>;
|
package/common/utils/Delay.js
DELETED
package/common/utils/Maths.d.ts
DELETED
package/common/utils/Maths.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
};
|