Skip to content

Commit

Permalink
feat: Adds support for:
Browse files Browse the repository at this point in the history
* Filtering out elite and weak.
* Filtering out traits that have been added to a blacklist.
* Adding a prefix (defaults to 'Unknown') to the mystified name.
  • Loading branch information
xdy committed Nov 21, 2021
1 parent 34f32d2 commit b7cf761
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 10 deletions.
17 changes: 14 additions & 3 deletions src/module/xdy-pf2e-constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const PF2E_RARITIES: string[] = ["common", "uncommon", "rare", "unique"];
//add PF2E_RARITIES,PF2E_CREATURE_TYPES,PF2E_CREATURE_FAMILIES to an array

export const PF2E_CREATURE_TYPES: string[] = [
const PF2E_RARITIES: string[] = ["common", "uncommon", "rare", "unique"];

const PF2E_CREATURE_TYPES: string[] = [
"aberration",
"animal",
"astral",
Expand All @@ -27,7 +29,7 @@ export const PF2E_CREATURE_TYPES: string[] = [
"undead",
];

export const PF2E_CREATURE_FAMILIES: string[] = [
const PF2E_CREATURE_FAMILIES: string[] = [
"aeon",
"agathion",
"alghollthu",
Expand Down Expand Up @@ -233,3 +235,12 @@ export const PF2E_CREATURE_FAMILIES: string[] = [
"xulgath",
"zombie",
];

const ELITE_WEAK: string[] = ["elite", "weak"];

export const TRAITS = {
RARITIES: PF2E_RARITIES,
CREATURE_TYPES: PF2E_CREATURE_TYPES,
CREATURE_FAMILIES: PF2E_CREATURE_FAMILIES,
ELITE_WEAK: ELITE_WEAK,
};
62 changes: 55 additions & 7 deletions src/module/xdy-pf2e-workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Import TypeScript modules
import { preloadTemplates } from "./preloadTemplates";
import { PF2E_CREATURE_FAMILIES, PF2E_CREATURE_TYPES, PF2E_RARITIES } from "./xdy-pf2e-constants";
import { TRAITS } from "./xdy-pf2e-constants";

const MODULENAME = "xdy-pf2e-workbench";

Expand Down Expand Up @@ -63,6 +63,7 @@ function registerSettings() {
default: true,
type: Boolean,
});

game.settings.register(MODULENAME, "npcMystifierFilterRarities", {
name: "No npc rarity in name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifierFilterRarities.Name`),
hint: "Filter out rarities from the mystified name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.filterRarities.Hint`),
Expand All @@ -72,6 +73,33 @@ function registerSettings() {
type: Boolean,
});

game.settings.register(MODULENAME, "npcMystifierFilterEliteWeak", {
name: "No npc elite/weak status in name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.FilterElitWeak.Name`),
hint: "Filter out elite/weak from the mystified name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.filterEliteWeak.Hint`),
scope: "world",
config: true,
default: false,
type: Boolean,
});

game.settings.register(MODULENAME, "npcMystifierFilterBlacklist", {
name: "Blacklist traits to never add to name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifierFilterBlacklist.Name`),
hint: "Filter out all words in this comma-separated blacklist from the mystified name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.filterBlacklist.Hint`),
scope: "world",
config: true,
default: "",
type: String,
});

game.settings.register(MODULENAME, "npcMystifierPrefix", {
name: "Word to prefix new name with", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.prefix.Hint`),
hint: "What to prefix new name with (default 'Unknown').", //game.i18n.localize(`${MODULENAME}.SETTINGS.npcMystifier.prefix.Name`),
scope: "world",
config: true,
type: String,
default: "Unknown",
});

game.settings.register(MODULENAME, "npcMystifierKey", {
name: "Key to mystify", //game.i18n.localize(`${MODULENAME}.settings.npcMystifier.key.Hint`),
hint: "Hold this to mystify npc as it's dragged out to the scene. Note that if you choose Alt (the default) it also hides the npc.", //game.i18n.localize(`${MODULENAME}.SETTINGS.npcMystifier.key.Name`),
Expand Down Expand Up @@ -109,18 +137,38 @@ Hooks.on("preCreateToken", async (token: Token, data: any) => {
if (game.keyboard.isDown(mystifyKey) && !hasProperty(data.flags, MODULENAME + ".OriginalName")) {
//Option to filter out other traits?
let traitsList = token?.actor?.data?.data["traits"]["traits"]?.value;

//TODO Clean up this mess
if (game.settings.get(MODULENAME, "npcMystifierFilterRarities")) {
traitsList = traitsList.filter((trait: string) => !PF2E_RARITIES.includes(trait));
traitsList = traitsList.filter((trait: string) => !TRAITS.RARITIES.includes(trait));
}

const rarities = traitsList.filter((trait: string) => PF2E_RARITIES.includes(trait));
const creatures = traitsList.filter((trait: string) => PF2E_CREATURE_TYPES.includes(trait));
const families = traitsList.filter((trait: string) => PF2E_CREATURE_FAMILIES.includes(trait));
if (game.settings.get(MODULENAME, "npcMystifierFilterEliteWeak")) {
traitsList = traitsList.filter((trait: string) => !TRAITS.ELITE_WEAK.includes(trait));
}
if (game.settings.get(MODULENAME, "npcMystifierFilterBlacklist")) {
const blacklist =
(<string>game.settings.get(MODULENAME, "npcMystifierFilterBlacklist")).split(",") || null;
if (blacklist) {
traitsList = traitsList.filter((trait: string) => {
return !blacklist.map((trait: string) => trait.trim()).includes(trait);
});
}
}
const eliteWeak = traitsList.filter((trait: string) => TRAITS.ELITE_WEAK.includes(trait));
const rarities = traitsList.filter((trait: string) => TRAITS.RARITIES.includes(trait));
const creatures = traitsList.filter((trait: string) => TRAITS.CREATURE_TYPES.includes(trait));
const families = traitsList.filter((trait: string) => TRAITS.CREATURE_FAMILIES.includes(trait));
const others = traitsList
.filter((trait: string) => !eliteWeak.includes(trait))
.filter((trait: string) => !rarities.includes(trait))
.filter((trait: string) => !creatures.includes(trait))
.filter((trait: string) => !families.includes(trait));
traitsList = rarities.concat(others).concat(creatures).concat(families);
traitsList = [<string>game.settings.get(MODULENAME, "npcMystifierPrefix")]
.concat(eliteWeak)
.concat(rarities)
.concat(others)
.concat(creatures)
.concat(families);

name = traitsList
.map((trait: string) => {
Expand Down

0 comments on commit b7cf761

Please sign in to comment.