triggerClient / register client event

This commit is contained in:
Oleksandr Honcharov 2024-06-10 15:54:13 +03:00
parent 3b20276486
commit bea9d570ad
5 changed files with 29 additions and 10 deletions

View File

@ -11,11 +11,11 @@
"types": "dts-bundle-generator --config dts.config.json" "types": "dts-bundle-generator --config dts.config.json"
}, },
"peerDependencies": { "peerDependencies": {
"@ragempcommunity/types-client": "^2.1.8",
"rage-fw-shared-types": "workspace:^" "rage-fw-shared-types": "workspace:^"
}, },
"dependencies": { "dependencies": {
"rage-rpc": "^0.4.0" "rage-rpc": "^0.4.0",
"@ragempcommunity/types-client": "^2.1.8"
}, },
"keywords": [], "keywords": [],
"author": "SashaGoncharov19", "author": "SashaGoncharov19",

View File

@ -1,10 +1,21 @@
import rpc from 'rage-rpc' import rpc from 'rage-rpc'
import type { import {
RageFW_ClientEventReturn, RageFW_ClientEventReturn,
RageFW_ClientEvent, RageFW_ClientEvent,
RageFW_ClientEventArguments, RageFW_ClientEventArguments,
RageFW_ClientServerCallback,
RageFW_ClientServerEvent,
} from './types' } from './types'
class Client {
public register<EventName extends RageFW_ClientServerEvent>(
eventName: EventName,
callback: RageFW_ClientServerCallback<EventName>,
): void {
rpc.register(eventName, callback as rpc.ProcedureListener)
}
}
class Player { class Player {
public triggerServer<EventName extends RageFW_ClientEvent>( public triggerServer<EventName extends RageFW_ClientEvent>(
eventName: EventName, eventName: EventName,
@ -14,6 +25,7 @@ class Player {
} }
} }
export const rage = { export const fw = {
event: new Client(),
player: new Player(), player: new Player(),
} }

View File

@ -1,6 +1,9 @@
/// <reference types="@ragempcommunity/types-client" /> /// <reference types="@ragempcommunity/types-client" />
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types' import type {
RageFW_ICustomClientEvent,
RageFW_ICustomServerEvent,
} from 'rage-fw-shared-types'
export type RageFW_ClientEvent = export type RageFW_ClientEvent =
| keyof RageFW_ICustomClientEvent | keyof RageFW_ICustomClientEvent
@ -15,3 +18,9 @@ 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 RageFW_ClientServerEvent = keyof RageFW_ICustomServerEvent
export type RageFW_ClientServerCallback<K extends RageFW_ClientServerEvent> = (
args: Parameters<RageFW_ICustomServerEvent[K]>,
) => ReturnType<RageFW_ICustomServerEvent[K]>

View File

@ -6,10 +6,7 @@
"entries": [ "entries": [
{ {
"filePath": "./src/index.ts", "filePath": "./src/index.ts",
"outFile": "./dist/index.d.ts", "outFile": "./dist/index.d.ts"
"libraries": {
"inlinedLibraries": ["@ragempcommunity/types-server"]
}
} }
] ]
} }

View File

@ -15,7 +15,8 @@
"rage-fw-shared-types": "workspace:^" "rage-fw-shared-types": "workspace:^"
}, },
"dependencies": { "dependencies": {
"rage-rpc": "^0.4.0" "rage-rpc": "^0.4.0",
"@ragempcommunity/types-server": "^2.1.8"
}, },
"keywords": [], "keywords": [],
"author": "SashaGoncharov19", "author": "SashaGoncharov19",