mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
parent
f87dfe477a
commit
c7f3ec8ab3
10 changed files with 156 additions and 388 deletions
|
|
@ -64,9 +64,9 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
return actionItem.system.actionsList?.find(a => a.id === this.source.action);
|
||||
}
|
||||
|
||||
get messageTemplate() {
|
||||
return 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
||||
}
|
||||
// get messageTemplate() {
|
||||
// return 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
||||
// }
|
||||
|
||||
get targetMode() {
|
||||
return this.targetSelection;
|
||||
|
|
@ -100,7 +100,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
this.oldTargets.push(ct);
|
||||
});
|
||||
if(this.hasSave) this.setPendingSaves();
|
||||
if(this.currentTargets.length) {
|
||||
// if(this.currentTargets.length) {
|
||||
if(!this.parent._id) return;
|
||||
const updates = await this.parent.update(
|
||||
{
|
||||
|
|
@ -111,7 +111,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
);
|
||||
if(!updates && ui.chat.collection.get(this.parent.id))
|
||||
ui.chat.updateMessage(this.parent);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -275,6 +275,7 @@ export function ActionMixin(Base) {
|
|||
}
|
||||
};
|
||||
|
||||
ChatMessage.applyRollMode(msg, game.settings.get('core', 'rollMode'));
|
||||
cls.create(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,16 +31,17 @@ export default class DamageRoll extends DHRoll {
|
|||
}
|
||||
|
||||
static async buildPost(roll, config, message) {
|
||||
const chatMessage = config.source?.message ? ui.chat.collection.get(config.source.message) : getDocumentClass('ChatMessage').applyRollMode({}, config.rollMode);
|
||||
if (game.modules.get('dice-so-nice')?.active) {
|
||||
const pool = foundry.dice.terms.PoolTerm.fromRolls(
|
||||
Object.values(config.damage).flatMap(r => r.parts.map(p => p.roll))
|
||||
),
|
||||
diceRoll = Roll.fromTerms([pool]);
|
||||
await game.dice3d.showForRoll(diceRoll, game.user, true);
|
||||
await game.dice3d.showForRoll(diceRoll, game.user, true, chatMessage.whisper, chatMessage.blind);
|
||||
}
|
||||
await super.buildPost(roll, config, message);
|
||||
if (config.source?.message) {
|
||||
const chatMessage = ui.chat.collection.get(config.source.message);
|
||||
// const chatMessage = ui.chat.collection.get(config.source.message);
|
||||
chatMessage.update({ 'system.damage': config.damage });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ export default class DHRoll extends Roll {
|
|||
|
||||
static messageType = 'adversaryRoll';
|
||||
|
||||
static CHAT_TEMPLATE = 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
||||
|
||||
static DefaultDialog = D20RollDialog;
|
||||
|
||||
static async build(config = {}, message = {}) {
|
||||
|
|
@ -95,6 +97,39 @@ export default class DHRoll extends Roll {
|
|||
if(roll._evaluated) return await cls.create(msg, { rollMode: config.selectedRollMode });
|
||||
return msg;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async render({flavor, template=this.constructor.CHAT_TEMPLATE, isPrivate=false, ...options}={}) {
|
||||
if ( !this._evaluated ) return;
|
||||
const chatData = await this._prepareChatRenderContext({flavor, isPrivate, ...options});
|
||||
return foundry.applications.handlebars.renderTemplate(template, chatData);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async _prepareChatRenderContext({flavor, isPrivate=false, ...options}={}) {
|
||||
if(isPrivate) {
|
||||
return {
|
||||
user: game.user.id,
|
||||
flavor: null,
|
||||
title: "???",
|
||||
roll: {
|
||||
total: "??"
|
||||
},
|
||||
hasRoll: true,
|
||||
isPrivate
|
||||
}
|
||||
} else {
|
||||
options.message.system.user = game.user.id;
|
||||
return options.message.system;
|
||||
}
|
||||
// return {
|
||||
// formula: isPrivate ? "???" : this._formula,
|
||||
// flavor: isPrivate ? null : flavor ?? this.options.flavor,
|
||||
// user: game.user.id,
|
||||
// tooltip: isPrivate ? "" : await this.getTooltip(),
|
||||
// total: isPrivate ? "?" : Math.round(this.total * 100) / 100
|
||||
// };
|
||||
}
|
||||
|
||||
static applyKeybindings(config) {
|
||||
if (config.event)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ export default class DualityRoll extends D20Roll {
|
|||
}
|
||||
if (this.rallyFaces)
|
||||
this.terms.push(
|
||||
new foundry.dice.terms.OperatorTerm({ operator: this.hasDisadvantage ? '-' : '+' }),
|
||||
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
||||
new foundry.dice.terms.Die({ faces: this.rallyFaces })
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,48 @@
|
|||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||
async renderHTML() {
|
||||
if (this.system.messageTemplate)
|
||||
this.content = await foundry.applications.handlebars.renderTemplate(this.system.messageTemplate, {
|
||||
...this.system,
|
||||
_source: this.system._source
|
||||
});
|
||||
// if (this.system.messageTemplate)
|
||||
// this.content = await foundry.applications.handlebars.renderTemplate(this.system.messageTemplate, {
|
||||
// ...this.system,
|
||||
// _source: this.system._source
|
||||
// });
|
||||
|
||||
const actor = game.actors.get(this.speaker.actor);
|
||||
const actorData = actor ?? {
|
||||
const actorData = actor && this.isContentVisible ? actor : {
|
||||
img: this.author.avatar ? this.author.avatar : 'icons/svg/mystery-man.svg',
|
||||
name: ''
|
||||
};
|
||||
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
|
||||
const html = await super.renderHTML({ actor: actorData, author: this.author });
|
||||
this.applyPermission(html);
|
||||
|
||||
if (this.type === 'dualityRoll') {
|
||||
this.enrichChatMessage(html);
|
||||
this.addChatListeners(html);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/* async _preCreate(data, options, user) {
|
||||
options.speaker = ChatMessage.getSpeaker();
|
||||
const rollActorOwner = data.rolls?.[0]?.data?.parent?.owner;
|
||||
if (rollActorOwner) {
|
||||
data.author = rollActorOwner ? rollActorOwner.id : data.author;
|
||||
await this.updateSource({ author: rollActorOwner ?? user });
|
||||
}
|
||||
|
||||
return super._preCreate(data, options, rollActorOwner ?? user);
|
||||
} */
|
||||
|
||||
enrichChatMessage(html) {
|
||||
const elements = html.querySelectorAll('[data-perm-id]');
|
||||
elements.forEach(e => {
|
||||
const uuid = e.dataset.permId,
|
||||
document = fromUuidSync(uuid);
|
||||
if (!document) return;
|
||||
|
||||
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
|
||||
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
|
||||
});
|
||||
|
||||
if (this.isContentVisible && this.type === 'dualityRoll') {
|
||||
html.classList.add('duality');
|
||||
switch (this.system.roll?.result?.duality) {
|
||||
case 1:
|
||||
|
|
@ -29,36 +56,9 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.enrichChatMessage(html);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
applyPermission(html) {
|
||||
const elements = html.querySelectorAll('[data-perm-id]');
|
||||
elements.forEach(e => {
|
||||
const uuid = e.dataset.permId,
|
||||
document = fromUuidSync(uuid);
|
||||
if (!document) return;
|
||||
|
||||
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
|
||||
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
|
||||
});
|
||||
}
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
options.speaker = ChatMessage.getSpeaker();
|
||||
const rollActorOwner = data.rolls?.[0]?.data?.parent?.owner;
|
||||
if (rollActorOwner) {
|
||||
data.author = rollActorOwner ? rollActorOwner.id : data.author;
|
||||
await this.updateSource({ author: rollActorOwner ?? user });
|
||||
}
|
||||
|
||||
return super._preCreate(data, options, rollActorOwner ?? user);
|
||||
}
|
||||
|
||||
enrichChatMessage(html) {
|
||||
addChatListeners(html) {
|
||||
html.querySelectorAll('.damage-button').forEach(element =>
|
||||
element.addEventListener('click', this.onDamage.bind(this))
|
||||
);
|
||||
|
|
@ -66,6 +66,12 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
html.querySelectorAll('.duality-action-effect').forEach(element =>
|
||||
element.addEventListener('click', this.onApplyEffect.bind(this))
|
||||
);
|
||||
|
||||
html.querySelectorAll('.roll-target').forEach(element => {
|
||||
element.addEventListener('mouseenter', this.hoverTarget);
|
||||
element.addEventListener('mouseleave', this.unhoverTarget);
|
||||
element.addEventListener('click', this.clickTarget);
|
||||
});
|
||||
}
|
||||
|
||||
getTargetList() {
|
||||
|
|
@ -146,4 +152,25 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
|||
if (action) action.consume(this.system, true);
|
||||
}
|
||||
}
|
||||
|
||||
hoverTarget(event) {
|
||||
event.stopPropagation();
|
||||
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
||||
if (!token?.controlled) token._onHoverIn(event, { hoverOutOthers: true });
|
||||
}
|
||||
|
||||
unhoverTarget(event) {
|
||||
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
||||
if (!token?.controlled) token._onHoverOut(event);
|
||||
}
|
||||
|
||||
clickTarget(event) {
|
||||
event.stopPropagation();
|
||||
const token = canvas.tokens.get(event.currentTarget.dataset.token);
|
||||
if (!token) {
|
||||
ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.attackTargetDoesNotExist'));
|
||||
return;
|
||||
}
|
||||
game.canvas.pan(token);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue