diff --git a/module/Apps/ActorSheets/HeroSkillsCardV1.mjs b/module/Apps/ActorSheets/HeroSkillsCardV1.mjs index 608d921..b0e83fb 100644 --- a/module/Apps/ActorSheets/HeroSkillsCardV1.mjs +++ b/module/Apps/ActorSheets/HeroSkillsCardV1.mjs @@ -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; }; diff --git a/module/consts.mjs b/module/consts.mjs index a3242a2..b8ec178 100644 --- a/module/consts.mjs +++ b/module/consts.mjs @@ -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)); }; diff --git a/templates/Apps/HeroSkillsCardV1/content.hbs b/templates/Apps/HeroSkillsCardV1/content.hbs index 8a6a829..eee8d4a 100644 --- a/templates/Apps/HeroSkillsCardV1/content.hbs +++ b/templates/Apps/HeroSkillsCardV1/content.hbs @@ -1,7 +1,6 @@
{{ rc-i18n "RipCrypt.Apps.grit-skills" }} - {{ rc-i18n "RipCrypt.common.rank" }}
    {{#each skills.grit as | skill |}} @@ -24,7 +23,6 @@
    {{ rc-i18n "RipCrypt.Apps.gait-skills" }} - {{ rc-i18n "RipCrypt.common.rank" }}
      {{#each skills.gait as | skill |}} @@ -47,7 +45,6 @@
      {{ rc-i18n "RipCrypt.Apps.grip-skills" }} - {{ rc-i18n "RipCrypt.common.rank" }}
        {{#each skills.grip as | skill |}} @@ -70,7 +67,6 @@
        {{ rc-i18n "RipCrypt.Apps.glim-skills" }} - {{ rc-i18n "RipCrypt.common.rank" }}
          {{#each skills.glim as | skill |}}