@armoury/fivem-framework-common 1.0.47 → 1.0.49
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/dist/cjs/decorators/command.decorator.js +1 -2
- package/dist/cjs/decorators/key-binding.decorator.js +11 -4
- package/dist/cjs/decorators/ui-listener.decorator.js +12 -4
- package/dist/esm/decorators/command.decorator.js +1 -2
- package/dist/esm/decorators/key-binding.decorator.js +12 -5
- package/dist/esm/decorators/ui-listener.decorator.js +12 -4
- package/dist/types/decorators/ui-listener.decorator.d.ts +1 -1
- package/package.json +1 -1
|
@@ -15,8 +15,7 @@ function Commands(target, _prototype, providers) {
|
|
|
15
15
|
.forEach((mapping) => {
|
|
16
16
|
var _a;
|
|
17
17
|
const rawCommandName = mapping.key.split('_').slice(2).join('_');
|
|
18
|
-
const
|
|
19
|
-
const commandName = `${keybinding ? '+' : ''}` + rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
|
|
18
|
+
const commandName = rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
|
|
20
19
|
if (!Cfx.Client.IsDuplicityVersion()) {
|
|
21
20
|
Cfx.Client.RegisterCommand(commandName, (_source, args, _raw) => {
|
|
22
21
|
mapping.target[rawCommandName].apply(mapping.target, args);
|
|
@@ -14,16 +14,23 @@ function KeyBinding(data) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
function KeyBindings(target, _prototype, providers) {
|
|
17
|
-
|
|
17
|
+
if (Cfx.Client.IsDuplicityVersion()) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const mappings = decorator_utils_1.DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : []);
|
|
21
|
+
mappings
|
|
18
22
|
.filter((mapping) => mapping.key.startsWith('arm_keybinding_'))
|
|
19
23
|
.forEach((mapping) => {
|
|
20
|
-
var _a, _b, _c, _d;
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
21
25
|
const keybindingName = mapping.key.split('_').slice(2).join('_');
|
|
22
|
-
const
|
|
26
|
+
const commandMapping = mappings.find((entry) => entry.target === mapping.target && entry.key === `arm_command_${keybindingName}`);
|
|
27
|
+
const command = ((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.command)
|
|
28
|
+
? mapping.value.command.toLowerCase()
|
|
29
|
+
: keybindingName.toLowerCase() + (((_b = commandMapping === null || commandMapping === void 0 ? void 0 : commandMapping.value) === null || _b === void 0 ? void 0 : _b.suffix) || '');
|
|
23
30
|
if (!command) {
|
|
24
31
|
console.error(`Could not find any relevant command for key binding ${keybindingName}`);
|
|
25
32
|
return;
|
|
26
33
|
}
|
|
27
|
-
Cfx.Client.RegisterKeyMapping(
|
|
34
|
+
Cfx.Client.RegisterKeyMapping(command, (_c = mapping.value) === null || _c === void 0 ? void 0 : _c.description, (_d = mapping.value) === null || _d === void 0 ? void 0 : _d.defaultMapper, (_e = mapping.value) === null || _e === void 0 ? void 0 : _e.key);
|
|
28
35
|
});
|
|
29
36
|
}
|
|
@@ -4,7 +4,7 @@ exports.UIListener = UIListener;
|
|
|
4
4
|
exports.UIListeners = UIListeners;
|
|
5
5
|
const decorator_utils_1 = require("./decorator.utils");
|
|
6
6
|
function UIListener(data) {
|
|
7
|
-
return function (target, propertyKey) {
|
|
7
|
+
return function (target, propertyKey, _descriptor) {
|
|
8
8
|
const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
|
|
9
9
|
Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
|
|
10
10
|
};
|
|
@@ -16,9 +16,17 @@ function UIListeners(target, _prototype, providers) {
|
|
|
16
16
|
const { eventName } = mapping.value;
|
|
17
17
|
const func = mapping.key.split('_').slice(2).join('_');
|
|
18
18
|
Cfx.Client.RegisterNuiCallbackType(eventName);
|
|
19
|
-
Cfx.Client.on('__cfx_nui:' + eventName, (data, cb) => {
|
|
20
|
-
mapping.target[func].call(mapping.target, data);
|
|
21
|
-
|
|
19
|
+
Cfx.Client.on('__cfx_nui:' + eventName, async (data, cb) => {
|
|
20
|
+
const result = await mapping.target[func].call(mapping.target, data);
|
|
21
|
+
if (result === undefined) {
|
|
22
|
+
cb({ ok: true });
|
|
23
|
+
}
|
|
24
|
+
else if (result !== null && typeof result === 'object') {
|
|
25
|
+
cb(result);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
cb({ response: result });
|
|
29
|
+
}
|
|
22
30
|
});
|
|
23
31
|
});
|
|
24
32
|
}
|
|
@@ -11,8 +11,7 @@ export function Commands(target, _prototype, providers) {
|
|
|
11
11
|
.forEach((mapping) => {
|
|
12
12
|
var _a;
|
|
13
13
|
const rawCommandName = mapping.key.split('_').slice(2).join('_');
|
|
14
|
-
const
|
|
15
|
-
const commandName = `${keybinding ? '+' : ''}` + rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
|
|
14
|
+
const commandName = rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
|
|
16
15
|
if (!Cfx.Client.IsDuplicityVersion()) {
|
|
17
16
|
Cfx.Client.RegisterCommand(commandName, (_source, args, _raw) => {
|
|
18
17
|
mapping.target[rawCommandName].apply(mapping.target, args);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DecoratorUtils } from
|
|
1
|
+
import { DecoratorUtils } from './decorator.utils';
|
|
2
2
|
export function KeyBinding(data) {
|
|
3
3
|
return function (target, propertyKey) {
|
|
4
4
|
Reflect.defineMetadata(`arm_keybinding_${propertyKey}`, {
|
|
@@ -10,16 +10,23 @@ export function KeyBinding(data) {
|
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
export function KeyBindings(target, _prototype, providers) {
|
|
13
|
-
|
|
13
|
+
if (Cfx.Client.IsDuplicityVersion()) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const mappings = DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : []);
|
|
17
|
+
mappings
|
|
14
18
|
.filter((mapping) => mapping.key.startsWith('arm_keybinding_'))
|
|
15
19
|
.forEach((mapping) => {
|
|
16
|
-
var _a, _b, _c, _d;
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
17
21
|
const keybindingName = mapping.key.split('_').slice(2).join('_');
|
|
18
|
-
const
|
|
22
|
+
const commandMapping = mappings.find((entry) => entry.target === mapping.target && entry.key === `arm_command_${keybindingName}`);
|
|
23
|
+
const command = ((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.command)
|
|
24
|
+
? mapping.value.command.toLowerCase()
|
|
25
|
+
: keybindingName.toLowerCase() + (((_b = commandMapping === null || commandMapping === void 0 ? void 0 : commandMapping.value) === null || _b === void 0 ? void 0 : _b.suffix) || '');
|
|
19
26
|
if (!command) {
|
|
20
27
|
console.error(`Could not find any relevant command for key binding ${keybindingName}`);
|
|
21
28
|
return;
|
|
22
29
|
}
|
|
23
|
-
Cfx.Client.RegisterKeyMapping(
|
|
30
|
+
Cfx.Client.RegisterKeyMapping(command, (_c = mapping.value) === null || _c === void 0 ? void 0 : _c.description, (_d = mapping.value) === null || _d === void 0 ? void 0 : _d.defaultMapper, (_e = mapping.value) === null || _e === void 0 ? void 0 : _e.key);
|
|
24
31
|
});
|
|
25
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DecoratorUtils } from "./decorator.utils";
|
|
2
2
|
export function UIListener(data) {
|
|
3
|
-
return function (target, propertyKey) {
|
|
3
|
+
return function (target, propertyKey, _descriptor) {
|
|
4
4
|
const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
|
|
5
5
|
Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
|
|
6
6
|
};
|
|
@@ -12,9 +12,17 @@ export function UIListeners(target, _prototype, providers) {
|
|
|
12
12
|
const { eventName } = mapping.value;
|
|
13
13
|
const func = mapping.key.split('_').slice(2).join('_');
|
|
14
14
|
Cfx.Client.RegisterNuiCallbackType(eventName);
|
|
15
|
-
Cfx.Client.on('__cfx_nui:' + eventName, (data, cb) => {
|
|
16
|
-
mapping.target[func].call(mapping.target, data);
|
|
17
|
-
|
|
15
|
+
Cfx.Client.on('__cfx_nui:' + eventName, async (data, cb) => {
|
|
16
|
+
const result = await mapping.target[func].call(mapping.target, data);
|
|
17
|
+
if (result === undefined) {
|
|
18
|
+
cb({ ok: true });
|
|
19
|
+
}
|
|
20
|
+
else if (result !== null && typeof result === 'object') {
|
|
21
|
+
cb(result);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cb({ response: result });
|
|
25
|
+
}
|
|
18
26
|
});
|
|
19
27
|
});
|
|
20
28
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function UIListener(data?: {
|
|
2
2
|
eventName?: string;
|
|
3
|
-
}): (target: any, propertyKey: string) => void;
|
|
3
|
+
}): <T extends (...args: any[]) => any>(target: any, propertyKey: string, _descriptor: TypedPropertyDescriptor<T> & (Parameters<T> extends [object, ...unknown[]] ? unknown : never)) => void;
|
|
4
4
|
export declare function UIListeners(target: any, _prototype: any, providers?: Object[]): void;
|