diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 8fc46ec..c5790bc 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -64,12 +64,32 @@ export default class DeltaGreenActorSheet extends ActorSheet { this._prepareCharacterItems(data); data.showHyperGeometrySection = this.shouldShowHyperGeometrySection( - this.actor, + this.actor ); // Make it easy for the sheet handlebars to understand how to sort the skills. data.sortSkillsSetting = game.settings.get("deltagreen", "sortSkills"); + let sortedSkills = []; + for (const [key, skill] of Object.entries(this.actor.system.skills)) { + skill.key = key; + skill.sortLabel = game.i18n.localize(`DG.Skills.${key}`); + + if (skill.sortLabel === "" || skill.sortLabel === `DG.Skills.${key}`) { + skill.sortLabel = skill.label; + } + + 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; + // Prepare a simplified version of the special training for display on sheet. if (this.actor.type !== "vehicle") { const specialTraining = this.actor.system.specialTraining.map( @@ -104,7 +124,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { break; } return simplifiedTraining; - }, + } ); data.specialTraining = specialTraining; } @@ -113,20 +133,20 @@ export default class DeltaGreenActorSheet extends ActorSheet { case "agent": data.enrichedDescription = await TextEditor.enrichHTML( this.object.system.physicalDescription, - { async: true }, + { async: true } ); break; case "vehicle": data.enrichedDescription = await TextEditor.enrichHTML( this.object.system.description, - { async: true }, + { async: true } ); break; case "npc": case "unnatural": data.enrichedDescription = await TextEditor.enrichHTML( this.object.system.notes, - { async: true }, + { async: true } ); break; default: @@ -147,7 +167,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { if ( game.settings.get( "deltagreen", - "alwaysShowHypergeometrySectionForPlayers", + "alwaysShowHypergeometrySectionForPlayers" ) ) { return true; @@ -307,7 +327,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { label2 = game.i18n.translations.DG.Luck; } catch { console.error( - "Missing translation key for either DG.RollLuck or DG.Luck key.", + "Missing translation key for either DG.RollLuck or DG.Luck key." ); } @@ -372,7 +392,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { }, ], }, - owner, + owner ).create(); } @@ -414,7 +434,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { html.find(".toggle-untrained").click(() => this.actor.update({ "system.showUntrainedSkills": !this.actor.system.showUntrainedSkills, - }), + }) ); // Macro for toggling an item's equipped state @@ -464,7 +484,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { this._showNewEditTypeSkillDialog( targetskill, existingLabel, - existingGroup, + existingGroup ); }); @@ -488,11 +508,11 @@ export default class DeltaGreenActorSheet extends ActorSheet { event.preventDefault(); const targetID = event.currentTarget.getAttribute("data-id"); const specialTrainingArray = foundry.utils.duplicate( - this.actor.system.specialTraining, + this.actor.system.specialTraining ); // Get the index of the training to be deleted const index = specialTrainingArray.findIndex( - (training) => training.id === targetID, + (training) => training.id === targetID ); specialTrainingArray.splice(index, 1); @@ -503,10 +523,10 @@ export default class DeltaGreenActorSheet extends ActorSheet { event.preventDefault(); const failedSkills = Object.entries(this.actor.system.skills).filter( - (skill) => skill[1].failure, + (skill) => skill[1].failure ); const failedTypedSkills = Object.entries( - this.actor.system.typedSkills, + this.actor.system.typedSkills ).filter((skill) => skill[1].failure); if (failedSkills.length === 0 && failedTypedSkills.length === 0) { ui.notifications.warn("No Skills to Increase"); @@ -525,27 +545,27 @@ export default class DeltaGreenActorSheet extends ActorSheet { failedTypedSkills.forEach(([skillName, skillData], value) => { if (value === 0 && failedSkillNames === "") { failedSkillNames += `${game.i18n.localize( - `DG.TypeSkills.${skillData.group.split(" ").join("")}`, + `DG.TypeSkills.${skillData.group.split(" ").join("")}` )} (${skillData.label})`; } else { failedSkillNames += `, ${game.i18n.localize( - `DG.TypeSkills.${skillData.group.split(" ").join("")}`, + `DG.TypeSkills.${skillData.group.split(" ").join("")}` )} (${skillData.label})`; } }); const baseRollFormula = game.settings.get( "deltagreen", - "skillImprovementFormula", + "skillImprovementFormula" ); htmlContent += `
`; htmlContent += ` `; htmlContent += `
`; htmlContent += ` ${game.i18n.localize( - "DG.Skills.ApplySkillImprovementsDialogEffectsFollowing", + "DG.Skills.ApplySkillImprovementsDialogEffectsFollowing" )} ${failedSkillNames} `; htmlContent += `
`; @@ -562,7 +582,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { this._applySkillImprovements( baseRollFormula, failedSkills, - failedTypedSkills, + failedTypedSkills ); }, }, @@ -801,7 +821,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { this._updateTypedSkill( targetSkill, newTypeSkillLabel, - newTypeSkillGroup, + newTypeSkillGroup ); }, }, @@ -917,17 +937,17 @@ export default class DeltaGreenActorSheet extends ActorSheet { async _showSpecialTrainingDialog(action, targetID) { const specialTraining = this.actor.system.specialTraining.find( - (training) => training.id === targetID, + (training) => training.id === targetID ); // Define the option groups for our drop-down menu. const optionGroups = { stats: game.i18n.localize( - "DG.SpecialTraining.Dialog.DropDown.Statistics", + "DG.SpecialTraining.Dialog.DropDown.Statistics" ), skills: game.i18n.localize("DG.SpecialTraining.Dialog.DropDown.Skills"), typedSkills: game.i18n.localize( - "DG.SpecialTraining.Dialog.DropDown.CustomSkills", + "DG.SpecialTraining.Dialog.DropDown.CustomSkills" ), }; @@ -938,7 +958,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { group: optionGroups.stats, label: game.i18n.localize(`DG.Attributes.${key}`), targetNumber: stat.value * 5, - }), + }) ); // Prepare simplified skill list @@ -948,7 +968,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { group: optionGroups.skills, label: skill.label, targetNumber: skill.proficiency, - }), + }) ); // Prepare simplified typed/custom skill list @@ -958,7 +978,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { group: optionGroups.typedSkills, label: `${skill.group} (${skill.label})`, targetNumber: skill.proficiency, - }), + }) ); // Prepare the Select element @@ -978,11 +998,11 @@ export default class DeltaGreenActorSheet extends ActorSheet { statList, skillList, typedSkillList, - }, + } ); const buttonLabel = game.i18n.localize( - `DG.SpecialTraining.Dialog.${action}SpecialTraining`, + `DG.SpecialTraining.Dialog.${action}SpecialTraining` ); // Prepare and render dialog with above template. @@ -1003,13 +1023,13 @@ export default class DeltaGreenActorSheet extends ActorSheet { if (action === "Create") this._createSpecialTraining( specialTrainingLabel, - specialTrainingAttribute, + specialTrainingAttribute ); if (action === "Edit") this._editSpecialTraining( specialTrainingLabel, specialTrainingAttribute, - targetID, + targetID ); }, }, @@ -1019,7 +1039,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { _createSpecialTraining(label, attribute) { const specialTrainingArray = foundry.utils.duplicate( - this.actor.system.specialTraining, + this.actor.system.specialTraining ); specialTrainingArray.push({ name: label, @@ -1031,10 +1051,10 @@ export default class DeltaGreenActorSheet extends ActorSheet { _editSpecialTraining(label, attribute, id) { const specialTrainingArray = foundry.utils.duplicate( - this.actor.system.specialTraining, + this.actor.system.specialTraining ); const specialTraining = specialTrainingArray.find( - (training) => training.id === id, + (training) => training.id === id ); specialTraining.name = label; specialTraining.attribute = attribute; @@ -1060,7 +1080,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { game.i18n.translations.DOCUMENT?.New || "DG.FallbackText.newItem", { type: game.i18n.localize(`TYPES.Item.${type}`), - }, + } ); // Prepare the item object. @@ -1220,7 +1240,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { async _applySkillImprovements( baseRollFormula, failedSkills, - failedTypedSkills, + failedTypedSkills ) { const actorData = this.actor.system; const resultList = []; @@ -1248,8 +1268,8 @@ export default class DeltaGreenActorSheet extends ActorSheet { // Put the results into a list. roll.terms[0].results.forEach((result) => resultList.push( - baseRollFormula === "1d4-1" ? result.result - 1 : result.result, - ), + baseRollFormula === "1d4-1" ? result.result - 1 : result.result + ) ); } @@ -1267,11 +1287,11 @@ export default class DeltaGreenActorSheet extends ActorSheet { // The if statement tells us whether to add a comma before the term or not. if (value === 0) { improvedSkillList += `${game.i18n.localize( - `DG.Skills.${skill}`, + `DG.Skills.${skill}` )}: +${resultList[value] ?? 1}%`; } else { improvedSkillList += `, ${game.i18n.localize( - `DG.Skills.${skill}`, + `DG.Skills.${skill}` )}: +${resultList[value] ?? 1}%`; } }); @@ -1287,13 +1307,13 @@ export default class DeltaGreenActorSheet extends ActorSheet { // The if statement tells us whether to add a comma before the term or not. if (value === 0 && improvedSkillList === "") { improvedSkillList += `${game.i18n.localize( - `DG.TypeSkills.${skillData.group.split(" ").join("")}`, + `DG.TypeSkills.${skillData.group.split(" ").join("")}` )} (${skillData.label}): +${ resultList[value + failedSkills.length] ?? 1 }%`; } else { improvedSkillList += `, ${game.i18n.localize( - `DG.TypeSkills.${skillData.group.split(" ").join("")}`, + `DG.TypeSkills.${skillData.group.split(" ").join("")}` )} (${skillData.label}): +${ resultList[value + failedSkills.length] ?? 1 }%`; @@ -1318,7 +1338,7 @@ export default class DeltaGreenActorSheet extends ActorSheet { }), content: html, flavor: `${game.i18n.localize( - "DG.Skills.ApplySkillImprovementsChatFlavor", + "DG.Skills.ApplySkillImprovementsChatFlavor" )} +${baseRollFormula}%:`, type: baseRollFormula === "1" ? 0 : 5, // 0 = CHAT_MESSAGE_TYPES.OTHER, 5 = CHAT_MESSAGE_TYPES.ROLL rolls: baseRollFormula === "1" ? [] : [roll], // If adding flat +1, there is no roll. diff --git a/module/actor/actor.js b/module/actor/actor.js index 0de87f0..32e02b3 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -74,7 +74,7 @@ export default class DeltaGreenActor extends Actor { try { system.health.max = Math.ceil( - (system.statistics.con.value + system.statistics.str.value) / 2, + (system.statistics.con.value + system.statistics.str.value) / 2 ); } catch (ex) { system.health.max = 10; @@ -220,7 +220,7 @@ export default class DeltaGreenActor extends Actor { system.wp.max = system.statistics.pow.value; system.health.max = Math.ceil( - (system.statistics.con.value + system.statistics.str.value) / 2, + (system.statistics.con.value + system.statistics.str.value) / 2 ); // initialize sanity, don't set these afterwards, as they need to be manually edited @@ -312,7 +312,7 @@ export default class DeltaGreenActor extends Actor { { actorLink: true, // this will make the 'Link Actor Data' option for a token is checked by default. So changes to the token sheet will reflect to the actor sheet. }, - { overwrite: false }, + { overwrite: false } ); } return super.create(data, options); @@ -336,7 +336,7 @@ export default class DeltaGreenActor extends Actor { } const handToHandPack = await game.packs.get( - "deltagreen.hand-to-hand-weapons", + "deltagreen.hand-to-hand-weapons" ); const itemIndex = await handToHandPack.getIndex(); const toAdd = []; // createEmbeddedDocument expects an array @@ -404,7 +404,7 @@ export default class DeltaGreenActor extends Actor { description, protection, isEquipped, - expense = "NA", + expense = "NA" ) { const armorData = { type: "armor", @@ -434,7 +434,7 @@ export default class DeltaGreenActor extends Actor { killRadius = "N/A", ammo = "", expense = "NA", - equipped = true, + equipped = true ) { const weaponData = { type: "weapon", diff --git a/module/settings.js b/module/settings.js index 79a1b17..b530741 100644 --- a/module/settings.js +++ b/module/settings.js @@ -24,7 +24,7 @@ export default function registerSystemSettings() { hint: "Checked sorts by column. Unchecked sorts by row.", scope: "client", config: true, - requiresReload: false, + requiresReload: true, type: Boolean, default: false, }); @@ -70,7 +70,7 @@ export default function registerSystemSettings() { requiresReload: true, type: Boolean, default: false, - }, + } ); game.settings.register("deltagreen", "showImpossibleLandscapesContent", { diff --git a/templates/actor/actor-sheet.html b/templates/actor/actor-sheet.html index 41ea7ab..3dba891 100644 --- a/templates/actor/actor-sheet.html +++ b/templates/actor/actor-sheet.html @@ -97,37 +97,37 @@
- {{#each actor.system.skills as |skill key|}} + {{#each actor.system.sortedSkills as |skill key|}}
- - {{#if_eq key 'ritual' }} + {{#if_eq skill.key 'ritual' }} {{#if (keepSanityPrivate)}} - - + {{/if}} {{#unless (keepSanityPrivate)}} - - + {{/unless}} {{/if_eq}} - {{#if_not_eq key 'ritual' }} - - + {{/if_not_eq}} diff --git a/templates/actor/npc-sheet.html b/templates/actor/npc-sheet.html index e9a84f8..1a3b34a 100644 --- a/templates/actor/npc-sheet.html +++ b/templates/actor/npc-sheet.html @@ -98,18 +98,18 @@
- {{#each actor.system.skills as |skill key|}} + {{#each actor.system.sortedSkills as |skill key|}} {{#if (hideSkillBasedOnProficiencyAndUserChoice ../actor.system.showUntrainedSkills skill.proficiency)}}
- - +
{{/if}} diff --git a/templates/actor/unnatural-sheet.html b/templates/actor/unnatural-sheet.html index f5d54cf..d5a8ce7 100644 --- a/templates/actor/unnatural-sheet.html +++ b/templates/actor/unnatural-sheet.html @@ -92,18 +92,18 @@
- {{#each actor.system.skills as |skill key|}} + {{#each actor.system.sortedSkills as |skill key|}} {{#if (hideSkillBasedOnProficiencyAndUserChoice ../actor.system.showUntrainedSkills skill.proficiency)}}
- - +
{{/if}}