Compare commits

...

3 Commits

Author SHA1 Message Date
4695f5dbd1 types 2024-06-11 02:57:19 +01:00
fa4c218a7a Merge remote-tracking branch 'origin/master'
# Conflicts:
#	server/src/index.ts
#	server/src/types.ts
2024-06-11 02:50:29 +01:00
454fc12d2e types 2024-06-11 02:49:56 +01:00
3 changed files with 20 additions and 16 deletions

View File

@ -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 {
) rpc.register(eventName, (args: unknown[]) => {
} else { return Array.isArray(args)
rpc.register(eventName, (args: unknown[]) => { ? (callback as (...arg: typeof args) => void)(
return Array.isArray(args) ...args,
? (callback as (...arg: typeof args) => void)(...args) )
: (callback as (arg: typeof args) => void)(args) : (callback as (arg: typeof args) => void)(args)
}) })
} }
}) },
)
} }
} }

View File

@ -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

View File

@ -1,5 +1,8 @@
declare module 'rage-fw-shared-types' { 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 {} export interface RageFW_ICustomClientEvent {}
} }