Improve sort order and remove list header that's inaccurate now
This commit is contained in:
parent
1302d91469
commit
7d9993b158
3 changed files with 26 additions and 7 deletions
|
|
@ -128,7 +128,7 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
|||
ctx.skills = {};
|
||||
const abilities = Object.values(gameTerms.Abilities);
|
||||
const heroRank = ctx.actor.system.level.rank;
|
||||
const embeddedSkills = ctx.actor.itemTypes.skill.sort(documentSorter);
|
||||
const embeddedSkills = ctx.actor.itemTypes.skill;
|
||||
|
||||
for (let ability of abilities) {
|
||||
const skills = [];
|
||||
|
|
@ -137,6 +137,7 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
|||
skills.push({
|
||||
uuid: skill.uuid,
|
||||
name: skill.name,
|
||||
sort: skill.sort,
|
||||
use: skill.system.advances[heroRank],
|
||||
});
|
||||
};
|
||||
|
|
@ -162,6 +163,9 @@ export class HeroSkillsCardV1 extends GenericAppMixin(HandlebarsApplicationMixin
|
|||
.concat(Array(limit - length).fill(null))
|
||||
.slice(0, limit);
|
||||
};
|
||||
|
||||
// Sort the skills
|
||||
ctx.skills[ability] = ctx.skills[ability].sort(documentSorter);
|
||||
}
|
||||
return ctx;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,11 +7,30 @@ export function filePath(path) {
|
|||
};
|
||||
|
||||
// MARK: documentSorter
|
||||
/**
|
||||
* @typedef {Object} Sortable
|
||||
* @property {integer} sort
|
||||
* @property {string} name
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compares two Sortable documents in order to determine ordering
|
||||
* @param {Sortable} a
|
||||
* @param {Sortable} b
|
||||
* @returns An integer dictating which order the two documents should be sorted in
|
||||
*/
|
||||
export function documentSorter(a, b) {
|
||||
if (!a && !b) {
|
||||
return 0;
|
||||
} else if (!a) {
|
||||
return 1;
|
||||
} else if (!b) {
|
||||
return -1;
|
||||
};
|
||||
|
||||
const sortDelta = b.sort - a.sort;
|
||||
if (sortDelta !== 0) {
|
||||
return sortDelta;
|
||||
};
|
||||
// TODO alphabetical sort
|
||||
return 0;
|
||||
return Math.sign(a.name.localeCompare(b.name));
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue