Rpc integration + type fixes #3

Merged
rilaxik merged 26 commits from dev into master 2024-10-28 12:13:19 +00:00
2 changed files with 9 additions and 40 deletions
Showing only changes of commit 987bba717e - Show all commits

View File

@ -8,11 +8,11 @@ import {
RageFW_CefArgs,
RageFW_CefEvent,
RageFW_CefReturn,
RageFW_ClientEventArguments,
RageFW_ClientEventReturn,
RageFW_ClientArgs,
RageFW_ClientReturn,
RageFW_ClientServerEvent,
RageFW_ClientServerEventArguments,
RageFW_ClientServerEventReturn,
RageFW_ClientServerArgs,
RageFW_ClientServerReturn,
} from '../types'
export class Player {
@ -21,18 +21,18 @@ export class Player {
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
eventName: EventName,
...args: _ClientEventHasArgs<EventName> extends true
? [RageFW_ClientEventArguments<EventName>]
? [RageFW_ClientArgs<EventName>]
: []
): Promise<RageFW_ClientEventReturn<EventName>> {
return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args)
): Promise<RageFW_ClientReturn<EventName>> {
return rpc.call<RageFW_ClientReturn<EventName>>(eventName, args)
}
public triggerServer<EventName extends RageFW_ClientServerEvent>(
eventName: EventName,
...args: _ServerEventHasArgs<EventName> extends true
? [RageFW_ClientServerEventArguments<EventName>]
? [RageFW_ClientServerArgs<EventName>]
: []
): Promise<RageFW_ClientServerEventReturn<EventName>> {
): Promise<RageFW_ClientServerReturn<EventName>> {
return rpc.callServer(eventName, args)
}

View File

@ -12,38 +12,7 @@ import {
RageFW_ServerReturn,
} from '../types'
type MiddlewarePoolServer<EventName extends RageFW_ServerEvent> = Partial<{
[K in EventName]: {
mwName: string
mw: MiddlewareFunction<K>
}
}>
export type MiddlewareFunction<EventName extends RageFW_ServerEvent> = (
player: PlayerMp,
eventName: EventName,
...args: _ServerEventHasArgs<EventName> extends true
? [RageFW_ServerArgs<EventName>]
: []
) => void
export class Server {
private middlewarePool: MiddlewarePoolServer<RageFW_ServerEvent> = {}
public use<EventName extends RageFW_ServerEvent>(
mwName: string,
eventName: EventName,
mw: MiddlewareFunction<EventName>,
) {
this.middlewarePool = {
...this.middlewarePool,
[eventName]: {
mwName,
mw,
},
}
}
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
return nativeEvents.includes(eventName)
}