diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 0a733f8..9c16a69 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -20,6 +20,7 @@ export default class DeltaGreenActorSheet extends DGSheetMixin(ActorSheetV2) { roll: DeltaGreenActorSheet._onRoll, resetBreakingPoint: DeltaGreenActorSheet._resetBreakingPoint, typedSkillAction: DeltaGreenActorSheet._onTypedSkillAction, + specialTrainingAction: DeltaGreenActorSheet._onSpecialTrainingAction, }, }); @@ -601,6 +602,30 @@ export default class DeltaGreenActorSheet extends DGSheetMixin(ActorSheetV2) { } } + static _onSpecialTrainingAction(event, target) { + const { actionType, id } = target.dataset; + switch (actionType) { + case "delete": + { + const specialTrainingArray = foundry.utils.duplicate( + this.actor.system.specialTraining, + ); + + // Get the index of the training to be deleted + const index = specialTrainingArray.findIndex( + (training) => training.id === id, + ); + + specialTrainingArray.splice(index, 1); + this.actor.update({ "system.specialTraining": specialTrainingArray }); + } + break; + default: + this._showSpecialTrainingDialog(actionType, id); + break; + } + } + /** @override */ activateListeners(html) { super.activateListeners(html); @@ -632,29 +657,6 @@ export default class DeltaGreenActorSheet extends DGSheetMixin(ActorSheetV2) { }); } - html.find(".special-training-action").click((event) => { - event.preventDefault(); - const action = event.currentTarget.getAttribute("data-action"); - const targetID = event.currentTarget.getAttribute("data-id"); - this._showSpecialTrainingDialog(action, targetID); - }); - - // Handle deletion of Special Training - html.find(".special-training-delete").click((event) => { - event.preventDefault(); - const targetID = event.currentTarget.getAttribute("data-id"); - const specialTrainingArray = foundry.utils.duplicate( - this.actor.system.specialTraining, - ); - // Get the index of the training to be deleted - const index = specialTrainingArray.findIndex( - (training) => training.id === targetID, - ); - - specialTrainingArray.splice(index, 1); - this.actor.update({ "system.specialTraining": specialTrainingArray }); - }); - html.find(".apply-skill-improvements").click((event) => { event.preventDefault(); @@ -1175,12 +1177,12 @@ export default class DeltaGreenActorSheet extends DGSheetMixin(ActorSheetV2) { const specialTrainingAttribute = btn .find("[name='special-training-skill']") .val(); - if (action === "Create") + if (action === "create") this._createSpecialTraining( specialTrainingLabel, specialTrainingAttribute, ); - if (action === "Edit") + if (action === "edit") this._editSpecialTraining( specialTrainingLabel, specialTrainingAttribute, diff --git a/templates/actor/partials/custom-skills-partial.html b/templates/actor/partials/custom-skills-partial.html index 15d0177..43285a1 100644 --- a/templates/actor/partials/custom-skills-partial.html +++ b/templates/actor/partials/custom-skills-partial.html @@ -6,8 +6,9 @@ {{localize 'DG.Skills.AddTypedOrCustomSkill'}} - + {{localize 'DG.SpecialTraining.Dialog.CreateSpecialTraining'}} @@ -97,11 +98,14 @@