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

View File

@ -12,38 +12,7 @@ import {
RageFW_ServerReturn, RageFW_ServerReturn,
} from '../types' } 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 { 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 { private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
return nativeEvents.includes(eventName) return nativeEvents.includes(eventName)
} }