Skip to content

Commit

Permalink
Added Bestiary Category Customization
Browse files Browse the repository at this point in the history
  • Loading branch information
WBHarry committed Sep 10, 2024
1 parent 706a7ea commit 261bc92
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 20 deletions.
68 changes: 67 additions & 1 deletion BestiaryTracking.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions data/bestiaryAppearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ export const optionalFields = {
height: false,
weight: false,
};

export const bestiaryCategorySettings = {
creature: {
name: "PF2EBestiary.Bestiary.Category.Creatures",
image: "icons/creatures/magical/humanoid-silhouette-green.webp",
},
npc: {
name: "PF2EBestiary.Bestiary.Category.NPC",
image: "icons/environment/people/group.webp",
},
hazard: {
name: "PF2EBestiary.Bestiary.Category.Hazards",
image: "icons/environment/traps/trap-jaw-steel.webp",
},
};
5 changes: 5 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"Miscellaneous": {
"Name": "Name",
"Title": "Title",
"Level": "Level",
"AC": "AC",
"HP": "HP",
Expand Down Expand Up @@ -326,6 +327,10 @@
"AdditionalCreatureTypes": {
"Name": "Additional Creature Types",
"SubText": "You can add more available creature traits to choose from in the PF2E System Settings for Homebrew."
},
"CategorySettings": {
"Title": "Bestiary Category Customization",
"Image": "Image"
}
},
"BestiaryIntegration": {
Expand Down
7 changes: 6 additions & 1 deletion module/bestiary.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,13 @@ export default class PF2EBestiary extends HandlebarsApplicationMixin(
"contrast-revealed-state",
);
context.vagueDescriptions = foundry.utils.deepClone(
await game.settings.get("pf2e-bestiary-tracking", "vague-descriptions"),
game.settings.get("pf2e-bestiary-tracking", "vague-descriptions"),
);
context.categorySettings = game.settings.get(
"pf2e-bestiary-tracking",
"bestiary-category-settings",
);

context.recallKnowledgeJournal = this.bestiary.getFlag(
"pf2e-bestiary-tracking",
"recall-knowledge-journal",
Expand Down
45 changes: 44 additions & 1 deletion module/bestiaryAppearanceMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { revealedState } from "../data/bestiaryAppearance.js";
import {
bestiaryCategorySettings,
revealedState,
} from "../data/bestiaryAppearance.js";
import Tagify from "@yaireo/tagify";

const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
Expand Down Expand Up @@ -30,6 +33,10 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
"pf2e-bestiary-tracking",
"detailed-information-toggles",
),
categorySettings: game.settings.get(
"pf2e-bestiary-tracking",
"bestiary-category-settings",
),
};
}

Expand All @@ -44,8 +51,10 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
position: { width: 680, height: "auto" },
actions: {
resetContrastRevealedState: this.resetContrastRevealedState,
resetCategorySettings: this.resetCategorySettings,
toggleOptionalFields: this.toggleOptionalFields,
toggleDetailedInformation: this.toggleDetailedInformation,
filePicker: this.filePicker,
save: this.save,
},
form: { handler: this.updateData, submitOnChange: true },
Expand Down Expand Up @@ -110,6 +119,19 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
contrastRevealedState: data.contrastRevealedState,
optionalFields: data.optionalFields,
detailedInformation: { ...data.detailedInformation },
categorySettings: {
creature: {
...data.categorySettings.creature,
image: this.settings.categorySettings.creature.image,
},
npc: {
...data.categorySettings.npc,
image: this.settings.categorySettings.npc.image,
},
hazard: {
...this.settings.categorySettings.hazard,
},
},
};
this.render();
}
Expand All @@ -126,6 +148,11 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
this.render();
}

static async resetCategorySettings() {
this.settings.categorySettings = { ...bestiaryCategorySettings };
this.render();
}

static async toggleOptionalFields() {
const keys = Object.keys(this.settings.optionalFields);
const enable = Object.values(this.settings.optionalFields).some((x) => !x);
Expand All @@ -150,6 +177,17 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
this.render();
}

static async filePicker(_, button) {
new FilePicker({
type: "image",
title: "Image Select",
callback: async (path) => {
foundry.utils.setProperty(this.settings, button.dataset.path, path);
this.render();
},
}).render(true);
}

static async save(_) {
await game.settings.set(
"pf2e-bestiary-tracking",
Expand Down Expand Up @@ -184,6 +222,11 @@ export default class BestiaryAppearanceMenu extends HandlebarsApplicationMixin(
"detailed-information-toggles",
this.settings.detailedInformation,
);
await game.settings.set(
"pf2e-bestiary-tracking",
"bestiary-category-settings",
this.settings.categorySettings,
);
this.close();
}
}
23 changes: 22 additions & 1 deletion scripts/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { optionalFields, revealedState } from "../data/bestiaryAppearance.js";
import {
bestiaryCategorySettings,
optionalFields,
revealedState,
} from "../data/bestiaryAppearance.js";
import { getVagueDescriptionLabels } from "../data/bestiaryLabels.js";
import { Creature } from "../data/creature.js";
import { NPC } from "../data/npc.js";
Expand Down Expand Up @@ -308,6 +312,23 @@ const bestiaryAppearance = () => {
restricted: true,
});

game.settings.register(
"pf2e-bestiary-tracking",
"bestiary-category-settings",
{
name: game.i18n.localize(
"PF2EBestiary.Settings.BestiaryCategorySettings.Name",
),
hint: game.i18n.localize(
"PF2EBestiary.Settings.BestiaryCategorySettings.Hint",
),
scope: "world",
config: false,
type: Object,
default: bestiaryCategorySettings,
},
);

game.settings.register("pf2e-bestiary-tracking", "contrast-revealed-state", {
name: game.i18n.localize("PF2EBestiary.Settings.ContrastRevealState.Name"),
hint: game.i18n.localize("PF2EBestiary.Settings.ContrastRevealState.Hint"),
Expand Down
11 changes: 11 additions & 0 deletions styles/pf2e-bestiary-tracking.css
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,17 @@
flex-direction: column;
gap: 8px;
}
.bestiary-settings-menu .bestiary-customization-container {
display: flex;
flex-direction: column;
gap: 8px;
}
.bestiary-settings-menu .bestiary-customization-container .no-flex {
flex: none;
}
.bestiary-settings-menu .bestiary-customization-container button {
height: 32px;
}
.bestiary-settings-menu .menu-grouper-container {
display: flex;
flex-direction: column;
Expand Down
14 changes: 14 additions & 0 deletions styles/stylesheets/bestiarySettingsMenu.less
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@
gap: 8px;
}

.bestiary-customization-container {
display: flex;
flex-direction: column;
gap: 8px;

.no-flex {
flex: none;
}

button {
height: 32px;
}
}

.menu-grouper-container {
display: flex;
flex-direction: column;
Expand Down
12 changes: 6 additions & 6 deletions templates/bestiary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
<div class="main-page-category-container">
<div class="main-page-category-card">
<div class="main-page-category-image-container primary-hover-container {{#if (eq this.selected.category 'pf2e-bestiary-tracking.creature')}}secondary-border-container{{/if}}" data-action="selectCategory" data-category="pf2e-bestiary-tracking.creature">
<img src="icons/creatures/magical/humanoid-silhouette-green.webp" />
<h4 class="main-page-category-label primary-container">{{localize "PF2EBestiary.Bestiary.Category.Creatures"}}</h4>
<img src="{{this.categorySettings.creature.image}}" />
<h4 class="main-page-category-label primary-container">{{localize this.categorySettings.creature.name}}</h4>
</div>
</div>
<div class="main-page-category-card">
<div class="main-page-category-image-container primary-hover-container {{#if (eq this.selected.category 'pf2e-bestiary-tracking.npc')}}secondary-border-container{{/if}}" data-action="selectCategory" data-category="pf2e-bestiary-tracking.npc">
<img src="icons/environment/people/group.webp" />
<h4 class="main-page-category-label primary-container">{{localize "PF2EBestiary.Bestiary.Category.NPC"}}</h4>
<img src="{{this.categorySettings.npc.image}}" />
<h4 class="main-page-category-label primary-container">{{localize this.categorySettings.npc.name}}</h4>
</div>
</div>
<div class="main-page-category-card" title="Not available yet!">
<div class="main-page-category-image-container secondary-border-container inactive">
<img src="icons/environment/traps/trap-jaw-steel.webp" class="inactive" />
<h4 class="main-page-category-label primary-container inactive">{{localize "PF2EBestiary.Bestiary.Category.Hazards"}}</h4>
<img src="{{this.categorySettings.hazard.image}}" class="inactive" />
<h4 class="main-page-category-label primary-container inactive">{{localize this.categorySettings.hazard.name}}</h4>
</div>
<i class="fa-solid fa-lock under-development primary-icon"></i>
</div>
Expand Down
Loading

0 comments on commit 261bc92

Please sign in to comment.