-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: system events, document checking, etc. (#14)
- Loading branch information
Showing
15 changed files
with
264 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Events | ||
|
||
These events are unique to the Rebar framework, and help provide information about when something happens. | ||
|
||
## Usage | ||
|
||
```ts | ||
import { useRebar } from '@Server/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
const RebarEvents = Rebar.events.useEvents(); | ||
|
||
// Called when an account is bound to a player | ||
RebarEvents.on('account-bound', (player, document) => { | ||
console.log(document); | ||
}); | ||
|
||
// Called when a character is bound to a player | ||
RebarEvents.on('character-bound', (player, document) => { | ||
console.log(document); | ||
}); | ||
|
||
// Called when a vehicle document is bound to a vehicle | ||
RebarEvents.on('vehicle-bound', (vehicle, document) => { | ||
console.log(document); | ||
}); | ||
|
||
// Called when a player sends a message | ||
RebarEvents.on('message', (player, msg) => { | ||
console.log(msg); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
expanded: false | ||
label: 'Events' | ||
order: -1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Check | ||
|
||
Check if a player has an account bound, or character bound. | ||
|
||
```ts | ||
import { useRebar } from '@Server/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
|
||
Rebar.player.useStatus(somePlayer).hasCharacter(); // Returns true / false | ||
Rebar.player.useStatus(somePlayer).hasAccount(); // Returns true / false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as alt from 'alt-server'; | ||
import { Account } from '@Shared/types/account.js'; | ||
import { Character } from '@Shared/types/character.js'; | ||
import { Vehicle } from '@Shared/types/vehicle.js'; | ||
|
||
type RebarEvents = { | ||
'account-bound': (player: alt.Player, document: Account) => void; | ||
'character-bound': (player: alt.Player, document: Character) => void; | ||
'vehicle-bound': (vehicle: alt.Vehicle, document: Vehicle) => void; | ||
message: (player: alt.Player, message: string) => void; | ||
}; | ||
|
||
type EventCallbacks<K extends keyof RebarEvents> = { [key in K]: RebarEvents[K][] }; | ||
|
||
const eventCallbacks: EventCallbacks<keyof RebarEvents> = { | ||
'account-bound': [], | ||
'character-bound': [], | ||
'vehicle-bound': [], | ||
message: [], | ||
}; | ||
|
||
export function useEvents() { | ||
function on<K extends keyof RebarEvents>(event: K, callback: RebarEvents[K]) { | ||
eventCallbacks[event].push(callback); | ||
} | ||
|
||
function invoke<K extends keyof RebarEvents>(event: K, ...args: Parameters<RebarEvents[K]>) { | ||
for (let cb of eventCallbacks[event]) { | ||
// Normally I would not do this but I know this works, and TypeScript is being a jerk. | ||
// @ts-ignore | ||
cb(...args); | ||
} | ||
} | ||
|
||
return { | ||
invoke, | ||
on, | ||
}; | ||
} |
Oops, something went wrong.