renamed types to follow similar naming pattern
This commit is contained in:
parent
22ed5c4588
commit
75b528ca45
@ -4,15 +4,15 @@ import {
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArguments,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefCallback,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientArguments,
|
||||
RageFW_ClientArgs,
|
||||
RageFW_ClientReturn,
|
||||
RageFW_ICustomCefEvent,
|
||||
RageFW_ICustomClientEvent,
|
||||
RageFW_ICustomServerEvent,
|
||||
RageFW_ServerArguments,
|
||||
RageFW_ServerArgs,
|
||||
RageFW_ServerReturn,
|
||||
} from './types'
|
||||
|
||||
@ -29,7 +29,7 @@ class Cef {
|
||||
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||
eventName: EventName,
|
||||
...args: _CefEventHasArgs<EventName> extends true
|
||||
? [RageFW_CefArguments<EventName>]
|
||||
? [RageFW_CefArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_CefReturn<EventName>> {
|
||||
if ('mp' in window) {
|
||||
@ -44,7 +44,7 @@ class Cef {
|
||||
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ServerArguments<EventName>]
|
||||
? [RageFW_ServerArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ServerReturn<EventName>> {
|
||||
if ('mp' in window) {
|
||||
@ -59,7 +59,7 @@ class Cef {
|
||||
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ClientEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientArguments<EventName>]
|
||||
? [RageFW_ClientArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientReturn<EventName>> {
|
||||
if ('mp' in window) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { RageFW_ICustomCefEvent } from 'rage-fw-shared-types'
|
||||
|
||||
export { RageFW_ICustomCefEvent } from 'rage-fw-shared-types'
|
||||
|
||||
/**
|
||||
@ -11,7 +12,7 @@ export type RageFW_CefEvent = keyof RageFW_ICustomCefEvent
|
||||
* Array of arguments of an event you pass as a generic
|
||||
* These only include custom cef events
|
||||
*/
|
||||
export type RageFW_CefArguments<K extends RageFW_CefEvent> = Parameters<
|
||||
export type RageFW_CefArgs<K extends RageFW_CefEvent> = Parameters<
|
||||
RageFW_ICustomCefEvent[K]
|
||||
>
|
||||
|
||||
@ -28,7 +29,7 @@ export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
||||
* These only include custom cef events
|
||||
*/
|
||||
export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = (
|
||||
args: RageFW_CefArguments<K>,
|
||||
args: RageFW_CefArgs<K>,
|
||||
) => RageFW_CefReturn<K>
|
||||
|
||||
export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> =
|
||||
|
@ -1,4 +1,5 @@
|
||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
||||
export type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
||||
/**
|
||||
@ -11,7 +12,7 @@ export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
||||
* Array of arguments of event you pass as a generic
|
||||
* These only include custom client events
|
||||
*/
|
||||
export type RageFW_ClientArguments<K extends RageFW_ClientEvent> = Parameters<
|
||||
export type RageFW_ClientArgs<K extends RageFW_ClientEvent> = Parameters<
|
||||
RageFW_ICustomClientEvent[K]
|
||||
>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||
|
||||
export type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||
|
||||
/**
|
||||
@ -11,7 +12,7 @@ export type RageFW_ServerEvent = keyof RageFW_ICustomServerEvent
|
||||
* Array of arguments of event you pass as a generic
|
||||
* These only include custom server events
|
||||
*/
|
||||
export type RageFW_ServerArguments<K extends RageFW_ServerEvent> = Parameters<
|
||||
export type RageFW_ServerArgs<K extends RageFW_ServerEvent> = Parameters<
|
||||
RageFW_ICustomServerEvent[K]
|
||||
>
|
||||
|
||||
|
8
client/src/core/browser.ts
Normal file
8
client/src/core/browser.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Player } from './'
|
||||
|
||||
export class Browser extends Player {
|
||||
public registerBrowser(browser: BrowserMp) {
|
||||
this.browser = browser
|
||||
return browser
|
||||
}
|
||||
}
|
20
client/src/core/client.ts
Normal file
20
client/src/core/client.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import rpc from 'rage-rpc'
|
||||
|
||||
import { RageFW_ClientCallback, RageFW_ClientEvent } from '../types'
|
||||
|
||||
export class Client {
|
||||
public register<EventName extends RageFW_ClientEvent>(
|
||||
eventName: EventName,
|
||||
callback: RageFW_ClientCallback<EventName>,
|
||||
): void {
|
||||
rpc.register(eventName, data => {
|
||||
return callback(data)
|
||||
})
|
||||
}
|
||||
|
||||
public unregister<EventName extends RageFW_ClientEvent>(
|
||||
eventName: EventName,
|
||||
): void {
|
||||
rpc.unregister(eventName)
|
||||
}
|
||||
}
|
4
client/src/core/index.ts
Normal file
4
client/src/core/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './client'
|
||||
export * from './player'
|
||||
export * from './browser'
|
||||
export * from './logger'
|
@ -1,4 +1,4 @@
|
||||
export default class Logger {
|
||||
export class Logger {
|
||||
public error(message: unknown) {
|
||||
mp.console.logError(
|
||||
`[${new Date().toLocaleTimeString()}] [ERROR] ${message}`,
|
49
client/src/core/player.ts
Normal file
49
client/src/core/player.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import rpc from 'rage-rpc'
|
||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
||||
import {
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientEventArguments,
|
||||
RageFW_ClientEventReturn,
|
||||
RageFW_ClientServerEvent,
|
||||
RageFW_ClientServerEventArguments,
|
||||
RageFW_ClientServerEventReturn,
|
||||
} from '../types'
|
||||
|
||||
export class Player {
|
||||
public browser: BrowserMp | undefined
|
||||
|
||||
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ClientEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientEventArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientEventReturn<EventName>> {
|
||||
return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args)
|
||||
}
|
||||
|
||||
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientServerEventArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientServerEventReturn<EventName>> {
|
||||
return rpc.callServer(eventName, args)
|
||||
}
|
||||
|
||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||
eventName: EventName,
|
||||
...args: _CefEventHasArgs<EventName> extends true
|
||||
? [RageFW_CefArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_CefReturn<EventName>> {
|
||||
if (!this.browser)
|
||||
throw new Error('You need to initialize browser first!')
|
||||
return rpc.callBrowser(this.browser, eventName, args)
|
||||
}
|
||||
}
|
@ -1,81 +1,4 @@
|
||||
import rpc from 'rage-rpc'
|
||||
|
||||
import Logger from './logger'
|
||||
|
||||
import {
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ClientEventArguments,
|
||||
RageFW_ClientEventCallback,
|
||||
RageFW_ClientEventReturn,
|
||||
RageFW_ClientServerEvent,
|
||||
RageFW_ClientServerEventArguments,
|
||||
RageFW_ClientServerEventReturn,
|
||||
} from './types'
|
||||
|
||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
||||
class Client {
|
||||
public register<EventName extends RageFW_ClientEvent>(
|
||||
eventName: EventName,
|
||||
callback: RageFW_ClientEventCallback<EventName>,
|
||||
): void {
|
||||
rpc.register(eventName, data => {
|
||||
return callback(data)
|
||||
})
|
||||
}
|
||||
|
||||
public unregister<EventName extends RageFW_ClientEvent>(
|
||||
eventName: EventName,
|
||||
): void {
|
||||
rpc.unregister(eventName)
|
||||
}
|
||||
}
|
||||
|
||||
class Player {
|
||||
public browser: BrowserMp | undefined
|
||||
|
||||
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ClientEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientEventArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientEventReturn<EventName>> {
|
||||
return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args)
|
||||
}
|
||||
|
||||
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientServerEventArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientServerEventReturn<EventName>> {
|
||||
return rpc.callServer(eventName, args)
|
||||
}
|
||||
|
||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||
eventName: EventName,
|
||||
...args: _CefEventHasArgs<EventName> extends true
|
||||
? [RageFW_CefArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_CefReturn<EventName>> {
|
||||
if (!this.browser)
|
||||
throw new Error('You need to initialize browser first!')
|
||||
return rpc.callBrowser(this.browser, eventName, args)
|
||||
}
|
||||
}
|
||||
|
||||
class Browser extends Player {
|
||||
public registerBrowser(browser: BrowserMp) {
|
||||
this.browser = browser
|
||||
return browser
|
||||
}
|
||||
}
|
||||
import { Browser, Client, Logger, Player } from './core'
|
||||
|
||||
export const fw = {
|
||||
event: new Client(),
|
||||
|
@ -14,7 +14,7 @@ export type RageFW_ClientEvent =
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These include custom and system events
|
||||
*/
|
||||
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
|
||||
export type RageFW_ClientArgs<K extends RageFW_ClientEvent> =
|
||||
K extends keyof RageFW_ICustomClientEvent
|
||||
? Parameters<RageFW_ICustomClientEvent[K]>
|
||||
: K extends keyof IClientEvents
|
||||
@ -25,15 +25,15 @@ export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
|
||||
* Callback (function) for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ClientEventCallback<K extends RageFW_ClientEvent> = (
|
||||
args: RageFW_ClientEventArguments<K>,
|
||||
) => RageFW_ClientEventReturn<K>
|
||||
export type RageFW_ClientCallback<K extends RageFW_ClientEvent> = (
|
||||
args: RageFW_ClientArgs<K>,
|
||||
) => RageFW_ClientReturn<K>
|
||||
|
||||
/**
|
||||
* Return type for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
||||
export type RageFW_ClientReturn<K extends RageFW_ClientEvent> =
|
||||
K extends keyof RageFW_ICustomClientEvent
|
||||
? ReturnType<RageFW_ICustomClientEvent[K]>
|
||||
: never
|
||||
|
@ -15,17 +15,16 @@ export type RageFW_ClientServerEvent = keyof RageFW_ICustomServerEvent
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ClientServerEventArguments<
|
||||
K extends RageFW_ClientServerEvent,
|
||||
> = K extends keyof RageFW_ICustomServerEvent
|
||||
? Parameters<RageFW_ICustomServerEvent[K]>
|
||||
: never
|
||||
export type RageFW_ClientServerArgs<K extends RageFW_ClientServerEvent> =
|
||||
K extends keyof RageFW_ICustomServerEvent
|
||||
? Parameters<RageFW_ICustomServerEvent[K]>
|
||||
: never
|
||||
|
||||
/**
|
||||
* Return type for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ClientServerEventReturn<K extends RageFW_ClientServerEvent> =
|
||||
export type RageFW_ClientServerReturn<K extends RageFW_ClientServerEvent> =
|
||||
K extends keyof RageFW_ICustomServerEvent
|
||||
? ReturnType<RageFW_ICustomServerEvent[K]>
|
||||
: never
|
||||
|
@ -1,4 +1,5 @@
|
||||
import winston, { format } from 'winston'
|
||||
|
||||
const { timestamp, printf, colorize } = format
|
||||
|
||||
export class Logger {
|
||||
|
@ -7,8 +7,8 @@ import {
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ServerClientEventArguments,
|
||||
RageFW_ServerClientEventReturn,
|
||||
RageFW_ServerClientArgs,
|
||||
RageFW_ServerClientReturn,
|
||||
} from '../types'
|
||||
|
||||
export class Player {
|
||||
@ -16,9 +16,9 @@ export class Player {
|
||||
player: PlayerMp,
|
||||
eventName: EventName,
|
||||
...args: _ClientEventHasArgs<EventName> extends true
|
||||
? [RageFW_ServerClientEventArguments<EventName>]
|
||||
? [RageFW_ServerClientArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ServerClientEventReturn<EventName>> {
|
||||
): Promise<RageFW_ServerClientReturn<EventName>> {
|
||||
return rpc.callClient(player, eventName, args)
|
||||
}
|
||||
|
||||
|
@ -3,19 +3,13 @@ import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||
|
||||
import { nativeEvents } from '../native.events'
|
||||
import {
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ServerClientEventArguments,
|
||||
RageFW_ServerArgs,
|
||||
RageFW_ServerCallback,
|
||||
RageFW_ServerCallbackCustom,
|
||||
RageFW_ServerCallbackNative,
|
||||
RageFW_ServerEvent,
|
||||
RageFW_ServerEventArguments,
|
||||
RageFW_ServerEventCallback,
|
||||
RageFW_ServerEventCallbackCustom,
|
||||
RageFW_ServerEventCallbackNative,
|
||||
RageFW_ServerEventReturn,
|
||||
RageFW_ServerReturn,
|
||||
} from '../types'
|
||||
|
||||
type MiddlewarePoolServer<EventName extends RageFW_ServerEvent> = Partial<{
|
||||
@ -25,11 +19,11 @@ type MiddlewarePoolServer<EventName extends RageFW_ServerEvent> = Partial<{
|
||||
}
|
||||
}>
|
||||
|
||||
type MiddlewareFunction<EventName extends RageFW_ServerEvent> = (
|
||||
export type MiddlewareFunction<EventName extends RageFW_ServerEvent> = (
|
||||
player: PlayerMp,
|
||||
eventName: EventName,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ServerEventArguments<EventName>]
|
||||
? [RageFW_ServerArgs<EventName>]
|
||||
: []
|
||||
) => void
|
||||
|
||||
@ -56,11 +50,11 @@ export class Server {
|
||||
|
||||
private registerCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||
eventName: EventName,
|
||||
callback: RageFW_ServerEventCallbackCustom<EventName>,
|
||||
callback: RageFW_ServerCallbackCustom<EventName>,
|
||||
): void {
|
||||
rpc.register(
|
||||
eventName,
|
||||
async (args: RageFW_ServerEventArguments<EventName>, info) => {
|
||||
async (args: RageFW_ServerArgs<EventName>, info) => {
|
||||
callback([info.player as PlayerMp, ...args])
|
||||
},
|
||||
)
|
||||
@ -68,7 +62,7 @@ export class Server {
|
||||
|
||||
private registerNative<EventName extends keyof IServerEvents>(
|
||||
eventName: EventName,
|
||||
callback: RageFW_ServerEventCallbackNative<EventName>,
|
||||
callback: RageFW_ServerCallbackNative<EventName>,
|
||||
): void {
|
||||
mp.events.add(
|
||||
eventName,
|
||||
@ -79,35 +73,35 @@ export class Server {
|
||||
|
||||
public register<EventName extends RageFW_ServerEvent>(
|
||||
eventName: EventName,
|
||||
callback: RageFW_ServerEventCallback<EventName>,
|
||||
callback: RageFW_ServerCallback<EventName>,
|
||||
): void {
|
||||
if (this.isNativeEvent(eventName)) {
|
||||
this.registerNative(
|
||||
eventName,
|
||||
callback as RageFW_ServerEventCallbackNative,
|
||||
callback as RageFW_ServerCallbackNative,
|
||||
)
|
||||
} else {
|
||||
this.registerCustom(
|
||||
eventName,
|
||||
callback as unknown as RageFW_ServerEventCallbackCustom,
|
||||
callback as unknown as RageFW_ServerCallbackCustom,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
||||
[event in EventName]: RageFW_ServerEventCallback<event>
|
||||
[event in EventName]: RageFW_ServerCallback<event>
|
||||
}): void {
|
||||
Object.entries<RageFW_ServerEventCallback<EventName>>(events).map(
|
||||
Object.entries<RageFW_ServerCallback<EventName>>(events).map(
|
||||
([eventName, callback]) => {
|
||||
if (this.isNativeEvent(eventName)) {
|
||||
this.registerNative(
|
||||
eventName,
|
||||
callback as RageFW_ServerEventCallbackNative,
|
||||
callback as RageFW_ServerCallbackNative,
|
||||
)
|
||||
} else {
|
||||
this.registerCustom(
|
||||
eventName as keyof RageFW_ICustomServerEvent,
|
||||
callback as unknown as RageFW_ServerEventCallbackCustom,
|
||||
callback as unknown as RageFW_ServerCallbackCustom,
|
||||
)
|
||||
}
|
||||
},
|
||||
@ -139,9 +133,9 @@ export class Server {
|
||||
public trigger<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||
eventName: EventName,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ServerEventArguments<EventName>]
|
||||
? [RageFW_ServerArgs<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ServerEventReturn<EventName>> {
|
||||
return rpc.call<RageFW_ServerEventReturn<EventName>>(eventName, args)
|
||||
): Promise<RageFW_ServerReturn<EventName>> {
|
||||
return rpc.call<RageFW_ServerReturn<EventName>>(eventName, args)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Server, Logger, Player } from './core'
|
||||
import { Logger, Player, Server } from './core'
|
||||
|
||||
export const fw = {
|
||||
event: new Server(),
|
||||
|
@ -12,7 +12,7 @@ export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
||||
* Array of arguments of an event you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ServerClientEventArguments<K extends RageFW_ClientEvent> =
|
||||
export type RageFW_ServerClientArgs<K extends RageFW_ClientEvent> =
|
||||
K extends RageFW_ClientEvent
|
||||
? Parameters<RageFW_ICustomClientEvent[K]>
|
||||
: never
|
||||
@ -21,7 +21,7 @@ export type RageFW_ServerClientEventArguments<K extends RageFW_ClientEvent> =
|
||||
* Return type of event you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ServerClientEventReturn<K extends RageFW_ClientEvent> =
|
||||
export type RageFW_ServerClientReturn<K extends RageFW_ClientEvent> =
|
||||
K extends RageFW_ClientEvent
|
||||
? ReturnType<RageFW_ICustomClientEvent[K]>
|
||||
: never
|
||||
|
@ -18,7 +18,7 @@ export type RageFW_ServerEvent =
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These also include system events
|
||||
*/
|
||||
export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> =
|
||||
export type RageFW_ServerArgs<K extends RageFW_ServerEvent> =
|
||||
K extends keyof RageFW_ICustomServerEvent
|
||||
? Parameters<RageFW_ICustomServerEvent[K]>
|
||||
: K extends keyof IServerEvents
|
||||
@ -29,18 +29,18 @@ export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> =
|
||||
* Callback (function) for an event, name of which you pass as a generic
|
||||
* These include system and custom events
|
||||
*/
|
||||
export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
||||
export type RageFW_ServerCallback<K extends RageFW_ServerEvent> =
|
||||
K extends keyof RageFW_ICustomServerEvent
|
||||
? RageFW_ServerEventCallbackCustom<K>
|
||||
? RageFW_ServerCallbackCustom<K>
|
||||
: K extends keyof IServerEvents
|
||||
? RageFW_ServerEventCallbackNative<K>
|
||||
? RageFW_ServerCallbackNative<K>
|
||||
: never
|
||||
|
||||
/**
|
||||
* Return type for an event, name of which you pass as a generic
|
||||
* These include system and custom events
|
||||
*/
|
||||
export type RageFW_ServerEventReturn<K extends RageFW_ServerEvent> =
|
||||
export type RageFW_ServerReturn<K extends RageFW_ServerEvent> =
|
||||
K extends keyof RageFW_ICustomServerEvent
|
||||
? ReturnType<RageFW_ICustomServerEvent[K]>
|
||||
: K extends keyof IServerEvents
|
||||
@ -51,17 +51,17 @@ export type RageFW_ServerEventReturn<K extends RageFW_ServerEvent> =
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These only include custom events
|
||||
*/
|
||||
export type RageFW_ServerEventCallbackCustom<
|
||||
export type RageFW_ServerCallbackCustom<
|
||||
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
|
||||
> = (
|
||||
payload: [player: PlayerMp, ...args: RageFW_ServerEventArguments<K>],
|
||||
) => RageFW_ServerEventReturn<K>
|
||||
payload: [player: PlayerMp, ...args: RageFW_ServerArgs<K>],
|
||||
) => RageFW_ServerReturn<K>
|
||||
|
||||
/**
|
||||
* Array of arguments for an event, name of which you pass as a generic
|
||||
* These only include system events
|
||||
*/
|
||||
export type RageFW_ServerEventCallbackNative<
|
||||
export type RageFW_ServerCallbackNative<
|
||||
K extends keyof IServerEvents = keyof IServerEvents,
|
||||
> = (payload: Parameters<IServerEvents[K]>) => ReturnType<IServerEvents[K]>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user