Rpc integration + type fixes #3

Merged
rilaxik merged 26 commits from dev into master 2024-10-28 12:13:19 +00:00
10 changed files with 25 additions and 30 deletions
Showing only changes of commit fafcdb50a8 - Show all commits

View File

@ -37,7 +37,7 @@ class Cef {
}
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(
'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(
'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 = {
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
* These only include custom events
* These only include custom events and some extras from RageFW
*/
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 './player'
export * from './browser'
export * from './logger'

View File

@ -1,19 +1,19 @@
export class Logger {
public error(message: unknown) {
public error(...message: unknown[]) {
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(
`[${new Date().toLocaleTimeString()}] [WARN] ${message}`,
`[${new Date().toLocaleTimeString()}] [WARN] ${message.join(' ')}`,
)
}
public info(message: unknown) {
public info(...message: unknown[]) {
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>> {
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)
}
}

View File

@ -1,9 +1,8 @@
import { Browser, Client, Logger, Player } from './core'
import { Client, Logger, Player } from './core'
export const fw = {
event: new Client(),
player: new Player(),
browser: new Browser(),
system: {
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> =
K extends keyof RageFW_ICustomClientEvent
? ReturnType<RageFW_ICustomClientEvent[K]>
: never
: void
export type _ClientEventHasArgs<
EventName extends keyof RageFW_ICustomClientEvent,

View File

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

View File

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