upd core
- types now use namespace to avoid bloating - moved items for further usage into data folder
This commit is contained in:
parent
3a4fe19df0
commit
588bb42d04
@ -1,20 +1,5 @@
|
|||||||
import { Rpc } from '@entityseven/rage-fw-rpc'
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
import type * as T from './types'
|
||||||
import type {
|
|
||||||
_CefEventHasArgs,
|
|
||||||
_ClientEventHasArgs,
|
|
||||||
_ServerEventHasArgs,
|
|
||||||
RageFW_CefArgs,
|
|
||||||
RageFW_CefCallback,
|
|
||||||
RageFW_CefReturn,
|
|
||||||
RageFW_ClientArgs,
|
|
||||||
RageFW_ClientReturn,
|
|
||||||
RageFW_ICustomCefEvent,
|
|
||||||
RageFW_ICustomClientEvent,
|
|
||||||
RageFW_ICustomServerEvent,
|
|
||||||
RageFW_ServerArgs,
|
|
||||||
RageFW_ServerReturn,
|
|
||||||
} from './types'
|
|
||||||
|
|
||||||
class Cef {
|
class Cef {
|
||||||
private _debugMode: boolean = false
|
private _debugMode: boolean = false
|
||||||
@ -30,9 +15,9 @@ class Cef {
|
|||||||
return this._rpc
|
return this._rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
public register<EventName extends keyof RageFW_ICustomCefEvent>(
|
public register<EventName extends keyof T.RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_CefCallback<EventName>,
|
callback: T.RageFW_CefCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
if (this._debugMode) {
|
if (this._debugMode) {
|
||||||
console.log('[RPC](register):', eventName, callback)
|
console.log('[RPC](register):', eventName, callback)
|
||||||
@ -43,12 +28,12 @@ class Cef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
public async trigger<EventName extends keyof T.RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _CefEventHasArgs<EventName> extends true
|
...args: T._CefEventHasArgs<EventName> extends true
|
||||||
? [RageFW_CefArgs<EventName>]
|
? [T.RageFW_CefArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<T.RageFW_CefReturn<EventName>> {
|
||||||
if (this._debugMode) {
|
if (this._debugMode) {
|
||||||
console.log('[RPC](trigger):', eventName, ...args)
|
console.log('[RPC](trigger):', eventName, ...args)
|
||||||
}
|
}
|
||||||
@ -63,13 +48,13 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async triggerServer<
|
public async triggerServer<
|
||||||
EventName extends keyof RageFW_ICustomServerEvent,
|
EventName extends keyof T.RageFW_ICustomServerEvent,
|
||||||
>(
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ServerEventHasArgs<EventName> extends true
|
...args: T._ServerEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ServerArgs<EventName>]
|
? [T.RageFW_ServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerReturn<EventName>> {
|
): Promise<T.RageFW_ServerReturn<EventName>> {
|
||||||
if (this._debugMode) {
|
if (this._debugMode) {
|
||||||
console.log('[RPC](triggerServer):', eventName, ...args)
|
console.log('[RPC](triggerServer):', eventName, ...args)
|
||||||
}
|
}
|
||||||
@ -84,13 +69,13 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async triggerClient<
|
public async triggerClient<
|
||||||
EventName extends keyof RageFW_ICustomClientEvent,
|
EventName extends keyof T.RageFW_ICustomClientEvent,
|
||||||
>(
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: T._ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [T.RageFW_ClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientReturn<EventName>> {
|
): Promise<T.RageFW_ClientReturn<EventName>> {
|
||||||
if (this._debugMode) {
|
if (this._debugMode) {
|
||||||
console.log('[RPC](triggerClient):', eventName, ...args)
|
console.log('[RPC](triggerClient):', eventName, ...args)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types'
|
import type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types'
|
||||||
|
|
||||||
export { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types'
|
export type { RageFW_ICustomCefEvent } from '@entityseven/rage-fw-shared-types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Union of all available cef event names
|
* Union of all available cef event names
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import { Rpc } from '@entityseven/rage-fw-rpc'
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
|
||||||
import type {
|
import type * as T from '../types'
|
||||||
RageFW_ClientArgs,
|
|
||||||
RageFW_ClientCallback,
|
|
||||||
RageFW_ClientEvent,
|
|
||||||
} from '../types'
|
|
||||||
|
|
||||||
export class Client {
|
export class Client {
|
||||||
private _rpc: Rpc = new Rpc()
|
private _rpc: Rpc = new Rpc()
|
||||||
@ -13,19 +9,19 @@ export class Client {
|
|||||||
return this._rpc
|
return this._rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
public register<EventName extends RageFW_ClientEvent>(
|
public register<EventName extends T.RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ClientCallback<EventName>,
|
callback: T.RageFW_ClientCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
this._rpc.register(
|
this._rpc.register(
|
||||||
eventName,
|
eventName,
|
||||||
async (data: RageFW_ClientArgs<EventName>) => {
|
async (data: T.RageFW_ClientArgs<EventName>) => {
|
||||||
return await callback(data)
|
return await callback(data)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregister<EventName extends RageFW_ClientEvent>(
|
public unregister<EventName extends T.RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
this._rpc.unregister(eventName)
|
this._rpc.unregister(eventName)
|
||||||
|
@ -1,19 +1,7 @@
|
|||||||
import { Rpc } from '@entityseven/rage-fw-rpc'
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
import type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types'
|
import type { RageFW_ICustomClientEvent } from '@entityseven/rage-fw-shared-types'
|
||||||
|
|
||||||
import {
|
import type * as T from '../types'
|
||||||
_CefEventHasArgs,
|
|
||||||
_ClientEventHasArgs,
|
|
||||||
_ServerEventHasArgs,
|
|
||||||
RageFW_CefArgs,
|
|
||||||
RageFW_CefEvent,
|
|
||||||
RageFW_CefReturn,
|
|
||||||
RageFW_ClientArgs,
|
|
||||||
RageFW_ClientReturn,
|
|
||||||
RageFW_ClientServerEvent,
|
|
||||||
RageFW_ClientServerArgs,
|
|
||||||
RageFW_ClientServerReturn,
|
|
||||||
} from '../types'
|
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
private _rpc: Rpc = new Rpc()
|
private _rpc: Rpc = new Rpc()
|
||||||
@ -24,28 +12,28 @@ export 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: T._ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [T.RageFW_ClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientReturn<EventName>> {
|
): Promise<T.RageFW_ClientReturn<EventName>> {
|
||||||
return this._rpc.call(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
public triggerServer<EventName extends T.RageFW_ClientServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ServerEventHasArgs<EventName> extends true
|
...args: T._ServerEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientServerArgs<EventName>]
|
? [T.RageFW_ClientServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientServerReturn<EventName>> {
|
): Promise<T.RageFW_ClientServerReturn<EventName>> {
|
||||||
return this._rpc.callServer(eventName, args)
|
return this._rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends T.RageFW_CefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _CefEventHasArgs<EventName> extends true
|
...args: T._CefEventHasArgs<EventName> extends true
|
||||||
? [RageFW_CefArgs<EventName>]
|
? [T.RageFW_CefArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<T.RageFW_CefReturn<EventName>> {
|
||||||
if (!this.browser)
|
if (!this.browser)
|
||||||
throw new Error('You need to initialize browser first')
|
throw new Error('You need to initialize browser first')
|
||||||
return this._rpc.callBrowser(this.browser, eventName, args)
|
return this._rpc.callBrowser(this.browser, eventName, args)
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
import { Rpc } from '@entityseven/rage-fw-rpc'
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
|
||||||
import type {
|
import type * as T from '../types'
|
||||||
_CefEventHasArgs,
|
|
||||||
_ClientEventHasArgs,
|
|
||||||
RageFW_CefArgs,
|
|
||||||
RageFW_CefEvent,
|
|
||||||
RageFW_CefReturn,
|
|
||||||
RageFW_ClientEvent,
|
|
||||||
RageFW_ServerClientArgs,
|
|
||||||
RageFW_ServerClientReturn,
|
|
||||||
} from '../types'
|
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
private _rpc: Rpc = new Rpc()
|
private _rpc: Rpc = new Rpc()
|
||||||
@ -18,23 +9,23 @@ export class Player {
|
|||||||
return this._rpc
|
return this._rpc
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends RageFW_ClientEvent>(
|
public triggerClient<EventName extends T.RageFW_ClientEvent>(
|
||||||
player: PlayerMp,
|
player: PlayerMp,
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: T._ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ServerClientArgs<EventName>]
|
? [T.RageFW_ServerClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerClientReturn<EventName>> {
|
): Promise<T.RageFW_ServerClientReturn<EventName>> {
|
||||||
return this._rpc.callClient(player, eventName, args)
|
return this._rpc.callClient(player, eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends T.RageFW_CefEvent>(
|
||||||
player: PlayerMp,
|
player: PlayerMp,
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _CefEventHasArgs<EventName> extends true
|
...args: T._CefEventHasArgs<EventName> extends true
|
||||||
? [RageFW_CefArgs<EventName>]
|
? [T.RageFW_CefArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<T.RageFW_CefReturn<EventName>> {
|
||||||
return this._rpc.callBrowser(player, eventName, args)
|
return this._rpc.callBrowser(player, eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
import { Rpc } from '@entityseven/rage-fw-rpc'
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
import { RageFW_ICustomServerEvent } from '@entityseven/rage-fw-shared-types'
|
import { RageFW_ICustomServerEvent } from '@entityseven/rage-fw-shared-types'
|
||||||
|
|
||||||
import { nativeEvents } from '../native.events'
|
import { nativeEvents } from '../data/nativeEvents'
|
||||||
import type {
|
import type * as T from '../types'
|
||||||
_ServerEventHasArgs,
|
|
||||||
RageFW_ServerArgs,
|
|
||||||
RageFW_ServerCallback,
|
|
||||||
RageFW_ServerCallbackCustom,
|
|
||||||
RageFW_ServerCallbackNative,
|
|
||||||
RageFW_ServerEvent,
|
|
||||||
RageFW_ServerReturn,
|
|
||||||
} from '../types'
|
|
||||||
|
|
||||||
export class Server {
|
export class Server {
|
||||||
private _rpc: Rpc = new Rpc()
|
private _rpc: Rpc = new Rpc()
|
||||||
@ -25,12 +17,12 @@ export class Server {
|
|||||||
|
|
||||||
private registerCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
private registerCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerCallbackCustom<EventName>,
|
callback: T.RageFW_ServerCallbackCustom<EventName>,
|
||||||
): void {
|
): void {
|
||||||
this._rpc.register(
|
this._rpc.register(
|
||||||
eventName,
|
eventName,
|
||||||
// fixme
|
// fixme
|
||||||
async (args: RageFW_ServerArgs<EventName>, info) => {
|
async (args: T.RageFW_ServerArgs<EventName>, info) => {
|
||||||
await callback([info.player as PlayerMp, ...args])
|
await callback([info.player as PlayerMp, ...args])
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -38,7 +30,7 @@ export class Server {
|
|||||||
|
|
||||||
private registerNative<EventName extends keyof IServerEvents>(
|
private registerNative<EventName extends keyof IServerEvents>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerCallbackNative<EventName>,
|
callback: T.RageFW_ServerCallbackNative<EventName>,
|
||||||
): void {
|
): void {
|
||||||
mp.events.add(
|
mp.events.add(
|
||||||
eventName,
|
eventName,
|
||||||
@ -47,37 +39,37 @@ export class Server {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public register<EventName extends RageFW_ServerEvent>(
|
public register<EventName extends T.RageFW_ServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerCallback<EventName>,
|
callback: T.RageFW_ServerCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
if (this.isNativeEvent(eventName)) {
|
if (this.isNativeEvent(eventName)) {
|
||||||
this.registerNative(
|
this.registerNative(
|
||||||
eventName,
|
eventName,
|
||||||
callback as RageFW_ServerCallbackNative,
|
callback as T.RageFW_ServerCallbackNative,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.registerCustom(
|
this.registerCustom(
|
||||||
eventName,
|
eventName,
|
||||||
callback as unknown as RageFW_ServerCallbackCustom,
|
callback as unknown as T.RageFW_ServerCallbackCustom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
public registerMany<EventName extends T.RageFW_ServerEvent>(events: {
|
||||||
[event in EventName]: RageFW_ServerCallback<event>
|
[event in EventName]: T.RageFW_ServerCallback<event>
|
||||||
}): void {
|
}): void {
|
||||||
Object.entries<RageFW_ServerCallback<EventName>>(events).map(
|
Object.entries<T.RageFW_ServerCallback<EventName>>(events).map(
|
||||||
([eventName, callback]) => {
|
([eventName, callback]) => {
|
||||||
if (this.isNativeEvent(eventName)) {
|
if (this.isNativeEvent(eventName)) {
|
||||||
this.registerNative(
|
this.registerNative(
|
||||||
eventName,
|
eventName,
|
||||||
callback as RageFW_ServerCallbackNative,
|
callback as T.RageFW_ServerCallbackNative,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.registerCustom(
|
this.registerCustom(
|
||||||
eventName as keyof RageFW_ICustomServerEvent,
|
eventName as keyof RageFW_ICustomServerEvent,
|
||||||
callback as unknown as RageFW_ServerCallbackCustom,
|
callback as unknown as T.RageFW_ServerCallbackCustom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -96,7 +88,7 @@ export class Server {
|
|||||||
mp.events.remove(eventName)
|
mp.events.remove(eventName)
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregister<EventName extends RageFW_ServerEvent>(
|
public unregister<EventName extends T.RageFW_ServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
if (this.isNativeEvent(eventName)) {
|
if (this.isNativeEvent(eventName)) {
|
||||||
@ -108,10 +100,10 @@ export 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: T._ServerEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ServerArgs<EventName>]
|
? [T.RageFW_ServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerReturn<EventName>> {
|
): Promise<T.RageFW_ServerReturn<EventName>> {
|
||||||
return this._rpc.call(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user