Skip to content

Commit

Permalink
Merge pull request #2612 from Azmoria/QoL---add-damage-type-to-/dmg-r…
Browse files Browse the repository at this point in the history
…olls-after-`-`-eg-`/dmg-8d6-fireball-fire`;-Wrap-roll-type-below-roll-action-name-so-it's-never-pushed-out-of-view.-

QoL - add damage type to /dmg rolls after ` ` eg `/dmg 8d6 fireball fire`; In gamelog wrap roll type below roll action name so it's never pushed out of view.
  • Loading branch information
Azmoria authored Oct 28, 2024
2 parents 73f6687 + c3620b1 commit 407acab
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
7 changes: 5 additions & 2 deletions CharactersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ function getRollData(rollButton){
let expression = '';
let rollType = 'custom';
let rollTitle = 'AboveVTT';
let damageType = undefined;
if($(rollButton).find('.ddbc-damage__value').length>0){
expression = $(rollButton).find('.ddbc-damage__value').text().replace(/\s/g, '');
}
Expand All @@ -462,7 +463,9 @@ function getRollData(rollButton){
rollType = $(rollButton).attr('data-rolltype');;
}
if($(rollButton).hasClass('avtt-roll-formula-button')){
expression = DiceRoll.fromSlashCommand($(rollButton).attr('data-slash-command')).expression;
let slashCommand = DiceRoll.fromSlashCommand($(rollButton).attr('data-slash-command'))
expression = slashCommand.expression;
damageType = slashCommand.damageType;
let title = $(rollButton).attr('title').split(':');
if(title != undefined && title[0] != undefined){
rollTitle = title[0];
Expand Down Expand Up @@ -520,7 +523,7 @@ 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
damageType = followingText && window.ddbConfigJson.damageTypes.some(d => d.name.toLowerCase() == followingText.toLowerCase()) ? followingText : damageType;


return {
Expand Down
26 changes: 7 additions & 19 deletions ChatObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,15 @@ class ChatObserver {

#parseSlashCommand(text) {
let diceRoll = DiceRoll.fromSlashCommand(text);
if(window.AboveDice){

let didSend = window.diceRoller.roll(diceRoll); // TODO: update this with more details?
if (didSend === false) {
// it was too complex so try to send it through rpgDiceRoller
let expression = text.replace(diceRollCommandRegex, "").match(allowedExpressionCharactersRegex)?.[0];
let roll = new rpgDiceRoller.DiceRoll(expression);
let msgdata = {
player: window.PLAYER_NAME,
img: window.PLAYER_IMG,
text: `<div><span class='aboveDiceTotal'>${roll.total}</span><span class='aboveDiceOutput'>${roll.output}</span></div>`,
whisper: (gamelog_send_to_text() != "Everyone") ? window.PLAYER_NAME : ``,
language: $('#chat-language').val()
};
window.MB.inject_chat(msgdata);
}
else{
let didSend = window.diceRoller.roll(diceRoll); // TODO: update this with more details?
if (didSend === false) {
// it was too complex so try to send it through rpgDiceRoller
let expression = text.replace(diceRollCommandRegex, "").match(allowedExpressionCharactersRegex)?.[0];
didSend = send_rpg_dice_to_ddb(expression, window.pc.name, window.pc.image, rollType, undefined, action);
}
return didSend;
didSend = send_rpg_dice_to_ddb(expression, window.pc.name, window.pc.image, rollType, undefined, action);
}
return didSend;


}

Expand Down
19 changes: 14 additions & 5 deletions DiceRoller.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DiceRoll {
* @param entityId {string|undefined} the id of the entity associated with this roll. If {entityType} is "character" this should be the id for that character. If {entityType} is "monster" this should be the id for that monster. If {entityType} is "user" this should be the id for that user.
* @param sendToOverride {string|undefined} if undefined, the roll will go to whatever the gamelog is set to.
*/
constructor(expression, action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined, sendToOverride = undefined) {
constructor(expression, action = undefined, rollType = undefined, name = undefined, avatarUrl = undefined, entityType = undefined, entityId = undefined, sendToOverride = undefined, damageType = undefined) {

let parsedExpression = expression.replaceAll(/\s+/g, "").replaceAll(/^(d\d+)|([+-])(d\d+)/g, '$21$1$3');; // remove all spaces and 1's to d6 -> 1d6, d8 -> 1d8 etc.

Expand Down Expand Up @@ -173,6 +173,7 @@ class DiceRoll {
this.action = action;
this.rollType = rollType;
this.sendToOverride = sendToOverride;
this.damageType = damageType;
if (name) this.name = name;
if (avatarUrl) this.avatarUrl = avatarUrl;
if (entityType) this.entityType = entityType;
Expand Down Expand Up @@ -225,12 +226,14 @@ class DiceRoll {
let action = modifiedSlashCommand.replace(diceRollCommandRegex, "").replace(allowedExpressionCharactersRegex, "");
console.debug("DiceRoll.fromSlashCommand text: ", slashCommandText, ", slashCommand:", slashCommand, ", expression: ", expression, ", action: ", action);
let rollType = undefined;
let damageType = undefined;
if (slashCommand.startsWith("/r")) {
// /r and /roll allow users to set both the action and the rollType by separating them with `:` so try to parse that out
[action, rollType] = action.split(":") || [undefined, undefined];
} else if (slashCommand.startsWith("/hit")) {
rollType = "to hit";
} else if (slashCommand.startsWith("/dmg")) {
[action, damageType] = action.split(":") || [action, undefined];
rollType = "damage";
} else if (slashCommand.startsWith("/skill")) {
rollType = "check";
Expand All @@ -239,7 +242,7 @@ class DiceRoll {
} else if (slashCommand.startsWith("/heal")) {
rollType = "heal";
}
return new DiceRoll(expression, action, rollType, name, avatarUrl, entityType, entityId, sendToOverride);
return new DiceRoll(expression, action, rollType, name, avatarUrl, entityType, entityId, sendToOverride, damageType);
}
}

Expand Down Expand Up @@ -378,15 +381,18 @@ class DiceRoller {
if(damageType == undefined && this.#pendingDamageType != undefined){
damageType = this.#pendingDamageType;
}
else if(damageType == undefined && diceRoll.damageType != undefined){
damageType = diceRoll.damageType;
}
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.replace(' ', '-')}'>${damageType != undefined ? `${damageType} ` : ''}${rollType}</span>
</span>
<span class='aboveDiceOutput'>${rollTitle}</span>
:
<span class='abovevtt-roll-${rollType.replace(' ', '-')}'>${damageType != undefined ? `${damageType} ` : ''}${rollType}</span>
</div>
</div>
<svg width="1" height="32" class="tss-10y9gcy-Divider"><path fill="currentColor" d="M0 0h1v32H0z"></path></svg>
Expand Down Expand Up @@ -428,6 +434,9 @@ class DiceRoller {
damageType = this.#pendingDamageType;
this.#pendingDamageType = undefined;
}
else if(damageType == undefined && diceRoll.damageType != undefined){
damageType = diceRoll.damageType;
}
let rollData = {
roll: roll,
expression: diceRoll.expression,
Expand Down
2 changes: 1 addition & 1 deletion MessageBroker.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class MessageBroker {
li.height(oldheight);
li.animate({ opacity: 1, height: neweight }, animationDuration, () => { li.height("") });
let output = $(`${current.data.injected_data.whisper == '' ? '' : `<div class='above-vtt-roll-whisper'>To: ${(current.data.injected_data.whisper == window.PLAYER_NAME && current.data.player_name == window.PLAYER_NAME) ? `Self` : current.data.injected_data.whisper}</div>`}<div class='above-vtt-container-roll-output'>${li.find('.abovevtt-roll-container').attr('title')}</div>`);
li.find('.abovevtt-roll-container').append(output);
li.find('.abovevtt-roll-container [class*="Result"]').append(output);
let img = li.find(".magnify");
for(let i=0; i<img.length; i++){
if($(img[i]).is('img')){
Expand Down
25 changes: 23 additions & 2 deletions abovevtt.css
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,7 @@ div#selectedTokensBorder {
}
}
.above-vtt-container-roll-output{
position: absolute;
position: relative;
top: 33%;
left: 0px;
width: 220px;
Expand Down Expand Up @@ -3541,7 +3541,7 @@ div#selectedTokensBorder {
flex: 1 1 auto;
min-width: 0px;
overflow: hidden;
top: -13px;
top: 0px;
position: relative;
}
.abovevtt-roll-container [class*='Total-Other-Collapsed-Pending-Flex'] {
Expand Down Expand Up @@ -5960,6 +5960,26 @@ div#selectedTokensBorderRotationGrabberConnector,
fill: #000;
right: 0;
}
.glc-game-log [class*='-Result']>[class*='-Line-Title-'] {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start;
}

.glc-game-log [class*='-Result']>[class*='-Line-Title-']{
visibility: hidden;
font-size:0px;
}
.glc-game-log [class*='-Result']>[class*='-Line-Title-'] span{
font-size:12px;
max-width:100%;
overflow:hidden;
visibility: visible;
text-overflow: ellipsis;
white-space:nowrap;
}
.journal-button{
filter: none;
border: 1px solid #c5c5c5;
Expand Down Expand Up @@ -6025,6 +6045,7 @@ div#selectedTokensBorderRotationGrabberConnector,
text-transform: uppercase;
font-weight: 700;
color: rgb(92, 112, 128);
line-height: 1;
}

[class*='Line-Title'] .aboveDiceOutput .skill-tooltip{
Expand Down

0 comments on commit 407acab

Please sign in to comment.