-
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.
Add hook to replace race on character
Closes #384
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import WvActor from "../actor/wvActor.js"; | ||
import { TYPES } from "../constants.js"; | ||
import type WvItem from "../item/wvItem.js"; | ||
|
||
export default function registerForPreCreateItem(): void { | ||
Hooks.on<Hooks.PreCreateDocument<typeof Item>>( | ||
"preCreateItem", | ||
replaceCharacterRace | ||
); | ||
} | ||
|
||
type HookParams = Parameters<Hooks.PreCreateDocument<typeof Item>>; | ||
|
||
/** | ||
* Replace existing Race items on an actor, if a Race is created on an actor. | ||
*/ | ||
function replaceCharacterRace(document: HookParams[0]): false | void { | ||
if ( | ||
document.data.type !== TYPES.ITEM.RACE || | ||
!(document.parent instanceof WvActor) | ||
) | ||
return; | ||
|
||
document.parent.deleteEmbeddedDocuments( | ||
"Item", | ||
document.parent.itemTypes.race | ||
.filter((item): item is StoredDocument<WvItem> => item.id !== null) | ||
.map((item) => item.id) | ||
); | ||
} |
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