WIP: improve _applySkillImprovements

This commit is contained in:
jalensailin
2025-07-24 14:55:08 -04:00
parent c57fea8c64
commit 84febb8473
6 changed files with 35 additions and 31 deletions
+5 -5
View File
@@ -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: <b>{formula}</b>",
"DG.Skills.ApplySkillImprovements.DialogEffectsFollowing": "Effects the following skills: <b>{skillList}</b>",
"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",
+4
View File
@@ -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 };
+14 -22
View File
@@ -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 += `<div>`;
htmlContent += ` <label>${game.i18n.localize(
"DG.Skills.ApplySkillImprovementsDialogLabel",
)} <b>+${baseRollFormula}%</b></label>`;
htmlContent += ` <hr>`;
htmlContent += ` <span> ${game.i18n.localize(
"DG.Skills.ApplySkillImprovementsDialogEffectsFollowing",
)} <b>${failedSkillNames}</b> </span>`;
htmlContent += `</div>`;
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",
)} <b>+${baseRollFormula}%</b>:`,
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.
+2 -3
View File
@@ -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");
@@ -14,7 +14,7 @@
</a>
{{#if_eq actor.type "agent" }}
<a class="item-control action-pill" data-action="applySkillImprovements">
{{localize 'DG.Skills.ApplySkillImprovements'}}
{{localize 'DG.Skills.ApplySkillImprovements.Title'}}
<i class="fas fa-dice"></i>
</a>
{{/if_eq}}
@@ -0,0 +1,9 @@
<div>
<label>
{{{localize "DG.Skills.ApplySkillImprovements.DialogLabel" formula=baseRollFormula}}}
</label>
<hr>
<span>
{{{localize "DG.Skills.ApplySkillImprovements.DialogEffectsFollowing" skillList=failedSkillNames}}}
</span>
</div>