Skip to content

Commit

Permalink
PF1 and Starfinder support
Browse files Browse the repository at this point in the history
  • Loading branch information
mclemente committed Aug 22, 2021
1 parent beeda3d commit 22dacad
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 30 deletions.
208 changes: 207 additions & 1 deletion module/SystemProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@ export class SystemProvider {
this.id = id
}

get customCSS() {
return [];
}

get loadTemplates() {
return [];
}

get template() {
throw new Error("A SystemProvider must implement the template function");
return "/modules/party-overview/templates/generic.hbs"
}

get width() {
return 500;
}

getActorDetails(actor) {
const data = actor.data.data;
return {
id: actor.id,
name: actor.name,
hp: data.attributes?.hp || data.hp
}
}

getUpdate(actors) {
return [actors, {}]
}
Expand Down Expand Up @@ -144,6 +157,102 @@ export class dnd5eProvider extends SystemProvider {
}
}

export class pf1Provider extends SystemProvider {
get loadTemplates() {
return [
"modules/party-overview/templates/parts/PF2e-Lore.html",
"modules/party-overview/templates/parts/PF2e-Bulk.html"
];
}

get template() {
return "/modules/party-overview/templates/pf1.hbs"
}

getLore(data) {
let result = [];
for (let key in data) {
result.push(data[key].name);
}

return result;
}

getTotalGP(currency) {
return currency.cp / 100 + currency.sp / 10 + currency.gp + currency.pp * 10;
}

getActorDetails(actor) {
const data = actor.data.data;
return {
id: actor.id,
name: actor.name,
hp: {
value: data.attributes.hp.value,
max: data.attributes.hp.max
},
armor: data.armor.total ? data.armor.total : 10,
shieldAC: data.shield && data.shield.total ? `(+${data.shield.total})` : "",
perception: data.skills.per.mod,
stealth: data.skills.ste.mod,
speed: data.attributes.speed.land.total,

saves: {
fortitude: data.attributes.savingThrows.fort.total,
reflex: data.attributes.savingThrows.ref.total,
will: data.attributes.savingThrows.will.total,
},
languages: data.traits.languages ? data.traits.languages.value.map(code => game.i18n.localize(CONFIG.PF1.languages[code])) : [],
currency: data.currency,

lore: this.getLore(actor.data.data.skills.lor.subSkills),
totalGP: this.getTotalGP(data.currency).toFixed(2)
}
}

getUpdate(actors) {
let languages = actors
.reduce((languages, actor) => [...new Set(languages.concat(actor.languages))], [])
.filter(language => language !== undefined)
.sort();
let totalCurrency = actors.reduce(
(currency, actor) => {
for (let prop in actor.currency) {
currency[prop] += actor.currency[prop];
}
return currency;
},
{
cp: 0,
sp: 0,
gp: 0,
pp: 0,
}
);
let totalPartyGP = actors.reduce((totalGP, actor) => totalGP + parseFloat(actor.totalGP), 0).toFixed(2);
let lores = actors
.reduce((lore, actor) => [...new Set(lore.concat(actor.lore))], [])
.filter(lore => lore !== undefined)
.sort();
actors = actors.map(actor => {
return {
...actor,
languages: languages.map(language => actor.languages && actor.languages.includes(language)),
lore: lores.map(lore => actor.lore && actor.lore.includes(lore)),
}
})
return [
actors,
{
languages: languages,
totalCurrency: totalCurrency,
totalPartyGP: totalPartyGP,
lore: lores
}
]
}
}

export class pf2eProvider extends SystemProvider {
get loadTemplates() {
return [
Expand Down Expand Up @@ -254,6 +363,99 @@ export class pf2eProvider extends SystemProvider {
}
}

export class sfrpgProvider extends SystemProvider {
get loadTemplates() {
return [
"modules/party-overview/templates/parts/PF2e-Lore.html",
"modules/party-overview/templates/parts/PF2e-Bulk.html"
];
}

get template() {
return "/modules/party-overview/templates/sfrpg.hbs"
}

getLore(data) {
let result = [];
for (let key in data) {
if (key.startsWith("pro") && Number(key.slice(key.length-1))) {
result.push(data[key].subname);
}
}
return result;
}

getActorDetails(actor) {
const data = actor.data.data;
return {
id: actor.id,
name: actor.name,
hp: {
value: data.attributes.hp.value,
max: data.attributes.hp.max
},
armor: data.attributes.eac.value ? data.attributes.eac.value : 10,
perception: data.skills.per.mod,
stealth: data.skills.ste.mod,
speed: data.attributes.speed.land.value,

saves: {
fortitude: data.attributes.fort.value,
reflex: data.attributes.reflex.value,
will: data.attributes.will.value,
},
languages: data.traits.languages ? data.traits.languages.value.map(code => game.i18n.localize(CONFIG.SFRPG.languages[code])) : [],
currency: data.currency,

lore: this.getLore(actor.data.data.skills)
}
}

getUpdate(actors) {
let languages = actors
.reduce((languages, actor) => [...new Set(languages.concat(actor.languages))], [])
.filter(language => language !== undefined)
.sort();
let totalCurrency = actors.reduce(
(currency, actor) => {
for (let prop in actor.currency) {
currency[prop] += actor.currency[prop];
}
return currency;
},
{
cp: 0,
sp: 0,
gp: 0,
pp: 0,
}
);
let totalPartyCredits = actors.reduce((total, actor) => total + parseFloat(actor.currency.credit), 0);
let totalPartyUPB = actors.reduce((total, actor) => total + parseFloat(actor.currency.upb), 0);
let lores = actors
.reduce((lore, actor) => [...new Set(lore.concat(actor.lore))], [])
.filter(lore => lore !== undefined)
.sort();
actors = actors.map(actor => {
return {
...actor,
languages: languages.map(language => actor.languages && actor.languages.includes(language)),
lore: lores.map(lore => actor.lore && actor.lore.includes(lore)),
}
})
return [
actors,
{
languages: languages,
totalCurrency: totalCurrency,
totalPartyCredits: totalPartyCredits,
totalPartyUPB: totalPartyUPB,
lore: lores
}
]
}
}

export class swadeProvider extends SystemProvider {
get template() {
return "/modules/party-overview/templates/swade.hbs"
Expand All @@ -276,6 +478,10 @@ export class swadeProvider extends SystemProvider {
}

export class wfrp4eProvider extends SystemProvider {
get customCSS() {
return ["wfrp4e"];
}

get template() {
return "/modules/party-overview/templates/wfrp4e.hbs"
}
Expand Down
8 changes: 7 additions & 1 deletion module/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SystemProvider, dnd5eProvider, pf2eProvider, swadeProvider, wfrp4eProvider
import {SystemProvider, dnd5eProvider, pf1Provider, pf2eProvider, sfrpgProvider, swadeProvider, wfrp4eProvider
} from "./SystemProvider.js"

export const availableSystemProviders = {}
Expand Down Expand Up @@ -47,9 +47,15 @@ export function initApi() {
case "dnd5e":
systemProviders.push(new dnd5eProvider("native.dnd5e"));
break;
case "pf1":
systemProviders.push(new pf1Provider("native.pf1"));
break;
case "pf2e":
systemProviders.push(new pf2eProvider("native.pf2e"));
break;
case "sfrpg":
systemProviders.push(new sfrpgProvider("native.swade"));
break;
case "swade":
systemProviders.push(new swadeProvider("native.swade"));
break;
Expand Down
2 changes: 1 addition & 1 deletion module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PartyOverviewApp extends Application {
resizable: true,
title: "Party Overview",
template: currentSystemProvider.template,
classes: ["party-overview", game.system.id],
classes: ["party-overview", ...currentSystemProvider.customCSS],
tabs: [
{
navSelector: ".tabs",
Expand Down
2 changes: 1 addition & 1 deletion party-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Hooks.on("renderActorDirectory", (app, html, data) => {
if (!game.user.isGM && !game.settings.get("party-overview", "EnablePlayerAccess"))
return;
let div = $(
`<div id="party-overview" class="action-buttons flexrow ${game.system.id}"></div>`
`<div id="party-overview" class="action-buttons flexrow"></div>`
);
$(html).find("header.directory-header").prepend(div);

Expand Down
5 changes: 0 additions & 5 deletions style/party-overview.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,3 @@ div.party-overview.wfrp4e .table-row .button button {
div.party-overview.wfrp4e .table-row:nth-child(2n) {
background-color: rgba(228, 228, 228, 0.34);
}

.dnd5e button.party-overview {
background: rgba(255, 255, 240, 0.8);
border: 1px solid #b5b3a4;
}
28 changes: 28 additions & 0 deletions templates/generic.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div>
<nav class="tabs" data-group="party">
<li class="item" data-tab="general">{{localize "party-overview.GENERAL"}}</li>
</nav>
<section class="content">
<div class="tab" data-tab="general" data-group="party">
<div class="table-row header">
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="num" title="Health"><i class="fas fa-heart"></i></div>
</div>

{{#each actors as | actor | }}
<div class="table-row">
<div class="button">
<button class="btn-toggle-visibility" data-actor="{{actor.id }}">
{{#if actor.isHidden }}<i class="value fas fa-eye-slash"></i>{{else}}<i
class="value fas fa-eye"></i>{{/if}}
</button>
</div>
<div class="text">{{ actor.shortestName }}</div>

<div class="num">{{ actor.hp.value }}/{{ actor.hp.max }}</div>
</div>
{{/each}}
</div>
</section>
</div>
4 changes: 2 additions & 2 deletions templates/parts/Languages.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
{{#each languages as | language | }}
<div class="text icon" style="flex: 1" title="{{language}}">{{language}}</div>
<div class="text" style="flex: 1" title="{{language}}">{{language}}</div>
{{/each}}
</div>

Expand All @@ -17,7 +17,7 @@
</div>
<div class="text">{{ actor.shortestName }}</div>
{{#each actor.languages as | language | }}
<div class="text icon" style="flex: 1">{{#if language}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
<div class="text" style="flex: 1">{{#if language}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
style="color: gray"></i>{{/if}}</div>
{{/each}}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/parts/PF2e-Lore.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">{{localize "party-overview.NAME"}}</div>
{{#each lore as | l | }}
<div class="text icon" style="flex: 1" title="{{l}}">{{l}}</div>
<div class="text" style="flex: 1" title="{{l}}">{{l}}</div>
{{/each}}
</div>

Expand All @@ -17,7 +17,7 @@
</div>
<div class="text">{{ actor.shortestName }}</div>
{{#each actor.lore as | lore | }}
<div class="text icon" style="flex: 1">{{#if lore}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
<div class="text" style="flex: 1">{{#if lore}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
style="color: gray"></i>{{/if}}</div>
{{/each}}
</div>
Expand Down
Loading

0 comments on commit 22dacad

Please sign in to comment.