Added DualityRoll direct rolls in chat

This commit is contained in:
WBHarry 2025-05-25 13:56:04 +02:00
parent eeede65443
commit 4501edcf4a
5 changed files with 165 additions and 1087 deletions

View file

@ -22,17 +22,6 @@ const getCompendiumOptions = async compendium => {
};
export const getWidthOfText = (txt, fontsize, allCaps, bold) => {
// if(getWidthOfText.e === undefined){
// getWidthOfText.e = document.createElement('span');
// getWidthOfText.e.style.display = "none";
// document.body.appendChild(getWidthOfText.e);
// }
// if(getWidthOfText.e.style.fontSize !== fontsize)
// getWidthOfText.e.style.fontSize = fontsize;
// if(getWidthOfText.e.style.fontFamily !== 'Signika, sans-serif')
// getWidthOfText.e.style.fontFamily = 'Signika, sans-serif';
// getWidthOfText.e.innerText = txt;
// return getWidthOfText.e.offsetWidth;
const text = allCaps ? txt.toUpperCase() : txt;
if (getWidthOfText.c === undefined) {
getWidthOfText.c = document.createElement('canvas');
@ -82,3 +71,32 @@ export const generateId = (title, length) => {
.join('');
return Number.isNumeric(length) ? id.slice(0, length).padEnd(length, '0') : id;
};
export const rollCommandToJSON = text => {
try {
return JSON.parse(`{${text.replaceAll(' ', ',').replace(/(\w+(?==))(=)/g, '"$1":')}}`);
} catch (_) {
return null;
}
};
export const getCommandTarget = () => {
let target = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0].actor : null;
if (!game.user.isGM) {
target = game.user.character;
if (!target) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.NoAssignedPlayerCharacter'));
return null;
}
}
if (!target) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.NoSelectedToken'));
return null;
}
if (target.type !== 'pc') {
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.OnlyUseableByPC'));
return null;
}
return target;
};