vtt-lair / token-replacer Goto Github PK
View Code? Open in Web Editor NEWFoundry VTT - Automatically replace NPC actor tokens and/or portraits dependent on token assets saved in a defined folder structure
License: MIT License
Foundry VTT - Automatically replace NPC actor tokens and/or portraits dependent on token assets saved in a defined folder structure
License: MIT License
Hi there,
did several tests and the module seems to work for me most of the time. It's a bit troublesome that it only tries once to update an actor the moment the token is dragged to the scene and that it means reloading the page if something goes wrong - but that is a managable drawback.
I still get an error message the moment I create a new npc actor in the actor tab, but the module still seems to work fine.
After your recent refactoring, the save button is once again broken when debug logging is enabled, only logging
ReferenceError: imageNameFormat is not defined
at TokenReplacerSetup._updateObject (token-replacer.js:152)
to the console. This is caused by this part of the code which I fixed just last week:
if (isTRDebug) {
if (folderNameFormat === "proper") {
folderNameFormat = " ";
}
if (imageNameFormat === "proper") {
imageNameFormat = " ";
}
console.log(`Token Replacer: Format Structure Setup: '${tr_tokenDirectory.activeSource}/${tr_tokenDirectory.current}/${diffName}${folderNameFormat}0_25/Monster${imageNameFormat}Name.png'`);
}
because after your recent changes, these nameFormat variables no longer exist (instead you use the index from the dropdown in line 113, right below my now-outdated comment about not using const
).
The logging should be changed accordingly (or removed entirely).
Please allow the module to read files as they are already saved instead of forcing a change to underscores.
Downloading a new release causes any of your own images in the tokens folder to be removed and replaced by what is in the release.
Will add an input to set the path to private tokens, so the tokens in the release don't overwrite.
Hi there,
I found one more thing that need a fix.
When I drag an actor, who hast already a defined portrait and token art, from a compendium to a scene or import it to the actors tab, token replacer updates both arts even if he can't find images for this actor - he replaces the aldready defined art with Mystery Man.
Hi,
first things first - this is a great module, I love it.
Due to this fact I want to use the module, but unfortunately ran into several issues:
Sometimes one just wants to see what's currently being used, so you know what folder path you're dealing with.
Hi. Great module!
Item Piles don't work with Token Replacer. They generate an error together.
I don't know which module should patch it. But, I'm reporting.
Thank you.
Issue on item piles: fantasycalendar/FoundryVTT-ItemPiles#36
token-replacer/scripts/token-replacer.js
Line 16 in a803aa5
causes namespace issues when 2 modules use the same variable, this occured with Active Auras and just giving you a heads up
Thanks for making this! I love the functionality and I have it partially working, but I'm having a few issues:
EDIT: I was able to resolve both of these issues by selecting the "Use NPC Difficulty Folder Structure" setting, even though I'm not actually using such a folder.
Finally, I have a feature suggestion:
Thanks again!
It's the only thing holding this editor back.
One want's to be able to zoom in on a face from an artwork for example.
Filename matches fail if the actor name and image have parenthesis.
I have the following image in the directory configured as token-replacer's root:
In addition I added a few others when troubleshooting:
The only match that fails is Giant_Beetle_(4HD).svg
. I added a log statement to show the contents of the cache, and you can see that of the 4 filenames above, the comma and brackets are all escaped, while the parens are unaltered:
token-replacer.js:891 Token Replacer: Caching root folder: 'data', 'modules/tuirgins-tokens/tokens/dd-glyphs'
token-replacer.js:922 Token Replacer: tr_cachedTokens:
modules/tuirgins-tokens/tokens/dd-glyphs/Giant_Beetle%2C_4HD.svg,modules/tuirgins-tokens/tokens/dd-glyphs/Giant_Beetle_(4HD).svg,modules/tuirgins-tokens/tokens/dd-glyphs/Giant_Beetle_%5B4HD%5D.svg,modules/tuirgins-tokens/tokens/dd-glyphs/Giant_Beetle_%7B4HD%7D.svg
However, when the attempt to match occurs, token-replacer is looking for a pattern with escaped parens:
token-replacer.js:709 Token Replacer: searching for token for giant_beetle_%284hd%29
token-replacer.js:710 Token Replacer: searching for portrait for portrait_giant_beetle_%284hd%29
Here's an export of my console log from which the above code blocks were taken: 202204281019-token_replacer-parenthesis.log
cachedTokens
will contain %20
but tokenCheck
will contain a space character
.
My suggestion on this would be to ignore folder names. Cache only file names and remove the CR check.
After that, match purely in Actor name VS File name.
The only situation I'd see this becoming an issue would be if there's two monsters with the same name in two different CRs. I know that for 5e this isn't possible as every monster has a unique name.
EDIT: The default Forgotten-Adventures token folder name for Patreon is Tokens (Patreon)
. Renaming to Tokens_Patreon
resolved my issue.
EDIT2: Due to the indexOf
check, this could be an issue if there's a CR 1 creature named "Goblin" and a CR 2 creature named "Goblin Archer". By adding a "Goblin" token, both creatures would be matched as they both contain the string "Goblin".
This is subjective, but my opinion is that CR shouldn't be the differenciating factor as you could have the same problem if both had the same CR. A more strict check than indexOf
would allow clearer matching. Perhaps allow users to configure their name convention for tokens?
e.g. ${data.name}_${data.data.traits.size}_${data.data.details.type}
This might be too flexible and complex though.
When I try to save the options after I removed the "cr" from the Field for "NPC Difficulty name", I get this error and it does not save.
TypeError: Assignment to constant variable.
at TokenReplacerSetup._updateObject (token-replacer.js:68)
at TokenReplacerSetup._onSubmit (foundry.js:5251)
In row 68 the code tries to change "diffVariable", but that is a constant.
Hello! I want to use this extension with Forgotten Adventures' amazing collection of token.
I downloaded the entire Google Drive (the Patreon one, but you can see the free version here).
Token Replacer can support the sub-folder naming convention using the value CR_
but Forgotten-Adventures' naming convention appends the creature size and type to the file name.
i.e. For an "Animated Armor", Token Replacer expects Animated_Armor_01.png
but FA's file name is Animated_Armor_Medium_Construct_01.png
Could the plugin support mort flexible naming convention (or perhaps fuzzy matching?)
An option to force closest match and not randomize a variant token for subsequent drags past the first would be nice.
CR/Type matching doesn't really help when dealing with colour variants having minorly different stat blocks sadly.
My Folders are prenamed CR_1⁄4 ... but that doesn't seem to work quite.
I wasn't able to find out what folder name to use instead, as /
is not supported in folder names.
Thank you in advance!
Waldleufer
Currently the token folder is generated by the module below the module install folder. This causes problems like #21, and also is "unfortunate" in hosted environments like in forge-vtt.com, where there is a better separation between module data and user assets.
Thus I would propose to add a configurable option that allows users to define the token path. Default could be to the current directory to not break things for existing users.
I managed to get it working fine for CR1 creatures but not for CR1/4, which I assume is the cr0_25
folder (I tried all of the CR0 folders, nothing works)
See the following exception thrown.
Uncaught (in promise) TypeError: token.update is not a function
[Detected 1 package: token-replacer]
at preCreateTokenHook (token-replacer.js:466:23)
While some may find the shuffle feature useful, I find that it causes more trouble than help. I would love if when I bring in an actor that it finds the best match for the token and then stays static. Another solution is just to be able to turn off token replacer on individual actors so you can pick one image and avoid having it replace the chosen images.
Thank you for your hard work on this module. It's a real time saver.
Trying to install through foundry and get this error "installation failed: k is not defined"
Tried to use the .json link directly and got a similar one : "installation failed: the request to https://github.com/vtt-lair/token-replacer/blob/main/module.json did not provide a valid manifest file."
Using foundry version 0.8.7
I'm 99% sure I got all my settings right... Links go to IMGUR
Ideally in the elipses menu, allow the option to disable / enable this plugin for a given actor. There are times when the default is a better option, times when it's not, so having both options would make this a much more useful tool. Also this would also solve #90.
When I don’t have the box checked for separate dialogues for actor and token, when I select a token from the single prompt, it only affects the actor not the default token. I think it should change both right?
When using on The Forge, the Token Directory gives an error: 'Directory does not exist or is not accessible in this storage location.'
Hello.
I'll provide this in an structured format:
Allow some sort of presets which can be added or removed to the TR's module settings, which customize the settings according to the user's interests of a content pack (such as FA and several others), including self-made ones. This would allow users to define their own presets or content creators to provide their supporters with a configuration file that allows them to seamlessly configure vanilla tokens to be replaced with their provided art tokens.
FVTT users, content creators and content creators' supporters.
The TR's settings interface would have a dropdown menu added with one option available -Default-, and five buttons (Save, Add, Remove, Import, Export). The person would then configure their TR settings as usual. After configuring, they would have the option to 'Save' -overwrite- their current settings in the selected Preset, 'Add' them as another Preset configuration, 'Remove' the current preset -Default cannot be removed-, 'Rename' their preset, 'Import a Config' and 'Export a Config' (the import config option wouldn't overwrite, but rather import with the preset name as it was exported).
These configs could be provided as a .json file, as a .json syntax in a field (which users can copy from) or any other manageable format, and the import/export dialogs could reflect the chosen method.
Through community effort, people -especially those with interest in supporting the content creator community- (o cc themselves) could make unofficial configs (with the potential of it being branded as an official preset by the content creator).
By changing the preset option, you could switch the config thus adapting your TR behaviour to the content pack you're interested in at the moment (perhaps due to the token/s being imported atm). The behavior would be the same as always when there's no matching token name.
I recorded a video of the issue: https://www.dropbox.com/s/vsm20ksxvk2dscl/Screen%20Recording%202021-05-02%20at%208.15.39%20PM.mov?dl=0
Note. I am not using the CR feature and this is in the Pathfinder 2 system.
Expected Behavior:
I have two files, Augrael.png & p_Augrael.png
I drag the token out, Augrael.png is set to the Token Image & p_Augrael.png is set to the portrait.
Actual Behavior:
When 'Use NPC Difficulty Folder Structure' is checked:
I drag the token out, Augrael.png is set to the token image, the portrait is not set.
When 'Use NPC Difficulty Folder Structure' is unchecked:
I drag the token out, p_Augrael.png is set to the token image (the file meant for the portrait), the portrait is not set.
Also, when 'Use NPC Difficulty Folder Structure' is unchecked and attempting to change the settings, I get this console error:
foundry.js:5253 TypeError: Cannot set property 'selected' of undefined
at TokenReplacerSetup._updateObject (token-replacer.js:129)
at TokenReplacerSetup._onSubmit (foundry.js:5251)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.