Skip to content

Commit

Permalink
Merge pull request cyruzzo#2290 from Azmoria/QoL---icon-and-cast-butt…
Browse files Browse the repository at this point in the history
…on-rolls-will-now-send-the-save-type-and-DC-to-the-gamelog

QoL - icon and cast button rolls will now send the save type and DC to the gamelog
  • Loading branch information
Azmoria committed Jul 4, 2024
2 parents 25823a5 + cd5e131 commit 68dffa9
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 15 deletions.
67 changes: 59 additions & 8 deletions CharactersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,12 @@ function observe_character_sheet_changes(documentToObserve) {
e.stopPropagation();
$(this).closest('.ct-content-group').find(`.ct-slot-manager [aria-checked='false']`).first().click();

let rollButtons = $(this).parent().find(`.integrated-dice__container:not('.avtt-roll-formula-button'):not('.above-vtt-visited'):not('.above-vtt-dice-visited')`);
let rollButtons = $(this).parent().find(`.integrated-dice__container:not('.avtt-roll-formula-button'):not('.above-vtt-visited'):not('.above-vtt-dice-visited'):not('.above-aoe'), .integrated-dice__container.abovevtt-icon-roll`);
let spellSave = $(this).parent().find(`.ct-spells-spell__save`);
let spellSaveText;
if(spellSave.length>0){
spellSaveText = `${spellSave.find('.ct-spells-spell__save-label').text().toUpperCase()} DC${spellSave.find('.ct-spells-spell__save-value').text()}`;
}
for(let i = 0; i<rollButtons.length; i++){
let data = getRollData(rollButtons[i]);
let diceRoll;
Expand All @@ -818,14 +823,36 @@ function observe_character_sheet_changes(documentToObserve) {
else if(e.ctrlKey || e.metaKey){
diceRoll = new DiceRoll(`2d20kl1${data.modifier}`, data.rollTitle, data.rollType);
}else{
diceRoll = new DiceRoll(data.expression, data.rollTitle, data.rollType)
diceRoll = new DiceRoll(data.expression, data.rollTitle, data.rollType);
}
}
else{
diceRoll = new DiceRoll(data.expression, data.rollTitle, data.rollType)
}
window.diceRoller.roll(diceRoll, true, window.CHARACTER_AVTT_SETTINGS.critRange ? window.CHARACTER_AVTT_SETTINGS.critRange : 20, window.CHARACTER_AVTT_SETTINGS.crit ? window.CHARACTER_AVTT_SETTINGS.crit : 2);
window.diceRoller.roll(diceRoll, true, window.CHARACTER_AVTT_SETTINGS.critRange ? window.CHARACTER_AVTT_SETTINGS.critRange : 20, window.CHARACTER_AVTT_SETTINGS.crit ? window.CHARACTER_AVTT_SETTINGS.crit : 2, spellSaveText);
spellSaveText = undefined;
}
}
if(rollButtons.length == 0 && spellSaveText != undefined){
let msgdata = {
player: window.PLAYER_NAME,
img: window.PLAYER_IMG,
text: `<div class='custom-spell-save-text' style='font-weight:600'><span>Casts ${$(this).parent().find('[class*="styles_spellName"]').text()}: </span><span>${spellSaveText}</span></div>`,
playerId: window.PLAYER_ID,
sendTo: window.sendToTab
}
if(is_abovevtt_page()){
window.MB.inject_chat(msgdata)
}
else if(window.sendToTab != undefined){
tabCommunicationChannel.postMessage({
msgType: 'SendToGamelog',
player: msgdata.player,
img: msgdata.img,
text: msgdata.text,
sendTo: msgdata.sendTo
});
}
}
});
if($(`style#advantageHover`).length == 0){
Expand Down Expand Up @@ -1028,7 +1055,12 @@ function observe_character_sheet_changes(documentToObserve) {
e.stopPropagation();
let versatileRoll = window.CHARACTER_AVTT_SETTINGS.versatile;

let rollButtons = $(this).parent().find(`.integrated-dice__container:not('.avtt-roll-formula-button'):not('.above-vtt-visited'):not('.above-vtt-dice-visited'), .integrated-dice__container.abovevtt-icon-roll`);
let rollButtons = $(this).parent().find(`.integrated-dice__container:not('.avtt-roll-formula-button'):not('.above-vtt-visited'):not('.above-vtt-dice-visited'):not('.above-aoe'), .integrated-dice__container.abovevtt-icon-roll`);
let spellSave = $(this).parent().find(`[class*='__save']`);
let spellSaveText;
if(spellSave.length>0){
spellSaveText = `${spellSave.find('[class*="__save-label"]').text().toUpperCase()} DC${spellSave.find('[class*="__save-value"]').text()}`;
}
for(let i = 0; i<rollButtons.length; i++){
let isVersatileDamage = $(rollButtons[i]).parent().hasClass('ddb-combat-item-attack__damage--is-versatile')
if(isVersatileDamage && versatileRoll =='1'){
Expand Down Expand Up @@ -1063,12 +1095,31 @@ function observe_character_sheet_changes(documentToObserve) {
else{
diceRoll = new DiceRoll(data.expression, data.rollTitle, data.rollType)
}
window.diceRoller.roll(diceRoll, true, window.CHARACTER_AVTT_SETTINGS.critRange ? window.CHARACTER_AVTT_SETTINGS.critRange : 20, window.CHARACTER_AVTT_SETTINGS.crit ? window.CHARACTER_AVTT_SETTINGS.crit : 2);

window.diceRoller.roll(diceRoll, true, window.CHARACTER_AVTT_SETTINGS.critRange ? window.CHARACTER_AVTT_SETTINGS.critRange : 20, window.CHARACTER_AVTT_SETTINGS.crit ? window.CHARACTER_AVTT_SETTINGS.crit : 2, spellSaveText);
}
}

});
if(rollButtons.length == 0 && spellSaveText != undefined){
let msgdata = {
player: window.PLAYER_NAME,
img: window.PLAYER_IMG,
text: `<div class='custom-spell-save-text' style='font-weight:600'><span>Casts ${$($(this).parent().find('[class*="__name"]>[class*="__label"]')[0]).text()}: </span><span>${spellSaveText}</span></div>`,
playerId: window.PLAYER_ID,
sendTo: window.sendToTab
}
if(is_abovevtt_page()){
window.MB.inject_chat(msgdata)
}
else if(window.sendToTab != undefined){
tabCommunicationChannel.postMessage({
msgType: 'SendToGamelog',
player: msgdata.player,
img: msgdata.img,
text: msgdata.text,
sendTo: msgdata.sendTo
});
}
}
})
if($(`style#advantageHover`).length == 0){
$('body').append(`
<style id='advantageHover'>
Expand Down
27 changes: 24 additions & 3 deletions DiceRoller.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class DiceRoller {
#critAttackAction = undefined;
#pendingCritRange = undefined;
#pendingCritType = undefined;
#pendingSpellSave = undefined;

/** @returns {boolean} true if a roll has been or will be initiated, and we're actively waiting for DDB messages to come in so we can parse them */
get #waitingForRoll() {
Expand Down Expand Up @@ -284,7 +285,7 @@ class DiceRoller {
* @param diceRoll {DiceRoll} the dice expression to parse and roll. EG: 1d20+4
* @returns {boolean} whether or not dice were rolled
*/
roll(diceRoll, multiroll = false, critRange = 20, critType = 2) {
roll(diceRoll, multiroll = false, critRange = 20, critType = 2, spellSave = undefined) {
try {
if (diceRoll === undefined || diceRoll.expression === undefined || diceRoll.expression.length === 0) {
console.warn("DiceRoller.parseAndRoll received an invalid diceRoll object", diceRoll);
Expand Down Expand Up @@ -348,7 +349,24 @@ class DiceRoller {
msgdata = {
player: diceRoll.name ? diceRoll.name : window.PLAYER_NAME,
img: diceRoll.avatarUrl ? diceRoll.avatarUrl : window.PLAYER_IMG,
text: `<div class="tss-24rg5g-DiceResultContainer-Flex abovevtt-roll-container ${critClass}" title='${diceRoll.expression}<br>${roll.output.replace(regExpression, '')}'><div class="tss-kucurx-Result"><div class="tss-3-Other-ref tss-1o65fpw-Line-Title-Other"><span class='aboveDiceOutput'>${rollTitle}: <span class='abovevtt-roll-${rollType}'>${rollType}</span></span></div></div><svg width="1" height="32" class="tss-10y9gcy-Divider"><path fill="currentColor" d="M0 0h1v32H0z"></path></svg><div class="tss-1jo3bnd-TotalContainer-Flex"><div class="tss-3-Other-ref tss-3-Collapsed-ref tss-3-Pending-ref tss-jpjmd5-Total-Other-Collapsed-Pending-Flex"><span class='aboveDiceTotal'>${roll.total}</span></div></div></div>`,
text: `<div class="tss-24rg5g-DiceResultContainer-Flex abovevtt-roll-container ${critClass}" title='${diceRoll.expression}<br>${roll.output.replace(regExpression, '')}'>
<div class="tss-kucurx-Result">
<div class="tss-3-Other-ref tss-1o65fpw-Line-Title-Other">
<span class='aboveDiceOutput'>${rollTitle}:
<span class='abovevtt-roll-${rollType}'>${rollType}</span>
</span>
</div>
</div>
<svg width="1" height="32" class="tss-10y9gcy-Divider"><path fill="currentColor" d="M0 0h1v32H0z"></path></svg>
<div class="tss-1jo3bnd-TotalContainer-Flex">
<div class="tss-3-Other-ref tss-3-Collapsed-ref tss-3-Pending-ref tss-jpjmd5-Total-Other-Collapsed-Pending-Flex">
<span class='aboveDiceTotal'>${roll.total}</span>
</div>
${spellSave != undefined ? `<div class='custom-spell-save-text'><span>${spellSave}</span></div>` : ''}
</div>
</div>
`,
whisper: (diceRoll.sendToOverride == "DungeonMaster") ? dm_id : ((gamelog_send_to_text() != "Everyone" && diceRoll.sendToOverride != "Everyone") || diceRoll.sendToOverride == "Self") ? window.PLAYER_NAME : ``,
rollType: rollType,
rollTitle: rollTitle,
Expand All @@ -374,7 +392,8 @@ class DiceRoller {
rollType: rollType,
rollTitle: rollTitle,
modifier: modifier,
regExpression: regExpression
regExpression: regExpression,
spellSave: spellSave
}

msgdata = {
Expand Down Expand Up @@ -428,6 +447,7 @@ class DiceRoller {
this.#pendingDiceRoll = new DiceRoll(diceRoll.expression, diceRoll.action, diceRoll.rollType, diceRoll.name, diceRoll.avatarUrl, diceRoll.entityType, diceRoll.entityId);
this.#pendingCritRange = critRange;
this.#pendingCritType = critType;
this.#pendingSpellSave = spellSave;
this.clickDiceButtons(diceRoll);
console.groupEnd();
return true;
Expand Down Expand Up @@ -746,6 +766,7 @@ class DiceRoller {
ddbMessage.avttExpressionResult = this.#pendingDiceRoll.expressionResult;
console.log("DiceRoll ddbMessage.avttExpression: ", ddbMessage.avttExpression);
}
ddbMessage.avttSpellSave = this.#pendingSpellSave;

if (["character", "monster"].includes(this.#pendingDiceRoll.entityType)) {
ddbMessage.entityType = this.#pendingDiceRoll.entityType;
Expand Down
12 changes: 11 additions & 1 deletion MessageBroker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ class MessageBroker {
gamelogItem.attr("data-avtt-expression-result", msg.avttExpressionResult);
replace_gamelog_message_expressions(gamelogItem);
}

if(msg.data.rolls != undefined){
let critSuccess = {};
let critFail = {};
Expand Down Expand Up @@ -1241,7 +1242,16 @@ class MessageBroker {
row++;
}
target.find(`[class*='DiceResultContainer']:nth-of-type(${row})`).toggleClass(`${critSuccess[i] && critFail[i] ? 'crit-mixed' : critSuccess[i] ? 'crit-success' : critFail[i] ? 'crit-fail' : ''}`, true)

if(msg.avttSpellSave !== undefined){

let totalContainer = target.find(`[class*='DiceResultContainer']:nth-of-type(${row}) [class*='TotalContainer-Flex']`);
if (totalContainer.length > 0) {
let spellSave = msg.avttSpellSave;
if (spellSave !== undefined && spellSave.length > 0) {
totalContainer.append(`${spellSave != undefined ? `<div class='custom-spell-save-text'><span class='data-spellSave' data-avtt-spellSave='${spellSave}'>${spellSave}</span></div>` : ''}`);
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $(function() {
event.data.msg.img,
"character",
event.data.msg.playerId
), event.data.multiroll, event.data.critRange, event.data.critType);
), event.data.multiroll, event.data.critRange, event.data.critType, event.data.msg.rollData.spellSave);
}
}
return;
Expand Down
10 changes: 8 additions & 2 deletions abovevtt.css
Original file line number Diff line number Diff line change
Expand Up @@ -3295,7 +3295,7 @@ div#selectedTokensBorder {
}
.above-vtt-container-roll-output{
position: absolute;
top: 9px;
top: 33%;
left: 0px;
width: 220px;
text-wrap: nowrap;
Expand Down Expand Up @@ -6875,7 +6875,13 @@ button span.onedrive-btn-status{
color:#4768ff !important;
}


[class*="glc-game-log"] div[class*="TotalContainer-Flex"] .custom-spell-save-text span{
color: #716f6f !important;
font-size: 10px;
font-weight: bold;
line-height: 10px;
text-wrap: nowrap;
}
.glc-game-log>div>div[class*="-Title"] {
margin-bottom: 7px;
}
Expand Down

0 comments on commit 68dffa9

Please sign in to comment.