Giter Site home page Giter Site logo

vtt-lair / token-replacer Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 4.0 21.28 MB

Foundry VTT - Automatically replace NPC actor tokens and/or portraits dependent on token assets saved in a defined folder structure

License: MIT License

JavaScript 79.57% Batchfile 13.40% HTML 7.03%

token-replacer's People

Contributors

etriebe avatar kageru avatar tuirgin avatar vtt-lair avatar vvechkanov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

token-replacer's Issues

One more error message

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.
image

Unhandled exceptions

Currently, there are a few unhandled exceptions your module generates:

image

image

Happens every time I reload Foundry using F5

Save button breaks when enabling debug logging

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).

New release overwrites previous token folders

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.

Token Replacer updating compendium entries

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.

Incompatibility, some bugs and some suggestions :-)

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:

  • The module seems to be incompatible with the Assets Library of The Forge. I can select a folder within the Assets Library as a location for token images, but when I try to import actors an error is thrown

image

  • When I manually create an actor in the actors tab with "replace token and portrait art" enabled, only the portrait art is replaced, the portrait stays at mystery man

image

  • The randomization of tokens seems to not function corectly - out of three available images only two are used

image

  • One feature suggestion: It would be great if token and portrait art could be handled separate from each other, e.g. by using a definable prefix like 'portrait' in the file names. That would allow a DM to put x files for the tokens and one different file for the portrait into the directory and let the module replace both in one step instead of having to manually choose the portrait every time.

image

Replacement not working for actors with multi-word names

Thanks for making this! I love the functionality and I have it partially working, but I'm having a few issues:

  1. My token and portrait replacements function correctly, but only for actors with single-word names (e.g., "Goblin"). For actors with multi-word names (e.g, "Bandit Captain"), no replacements occur and the existing artwork is retained.
  2. I added portrait images to the same image directory, prefacing filenames with "Av_" (avatar) and specifying "Av_" as the portrait preface string. Portraits replacements work (at least for single-word-named actors), but this introduced a new issue: The wildcard token matching also selects the portrait images ("Av_Actor_Name") as matches, so I get a mix of token and portrait art each time I drag an actor token onto a scene.

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.

  • With this option selected, multi-word actor names now match filenames as expected.
  • With this option selected, wildcard matching only applies after the Actor name, thus respecting the profile prefix.
  • Without this option selected, wildcard matching seems to apply before and after the actor name -- thus ignoring the profile prefix and matching those files as well.

Finally, I have a feature suggestion:

  • In order to reduce the need to group tokens by CR, it would be great to have a "strict wildcards" setting available. This setting would still allow wildcard matches, but would restrict them to a specified format to eliminate undesired matches. For example, strict wildcards might only match files of the format Actor Name_## (e.g., "Goblin_01", "Goblin_02", etc.) but would ignore "Goblin Captain." This would eliminate the need to group assets by CR to avoid false matches, while still enabling wildcard matches where desired.
  • Alternatively, a setting to "disable wildcard matching" would also address the CR folder issue, but would be less flexible overall.

Thanks again!

  • Jeff

Names with parenthesis are not matched

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:

  • Giant_Beetle_(4HD).svg

In addition I added a few others when troubleshooting:

  • Giant_Beetle,_4HD.svg
  • Giant_Beetle_[4HD].svg
  • Giant_Beetle_{4HD}.svg

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

Creature matching fails if there's a space in a folder in the path

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.

Cannot save empty "NPC Difficulty name"

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.

Support Forgotten Adventures naming convention

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?)

[Option Request] Ability to disable variant tokens

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.

Allow configurable token folder

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.

Doesn't seem to work for CR 1/4

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)

Failed to call token.update on V9

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)

[Feature Suggestion] Allow Toggling Token Replacer Off for Individual Actors

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.

Allow override for a given actor.

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.

One click for actor and token doesn’t work

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?

[Feature Suggestion] Expose or allow for configuration presets to be imported/exported for content packs

Hello.

I'll provide this in an structured format:

  • Description of the feature

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.

  • Who would use it?

FVTT users, content creators and content creators' supporters.

  • Proposed usage

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.

Can't get Portrait Replacement to work.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.