Skip to content

Commit

Permalink
Merge pull request cyruzzo#2492 from Azmoria/Beta---scan-monster-stat…
Browse files Browse the repository at this point in the history
…blocks-for-damage-type-text-immediately-after-roll-buttons-

Beta - scan monster statblocks for damage type text immediately after roll buttons
  • Loading branch information
Azmoria authored Sep 16, 2024
2 parents f13c1b2 + 39418e9 commit 68c79d6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CharactersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,18 @@ function getRollData(rollButton){
}
const modifier = (roll.rolls.length > 1 && expression.match(/[+-]\d*$/g, '')) ? `${roll.rolls[roll.rolls.length-2]}${roll.rolls[roll.rolls.length-1]}` : '';

const followingText = $(rollButton)[0].nextSibling?.textContent?.trim()?.split(' ')[0]
const damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : undefined


return {
roll: roll,
expression: expression,
rollType: rollType,
rollTitle: rollTitle,
modifier: modifier,
regExpression: regExpression
regExpression: regExpression,
damageType: damageType
}
}

Expand Down
4 changes: 2 additions & 2 deletions DiceContextMenu/DiceContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function standard_dice_context_menu(expression, modifierString = "", action = un
return menu;
}

function damage_dice_context_menu(diceExpression, modifierString = "", action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined) {
function damage_dice_context_menu(diceExpression, modifierString = "", action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined, damageType = undefined) {
if (typeof modifierString !== "string") {
modifierString = "";
}
Expand Down Expand Up @@ -96,7 +96,7 @@ function damage_dice_context_menu(diceExpression, modifierString = "", action =
diceRoll.entityType = entityType;
diceRoll.entityId = entityId;

window.diceRoller.roll(diceRoll);
window.diceRoller.roll(diceRoll, undefined, undefined, undefined, undefined, damageType);

});

Expand Down
13 changes: 11 additions & 2 deletions Journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,13 @@ class JournalManager{

$(this).attr('data-actiontype', rollAction);
$(this).attr('data-rolltype', rollType);

const followingText = $(this)[0].nextSibling?.textContent?.trim()?.split(' ')[0]

const damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : undefined
if(damageType != undefined){
$(this).attr('data-damagetype', damageType);
}
})


Expand All @@ -1072,16 +1079,18 @@ class JournalManager{
currentElement = null



$(target).find(".avtt-roll-button").click(clickHandler);
$(target).find(".avtt-roll-button").on("contextmenu", rightClickHandler);

$(target).find("button.avtt-roll-formula-button").off('click.avttRoll').on('click.avttRoll', function(clickEvent) {
clickEvent.stopPropagation();

const slashCommand = $(clickEvent.currentTarget).attr("data-slash-command");
const followingText = $(clickEvent.currentTarget)[0].nextSibling?.textContent?.trim()?.split(' ')[0]
const damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : undefined
const diceRoll = DiceRoll.fromSlashCommand(slashCommand, window.PLAYER_NAME, window.PLAYER_IMG, "character", window.PLAYER_ID); // TODO: add gamelog_send_to_text() once that's available on the characters page without avtt running
window.diceRoller.roll(diceRoll);
window.diceRoller.roll(diceRoll, undefined, undefined, undefined, undefined, damageType);
});
$(target).find(`button.avtt-roll-formula-button`).off('contextmenu.rpg-roller').on('contextmenu.rpg-roller', function(e){
e.stopPropagation();
Expand Down
11 changes: 8 additions & 3 deletions MonsterDice.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function scan_monster(target, stats, tokenId) {
const rollType = $(currentElement).attr("data-rolltype")?.replace(" ","-")
const actionType = $(currentElement).attr("data-rollaction")?.replace(" ","-") || "custom"
const text = $(currentElement)?.text()
$(this).replaceWith(`<button data-exp='${dice}' data-mod='${modifier}' data-rolltype='${rollType}' data-actiontype='${actionType}' class='avtt-roll-button' title="${actionType} ${rollType}">${text}</button>`)
const followingText = $(this)[0].nextSibling?.textContent?.trim()?.split(' ')[0]


$(this).replaceWith(`<button data-exp='${dice}' data-mod='${modifier}' data-rolltype='${rollType}' ${window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? `data-damagetype='${followingText}'` : ''} data-actiontype='${actionType}' class='avtt-roll-button' title="${actionType} ${rollType}">${text}</button>`)
// terminate the clones reference, overkill but rather be safe when it comes to memory
currentElement = null
})
Expand Down Expand Up @@ -323,9 +326,10 @@ function roll_button_contextmenu_handler(contextmenuEvent, displayName, imgUrl,
const modifier = pressedButton.attr('data-mod')?.replaceAll("(", "")?.replaceAll(")", "");
const rollType = pressedButton.attr('data-rolltype');
const actionType = pressedButton.attr('data-actiontype');
const damageType = pressedButton.attr('data-damagetype');

if (rollType === "damage") {
damage_dice_context_menu(`${expression}${modifier}`, modifier, actionType, rollType, displayName, imgUrl, entityType, entityId)
damage_dice_context_menu(`${expression}${modifier}`, modifier, actionType, rollType, displayName, imgUrl, entityType, entityId, damageType)
.present(contextmenuEvent.clientY, contextmenuEvent.clientX) // TODO: convert from iframe to main window
} else {
standard_dice_context_menu(expression, modifier, actionType, rollType, displayName, imgUrl, entityType, entityId)
Expand All @@ -347,6 +351,7 @@ function roll_button_clicked(clickEvent, displayName, imgUrl, entityType = undef
let modifier = pressedButton.attr('data-mod')?.replaceAll("(", "")?.replaceAll(")", "");
let rollType = pressedButton.attr('data-rolltype');
const action = pressedButton.attr('data-actiontype');
const damageType = pressedButton.attr('data-damagetype');
modifier = modifier == 0 ? '+0' : modifier;

window.diceRoller.roll(new DiceRoll(
Expand All @@ -357,7 +362,7 @@ function roll_button_clicked(clickEvent, displayName, imgUrl, entityType = undef
imgUrl,
entityType,
entityId
));
), undefined, undefined, undefined, undefined, damageType);

pressedButton = null
}
Expand Down
2 changes: 1 addition & 1 deletion MonsterStatBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function display_stat_block_in_container(statBlock, container, tokenId, customSt



window.diceRoller.roll(diceRoll, true);
window.diceRoller.roll(diceRoll, true, undefined, undefined, undefined, data.damageType);

}
}
Expand Down

0 comments on commit 68c79d6

Please sign in to comment.