Skip to content

Commit

Permalink
Fix for multi category creature linking.
Browse files Browse the repository at this point in the history
  • Loading branch information
WBHarry committed Aug 13, 2024
1 parent c1c58f7 commit b1fcc60
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
10 changes: 6 additions & 4 deletions module/bestiary.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
context.selected = foundry.utils.deepClone(this.selected);
context.openType = this.selected.type ? Object.keys(this.bestiary[this.selected.category][this.selected.type]).reduce((acc, key)=> {
const monster = this.bestiary[this.selected.category][this.selected.type][key];
if(!this.search.name || monster.name.toLowerCase().match(this.search.name.toLowerCase())) {
if(!this.search.name || (monster.name.revealed && monster.name.value.toLowerCase().match(this.search.name.toLowerCase()))) {
acc[key] = monster;
}

Expand Down Expand Up @@ -155,8 +155,10 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
static async toggleRevealed(_, button){
if(!game.user.isGM) return;

foundry.utils.setProperty(this.selected.monster, `${button.dataset.path}.revealed`, !foundry.utils.getProperty(this.selected.monster, `${button.dataset.path}.revealed`));

for(var type of this.selected.monster.inTypes){
foundry.utils.setProperty(this.bestiary.monster[type][this.selected.monster.slug], `${button.dataset.path}.revealed`, !foundry.utils.getProperty(this.bestiary.monster[type][this.selected.monster.slug]));
}

if(button.dataset.parent){
const values = Object.values(this.selected.monster[button.dataset.parent].values);
this.selected.monster[button.dataset.parent].currentRevealed = values.filter(x => x.revealed).length;
Expand Down Expand Up @@ -296,7 +298,7 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(Application
inTypes: types.map(x => x.key),
traits: traits,
size: getCreatureSize(item.system.traits.size.value),
name: item.name,
name: { reveal: false, value: item.name },
img: item.img,
abilities: {
revealed: false,
Expand Down
13 changes: 3 additions & 10 deletions scripts/handlebarHelpers.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
export default class RegisterHandlebarsHelpers {
static registerHelpers(){
Handlebars.registerHelper({
add: this.add,
nrKeys: this.nrKeys,
monsterValue: this.monsterValue,
categoryClassTitle: this.categoryClassTitle,
PF2EBTNrKeys: this.nrKeys,
PF2EBTMonsterValue: this.monsterValue,
PF2EBTCategoryClassTitle: this.categoryClassTitle,
});
};

static add(a, b){
const aNum = Number.parseInt(a);
const bNum = Number.parseInt(b);
return (Number.isNaN(aNum) ? 0 : aNum) + (Number.isNaN(bNum) ? 0 : bNum);
}

static nrKeys(obj) {
return obj ? Object.keys(obj).length : 0;
Expand Down
8 changes: 8 additions & 0 deletions scripts/migrationHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const handleDataMigration = async () => {
if(!game.user.isGM) return;

var version = await game.settings.get('pf2e-bestiary-tracking', 'version');
if(!version){
version = '0.8.1';
Expand All @@ -13,6 +15,12 @@ export const handleDataMigration = async () => {
if(!monster.name.value){
bestiary.monster[type][monsterKey].name = { revealed: false, value: monster.name };
}

for(var inType of monster.inTypes){
if(type !== inType){
bestiary.monster[inType][monsterKey] = foundry.utils.deepClone(bestiary.monster[type][monsterKey]);
}
}
});
});

Expand Down
1 change: 1 addition & 0 deletions styles/pf2e-bestiary-tracking.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
min-height: 32px;
}
.bestiary-tracking.bestiary header .return-container {
cursor: pointer;
Expand Down
1 change: 1 addition & 0 deletions styles/stylesheets/bestiary.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
min-height: 32px;

.return-container {
cursor: pointer;
Expand Down
4 changes: 2 additions & 2 deletions templates/bestiary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
{{/with}}
{{else}}
<div class="type-overview-container">
{{#if (eq (nrKeys this.openType) 0)}}
{{#if (eq (PF2EBTNrKeys this.openType) 0)}}
{{localize "PF2EBestiary.Bestiary.CategoryView.EmptyText" category=this.selected.type}}
{{else}}
{{#each this.openType as |type key|}}
Expand All @@ -67,7 +67,7 @@
</body>
<div class="right-bookmark-container">
{{#each bestiary.monster as |type key|}}
<div class="bookmark{{#if (eq ../selected.type key)}} selected{{/if}}{{#if (eq (nrKeys type) 0)}} empty{{/if}}" data-action="selectBookmark" data-bookmark="{{key}}">
<div class="bookmark{{#if (eq ../selected.type key)}} selected{{/if}}{{#if (eq (PF2EBTNrKeys type) 0)}} empty{{/if}}" data-action="selectBookmark" data-bookmark="{{key}}">
{{key}}
</div>
{{/each}}
Expand Down
22 changes: 11 additions & 11 deletions templates/partials/monsterView.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<i class="fa-solid fa-fw fa-shield-halved"></i>
<div>{{localize "PF2EBestiary.Miscellaneous.AC"}}</div>
</div>
<div class="flex-value">{{#if (or this.ac.revealed this.user.isGM)}}{{monsterValue this.ac this.vagueDescriptions.ac}}{{else}}?{{/if}}</div>
<div class="flex-value">{{#if (or this.ac.revealed this.user.isGM)}}{{PF2EBTMonsterValue this.ac this.vagueDescriptions.ac}}{{else}}?{{/if}}</div>
</div>

<div class="monster-left-data {{#if this.user.isGM}}toggle-container {{#if this.hp.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="hp">
<div class="flex-data">
<i class="fa-solid fa-fw fa-shield-halved"></i>
<div>{{localize "PF2EBestiary.Miscellaneous.HP"}}</div>
</div>
<div class="flex-value">{{#if (or this.hp.revealed this.user.isGM)}}{{monsterValue this.hp this.vagueDescriptions.hp}}{{else}}?{{/if}}</div>
<div class="flex-value">{{#if (or this.hp.revealed this.user.isGM)}}{{PF2EBTMonsterValue this.hp this.vagueDescriptions.hp}}{{else}}?{{/if}}</div>
</div>

<div class="flexcol">
Expand Down Expand Up @@ -65,9 +65,9 @@
data-action="toggleRevealed"
data-path="{{concat 'weaknesses.values.' key}}"
data-parent="weaknesses"
title="{{categoryClassTitle weakness.class 'Weakness' ../vagueDescriptions.weaknesses}}"
title="{{PF2EBTCategoryClassTitle weakness.class 'Weakness' ../vagueDescriptions.weaknesses}}"
>
{{monsterValue weakness ../vagueDescriptions.weaknesses}}
{{PF2EBTMonsterValue weakness ../vagueDescriptions.weaknesses}}
</div>
{{#if (and (not ../user.isGM) (gt ../weaknesses.currentRevealed weakness.index))}},&nbsp;{{/if}}
{{/if}}
Expand Down Expand Up @@ -99,9 +99,9 @@
data-action="toggleRevealed"
data-path="{{concat 'resistances.values.' key}}"
data-parent="resistances"
title="{{categoryClassTitle resistance.class 'Resistance' ../vagueDescriptions.resistances}}"
title="{{PF2EBTCategoryClassTitle resistance.class 'Resistance' ../vagueDescriptions.resistances}}"
>
{{monsterValue resistance ../vagueDescriptions.resistances}}
{{PF2EBTMonsterValue resistance ../vagueDescriptions.resistances}}
</div>
{{#if (and (not ../user.isGM) (gt ../this.resistances.currentRevealed resistance.index))}},&nbsp;{{/if}}
{{/if}}
Expand All @@ -122,15 +122,15 @@
<div class="saves-container">
<div class="save-container">
<div class="saves-title {{#if this.user.isGM }}toggle-container {{#if this.saves.fortitude.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="saves.fortitude">{{localize "PF2EBestiary.Miscellaneous.Saves.Fortitude.Short"}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.fortitude.revealed)}}{{monsterValue this.saves.fortitude this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.fortitude.revealed)}}{{PF2EBTMonsterValue this.saves.fortitude this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
</div>
<div class="save-container">
<div class="saves-title {{#if this.user.isGM }}toggle-container {{#if this.saves.reflex.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="saves.reflex">{{localize "PF2EBestiary.Miscellaneous.Saves.Reflex.Short"}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.reflex.revealed)}}{{monsterValue this.saves.reflex this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.reflex.revealed)}}{{PF2EBTMonsterValue this.saves.reflex this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
</div>
<div class="save-container">
<div class="saves-title {{#if this.user.isGM }}toggle-container {{#if this.saves.will.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="saves.will">{{localize "PF2EBestiary.Miscellaneous.Saves.Will.Short"}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.will.revealed)}}{{monsterValue this.saves.will this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
<div class="saves-value">{{#if (or this.user.isGM this.saves.will.revealed)}}{{PF2EBTMonsterValue this.saves.will this.vagueDescriptions.saves}}{{else}}?{{/if}}</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -160,7 +160,7 @@

<div class="right-monster-container">
<div class="flexcol">
<div class="monster-name {{#if this.user.isGM }}toggle-container {{#if this.name.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="name">{{#if (or this.user.isGM this.name.revealed)}}{{this.name.value}}{{else}}{{localize "PF2EBestiary.Miscellaneous.UnknownCreature"}}{{/if}}</div>
<div class="monster-name {{#if this.user.isGM }}toggle-container {{#if this.name.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="name">{{#if (or this.user.isGM this.name.revealed)}}{{this.name.value}}{{else}}{{localize "PF2EBestiary.Bestiary.Miscellaneous.UnknownCreature"}}{{/if}}</div>
<div class="monster-traits-row">
<div class="monster-size">{{this.size}}</div>
<div class="monster-traits flexrow">
Expand Down Expand Up @@ -213,7 +213,7 @@
<div class="flexrow {{#if ../user.isGM }}toggle-container {{#if sense.revealed}}revealed{{/if}}{{/if}}" data-action="toggleRevealed" data-path="{{concat 'senses.values.' key}}" data-parent="senses">
<div class="pf2e-bestiary-bold">{{sense.label}}</div>
{{#if (and (not ../user.isGM) (eq key 'perception'))}}
{{monsterValue sense ../vagueDescriptions.perception }}
{{PF2EBTMonsterValue sense ../vagueDescriptions.perception }}
{{else}}
{{sense.value}}
{{/if}}
Expand Down

0 comments on commit b1fcc60

Please sign in to comment.