mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Merge branch 'main' into bug/103-enrich-htmlfield-content-before-its-used-in-applications
This commit is contained in:
commit
d39d3d37b3
106 changed files with 1556 additions and 532 deletions
|
|
@ -1,35 +1,48 @@
|
|||
import { getWidthOfText } from './utils.mjs';
|
||||
|
||||
export default class RegisterHandlebarsHelpers {
|
||||
static registerHelpers() {
|
||||
Handlebars.registerHelper({
|
||||
times: this.times,
|
||||
add: this.add,
|
||||
subtract: this.subtract,
|
||||
includes: this.includes,
|
||||
times: this.times,
|
||||
damageFormula: this.damageFormula,
|
||||
damageSymbols: this.damageSymbols,
|
||||
tertiary: this.tertiary
|
||||
});
|
||||
}
|
||||
|
||||
static times(nr, block) {
|
||||
var accum = '';
|
||||
for (var i = 0; i < nr; ++i) accum += block.fn(i);
|
||||
return accum;
|
||||
}
|
||||
|
||||
static add(a, b) {
|
||||
const aNum = Number.parseInt(a);
|
||||
const bNum = Number.parseInt(b);
|
||||
return (Number.isNaN(aNum) ? 0 : aNum) + (Number.isNaN(bNum) ? 0 : bNum);
|
||||
}
|
||||
|
||||
static subtract(a, b) {
|
||||
const aNum = Number.parseInt(a);
|
||||
const bNum = Number.parseInt(b);
|
||||
return (Number.isNaN(aNum) ? 0 : aNum) - (Number.isNaN(bNum) ? 0 : bNum);
|
||||
}
|
||||
|
||||
static includes(list, item) {
|
||||
return list.includes(item);
|
||||
}
|
||||
|
||||
static times(nr, block) {
|
||||
var accum = '';
|
||||
for (var i = 0; i < nr; ++i) accum += block.fn(i);
|
||||
return accum;
|
||||
}
|
||||
|
||||
static damageFormula(attack, actor) {
|
||||
const traitTotal = actor.system.traits?.[attack.roll.trait]?.value;
|
||||
const instances = [
|
||||
attack.damage.parts.map(x => Roll.replaceFormulaData(x.value.getFormula(), actor)).join(' + '),
|
||||
traitTotal
|
||||
].filter(x => x);
|
||||
|
||||
return instances.join(traitTotal > 0 ? ' + ' : ' - ');
|
||||
}
|
||||
|
||||
static damageSymbols(damageParts) {
|
||||
const symbols = new Set();
|
||||
damageParts.forEach(part => symbols.add(...CONFIG.DH.GENERAL.damageTypes[part.type].icon));
|
||||
return new Handlebars.SafeString(Array.from(symbols).map(symbol => `<i class="fa-solid ${symbol}"></i>`));
|
||||
}
|
||||
|
||||
static tertiary(a, b) {
|
||||
return a ?? b;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,12 +126,10 @@ export const setDiceSoNiceForDualityRoll = (rollResult, advantageState) => {
|
|||
const diceSoNicePresets = getDiceSoNicePresets();
|
||||
rollResult.dice[0].options = { appearance: diceSoNicePresets.hope };
|
||||
rollResult.dice[1].options = { appearance: diceSoNicePresets.fear }; //diceSoNicePresets.fear;
|
||||
if (rollResult.dice[2]) {
|
||||
if (advantageState === true) {
|
||||
rollResult.dice[2].options = { appearance: diceSoNicePresets.advantage };
|
||||
} else if (advantageState === false) {
|
||||
rollResult.dice[2].options = { appearance: diceSoNicePresets.disadvantage };
|
||||
}
|
||||
if (rollResult.dice[2] && advantageState) {
|
||||
rollResult.dice[2].options = {
|
||||
appearance: advantageState === 1 ? diceSoNicePresets.advantage : diceSoNicePresets.disadvantage
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -238,16 +236,7 @@ Roll.replaceFormulaData = function (formula, data = {}, { missing, warn = false
|
|||
};
|
||||
|
||||
export const getDamageKey = damage => {
|
||||
switch (damage) {
|
||||
case 3:
|
||||
return 'severe';
|
||||
case 2:
|
||||
return 'major';
|
||||
case 1:
|
||||
return 'minor';
|
||||
case 0:
|
||||
return 'none';
|
||||
}
|
||||
return ['none', 'minor', 'major', 'severe'][damage];
|
||||
};
|
||||
|
||||
export const getDamageLabel = damage => {
|
||||
|
|
@ -255,16 +244,12 @@ export const getDamageLabel = damage => {
|
|||
};
|
||||
|
||||
export const damageKeyToNumber = key => {
|
||||
switch (key) {
|
||||
case 'severe':
|
||||
return 3;
|
||||
case 'major':
|
||||
return 2;
|
||||
case 'minor':
|
||||
return 1;
|
||||
case 'none':
|
||||
return 0;
|
||||
}
|
||||
return {
|
||||
'none': 0,
|
||||
'minor': 1,
|
||||
'major': 2,
|
||||
'severe': 3
|
||||
}[key];
|
||||
};
|
||||
|
||||
export default function constructHTMLButton({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue