manuelVo / foundryvtt-drag-ruler

A Foundry VTT module that shows a ruler when dragging tokens so you can see how far you've dragged them
MIT License
40 stars 55 forks source link

Feature Request: Add API for recover the unit and grid distance calculated from this module #180

Closed p4535992 closed 2 years ago

p4535992 commented 2 years ago

Why am I asking for this feature? Let's start with the condition that practically everyone uses drag rulers, there are a lot of modules that use distance calculation mechanisms on their own Arsm Reach, Item Piles, Levels, Innocenti Item loot and many other.

There is literally a logic of "each for himself", this has created several problems (for me at least with Arms reach to meet certain requests) for compatibility between modules, also I am not smart enough to do the work you did with pathfinding, difficult terrain, elevation control, etc.

To try to synchronize all these modules with each other, is it possible to give the possibility via API to reuse the calculation of units and grids carried out by Drag Ruler? Something like this:

dragRuler.getDistanceUnits(token, {x,y}) => number of unit distance e.g. 15 ft. dragRuler.getDistanceGrids(token, {x,y}) => number of grid distance e.g. 3

manuelVo commented 2 years ago

APIs similar to the ones you're suggesting are already available: Native Foundryvtt offers canvas.grid.grid.measureDistances to measure a unit distance from point x to point y (without accounting for difficult terrain). If you're interested in measuring unit distances form point x to point y with difficult terrian, the Terrain Ruler module is offering an API for that: terrainRuler.measureDistances.

If neither of those APIs fits your requirements, please let me know what precisely you need, so we can work out where to add which API (if, for example, you'd need access to Drag Ruler's Pathfinding capabilities, I'd rather move the pathfinding logic into a separate library than adding an API for that directly into Drag Ruler).

p4535992 commented 2 years ago

My idea was to use the Drag ruler itself as a library as a multisystem api to handle terrain rulers, pathfinding, etc. from the same "access point", so that different modules agree on calculating distances with the same "procedure". Foundry's default method works, but sometimes it doesn't take into account some things. But now I've realized that nobody's interested in it (apart from me), so you can close the ticket if you don't come up with brilliant ideas.

manuelVo commented 2 years ago

I absolutely agree that the functionality should be available via a commonly used API. There's no use in everyone re-implementing everything for themselves over and over again. However, I don't think that Drag Ruler itself should be used as a library module. It modifies foundry too heavily and adds features that some people might not use. Instead, I think that common functionality should be moved into a separate library module that could then be used by Drag Ruler and others.

This is why I'm asking about your specific needs. Extracting functionality into a library module isn't trivial and should be done with care with a well-designed API, so the library can be as useful as possible to as many people as possible, without cluttering the module list with library modules that nobody ends up using. So please let me know the specific tasks you'd like your module to achieve (using functionality that's currently present in drag ruler) an we can work on a solution :)

manuelVo commented 2 years ago

It took quite a while, but the Drag Ruler pathfinder is finally extracted into a dedicated library module: routinglib. If you're still interested in adding pathfinding to your module it should now be quite easy to grab routinglib as a (soft) dependency and just invoke its API to get a path calculated.

Are there any outstanding APIs that you were needing, or can I close this issue?

p4535992 commented 2 years ago

sure sorry totally forgot about this.... ty for the hard work . I'll chek out this week end ^^