Skip to content
M. Vaitkus edited this page Aug 15, 2023 · 4 revisions

API can be accessed via: game.modules.get('token-variants').api

showArtSelect(search, options)

Displays the art select window.

Parameters:

  • {string} search The text to be used as the search criteria

  • {object} Options which customize the search

    • {Function[]} [callback] Function to be called with the user selected image path
    • {SEARCH_TYPE|string} [searchType] Controls filters applied to the search results
    • {object} [options.searchOptions] Override for the Search Algorithm. See searchOptions
    • {Token|Actor} [object] Token/Actor used when displaying Custom Token Config prompt
    • {boolean} [options.force] If true will always override the current Art Select window if one exists instead of adding it to the queue

e.g.

  • game.modules.get('token-variants').api.showArtSelect("")
  • game.modules.get('token-variants').api.showArtSelect("dragon", \{callback: (selectedImg) => console.log(selectedImg)\})

doImageSearch(search, options)

Performs an image search and returns the results.

Parameters:

  • {string} search: Text to be used as the search criteria
  • {object} Options which customize the search
    • {SEARCH_TYPE|string} [options.searchType] Controls filters applied to the search results
    • {Boolean} [options.simpleResults] Results will be returned as an array of all image paths found
    • {Boolean} [options.callback] Function to be called with the found images
    • {object} [options.searchOptions] See searchOptions
  • returns: {Promise<Map<string, Array<object>|Array<string>>} Images found

e.g.

  • game.modules.get('token-variants').api.doImageSearch("Dragon")
  • game.modules.get('token-variants').api.doImageSearch("Dragon", {simpleResults: true})

doRandomSearch(search, options)

Performs a random image search and returns the results.

Parameters:

  • {string} search: Text to be used as the search criteria
  • {object} Options which customize the search
    • {SEARCH_TYPE|string} [options.searchType] Controls filters applied to the search results
    • {Actor} [options.actor] Used to retrieve 'shared' images from if enabled in the Randomizer Settings
    • {Function[]} [options.callback] Function to be called with the random image
    • {object} [options.searchOptions] See searchOptions
    • {object} [options.randomizerOptions] Override randomizer settings (these take precedence over searchOptions). See Randomizer
    • {Boolean} [options.randomizerOptions.tokenName] Should a full name search be performed
    • {Boolean} [options.randomizerOptions.keywords] Should a keyword search be performed
    • {Boolean} [options.randomizerOptions.shared] Should shared images be included in the search
  • returns: {Array|null} Image path and name

e.g.

  • game.modules.get('token-variants').api.doRandomSearch("Goblin")
  • game.modules.get('token-variants').api.doRandomSearch("Goblin", \{callback: (result) => console.log(result)\})

updateTokenImage(imgSrc, options)

Updates token image applying custom configuration if one exists.

  • {string} imgSrc: Image source path/url
  • {object} Update options
    • {Token} [token] Token to be updated with the new image
    • {Actor} [actor] Actor with Proto Token to be updated with the new image
    • {String} [imgName] Image name if it differs from the file name. Relevant for URLs or Rolltable sourced images.
    • {object} [config] Token Configuration to be applied to the token (e.g. scale, dimSight). This configuration will be removed upon next updateTokenImage call if config is not provided and no attached config exists for the imgSrc

e.g.

  • game.modules.get('token-variants').api.updateTokenImage("tokenImages/dragon/RedDragon.jpg", {token: canvas.tokens.controlled[0]});

{object} searchOptions

{object} algorithm

See Algorithm settings

  • {Boolean}[algorithm.exact] Exact type search
  • {Boolean}[algorithm.fuzzy] Fuzzy type search
  • {Integer}[algorithm.fuzzyLimit] >1 Limits numbers of results
  • {Float}[algorithm.fuzzyThreshold] 0.0-1.0 Match strength, 0.0 for exact match, 1.0 for loose match
  • {Boolean}[algorithm.fuzzyArtSelectPercentSlider] Should the Art Select include a percent slider

{object} searchFilters

See Search Filter settings

  • {String} [searchFilters.portraitFilterInclude]
  • {String} [searchFilters.portraitFilterExclude]
  • {String} [searchFilters.portraitFilterRegex]
  • {String} [searchFilters.tokenFilterInclude]
  • {String} [searchFilters.tokenFilterExclude]
  • {String} [searchFilters.tokenFilterRegex]
  • {String} [searchFilters.generalFilterInclude]
  • {String} [searchFilters.generalFilterExclude]
  • {String} [searchFilters.generalFilterRegex]

cacheImages()

When called will trigger the refresh of the image cache.

e.g. game.modules.get('token-variants').api.cacheImages()

TVA_CONFIG

Object containing currently active settings

e.g. game.modules.get('token-variants').api.TVA_CONFIG

assignUserSpecificImage(token, img, options)

Assign a token image to be displayed to specific users.

Parameters:

  • {Token} token token the image is to be applied to
  • {String} img image to be displayed, if no image is provided unassignUserSpecificImage(...) will be called
  • {object} Options
    • {String|String[]} [userName] name of the user that the image is to be displayed to
    • {String|String[]} [userId] id of the user that the image is to be displayed to

assignUserSpecificImageToSelected(img, options)

Calls assignUserSpecificImage(...) passing in all currently selected tokens.

Parameters:

  • {String} img image to be displayed
  • {object} Options
    • {String|String[]} [userName] name of the user that the image is to be displayed to
    • {String|String[]} [userId] id of the user that the image is to be displayed to

unassignUserSpecificImage(token, options)

Un-assign a token image set via assignUserSpecificImage(...)

Parameters:

  • {Token} token token the image is to be removed from
  • {object} Options
    • {String|String[]} [userName] name of the user that the image is to be removed for
    • {String|String[]} [userId] id of the user that the image is to be removed for

unassignUserSpecificImageFromSelected(options)

Calls unassignUserSpecificImage(...) passing in all currently selected tokens.

Parameters:

  • {object} Options
    • {String|String[]} [userName] name of the user that the image is to be removed for
    • {String|String[]} [userId] id of the user that the image is to be removed for

Clone this wiki locally