Compare commits

..

No commits in common. "fa3b1b1b0bbda238117cb87e380a6217e6a8daf8" and "c021ef3c59ded6367cecff2094e80b683d43a93e" have entirely different histories.

4 changed files with 17 additions and 78 deletions

View File

@ -2,16 +2,13 @@ import rpc from 'rage-rpc'
import Logger from './logger'
import {
import type {
RageFW_ClientEventCallback,
RageFW_ClientEvent,
RageFW_ClientServerEvent,
RageFW_ClientServerEventArguments,
RageFW_ClientServerEventReturn,
RageFW_ClientEventArguments,
RageFW_ClientEventReturn,
} from './types'
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
class Client {
public register<EventName extends RageFW_ClientEvent>(
@ -22,19 +19,6 @@ class Client {
return callback(data)
})
}
public unregister<EventName extends RageFW_ClientEvent>(
eventName: EventName,
): void {
rpc.unregister(eventName)
}
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
eventName: EventName,
args: RageFW_ClientEventArguments<EventName>,
): Promise<RageFW_ClientEventReturn<EventName>> {
return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args)
}
}
class Player {

View File

@ -4,11 +4,8 @@ import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
Parameters<RageFW_ICustomClientEvent[K]>
export type RageFW_ClientEventCallback<K extends RageFW_ClientEvent> = (
args: RageFW_ClientEventArguments<K>,
args: Parameters<RageFW_ICustomClientEvent[K]>,
) => RageFW_ClientEventReturn<K>
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =

View File

@ -2,17 +2,15 @@ import rpc from 'rage-rpc'
import Logger from './logger'
import {
import type {
RageFW_ClientEvent,
RageFW_ClientEventArguments,
RageFW_ClientEventReturn,
RageFW_ICustomServerEvent,
RageFW_ServerEvent,
RageFW_ServerEventArguments,
RageFW_ServerEventCallback,
RageFW_ServerEventCallbackCustom,
RageFW_ServerEventCallbackNative,
RageFW_ServerEventReturn,
} from './types'
import { nativeEvents } from './native.events'
@ -27,7 +25,10 @@ class Server {
): void {
rpc.register(
eventName,
async (args: RageFW_ServerEventArguments<EventName>, info) => {
async (
args: Parameters<RageFW_ICustomServerEvent[EventName]>,
info,
) => {
callback(info.player as PlayerMp, args)
},
)
@ -76,35 +77,6 @@ class Server {
},
)
}
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
eventName: EventName,
): void {
rpc.unregister(eventName)
}
private unregisterNative<EventName extends keyof IServerEvents>(
eventName: EventName,
): void {
mp.events.remove(eventName)
}
public unregister<EventName extends RageFW_ServerEvent>(
eventName: EventName,
): void {
if (this.isNativeEvent(eventName)) {
this.unregisterNative(eventName)
} else {
this.unregisterCustom(eventName)
}
}
private trigger<EventName extends keyof RageFW_ICustomServerEvent>(
eventName: EventName,
args: RageFW_ServerEventArguments<EventName>,
): Promise<RageFW_ServerEventReturn<EventName>> {
return rpc.call<RageFW_ServerEventReturn<EventName>>(eventName, args)
}
}
class Player {

View File

@ -7,12 +7,16 @@ export type RageFW_ServerEvent =
| keyof RageFW_ICustomServerEvent
| keyof IServerEvents
export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> =
K extends keyof RageFW_ICustomServerEvent
? Parameters<RageFW_ServerEventCallbackCustom<K>>
: K extends keyof IServerEvents
? Parameters<RageFW_ServerEventCallbackNative<K>>
: never
export type RageFW_ServerEventCallbackCustom<
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
> = (
player: PlayerMp,
args: Parameters<RageFW_ICustomServerEvent[K]>,
) => ReturnType<RageFW_ICustomServerEvent[K]>
export type RageFW_ServerEventCallbackNative<
K extends keyof IServerEvents = keyof IServerEvents,
> = IServerEvents[K]
export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
K extends keyof RageFW_ICustomServerEvent
@ -20,21 +24,3 @@ export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
: K extends keyof IServerEvents
? RageFW_ServerEventCallbackNative<K>
: never
export type RageFW_ServerEventReturn<K extends RageFW_ServerEvent> =
K extends keyof RageFW_ICustomServerEvent
? ReturnType<RageFW_ICustomServerEvent[K]>
: K extends keyof IServerEvents
? ReturnType<IServerEvents[K]>
: never
export type RageFW_ServerEventCallbackCustom<
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
> = (
player: PlayerMp,
args: RageFW_ServerEventArguments<K>,
) => RageFW_ServerEventReturn<K>
export type RageFW_ServerEventCallbackNative<
K extends keyof IServerEvents = keyof IServerEvents,
> = IServerEvents[K]