RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
801 stars 262 forks source link

Make tokens more closely follow their leader #4817

Closed kwvanderlinde closed 5 months ago

kwvanderlinde commented 5 months ago

Identify the Bug or Feature request

Fixes #4813

Description of the Change

Bug fix

A new approach is taken for deriving follower paths from leader paths. The general idea is that the waypoints in the follower path should follow the waypoints of the leader path, regardless of which tokens are STG or not. In most cases this is exact, but in the case of a STG token following a non-STG leader the waypoints are snapped to grid cells after being calculated. When both tokens are STG or both are not, the follower path will precisely follow the leader path even between waypoints (so pathfinding is accounted for). In the other cases, only the waypoints are considered, and intervening points may be interpolated.

Refactoring

There is a supporting refactor to Path to make the above idea solid. Path now has an invariant that makes sure the waypoint list and cell list make sense together:

  1. if either list is empty, both are empty
  2. if not empty, the lists have the same first and last point.
  3. All waypoints are guaranteed to appear in the cell list in the same order, but possibly with extra cells interposed.

To do this, callers are only allowed to append to the path, not otherwise modify it. And they no longer add cells and waypoints separately. Instead they can either:

  1. Append a single point to be treated as both cell and waypoint.
  2. Append a partial path whose last point is treated as a waypoint.

Only SelectionSet and MeasureTool really had a problem with that, and specifically for gridless paths. They were easily fixed by having them handle their own current point instead of hijacking the Path to do it for them.

New unit tests are included that fully cover Path aside from readResolve().

Possible Drawbacks

Serialized paths will not obey the new rules. This shouldn't really be an issue, but it does mean that if a user loads up an campaign, hit "Show Path" on a follower token, the paths they see won't match what they see if they tried the same drag that produced it originally.

Documentation Notes

Follower tokens try to follow the leader token as closely as possible when dragging.

Release Notes


This change is Reviewable