
Hello all, I was trying to change the HTML file of the character sheet I'm currently overhauling, to replace the string "name" with "character_name", thus allowing for quickchange between name of the character sheet & name in the sheet proper. The code that I was proposing was working fine in my test sheet: Previously : <label data-i18n-title="enter name" title="enter name">
<input data-i18n-placeholder="name" name="attr_name" placeholder="name" title="@{name}" type="text" value=""/> Proposed : <label data-i18n-title="enter character name" title="enter character name">
<input data-i18n-placeholder="name" name="attr_character_name" placeholder="name" title="@{character_name}" type="text" value=""/> Alas, since the sheet is already live, the pull request was blocked, as it would impact ongoing games. I was advised to use sheetworker scripts to enable the change instead. That's cool, no worries, and I understand the logic behind it, however I'm not that savvy with scripts apart from basic stuff and I was wondering if there's a simple way of doing it. I do have some sheetworkers already included in the HTML file : <script type="text/worker">const attributes = {
damage: ['strength', 'size'],
healing: ['strength', 'constitution'],
movement: ['strength', 'dexterity'],
hp: ['size', 'constitution'],
unconcious: ['total_hit_points'],
knights: ['old_knights', 'middle_aged_knights', 'young_knights'],
annualglory: ['annual_glory_rewards_traits', 'annual_glory_rewards_chivalry', 'annual_glory_rewards_holdings', 'annual_glory_rewards_passions', 'annual_glory_rewards_religion']
}
attributes.movement.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
attributeSumDivide(attributes.movement, 'movement_rate');
});
})
attributes.damage.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
attributeSumDivide(attributes.damage, 'damage');
});
})
attributes.healing.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
attributeSumDivide(attributes.healing, 'healing_rate');
});
})
attributes.hp.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
sumOfCalculator(attributes.hp, 'total_hit_points');
});
})
attributes.unconcious.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
unconciousCalculator(attributes.unconcious, 'unconcious');
});
})
attributes.knights.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
sumOfCalculator(attributes.knights, 'total_family_knights');
});
})
attributes.knights.forEach(attr => {
on(`change:${attr}`, (eventinfo) => {
sumOfCalculator(attributes.annualglory, 'annual_glory_rewards_total');
});
})
//When performing calculations in King Arthur Pendragon / Paladin, round
//0.5 and higher fractions upward and lesser fractions downward.
//For example, a character with a Damage value of 4.43 would
//have an effective value of 4, while a character with a Damage val-
//ue of 4.5 would have a 5.
const roundFraction = sum => sum >= 0.5 ? Math.ceil(sum) : Math.floor(sum)
const divideBy = (sum, num) => sum/num;
const totalAttributes = values => {
let sum = 0
Object.values(values).forEach(num => sum += parseInt(num) || 0)
return sum
}
const attributeSumDivide = (attributes, set) => {
getAttrs(attributes, (values) => {
const divide = set == 'damage' ? 6 : 10;
let sum = totalAttributes(values);
sum = divideBy(sum, divide) ;
setAttrs({
[`${set}`]: roundFraction(sum)
});
});
};
const sumOfCalculator = (attributes, set) => {
getAttrs(attributes, (values) => {
setAttrs({
[`${set}`]: totalAttributes(values)
});
});
};
const unconciousCalculator = (attributes, set) => {
getAttrs(attributes, (values) => {
let sum = totalAttributes(values);
sum = divideBy(sum, 4) ;
setAttrs({
[`${set}`]: roundFraction(sum)
});
});
};</script> Do I need to add a const attribute & then a formula in order to enable the change? Many thanks in advance to all kind souls who would be happy to help me :)