types
This commit is contained in:
parent
fa4c218a7a
commit
4695f5dbd1
@ -38,20 +38,21 @@ class Server {
|
|||||||
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
||||||
[event in EventName]: RageFW_ServerEventCallback<event>
|
[event in EventName]: RageFW_ServerEventCallback<event>
|
||||||
}): void {
|
}): void {
|
||||||
Object.entries(events).map(([eventName, callback]) => {
|
Object.entries<RageFW_ServerEventCallback<EventName>>(events).map(
|
||||||
if (nativeEvents.includes(eventName)) {
|
([eventName, callback]) => {
|
||||||
mp.events.add(
|
if (this.isNativeEvent(eventName)) {
|
||||||
eventName as keyof IServerEvents,
|
mp.events.add(eventName, callback)
|
||||||
callback as (...arg: unknown[]) => void,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
rpc.register(eventName, (args: unknown[]) => {
|
rpc.register(eventName, (args: unknown[]) => {
|
||||||
return Array.isArray(args)
|
return Array.isArray(args)
|
||||||
? (callback as (...arg: typeof args) => void)(...args)
|
? (callback as (...arg: typeof args) => void)(
|
||||||
|
...args,
|
||||||
|
)
|
||||||
: (callback as (arg: typeof args) => void)(args)
|
: (callback as (arg: typeof args) => void)(args)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ export type RageFW_ServerEventCallback<K extends RageFW_ServerEvent> =
|
|||||||
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
...args: Parameters<RageFW_ICustomServerEvent[K]>
|
||||||
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
||||||
: K extends keyof IServerEvents
|
: K extends keyof IServerEvents
|
||||||
? ThisifyServerEvents[K]
|
? IServerEvents[K]
|
||||||
: never
|
: never
|
||||||
|
|
||||||
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
||||||
|
Loading…
Reference in New Issue
Block a user