triggerClient / register client event
This commit is contained in:
parent
3b20276486
commit
bea9d570ad
@ -11,11 +11,11 @@
|
||||
"types": "dts-bundle-generator --config dts.config.json"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@ragempcommunity/types-client": "^2.1.8",
|
||||
"rage-fw-shared-types": "workspace:^"
|
||||
},
|
||||
"dependencies": {
|
||||
"rage-rpc": "^0.4.0"
|
||||
"rage-rpc": "^0.4.0",
|
||||
"@ragempcommunity/types-client": "^2.1.8"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "SashaGoncharov19",
|
||||
|
@ -1,10 +1,21 @@
|
||||
import rpc from 'rage-rpc'
|
||||
import type {
|
||||
import {
|
||||
RageFW_ClientEventReturn,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ClientEventArguments,
|
||||
RageFW_ClientServerCallback,
|
||||
RageFW_ClientServerEvent,
|
||||
} 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 {
|
||||
public triggerServer<EventName extends RageFW_ClientEvent>(
|
||||
eventName: EventName,
|
||||
@ -14,6 +25,7 @@ class Player {
|
||||
}
|
||||
}
|
||||
|
||||
export const rage = {
|
||||
export const fw = {
|
||||
event: new Client(),
|
||||
player: new Player(),
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
/// <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 =
|
||||
| keyof RageFW_ICustomClientEvent
|
||||
@ -15,3 +18,9 @@ export type RageFW_ClientEventReturn<K extends RageFW_ClientEvent> =
|
||||
K extends keyof RageFW_ICustomClientEvent
|
||||
? ReturnType<RageFW_ICustomClientEvent[K]>
|
||||
: 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]>
|
||||
|
@ -6,10 +6,7 @@
|
||||
"entries": [
|
||||
{
|
||||
"filePath": "./src/index.ts",
|
||||
"outFile": "./dist/index.d.ts",
|
||||
"libraries": {
|
||||
"inlinedLibraries": ["@ragempcommunity/types-server"]
|
||||
}
|
||||
"outFile": "./dist/index.d.ts"
|
||||
}
|
||||
]
|
||||
}
|
@ -15,7 +15,8 @@
|
||||
"rage-fw-shared-types": "workspace:^"
|
||||
},
|
||||
"dependencies": {
|
||||
"rage-rpc": "^0.4.0"
|
||||
"rage-rpc": "^0.4.0",
|
||||
"@ragempcommunity/types-server": "^2.1.8"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "SashaGoncharov19",
|
||||
|
Loading…
Reference in New Issue
Block a user