Skip to content

Commit

Permalink
feat: Added keybind to mystify all selected creatures (M by default, …
Browse files Browse the repository at this point in the history
…can be changed). Made it possible to always/never mystify when dragging from sidebar.

Fixes #4
  • Loading branch information
xdy committed Dec 17, 2021
1 parent df7bbac commit 4cb6a30
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 12,350 deletions.
12,550 changes: 227 additions & 12,323 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@league-of-foundry-developers/foundry-vtt-types": "^0.8.9-9",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/exec": "^6.0.2",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
Expand All @@ -38,13 +38,13 @@
"@types/fs-extra": "^9.0.13",
"@types/jquery": "^3.5.10",
"@types/mini-css-extract-plugin": "^2.4.0",
"@types/node": "^16.11.12",
"@types/node": "^16.11.14",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"copy-webpack-plugin": "^10.1.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"copy-webpack-plugin": "^10.2.0",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^3.2.0",
"css-minimizer-webpack-plugin": "^3.3.0",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
Expand All @@ -57,11 +57,11 @@
"prettier": "^2.5.1",
"semantic-release": "^18.0.1",
"simple-progress-webpack-plugin": "^2.0.0",
"terser-webpack-plugin": "^5.2.5",
"terser-webpack-plugin": "^5.3.0",
"thread-loader": "^3.0.4",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"typescript": "^4.5.3",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"write-file-webpack-plugin": "^4.5.1",
Expand Down
10 changes: 6 additions & 4 deletions src/module/app/mystify-token/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateNameFromTraits } from "./traits-name-generator";
import { MODULENAME } from "../../xdy-pf2e-workbench";
import { mystifyKey } from "../../settings";
import { mystifyModifierKey } from "../../settings";

function shouldSkipRandomNumber(token: Token) {
return (
Expand Down Expand Up @@ -55,16 +55,18 @@ export async function mystifyToken(token: Token | null, mystified: boolean): Pro
export function preTokenCreateMystification(token: Token) {
if (
(game as Game).user?.isGM &&
// @ts-ignore
(game as Game).keyboard?.downKeys.has(mystifyKey) &&
!((game as Game).settings.get(MODULENAME, "npcMystifierModifierKey") === "DISABLED") &&
((game as Game).settings.get(MODULENAME, "npcMystifierModifierKey") === "ALWAYS" ||
// @ts-ignore
(game as Game).keyboard?.downKeys.has(mystifyModifierKey)) &&
// @ts-ignore
(!(game as Game).keyboard?.downKeys.has("V") || (game as Game).keyboard?.downKeys.has("Insert"))
) {
mystifyToken(token, isTokenNameDifferent(token));
}
}

function isTokenNameDifferent(token: Token | null): boolean {
export function isTokenNameDifferent(token: Token | null): boolean {
const tokenName = token?.data.name;
const actorName = token?.actor?.name;
if (tokenName !== actorName && (game as Game).settings.get(MODULENAME, "npcMystifierKeepNumberAtEndOfName")) {
Expand Down
35 changes: 28 additions & 7 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Keyboard key controlling whether the actor should be mystified, if this feature is toggled on
import { MODULENAME } from "./xdy-pf2e-workbench";
import { isTokenNameDifferent, mystifyToken } from "./app/mystify-token";

export let mystifyKey: string;
export let mystifyModifierKey: string;

export function registerSettings() {
console.log(`${MODULENAME} | registerSettings`);
Expand Down Expand Up @@ -48,23 +49,43 @@ export function registerSettings() {
default: "",
});

settings.register(MODULENAME, "npcMystifierKey", {
name: "SETTINGS.npcMystifierKey.name",
hint: "SETTINGS.npcMystifierKey.hint",
settings.register(MODULENAME, "npcMystifierModifierKey", {
name: "SETTINGS.npcMystifierModifierKey.name",
hint: "SETTINGS.npcMystifierModifierKey.hint",
scope: "world",
config: true,
type: String,
choices: {
ALWAYS: "Always",
DISABLED: "Disabled",
ALT: "Alt",
CONTROL: "Ctrl",
SHIFT: "Shift",
},
default: "CONTROL",
onChange: (key) => {
return (mystifyKey = <string>key);
return (mystifyModifierKey = <string>key);
},
});

// @ts-ignore
game.keybindings.register(MODULENAME, "npcMystifierMystifyKey", {
name: "SETTINGS.npcMystifierMystifyKey.name",
hint: "SETTINGS.npcMystifierMystifyKey.hint",
editable: [
{
key: "M",
},
],
onDown: () => {
canvas?.tokens?.controlled.filter((token) => mystifyToken(token, isTokenNameDifferent(token)));
},
onUp: () => {},
restricted: false,
reservedModifiers: [],
// @ts-ignore
precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL,
});

settings.register(MODULENAME, "npcMystifierAddRandomNumber", {
name: "SETTINGS.npcMystifierAddRandomNumber.name",
hint: "SETTINGS.npcMystifierAddRandomNumber.hint",
Expand Down Expand Up @@ -174,5 +195,5 @@ export function registerSettings() {
type: String,
});

mystifyKey = (<string>settings.get(MODULENAME, "npcMystifierKey")).toLocaleUpperCase();
mystifyModifierKey = (<string>settings.get(MODULENAME, "npcMystifierModifierKey")).toLocaleUpperCase();
}
2 changes: 0 additions & 2 deletions src/module/xdy-pf2e-workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//TODO Make it so holding shift pops up a dialog where one can change the name
//TODO Can I use the pf2e localization strings?
//TODO Add the option to randomize a name from a list of names (kinda like token mold)
//TODO Add a way to disable the 'traits -> name' stuff but keep the rest. I.e. modularize the name generation.
//TODO Consider doing something to handle the actor name or the original token name being shown in abilities, etc. (i.e. If I get it working it'll hook into chat message creation from the token and simply string replace the actor name with the token name in the final chat message. E.g. if you're using an "Acid Beast" that has been renamed to "Unknown Creature 23' which has the ability "The Acid Beast spits acid" the text 'Acid Beast' will be replaced with 'Unknown Creature 23', making the final chat message read "The Unknown Creature 23 spids acid".)
//TODO Add an option to have the 'demystify' button post a message to chat/pop up a dialog that does that, with demystification details (e.g. pretty much the recall knowledge macro), with the chat button doing the actual demystification.
//TODO Make the button post a chat message with a properly set up roll that players can click, as well as a gm-only button on the message that the gm can use to actually unmystify all mystified tokens with the same base actor on that scene. After all, if you've recognized one zombie shambler I figure you would recognize all zombie shamblers.
//TODO Make issues out of the harder of the above todos...
Expand Down
10 changes: 7 additions & 3 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
"name": "Word to postfix new name with",
"hint": "What to postfix new name with, defaults to '' (example: 'Creature')."
},
"npcMystifierKey": {
"name": "Key to mystify",
"hint": "Hold this to mystify npc as it's dragged out to the scene. Note that if you choose Alt (not the default) it also hides the npc."
"npcMystifierModifierKey": {
"name": "Modifier key to use when mystifying by dragging onto the scene",
"hint": "Hold this to mystify creature as it's dragged out to the scene. Note that if you choose Alt (not the default) it also hides the npc."
},
"npcMystifierMystifyKey": {
"name": "Key for mystifying selected tokens",
"hint": "Select tokens and press this key to mystify them."
},
"npcMystifierAddRandomNumber": {
"name": "Add random number to name.",
Expand Down
10 changes: 7 additions & 3 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
"name": "Ord att postfixa nytt namn med",
"hint": "Vad ska ett nytt namn postfixas med, default '' (exempel: 'Varelse')."
},
"npcMystifierKey": {
"name": "Tangent för mystifiering",
"hint": "Håll denna tengent för att mystifiera npc när den dras ut till scenen. Observera att om du väljer Alt (inte standard) döljer den också npc:n."
"npcMystifierModifierKey": {
"name": "Modifieringstangent för att mystifera när varelse dras ut till scenen.",
"hint": "Håll denna tengent för att mystifiera varelse när den dras ut till scenen. Observera att om du väljer Alt (inte standard) döljer den också npc:n."
},
"npcMystifierMystifyKey": {
"name": "Tangent för att mystifiera valda spelfigurer",
"hint": "Välj spelfigurer och tryck denna knapp för att mystifiera dom."
},
"npcMystifierAddRandomNumber": {
"name": "Lägg till slumpmässigt nummer i namnet.",
Expand Down

0 comments on commit 4cb6a30

Please sign in to comment.