Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add dice rolls to details #1546

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/module/utils/TwodsixDiceRoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ export class TwodsixDiceRoll {
}
let flavorTable = `<table><tr><th>${game.i18n.localize("TWODSIX.Chat.Roll.Modifier")}</th><th>${game.i18n.localize("TWODSIX.Chat.Roll.Description")}</th><th class="centre">${game.i18n.localize("TWODSIX.Chat.Roll.DM")}</th></tr>`;

//Add roll data
if (this.roll?.dice[0]?.values) {
const diceDetails = getDiceSymbols(this.roll.dice[0].values); // this.roll.dice[0].values.join()
flavorTable += `<tr><td>${game.i18n.localize("TWODSIX.Chat.Roll.Dice")}</td><td style= "font-size: larger;">${diceDetails}</td><td class="centre">${this.roll.dice[0].total}</td></tr>`;
}

//Difficulty Text
flavorText += `<section><p><b>${rollingString}</b>: ${difficulty}`;
flavorTable += `<tr><td>${game.i18n.localize("TWODSIX.Chat.Roll.Difficulty")}</td><td>${difficulty}</td>`;
Expand Down Expand Up @@ -397,3 +403,16 @@ function getOperatorString(value: number):string {
return ` +`;
}
}

/**
* Returns a string of Font Awesome d6 icons for a roll
* @param {number[]} values an array of roll values
* @returns {string} html string of font awesome codes for the roll
*/
function getDiceSymbols (values:number[]): string {
let returnVal = ``;
for (const value of values) {
returnVal += `<i class="fa-solid fa-dice-` + [`one">`, `two">`, `three">`, `four">`, `five">`, `six">`][value - 1] + `</i> `;
}
return returnVal;
}
3 changes: 2 additions & 1 deletion static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@
"veryLong": "Very Long",
"distant": "Distant",
"none": "None"
}
},
"Dice": "Dice"
}
},
"Table": {
Expand Down
Loading