Skip to content

Commit

Permalink
add setting to handle scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Werner committed Jun 26, 2022
1 parent bb13fa7 commit c8e4ed1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
"TR.Tabs.Structure": "Structure",
"TR.Tabs.Formatting": "Formatting",
"TR.Tabs.Tokenizer": "Tokenizer",
"TR.Tokenizer.Question": "Use MrPrimate's Tokenizer? This will open the Tokenizer and will allow you to manually create a portrait and token image."
"TR.Tokenizer.Question": "Use MrPrimate's Tokenizer? This will open the Tokenizer and will allow you to manually create a portrait and token image.",
"TR.ScaleName.Name": "Scale Name",
"TR.ScaleName.Hint": "The wording in the image name that determines the scale the token should be set to. If the file name is 'Pit_Fiend_Large_Scale200', then you would set the variable to 'scale' and the token will be scaled to be 200%."
}


25 changes: 20 additions & 5 deletions scripts/token-replacer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const tr_tokenPathDefault = "modules/token-replacer/tokens/";
const tr_difficultyNameDefault = "cr";
const tr_difficultyVariableDefault = "data.details.cr";
const tr_scaleVariableDefault = "scale";
const tr_portraitPrefixDefault = "";
const tr_useStructureDefault = 1;
const tr_BAD_DIRS = ["[data]", "[data] ", "", null];
Expand All @@ -12,6 +13,7 @@ let tr_tokenDirectory;
let tr_difficultyName;
let tr_difficultyVariable;
let tr_portraitPrefix;
let tr_scaleName;
let tr_hookedFromTokenCreation = false;
let tr_imageNameFormat;
let tr_isTRDebug = false;
Expand Down Expand Up @@ -123,6 +125,7 @@ class TokenReplacerSetup extends FormApplication {
const prefix = formData['token-replacer.portraitPrefix'];
const integrateTokenizer = formData['token-replacer.integrateTokenizer'];
const promptTokenizer = formData['token-replacer.promptTokenizer'];
const scaleName = formData['token-replacer.scaleName'];

// can’t be const because it’s overwritten for debug logging
const imageNameIdx = formData['token-replacer.imageNameFormat'];
Expand Down Expand Up @@ -161,6 +164,7 @@ class TokenReplacerSetup extends FormApplication {
await game.settings.set("token-replacer", "folderNameFormat", folderNameIdx);
await game.settings.set("token-replacer", "integrateTokenizer", integrateTokenizer);
await game.settings.set("token-replacer", "promptTokenizer", promptTokenizer);
await game.settings.set("token-replacer", "scaleName", scaleName);

const isTRDebug = game.settings.get("token-replacer", "debug");
if (isTRDebug) {
Expand Down Expand Up @@ -330,6 +334,7 @@ const TokenReplacer = {
tr_difficultyName = game.settings.get("token-replacer", "difficultyName");
tr_difficultyVariable = game.settings.get("token-replacer", "difficultyVariable");
tr_portraitPrefix = game.settings.get("token-replacer", "portraitPrefix");
tr_scaleName = game.settings.get("token-replacer", "scaleName");
if (!tr_portraitPrefix) {
tr_portraitPrefix = 'portrait_';
}
Expand Down Expand Up @@ -360,7 +365,7 @@ const TokenReplacer = {
tr_integrateTokenizer = game.settings.get("token-replacer", "integrateTokenizer");
if (tr_integrateTokenizer) {
tr_promptTokenizer = game.settings.get("token-replacer", "promptTokenizer");
}
}

tr_isTRDebug = game.settings.get("token-replacer", "debug");
},
Expand Down Expand Up @@ -396,7 +401,7 @@ const TokenReplacer = {
document.update({
"img": document.data.img,
"token.img": document.data.token.img,
"token.scale": TokenReplacer.calculateScale(actor.data.token.img),
"token.scale": TokenReplacer.calculateScale(document.data.token.img),
});
},

Expand All @@ -423,7 +428,7 @@ const TokenReplacer = {
document.update({
"img": document.data.img,
"token.img": document.data.token.img,
"token.scale": TokenReplacer.calculateScale(actor.data.token.img),
"token.scale": TokenReplacer.calculateScale(document.data.token.img),
});
},

Expand Down Expand Up @@ -676,10 +681,10 @@ const TokenReplacer = {

calculateScale(imageName) {
let scale = 1;
let pos = imageName.toLowerCase().indexOf("scale");
let pos = imageName.toLowerCase().indexOf(tr_scaleName.toLowerCase());

if (pos >= 0) {
scale = imageName.toLowerCase().substr(pos + "scale".length, 3);
scale = imageName.toLowerCase().substr(pos + tr_scaleName.toLowerCase().length, 3);
scale = +scale / 100;

if (isNaN(scale)) {
Expand Down Expand Up @@ -864,6 +869,16 @@ async function registerTokenReplacerSettings() {
default: 0,
});

game.settings.register("token-replacer", "scaleName", {
name: game.i18n.localize("TR.ScaleName.Name"),
hint: game.i18n.localize("TR.ScaleName.Hint"),
scope: "world",
group: "format",
config: false,
type: String,
default: tr_scaleVariableDefault,
});

game.settings.register("token-replacer", "integrateTokenizer", {
name: game.i18n.localize("TR.Tokenizer.Name"),
hint: game.i18n.localize("TR.Tokenizer.Hint"),
Expand Down

0 comments on commit c8e4ed1

Please sign in to comment.