Compare commits

..

No commits in common. "0520b869dbdc1b879b1a8f7ba26fb8be556bd6a2" and "a9486db3f552f72e1ee8d10ca52fb7925526f5dd" have entirely different histories.

7 changed files with 31 additions and 72 deletions

View File

@ -10,8 +10,6 @@ import {
RageFW_ClientServerEventReturn, RageFW_ClientServerEventReturn,
RageFW_ClientEventArguments, RageFW_ClientEventArguments,
RageFW_ClientEventReturn, RageFW_ClientEventReturn,
_ClientEventHasArgs,
_ServerEventHasArgs,
RageFW_CefEvent, RageFW_CefEvent,
RageFW_CefArgs, RageFW_CefArgs,
RageFW_CefReturn, RageFW_CefReturn,
@ -41,18 +39,14 @@ class Player {
public trigger<EventName extends keyof RageFW_ICustomClientEvent>( public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
eventName: EventName, eventName: EventName,
...args: _ClientEventHasArgs<EventName> extends true args: RageFW_ClientEventArguments<EventName>,
? [RageFW_ClientEventArguments<EventName>]
: []
): Promise<RageFW_ClientEventReturn<EventName>> { ): Promise<RageFW_ClientEventReturn<EventName>> {
return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args) return rpc.call<RageFW_ClientEventReturn<EventName>>(eventName, args)
} }
public triggerServer<EventName extends RageFW_ClientServerEvent>( public triggerServer<EventName extends RageFW_ClientServerEvent>(
eventName: EventName, eventName: EventName,
...args: _ServerEventHasArgs<EventName> extends true args: RageFW_ClientServerEventArguments<EventName>,
? [RageFW_ClientServerEventArguments<EventName>]
: []
): Promise<RageFW_ClientServerEventReturn<EventName>> { ): Promise<RageFW_ClientServerEventReturn<EventName>> {
return rpc.callServer(eventName, args) return rpc.callServer(eventName, args)
} }

View File

@ -31,11 +31,3 @@ export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]> ? ReturnType<RageFW_ICustomClientEvent[K]>
: never : never
export type _ClientEventHasArgs<
EventName extends keyof RageFW_ICustomClientEvent,
> = keyof RageFW_ICustomClientEvent extends never
? false
: Parameters<RageFW_ICustomClientEvent[EventName]>[0] extends undefined
? false
: true

View File

@ -1,9 +1,6 @@
/// <reference types="@ragempcommunity/types-client" /> /// <reference types="@ragempcommunity/types-client" />
import type { import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
RageFW_ICustomClientEvent,
RageFW_ICustomServerEvent,
} from 'rage-fw-shared-types'
/** /**
* Union of all available server event names callable from client * Union of all available server event names callable from client
@ -29,11 +26,3 @@ export type RageFW_ClientServerEventReturn<K extends RageFW_ClientServerEvent> =
K extends keyof RageFW_ICustomServerEvent K extends keyof RageFW_ICustomServerEvent
? ReturnType<RageFW_ICustomServerEvent[K]> ? ReturnType<RageFW_ICustomServerEvent[K]>
: never : never
export type _ServerEventHasArgs<
EventName extends keyof RageFW_ICustomServerEvent,
> = keyof RageFW_ICustomClientEvent extends never
? false
: Parameters<RageFW_ICustomServerEvent[EventName]>[0] extends undefined
? false
: true

View File

@ -3,11 +3,12 @@ import rpc from 'rage-rpc'
import Logger from './logger' import Logger from './logger'
import { import {
_ClientEventHasArgs, RageFW_CefArgs,
_ServerEventHasArgs, RageFW_CefEvent,
RageFW_CefReturn,
RageFW_ClientEvent, RageFW_ClientEvent,
RageFW_ServerClientEventArguments, RageFW_ClientEventArguments,
RageFW_ServerClientEventReturn, RageFW_ClientEventReturn,
RageFW_ICustomServerEvent, RageFW_ICustomServerEvent,
RageFW_ServerEvent, RageFW_ServerEvent,
RageFW_ServerEventArguments, RageFW_ServerEventArguments,
@ -103,9 +104,7 @@ class Server {
public trigger<EventName extends keyof RageFW_ICustomServerEvent>( public trigger<EventName extends keyof RageFW_ICustomServerEvent>(
eventName: EventName, eventName: EventName,
...args: _ServerEventHasArgs<EventName> extends true args: RageFW_ServerEventArguments<EventName>,
? [RageFW_ServerEventArguments<EventName>]
: []
): Promise<RageFW_ServerEventReturn<EventName>> { ): Promise<RageFW_ServerEventReturn<EventName>> {
return rpc.call<RageFW_ServerEventReturn<EventName>>(eventName, args) return rpc.call<RageFW_ServerEventReturn<EventName>>(eventName, args)
} }
@ -115,12 +114,18 @@ class Player {
public triggerClient<EventName extends RageFW_ClientEvent>( public triggerClient<EventName extends RageFW_ClientEvent>(
player: PlayerMp, player: PlayerMp,
eventName: EventName, eventName: EventName,
...args: _ClientEventHasArgs<EventName> extends true args: RageFW_ClientEventArguments<EventName>,
? [RageFW_ServerClientEventArguments<EventName>] ): Promise<RageFW_ClientEventReturn<EventName>> {
: []
): Promise<RageFW_ServerClientEventReturn<EventName>> {
return rpc.callClient(player, eventName, args) return rpc.callClient(player, eventName, args)
} }
public triggerBrowser<EventName extends RageFW_CefEvent>(
player: PlayerMp,
eventName: EventName,
args: RageFW_CefArgs<EventName>,
): Promise<RageFW_CefReturn<EventName>> {
return rpc.callBrowsers(player, eventName, args)
}
} }
export const fw = { export const fw = {
@ -130,3 +135,7 @@ export const fw = {
log: new Logger(), log: new Logger(),
}, },
} }
fw.system.log.info(
'Working on Rage Framework. RageFW © Powered by Entity Seven Group',
)

View File

@ -12,7 +12,7 @@ export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent
* Array of arguments of an event you pass as a generic * Array of arguments of an event you pass as a generic
* These only include custom events * These only include custom events
*/ */
export type RageFW_ServerClientEventArguments<K extends RageFW_ClientEvent> = export type RageFW_ClientEventArguments<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent K extends RageFW_ClientEvent
? Parameters<RageFW_ICustomClientEvent[K]> ? Parameters<RageFW_ICustomClientEvent[K]>
: never : never
@ -21,15 +21,7 @@ export type RageFW_ServerClientEventArguments<K extends RageFW_ClientEvent> =
* Return type of event you pass as a generic * Return type of event you pass as a generic
* These only include custom events * These only include custom events
*/ */
export type RageFW_ServerClientEventReturn<K extends RageFW_ClientEvent> = export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
K extends RageFW_ClientEvent K extends RageFW_ClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]> ? ReturnType<RageFW_ICustomClientEvent[K]>
: never : never
export type _ClientEventHasArgs<
EventName extends keyof RageFW_ICustomClientEvent,
> = keyof RageFW_ICustomClientEvent extends never
? false
: Parameters<RageFW_ICustomClientEvent[EventName]>[0] extends undefined
? false
: true

View File

@ -1,9 +1,6 @@
/// <reference types="@ragempcommunity/types-server" /> /// <reference types="@ragempcommunity/types-server" />
import type { import type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
RageFW_ICustomClientEvent,
RageFW_ICustomServerEvent,
} from 'rage-fw-shared-types'
export type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types' export type { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
/** /**
@ -20,9 +17,9 @@ export type RageFW_ServerEvent =
*/ */
export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> = export type RageFW_ServerEventArguments<K extends RageFW_ServerEvent> =
K extends keyof RageFW_ICustomServerEvent K extends keyof RageFW_ICustomServerEvent
? Parameters<RageFW_ICustomServerEvent[K]> ? Parameters<RageFW_ServerEventCallbackCustom<K>>
: K extends keyof IServerEvents : K extends keyof IServerEvents
? Parameters<IServerEvents[K]> ? Parameters<RageFW_ServerEventCallbackNative<K>>
: never : never
/** /**
@ -65,11 +62,3 @@ export type RageFW_ServerEventCallbackCustom<
export type RageFW_ServerEventCallbackNative< export type RageFW_ServerEventCallbackNative<
K extends keyof IServerEvents = keyof IServerEvents, K extends keyof IServerEvents = keyof IServerEvents,
> = IServerEvents[K] > = IServerEvents[K]
export type _ServerEventHasArgs<
EventName extends keyof RageFW_ICustomServerEvent,
> = keyof RageFW_ICustomClientEvent extends never
? false
: Parameters<RageFW_ICustomServerEvent[EventName]>[0] extends undefined
? false
: true

View File

@ -1,13 +1,7 @@
declare module 'rage-fw-shared-types' { declare module 'rage-fw-shared-types' {
export interface RageFW_ICustomServerEvent { export interface RageFW_ICustomServerEvent {}
customServerEvent(test: string, test2: number): void
}
export interface RageFW_ICustomClientEvent { export interface RageFW_ICustomClientEvent {}
customClientEvent(test: string, test2: number): void
}
export interface RageFW_ICustomCefEvent { export interface RageFW_ICustomCefEvent {}
customCefEvent(test: string, test2: number): void
}
} }