mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
Added DualityRoll direct rolls in chat
This commit is contained in:
parent
eeede65443
commit
4501edcf4a
5 changed files with 165 additions and 1087 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,38 +1,36 @@
|
|||
import { abilities } from '../config/actorConfig.mjs';
|
||||
import { rollCommandToJSON } from '../helpers/utils.mjs';
|
||||
|
||||
export async function dualityRollEnricher(match, _options) {
|
||||
try {
|
||||
const {
|
||||
hope = 'd12',
|
||||
fear = 'd12',
|
||||
attribute,
|
||||
advantage,
|
||||
disadvantage
|
||||
} = JSON.parse(`{${match[1].replace(' ', ',').replace(/(\w+(?==))(=)/g, '"$1":')}}`);
|
||||
const dualityElement = document.createElement('span');
|
||||
export function dualityRollEnricher(match, _options) {
|
||||
const roll = rollCommandToJSON(match[1]);
|
||||
if (!roll) return match[0];
|
||||
|
||||
const attributeLabel =
|
||||
attribute && abilities[attribute]
|
||||
? game.i18n.format('DAGGERHEART.General.Check', {
|
||||
check: game.i18n.localize(abilities[attribute].label)
|
||||
})
|
||||
: null;
|
||||
const label = attributeLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
|
||||
dualityElement.innerHTML = `
|
||||
<button class="duality-roll-button"
|
||||
data-hope="${hope}"
|
||||
data-fear="${fear}"
|
||||
${attribute ? `data-attribute="${attribute}"` : ''}
|
||||
${advantage ? 'data-advantage="true"' : ''}
|
||||
${disadvantage ? 'data-disadvantage="true"' : ''}
|
||||
>
|
||||
<i class="fa-solid fa-circle-half-stroke"></i>
|
||||
${label}
|
||||
</button>
|
||||
`;
|
||||
|
||||
return dualityElement;
|
||||
} catch (_) {
|
||||
return match[0];
|
||||
}
|
||||
return getDualityMessage(roll);
|
||||
}
|
||||
|
||||
export function getDualityMessage(roll) {
|
||||
const attributeLabel =
|
||||
roll.attribute && abilities[roll.attribute]
|
||||
? game.i18n.format('DAGGERHEART.General.Check', {
|
||||
check: game.i18n.localize(abilities[roll.attribute].label)
|
||||
})
|
||||
: null;
|
||||
const label = attributeLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
|
||||
|
||||
const dualityElement = document.createElement('span');
|
||||
dualityElement.innerHTML = `
|
||||
<button class="duality-roll-button"
|
||||
data-label="${label}"
|
||||
data-hope="${roll.hope ?? 'd12'}"
|
||||
data-fear="${roll.fear ?? 'd12'}"
|
||||
${roll.attribute && abilities[roll.attribute] ? `data-attribute="${roll.attribute}"` : ''}
|
||||
${roll.advantage ? 'data-advantage="true"' : ''}
|
||||
${roll.disadvantage ? 'data-disadvantage="true"' : ''}
|
||||
>
|
||||
<i class="fa-solid fa-circle-half-stroke"></i>
|
||||
${label}
|
||||
</button>
|
||||
`;
|
||||
|
||||
return dualityElement;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue