[Feature] 1541 - Trigger Improvements (#1542)

* Improved registration and unregistration of triggers

* Added logging

* Fixed Feature level unregistration

* Fixed action deletion unregistration

* SceneEnvironment stub

* Update module/data/registeredTriggers.mjs

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>

---------

Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
This commit is contained in:
WBHarry 2026-01-16 07:43:25 +01:00 committed by GitHub
parent 4cd6fe58da
commit fad09a1b3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 226 additions and 66 deletions

View file

@ -104,6 +104,16 @@ export default class DhpActor extends Actor {
}
}
async _preDelete() {
if (this.prototypeToken.actorLink) {
game.system.registeredTriggers.unregisterItemTriggers(this.items);
} else {
for (const token of this.getActiveTokens()) {
game.system.registeredTriggers.unregisterItemTriggers(token.actor.items);
}
}
}
_onDelete(options, userId) {
super._onDelete(options, userId);
for (const party of this.parties) {

View file

@ -208,4 +208,23 @@ export default class DHItem extends foundry.documents.Item {
cls.create(msg);
}
deleteTriggers() {
const actions = Array.from(this.system.actions ?? []);
if (!actions.length) return;
const triggerKeys = actions.flatMap(action => action.triggers.map(x => x.trigger));
game.system.registeredTriggers.unregisterTriggers(triggerKeys, this.uuid);
if (!(this.actor.parent instanceof game.system.api.documents.DhToken)) {
for (const token of this.actor.getActiveTokens()) {
game.system.registeredTriggers.unregisterTriggers(triggerKeys, `${token.document.uuid}.${this.uuid}`);
}
}
}
async _preDelete() {
this.deleteTriggers();
}
}

View file

@ -536,4 +536,10 @@ export default class DHToken extends CONFIG.Token.documentClass {
};
}
//#endregion
async _preDelete() {
if (this.actor && !this.actor.prototypeToken?.actorLink) {
game.system.registeredTriggers.unregisterItemTriggers(this.actor.items);
}
}
}