From a6512e0fa18742c7814968a9268d82ba651c5c77 Mon Sep 17 00:00:00 2001 From: jalensailin Date: Tue, 5 Dec 2023 15:21:40 -0500 Subject: [PATCH] add Edit Special Training logic --- module/actor/actor-sheet.js | 32 ++++++++++++++++------ templates/actor/custom-skills-partial.html | 4 +-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index b66d973..a5ac4cf 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -306,8 +306,8 @@ export default class DeltaGreenActorSheet extends ActorSheet { html.find(".special-training-action").click((event) => { event.preventDefault(); - const action = event.target.getAttribute("data-action"); - const targetID = event.target.getAttribute("data-id"); + const action = event.currentTarget.getAttribute("data-action"); + const targetID = event.currentTarget.getAttribute("data-id"); this._showSpecialTrainingDialog(action, targetID); }); @@ -730,18 +730,24 @@ export default class DeltaGreenActorSheet extends ActorSheet { const specialTrainingSkill = btn .find("[name='special-training-skill']") .val(); - this._addSpecialTraining( - specialTrainingLabel, - specialTrainingSkill, - targetID, - ); + if (action === "Create") + this._createSpecialTraining( + specialTrainingLabel, + specialTrainingSkill, + ); + if (action === "Edit") + this._editSpecialTraining( + specialTrainingLabel, + specialTrainingSkill, + targetID, + ); }, }, }, }).render(true); } - _addSpecialTraining(label, skill) { + _createSpecialTraining(label, skill) { const specialTrainingArray = duplicate(this.actor.system.specialTraining); specialTrainingArray.push({ name: label, @@ -751,6 +757,16 @@ export default class DeltaGreenActorSheet extends ActorSheet { this.actor.update({ "system.specialTraining": specialTrainingArray }); } + _editSpecialTraining(label, skill, id) { + const specialTrainingArray = duplicate(this.actor.system.specialTraining); + const specialTraining = specialTrainingArray.find( + (training) => training.id === id, + ); + specialTraining.name = label; + specialTraining.skill = skill; + this.actor.update({ "system.specialTraining": specialTrainingArray }); + } + /** * Handle creating a new Owned Item for the actor using initial data defined in the HTML dataset * @param {Event} event The originating click event diff --git a/templates/actor/custom-skills-partial.html b/templates/actor/custom-skills-partial.html index 81cefa8..333795e 100644 --- a/templates/actor/custom-skills-partial.html +++ b/templates/actor/custom-skills-partial.html @@ -28,8 +28,8 @@ {{training.name}}
- - + +
{{/each}}