-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
17 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# 1.0.3 | ||
|
||
- Simplify `onSync` logic to just pass any entity. | ||
- Allows for more control over what to do with entity data when onSync is called. | ||
|
||
# 1.0.2 | ||
|
||
- Fixed bug where specifying `_id` would not convert it to ObjectID for usage. |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { onKeyChange } from './keyChange.js'; | ||
export * as onSync from './onSync.js'; | ||
export { onSync } from './onSync.js'; |
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 |
---|---|---|
@@ -1,51 +1,19 @@ | ||
import * as alt from 'alt-server'; | ||
|
||
const callbacks: { [key: string]: Array<(entity: alt.Entity) => void> } = {}; | ||
|
||
function bindCallback(type: string, callback: (entity: alt.Entity) => void) { | ||
if (!callbacks[type]) { | ||
callbacks[type] = []; | ||
} | ||
|
||
callbacks[type].push(callback); | ||
} | ||
const callbacks: Array<(entity: alt.Entity) => void> = []; | ||
|
||
export function invoke(entity: alt.Entity) { | ||
const type = entity.constructor.name.toLowerCase(); | ||
const availableCallbacks = callbacks[type]; | ||
if (!availableCallbacks) { | ||
return; | ||
} | ||
|
||
for (let callback of availableCallbacks) { | ||
for (let callback of callbacks) { | ||
callback(entity); | ||
} | ||
} | ||
|
||
export function onPlayer(callback: (entity: alt.Entity) => void) { | ||
bindCallback('player', callback); | ||
} | ||
|
||
export function onVehicle(callback: (entity: alt.Entity) => void) { | ||
bindCallback('vehicle', callback); | ||
} | ||
|
||
export function onColshape(callback: (entity: alt.Entity) => void) { | ||
bindCallback('colshape', callback); | ||
} | ||
|
||
export function onCheckpoint(callback: (entity: alt.Entity) => void) { | ||
bindCallback('checkpoint', callback); | ||
} | ||
|
||
export function onPed(callback: (entity: alt.Entity) => void) { | ||
bindCallback('ped', callback); | ||
} | ||
|
||
export function onObject(callback: (entity: alt.Entity) => void) { | ||
bindCallback('object', callback); | ||
} | ||
|
||
export function onMarker(callback: (entity: alt.Entity) => void) { | ||
bindCallback('marker', callback); | ||
/** | ||
* Calls when an entity has `crc.data.sync` invoked on it. | ||
* | ||
* @export | ||
* @param {(entity: alt.Entity) => void} callback | ||
*/ | ||
export function onSync(callback: (entity: alt.Entity) => void) { | ||
callbacks.push(callback); | ||
} |