Skip to content

Commit

Permalink
Feat/chatcard-damage (#70)
Browse files Browse the repository at this point in the history
* chatCard-damage

setting added

* chatCard-damage

* fix: added i18 strings and missing bracket

Co-authored-by: Grim <[email protected]>
  • Loading branch information
anthonyronda and RabidOwlbear authored Jan 30, 2022
1 parent 6c2b523 commit 5ed461a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
"OSE.Setting.Languages": "Languages",
"OSE.Setting.LanguagesHint": "Enter a comma separated list of languages",
"OSE.Setting.EnableInventory": "Enable Inventory",
"OSE.Setting.applyDamageOption": "Token Damage Target",
"OSE.Setting.applyDamageOptionHint": "Which token(s) to apply damage to on an attack roll",
"OSE.Setting.damageSelected": "Selected",
"OSE.Setting.damageTarget": "Target",

"OSE.items.Equip": "Equip",
"OSE.items.Unequip": "Unequip",
Expand Down
55 changes: 37 additions & 18 deletions src/module/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,57 @@
*
* @return {Array} The extended options Array including new context choices
*/
export const addChatMessageContextOptions = function(html, options) {
let canApply = li => canvas.tokens.controlled.length && li.find(".dice-roll").length;
export const addChatMessageContextOptions = function (html, options) {
let canApply = (li) =>
canvas.tokens.controlled.length && li.find(".dice-roll").length;
options.push(
{
name: game.i18n.localize("OSE.messages.applyDamage"),
icon: '<i class="fas fa-user-minus"></i>',
condition: canApply,
callback: li => applyChatCardDamage(li, 1)
callback: (li) => applyChatCardDamage(li, 1),
},
{
name: game.i18n.localize("OSE.messages.applyHealing"),
icon: '<i class="fas fa-user-plus"></i>',
condition: canApply,
callback: li => applyChatCardDamage(li, -1)
callback: (li) => applyChatCardDamage(li, -1),
}
);
return options;
};

/* -------------------------------------------- */

export const addChatMessageButtons = function(msg, html, data) {
export const addChatMessageButtons = function (msg, html, data) {
// Hide blind rolls
let blindable = html.find('.blindable');
if (msg.data.blind && !game.user.isGM && blindable && blindable.data('blind') === true) {
blindable.replaceWith("<div class='dice-roll'><div class='dice-result'><div class='dice-formula'>???</div></div></div>");
let blindable = html.find(".blindable");
if (
msg.data.blind &&
!game.user.isGM &&
blindable &&
blindable.data("blind") === true
) {
blindable.replaceWith(
"<div class='dice-roll'><div class='dice-result'><div class='dice-formula'>???</div></div></div>"
);
}
// Buttons
let roll = html.find('.damage-roll');
let roll = html.find(".damage-roll");
if (roll.length > 0) {
let total = roll.find('.dice-total');
let total = roll.find(".dice-total");
let value = total.text();
roll.append($(`<div class="dice-damage"><button type="button" data-action="apply-damage"><i class="fas fa-tint"></i></button></div>`))
roll.append(
$(
`<div class="dice-damage"><button type="button" data-action="apply-damage"><i class="fas fa-tint"></i></button></div>`
)
);
roll.find('button[data-action="apply-damage"]').click((ev) => {
ev.preventDefault();
applyChatCardDamage(roll, 1);
})
});
}
}
};

/**
* Apply rolled dice damage to the token or tokens which are currently controlled.
Expand All @@ -56,11 +68,18 @@ export const addChatMessageButtons = function(msg, html, data) {
* @return {Promise}
*/
function applyChatCardDamage(roll, multiplier) {
const amount = roll.find('.dice-total').last().text();
return Promise.all(canvas.tokens.controlled.map(t => {
const a = t.actor;
return a.applyDamage(amount, multiplier);
}));
const amount = roll.find(".dice-total").last().text();
const dmgTgt = game.settings.get("ose", "applyDamageOption");
if (dmgTgt === `targeted`) {
game.user.targets.forEach(async (t) => {
if (game.user.isGM) return await t.actor.applyDamage(amount, multiplier);
});
}
if (dmgTgt === `selected`) {
canvas.tokens.controlled.forEach(async (t) => {
if (game.user.isGM) return await t.actor.applyDamage(amount, multiplier);
});
}
}

/* -------------------------------------------- */
13 changes: 13 additions & 0 deletions src/module/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ export const registerSettings = function () {
config: true,
onChange: _ => window.location.reload()
});
game.settings.register('ose', 'applyDamageOption', {
name: game.i18n.localize('OSE.Setting.applyDamageOption'),
hint: game.i18n.localize('OSE.Setting.applyDamageOptionHint'),
default: 'selected',
scope: 'world',
type: String,
config: true,
choices: {
selected: 'OSE.Setting.damageSelected',
targeted: 'OSE.Setting.damageTarget'
},
onChange: _ => window.location.reload()
});
};

0 comments on commit 5ed461a

Please sign in to comment.