Release v.0.1.0 #2
@ -4,16 +4,22 @@ import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
||||
/**
|
||||
* Union of all available client event names
|
||||
* These only include custom events
|
||||
* These include custom and system events
|
||||
*/
|
||||
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
||||
export type RageFW_ClientEvent =
|
||||
| keyof RageFW_ICustomClientEvent
|
||||
| keyof IClientEvents
|
||||
|
||||
/**
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
* These include custom and system events
|
||||
*/
|
||||
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
|
||||
Parameters<RageFW_ICustomClientEvent[K]>
|
||||
K extends keyof RageFW_ICustomClientEvent
|
||||
? Parameters<RageFW_ICustomClientEvent[K]>
|
||||
: K extends keyof IClientEvents
|
||||
? Parameters<IClientEvents[K]>
|
||||
: never
|
||||
|
||||
/**
|
||||
* Callback (function) for an event, name of which you pass as a generic
|
||||
|
@ -34,7 +34,7 @@ class Server {
|
||||
rpc.register(
|
||||
eventName,
|
||||
async (args: RageFW_ServerEventArguments<EventName>, info) => {
|
||||
callback(info.player as PlayerMp, args)
|
||||
callback([info.player as PlayerMp, ...args])
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -43,7 +43,11 @@ class Server {
|
||||
eventName: EventName,
|
||||
callback: RageFW_ServerEventCallbackNative<EventName>,
|
||||
): void {
|
||||
mp.events.add(eventName, callback)
|
||||
mp.events.add(
|
||||
eventName,
|
||||
(...args: Parameters<IServerEvents[EventName]>) =>
|
||||
callback([...args]),
|
||||
)
|
||||
}
|
||||
|
||||
public register<EventName extends RageFW_ServerEvent>(
|
||||
|
@ -54,8 +54,7 @@ export type RageFW_ServerEventReturn<K extends RageFW_ServerEvent> =
|
||||
export type RageFW_ServerEventCallbackCustom<
|
||||
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
|
||||
> = (
|
||||
player: PlayerMp,
|
||||
args: RageFW_ServerEventArguments<K>,
|
||||
payload: [player: PlayerMp, ...args: RageFW_ServerEventArguments<K>],
|
||||
) => RageFW_ServerEventReturn<K>
|
||||
|
||||
/**
|
||||
@ -64,7 +63,7 @@ export type RageFW_ServerEventCallbackCustom<
|
||||
*/
|
||||
export type RageFW_ServerEventCallbackNative<
|
||||
K extends keyof IServerEvents = keyof IServerEvents,
|
||||
> = IServerEvents[K]
|
||||
> = (payload: Parameters<IServerEvents[K]>) => ReturnType<IServerEvents[K]>
|
||||
|
||||
export type _ServerEventHasArgs<
|
||||
EventName extends keyof RageFW_ICustomServerEvent,
|
||||
|
8
shared-types/types/types/index.d.ts
vendored
8
shared-types/types/types/index.d.ts
vendored
@ -1,7 +1,11 @@
|
||||
declare module 'rage-fw-shared-types' {
|
||||
export interface RageFW_ICustomServerEvent {}
|
||||
export interface RageFW_ICustomServerEvent {
|
||||
test(test: string): void
|
||||
}
|
||||
|
||||
export interface RageFW_ICustomClientEvent {}
|
||||
export interface RageFW_ICustomClientEvent {
|
||||
test(test: string): void
|
||||
}
|
||||
|
||||
export interface RageFW_ICustomCefEvent {
|
||||
test(test: string): void
|
||||
|
Loading…
Reference in New Issue
Block a user