Compare commits
3 Commits
2da34bd382
...
4695f5dbd1
Author | SHA1 | Date | |
---|---|---|---|
4695f5dbd1 | |||
fa4c218a7a | |||
454fc12d2e |
@ -38,20 +38,21 @@ class Server {
|
||||
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
||||
[event in EventName]: RageFW_ServerEventCallback<event>
|
||||
}): void {
|
||||
Object.entries(events).map(([eventName, callback]) => {
|
||||
if (nativeEvents.includes(eventName)) {
|
||||
mp.events.add(
|
||||
eventName as keyof IServerEvents,
|
||||
callback as (...arg: unknown[]) => void,
|
||||
)
|
||||
} else {
|
||||
rpc.register(eventName, (args: unknown[]) => {
|
||||
return Array.isArray(args)
|
||||
? (callback as (...arg: typeof args) => void)(...args)
|
||||
: (callback as (arg: typeof args) => void)(args)
|
||||
})
|
||||
}
|
||||
})
|
||||
Object.entries<RageFW_ServerEventCallback<EventName>>(events).map(
|
||||
([eventName, callback]) => {
|
||||
if (this.isNativeEvent(eventName)) {
|
||||
mp.events.add(eventName, callback)
|
||||
} else {
|
||||
rpc.register(eventName, (args: unknown[]) => {
|
||||
return Array.isArray(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]>
|
||||
) => ReturnType<RageFW_ICustomServerEvent[K]>
|
||||
: K extends keyof IServerEvents
|
||||
? ThisifyServerEvents[K]
|
||||
? IServerEvents[K]
|
||||
: never
|
||||
|
||||
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
|
||||
|
5
shared-types/types/types/index.d.ts
vendored
5
shared-types/types/types/index.d.ts
vendored
@ -1,5 +1,8 @@
|
||||
declare module 'rage-fw-shared-types' {
|
||||
export interface RageFW_ICustomServerEvent {}
|
||||
export interface RageFW_ICustomServerEvent {
|
||||
customServerEvent(customArgs: string[]): boolean
|
||||
customServerEvent2(customArgs2: number[]): void
|
||||
}
|
||||
|
||||
export interface RageFW_ICustomClientEvent {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user