From e3cb1cd91f01d467a14a73f9b7d4e9938b58df1f Mon Sep 17 00:00:00 2001 From: TheLastScrub <67403321+TheLastScrub@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:04:10 -0800 Subject: [PATCH 1/6] [ENH] Sort Custom Skills & Special Trainings alphabetically / by column Fixes #129 --- module/actor/actor-sheet.js | 56 +++++++++++++++++++ .../actor/partials/custom-skills-partial.html | 55 +++++++++--------- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index c5790bc..d0bd5a6 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -129,6 +129,47 @@ export default class DeltaGreenActorSheet extends ActorSheet { data.specialTraining = specialTraining; } + // try to make a combined array of both typed skills and special trainings, so that it can be sorted neatly on the sheet + let sortedCustomSkills = []; + + for (const [key, skill] of Object.entries(this.actor.system.typedSkills)) { + skill.type = "typeSkill"; + skill.key = key; + skill.sortLabel = skill.group + "." + skill.label; + + skill.sortLabel = skill.sortLabel.toUpperCase(); + + if (skill.sortLabel === "" || skill.sortLabel === `DG.Skills.${key}`) { + skill.sortLabel = skill.label; + } + + sortedCustomSkills.push(skill); + } + + for (var i = 0; i < data.specialTraining.length; i++) { + let training = data.specialTraining[i]; + + training.type = "training"; + training.sortLabel = training.name.toUpperCase(); + + sortedCustomSkills.push(training); + } + + sortedCustomSkills.sort(function (a, b) { + return a.sortLabel.localeCompare(b.sortLabel, game.i18n.lang); + }); + + if (game.settings.get("deltagreen", "sortSkills")) { + let columnSortedSkills = this.reorderForColumnSorting( + sortedCustomSkills, + 2 + ); + + this.actor.system.sortedCustomSkills = columnSortedSkills; + } else { + this.actor.system.sortedCustomSkills = sortedCustomSkills; + } + switch (this.actor.type) { case "agent": data.enrichedDescription = await TextEditor.enrichHTML( @@ -155,6 +196,21 @@ export default class DeltaGreenActorSheet extends ActorSheet { return data; } + reorderForColumnSorting(arr, numCols) { + let numRows = Math.ceil(arr.length / numCols); + let reordered = new Array(arr.length); + + for (let i = 0; i < arr.length; i++) { + let row = i % numRows; + let col = Math.floor(i / numRows); + let newIndex = row * numCols + col; + + reordered[newIndex] = arr[i]; + } + + return reordered; + } + // some handlers may wish to avoid leading players to think they should be seeking out magic // so control whether an actor sheet shows the hypergeometry (rituals and tomes) section shouldShowHyperGeometrySection(actor) { diff --git a/templates/actor/partials/custom-skills-partial.html b/templates/actor/partials/custom-skills-partial.html index 37fb939..9d96829 100644 --- a/templates/actor/partials/custom-skills-partial.html +++ b/templates/actor/partials/custom-skills-partial.html @@ -7,39 +7,42 @@
- {{#each actor.system.typedSkills as |skill key|}} -
-
- - - {{#if_eq ../actorType "agent"}} - - {{/if_eq}} + {{#each actor.system.sortedCustomSkills as |skill|}} + {{#if_eq type "typeSkill"}} + {{log skill}} +
+
+ + + {{#if_eq ../actorType "agent"}} + + {{/if_eq}} +
+
+ + +
-
- - -
-
- {{/each}} + {{/if_eq}} - {{#each specialTraining as |training|}} + {{#if_eq type "training"}}
-
- {{/each}} + {{/if_eq}} + {{/each}}
From 996a1a377d3d24c4e856c92e62d74c8638234fca Mon Sep 17 00:00:00 2001 From: TheLastScrub <67403321+TheLastScrub@users.noreply.github.com> Date: Sat, 15 Feb 2025 23:07:22 -0800 Subject: [PATCH 2/6] npc, unnatural sorting by column working better --- css/deltagreen.css | 2 +- module/actor/actor-sheet.js | 20 +++++++++++--- templates/actor/actor-sheet.html | 4 +-- templates/actor/npc-sheet.html | 4 +-- .../actor/partials/custom-skills-partial.html | 26 ++++++++++++------- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/css/deltagreen.css b/css/deltagreen.css index 4e5c568..6350c23 100644 --- a/css/deltagreen.css +++ b/css/deltagreen.css @@ -457,7 +457,7 @@ explicitly define a number of rows, rather than columns. */ } .deltagreen .skill-and-training-controls { - flex: 0 0 80px; + flex: 0 0 35px; } .deltagreen .action-pill { diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index d0bd5a6..296dc21 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -79,16 +79,28 @@ export default class DeltaGreenActorSheet extends ActorSheet { skill.sortLabel = skill.label; } - sortedSkills.push(skill); + if ( + !( + (this.actor.type == "npc" || this.actor.type == "unnatural") && + this.actor.system.showUntrainedSkills == true && + skill.proficiency < 1 + ) + ) { + sortedSkills.push(skill); + } } - //console.log(sortedSkills); - sortedSkills.sort(function (a, b) { return a.sortLabel.localeCompare(b.sortLabel, game.i18n.lang); }); - this.actor.system.sortedSkills = sortedSkills; + if (game.settings.get("deltagreen", "sortSkills")) { + let columnSortedSkills = this.reorderForColumnSorting(sortedSkills, 3); + + this.actor.system.sortedSkills = columnSortedSkills; + } else { + this.actor.system.sortedSkills = sortedSkills; + } // Prepare a simplified version of the special training for display on sheet. if (this.actor.type !== "vehicle") { diff --git a/templates/actor/actor-sheet.html b/templates/actor/actor-sheet.html index 3dba891..8f6ffb7 100644 --- a/templates/actor/actor-sheet.html +++ b/templates/actor/actor-sheet.html @@ -96,9 +96,9 @@ {{localize "DG.Sheet.BlockHeaders.SkillsAndTraining"}}
-
+
{{#each actor.system.sortedSkills as |skill key|}} -
+
-
+
{{#each actor.system.sortedSkills as |skill key|}} {{#if (hideSkillBasedOnProficiencyAndUserChoice ../actor.system.showUntrainedSkills skill.proficiency)}} -
+