Skip to content

Commit

Permalink
4.3.14
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Aug 18, 2024
1 parent fca726d commit dd3f1db
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# [4.3.14]

- If using dynamic token rings save token image to dynamic texture field as well as token field to allow proper scaling for grid scaled rings.

# [4.3.13]

- Add some mask templates for grid scale dynamic rings.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tokenizer",
"version": "4.3.13",
"version": "4.3.14",
"license": "MIT",
"scripts": {
"lint": "npx eslint src/",
Expand Down
44 changes: 26 additions & 18 deletions src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ function launchTokenizer(options, callback) {

}

function updateDynamicRingData(update, path) {
if (game.release.generation < 12) {
if (update.prototypeToken) {
foundry.utils.setProperty(update.prototypeToken, "flags.dnd5e.tokenRing.enabled", true);
}
if (update.token) {
foundry.utils.setProperty(update.token, "flags.dnd5e.tokenRing.enabled", true);
}
} else {
if (update.prototypeToken) {
foundry.utils.setProperty(update.prototypeToken, "ring.enabled", true);
foundry.utils.setProperty(update.prototypeToken, "ring.subject.texture", path);
}
if (update.token) {
foundry.utils.setProperty(update.token, "ring.enabled", true);
foundry.utils.setProperty(update.token, "ring.subject.texture", path);
}
}
}

async function updateActor(tokenizerResponse) {
logger.debug("Updating Actor, tokenizer data", tokenizerResponse);
const dateTag = `${+new Date()}`;
Expand All @@ -70,10 +90,15 @@ async function updateActor(tokenizerResponse) {
const avatarKey = getAvatarKey();
update[avatarKey] = tokenizerResponse.avatarFilename.split("?")[0] + "?" + dateTag;

const updateDynamicRing = game.settings.get(CONSTANTS.MODULE_ID, "auto-apply-dynamic-token-ring")
|| foundry.utils.getProperty(update.prototypeToken, "ring.enabled")
|| foundry.utils.getProperty(update.token, "ring.enabled");

if (!tokenizerResponse.actor.prototypeToken.randomImg) {
// for non-wildcard tokens, we set the token img now
const tokenPath = tokenizerResponse.tokenFilename.split("?")[0] + "?" + dateTag;
foundry.utils.setProperty(update, "prototypeToken.texture.src", tokenPath);
if (updateDynamicRing) updateDynamicRingData(update, tokenPath);
} else if (tokenizerResponse.actor.prototypeToken.texture.src.indexOf("*") === -1) {
// if it is a wildcard and it isn't get like one, we change that
const actorName = tokenizerResponse.actor.name.replace(/[^\w.]/gi, "_").replace(/__+/g, "");
Expand All @@ -86,24 +111,7 @@ async function updateActor(tokenizerResponse) {
update.token = {
img: `${options.current}/${actorName}.Token-*.${imageFormat}`,
};
}

if (game.settings.get(CONSTANTS.MODULE_ID, "auto-apply-dynamic-token-ring")) {
if (game.release.generation < 12) {
if (update.prototypeToken) {
foundry.utils.setProperty(update.prototypeToken, "flags.dnd5e.tokenRing.enabled", true);
}
if (update.token) {
foundry.utils.setProperty(update.token, "flags.dnd5e.tokenRing.enabled", true);
}
} else {
if (update.prototypeToken) {
foundry.utils.setProperty(update.prototypeToken, "ring.enabled", true);
}
if (update.token) {
foundry.utils.setProperty(update.token, "ring.enabled", true);
}
}
if (updateDynamicRing) updateDynamicRingData(update, `${options.current}/${actorName}.Token-*.${imageFormat}`);
}

logger.debug("Updating with", update);
Expand Down
34 changes: 17 additions & 17 deletions src/tokenizer/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,23 @@ export default class Tokenizer extends FormApplication {
});
}

const foundryGridMask = `[data] ${CONSTANTS.PATH}img/dynamic-ring-circle-mask-grid.webp`.replace(/^\/|\/$/g, "");
if (defaultMask !== foundryGridMask) {
defaultMasks.push({
key: foundryGridMask,
label: game.i18n.localize("vtta-tokenizer.dynamic-grid-mask.foundry"),
selected: false,
});
}

const foundryGridTopMask = `[data] ${CONSTANTS.PATH}img/dynamic-ring-top-mask-grid.webp`.replace(/^\/|\/$/g, "");
if (defaultMask !== foundryGridTopMask) {
defaultMasks.push({
key: foundryGridTopMask,
label: game.i18n.localize("vtta-tokenizer.dynamic-grid-top-mask.foundry"),
selected: false,
});
}
// const foundryGridMask = `[data] ${CONSTANTS.PATH}img/dynamic-ring-circle-mask-grid.webp`.replace(/^\/|\/$/g, "");
// if (defaultMask !== foundryGridMask) {
// defaultMasks.push({
// key: foundryGridMask,
// label: game.i18n.localize("vtta-tokenizer.dynamic-grid-mask.foundry"),
// selected: false,
// });
// }

// const foundryGridTopMask = `[data] ${CONSTANTS.PATH}img/dynamic-ring-top-mask-grid.webp`.replace(/^\/|\/$/g, "");
// if (defaultMask !== foundryGridTopMask) {
// defaultMasks.push({
// key: foundryGridTopMask,
// label: game.i18n.localize("vtta-tokenizer.dynamic-grid-top-mask.foundry"),
// selected: false,
// });
// }

return defaultMasks;
}
Expand Down

0 comments on commit dd3f1db

Please sign in to comment.