* Fixes

* Remove comment
This commit is contained in:
Dapoulp 2025-08-10 01:23:00 +02:00 committed by GitHub
parent 7faec34597
commit 2aaab73699
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 87 additions and 53 deletions

View file

@ -18,14 +18,12 @@ const targetsField = () =>
);
export default class DHActorRoll extends foundry.abstract.TypeDataModel {
targetHook = null;
static defineSchema() {
return {
title: new fields.StringField(),
roll: new fields.ObjectField(),
targets: targetsField(),
targetSelection: new fields.BooleanField({ initial: false }),
hasRoll: new fields.BooleanField({ initial: false }),
hasDamage: new fields.BooleanField({ initial: false }),
hasHealing: new fields.BooleanField({ initial: false }),
@ -63,42 +61,45 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
}
get targetMode() {
return this.targetSelection;
return this.parent.targetSelection;
}
set targetMode(mode) {
this.targetSelection = mode;
if(!this.parent.isAuthor) return;
this.parent.targetSelection = mode;
this.registerTargetHook();
this.updateTargets();
}
get hitTargets() {
return this.currentTargets.filter(t => t.hit || !this.hasRoll || !this.targetSelection);
return this.currentTargets.filter(t => t.hit || !this.hasRoll || !this.targetMode);
}
async updateTargets() {
if(!ui.chat.collection.get(this.parent.id)) return;
let targets;
if(this.targetSelection)
if(this.targetMode)
targets = this.targets;
else
targets = Array.from(game.user.targets).map(t => game.system.api.fields.ActionFields.TargetField.formatTarget(t));
this.parent.setFlag(game.system.id, "targets", targets);
await this.parent.updateSource({
system: {
targetSelection: this.targetSelection
await this.parent.update({
flags: {
[game.system.id]: {
targets: targets,
targetMode: this.targetMode
}
}
});
})
}
registerTargetHook() {
if(!this.parent.isAuthor) return;
if(this.targetSelection && this.targetHook !== null) {
Hooks.off("targetToken", this.targetHook);
this.targetHook = null;
} else if (!this.targetSelection && this.targetHook === null) {
this.targetHook = Hooks.on('targetToken', foundry.utils.debounce(this.updateTargets.bind(this), 50));
if(this.targetMode && this.parent.targetHook !== null) {
Hooks.off("targetToken", this.parent.targetHook);
return this.parent.targetHook = null;
} else if (!this.targetMode && this.parent.targetHook === null) {
return this.parent.targetHook = Hooks.on('targetToken', foundry.utils.debounce(this.updateTargets.bind(this), 50));
}
}
@ -106,9 +107,8 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
if (this.hasTarget) {
this.hasHitTarget = this.targets.filter(t => t.hit === true).length > 0;
this.currentTargets = this.getTargetList();
this. registerTargetHook();
if(this.targetSelection === true && this.hasRoll) {
if(this.targetMode === true && this.hasRoll) {
this.targetShort = this.targets.reduce((a,c) => {
if(c.hit) a.hit += 1;
else a.miss += 1;
@ -123,7 +123,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
}
getTargetList() {
const targets = this.targetSelection && this.parent.isAuthor ? this.targets : (this.parent.getFlag(game.system.id, "targets") ?? this.targets),
const targets = this.targetMode && this.parent.isAuthor ? this.targets : (this.parent.getFlag(game.system.id, "targets") ?? this.targets),
reactionRolls = this.parent.getFlag(game.system.id, "reactionRolls");
if(reactionRolls) {
@ -137,7 +137,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
}
setPendingSaves() {
this.pendingSaves = this.targetSelection
this.pendingSaves = this.targetMode
? this.targets.filter(target => target.hit && target.saved.success === null).length > 0
: this.currentTargets.filter(target => target.saved.success === null).length > 0;
}