lenix 1.7.20 → 1.7.22
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 +5 -2
- package/client/blip.ts +2 -2
- package/client/cam.ts +0 -2
- package/client/client.ts +1 -2
- package/client/control.ts +6 -6
- package/client/index.ts +0 -1
- package/client/nearest.ts +3 -4
- package/client/pool.ts +0 -1
- package/nui/{trigger.ts → fetch.ts} +4 -3
- package/nui/focus.ts +23 -6
- package/nui/index.ts +1 -1
- package/nui/on.ts +0 -1
- package/package.json +2 -2
- package/shared/index.ts +1 -0
- package/{client → shared}/timer.ts +7 -2
- package/shared/types.ts +3 -12
package/client/_init.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Request } from '../shared/types.ts'
|
|
2
2
|
import { onNui } from './nui.ts'
|
|
3
3
|
|
|
4
|
-
onNui<
|
|
4
|
+
onNui<Request<true, '__nuiFocus', {
|
|
5
|
+
keyboard: boolean,
|
|
6
|
+
cursor: boolean
|
|
7
|
+
}>>('__nuiFocus', ({
|
|
5
8
|
keyboard,
|
|
6
9
|
cursor
|
|
7
10
|
}) => {
|
package/client/blip.ts
CHANGED
package/client/cam.ts
CHANGED
|
@@ -64,7 +64,6 @@ const toggleCam = ({
|
|
|
64
64
|
}) => {
|
|
65
65
|
setTimeout(() => {
|
|
66
66
|
SetCamActive(cam, state)
|
|
67
|
-
// deno-lint-ignore no-boolean-literal-for-arguments
|
|
68
67
|
RenderScriptCams(state, state, delay, true, state)
|
|
69
68
|
DoScreenFadeIn(fadeIn)
|
|
70
69
|
}, delay)
|
|
@@ -89,7 +88,6 @@ const create = ({
|
|
|
89
88
|
rotationOrder = details?.rotationOrder ?? 0
|
|
90
89
|
|
|
91
90
|
DoScreenFadeOut(fadeOut)
|
|
92
|
-
// deno-lint-ignore no-boolean-literal-for-arguments
|
|
93
91
|
const cam = CreateCamWithParams(
|
|
94
92
|
'DEFAULT_SCRIPTED_CAMERA',
|
|
95
93
|
coords[0],
|
package/client/client.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { JsonValue } from '@lenix/lenix'
|
|
1
2
|
import { repeat } from '../shared/repeat.ts'
|
|
2
3
|
import type { Vec3, Vec4 } from '../shared/types.ts'
|
|
3
4
|
|
|
4
|
-
type JsonPrimitive = string | number | boolean | null
|
|
5
|
-
type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
|
|
6
5
|
|
|
7
6
|
export const client = {
|
|
8
7
|
entity: {
|
package/client/control.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { pool } from './pool'
|
|
|
4
4
|
export interface Bind {
|
|
5
5
|
event: keyof typeof EVENTS,
|
|
6
6
|
key: keyof typeof CONTROLS,
|
|
7
|
-
|
|
7
|
+
onEvent: () => void,
|
|
8
8
|
type: keyof typeof TYPES,
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -115,7 +115,7 @@ const binds = new Set<Bind>()
|
|
|
115
115
|
const on = ({
|
|
116
116
|
event,
|
|
117
117
|
key,
|
|
118
|
-
cb,
|
|
118
|
+
onEvent: cb,
|
|
119
119
|
type = 'player',
|
|
120
120
|
}: Omit<Bind, 'event' | 'type'> & {
|
|
121
121
|
type?: Bind['type']
|
|
@@ -125,7 +125,7 @@ const on = ({
|
|
|
125
125
|
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
126
126
|
|
|
127
127
|
binds.add({
|
|
128
|
-
event, key, cb, type
|
|
128
|
+
event, key, onEvent: cb, type
|
|
129
129
|
})
|
|
130
130
|
}
|
|
131
131
|
const disable = ({
|
|
@@ -137,7 +137,7 @@ const disable = ({
|
|
|
137
137
|
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
138
138
|
|
|
139
139
|
binds.add({
|
|
140
|
-
event: 'disable', key,
|
|
140
|
+
event: 'disable', key, onEvent: () => {}, type
|
|
141
141
|
})
|
|
142
142
|
}
|
|
143
143
|
const enable = ({
|
|
@@ -149,11 +149,11 @@ const enable = ({
|
|
|
149
149
|
asserts(CONTROLS[key], `Could not find key<${key}>`)
|
|
150
150
|
|
|
151
151
|
binds.add({
|
|
152
|
-
event: 'enable', key,
|
|
152
|
+
event: 'enable', key, onEvent: () => {}, type
|
|
153
153
|
})
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
pool(() => binds.forEach(({ event, key, cb, type }) => {
|
|
156
|
+
pool(() => binds.forEach(({ event, key, onEvent: cb, type }) => {
|
|
157
157
|
for (const index of CONTROLS[key]) {
|
|
158
158
|
if (!EVENTS[event](TYPES[type], index, true)) continue
|
|
159
159
|
cb()
|
package/client/index.ts
CHANGED
package/client/nearest.ts
CHANGED
|
@@ -48,10 +48,9 @@ const player = (
|
|
|
48
48
|
|
|
49
49
|
if (playerId !== PlayerPedId() || includePlayer) {
|
|
50
50
|
const playerPed = GetPlayerPed(playerId)
|
|
51
|
-
// deno-lint-ignore no-boolean-literal-for-arguments
|
|
52
51
|
const vehicle = GetVehiclePedIsIn(playerPed, false)
|
|
53
52
|
const playerCoords: Vec3 = vehicle === 0
|
|
54
|
-
? client.entity.coords(
|
|
53
|
+
? client.entity.coords(playerPed, true)
|
|
55
54
|
: GetWorldPositionOfEntityBone(playerPed, 0) as Vec3
|
|
56
55
|
|
|
57
56
|
const distance = Vdist(
|
|
@@ -85,14 +84,14 @@ const player = (
|
|
|
85
84
|
* Finds the nearest vehicle around an entity.
|
|
86
85
|
*/
|
|
87
86
|
const vehicle = (entity: number, radialSpace: number): number | undefined => {
|
|
88
|
-
const coords: Vec3 = client.entity.coords(
|
|
87
|
+
const coords: Vec3 = client.entity.coords(entity, true)
|
|
89
88
|
const vehicles = GetGamePool('CVehicle') as number[]
|
|
90
89
|
|
|
91
90
|
let closest: number | undefined
|
|
92
91
|
let closestDistance = radialSpace
|
|
93
92
|
|
|
94
93
|
for (const vehicle of vehicles) {
|
|
95
|
-
const vehCoords: Vec3 = client.entity.coords(
|
|
94
|
+
const vehCoords: Vec3 = client.entity.coords(vehicle, true)
|
|
96
95
|
const x = coords[0] - vehCoords[0]
|
|
97
96
|
const y = coords[1] - vehCoords[1]
|
|
98
97
|
const z = coords[2] - vehCoords[2]
|
package/client/pool.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { JsonValue } from '@lenix/lenix'
|
|
1
2
|
import type { Request } from '../shared/types.ts'
|
|
2
3
|
|
|
3
4
|
declare function GetParentResourceName(): string
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Fetchs a typed request from the NUI browser to the game client.
|
|
7
8
|
*/
|
|
8
|
-
export const
|
|
9
|
+
export const fetchNui = async <T extends Request<JsonValue, string, object>>(
|
|
9
10
|
id: T[1],
|
|
10
11
|
data: T[2]
|
|
11
12
|
): Promise<T[0]> => {
|
|
@@ -19,6 +20,6 @@ export const triggerNui = async <T extends Request<unknown, string, object>>(
|
|
|
19
20
|
})
|
|
20
21
|
return await response.json()
|
|
21
22
|
} catch (e) {
|
|
22
|
-
throw
|
|
23
|
+
throw `Error occured while emiting an nui<${id}>.\n${e}`
|
|
23
24
|
}
|
|
24
25
|
}
|
package/nui/focus.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Request } from '../shared/types.ts'
|
|
2
|
+
import { fetchNui } from './fetch.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Requests keyboard and cursor focus for the NUI browser.
|
|
6
6
|
*/
|
|
7
|
-
export const focus = (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const focus = (exclude?: 'keyboard' | 'cursor'): Promise<true> => {
|
|
8
|
+
return fetchNui<Request<true, '__nuiFocus', {
|
|
9
|
+
keyboard: boolean,
|
|
10
|
+
cursor: boolean
|
|
11
|
+
}>>('__nuiFocus', { keyboard: exclude === 'keyboard' ? false : true, cursor: exclude === 'cursor' ? false : true })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const unFocus = (
|
|
15
|
+
key: KeyboardEvent['key'],
|
|
16
|
+
onEvent: () => void
|
|
17
|
+
) => {
|
|
18
|
+
|
|
19
|
+
const handler = (e: KeyboardEvent) => {
|
|
20
|
+
if (e.key !== key) return
|
|
21
|
+
|
|
22
|
+
onEvent()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
window.addEventListener('keydown', handler)
|
|
26
|
+
return () => window.removeEventListener('keydown', handler)
|
|
27
|
+
}
|
package/nui/index.ts
CHANGED
package/nui/on.ts
CHANGED
|
@@ -6,7 +6,6 @@ interface Listener<T extends unknown[]> {
|
|
|
6
6
|
}
|
|
7
7
|
const events = new Map<string, Set<Listener<unknown[]>>>()
|
|
8
8
|
|
|
9
|
-
// deno-lint-ignore no-window no-window-prefix no-unused-vars
|
|
10
9
|
const handler = (event: MessageEvent) => {
|
|
11
10
|
const { id, params } = event.data
|
|
12
11
|
const callbacks = events.get(id)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lenix",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.22",
|
|
4
4
|
"description": "Typed FiveM utilities for client, server, shared, and NUI scripts",
|
|
5
5
|
"author": "Lenix",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"typescript": "^5"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lenix/lenix": "npm:@jsr/lenix__lenix"
|
|
50
|
+
"@lenix/lenix": "npm:@jsr/lenix__lenix@1.8.16"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/shared/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Starts a client timer using FiveM game time.
|
|
3
3
|
*/
|
|
4
|
-
export const useTimer = (
|
|
4
|
+
export const useTimer = ({
|
|
5
|
+
duration,
|
|
6
|
+
updateInterval,
|
|
7
|
+
onTick,
|
|
8
|
+
onEnd
|
|
9
|
+
}: {
|
|
5
10
|
duration: number,
|
|
6
11
|
updateInterval: number,
|
|
7
12
|
onTick: (timeLeft: number) => void,
|
|
8
13
|
onEnd: () => void
|
|
9
|
-
): () => void => {
|
|
14
|
+
}): () => void => {
|
|
10
15
|
const start = GetGameTimer()
|
|
11
16
|
|
|
12
17
|
const interval = setInterval(() => {
|
package/shared/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { JsonValue } from "@lenix/lenix"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Three-dimensional coordinates plus heading.
|
|
3
5
|
*/
|
|
@@ -17,19 +19,8 @@ export type Event<Id extends string, Params extends unknown[] = never> = [Id, Pa
|
|
|
17
19
|
* Typed request tuple containing a response type, request id, and object payload.
|
|
18
20
|
*/
|
|
19
21
|
export type Request<
|
|
20
|
-
Response,
|
|
22
|
+
Response extends JsonValue,
|
|
21
23
|
Id extends string,
|
|
22
24
|
Params extends object = { [key: string]: unknown }
|
|
23
25
|
> = Params extends readonly unknown[] ? never
|
|
24
26
|
: [Response, Id, Params]
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Internal NUI requests used by Lenix helpers. DO NOT USE
|
|
29
|
-
*/
|
|
30
|
-
export interface _InternalRequests {
|
|
31
|
-
focus: Request<true, '__nuiFocus', {
|
|
32
|
-
keyboard: boolean,
|
|
33
|
-
cursor: boolean
|
|
34
|
-
}>
|
|
35
|
-
}
|