* 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

@ -644,16 +644,20 @@ export default class DhpActor extends Actor {
);
break;
case 'armor':
updates.armor.resources['system.marks.value'] = Math.max(
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
0
);
if(this.system.armor?.system?.marks) {
updates.armor.resources['system.marks.value'] = Math.max(
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
0
);
}
break;
default:
updates.actor.resources[`system.resources.${r.key}.value`] = Math.max(
Math.min(this.system.resources[r.key].value + r.value, this.system.resources[r.key].max),
0
);
if(this.system.resources?.[r.key]) {
updates.actor.resources[`system.resources.${r.key}.value`] = Math.max(
Math.min(this.system.resources[r.key].value + r.value, this.system.resources[r.key].max),
0
);
}
break;
}
}

View file

@ -1,4 +1,7 @@
export default class DhpChatMessage extends foundry.documents.ChatMessage {
targetHook = null;
targetSelection = null;
async renderHTML() {
const actor = game.actors.get(this.speaker.actor);
const actorData = actor && this.isContentVisible ? actor : {
@ -14,6 +17,32 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
return html;
}
/* -------------------------------------------- */
/** @inheritDoc */
prepareData() {
if(this.isAuthor && this.targetSelection === null)
this.targetSelection = this.system.targets?.length > 0;
super.prepareData();
}
/* -------------------------------------------- */
/** @inheritDoc */
_onCreate(data, options, userId) {
super._onCreate(data, options, userId);
if(this.system.registerTargetHook) this.system.registerTargetHook();
}
/* -------------------------------------------- */
/** @inheritDoc */
async _preDelete(options, user) {
if(this.targetHook !== null) Hooks.off("targetToken", this.targetHook);
return super._preDelete(options, user);
}
enrichChatMessage(html) {
const elements = html.querySelectorAll('[data-perm-id]');
elements.forEach(e => {
@ -62,7 +91,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
}
getTargetList() {
const targets = this.system.hitTargets;
const targets = this.system.hitTargets ?? [];
return targets.map(target => game.canvas.tokens.documentCollection.find(t => t.actor?.uuid === target.actorId));
}
@ -134,7 +163,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
}
consumeOnSuccess() {
if (!this.system.successConsumed && !this.system.targetSelection) {
if (!this.system.successConsumed && !this.targetSelection) {
const action = this.system.action;
if (action) action.consume(this.system, true);
}
@ -143,12 +172,12 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
hoverTarget(event) {
event.stopPropagation();
const token = canvas.tokens.get(event.currentTarget.dataset.token);
if (!token?.controlled) token._onHoverIn(event, { hoverOutOthers: true });
if (token && !token?.controlled) token._onHoverIn(event, { hoverOutOthers: true });
}
unhoverTarget(event) {
const token = canvas.tokens.get(event.currentTarget.dataset.token);
if (!token?.controlled) token._onHoverOut(event);
if (token && !token?.controlled) token._onHoverOut(event);
}
clickTarget(event) {
@ -163,6 +192,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
onTargetSelection(event) {
event.stopPropagation();
this.system.targetMode = Boolean(event.target.dataset.targetHit);
if(!event.target.classList.contains("target-selected"))
this.system.targetMode = Boolean(event.target.dataset.targetHit);
}
}