KayelGee / token-attacher

MIT License
12 stars 18 forks source link

[Feature Request] Allow the rider token to be moved as long as it does not leave the area of mount token #67

Closed p4535992 closed 2 years ago

p4535992 commented 2 years ago

Hi, I have developed a small utility module which is based on your module Mountup. In particular as regards the up and drop macros in a token.

I'm banging my head on a problem that I can't solve and I was thinking about analyzing your code to find out if it was possible to add (if it doesn't already exist and I missed it) the possibility that when you link a token A to a token B, not to constrain the coordinates of token A, but to allow it to be moved as long as it does not leave the area of token B.

To make it clear what is the result I want, I'll give you two gifs the first is the current result the second what I would like, that is to be able to move the rider inside the mount.

What i have now. img1 What i want img2

I don't know if it will be useful to you this is the function I use to check if the token is contained within the area of another token.

function riderIsContainedOnMount(riderToken, mountToken) {
  let x = riderToken.x;
  let y = riderToken.y;
  let width = riderToken.w;
  let height = riderToken.h;
  return Number.between(mountToken.x, x, x + width) && Number.between(mountToken.y, y, y + height);
 }
KayelGee commented 2 years ago

You could do it in a kinda roundabout way by detaching the token and then reattaching it at the new location. Although on second thought it's not that easy. You'd need to set options which would prevent TA from blocking the movement, which would only be possilbe if you'd monkey patch the ui drop function. Let me think about it some more.

KayelGee commented 2 years ago

Next update will allow setting a "canMoveConstrained" flag via api. That will allow the attached token to move within their parent(and update the offsets correctly) so when the parent moves afterwards it will keep the new position.