foundry-dsa41-game/src/module/handlebar-helpers/weight.mjs

40 lines
894 B
JavaScript

function weight(money) {
const baseValue = money * 1000 // to get to gramms (1/1000 Stone)
const stone = Math.floor(baseValue / 1000)
const remainder = baseValue - (stone * 1000)
const ounces = remainder / 25
let stoneRepresentation = ''
let ouncesRepresentation = ''
return {
stone: stoneRepresentation,
ounces: ouncesRepresentation,
}
}
function registerHelper(hbs) {
hbs?.registerHelper('weight', (data) => {
let template = `<span class="weight">`
const {stone, ounces} = weight(data)
if (stone > 0) {
template += `<span class="stone">${stone}</span>`
}
if (ounces > 0) {
template += `<span class="ounces">${ounces}</span>`
}
template += `</span>`
return new Handlebars.SafeString(template)
})
}
export {
weight,
registerHelper
}