v0.1.0 #1

Merged
sashagoncharov19 merged 32 commits from dev into unstable 2024-06-15 13:48:41 +00:00
4 changed files with 24 additions and 11 deletions
Showing only changes of commit 2df12062d0 - Show all commits

View File

@ -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

View File

@ -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>(

View File

@ -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,

View File

@ -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