Consistency updates + cleanup #5
@ -35,19 +35,19 @@ export class Player {
|
||||
>(eventName, args)
|
||||
}
|
||||
|
||||
public async triggerBrowser<EventName extends T.RageFW_CefEvent>(
|
||||
public async triggerBrowser<EventName extends T.RageFW_BrowserEvent>(
|
||||
eventName: EventName,
|
||||
...args: T._CefEventHasArgs<EventName> extends true
|
||||
? [T.RageFW_CefArgs<EventName>]
|
||||
...args: T._BrowserEventHasArgs<EventName> extends true
|
||||
? [T.RageFW_BrowserArgs<EventName>]
|
||||
: []
|
||||
): Promise<T.RageFW_CefReturn<EventName>> {
|
||||
): Promise<T.RageFW_BrowserReturn<EventName>> {
|
||||
if (!this._browser)
|
||||
throw new Error('You need to initialize browser first')
|
||||
|
||||
return await rpc.callBrowser<
|
||||
typeof args,
|
||||
EventName,
|
||||
T.RageFW_CefReturn<EventName>
|
||||
T.RageFW_BrowserReturn<EventName>
|
||||
>(eventName, args)
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,21 @@ import type { RageFW_ICustomBrowserEvent } from '@entityseven/rage-fw-shared-typ
|
||||
* Union of all available browser event names callable from client
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_CefEvent = keyof RageFW_ICustomBrowserEvent
|
||||
export type RageFW_BrowserEvent = keyof RageFW_ICustomBrowserEvent
|
||||
|
||||
/**
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_CefArgs<K extends RageFW_CefEvent> = Parameters<
|
||||
export type RageFW_BrowserArgs<K extends RageFW_BrowserEvent> = Parameters<
|
||||
RageFW_ICustomBrowserEvent[K]
|
||||
>
|
||||
|
||||
export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
||||
export type RageFW_BrowserReturn<K extends RageFW_BrowserEvent> = ReturnType<
|
||||
RageFW_ICustomBrowserEvent[K]
|
||||
>
|
||||
|
||||
export type _CefEventHasArgs<
|
||||
export type _BrowserEventHasArgs<
|
||||
EventName extends keyof RageFW_ICustomBrowserEvent,
|
||||
> = keyof RageFW_ICustomBrowserEvent extends never
|
||||
? false
|
||||
|
@ -15,7 +15,7 @@ export class Player {
|
||||
public async triggerBrowser<EventName extends T.RageFW_BrowserEvent>(
|
||||
player: PlayerMp,
|
||||
eventName: EventName,
|
||||
...args: T._CefEventHasArgs<EventName> extends true
|
||||
...args: T._BrowserEventHasArgs<EventName> extends true
|
||||
? [T.RageFW_BrowserArgs<EventName>]
|
||||
: []
|
||||
): Promise<T.RageFW_BrowserReturn<EventName>> {
|
||||
|
@ -25,7 +25,7 @@ export type RageFW_BrowserReturn<K extends RageFW_BrowserEvent> = ReturnType<
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export type _CefEventHasArgs<
|
||||
export type _BrowserEventHasArgs<
|
||||
EventName extends keyof RageFW_ICustomBrowserEvent,
|
||||
> = keyof RageFW_ICustomBrowserEvent extends never
|
||||
? false
|
||||
|
Loading…
Reference in New Issue
Block a user