lenix 1.7.18 → 1.7.19
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/client/control.ts +171 -0
- package/client/index.ts +1 -0
- package/package.json +6 -6
- package/client/control/binds.json +0 -87
- package/client/control/disable/index.ts +0 -12
- package/client/control/index.ts +0 -42
- package/client/control/onDisabled/index.ts +0 -15
- package/client/control/onHold/index.ts +0 -12
- package/client/control/onPress/index.ts +0 -12
- package/client/control/onRelease/index.ts +0 -12
- package/client/control/onReleased/index.ts +0 -11
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { asserts } from '@lenix/lenix'
|
|
2
|
+
import { pool } from './pool'
|
|
3
|
+
|
|
4
|
+
export interface Bind {
|
|
5
|
+
event: keyof typeof EVENTS,
|
|
6
|
+
key: keyof typeof CONTROLS,
|
|
7
|
+
cb: () => void,
|
|
8
|
+
type: keyof typeof TYPES,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const EVENTS = {
|
|
12
|
+
press: IsControlJustPressed,
|
|
13
|
+
hold: IsControlPressed,
|
|
14
|
+
release: IsControlJustReleased,
|
|
15
|
+
released: IsControlReleased,
|
|
16
|
+
disabled: IsDisabledControlJustPressed,
|
|
17
|
+
disable: DisableControlAction,
|
|
18
|
+
enable: EnableControlAction,
|
|
19
|
+
}
|
|
20
|
+
export const TYPES = {
|
|
21
|
+
player: 0,
|
|
22
|
+
camera: 1,
|
|
23
|
+
frontend: 2,
|
|
24
|
+
} as const
|
|
25
|
+
export const CONTROLS = {
|
|
26
|
+
"V": [0, 236, 320, 325],
|
|
27
|
+
"MOUSE RIGHT": [1, 6, 13, 66, 98, 220, 270, 271, 282, 283, 286, 287, 290, 333],
|
|
28
|
+
"MOUSE DOWN": [2, 4, 12, 67, 95, 112, 198, 221, 273, 291, 293, 332],
|
|
29
|
+
"S": [8, 33, 60, 72, 88, 126, 139, 149, 151, 196, 219, 233, 268, 269, 302],
|
|
30
|
+
"D": [9, 30, 35, 59, 64, 90, 195, 218, 235, 267, 278, 279, 342],
|
|
31
|
+
"PAGEUP": [10],
|
|
32
|
+
"PAGEDOWN": [11],
|
|
33
|
+
"SCROLLWHEEL DOWN": [14, 16, 50, 97, 180, 198, 242, 262, 334, 336],
|
|
34
|
+
"SCROLLWHEEL UP": [17, 96, 99, 115, 181, 241, 261, 335],
|
|
35
|
+
"ENTER": [18, 176, 191, 201, 215],
|
|
36
|
+
"LEFT MOUSE BUTTON": [18, 24, 122, 135, 142, 144, 176, 223, 229, 237, 257, 329, 346],
|
|
37
|
+
"SPACEBAR": [18, 22, 55, 76, 102, 143, 179, 203, 216, 255, 298, 321, 328, 353],
|
|
38
|
+
"LEFT ALT": [19],
|
|
39
|
+
"Z": [20, 48],
|
|
40
|
+
"LEFT SHIFT": [21, 61, 131, 137, 155, 209, 254, 340, 352],
|
|
41
|
+
"F": [23, 49, 56, 75, 144, 145, 251],
|
|
42
|
+
"E": [23, 38, 46, 51, 54, 86, 103, 119, 184, 206, 350, 351, 355, 356],
|
|
43
|
+
"RIGHT MOUSE BUTTON": [25, 68, 70, 91, 114, 177, 222, 225, 238, 330, 331, 347],
|
|
44
|
+
"C": [26, 79, 253, 319, 324],
|
|
45
|
+
"ARROW UP": [27, 172, 188, 300, 303],
|
|
46
|
+
"B": [29, 170, 305],
|
|
47
|
+
"W": [32, 61, 71, 77, 87, 111, 129, 136, 150, 232],
|
|
48
|
+
"A": [34, 63, 89, 124, 133, 147, 234, 338],
|
|
49
|
+
"LEFT CTRL": [36, 60, 62, 132, 210, 224, 280, 281, 326, 341, 343],
|
|
50
|
+
"TAB": [37, 192, 204, 211, 349],
|
|
51
|
+
"[": [39, 41, 43, 100, 116, 274, 275, 276, 277, 312],
|
|
52
|
+
"]": [40, 42, 197, 313],
|
|
53
|
+
"Q": [44, 52, 85, 138, 141, 152, 205, 264],
|
|
54
|
+
"R": [45, 80, 140, 250, 263, 310],
|
|
55
|
+
"G": [47, 58, 113, 183],
|
|
56
|
+
"F9": [56],
|
|
57
|
+
"F10": [57],
|
|
58
|
+
"X": [73, 105, 120, 131, 154, 186, 203, 214, 224, 252, 256, 296, 323, 337, 345, 349, 354, 357],
|
|
59
|
+
"H": [74, 101, 104, 304],
|
|
60
|
+
".": [81],
|
|
61
|
+
",": [82],
|
|
62
|
+
"=": [83],
|
|
63
|
+
"-": [84],
|
|
64
|
+
"NUMPAD-": [96],
|
|
65
|
+
"NUMPAD+": [97, 314],
|
|
66
|
+
"NUMPAD 6": [107, 109, 123, 125],
|
|
67
|
+
"NUMPAD 4": [108, 124],
|
|
68
|
+
"NUMPAD 5": [110, 112, 126, 128],
|
|
69
|
+
"NUMPAD 8": [111, 127],
|
|
70
|
+
"NUMPAD 7": [117],
|
|
71
|
+
"NUMPAD 9": [118],
|
|
72
|
+
"INSERT": [121],
|
|
73
|
+
"1": [157],
|
|
74
|
+
"2": [158],
|
|
75
|
+
"6": [159],
|
|
76
|
+
"3": [160],
|
|
77
|
+
"7": [161],
|
|
78
|
+
"8": [162],
|
|
79
|
+
"9": [163],
|
|
80
|
+
"4": [164],
|
|
81
|
+
"5": [165],
|
|
82
|
+
"F5": [166, 318, 327],
|
|
83
|
+
"F6": [167],
|
|
84
|
+
"F7": [168],
|
|
85
|
+
"F8": [169],
|
|
86
|
+
"F3": [170],
|
|
87
|
+
"CAPSLOCK": [137, 171, 217],
|
|
88
|
+
"ARROW DOWN": [173, 187, 233, 299],
|
|
89
|
+
"ARROW LEFT": [174, 189, 308],
|
|
90
|
+
"ARROW RIGHT": [175, 190, 307],
|
|
91
|
+
"BACKSPACE": [177, 194, 202],
|
|
92
|
+
"DELETE": [178, 214, 256, 296],
|
|
93
|
+
"Y": [178, 204, 246, 348],
|
|
94
|
+
"ESC": [177, 200, 202, 322],
|
|
95
|
+
"P": [199],
|
|
96
|
+
"NUMPAD ENTER": [201],
|
|
97
|
+
"PAGE DOWN": [207, 317],
|
|
98
|
+
"PAGE UP": [208, 316],
|
|
99
|
+
"HOME": [212, 213],
|
|
100
|
+
"T": [245, 309],
|
|
101
|
+
"M": [244, 301],
|
|
102
|
+
"N": [249, 306],
|
|
103
|
+
"~": [243],
|
|
104
|
+
"`": [243],
|
|
105
|
+
"K": [311],
|
|
106
|
+
"U": [303],
|
|
107
|
+
"F1": [288],
|
|
108
|
+
"F2": [289],
|
|
109
|
+
"F11": [344],
|
|
110
|
+
"SCROLLWHEEL BUTTON (PRESS)": [27, 348]
|
|
111
|
+
} as const
|
|
112
|
+
|
|
113
|
+
const binds = new Set<Bind>()
|
|
114
|
+
|
|
115
|
+
const on = ({
|
|
116
|
+
event,
|
|
117
|
+
key,
|
|
118
|
+
cb,
|
|
119
|
+
type = 'player',
|
|
120
|
+
}: Omit<Bind, 'event' | 'type'> & {
|
|
121
|
+
type?: Bind['type']
|
|
122
|
+
} & {
|
|
123
|
+
event: Exclude<Bind['event'], 'disable' | 'enable'>
|
|
124
|
+
}) => {
|
|
125
|
+
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
126
|
+
|
|
127
|
+
binds.add({
|
|
128
|
+
event, key, cb, type
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
const disable = ({
|
|
132
|
+
key,
|
|
133
|
+
type = 'player',
|
|
134
|
+
}: Pick<Bind, 'key'> & {
|
|
135
|
+
type?: Bind['type']
|
|
136
|
+
}) => {
|
|
137
|
+
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
138
|
+
|
|
139
|
+
binds.add({
|
|
140
|
+
event: 'disable', key, cb: () => {}, type
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
const enable = ({
|
|
144
|
+
key,
|
|
145
|
+
type = 'player',
|
|
146
|
+
}: Pick<Bind, 'key'> & {
|
|
147
|
+
type?: Bind['type']
|
|
148
|
+
}) => {
|
|
149
|
+
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
150
|
+
|
|
151
|
+
binds.add({
|
|
152
|
+
event: 'enable', key, cb: () => {}, type
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
pool(() => binds.forEach(({ event, key, cb, type }) => {
|
|
157
|
+
for (const index of CONTROLS[key]) {
|
|
158
|
+
if (!EVENTS[event](TYPES[type], index, true)) continue
|
|
159
|
+
cb()
|
|
160
|
+
break
|
|
161
|
+
}
|
|
162
|
+
}))
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @beta This API is in beta. Use with caution.
|
|
166
|
+
*/
|
|
167
|
+
export const control = {
|
|
168
|
+
on,
|
|
169
|
+
disable,
|
|
170
|
+
enable
|
|
171
|
+
}
|
package/client/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lenix",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.19",
|
|
4
4
|
"description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
|
|
5
5
|
"author": "Lenix",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"lenix",
|
|
10
|
-
"modules",
|
|
11
|
-
"typescript",
|
|
12
10
|
"fivem",
|
|
11
|
+
"typescript",
|
|
13
12
|
"lua",
|
|
14
13
|
"luarocks",
|
|
15
14
|
"oop",
|
|
16
15
|
"api",
|
|
17
|
-
"class",
|
|
18
|
-
"fxmanifest",
|
|
19
16
|
"eslint",
|
|
20
|
-
"linter"
|
|
17
|
+
"linter",
|
|
18
|
+
"modules",
|
|
19
|
+
"class",
|
|
20
|
+
"fxmanifest"
|
|
21
21
|
],
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"V": [0, 236, 320, 325],
|
|
3
|
-
"MOUSE RIGHT": [1, 6, 13, 66, 98, 220, 270, 271, 282, 283, 286, 287, 290, 333],
|
|
4
|
-
"MOUSE DOWN": [2, 4, 12, 67, 95, 112, 198, 221, 273, 291, 293, 332],
|
|
5
|
-
"S": [8, 33, 60, 72, 88, 126, 139, 149, 151, 196, 219, 233, 268, 269, 302],
|
|
6
|
-
"D": [9, 30, 35, 59, 64, 90, 195, 218, 235, 267, 278, 279, 342],
|
|
7
|
-
"PAGEUP": [10],
|
|
8
|
-
"PAGEDOWN": [11],
|
|
9
|
-
"SCROLLWHEEL DOWN": [14, 16, 50, 97, 180, 198, 242, 262, 334, 336],
|
|
10
|
-
"SCROLLWHEEL UP": [17, 96, 99, 115, 181, 241, 261, 335],
|
|
11
|
-
"ENTER": [18, 176, 191, 201, 215],
|
|
12
|
-
"LEFT MOUSE BUTTON": [18, 24, 122, 135, 142, 144, 176, 223, 229, 237, 257, 329, 346],
|
|
13
|
-
"SPACEBAR": [18, 22, 55, 76, 102, 143, 179, 203, 216, 255, 298, 321, 328, 353],
|
|
14
|
-
"LEFT ALT": [19],
|
|
15
|
-
"Z": [20, 48],
|
|
16
|
-
"LEFT SHIFT": [21, 61, 131, 137, 155, 209, 254, 340, 352],
|
|
17
|
-
"F": [23, 49, 56, 75, 144, 145, 251],
|
|
18
|
-
"E": [23, 38, 46, 51, 54, 86, 103, 119, 184, 206, 350, 351, 355, 356],
|
|
19
|
-
"RIGHT MOUSE BUTTON": [25, 68, 70, 91, 114, 177, 222, 225, 238, 330, 331, 347],
|
|
20
|
-
"C": [26, 79, 253, 319, 324],
|
|
21
|
-
"ARROW UP": [27, 172, 188, 300, 303],
|
|
22
|
-
"B": [29, 170, 305],
|
|
23
|
-
"W": [32, 61, 71, 77, 87, 111, 129, 136, 150, 232],
|
|
24
|
-
"A": [34, 63, 89, 124, 133, 147, 234, 338],
|
|
25
|
-
"LEFT CTRL": [36, 60, 62, 132, 210, 224, 280, 281, 326, 341, 343],
|
|
26
|
-
"TAB": [37, 192, 204, 211, 349],
|
|
27
|
-
"[": [39, 41, 43, 100, 116, 274, 275, 276, 277, 312],
|
|
28
|
-
"]": [40, 42, 197, 313],
|
|
29
|
-
"Q": [44, 52, 85, 138, 141, 152, 205, 264],
|
|
30
|
-
"R": [45, 80, 140, 250, 263, 310],
|
|
31
|
-
"G": [47, 58, 113, 183],
|
|
32
|
-
"F9": [56],
|
|
33
|
-
"F10": [57],
|
|
34
|
-
"X": [73, 105, 120, 131, 154, 186, 203, 214, 224, 252, 256, 296, 323, 337, 345, 349, 354, 357],
|
|
35
|
-
"H": [74, 101, 104, 304],
|
|
36
|
-
".": [81],
|
|
37
|
-
",": [82],
|
|
38
|
-
"=": [83],
|
|
39
|
-
"-": [84],
|
|
40
|
-
"NUMPAD-": [96],
|
|
41
|
-
"NUMPAD+": [97, 314],
|
|
42
|
-
"NUMPAD 6": [107, 109, 123, 125],
|
|
43
|
-
"NUMPAD 4": [108, 124],
|
|
44
|
-
"NUMPAD 5": [110, 112, 126, 128],
|
|
45
|
-
"NUMPAD 8": [111, 127],
|
|
46
|
-
"NUMPAD 7": [117],
|
|
47
|
-
"NUMPAD 9": [118],
|
|
48
|
-
"INSERT": [121],
|
|
49
|
-
"1": [157],
|
|
50
|
-
"2": [158],
|
|
51
|
-
"6": [159],
|
|
52
|
-
"3": [160],
|
|
53
|
-
"7": [161],
|
|
54
|
-
"8": [162],
|
|
55
|
-
"9": [163],
|
|
56
|
-
"4": [164],
|
|
57
|
-
"5": [165],
|
|
58
|
-
"F5": [166, 318, 327],
|
|
59
|
-
"F6": [167],
|
|
60
|
-
"F7": [168],
|
|
61
|
-
"F8": [169],
|
|
62
|
-
"F3": [170],
|
|
63
|
-
"CAPSLOCK": [137, 171, 217],
|
|
64
|
-
"ARROW DOWN": [173, 187, 233, 299],
|
|
65
|
-
"ARROW LEFT": [174, 189, 308],
|
|
66
|
-
"ARROW RIGHT": [175, 190, 307],
|
|
67
|
-
"BACKSPACE": [177, 194, 202],
|
|
68
|
-
"DELETE": [178, 214, 256, 296],
|
|
69
|
-
"Y": [178, 204, 246, 348],
|
|
70
|
-
"ESC": [177, 200, 202, 322],
|
|
71
|
-
"P": [199],
|
|
72
|
-
"NUMPAD ENTER": [201],
|
|
73
|
-
"PAGE DOWN": [207, 317],
|
|
74
|
-
"PAGE UP": [208, 316],
|
|
75
|
-
"HOME": [212, 213],
|
|
76
|
-
"T": [245, 309],
|
|
77
|
-
"M": [244, 301],
|
|
78
|
-
"N": [249, 306],
|
|
79
|
-
"~": [243],
|
|
80
|
-
"`": [243],
|
|
81
|
-
"K": [311],
|
|
82
|
-
"U": [303],
|
|
83
|
-
"F1": [288],
|
|
84
|
-
"F2": [289],
|
|
85
|
-
"F11": [344],
|
|
86
|
-
"SCROLLWHEEL BUTTON (PRESS)": [27, 348]
|
|
87
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, noop, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
setTick(() => onKey(DisableControlAction, key, noop, true) )
|
|
8
|
-
} catch (error) {
|
|
9
|
-
console.error(error)
|
|
10
|
-
}
|
|
11
|
-
return true
|
|
12
|
-
}
|
package/client/control/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { trace } from '../../../tr_lib/package/src/shared'
|
|
2
|
-
import binds from './binds.json'
|
|
3
|
-
|
|
4
|
-
export type Bind = keyof typeof binds
|
|
5
|
-
export const noop = () => {}
|
|
6
|
-
|
|
7
|
-
export const onKey = (Function: Function, key: Bind, callback: Function, ...parameters: any) => {
|
|
8
|
-
for (const index of binds[key]) {
|
|
9
|
-
if (Function(0, index, ...parameters)) {
|
|
10
|
-
if (callback) {
|
|
11
|
-
callback()
|
|
12
|
-
}
|
|
13
|
-
break
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const isInvalidKey = (key: Bind) => {
|
|
19
|
-
if (!binds[key]) {
|
|
20
|
-
trace(`Invalid control key passed: ${key}`)
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const getKeyByIndex = (index: number) => {
|
|
26
|
-
for (const key of Object.keys(binds)) {
|
|
27
|
-
for (const value of binds[key as Bind]) {
|
|
28
|
-
if (value == index) {
|
|
29
|
-
return key
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
import disable from './disable'
|
|
36
|
-
import onDisabled from './onDisabled'
|
|
37
|
-
import onHold from './onHold'
|
|
38
|
-
import onPress from './onPress'
|
|
39
|
-
import onRelease from './onRelease'
|
|
40
|
-
import onReleased from './onReleased'
|
|
41
|
-
|
|
42
|
-
export default { disable, onDisabled, onHold, onPress, onRelease, onReleased }
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, noop, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind, callback: Function) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
setTick(() => {
|
|
8
|
-
onKey(DisableControlAction, key, noop, true)
|
|
9
|
-
onKey(IsDisabledControlJustPressed, key, callback)
|
|
10
|
-
})
|
|
11
|
-
} catch (error) {
|
|
12
|
-
console.error(error)
|
|
13
|
-
}
|
|
14
|
-
return true
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind, callback: Function) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
setTick(() => onKey(IsControlPressed, key, callback))
|
|
8
|
-
} catch (error) {
|
|
9
|
-
console.error(error)
|
|
10
|
-
}
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind, callback: Function) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
setTick(() => onKey(IsControlJustPressed, key, callback))
|
|
8
|
-
} catch (error) {
|
|
9
|
-
console.error(error)
|
|
10
|
-
}
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind, callback: Function) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
setTick(() => onKey(IsControlJustReleased, key, callback))
|
|
8
|
-
} catch (error) {
|
|
9
|
-
console.error(error)
|
|
10
|
-
}
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Bind, isInvalidKey, onKey } from ".."
|
|
2
|
-
|
|
3
|
-
export default (key: Bind, callback: Function) => {
|
|
4
|
-
if (isInvalidKey(key)) return false
|
|
5
|
-
try {
|
|
6
|
-
setTick(() => onKey(IsControlReleased, key, callback))
|
|
7
|
-
} catch (error) {
|
|
8
|
-
console.error(error)
|
|
9
|
-
}
|
|
10
|
-
return true
|
|
11
|
-
}
|