Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mclemente committed Jul 23, 2021
1 parent 40923a0 commit 487a2f1
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 123 deletions.
27 changes: 25 additions & 2 deletions module/SystemProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export class SystemProvider {
this.id = id
}

get hasCurrency() {
return false;
}

get template() {
throw new Error("A SystemProvider must implement the template function");
}
Expand All @@ -13,6 +17,16 @@ export class SystemProvider {
}

export class dnd5eProvider extends SystemProvider {
get hasCurrency() {
return {
cp: 0,
sp: 0,
ep: 0,
gp: 0,
pp: 0,
}
}

get template() {
return "/modules/party-overview/templates/dnd5e.hbs"
}
Expand Down Expand Up @@ -87,7 +101,7 @@ export class dnd5eProvider extends SystemProvider {
flaw: this.htmlDecode(data.details.flaw)
},
inspiration: data.attributes.inspiration,
languages: data.traits.languages.value.map(code => CONFIG.DND5E.languages[code]),
languages: data.traits.languages ? data.traits.languages.value.map(code => CONFIG.DND5E.languages[code]) : [],
alignment: data.details.alignment,
currency: data.currency,
totalGP: this.getTotalGP(data).toFixed(2)
Expand All @@ -96,6 +110,15 @@ export class dnd5eProvider extends SystemProvider {
}

export class pf2eProvider extends SystemProvider {
get hasCurrency() {
return {
cp: 0,
sp: 0,
gp: 0,
pp: 0,
}
}

get template() {
return "/modules/party-overview/templates/pf2e.hbs"
}
Expand Down Expand Up @@ -142,7 +165,7 @@ export class pf2eProvider extends SystemProvider {
reflex: data.saves.reflex.value,
will: data.saves.will.value,
},
languages: data.traits.languages.value.map(code => game.i18n.localize(CONFIG.PF2E.languages[code])),
languages: data.traits.languages ? data.traits.languages.value.map(code => game.i18n.localize(CONFIG.PF2E.languages[code])) : [],
currency: currency,
totalGP: this.getTotalGP(currency).toFixed(2)
}
Expand Down
14 changes: 4 additions & 10 deletions module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DISPLAY_MODE = {
SHOW_VISIBLE: "SHOW_VISIBLE",
};

const SIMPLE_SYTEMS = ['swade'];
const SIMPLE_SYTEMS = ['swade', 'wfrp4e'];

class PartyOverviewApp extends Application {
constructor(options) {
Expand All @@ -20,7 +20,7 @@ class PartyOverviewApp extends Application {


update() {
let actors = game.actors.entities
let actors = game.actors.contents
.filter(a => a.hasPlayerOwner)
.map(playerActor => playerActor.getActiveTokens())
.flat(1)
Expand Down Expand Up @@ -55,7 +55,7 @@ class PartyOverviewApp extends Application {

let languages;
let totalCurrency;
if (! SIMPLE_SYTEMS.includes(game.system.id)) {
if (currentSystemProvider.hasCurrency) {
// restructure the languages a bit so rendering gets easier
languages = actors
.reduce((languages, actor) => [...new Set(languages.concat(actor.languages))], [])
Expand All @@ -74,13 +74,7 @@ class PartyOverviewApp extends Application {
}
return currency;
},
{
cp: 0,
sp: 0,
ep: 0,
gp: 0,
pp: 0,
}
currentSystemProvider.hasCurrency
);
// summing up the total
}
Expand Down
5 changes: 5 additions & 0 deletions party-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Hooks.once("init", () => {
registerSettings();
initApi();
party = new PartyOverviewApp();

return loadTemplates([
"modules/party-overview/templates/parts/FilterButton.html",
"modules/party-overview/templates/parts/Languages.html"
]);
});

Hooks.on("ready", () => {
Expand Down
56 changes: 4 additions & 52 deletions templates/dnd5e.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
<section class="content">
<div class="tab" data-tab="general" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="num" title="Inspiration"><span>&#x1f340;</span></div>
<div class="num" title="Health"><i class="fas fa-heart"></i></div>
Expand Down Expand Up @@ -57,48 +51,12 @@
{{/each}}
</div>
<!-- Languages -->
<div class="tab" data-tab="languages" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
<i class="fas fa-filter {{#ifEquals mode 'SHOW_ALL'}}inactive{{/ifEquals}}"></i>
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
<div class="text">Name</div>
{{#each languages as | language | }}
<div class="text icon">{{language}}</div>
{{/each}}
</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>
{{#each actor.languages as | language | }}
<div class="text icon">{{#if language}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
style="color: gray"></i>{{/if}}</div>
{{/each}}
</div>
{{/each}}
</div>
{{> "modules/party-overview/templates/parts/Languages.html"}}

<!-- Currency -->
<div class="tab" data-tab="currencies" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="text icon">Platinum</div>
<div class="text icon">Gold</div>
Expand Down Expand Up @@ -142,13 +100,7 @@
<!-- Background -->
<div class="tab" data-tab="background" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="text icon">Traits</div>
<div class="text icon">Ideals</div>
Expand Down
7 changes: 7 additions & 0 deletions templates/parts/FilterButton.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
31 changes: 31 additions & 0 deletions templates/parts/languages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="tab" data-tab="languages" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
<div class="text" style="flex: 3">Name</div>
{{#each languages as | language | }}
<div class="text icon" style="flex: 1" title="{{language}}">{{language}}</div>
{{/each}}
</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" style="flex: 3">{{ 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"
style="color: gray"></i>{{/if}}</div>
{{/each}}
</div>
{{/each}}
</div>
48 changes: 3 additions & 45 deletions templates/pf2e.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
<section class="content">
<div class="tab" data-tab="general" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "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 class="num" title="Armor Class"><i class="fas fa-shield-alt"></i></div>
Expand Down Expand Up @@ -42,48 +36,12 @@
{{/each}}
</div>
<!-- Languages -->
<div class="tab" data-tab="languages" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
<div class="text">Name</div>
{{#each languages as | language | }}
<div class="text icon">{{language}}</div>
{{/each}}
</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>
{{#each actor.languages as | language | }}
<div class="text icon">{{#if language}}<i class="fas fa-check"></i>{{else}}<i class="value fas fa-times"
style="color: gray"></i>{{/if}}</div>
{{/each}}
</div>
{{/each}}
</div>
{{> "modules/party-overview/templates/parts/Languages.html"}}

<!-- Currency -->
<div class="tab" data-tab="currencies" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="text icon">Platinum</div>
<div class="text icon">Gold</div>
Expand Down
8 changes: 1 addition & 7 deletions templates/swade.hbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="num" title="Bennies"><i class="fas fa-bullseye"></i></div>
<div class="num" title="Wounds"><i class="fas fa-skull"></i></div>
Expand Down
8 changes: 1 addition & 7 deletions templates/wfrp4e.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
<section class="content">
<div class="tab" data-tab="general" data-group="party">
<div class="table-row header">
<div class="button">
<button class="btn-filter">
{{#ifEquals mode 'SHOW_ALL'}}<i class="fas fa-filter"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_VISIBLE' }}<i class="fas fa-eye"></i>{{/ifEquals}}
{{#ifEquals mode 'SHOW_HIDDEN' }}<i class="fas fa-eye-slash"></i>{{/ifEquals}}
</button>
</div>
{{> "modules/party-overview/templates/parts/FilterButton.html"}}
<div class="text">Name</div>
<div class="num" title="{{localize "Wounds"}}"><i class="fas fa-heart"></i></div>
<div class="num" title="{{localize "Advantage"}}"><i class="fas fa-plus-circle"></i></div>
Expand Down

0 comments on commit 487a2f1

Please sign in to comment.