@nativewrappers/common 0.0.44
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/Convar.d.ts +13 -0
- package/Convar.js +50 -0
- package/GlobalData.d.ts +6 -0
- package/GlobalData.js +6 -0
- package/Kvp.d.ts +91 -0
- package/Kvp.js +161 -0
- package/Resource.d.ts +14 -0
- package/Resource.js +47 -0
- package/decors/Events.d.ts +14 -0
- package/decors/Events.js +167 -0
- package/index.d.ts +7 -0
- package/index.js +7 -0
- package/net/NetworkedMap.d.ts +23 -0
- package/net/NetworkedMap.js +182 -0
- package/package.json +30 -0
- package/types.d.ts +5 -0
- package/types.js +1 -0
- package/utils/ClassTypes.d.ts +11 -0
- package/utils/ClassTypes.js +12 -0
- package/utils/Color.d.ts +14 -0
- package/utils/Color.js +25 -0
- package/utils/Maths.d.ts +4 -0
- package/utils/Maths.js +10 -0
- package/utils/PointF.d.ts +12 -0
- package/utils/PointF.js +14 -0
- package/utils/Quaternion.d.ts +10 -0
- package/utils/Quaternion.js +27 -0
- package/utils/Vector.d.ts +390 -0
- package/utils/Vector.js +559 -0
- package/utils/Vector2.d.ts +1 -0
- package/utils/Vector2.js +1 -0
- package/utils/Vector3.d.ts +1 -0
- package/utils/Vector3.js +1 -0
- package/utils/Vector4.d.ts +1 -0
- package/utils/Vector4.js +1 -0
- package/utils/cleanPlayerName.d.ts +6 -0
- package/utils/cleanPlayerName.js +27 -0
- package/utils/enumValues.d.ts +12 -0
- package/utils/enumValues.js +14 -0
- package/utils/getStringFromUInt8Array.d.ts +8 -0
- package/utils/getStringFromUInt8Array.js +10 -0
- package/utils/getUInt32FromUint8Array.d.ts +8 -0
- package/utils/getUInt32FromUint8Array.js +8 -0
- package/utils/index.d.ts +12 -0
- package/utils/index.js +12 -0
package/Convar.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Convar {
|
|
2
|
+
/**
|
|
3
|
+
* @returns the current console buffer
|
|
4
|
+
*/
|
|
5
|
+
buffer(): string;
|
|
6
|
+
get(variable: string, defaultVar: string): string;
|
|
7
|
+
getInt(variable: string, defaultVar: number): number;
|
|
8
|
+
getFloat(varName: string, defaultVar: number): number;
|
|
9
|
+
getBool(varName: string, defaultVar: boolean): boolean;
|
|
10
|
+
set(variable: string, value: string): void;
|
|
11
|
+
setReplicated(variable: string, value: string): void;
|
|
12
|
+
setServerInfo(variable: string, value: string): void;
|
|
13
|
+
}
|
package/Convar.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GlobalData } from "./GlobalData";
|
|
2
|
+
export class Convar {
|
|
3
|
+
/**
|
|
4
|
+
* @returns the current console buffer
|
|
5
|
+
*/
|
|
6
|
+
buffer() {
|
|
7
|
+
CLIENT: {
|
|
8
|
+
if (GlobalData.IS_CLIENT) {
|
|
9
|
+
throw new Error("This function isn't available on the client");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return GetConsoleBuffer();
|
|
13
|
+
}
|
|
14
|
+
get(variable, defaultVar) {
|
|
15
|
+
return GetConvar(variable, defaultVar);
|
|
16
|
+
}
|
|
17
|
+
getInt(variable, defaultVar) {
|
|
18
|
+
return GetConvarInt(variable, defaultVar);
|
|
19
|
+
}
|
|
20
|
+
getFloat(varName, defaultVar) {
|
|
21
|
+
return GetConvarFloat(varName, defaultVar);
|
|
22
|
+
}
|
|
23
|
+
getBool(varName, defaultVar) {
|
|
24
|
+
return GetConvarBool(varName, defaultVar);
|
|
25
|
+
}
|
|
26
|
+
set(variable, value) {
|
|
27
|
+
CLIENT: {
|
|
28
|
+
if (GlobalData.IS_CLIENT) {
|
|
29
|
+
throw new Error("This function isn't available on the client");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
SetConvar(variable, value);
|
|
33
|
+
}
|
|
34
|
+
setReplicated(variable, value) {
|
|
35
|
+
CLIENT: {
|
|
36
|
+
if (GlobalData.IS_CLIENT) {
|
|
37
|
+
throw new Error("This function isn't available on the client");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
SetConvarReplicated(variable, value);
|
|
41
|
+
}
|
|
42
|
+
setServerInfo(variable, value) {
|
|
43
|
+
CLIENT: {
|
|
44
|
+
if (GlobalData.IS_CLIENT) {
|
|
45
|
+
throw new Error("This function isn't available on the client");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
SetConvarServerInfo(variable, value);
|
|
49
|
+
}
|
|
50
|
+
}
|
package/GlobalData.d.ts
ADDED
package/GlobalData.js
ADDED
package/Kvp.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export declare class Kvp {
|
|
2
|
+
/**
|
|
3
|
+
* Sets the resource key to the specified value this is a blocking operation, if you're doing large write operations you should use [[setKvpAsync]] instead.
|
|
4
|
+
* @param key the key string
|
|
5
|
+
* @param value the value to set the key to
|
|
6
|
+
*/
|
|
7
|
+
setKvp<T = number | string>(key: string, value: T): void;
|
|
8
|
+
/**
|
|
9
|
+
* Sets the resource key to the specified value, this doesn't immediately write to disk and needs [[flush]] called afterwards.
|
|
10
|
+
* @param key the key string
|
|
11
|
+
* @param value the value to set the key to
|
|
12
|
+
*/
|
|
13
|
+
setKvpAsync<T = number | string>(key: string, value: T): void;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the specified key to the specified json value
|
|
16
|
+
* This can error if given an invalid object
|
|
17
|
+
* @param key the key string
|
|
18
|
+
* @param value the value to set the key to
|
|
19
|
+
*/
|
|
20
|
+
setKvpJson(key: string, value: any): void;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the specified value for key
|
|
23
|
+
* @param key the key of the value to get
|
|
24
|
+
* @returns a string, or null if there is no value
|
|
25
|
+
*/
|
|
26
|
+
getKvpString(key: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the specified value for key
|
|
29
|
+
* @param key the key of the value to get
|
|
30
|
+
* @returns the value stored, as a number, or 0 if there is no value
|
|
31
|
+
*/
|
|
32
|
+
getKvpNumber(key: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the specified value for key
|
|
35
|
+
* @param key the key of the value to get
|
|
36
|
+
* @returns the value stored as a float, or 0.0 if there is no value
|
|
37
|
+
*/
|
|
38
|
+
getKvpFloat(key: string): number;
|
|
39
|
+
getKvpJson<T>(key: string): T;
|
|
40
|
+
/**
|
|
41
|
+
* Deletes the specified value for key, this is a blocking operation, if you're deleting a bunch of keys you should use [[deleteAsync]]
|
|
42
|
+
* @param key the key of the value to delete
|
|
43
|
+
*/
|
|
44
|
+
delete(key: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Deletes the specified resource keys value, this doesn't immediately write to disk and needs [[flush]] called afterwards.
|
|
47
|
+
* @param key the key to delete
|
|
48
|
+
*/
|
|
49
|
+
deleteAsync(key: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Ensures that any previous async call is flushed to disk
|
|
52
|
+
*/
|
|
53
|
+
flush(): void;
|
|
54
|
+
private handleKvp;
|
|
55
|
+
/**
|
|
56
|
+
* enumerates over any kvp prefixed with the prefix
|
|
57
|
+
*
|
|
58
|
+
* ```typescript
|
|
59
|
+
* for (const value of Kvp.getKvpsAsString("native:")) {
|
|
60
|
+
* console.log(value);
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param prefix the prefix to search for
|
|
65
|
+
*/
|
|
66
|
+
getKvpsAsString(prefix: string): IterableIterator<string>;
|
|
67
|
+
/**
|
|
68
|
+
* enumerates over any kvp prefixed with the prefix
|
|
69
|
+
*
|
|
70
|
+
* ```typescript
|
|
71
|
+
* for (const value of Kvp.getKvpsAsNumber("native:")) {
|
|
72
|
+
* console.log(value);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param prefix the prefix to search for
|
|
77
|
+
*/
|
|
78
|
+
getKvpsAsNumber(prefix: string): IterableIterator<number>;
|
|
79
|
+
/**
|
|
80
|
+
* enumerates over any kvp prefixed with the prefix
|
|
81
|
+
*
|
|
82
|
+
* ```typescript
|
|
83
|
+
* for (const value of Kvp.getKvpsAsFloat("native:")) {
|
|
84
|
+
* console.log(value);
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param prefix the prefix to search for
|
|
89
|
+
*/
|
|
90
|
+
getKvpsAsFloat(prefix: string): IterableIterator<number>;
|
|
91
|
+
}
|
package/Kvp.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
export class Kvp {
|
|
3
|
+
// TODO: Find a way to do this without casting to any
|
|
4
|
+
/**
|
|
5
|
+
* Sets the resource key to the specified value this is a blocking operation, if you're doing large write operations you should use [[setKvpAsync]] instead.
|
|
6
|
+
* @param key the key string
|
|
7
|
+
* @param value the value to set the key to
|
|
8
|
+
*/
|
|
9
|
+
setKvp(key, value) {
|
|
10
|
+
const type = typeof value;
|
|
11
|
+
if (type === "string") {
|
|
12
|
+
SetResourceKvp(key, value);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (Number.isInteger(value)) {
|
|
16
|
+
SetResourceKvpInt(key, value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
SetResourceKvpFloat(key, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sets the resource key to the specified value, this doesn't immediately write to disk and needs [[flush]] called afterwards.
|
|
25
|
+
* @param key the key string
|
|
26
|
+
* @param value the value to set the key to
|
|
27
|
+
*/
|
|
28
|
+
setKvpAsync(key, value) {
|
|
29
|
+
const type = typeof value;
|
|
30
|
+
if (type === "string") {
|
|
31
|
+
SetResourceKvpNoSync(key, value);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (Number.isInteger(value)) {
|
|
35
|
+
SetResourceKvpIntNoSync(key, value);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
SetResourceKvpFloatNoSync(key, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets the specified key to the specified json value
|
|
44
|
+
* This can error if given an invalid object
|
|
45
|
+
* @param key the key string
|
|
46
|
+
* @param value the value to set the key to
|
|
47
|
+
*/
|
|
48
|
+
setKvpJson(key, value) {
|
|
49
|
+
const stringified = JSON.stringify(value);
|
|
50
|
+
this.setKvp(key, stringified);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets the specified value for key
|
|
54
|
+
* @param key the key of the value to get
|
|
55
|
+
* @returns a string, or null if there is no value
|
|
56
|
+
*/
|
|
57
|
+
getKvpString(key) {
|
|
58
|
+
return GetResourceKvpString(key);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the specified value for key
|
|
62
|
+
* @param key the key of the value to get
|
|
63
|
+
* @returns the value stored, as a number, or 0 if there is no value
|
|
64
|
+
*/
|
|
65
|
+
getKvpNumber(key) {
|
|
66
|
+
return GetResourceKvpInt(key);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the specified value for key
|
|
70
|
+
* @param key the key of the value to get
|
|
71
|
+
* @returns the value stored as a float, or 0.0 if there is no value
|
|
72
|
+
*/
|
|
73
|
+
getKvpFloat(key) {
|
|
74
|
+
return GetResourceKvpFloat(key);
|
|
75
|
+
}
|
|
76
|
+
getKvpJson(key) {
|
|
77
|
+
const kvp = this.getKvpString(key);
|
|
78
|
+
return JSON.parse(kvp || "{}");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Deletes the specified value for key, this is a blocking operation, if you're deleting a bunch of keys you should use [[deleteAsync]]
|
|
82
|
+
* @param key the key of the value to delete
|
|
83
|
+
*/
|
|
84
|
+
delete(key) {
|
|
85
|
+
DeleteResourceKvp(key);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Deletes the specified resource keys value, this doesn't immediately write to disk and needs [[flush]] called afterwards.
|
|
89
|
+
* @param key the key to delete
|
|
90
|
+
*/
|
|
91
|
+
deleteAsync(key) {
|
|
92
|
+
DeleteResourceKvpNoSync(key);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Ensures that any previous async call is flushed to disk
|
|
96
|
+
*/
|
|
97
|
+
flush() {
|
|
98
|
+
FlushResourceKvp();
|
|
99
|
+
}
|
|
100
|
+
*handleKvp(prefix, iterType) {
|
|
101
|
+
const handle = StartFindKvp(prefix);
|
|
102
|
+
if (handle === -1)
|
|
103
|
+
return;
|
|
104
|
+
let key;
|
|
105
|
+
do {
|
|
106
|
+
key = FindKvp(handle);
|
|
107
|
+
if (iterType === "string") {
|
|
108
|
+
yield GetResourceKvpString(key);
|
|
109
|
+
}
|
|
110
|
+
else if (iterType === "number") {
|
|
111
|
+
yield GetResourceKvpInt(key);
|
|
112
|
+
}
|
|
113
|
+
else if (iterType === "float") {
|
|
114
|
+
yield GetResourceKvpFloat(key);
|
|
115
|
+
}
|
|
116
|
+
} while (key);
|
|
117
|
+
EndFindKvp(handle);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* enumerates over any kvp prefixed with the prefix
|
|
121
|
+
*
|
|
122
|
+
* ```typescript
|
|
123
|
+
* for (const value of Kvp.getKvpsAsString("native:")) {
|
|
124
|
+
* console.log(value);
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param prefix the prefix to search for
|
|
129
|
+
*/
|
|
130
|
+
getKvpsAsString(prefix) {
|
|
131
|
+
return this.handleKvp(prefix, "string");
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* enumerates over any kvp prefixed with the prefix
|
|
135
|
+
*
|
|
136
|
+
* ```typescript
|
|
137
|
+
* for (const value of Kvp.getKvpsAsNumber("native:")) {
|
|
138
|
+
* console.log(value);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param prefix the prefix to search for
|
|
143
|
+
*/
|
|
144
|
+
getKvpsAsNumber(prefix) {
|
|
145
|
+
return this.handleKvp(prefix, "number");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* enumerates over any kvp prefixed with the prefix
|
|
149
|
+
*
|
|
150
|
+
* ```typescript
|
|
151
|
+
* for (const value of Kvp.getKvpsAsFloat("native:")) {
|
|
152
|
+
* console.log(value);
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @param prefix the prefix to search for
|
|
157
|
+
*/
|
|
158
|
+
getKvpsAsFloat(prefix) {
|
|
159
|
+
return this.handleKvp(prefix, "float");
|
|
160
|
+
}
|
|
161
|
+
}
|
package/Resource.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class Resource {
|
|
2
|
+
name: string;
|
|
3
|
+
constructor(name: string);
|
|
4
|
+
getMetadata(metadataKey: string, index: number): string;
|
|
5
|
+
getPath(): string;
|
|
6
|
+
loadFile(fileName: string): string;
|
|
7
|
+
saveFile(fileName: string, data: string, length: number): boolean;
|
|
8
|
+
scheduleTick(): void;
|
|
9
|
+
start(): void;
|
|
10
|
+
stop(): void;
|
|
11
|
+
static startResource(name: string): void;
|
|
12
|
+
static stopResource(name: string): void;
|
|
13
|
+
static resourceCount(): number;
|
|
14
|
+
}
|
package/Resource.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GlobalData } from "./GlobalData";
|
|
2
|
+
export class Resource {
|
|
3
|
+
name;
|
|
4
|
+
constructor(name) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
getMetadata(metadataKey, index) {
|
|
8
|
+
return GetResourceMetadata(this.name, metadataKey, index);
|
|
9
|
+
}
|
|
10
|
+
getPath() {
|
|
11
|
+
return GetResourcePath(this.name);
|
|
12
|
+
}
|
|
13
|
+
loadFile(fileName) {
|
|
14
|
+
return LoadResourceFile(this.name, fileName);
|
|
15
|
+
}
|
|
16
|
+
saveFile(fileName, data, length) {
|
|
17
|
+
CLIENT: {
|
|
18
|
+
if (GlobalData.IS_CLIENT) {
|
|
19
|
+
throw new Error("This function isn't available on the client");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return SaveResourceFile(this.name, fileName, data, length);
|
|
23
|
+
}
|
|
24
|
+
scheduleTick() {
|
|
25
|
+
CLIENT: {
|
|
26
|
+
if (GlobalData.IS_CLIENT) {
|
|
27
|
+
throw new Error("This function isn't available on the client");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return ScheduleResourceTick(this.name);
|
|
31
|
+
}
|
|
32
|
+
start() {
|
|
33
|
+
StartResource(this.name);
|
|
34
|
+
}
|
|
35
|
+
stop() {
|
|
36
|
+
StopResource(this.name);
|
|
37
|
+
}
|
|
38
|
+
static startResource(name) {
|
|
39
|
+
StartResource(name);
|
|
40
|
+
}
|
|
41
|
+
static stopResource(name) {
|
|
42
|
+
StopResource(name);
|
|
43
|
+
}
|
|
44
|
+
static resourceCount() {
|
|
45
|
+
return GetNumResources();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum ConVarType {
|
|
2
|
+
String = 0,
|
|
3
|
+
Integer = 1,
|
|
4
|
+
Float = 2,
|
|
5
|
+
Boolean = 3
|
|
6
|
+
}
|
|
7
|
+
export declare function Exports(exportName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
8
|
+
export declare function Event(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
9
|
+
export declare function NetEvent(eventName: string, remoteOnly?: boolean): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
10
|
+
export declare function NuiEvent(eventName: string): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
11
|
+
type DeserializeFn<T> = (data: T) => unknown;
|
|
12
|
+
export declare function ConVar<T>(name: string, is_floating_point?: boolean, deserialize?: DeserializeFn<T>): (_initialValue: any, context: ClassFieldDecoratorContext, ...args: any[]) => void;
|
|
13
|
+
export declare function SetTick(): (originalMethod: any, context: ClassMethodDecoratorContext) => void;
|
|
14
|
+
export {};
|
package/decors/Events.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export var ConVarType;
|
|
2
|
+
(function (ConVarType) {
|
|
3
|
+
ConVarType[ConVarType["String"] = 0] = "String";
|
|
4
|
+
ConVarType[ConVarType["Integer"] = 1] = "Integer";
|
|
5
|
+
ConVarType[ConVarType["Float"] = 2] = "Float";
|
|
6
|
+
ConVarType[ConVarType["Boolean"] = 3] = "Boolean";
|
|
7
|
+
})(ConVarType || (ConVarType = {}));
|
|
8
|
+
// TODO: Have a way to clean all of this up (maybe hook Symbol.disposable
|
|
9
|
+
// somehow?)
|
|
10
|
+
/*
|
|
11
|
+
* Registers the export call for {exportName} to this method
|
|
12
|
+
*/
|
|
13
|
+
export function Exports(exportName) {
|
|
14
|
+
return function actualDecorator(originalMethod, context) {
|
|
15
|
+
if (context.private) {
|
|
16
|
+
throw new Error("Exports does not work on private methods, please mark the method as public");
|
|
17
|
+
}
|
|
18
|
+
context.addInitializer(function () {
|
|
19
|
+
const t = this;
|
|
20
|
+
exports(exportName, (...args) => {
|
|
21
|
+
return originalMethod.call(t, ...args);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/*
|
|
27
|
+
* Registers the Event call for {eventName} to this method
|
|
28
|
+
*/
|
|
29
|
+
export function Event(eventName) {
|
|
30
|
+
return function actualDecorator(originalMethod, context) {
|
|
31
|
+
if (context.private) {
|
|
32
|
+
throw new Error("Event does not work on private methods, please mark the method as public");
|
|
33
|
+
}
|
|
34
|
+
context.addInitializer(function () {
|
|
35
|
+
const t = this;
|
|
36
|
+
on(eventName, (...args) => {
|
|
37
|
+
return originalMethod.call(t, ...args);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/*
|
|
43
|
+
* Registers the Net Event call for {eventName} to this method
|
|
44
|
+
*/
|
|
45
|
+
export function NetEvent(eventName, remoteOnly = false) {
|
|
46
|
+
return function actualDecorator(originalMethod, context) {
|
|
47
|
+
if (context.private) {
|
|
48
|
+
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
49
|
+
}
|
|
50
|
+
context.addInitializer(function () {
|
|
51
|
+
const t = this;
|
|
52
|
+
onNet(eventName, (...args) => {
|
|
53
|
+
CLIENT: {
|
|
54
|
+
if (remoteOnly && source !== 65535) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return originalMethod.call(t, ...args);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/*
|
|
64
|
+
* Registers the NUI Event call for {eventName} to this method, the function signature
|
|
65
|
+
* should be (data: unknown, cb: (data?: any) => void) => void
|
|
66
|
+
* You shoud always execute `cb` with '' if you don't want to send data back to
|
|
67
|
+
* the UI, otherwise you'll cause a network error for the `fetch` request
|
|
68
|
+
*/
|
|
69
|
+
export function NuiEvent(eventName) {
|
|
70
|
+
return function actualDecorator(originalMethod, context) {
|
|
71
|
+
if (context.private) {
|
|
72
|
+
throw new Error("NuiEvent does not work on private methods, please mark the method as public");
|
|
73
|
+
}
|
|
74
|
+
context.addInitializer(function () {
|
|
75
|
+
const t = this;
|
|
76
|
+
RegisterNuiCallback(eventName, (...args) => {
|
|
77
|
+
return originalMethod.call(t, ...args);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const get_convar_fn = (con_var_type) => {
|
|
83
|
+
switch (con_var_type) {
|
|
84
|
+
case ConVarType.String:
|
|
85
|
+
return GetConvar;
|
|
86
|
+
case ConVarType.Integer:
|
|
87
|
+
return GetConvarInt;
|
|
88
|
+
case ConVarType.Float:
|
|
89
|
+
return GetConvarFloat;
|
|
90
|
+
case ConVarType.Boolean:
|
|
91
|
+
return GetConvarBool;
|
|
92
|
+
}
|
|
93
|
+
// never guess people wont manage to hit this
|
|
94
|
+
throw new Error("Got invalid ConVarType");
|
|
95
|
+
};
|
|
96
|
+
/*
|
|
97
|
+
* Gets the specified `ConVar`s value, do note that if you *expect* the convar
|
|
98
|
+
* to be a float you should explicitly set is_floating_point, otherwise some
|
|
99
|
+
* bundlers will remove the float
|
|
100
|
+
*/
|
|
101
|
+
export function ConVar(name, is_floating_point, deserialize) {
|
|
102
|
+
// the implementation shows that this will be _initialValue, but it doesn't
|
|
103
|
+
// seem to actually be???
|
|
104
|
+
return function actualDecorator(_initialValue, context, ...args) {
|
|
105
|
+
if (context.private) {
|
|
106
|
+
throw new Error("ConVar does not work on private types, please mark the field as public");
|
|
107
|
+
}
|
|
108
|
+
context.addInitializer(function () {
|
|
109
|
+
const t = this;
|
|
110
|
+
const default_value = Reflect.get(t, context.name);
|
|
111
|
+
const default_type = typeof default_value;
|
|
112
|
+
let con_var_type = null;
|
|
113
|
+
if (default_type == "number") {
|
|
114
|
+
if (is_floating_point || !Number.isInteger(default_value)) {
|
|
115
|
+
con_var_type = ConVarType.Float;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
con_var_type = ConVarType.Integer;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (default_type == "boolean") {
|
|
122
|
+
con_var_type = ConVarType.Boolean;
|
|
123
|
+
}
|
|
124
|
+
else if (default_value == "string") {
|
|
125
|
+
con_var_type = ConVarType.String;
|
|
126
|
+
}
|
|
127
|
+
// if we're not set that means our default value was not valid, and likely
|
|
128
|
+
// undefined (which we should just get rid of) or an object, and the
|
|
129
|
+
// caller should send a deserialize function to work with.
|
|
130
|
+
if (!deserialize && con_var_type === null) {
|
|
131
|
+
throw new Error("You should provide a deserialize function if you want to convert this to an object type");
|
|
132
|
+
}
|
|
133
|
+
// if we got past our previous check then we're going to take the data as
|
|
134
|
+
// a string and pass it to the deserialize function
|
|
135
|
+
if (con_var_type === null) {
|
|
136
|
+
con_var_type = ConVarType.String;
|
|
137
|
+
}
|
|
138
|
+
const con_var_fn = get_convar_fn(con_var_type);
|
|
139
|
+
// nice and easy wrapper
|
|
140
|
+
const get_convar_value = () => {
|
|
141
|
+
const data = con_var_fn(name, default_value);
|
|
142
|
+
return deserialize ? deserialize(data) : data;
|
|
143
|
+
};
|
|
144
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
145
|
+
AddConvarChangeListener(name, (con_var_name) => {
|
|
146
|
+
Reflect.set(t, context.name, get_convar_value());
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/*
|
|
152
|
+
* Gets called per server/client tick, this is asyncronous though, if you await
|
|
153
|
+
* in it, it will not be called until whatever was being awaited resolves.
|
|
154
|
+
*/
|
|
155
|
+
export function SetTick() {
|
|
156
|
+
return function actualDecorator(originalMethod, context) {
|
|
157
|
+
if (context.private) {
|
|
158
|
+
throw new Error("SetTick does not work on private types, please mark the field as public");
|
|
159
|
+
}
|
|
160
|
+
context.addInitializer(function () {
|
|
161
|
+
const t = this;
|
|
162
|
+
setTick(async () => {
|
|
163
|
+
await originalMethod.call(t);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
private onPlayerDropped;
|
|
9
|
+
addSubscriber(sub: number): void;
|
|
10
|
+
removeSubscriber(sub: number): boolean;
|
|
11
|
+
listenForChange(key: K, fn: ChangeListener<V>): void;
|
|
12
|
+
set(key: K, value: V): this;
|
|
13
|
+
clear(): void;
|
|
14
|
+
delete(key: K): boolean;
|
|
15
|
+
networkTick(): void;
|
|
16
|
+
[Symbol.dispose](): void;
|
|
17
|
+
/**
|
|
18
|
+
* Unregisters from the tick handler and removes the event listener
|
|
19
|
+
*/
|
|
20
|
+
dispose(): void;
|
|
21
|
+
get [Symbol.toStringTag](): string;
|
|
22
|
+
}
|
|
23
|
+
export {};
|