@nativewrappers/common-game 0.0.122 → 0.0.123
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
package/index.js
CHANGED
|
@@ -17,28 +17,8 @@ export * from "./entities/CommonPlayer";
|
|
|
17
17
|
export * from "./entities/CommonProp";
|
|
18
18
|
export * from "./entities/CommonVehicle";
|
|
19
19
|
export * from "./entities/GetEntityClassIdFromHandle";
|
|
20
|
+
export * from "./entities/IHandle";
|
|
20
21
|
export * from "./definitions/index.d";
|
|
21
22
|
export * from "./definitions/redm.d";
|
|
22
|
-
export * from "./common/Command";
|
|
23
|
-
export * from "./common/Convar";
|
|
24
|
-
export * from "./common/GlobalData";
|
|
25
|
-
export * from "./common/Kvp";
|
|
26
|
-
export * from "./common/Resource";
|
|
27
|
-
export * from "./common/types";
|
|
28
|
-
export * from "./common/utils/ClassTypes";
|
|
29
|
-
export * from "./common/utils/Color";
|
|
30
|
-
export * from "./common/utils/Delay";
|
|
31
|
-
export * from "./common/utils/Maths";
|
|
32
|
-
export * from "./common/utils/Point";
|
|
33
|
-
export * from "./common/utils/PointF";
|
|
34
|
-
export * from "./common/utils/Quaternion";
|
|
35
|
-
export * from "./common/utils/Vector";
|
|
36
|
-
export * from "./common/utils/cleanPlayerName";
|
|
37
|
-
export * from "./common/utils/enumValues";
|
|
38
|
-
export * from "./common/utils/getStringFromUInt8Array";
|
|
39
|
-
export * from "./common/utils/getUInt32FromUint8Array";
|
|
40
|
-
export * from "./common/utils/randomInt";
|
|
41
|
-
export * from "./common/net/NetworkedMap";
|
|
42
|
-
export * from "./common/decors/Events";
|
|
43
23
|
export * from "./cfx/StateBagChangeHandler";
|
|
44
24
|
export * from "./cfx/cfx";
|
package/package.json
CHANGED
package/utils/Animations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { Delay } from "
|
|
3
|
+
import { Delay } from "@common/utils/Delay";
|
|
4
4
|
const LoadAnimDict = /* @__PURE__ */ __name(async (animDict, waitTime = 1e3) => {
|
|
5
5
|
const start = GetGameTimer();
|
|
6
6
|
if (!HasAnimDictLoaded(animDict)) {
|
package/common/Command.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
type Restricted = boolean | string | string[];
|
|
2
|
-
interface ParameterTypes {
|
|
3
|
-
number: number;
|
|
4
|
-
playerId: number;
|
|
5
|
-
string: string;
|
|
6
|
-
longString: string;
|
|
7
|
-
}
|
|
8
|
-
interface Parameter {
|
|
9
|
-
name: string;
|
|
10
|
-
type: keyof ParameterTypes;
|
|
11
|
-
defaultValue?: any;
|
|
12
|
-
help?: string;
|
|
13
|
-
optional?: boolean;
|
|
14
|
-
}
|
|
15
|
-
type MappedParameters<T extends Parameter[]> = {
|
|
16
|
-
[K in T[number] as K["name"]]: ParameterTypes[K["type"]];
|
|
17
|
-
} & {
|
|
18
|
-
source: number;
|
|
19
|
-
raw: string;
|
|
20
|
-
};
|
|
21
|
-
type CommandHandler<T extends Parameter[]> = (args: MappedParameters<T>) => void | Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* ```typescript
|
|
24
|
-
* new Command(["do", "deleteobjects"], async ({source, radius}) => {
|
|
25
|
-
* const entities = Prop.AllProps();
|
|
26
|
-
* const ply = new Player(source);
|
|
27
|
-
* const pos = ply.Ped.Position
|
|
28
|
-
* for (const ent of entities) {
|
|
29
|
-
* // if they're outside of the range of our specified radius just continue to next
|
|
30
|
-
* if (ent.Position.distance(pos) > radius) continue;
|
|
31
|
-
* ent.delete();
|
|
32
|
-
* }
|
|
33
|
-
* }, "Deletes all objects in the specified range", [
|
|
34
|
-
* {
|
|
35
|
-
* name: "radius",
|
|
36
|
-
* type: "number",
|
|
37
|
-
* help: "The radius to delete the entities in",
|
|
38
|
-
* defaultValue: 5.0
|
|
39
|
-
* }
|
|
40
|
-
* ] as const, "group.moderator")
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare class Command<T extends Parameter[] = Parameter[]> {
|
|
44
|
-
#private;
|
|
45
|
-
readonly name: string | string[];
|
|
46
|
-
readonly help?: string | undefined;
|
|
47
|
-
readonly params?: T | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Registers a new executable command with optional parameter validation and permission restrictions.
|
|
50
|
-
* @param name The unique identifier(s) for the command, either as a single string or an array of strings.
|
|
51
|
-
* @param handler The function to execute when the command is executed.
|
|
52
|
-
* @param help A description of the command, displayed as a chat suggestion.
|
|
53
|
-
* @param params An optional array of parameter definitions specifying the command's expected arguments,
|
|
54
|
-
* including their names, types, and descriptive help text for chat suggestions.
|
|
55
|
-
* @param restricted Determines the command's access permissions:
|
|
56
|
-
* - Defaults to `true`, restricting usage to users with the "command.commandName" ACE permission.
|
|
57
|
-
* - A string such as `"group.admin"` grants the command permission to the specified principal.
|
|
58
|
-
* - An array of strings grants permission to multiple principals.
|
|
59
|
-
*/
|
|
60
|
-
constructor(name: string | string[], handler: CommandHandler<T>, help?: string | undefined, params?: T | undefined, restricted?: Restricted);
|
|
61
|
-
/**
|
|
62
|
-
* Maps the arguments received from a command call to the defined parameters while validating the argument types.
|
|
63
|
-
* @param source The client that executed the command, or -1 if executed by the server.
|
|
64
|
-
* @param args The arguments passed to the command.
|
|
65
|
-
* @param raw The raw input string passed to the command.
|
|
66
|
-
* @returns A mapped object containing parsed parameters.
|
|
67
|
-
*/
|
|
68
|
-
private mapArguments;
|
|
69
|
-
/**
|
|
70
|
-
* Executes the command with the given arguments and source, validating and mapping the arguments before calling the handler.
|
|
71
|
-
* @param source The client that executed the command.
|
|
72
|
-
* @param args The arguments passed to the command.
|
|
73
|
-
* @param raw The raw input string passed to the command.
|
|
74
|
-
*/
|
|
75
|
-
call(source: number, args: string[], raw?: string): Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
export {};
|
package/common/Command.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { GlobalData } from "./GlobalData";
|
|
4
|
-
const commands = [];
|
|
5
|
-
$SERVER: {
|
|
6
|
-
on("playerJoining", () => emitNet("chat:addSuggestions", source, commands));
|
|
7
|
-
}
|
|
8
|
-
function registerCommand(name, commandHandler, restricted = true) {
|
|
9
|
-
if (Array.isArray(name)) {
|
|
10
|
-
for (const command of name) {
|
|
11
|
-
registerCommand(command, commandHandler, restricted);
|
|
12
|
-
}
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
RegisterCommand(name, commandHandler, GlobalData.IS_CLIENT ? false : !!restricted);
|
|
16
|
-
$SERVER: {
|
|
17
|
-
const ace = `command.${name}`;
|
|
18
|
-
if (typeof restricted === "string") {
|
|
19
|
-
if (IsPrincipalAceAllowed(restricted, ace)) return;
|
|
20
|
-
return ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
21
|
-
}
|
|
22
|
-
if (Array.isArray(restricted)) {
|
|
23
|
-
for (const principal of restricted) {
|
|
24
|
-
if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${restricted} ${ace} allow`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
__name(registerCommand, "registerCommand");
|
|
30
|
-
class Command {
|
|
31
|
-
/**
|
|
32
|
-
* Registers a new executable command with optional parameter validation and permission restrictions.
|
|
33
|
-
* @param name The unique identifier(s) for the command, either as a single string or an array of strings.
|
|
34
|
-
* @param handler The function to execute when the command is executed.
|
|
35
|
-
* @param help A description of the command, displayed as a chat suggestion.
|
|
36
|
-
* @param params An optional array of parameter definitions specifying the command's expected arguments,
|
|
37
|
-
* including their names, types, and descriptive help text for chat suggestions.
|
|
38
|
-
* @param restricted Determines the command's access permissions:
|
|
39
|
-
* - Defaults to `true`, restricting usage to users with the "command.commandName" ACE permission.
|
|
40
|
-
* - A string such as `"group.admin"` grants the command permission to the specified principal.
|
|
41
|
-
* - An array of strings grants permission to multiple principals.
|
|
42
|
-
*/
|
|
43
|
-
constructor(name, handler, help, params, restricted = true) {
|
|
44
|
-
this.name = name;
|
|
45
|
-
this.help = help;
|
|
46
|
-
this.params = params;
|
|
47
|
-
this.#handler = handler;
|
|
48
|
-
registerCommand(name, (source2, args, raw) => this.call(source2, args, raw), restricted);
|
|
49
|
-
if (params) {
|
|
50
|
-
for (const parameter of params) {
|
|
51
|
-
if (parameter.type) {
|
|
52
|
-
const defaultString = parameter.defaultValue !== void 0 ? `[default: ${parameter.defaultValue}]` : "";
|
|
53
|
-
const typeString = `[type: ${parameter.type}] ${defaultString}`;
|
|
54
|
-
parameter.help = parameter.help ? `${parameter.help} ${typeString}` : `${typeString}`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
const names = Array.isArray(name) ? name : [name];
|
|
60
|
-
for (const name2 of names) {
|
|
61
|
-
const commandObj = { ...this, name: `/${name2}` };
|
|
62
|
-
$SERVER: {
|
|
63
|
-
commands.push(commandObj);
|
|
64
|
-
emitNet("chat:addSuggestions", -1, commandObj);
|
|
65
|
-
}
|
|
66
|
-
$CLIENT: {
|
|
67
|
-
emit("chat:addSuggestion", commandObj);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}, 100);
|
|
71
|
-
}
|
|
72
|
-
static {
|
|
73
|
-
__name(this, "Command");
|
|
74
|
-
}
|
|
75
|
-
#handler;
|
|
76
|
-
/**
|
|
77
|
-
* Maps the arguments received from a command call to the defined parameters while validating the argument types.
|
|
78
|
-
* @param source The client that executed the command, or -1 if executed by the server.
|
|
79
|
-
* @param args The arguments passed to the command.
|
|
80
|
-
* @param raw The raw input string passed to the command.
|
|
81
|
-
* @returns A mapped object containing parsed parameters.
|
|
82
|
-
*/
|
|
83
|
-
mapArguments(source2, args, raw) {
|
|
84
|
-
const mapped = {
|
|
85
|
-
source: source2,
|
|
86
|
-
raw
|
|
87
|
-
};
|
|
88
|
-
if (!this.params) return mapped;
|
|
89
|
-
const result = this.params.every((param, index) => {
|
|
90
|
-
const arg = args[index];
|
|
91
|
-
let value = arg;
|
|
92
|
-
const hasDefaultValue = param.defaultValue !== void 0;
|
|
93
|
-
const hasArg = typeof arg === "string";
|
|
94
|
-
if (!hasArg && hasDefaultValue) {
|
|
95
|
-
value = param.defaultValue;
|
|
96
|
-
} else {
|
|
97
|
-
switch (param.type) {
|
|
98
|
-
case "number":
|
|
99
|
-
if (hasDefaultValue && !hasArg) {
|
|
100
|
-
value = param.defaultValue;
|
|
101
|
-
} else {
|
|
102
|
-
value = +arg;
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
case "string":
|
|
106
|
-
value = !Number(arg) ? arg : false;
|
|
107
|
-
break;
|
|
108
|
-
case "playerId":
|
|
109
|
-
$SERVER: {
|
|
110
|
-
value = arg === "me" ? source2 : +arg;
|
|
111
|
-
if (!value || !DoesPlayerExist(value.toString())) value = void 0;
|
|
112
|
-
}
|
|
113
|
-
$CLIENT: {
|
|
114
|
-
value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
|
|
115
|
-
if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
|
|
116
|
-
}
|
|
117
|
-
break;
|
|
118
|
-
case "longString":
|
|
119
|
-
value = raw.substring(raw.indexOf(arg));
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (value === void 0 && (!param.optional || param.optional && arg)) {
|
|
124
|
-
return Citizen.trace(
|
|
125
|
-
`^1command '${raw.split(" ")[0] || raw}' received an invalid ${param.type} for argument ${index + 1} (${param.name}), received '${arg}'^0`
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
mapped[param.name] = value;
|
|
129
|
-
return true;
|
|
130
|
-
});
|
|
131
|
-
return result ? mapped : null;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Executes the command with the given arguments and source, validating and mapping the arguments before calling the handler.
|
|
135
|
-
* @param source The client that executed the command.
|
|
136
|
-
* @param args The arguments passed to the command.
|
|
137
|
-
* @param raw The raw input string passed to the command.
|
|
138
|
-
*/
|
|
139
|
-
async call(source2, args, raw = args.join(" ")) {
|
|
140
|
-
const parsed = this.mapArguments(source2, args, raw);
|
|
141
|
-
if (!parsed) return;
|
|
142
|
-
try {
|
|
143
|
-
await this.#handler(parsed);
|
|
144
|
-
} catch (err) {
|
|
145
|
-
Citizen.trace(`^1command '${raw.split(" ")[0] || raw}' failed to execute!^0
|
|
146
|
-
${err.message}`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
export {
|
|
151
|
-
Command
|
|
152
|
-
};
|
package/common/Convar.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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/common/Convar.js
DELETED
|
@@ -1,58 +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 Convar {
|
|
5
|
-
static {
|
|
6
|
-
__name(this, "Convar");
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @returns the current console buffer
|
|
10
|
-
*/
|
|
11
|
-
buffer() {
|
|
12
|
-
$CLIENT: {
|
|
13
|
-
if (GlobalData.IS_CLIENT) {
|
|
14
|
-
throw new Error("This function isn't available on the client");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return GetConsoleBuffer();
|
|
18
|
-
}
|
|
19
|
-
get(variable, defaultVar) {
|
|
20
|
-
return GetConvar(variable, defaultVar);
|
|
21
|
-
}
|
|
22
|
-
getInt(variable, defaultVar) {
|
|
23
|
-
return GetConvarInt(variable, defaultVar);
|
|
24
|
-
}
|
|
25
|
-
getFloat(varName, defaultVar) {
|
|
26
|
-
return GetConvarFloat(varName, defaultVar);
|
|
27
|
-
}
|
|
28
|
-
getBool(varName, defaultVar) {
|
|
29
|
-
return GetConvarBool(varName, defaultVar);
|
|
30
|
-
}
|
|
31
|
-
set(variable, value) {
|
|
32
|
-
$CLIENT: {
|
|
33
|
-
if (GlobalData.IS_CLIENT) {
|
|
34
|
-
throw new Error("This function isn't available on the client");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
SetConvar(variable, value);
|
|
38
|
-
}
|
|
39
|
-
setReplicated(variable, value) {
|
|
40
|
-
$CLIENT: {
|
|
41
|
-
if (GlobalData.IS_CLIENT) {
|
|
42
|
-
throw new Error("This function isn't available on the client");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
SetConvarReplicated(variable, value);
|
|
46
|
-
}
|
|
47
|
-
setServerInfo(variable, value) {
|
|
48
|
-
$CLIENT: {
|
|
49
|
-
if (GlobalData.IS_CLIENT) {
|
|
50
|
-
throw new Error("This function isn't available on the client");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
SetConvarServerInfo(variable, value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export {
|
|
57
|
-
Convar
|
|
58
|
-
};
|
package/common/GlobalData.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare class GlobalData {
|
|
2
|
-
static CurrentResource: string;
|
|
3
|
-
static GameName: string;
|
|
4
|
-
static GameBuild: number;
|
|
5
|
-
static IS_SERVER: boolean;
|
|
6
|
-
static IS_REDM: boolean;
|
|
7
|
-
static IS_FIVEM: boolean;
|
|
8
|
-
static IS_CLIENT: boolean;
|
|
9
|
-
static NetworkTick: number | null;
|
|
10
|
-
static NetworkedTicks: any[];
|
|
11
|
-
static EnablePrettyPrint: boolean;
|
|
12
|
-
}
|
package/common/GlobalData.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
class GlobalData {
|
|
4
|
-
static {
|
|
5
|
-
__name(this, "GlobalData");
|
|
6
|
-
}
|
|
7
|
-
static CurrentResource = GetCurrentResourceName();
|
|
8
|
-
static GameName = GetGameName();
|
|
9
|
-
static GameBuild = GetGameBuildNumber();
|
|
10
|
-
static IS_SERVER = IsDuplicityVersion();
|
|
11
|
-
static IS_REDM = GetGameName() === "redm";
|
|
12
|
-
static IS_FIVEM = GetGameName() === "fivem";
|
|
13
|
-
static IS_CLIENT = !GlobalData.IS_SERVER;
|
|
14
|
-
static NetworkTick = null;
|
|
15
|
-
static NetworkedTicks = [];
|
|
16
|
-
static EnablePrettyPrint = true;
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
GlobalData
|
|
20
|
-
};
|
package/common/Kvp.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
type KvpSchema = Record<string, string | number | object>;
|
|
2
|
-
type KvpObject<T> = T extends `${infer Prefix}.${infer Rest}` ? Rest extends `${string}.${string}` ? never : Prefix : never;
|
|
3
|
-
type ValidJsonKey<Schema> = {
|
|
4
|
-
[K in keyof Schema]: K extends string ? `${K}.${string}` : never;
|
|
5
|
-
}[keyof Schema];
|
|
6
|
-
export declare class Kvp<Schema extends KvpSchema> {
|
|
7
|
-
/**
|
|
8
|
-
* Returns the value associated with a key as a number.
|
|
9
|
-
*/
|
|
10
|
-
getNumber<K extends string & keyof Schema>(key: K): number;
|
|
11
|
-
/**
|
|
12
|
-
* Returns the value associated with a key as a float.
|
|
13
|
-
*/
|
|
14
|
-
getFloat<K extends string & keyof Schema>(key: K): number;
|
|
15
|
-
/**
|
|
16
|
-
* Returns the value associated with a key as a string.
|
|
17
|
-
*/
|
|
18
|
-
getString<K extends string & keyof Schema>(key: K): string | null;
|
|
19
|
-
/**
|
|
20
|
-
* Returns the value associated with a key as a parsed JSON string.
|
|
21
|
-
*/
|
|
22
|
-
getJson<K extends string, O = KvpObject<K>>(key: K extends ValidJsonKey<O> ? K : never): (O extends string ? Schema[O] : null) | null;
|
|
23
|
-
/**
|
|
24
|
-
* Sets the value associated with a key as a number.
|
|
25
|
-
* @param async set the value using an async operation.
|
|
26
|
-
*/
|
|
27
|
-
setNumber<K extends string & keyof Schema>(key: K, value: number, async?: boolean): void;
|
|
28
|
-
/**
|
|
29
|
-
* Sets the value associated with a key as a float.
|
|
30
|
-
* @param async set the value using an async operation.
|
|
31
|
-
*/
|
|
32
|
-
setFloat<K extends string & keyof Schema>(key: K, value: number, async?: boolean): void;
|
|
33
|
-
/**
|
|
34
|
-
* Sets the value associated with a key as a string.
|
|
35
|
-
* @param async set the value using an async operation.
|
|
36
|
-
*/
|
|
37
|
-
setString<K extends string & keyof Schema>(key: K, value: string, async?: boolean): void;
|
|
38
|
-
/**
|
|
39
|
-
* Sets the value associated with a key as a JSON string.
|
|
40
|
-
* @param async set the value using an async operation.
|
|
41
|
-
*/
|
|
42
|
-
setJson<K extends string, O = KvpObject<K>>(key: K extends ValidJsonKey<O> ? K : never, value: O extends string ? Schema[O] : never, async?: boolean): void;
|
|
43
|
-
/**
|
|
44
|
-
* Sets the value associated with a key as a JSON string.
|
|
45
|
-
* @param async set the value using an async operation.
|
|
46
|
-
*/
|
|
47
|
-
set<K extends string, O = KvpObject<K>>(key: K extends keyof Schema ? K : O extends string ? K : never, value: K extends keyof Schema ? Schema[K] : O extends string ? Schema[O] : never, async?: boolean): void;
|
|
48
|
-
/**
|
|
49
|
-
* Deletes the specified value for key.
|
|
50
|
-
* @param async remove the value using an async operation
|
|
51
|
-
*/
|
|
52
|
-
delete(key: string, async?: boolean): void;
|
|
53
|
-
/**
|
|
54
|
-
* Commits pending asynchronous operations to disk, ensuring data consistency.
|
|
55
|
-
*
|
|
56
|
-
* Should be called after calling set methods using the async flag.
|
|
57
|
-
*/
|
|
58
|
-
flush(): void;
|
|
59
|
-
getAllKeys(prefix: string): (keyof Schema)[];
|
|
60
|
-
/**
|
|
61
|
-
* Returns an array of keys which match or contain the given keys.
|
|
62
|
-
*/
|
|
63
|
-
getKeys<K extends (string & keyof Schema) | string[]>(prefix: K): (keyof Schema)[];
|
|
64
|
-
/**
|
|
65
|
-
* Get all values from keys in an array as the specified type.
|
|
66
|
-
*/
|
|
67
|
-
getValuesAsType<K extends (string & keyof Schema) | (string & keyof Schema)[]>(prefix: K, type: any): (string | number | Schema[string] | null)[];
|
|
68
|
-
}
|
|
69
|
-
export {};
|
package/common/Kvp.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
class Kvp {
|
|
4
|
-
static {
|
|
5
|
-
__name(this, "Kvp");
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Returns the value associated with a key as a number.
|
|
9
|
-
*/
|
|
10
|
-
getNumber(key) {
|
|
11
|
-
return GetResourceKvpInt(key);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Returns the value associated with a key as a float.
|
|
15
|
-
*/
|
|
16
|
-
getFloat(key) {
|
|
17
|
-
return GetResourceKvpFloat(key);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns the value associated with a key as a string.
|
|
21
|
-
*/
|
|
22
|
-
getString(key) {
|
|
23
|
-
return GetResourceKvpString(key);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns the value associated with a key as a parsed JSON string.
|
|
27
|
-
*/
|
|
28
|
-
getJson(key) {
|
|
29
|
-
const str = GetResourceKvpString(key);
|
|
30
|
-
return str ? JSON.parse(str) : null;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Sets the value associated with a key as a number.
|
|
34
|
-
* @param async set the value using an async operation.
|
|
35
|
-
*/
|
|
36
|
-
setNumber(key, value, async = false) {
|
|
37
|
-
return async ? SetResourceKvpIntNoSync(key, value) : SetResourceKvpInt(key, value);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Sets the value associated with a key as a float.
|
|
41
|
-
* @param async set the value using an async operation.
|
|
42
|
-
*/
|
|
43
|
-
setFloat(key, value, async = false) {
|
|
44
|
-
return async ? SetResourceKvpFloatNoSync(key, value) : SetResourceKvpFloat(key, value);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Sets the value associated with a key as a string.
|
|
48
|
-
* @param async set the value using an async operation.
|
|
49
|
-
*/
|
|
50
|
-
setString(key, value, async = false) {
|
|
51
|
-
return async ? SetResourceKvpNoSync(key, value) : SetResourceKvp(key, value);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Sets the value associated with a key as a JSON string.
|
|
55
|
-
* @param async set the value using an async operation.
|
|
56
|
-
*/
|
|
57
|
-
setJson(key, value, async = false) {
|
|
58
|
-
const str = JSON.stringify(value);
|
|
59
|
-
return async ? SetResourceKvpNoSync(key, str) : SetResourceKvp(key, str);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Sets the value associated with a key as a JSON string.
|
|
63
|
-
* @param async set the value using an async operation.
|
|
64
|
-
*/
|
|
65
|
-
set(key, value, async = false) {
|
|
66
|
-
switch (typeof value) {
|
|
67
|
-
case "function":
|
|
68
|
-
case "symbol":
|
|
69
|
-
throw new Error(`Failed to set Kvp for invalid type '${typeof value}'`);
|
|
70
|
-
case "undefined":
|
|
71
|
-
return this.delete(key, async);
|
|
72
|
-
case "object":
|
|
73
|
-
return this.setJson(key, value, async);
|
|
74
|
-
case "boolean":
|
|
75
|
-
value = value ? 1 : 0;
|
|
76
|
-
case "number":
|
|
77
|
-
return Number.isInteger(value) ? this.setNumber(key, value, async) : this.setFloat(key, value, async);
|
|
78
|
-
default:
|
|
79
|
-
value = String(value);
|
|
80
|
-
return this.setString(key, value, async);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Deletes the specified value for key.
|
|
85
|
-
* @param async remove the value using an async operation
|
|
86
|
-
*/
|
|
87
|
-
delete(key, async = false) {
|
|
88
|
-
return async ? DeleteResourceKvpNoSync(key) : DeleteResourceKvp(key);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Commits pending asynchronous operations to disk, ensuring data consistency.
|
|
92
|
-
*
|
|
93
|
-
* Should be called after calling set methods using the async flag.
|
|
94
|
-
*/
|
|
95
|
-
flush() {
|
|
96
|
-
FlushResourceKvp();
|
|
97
|
-
}
|
|
98
|
-
getAllKeys(prefix) {
|
|
99
|
-
const keys = [];
|
|
100
|
-
const handle = StartFindKvp(prefix);
|
|
101
|
-
if (handle === -1) return keys;
|
|
102
|
-
let key;
|
|
103
|
-
do {
|
|
104
|
-
key = FindKvp(handle);
|
|
105
|
-
if (key) keys.push(key);
|
|
106
|
-
} while (key);
|
|
107
|
-
EndFindKvp(handle);
|
|
108
|
-
return keys;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns an array of keys which match or contain the given keys.
|
|
112
|
-
*/
|
|
113
|
-
getKeys(prefix) {
|
|
114
|
-
return typeof prefix === "string" ? this.getAllKeys(prefix) : prefix.flatMap((key) => this.getAllKeys(key));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Get all values from keys in an array as the specified type.
|
|
118
|
-
*/
|
|
119
|
-
getValuesAsType(prefix, type) {
|
|
120
|
-
const values = this.getKeys(prefix);
|
|
121
|
-
return values.map((key) => {
|
|
122
|
-
switch (type) {
|
|
123
|
-
case "number":
|
|
124
|
-
return this.getNumber(key);
|
|
125
|
-
case "float":
|
|
126
|
-
return this.getFloat(key);
|
|
127
|
-
case "string":
|
|
128
|
-
return this.getString(key);
|
|
129
|
-
default:
|
|
130
|
-
return this.getJson(key);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
export {
|
|
136
|
-
Kvp
|
|
137
|
-
};
|
package/common/Resource.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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/common/Resource.js
DELETED
|
@@ -1,54 +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 Resource {
|
|
5
|
-
constructor(name) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
}
|
|
8
|
-
static {
|
|
9
|
-
__name(this, "Resource");
|
|
10
|
-
}
|
|
11
|
-
getMetadata(metadataKey, index) {
|
|
12
|
-
return GetResourceMetadata(this.name, metadataKey, index);
|
|
13
|
-
}
|
|
14
|
-
getPath() {
|
|
15
|
-
return GetResourcePath(this.name);
|
|
16
|
-
}
|
|
17
|
-
loadFile(fileName) {
|
|
18
|
-
return LoadResourceFile(this.name, fileName);
|
|
19
|
-
}
|
|
20
|
-
saveFile(fileName, data, length) {
|
|
21
|
-
$CLIENT: {
|
|
22
|
-
if (GlobalData.IS_CLIENT) {
|
|
23
|
-
throw new Error("This function isn't available on the client");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return SaveResourceFile(this.name, fileName, data, length);
|
|
27
|
-
}
|
|
28
|
-
scheduleTick() {
|
|
29
|
-
$CLIENT: {
|
|
30
|
-
if (GlobalData.IS_CLIENT) {
|
|
31
|
-
throw new Error("This function isn't available on the client");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return ScheduleResourceTick(this.name);
|
|
35
|
-
}
|
|
36
|
-
start() {
|
|
37
|
-
StartResource(this.name);
|
|
38
|
-
}
|
|
39
|
-
stop() {
|
|
40
|
-
StopResource(this.name);
|
|
41
|
-
}
|
|
42
|
-
static startResource(name) {
|
|
43
|
-
StartResource(name);
|
|
44
|
-
}
|
|
45
|
-
static stopResource(name) {
|
|
46
|
-
StopResource(name);
|
|
47
|
-
}
|
|
48
|
-
static resourceCount() {
|
|
49
|
-
return GetNumResources();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
Resource
|
|
54
|
-
};
|