Compare commits
No commits in common. "fa3b1b1b0bbda238117cb87e380a6217e6a8daf8" and "c021ef3c59ded6367cecff2094e80b683d43a93e" have entirely different histories.
fa3b1b1b0b
...
c021ef3c59
@ -2,16 +2,13 @@ import rpc from 'rage-rpc'
|
|||||||
|
|
||||||
import Logger from './logger'
|
import Logger from './logger'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
RageFW_ClientEventCallback,
|
RageFW_ClientEventCallback,
|
||||||
RageFW_ClientEvent,
|
RageFW_ClientEvent,
|
||||||
RageFW_ClientServerEvent,
|
RageFW_ClientServerEvent,
|
||||||
RageFW_ClientServerEventArguments,
|
RageFW_ClientServerEventArguments,
|
||||||
RageFW_ClientServerEventReturn,
|
RageFW_ClientServerEventReturn,
|
||||||
RageFW_ClientEventArguments,
|
|
||||||
RageFW_ClientEventReturn,
|
|
||||||
} from './types'
|
} from './types'
|
||||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
|
||||||
|
|
||||||
class Client {
|
class Client {
|
||||||
public register<EventName extends RageFW_ClientEvent>(
|
public register<EventName extends RageFW_ClientEvent>(
|
||||||
@ -22,19 +19,6 @@ class Client {
|
|||||||
return callback(data)
|
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 {
|
class Player {
|
||||||
|
@ -4,11 +4,8 @@ import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
|||||||
|
|
||||||
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
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> = (
|
export type RageFW_ClientEventCallback<K extends RageFW_ClientEvent> = (
|
||||||
args: RageFW_ClientEventArguments<K>,
|
args: Parameters<RageFW_ICustomClientEvent[K]>,
|
||||||
) => RageFW_ClientEventReturn<K>
|
) => RageFW_ClientEventReturn<K>
|
||||||
|
|
||||||
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
||||||
|
@ -2,17 +2,15 @@ import rpc from 'rage-rpc'
|
|||||||
|
|
||||||
import Logger from './logger'
|
import Logger from './logger'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
RageFW_ClientEvent,
|
RageFW_ClientEvent,
|
||||||
RageFW_ClientEventArguments,
|
RageFW_ClientEventArguments,
|
||||||
RageFW_ClientEventReturn,
|
RageFW_ClientEventReturn,
|
||||||
RageFW_ICustomServerEvent,
|
RageFW_ICustomServerEvent,
|
||||||
RageFW_ServerEvent,
|
RageFW_ServerEvent,
|
||||||
RageFW_ServerEventArguments,
|
|
||||||
RageFW_ServerEventCallback,
|
RageFW_ServerEventCallback,
|
||||||
RageFW_ServerEventCallbackCustom,
|
RageFW_ServerEventCallbackCustom,
|
||||||
RageFW_ServerEventCallbackNative,
|
RageFW_ServerEventCallbackNative,
|
||||||
RageFW_ServerEventReturn,
|
|
||||||
} from './types'
|
} from './types'
|
||||||
import { nativeEvents } from './native.events'
|
import { nativeEvents } from './native.events'
|
||||||
|
|
||||||
@ -27,7 +25,10 @@ class Server {
|
|||||||
): void {
|
): void {
|
||||||
rpc.register(
|
rpc.register(
|
||||||
eventName,
|
eventName,
|
||||||
async (args: RageFW_ServerEventArguments<EventName>, info) => {
|
async (
|
||||||
|
args: Parameters<RageFW_ICustomServerEvent[EventName]>,
|
||||||
|
info,
|
||||||
|
) => {
|
||||||
callback(info.player as PlayerMp, args)
|
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 {
|
class Player {
|
||||||
|
@ -7,12 +7,16 @@ export type RageFW_ServerEvent =
|
|||||||
| keyof RageFW_ICustomServerEvent
|
| keyof RageFW_ICustomServerEvent
|
||||||
| keyof IServerEvents
|
| keyof IServerEvents
|
||||||
|
|
||||||
export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> =
|
export type RageFW_ServerEventCallbackCustom<
|
||||||
K extends keyof RageFW_ICustomServerEvent
|
K extends keyof RageFW_ICustomServerEvent = keyof RageFW_ICustomServerEvent,
|
||||||
? Parameters<RageFW_ServerEventCallbackCustom<K>>
|
> = (
|
||||||
: K extends keyof IServerEvents
|
player: PlayerMp,
|
||||||
? Parameters<RageFW_ServerEventCallbackNative<K>>
|
args: Parameters<RageFW_ICustomServerEvent[K]>,
|
||||||
: never
|
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
||||||
|
|
||||||
|
export type RageFW_ServerEventCallbackNative<
|
||||||
|
K extends keyof IServerEvents = keyof IServerEvents,
|
||||||
|
> = IServerEvents[K]
|
||||||
|
|
||||||
export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
||||||
K extends keyof RageFW_ICustomServerEvent
|
K extends keyof RageFW_ICustomServerEvent
|
||||||
@ -20,21 +24,3 @@ export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
|||||||
: K extends keyof IServerEvents
|
: K extends keyof IServerEvents
|
||||||
? RageFW_ServerEventCallbackNative<K>
|
? RageFW_ServerEventCallbackNative<K>
|
||||||
: never
|
: 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]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user