@nativewrappers/common-game 0.0.114
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/CommonGameConstants.d.ts +7 -0
- package/CommonGameConstants.js +24 -0
- package/CommonModel.d.ts +99 -0
- package/CommonModel.js +172 -0
- package/CommonTasks.d.ts +43 -0
- package/CommonTasks.js +232 -0
- package/README.md +45 -0
- package/cfx/StateBagChangeHandler.d.ts +1 -0
- package/cfx/StateBagChangeHandler.js +0 -0
- package/cfx/cfx.d.ts +6 -0
- package/cfx/cfx.js +4 -0
- 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 +10 -0
- package/common/GlobalData.js +18 -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/Events.d.ts +65 -0
- package/common/decors/Events.js +208 -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/definitions/index.d.js +0 -0
- package/definitions/redm.d.js +0 -0
- package/entities/CommonBaseEntity.d.ts +66 -0
- package/entities/CommonBaseEntity.js +180 -0
- package/entities/CommonBaseEntityBone.d.ts +11 -0
- package/entities/CommonBaseEntityBone.js +32 -0
- package/entities/CommonBaseEntityBoneCollection.d.ts +9 -0
- package/entities/CommonBaseEntityBoneCollection.js +17 -0
- package/entities/CommonEntityBone.d.ts +5 -0
- package/entities/CommonEntityBone.js +14 -0
- package/entities/CommonEntityBoneCollection.d.ts +9 -0
- package/entities/CommonEntityBoneCollection.js +24 -0
- package/entities/CommonEntityType.d.ts +4 -0
- package/entities/CommonEntityType.js +3 -0
- package/entities/CommonPed.d.ts +17 -0
- package/entities/CommonPed.js +55 -0
- package/entities/CommonPedBone.d.ts +6 -0
- package/entities/CommonPedBone.js +17 -0
- package/entities/CommonPedBoneCollection.d.ts +10 -0
- package/entities/CommonPedBoneCollection.js +31 -0
- package/entities/CommonPlayer.d.ts +61 -0
- package/entities/CommonPlayer.js +156 -0
- package/entities/CommonProp.d.ts +16 -0
- package/entities/CommonProp.js +46 -0
- package/entities/CommonVehicle.d.ts +12 -0
- package/entities/CommonVehicle.js +39 -0
- package/entities/GetEntityClassIdFromHandle.d.ts +2 -0
- package/entities/GetEntityClassIdFromHandle.js +23 -0
- package/enums/VehicleSeat.d.ts +13 -0
- package/enums/VehicleSeat.js +17 -0
- package/index.d.ts +44 -0
- package/index.js +44 -0
- package/interfaces/Dimension.d.ts +5 -0
- package/interfaces/Dimension.js +0 -0
- package/package.json +36 -0
- package/utils/Animations.d.ts +19 -0
- package/utils/Animations.js +43 -0
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 {};
|
|
@@ -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
|
+
};
|