From 57935f4f9e045fd0cbcc59c7d9ad7e91707f95d2 Mon Sep 17 00:00:00 2001 From: Javier Romero Date: Wed, 21 Jul 2021 10:31:40 -0400 Subject: [PATCH] Added parameter setting in filename: * Wildcard images that include any of the following _height_ _width_ _scale_ anywhere in the name will use the value of instead of the prototype token values to set the dimensions of the token --- README.md | 7 +++++++ token-hud-wildcard.zip | Bin 6103 -> 6291 bytes token-hud-wildcard/main.js | 25 +++++++++++++++++++++++-- token-hud-wildcard/module.json | 4 ++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 11cda1f..3235510 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ If you don't want the image on drop to be chosen randomly, you can use the field If you're gonna use the default image field, I recommend you use an image file that follows the wildcard pattern. but it's not required and you can have a different default image. If you choose an image that doesn't follow the pattern you just won't be able to pick it again after changing it in the images panel. +You can also use the image filename to set the dimensions of the token using the following example format: + +- wildcard images use this pattern `name*` +- `name_height_width_scale_.extension`, it's important that each parameter s preceded and followed by an underscore, so if you want to set up height, there has to be a `_height_` somewhere in the name +- you can choose to change `` for a positive integer or floating number and which one to fill. If there are any parameter missing then the module will use the prototype token parameters to fill the ones missing, so you can use images with no parameter setting at all or just set one or two of the parameters. +- these are valid filenames that will be picked up by the module `name.extension`, `name-different.extension`, `name-other_height2_scale1.5_.extension` + ## Installation To install the module, follow any of these methods: diff --git a/token-hud-wildcard.zip b/token-hud-wildcard.zip index 8473200304d1e7b0af40ae8aca9b51eef2e4f261..bb404ec8d1a5993c279a0a9d78061bd527de38de 100644 GIT binary patch delta 2682 zcmV-=3WfF8FOxB_MhAZ}QuR`dyoHn)2LJ%z7ytkV0001OVQFqIYIChv>u%F96#kFI zJD3WQ1f^a9J@$7wf>zB|X4#Bq|27N}rpY@g5P`uVs~ zo|OWL{3p%ceL4BYk~ktfMl*DC_YQ&&r%P4}%0E*fShg&u$Pa(e?4_DEpCw5tF3miy z1$<9|j#pJY-WXUfL>^1YlAf@#NXRw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ts*no^-6Pi`Th{5!lw$DWC+6g*poz<1BaX&a-X}Jtoz6X`_wOKI7wJrv$#tJv zqt{c`8WG>w+AzRWLW;x)Q6R?+@VJu~`;D;BEY&H6Qh)PVfJNYzDk`o1TMgd2RjU(p zy<%pTF(oA((kveadL=6zTr`**Ww22BYhS~J8mbGvw-g*)>n`pIndg_N;0$TDJ^e;Q zR(EcCUgN>t48EjjoW0M+!sB;mGHQFeHOs8B*ym8iUI@jVOSPa+FTb`GMX8iHV?|la zcZ`)-i;|q5fAqT`8ua;DOMD4)vzj~Y;j5q=Ngh&uTq&(#rIB?dx2oFan^S5TVI`sR z;zbfyI2zpR8Pq>JZsgqZqQtdC+96tduQvPnsug~92TiIzvo*R3`T4ck^pCa7_X34W z46fd26x$!zXxsSP9Lu=6{ydzX+qE1~k69+MridQ^IOXr*M8FiEm`a7%EvIaS&NXE$ z=xIm&;uDdhrqrUH$7`b5icYcb69f$eB=A2d6^m5U$B~D>thQRz4Hp5wI#QgdFPgz3Dz9RK^q;F@?(8#>nco({P=Mb~W(wLS3_nK7=7H>T*U z&FScM0ROjebN~PYBLKh(kUn0-6A?c)5<5xj~{BpANJ158#-NgJq3QWiE768C@tU { + const height = imgName.match(/_height(.*)_/) + const width = imgName.match(/_width(.*)_/) + const scale = imgName.match(/_scale(.*)_/) + + const prototypeData = token._actor.data.token + + return { + height: height ? parseFloat(height[1]) : prototypeData.height, + width: width ? parseFloat(width[1]) : prototypeData.width, + scale: scale ? parseFloat(scale[1]) : prototypeData.scale, + } +} + Hooks.on('init', () => { tokenHUDWildcard.registerSettings() }) @@ -39,8 +53,11 @@ const WildcardDefault = { Hooks.on('preCreateToken', (token, data, options, userId) => { const actor = token.actor const defaultValue = data.flags['token-hud-wildcard'] ? data.flags['token-hud-wildcard'].default : '' + if (defaultValue !== '' && actor?.data.token.randomImg) { - token.data.update({img:defaultValue}); + const dimensions = getTokenDimensions(token, defaultValue) + let updateInfo = { img: defaultValue, ...dimensions } + token.data.update(updateInfo) } }) }, @@ -131,7 +148,11 @@ Hooks.on('renderTokenHUD', async (hud, html, token) => { const index = controlled.findIndex(x => x.data._id === token._id) const tokenToChange = controlled[index] const updateTarget = is080 ? tokenToChange.document : tokenToChange - updateTarget.update({ img: event.target.dataset.name }) + + const dimensions = getTokenDimensions(updateTarget, event.target.dataset.name) + let updateInfo = { img: event.target.dataset.name, ...dimensions } + + updateTarget.update(updateInfo) }) }) }) diff --git a/token-hud-wildcard/module.json b/token-hud-wildcard/module.json index 4ea0e9f..1617666 100644 --- a/token-hud-wildcard/module.json +++ b/token-hud-wildcard/module.json @@ -2,9 +2,9 @@ "name": "token-hud-wildcard", "title": "Token HUD Wildcard", "description": "This module adds a button to the Token HUD if the token has wildcard set and detects more than 1 image to choose from. Pressing the button displays a panel on the right side of the HUD with buttons for each image, pressing one of these allows to change the token image.", - "version": "1.3.1", + "version": "1.4.0", "minimumCoreVersion": "0.6.0", - "compatibleCoreVersion": "0.8.7", + "compatibleCoreVersion": "0.8.8", "author": "Javieros", "scripts": ["main.js"], "styles": ["./css/token-hud-wildcard.css"],