Skip to content

Commit

Permalink
fix: Cascade works better, still only on animals skill.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdy committed Aug 22, 2020
1 parent d803927 commit c7ff0f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 123 deletions.
6 changes: 3 additions & 3 deletions src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export default function registerHandlebarsHelpers():void {
});

Handlebars.registerHelper('checkTrainedSkill', function (skill) {
return skill.trained
return skill.value >= 0
});

Handlebars.registerHelper('shouldShowSkill', function (skill, hideUntrainedSkills) {
return skill.trained || hideUntrainedSkills
return skill.value >= 0 || hideUntrainedSkills
});

Handlebars.registerHelper('getSkillValueWithJoat', getSkillValueWithJoat);

function getSkillValueWithJoat(skill, joat) {
if (skill.trained) return skill.value
if (skill.value >= 0) return skill.value
return skill.value + joat.value
}

Expand Down
21 changes: 9 additions & 12 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,35 +192,32 @@ export class TwodsixActorSheet extends ActorSheet {
if (this.parentSkillIsTrained(matchingSkill) && matchingSkill.value < maxSkillLevel) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1})
}
} else if (!matchingSkill.trained) {
} else if (matchingSkill.value < 0) {
this.actor.update({[`data.skills.${skillName}.value`]: 0})
this.actor.update({[`data.skills.${skillName}.trained`]: true})
if (matchingSkill.hasChildren) {
this.processChildren(data, skillName, 0, true);
this.processChildren(data, skillName, 0);
}
} else if (!matchingSkill.hasChildren && matchingSkill.value < maxSkillLevel) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1})
}
}
}

private processChildren(data:any, skillName:string, level:number, trained:boolean) {
private processChildren(data:any, skillName:string, level:number) {
for (const [key, value] of Object.entries(data.skills)) {
if (key.startsWith(skillName + "-")) {
this.actor.update({[`data.skills.${key}.value`]: level})
this.actor.update({[`data.skills.${key}.trained`]: trained})
console.log(`${key}: ${value["label"]}`);
}
}
}

private static isChildSkill(matchingSkill:any) {
return matchingSkill.childOf === "";
return matchingSkill.childOf != null && matchingSkill.childOf != "";
}

private parentSkillIsTrained(matchingSkill:any) {
const parent = this.actor.data.data.skills[matchingSkill.childOf];
return parent.trained && matchingSkill.childOf === parent.label;
return parent && parent.value >= 0;
}

/**
Expand All @@ -235,14 +232,14 @@ export class TwodsixActorSheet extends ActorSheet {
const actorData = this.actor.data;
const data = actorData.data;
const matchingSkill = data.skills[skillName];
const parent = matchingSkill.childOf
if (matchingSkill) {
if (matchingSkill.trained && data.skills[skillName].value === 0) {
if (matchingSkill.value === 0 && parent == null) {
this.actor.update({[`data.skills.${skillName}.value`]: -3})
this.actor.update({[`data.skills.${skillName}.trained`]: false})
if (matchingSkill.hasChildren) {
this.processChildren(data, skillName, -3, false);
this.processChildren(data, skillName, -3);
}
} else if (matchingSkill.trained) {
} else if (matchingSkill.value > 0) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value - 1})
}
}
Expand Down
Loading

0 comments on commit c7ff0f8

Please sign in to comment.