diff --git a/lang/en.json b/lang/en.json index 8058879..e076da4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -86,11 +86,11 @@ "DG.Skills.AddTypedOrCustomSkill": "Add Typed/Custom Skill", "DG.Skills.AddSkill": "Add Skill", "DG.Skills.Apply": "Apply", - "DG.Skills.ApplySkillImprovements": "Apply Skill Improvements", - "DG.Skills.ApplySkillImprovementsChatFlavor": "Improved the following skills by", - "DG.Skills.ApplySkillImprovementsDialogLabel": "Improve skills by the following formula:", - "DG.Skills.ApplySkillImprovementsDialogEffectsFollowing": "Effects the following skills:", - "DG.Skills.ApplySkillImprovementsWarning": "No failed skills to improve.", + "DG.Skills.ApplySkillImprovements.Title": "Apply Skill Improvements", + "DG.Skills.ApplySkillImprovements.ChatFlavor": "Improved the following skills by", + "DG.Skills.ApplySkillImprovements.DialogLabel": "Improve skills by the following formula: {formula}", + "DG.Skills.ApplySkillImprovements.DialogEffectsFollowing": "Effects the following skills: {skillList}", + "DG.Skills.ApplySkillImprovements.Warning": "No failed skills to improve.", "DG.Skills.EditTypedOrCustomSkill": "Edit Typed or Custom Skill", "DG.Skills.EditSkill": "Edit Skill", "DG.Skills.SkillGroup": "Skill Group", diff --git a/module/config.js b/module/config.js index 9e06eae..e2b54eb 100644 --- a/module/config.js +++ b/module/config.js @@ -54,4 +54,8 @@ const DG = /** @type {const} */ ({ statistics: ["str", "con", "dex", "int", "pow", "cha"], }); +// Set base template path for single source of truth for hbs locations. +const BASE_TEMPLATE_PATH = /** @type {const} */ (`systems/${DG.ID}/templates`); + export default DG; +export { DG, BASE_TEMPLATE_PATH }; diff --git a/module/sheets/agent-sheet.js b/module/sheets/agent-sheet.js index 4d713b7..5708a38 100644 --- a/module/sheets/agent-sheet.js +++ b/module/sheets/agent-sheet.js @@ -1,5 +1,8 @@ +import { DG, BASE_TEMPLATE_PATH } from "../config.js"; import DGActorSheet from "./base-actor-sheet.js"; +const { renderTemplate } = foundry.applications.handlebars; + /** @extends {DGActorSheet} */ export default class DGAgentSheet extends DGActorSheet { /** @override */ @@ -84,7 +87,7 @@ export default class DGAgentSheet extends DGActorSheet { /* -------------------------------------------- */ - static _applySkillImprovements(event, target) { + static async _applySkillImprovements(event, target) { const failedSkills = Object.entries(this.actor.system.skills).filter( (skill) => skill[1].failure, ); @@ -92,11 +95,10 @@ export default class DGAgentSheet extends DGActorSheet { this.actor.system.typedSkills, ).filter((skill) => skill[1].failure); if (failedSkills.length === 0 && failedTypedSkills.length === 0) { - ui.notifications.warn("No Skills to Increase"); + ui.notifications.warn("DG.Skills.ApplySkillImprovements.Warning"); return; } - let htmlContent = ""; let failedSkillNames = ""; failedSkills.forEach(([skill], value) => { if (value === 0) { @@ -117,30 +119,20 @@ export default class DGAgentSheet extends DGActorSheet { } }); - const baseRollFormula = game.settings.get( - "deltagreen", - "skillImprovementFormula", + const baseRollFormula = game.settings.get(DG.ID, "skillImprovementFormula"); + + const content = await renderTemplate( + `${BASE_TEMPLATE_PATH}/dialog/apply-skill-improvements.html`, + { failedSkillNames, baseRollFormula }, ); - htmlContent += `
`; - htmlContent += ` `; - htmlContent += `
`; - htmlContent += ` ${game.i18n.localize( - "DG.Skills.ApplySkillImprovementsDialogEffectsFollowing", - )} ${failedSkillNames} `; - htmlContent += `
`; - new Dialog({ - content: htmlContent, - title: - game.i18n.translations.DG?.Skills?.ApplySkillImprovements ?? - "Apply Skill Improvements", + content, + title: game.i18n.localize("DG.Skills.ApplySkillImprovements.Title"), default: "add", buttons: { apply: { - label: game.i18n.translations.DG?.Skills?.Apply ?? "Apply", + label: game.i18n.localize("DG.Skills.Apply"), callback: (btn) => { this._applySkillImprovements( baseRollFormula, @@ -286,7 +278,7 @@ export default class DGAgentSheet extends DGActorSheet { }), content: html, flavor: `${game.i18n.localize( - "DG.Skills.ApplySkillImprovementsChatFlavor", + "DG.Skills.ApplySkillImprovements.ChatFlavor", )} +${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/sheets/base-sheet.js b/module/sheets/base-sheet.js index de42d33..ad48f9b 100644 --- a/module/sheets/base-sheet.js +++ b/module/sheets/base-sheet.js @@ -1,4 +1,4 @@ -import DG from "../config.js"; +import { DG, BASE_TEMPLATE_PATH } from "../config.js"; const HbsAppMixin = foundry.applications.api.HandlebarsApplicationMixin; @@ -11,8 +11,7 @@ const DGSheetMixin = (Base) => { form: { submitOnChange: true }, }); - /** @inheritdoc */ - static TEMPLATE_PATH = /** @type {const} */ (`systems/${DG.ID}/templates`); + static TEMPLATE_PATH = BASE_TEMPLATE_PATH; static get THEME() { return game.settings.get(DG.ID, "characterSheetStyle"); diff --git a/templates/actor/partials/custom-skills-partial.html b/templates/actor/partials/custom-skills-partial.html index 4d01753..fd0df26 100644 --- a/templates/actor/partials/custom-skills-partial.html +++ b/templates/actor/partials/custom-skills-partial.html @@ -14,7 +14,7 @@ {{#if_eq actor.type "agent" }} - {{localize 'DG.Skills.ApplySkillImprovements'}} + {{localize 'DG.Skills.ApplySkillImprovements.Title'}} {{/if_eq}} diff --git a/templates/dialog/apply-skill-improvements.html b/templates/dialog/apply-skill-improvements.html new file mode 100644 index 0000000..a430a4d --- /dev/null +++ b/templates/dialog/apply-skill-improvements.html @@ -0,0 +1,9 @@ +
+ +
+ + {{{localize "DG.Skills.ApplySkillImprovements.DialogEffectsFollowing" skillList=failedSkillNames}}} + +