Skip to content

Commit

Permalink
[FEATURE] Autofill skill attribute when using skill in action (#1117)
Browse files Browse the repository at this point in the history
Fixes #967
  • Loading branch information
taMiF committed Jan 14, 2024
1 parent c43b28a commit 8a43352
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/module/item/flows/UpdateActionFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,41 @@ export const UpdateActionFlow = {
* @param item The item as context of what's being changed.
*/
onUpdateAlterActionData(changeData: DeepPartial<Shadowrun.ShadowrunItemData>, item: SR5Item) {
UpdateActionFlow.onSkillUpdateAlterAttribute(changeData, item);
UpdateActionFlow.onSkillUpdateAlterAttribute2(changeData, item);
},

/**
* If a skill is selected, try to autofill the connect attribute of it.
*
* This differs for items on actors, as here we can access actual skill data.
* For item outside of actors we can only use default values.
* @param changeData The _update changes given by the event
* @param item The item as context of what's being changed.
*/
onSkillUpdateAlterAttribute(changeData: DeepPartial<Shadowrun.ShadowrunItemData>, item: SR5Item) {
// Only change to connected attribute when no attribute has already been chosen.
if (item.system.action?.attribute !== '') return;
const skillIdOrLabel = foundry.utils.getProperty(changeData, 'system.action.skill');
if (skillIdOrLabel === undefined || skillIdOrLabel === '') return;

// CASE - Sidebar item not owned by actor.
if (item.actor === null) {
const skill = game.model.Actor.character.skills.active[skillIdOrLabel];
if (skill === undefined) return;

changeData['system.action.attribute'] = skill.attribute;

// CASE - Owned Item on actor.
} else {
// Support both legacy and custom skills.
const skill = item.actor.getSkill(skillIdOrLabel) ?? item.actor.getSkillByLabel(skillIdOrLabel);
if (skill === undefined) return;

changeData['system.action.attribute'] = skill.attribute;
}
},

/**
* When a skill is changed, remove the second attribute, as it's not needed and might cause confusion
* at different places.
Expand Down

0 comments on commit 8a43352

Please sign in to comment.