lenix 1.7.11 → 1.7.12

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/_init.ts CHANGED
@@ -1,4 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
1
  import type { _InternalRequests } from '../shared/types.ts'
3
2
  import { onNui } from './nui.ts'
4
3
 
package/client/blip.ts CHANGED
@@ -1,5 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
-
3
1
  import type { Vec4 } from '../shared/types.ts'
4
2
 
5
3
  export interface Blip {
package/client/cam.ts CHANGED
@@ -1,5 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
-
3
1
  import type { Vec4 } from '../shared/types.ts'
4
2
 
5
3
  const cams = new Set<number>()
package/client/client.ts CHANGED
@@ -138,8 +138,15 @@ export const client = {
138
138
  },
139
139
 
140
140
  /* */
141
- coords(excludeH?: true, isAlive?: boolean) {
142
- return client.entity.coords(this.entity(), excludeH, isAlive)
141
+ coords<T extends true | undefined = undefined>(
142
+ excludeH?: T,
143
+ isAlive?: boolean
144
+ ): T extends true ? Vec3 : Vec4 {
145
+ return (
146
+ excludeH === true
147
+ ? client.entity.coords(this.entity(), true, isAlive)
148
+ : client.entity.coords(this.entity(), false, isAlive)
149
+ ) as T extends true ? Vec3 : Vec4;
143
150
  },
144
151
 
145
152
  /* */
@@ -0,0 +1,87 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,42 @@
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 }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
package/client/nearest.ts CHANGED
@@ -1,4 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
1
  import type { Vec3 } from '../shared/types.ts'
3
2
  import { client } from './client.ts'
4
3
 
package/client/nui.ts CHANGED
@@ -1,4 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
1
  import type { Request } from '../shared/types.ts'
3
2
 
4
3
  /**
package/client/pool.ts CHANGED
@@ -1,4 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
1
  const tasks = new Set<() => void>()
3
2
  let running = false
4
3
 
package/client/timer.ts CHANGED
@@ -1,5 +1,3 @@
1
- // deno-lint-ignore-file no-undef
2
-
3
1
  /**
4
2
  * Starts a client timer using FiveM game time.
5
3
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lenix",
3
- "version": "1.7.11",
3
+ "version": "1.7.12",
4
4
  "description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
5
5
  "author": "Lenix",
6
6
  "license": "MIT",
@@ -9,13 +9,13 @@
9
9
  "lenix",
10
10
  "modules",
11
11
  "typescript",
12
+ "fivem",
12
13
  "lua",
13
14
  "luarocks",
14
15
  "oop",
15
- "fivem",
16
- "fxmanifest",
17
16
  "api",
18
17
  "class",
18
+ "fxmanifest",
19
19
  "eslint",
20
20
  "linter"
21
21
  ],
@@ -36,13 +36,17 @@
36
36
  "nui"
37
37
  ],
38
38
  "scripts": {
39
- "prepare": "rm -rf ./client ./server ./shared ./nui && cp -R ../modules/client ./client && cp -R ../modules/server ./server && cp -R ../modules/shared ./shared && cp -R ../modules/nui ./nui && cp -R ../LICENSE ./",
40
- "packpreview": "rm -rf ./package-preview && mkdir -p ./package-preview && bun pm pack --destination ./package-preview && tar -xzf ./package-preview/*.tgz -C ./package-preview && find ./package-preview/package -type f | sort"
39
+ "packprev": "rm -rf ./package-preview && mkdir -p ./package-preview && bun pm pack --destination ./package-preview && tar -xzf ./package-preview/*.tgz -C ./package-preview && find ./package-preview/package -type f | sort"
41
40
  },
42
41
  "devDependencies": {
42
+ "@citizenfx/client": "^2.0.33230-1",
43
+ "@citizenfx/server": "^2.0.32561-1",
43
44
  "@types/bun": "latest"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "typescript": "^5"
48
+ },
49
+ "dependencies": {
50
+ "@lenix/lenix": "npm:@jsr/lenix__lenix"
47
51
  }
48
52
  }
package/shared/api.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { asserts } from "@lenix/lenix"
2
+ import type { Fn } from "./types"
3
+
4
+ interface Api {
5
+ [resource: number]: never
6
+ [resource: string]: {
7
+ [method: number]: never
8
+ [method: string]: <T extends Fn<unknown, any[]>>(...args: Parameters<T>) => ReturnType<T>
9
+ }
10
+ }
11
+
12
+ export const api: Api = new Proxy(globalThis.exports, {
13
+ get(target, resource: string) {
14
+ const value = target[resource]
15
+
16
+ asserts(
17
+ GetResourceState(resource) === 'started' && value,
18
+ `<${resource}> is not started yet to be invoked`
19
+ )
20
+
21
+ return new Proxy(value, {
22
+ get(target, method: string) {
23
+ const value = target[method]
24
+
25
+ asserts(
26
+ value,
27
+ `Could not find <${method}> export in ${resource}`
28
+ )
29
+
30
+ return value
31
+ },
32
+ })
33
+ },
34
+ }) as unknown as Api
package/shared/index.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * Shared helpers that can be used from both client and server contexts.
5
5
  */
6
6
 
7
- export * from './assert.ts'
7
+ export * from './api.ts'
8
8
  export * from './types.ts'
9
9
  export * from './repeat.ts'
package/shared/types.ts CHANGED
@@ -33,3 +33,5 @@ export interface _InternalRequests {
33
33
  cursor: boolean
34
34
  }>
35
35
  }
36
+
37
+ export type Fn<Return, Args extends unknown[] = []> = (...args: Args) => Return
package/shared/assert.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Asserts that a condition is true and narrows its type.
3
- */
4
- export const asserts = <T extends boolean>(
5
- condition: T,
6
- errorMessage = 'assertion did not passed successfuly'
7
- ): asserts condition => {
8
- if (condition) return
9
-
10
- throw new Error(errorMessage)
11
- }