mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
parent
7faec34597
commit
2aaab73699
11 changed files with 87 additions and 53 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue