Skip to content

Commit

Permalink
feat: Add experimental feature that mostly succeeds at keeping the my…
Browse files Browse the repository at this point in the history
…stified token name out of chat messages (it depends on the creature ability chat text consistently using the *full* name of the creature, which is not always the case.)

E.g. it works well for the Balor, but not so well for the Aapoph Serpentfolk (that sometimes just uses 'aapoph' in the chat text.)
  • Loading branch information
xdy committed Dec 4, 2021
1 parent 1747d5a commit a727d8a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/module/mystify-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ export function renderNameHud(data: any, html: JQuery<HTMLElement>) {
html.find("div.col.left").append(toggle);
}
}

export function mangleChatMessage(message: ChatMessage, html: JQuery) {
const actorId = <string>message.data.speaker.actor;
const tokenId = message.data.speaker.token;
const actor = (game as Game).actors?.get(actorId);
const jqueryContent = html.find(".action-card");

const tokenName = <string>(game as Game).scenes?.active?.tokens?.find((t) => t?.id === tokenId)?.name;
const tokenNameNoNumber = tokenName?.replace(/\d+$/, "").trim();

jqueryContent.html(jqueryContent.html().replace(new RegExp(<string>actor?.name, "gi"), tokenNameNoNumber));
}
13 changes: 11 additions & 2 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function registerSettings() {

settings.register(MODULENAME, "npcMystifierAddRandomNumber", {
name: "Add random number to name.", //game.i18n.localize(`${MODULENAME}.SETTINGS.npcMystifierAddRandomNumber.Name`),
hint: "Turns on adding a random number when mystifying npcs.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifierAddRandomNumber.Hint`),
hint: "Turns on adding a random number when mystifying npcs. Note that if the token or actor already has a number as a suffix this will not work well.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifierAddRandomNumber.Hint`),
scope: "world",
config: true,
default: true,
Expand All @@ -75,13 +75,22 @@ export function registerSettings() {

settings.register(MODULENAME, "npcMystifierKeepNumberAtEndOfName", {
name: "Keep token number when mystifying/demystifying.", //(game as Game).i18n.localize(`${MODULENAME}.SETTINGS.npcMystifierKeepNumberAtEndOfName.Name`),
hint: "Keep token number at end of name (if any) when mystifying/demystifying npcs.", //(game as Game).i18n.localize(`${MODULENAME}.settings.npcMystifierKeepNumberAtEndOfName.Hint`),
hint: "Keep token number *added by this module* at end of name (if any) when mystifying/demystifying npcs.", //(game as Game).i18n.localize(`${MODULENAME}.settings.npcMystifierKeepNumberAtEndOfName.Hint`),
scope: "world",
config: true,
default: true,
type: Boolean,
});

settings.register(MODULENAME, "npcMystifierUseMystifiedNameInChat", {
name: "(Experimental) Use mystified name inside chat messages.", //(game as Game).i18n.localize(`${MODULENAME}.SETTINGS.npcMystifierKeepNumberAtEndOfName.Name`),
hint: "(Experimental) Use mystified name inside chat messages by replacing the actor name with the mystified name. Will doubtlessly look real bad on some abilities.", //(game as Game).i18n.localize(`${MODULENAME}.settings.npcMystifierKeepNumberAtEndOfName.Hint`),
scope: "world",
config: true,
default: false,
type: Boolean,
});

//TODO These apply only to trait mystification and should be grouped together, maybe on a separate tab?
settings.register(MODULENAME, "npcMystifierFilterRarities", {
name: "No npc rarity in name.", //game.i18n.localize(`${MODULENAME}.settings.npcMystifierFilterRarities.Name`),
Expand Down
1 change: 1 addition & 0 deletions src/module/traits-name-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function generateNameFromTraits(token: Token) {
traitsList = filterTraitList(traitsList);

const name = traitsList
.filter((trait: string) => trait !== "")
.map((trait: string) => {
return trait?.charAt(0).toUpperCase() + trait?.slice(1);
})
Expand Down
8 changes: 7 additions & 1 deletion src/module/xdy-pf2e-workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Import TypeScript modules
import { preloadTemplates } from "./preloadTemplates";
import { registerSettings } from "./settings";
import { preTokenCreateMystification, renderNameHud } from "./mystify-token";
import { mangleChatMessage, preTokenCreateMystification, renderNameHud } from "./mystify-token";

export const MODULENAME = "xdy-pf2e-workbench";

Expand Down Expand Up @@ -66,3 +66,9 @@ Hooks.on("renderTokenHUD", (_app: TokenHUD, html: JQuery, data: any) => {
renderNameHud(data, html);
}
});

Hooks.on("renderChatMessage", (message: ChatMessage, html: JQuery) => {
if ((game as Game).settings.get(MODULENAME, "npcMystifierUseMystifiedNameInChat")) {
mangleChatMessage(message, html);
}
});

0 comments on commit a727d8a

Please sign in to comment.