KayelGee / token-attacher

MIT License
11 stars 18 forks source link

FoundryVTT - Token Attacher

GitHub release (latest SemVer) Forge Installs GitHub Releases GitHub All Releases

[Compatibility]: FoundryVTT v12+ [Systems]: any
[Languages]: English, Korean, Japanese

Attach anything(even other tokens and their attached elements aswell) to tokens, so that they move when the token moves and rotate/move when the token rotates. Resizing the base token will also resize all attached elements.

Baileywiki created a great showcase and tutorial video for the 4.0 release. I recommend it if you're updating from 3.x to 4.0 or if you haven't yet used Token Attacher at all: https://www.youtube.com/watch?v=2i0TX0BS8Vg

Attached elements can no longer be selected via the rectangle selection tool of each layer, unless the attach ui of the base token is open or you use the unlock feature. Attached elements can still be interacted with via double left or right click. Attached elements can no longer move independently of the base token. When dragging an prefab to the canvas the attached tiles will be sorted to the top(but still respect their z order inside the prefab).

To be able to attach measure templates, lights, sounds and journals you need the select-tool-everywhere module, as of writing this there is no select tool in those controls. You can also attach those by using the new all layer select tool in combination with a select tool on a layer like the token layer.

Table of Contents

Macros

A public interface for usage in macros can be accessed via tokenAttacher, following functions can be called:

There are some example macros bundled in a macro compendium.

Also there are some GM only macros in the macro compendium

Simple Macro Example:

(async () => {
const some_element = canvas.tiles.children[0].children[0];
const some_token = canvas.tokens.children[0].children[0];
await tokenAttacher.attachElementToToken(some_element, some_token, true);

const all_attached = await tokenAttacher.getAllAttachedElementsOfToken(some_token);
const all_attached_tiles = await tokenAttacher.getAllAttachedElementsByTypeOfToken(some_token, "Tile");
console.log(all_attached);
console.log(all_attached_tiles);
console.log(canvas.tiles.get(all_attached_tiles[0]));
})();

Known Issues

Installation

  1. token-attacher using manifest URL: https://raw.githubusercontent.com/KayelGee/token-attacher/master/module.json
  2. While loaded in World, enable Token Attacher module.

Usage

Open attach UI

Select a token and open the attaching UI.

Attach or detach element

Attach or detach an element by selecting it and pressing the attach or detach button.

Attach with multi layer selection tool

Attach elements on multiple layer with the rectangle select tool.

Detach all elements

Detach all elements by clicking the detach all button.

Enable selection of attached element

Enable selection of an attached element by selecting the element and then pressing the unlock button. To prevent the selection again use the lock button.

Highlight attached elements

Highlight your attached elements by pressing the highlight button.

Copy and paste attached elements from one base to another

Copy and paste all attached elements by pressing the copy button on the source token and the paste button on the target token.

Quickly reposition attached element with Quick Edit Mode

Quickly reposition attached elements without opening the attachment ui by clicking the Quick Edit Button, move attachments and then finish by clicking the Quick Edit Button again.

Make a prefab

Make a prefab by adding a token with attached elements to the prototype Token of an Actor. The grid size of the current scene will be saved to the prefab, so when you drag the prefab out on a scene with a different grid size it will resize accordingly.

Export compendiums with prefabs

Export compendiums with prefabs. Copy the resulting json into a .json file. To see how to auto import compendiums(so that this works between systems) in your module see my example module: https://github.com/KayelGee/token-attacher-compendium-example

Resize base and children

Resize the whole chain by resizing the base token.

Automatic resizing on different grid size

Auto resizing when the grid size differs from what the prefab was saved with.

Allow movement in base token area

Enable canMoveConstrained flag with API call to setElementsMoveConstrainedStatus(see Mount Up! macro), then move the token freely within the area of the base token.

Contact

If you wish to contact me for any reason, reach me out on Discord using my tag: KayelGee#5241

Credits

Korean translation provided by KLO

Japanese translation provided by touge