REFACTOR: remove unnecessary handlebars

This commit is contained in:
Joaquin Pereyra 2025-07-05 11:27:52 -03:00
parent 0add5f369e
commit 2398a17dda
5 changed files with 5 additions and 96 deletions

View file

@ -7,49 +7,11 @@ export default class RegisterHandlebarsHelpers {
join: this.join,
add: this.add,
subtract: this.subtract,
objectSelector: this.objectSelector,
includes: this.includes,
debug: this.debug,
signedNumber: this.signedNumber,
length: this.length,
switch: this.switch,
case: this.case,
eq: this.eq,
ne: this.ne,
lt: this.lt,
gt: this.gt,
lte: this.lte,
gte: this.gte,
and: this.and,
or: this.or
});
}
static eq(v1, v2) {
return v1 === v2;
}
static ne(v1, v2) {
return v1 !== v2;
}
static lt(v1, v2) {
return v1 < v2;
}
static gt(v1, v2) {
return v1 > v2;
}
static lte(v1, v2) {
return v1 <= v2;
}
static gte(v1, v2) {
return v1 >= v2;
}
static and() {
return Array.prototype.every.call(arguments, Boolean);
}
static or() {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
}
static times(nr, block) {
var accum = '';
for (var i = 0; i < nr; ++i) accum += block.fn(i);
@ -72,59 +34,11 @@ export default class RegisterHandlebarsHelpers {
return (Number.isNaN(aNum) ? 0 : aNum) - (Number.isNaN(bNum) ? 0 : bNum);
}
static objectSelector(options) {
let { title, values, titleFontSize, ids, style } = options.hash;
const titleLength = getWidthOfText(title, titleFontSize, true, true);
const margins = 12;
const buttons = options.fn();
const nrButtons = Math.max($(buttons).length - 1, 1);
const iconWidth = 26;
const texts = values
.reduce((acc, x, index) => {
if (x) {
acc.push(
`<span class="object-select-item" data-action="viewObject" data-value="${ids[index]}">${x}</span>`
);
}
return acc;
}, [])
.join(' ');
const html = `<div ${style ? 'style="' + style + '"' : ''}">
<div class="object-select-display iconbar">
<span class="object-select-title">${title}</span>
<div class="object-select-text" style="padding-left: ${titleLength + margins}px; padding-right: ${nrButtons * iconWidth}px;">
${texts}
</div>
${buttons}
</div>
</div>
`;
return new Handlebars.SafeString(html);
}
static includes(list, item) {
return list.includes(item);
}
static signedNumber(number) {
return number >= 0 ? `+${number}` : number;
}
static length(obj) {
return Object.keys(obj).length;
}
static switch(value, options) {
this.switch_value = value;
this.switch_break = false;
return options.fn(this);
}
static case(value, options) {
if (value == this.switch_value) {
@ -132,9 +46,4 @@ export default class RegisterHandlebarsHelpers {
return options.fn(this);
}
}
static debug(a) {
console.log(a);
return a;
}
}

View file

@ -74,7 +74,7 @@
{{#each experience.values as |experience id|}}
<div class="experience-container">
<input class="experience-description" type="text" name="{{concat "experiences." id ".description" }}" value="{{experience.description}}" placeholder="{{localize "DAGGERHEART.CharacterCreation.NewExperience"}}" />
<div class="experience-value">{{signedNumber this.value}}</div>
<div class="experience-value">{{numberFormat this.value sign=true}}</div>
</div>
{{/each}}
</div>

View file

@ -12,7 +12,7 @@
<div class="achievement-experience-card">
<div class="flexrow">
<input type="text" name="{{concat "levelup.levels." this.level ".achievements.experiences." this.key ".name"}}" value="{{this.name}}" placeholder="{{localize "DAGGERHEART.Application.LevelUp.summary.experiencePlaceholder"}}" />
<div class="flex0">{{signedNumber this.modifier}}</div>
<div class="flex0">{{numberFormat this.modifier sign=true}}</div>
</div>
<div class="achievement-experience-marker">
{{#if this.name}}<i class="fa-solid fa-check"></i>{{/if}}

View file

@ -48,7 +48,7 @@
<h5>{{localize "DAGGERHEART.Application.LevelUp.summary.newExperiences"}}</h5>
<div class="summary-selection-container">
{{#each this.achievements.experiences.values}}
<div class="summary-selection">{{this.name}} {{signedNumber this.modifier}}</div>
<div class="summary-selection">{{this.name}} {{numberFormat this.modifier sign=true}}</div>
{{/each}}
</div>
</div>
@ -125,7 +125,7 @@
<h5>{{localize "DAGGERHEART.Application.LevelUp.summary.experienceIncreases"}}</h5>
<div class="summary-selection-container">
{{#each this.advancements.experiences}}
<div class="summary-selection">{{this.name}} {{signedNumber this.modifier}}</div>
<div class="summary-selection">{{this.name}} {{numberFormat this.modifier sign=true}}</div>
{{/each}}
</div>
</div>

View file

@ -17,7 +17,7 @@
{{#each source.system.experiences as |experience key|}}
<div class="flexrow">
<input type="text" name="{{concat "system.experiences." key ".name"}}" value="{{experience.name}}" />
<div>{{signedNumber experience.value}}</div>
<div>{{numberFormat experience.value sign=true}}</div>
</div>
{{/each}}
</div>