fix: missing types
This commit is contained in:
parent
f08291eace
commit
1467bb65b0
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user