Skip to content

Commit

Permalink
Proficiencies for DND5e and PF2e
Browse files Browse the repository at this point in the history
Proficiencies
  • Loading branch information
mclemente committed Jan 17, 2022
1 parent 676ce60 commit 114a632
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 36 deletions.
101 changes: 100 additions & 1 deletion module/SystemProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ export class dnd35eProvider extends SystemProvider {
}

export class dnd5eProvider extends SystemProvider {
constructor(id) {
super(id);
Handlebars.registerHelper("partyOverviewGetSkillList", function (skill, actors, opt) {
return actors.map((actor) => {
return {
...actor.skills[skill],
};
});
});
}

get loadTemplates() {
return ["modules/party-overview/templates/parts/DND5E-Proficiencies.html"];
}
Expand All @@ -182,6 +193,7 @@ export class dnd5eProvider extends SystemProvider {
background: { id: "background", visible: true, localization: "DND5E.Background" },
saves: { id: "saves", visible: true, localization: "DND5E.ClassSaves" },
proficiencies: { id: "proficiencies", visible: true, localization: "party-overview.PROFICIENCIES" },
tools: { id: "tools", visible: true, localization: "DND5E.ItemTypeToolPl" },
};
}

Expand Down Expand Up @@ -219,7 +231,11 @@ export class dnd5eProvider extends SystemProvider {
};
const skills = {};
for (let skill in data.skills) {
skills[skill] = icons[data.skills[skill].proficient];
skills[skill] = {
icon: icons[data.skills[skill].proficient],
proficient: CONFIG.DND5E.proficiencyLevels[data.skills[skill].proficient],
value: data.skills[skill].total,
};
}
return skills;
}
Expand All @@ -237,6 +253,44 @@ export class dnd5eProvider extends SystemProvider {

return str;
}
getTools(data) {
function getBaseItem(identifier) {
let pack = CONFIG.DND5E.sourcePacks.ITEMS;
let [scope, collection, id] = identifier.split(".");
if (scope && collection) pack = `${scope}.${collection}`;
if (!id) id = identifier;

const packObject = game.packs.get(pack);

return packObject?.index.get(id);
}
const profs = CONFIG.DND5E.toolProficiencies;
const type = "tool";
const itemTypes = CONFIG.DND5E[`${type}Ids`];

let values = [];
if (data.value) {
values = data.value instanceof Array ? data.value : [data.value];
}

data.selected = {};
for (const key of values) {
if (profs[key]) {
data.selected[key] = profs[key];
} else if (itemTypes && itemTypes[key]) {
const item = getBaseItem(itemTypes[key]);
if (item) data.selected[key] = item.name;
} else if (type === "tool" && CONFIG.DND5E.vehicleTypes[key]) {
data.selected[key] = CONFIG.DND5E.vehicleTypes[key];
}
}

// Add custom entries
if (data.custom) {
data.custom.split(";").forEach((c, i) => (data.selected[`custom${i + 1}`] = c.trim()));
}
return data.selected;
}

getTotalGP(data) {
const currency = foundry.utils.deepClone(data.currency);
Expand Down Expand Up @@ -291,7 +345,9 @@ export class dnd5eProvider extends SystemProvider {
skills: this.getSkills(data),
inspiration: data.attributes.inspiration,
languages: data.traits.languages ? data.traits.languages.value.map((code) => CONFIG.DND5E.languages[code]) : [],
tools: this.getTools(data.traits.toolProf) || {},
alignment: data.details.alignment,

currency: data.currency,
totalGP: this.getTotalGP(data).toFixed(2),
};
Expand Down Expand Up @@ -447,9 +503,22 @@ export class pf1Provider extends SystemProvider {
}

export class pf2eProvider extends SystemProvider {
constructor(id) {
super(id);
Handlebars.registerHelper("partyOverviewGetSkillList", function (skill, actors, opt) {
return actors.map((actor) => {
return {
rankLetter: actor.skills[skill].rankName[0],
...actor.skills[skill],
};
});
});
}

get loadTemplates() {
return [
"modules/party-overview/templates/parts/PF2e-Lore.html",
"modules/party-overview/templates/parts/PF2e-Proficiencies.html",
// "modules/party-overview/templates/parts/PF2e-Bulk.html"
];
}
Expand All @@ -460,6 +529,7 @@ export class pf2eProvider extends SystemProvider {
// bulk: { id: "bulk", visible: true, localization: "PF2E.BulkShortLabel" },
languages: { id: "languages", visible: true, localization: "PF2E.Languages" },
lore: { id: "lore", visible: true, localization: "PF2E.Lore" },
proficiencies: { id: "skills", visible: true, localization: "PF2E.SkillsLabel" },
};
}

Expand Down Expand Up @@ -501,6 +571,33 @@ export class pf2eProvider extends SystemProvider {
return lore;
}

getSkills(data) {
const proficiency = {
0: game.i18n.localize("PF2E.ProficiencyLevel0"),
1: game.i18n.localize("PF2E.ProficiencyLevel1"),
2: game.i18n.localize("PF2E.ProficiencyLevel2"),
3: game.i18n.localize("PF2E.ProficiencyLevel3"),
4: game.i18n.localize("PF2E.ProficiencyLevel4"),
};
const proficiencyColors = {
0: "initial",
1: "#171f69",
2: "#3c005e",
3: "#640",
4: "#5e0000",
};
const skills = {};
for (let skill in data.skills) {
skills[skill] = {
color: proficiencyColors[data.skills[skill].rank],
rank: data.skills[skill].rank,
rankName: proficiency[data.skills[skill].rank],
value: data.skills[skill].value,
};
}
return skills;
}

getTotalGP(currency) {
return currency.cp / 100 + currency.sp / 10 + currency.gp + currency.pp * 10;
}
Expand All @@ -521,6 +618,7 @@ export class pf2eProvider extends SystemProvider {
shieldAC: data.attributes.shield?.ac || 0,
perception: data.attributes.perception?.value || 0,
// speed: actor.type === "vehicle" ? data.details.speed : data.attributes.speed?.value || 0,
skills: this.getSkills(data),

saves: {
fortitude: data.saves?.fortitude?.value || 0,
Expand Down Expand Up @@ -578,6 +676,7 @@ export class pf2eProvider extends SystemProvider {
totalPartyGP: totalPartyGP,
sumItemsGP: (Number(itemsValue) + Number(totalPartyGP)).toFixed(2),
lore: lores,
skills: CONFIG.PF2E.skills,
},
];
}
Expand Down
26 changes: 20 additions & 6 deletions style/party-overview.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ div.party-overview-window .table-row .button {
flex-shrink: 1;
}

div.party-overview-window .table-row.header .button:not(:first-child) {
flex-basis: 27px;
}

button.btn-filter,
button.btn-toggle-visibility {
line-height: initial;
Expand Down Expand Up @@ -145,20 +149,30 @@ button.party-overview-button:not(.wfrp4e) {
flex-basis: 100%;
}

.party-overview-window.dnd5e .proficiencies.tab .header .num {
.party-overview-window.dnd5e .proficiencies.tab .header .num,
.party-overview-window.pf2e .proficiencies.tab .header .num {
flex: 1;
}

.party-overview-ellipsis {
overflow: hidden;
white-space: nowrap;
.party-overview-no-ellipsis,
div.party-overview-window .table-row .text.party-overview-no-ellipsis,
div.party-overview-window .table-row .text.icon.party-overview-no-ellipsis,
div.party-overview-window .table-row .num.party-overview-no-ellipsis {
overflow: visible;
white-space: normal;
text-overflow: clip;
}

.party-overview-ellipsis {
.party-overview-ellipsis,
div.party-overview-window .table-row .text.party-overview-ellipsis,
div.party-overview-window .table-row .text.icon.party-overview-ellipsis,
div.party-overview-window .table-row .num.party-overview-ellipsis {
overflow: hidden;
white-space: nowrap;
text-overflow: clip;
border-right: 1px solid black;
}

.party-overview-ellipsis:last-child {
border-right: none;
}
}
17 changes: 17 additions & 0 deletions templates/dnd5e.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,22 @@
</div>
{{/each}}
</div>

<!-- Saving Throws -->
<div class="tab" data-tab="tools" data-group="party">
<div class="table-row header">
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
<div class="text">{{localize "DND5E.TraitToolProf"}}</div>
</div>

{{#each actors as | actor | }}
<div class="table-row">
{{> "modules/party-overview/templates/parts/ToggleVisibilityButton.html" actor=actor}}
<div class="text">{{ actor.shortestName }}</div>
<div class="text party-overview-no-ellipsis">{{#each actor.tools as | tool | }}{{tool}}{{#unless @last}}, {{/unless}}{{/each}}</div>
</div>
{{/each}}
</div>
</section>
</div>
26 changes: 15 additions & 11 deletions templates/parts/DND5E-Proficiencies.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<!-- prettier-ignore -->
<div class="tab proficiencies" data-tab="proficiencies" data-group="party">
<div class="table-row header">
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
{{#each skills as | s | }}
<div class="num party-overview-ellipsis" title="{{s}}">{{s}}</div>
{{#each actors as | actor | }}
{{> "modules/party-overview/templates/parts/ToggleVisibilityButton.html" actor=actor}}
<div class="num party-overview-ellipsis" title="{{ actor.shortestName }}">
{{ actor.shortestName }}
</div>
{{/each}}
</div>

{{#each actors as | actor | }}
<div class="table-row">
{{> "modules/party-overview/templates/parts/ToggleVisibilityButton.html"}}
<div class="text">{{ actor.shortestName }}</div>
{{#each actor.skills as | skill| }}
<div class="num" style="flex: 1">
<i class="{{skill}}"></i>
{{#each skills as | value key | }}
<div class="table-row">
<div></div>
<div class="text">{{localize value}}</div>
{{#each (partyOverviewGetSkillList key ../actors)}}
<div class="num" style="flex: 1;" title="{{this.proficient}}">
{{numberFormat this.value decimals=0 sign=true}} <i class="{{this.icon}}"></i>
</div>
{{/each}}
</div>
{{/each}}
</div>
{{/each}}
</div>
25 changes: 25 additions & 0 deletions templates/parts/PF2e-Proficiencies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- prettier-ignore -->
<div class="tab proficiencies" data-tab="skills" data-group="party">
<div class="table-row header">
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
{{#each actors as | actor | }}
{{> "modules/party-overview/templates/parts/ToggleVisibilityButton.html" actor=actor}}
<div class="num party-overview-ellipsis" title="{{ actor.shortestName }}">
{{ actor.shortestName }}
</div>
{{/each}}
</div>

{{#each skills as | value key | }}
<div class="table-row">
<div></div>
<div class="text">{{localize value}}</div>
{{#each (partyOverviewGetSkillList key ../actors)}}
<div class="num" style="flex: 1; {{#if this.rank}}color: white; background-color: {{this.color}}"title="{{this.rankName}}{{/if}}">
{{numberFormat this.value decimals=0 sign=true}}
</div>
{{/each}}
</div>
{{/each}}
</div>
38 changes: 20 additions & 18 deletions templates/pf2e.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
<div class="table-row header">
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
<div class="text icon" title="{{localize "PF2E.HeroPointsLabel"}}">Hero</div>
<div class="text icon" title="{{localize "PF2E.HitPointsHeader"}}"><i class="fas fa-heart"></i></div>
<div class="text icon" title="{{localize "PF2E.ArmorClassLabel"}}"><i class="fas fa-shield-alt"></i></div>
<div class="text icon" title="{{localize "PF2E.Focus.label"}}"><i class="fas fa-hand-sparkles"></i></div>
<div class="text icon" title="{{localize "PF2E.PerceptionHeader"}}"><i class="far fa-eye"></i></div>
{{!-- <div class="text icon" title="{{localize "PF2E.Speed"}}"><i class="fas fa-tachometer-alt"></i></div> --}}
<div class="text icon" title="{{localize "PF2E.SavesFortitude"}}"><i class="fas fa-hard-hat"></i></div>
<div class="text icon" title="{{localize "PF2E.SavesReflex"}}"><i class="fas fa-running"></i></div>
<div class="text icon" title="{{localize "PF2E.SavesWill"}}"><i class="fas fa-brain"></i></div>
<div class="num" title="{{localize "PF2E.HeroPointsLabel"}}">Hero</div>
<div class="num" title="{{localize "PF2E.HitPointsHeader"}}"><i class="fas fa-heart"></i></div>
<div class="num" title="{{localize "PF2E.ArmorClassLabel"}}"><i class="fas fa-shield-alt"></i></div>
<div class="num" title="{{localize "PF2E.Focus.label"}}"><i class="fas fa-hand-sparkles"></i></div>
<div class="num" title="{{localize "PF2E.PerceptionHeader"}}"><i class="far fa-eye"></i></div>
{{!-- <div class="num" title="{{localize "PF2E.Speed"}}"><i class="fas fa-tachometer-alt"></i></div> --}}
<div class="num" title="{{localize "PF2E.SavesFortitude"}}"><i class="fas fa-hard-hat"></i></div>
<div class="num" title="{{localize "PF2E.SavesReflex"}}"><i class="fas fa-running"></i></div>
<div class="num" title="{{localize "PF2E.SavesWill"}}"><i class="fas fa-brain"></i></div>
</div>

{{#each actors as | actor | }}
<div class="table-row">
{{> "modules/party-overview/templates/parts/ToggleVisibilityButton.html" actor=actor}}
<div class="text">{{ actor.shortestName }}</div>
<div class="text icon">{{ actor.heroPoints.value }}/{{ actor.heroPoints.max }}</div>
<div class="text icon">{{ actor.hp.value }}/{{ actor.hp.max }}</div>
<div class="text icon">{{ actor.armor }} {{#if actor.shieldAC}}({{numberFormat actor.shieldAC decimals=0 sign=true}}){{/if}}</div>
<div class="text icon">{{ actor.focus.value }}/{{ actor.focus.max }}</div>
<div class="text icon">{{ actor.perception }}</div>
{{!-- <div class="text icon">{{ actor.speed }}</div> --}}
<div class="text icon">{{ actor.saves.fortitude }}</div>
<div class="text icon">{{ actor.saves.reflex }}</div>
<div class="text icon">{{ actor.saves.will }}</div>
<div class="num">{{ actor.heroPoints.value }}/{{ actor.heroPoints.max }}</div>
<div class="num">{{ actor.hp.value }}/{{ actor.hp.max }}</div>
<div class="num">{{ actor.armor }} {{#if actor.shieldAC}}({{numberFormat actor.shieldAC decimals=0 sign=true}}){{/if}}</div>
<div class="num">{{ actor.focus.value }}/{{ actor.focus.max }}</div>
<div class="num">{{ actor.perception }}</div>
{{!-- <div class="num">{{ actor.speed }}</div> --}}
<div class="num">{{ actor.saves.fortitude }}</div>
<div class="num">{{ actor.saves.reflex }}</div>
<div class="num">{{ actor.saves.will }}</div>
</div>
{{/each}}
</div>
Expand Down Expand Up @@ -82,5 +82,7 @@

<!-- Bulk -->
{{!-- {{> "modules/party-overview/templates/parts/PF2e-Bulk.html"}} --}}

{{> "modules/party-overview/templates/parts/PF2e-Proficiencies.html"}}
</section>
</div>

0 comments on commit 114a632

Please sign in to comment.