- moved browser to player instance
- logger accepts multiple arguments
- changed error messages
This commit is contained in:
Danya H 2024-09-30 20:39:20 +01:00
parent cf9c4ce691
commit fafcdb50a8
10 changed files with 25 additions and 30 deletions

View File

@ -37,7 +37,7 @@ class Cef {
} }
return Promise.reject( return Promise.reject(
'RageFW was started in window which not contain global variable MP!', 'RageFW was started in window which does not contain MP',
) )
} }
@ -52,7 +52,7 @@ class Cef {
} }
return Promise.reject( return Promise.reject(
'RageFW was started in window which not contain global variable MP!', 'RageFW was started in window which does not contain MP',
) )
} }
@ -67,7 +67,7 @@ class Cef {
} }
return Promise.reject( return Promise.reject(
'RageFW was started in window which not contain global variable MP!', 'RageFW was started in window which does not contain MP',
) )
} }
} }
@ -75,3 +75,6 @@ class Cef {
export const fw = { export const fw = {
event: new Cef(), event: new Cef(),
} }
;(async () => {
await fw.event.triggerClient('cefReady')
})()

View File

@ -4,7 +4,7 @@ export type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
/** /**
* Union of all available client event names * Union of all available client event names
* These only include custom events * These only include custom events and some extras from RageFW
*/ */
export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent export type RageFW_ClientEvent = keyof RageFW_ICustomClientEvent

View File

@ -1,8 +0,0 @@
import { Player } from './'
export class Browser extends Player {
public registerBrowser(browser: BrowserMp) {
this.browser = browser
return browser
}
}

View File

@ -1,4 +1,3 @@
export * from './client' export * from './client'
export * from './player' export * from './player'
export * from './browser'
export * from './logger' export * from './logger'

View File

@ -1,19 +1,19 @@
export class Logger { export class Logger {
public error(message: unknown) { public error(...message: unknown[]) {
mp.console.logError( mp.console.logError(
`[${new Date().toLocaleTimeString()}] [ERROR] ${message}`, `[${new Date().toLocaleTimeString()}] [ERROR] ${message.join(' ')}`,
) )
} }
public warn(message: unknown) { public warn(...message: unknown[]) {
mp.console.logWarning( mp.console.logWarning(
`[${new Date().toLocaleTimeString()}] [WARN] ${message}`, `[${new Date().toLocaleTimeString()}] [WARN] ${message.join(' ')}`,
) )
} }
public info(message: unknown) { public info(...message: unknown[]) {
mp.console.logInfo( mp.console.logInfo(
`[${new Date().toLocaleTimeString()}] [INFO] ${message}`, `[${new Date().toLocaleTimeString()}] [INFO] ${message.join(' ')}`,
) )
} }
} }

View File

@ -43,7 +43,7 @@ export class Player {
: [] : []
): Promise<RageFW_CefReturn<EventName>> { ): Promise<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 rpc.callBrowser(this.browser, eventName, args) return rpc.callBrowser(this.browser, eventName, args)
} }
} }

View File

@ -1,9 +1,8 @@
import { Browser, Client, Logger, Player } from './core' import { Client, Logger, Player } from './core'
export const fw = { export const fw = {
event: new Client(), event: new Client(),
player: new Player(), player: new Player(),
browser: new Browser(),
system: { system: {
log: new Logger(), log: new Logger(),
}, },

View File

@ -36,7 +36,7 @@ export type RageFW_ClientCallback<K extends RageFW_ClientEvent> = (
export type RageFW_ClientReturn<K extends RageFW_ClientEvent> = export type RageFW_ClientReturn<K extends RageFW_ClientEvent> =
K extends keyof RageFW_ICustomClientEvent K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]> ? ReturnType<RageFW_ICustomClientEvent[K]>
: never : void
export type _ClientEventHasArgs< export type _ClientEventHasArgs<
EventName extends keyof RageFW_ICustomClientEvent, EventName extends keyof RageFW_ICustomClientEvent,

View File

@ -23,15 +23,15 @@ export class Logger {
), ),
}) })
public info(message: unknown) { public info(...message: unknown[]) {
this.systemLogger.info(message) this.systemLogger.info(message.join(' '))
} }
public warn(message: unknown) { public warn(...message: unknown[]) {
this.systemLogger.warn(message) this.systemLogger.warn(message.join(' '))
} }
public error(message: unknown) { public error(...message: unknown[]) {
this.systemLogger.error(message) this.systemLogger.error(message.join(' '))
} }
} }

View File

@ -1,7 +1,9 @@
declare module 'rage-fw-shared-types' { declare module 'rage-fw-shared-types' {
export interface RageFW_ICustomServerEvent {} export interface RageFW_ICustomServerEvent {}
export interface RageFW_ICustomClientEvent {} export interface RageFW_ICustomClientEvent {
cefReady(): void
}
export interface RageFW_ICustomCefEvent {} export interface RageFW_ICustomCefEvent {}
} }