Thread: Experimental APIs for FGU
-
January 27th, 2021, 21:22 #11
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,668
Unity does not have a native JSON encoder/decoder. It has a very special purpose JSON->screen object decoder, which requires a prefab that exactly matches the JSON to work. So, it can't be used for general purpose arbitrary JSON encoding/decoding. I actually looked at this very specifically for you.
My plan is to eventually add encode/decode JSON. However, it requires adding a complete library just to support a single set of APIs; so I'd like to sound out the rest first.
Regards,
JPG
-
January 27th, 2021, 21:25 #12
I did some testing with these and noticed that the values are not "between tokens" but "center of token -> center of other token". Between (IMO) would be from sourceToken edge to targetToken edge.
The target mechanic (which is fine) on tokens does the same so you can visually see what I mean.
I thought the functions would return 5 ft, not 10 ft. The Token.getDistanceBetween function output 10, not 5, in the above situation.
This is the function I use to get the "actual" distance between tokens.
The TLDR is you have to subtract the "tokensize" space out of the calculation.... IF you're wanting to get what I would call "between".
Regardless I can use this function to replace some of my code for the basic calculations and adjust for tokensize on my own.
Code:--[[ This will get the distance BETWEEN these 2 tokens. getTokenDistance(source,target); ]] function getTokenDistanceBetween(tokenSource,tokenTarget) local bValidDistance = true; local nDistanceBetween = 0; local nGridSize = 0; local yOffset = 0; local xOffset = 0; local imageSource = ImageManager.getImageControl(tokenSource); local imageTarget = ImageManager.getImageControl(tokenTarget); if tokenSource ~= tokenTarget and imageSource and imageTarget and imageSource == imageTarget and imageSource.hasGrid() then local xSource,ySource = tokenSource.getPosition(); local xTarget,yTarget = tokenTarget.getPosition(); nGridSize = imageSource.getGridSize(); local nMapUnitSize = 10; if UtilityManager.isClientFGU() then nMapUnitSize = imageSource.getDistanceBaseUnits() or 10; else nMapUnitSize = imageSource.getUnitControlValue() or 10; end xOffset,yOffset = imageSource.getGridOffset(); local xGridSource = (xSource + xOffset) / nGridSize; local yGridSource = (ySource + yOffset) / nGridSize; local xGridTarget = (xTarget + xOffset) / nGridSize; local yGridTarget = (yTarget + yOffset) / nGridSize; local nX = math.abs(xGridTarget - xGridSource); local nY = math.abs(yGridTarget - yGridSource); local nDistance = math.sqrt((nX * nX) + (nY * nY)); local nodeSourceCT = CombatManager.getCTFromToken(tokenSource); local nSourceSpace = DB.getValue(nodeSourceCT,"space",nMapUnitSize)/nMapUnitSize; local nSourceSize = ((nSourceSpace)*nMapUnitSize)/(2*nSourceSpace); local nodeTargetCT = CombatManager.getCTFromToken(tokenTarget); local nTargetSpace = DB.getValue(nodeTargetCT,"space",nMapUnitSize)/nMapUnitSize; local nTargetSize = ((nTargetSpace)*nMapUnitSize)/(2*nTargetSpace); nDistanceBetween = math.floor((nMapUnitSize * nDistance) - (nSourceSize + nTargetSize)); else -- target and source not in same image -- or source == target -- or no grid on map bValidDistance = false; end -- Debug.console("manager_token_adnd.lua","getTokenDistanceBetween","nDistanceBetween",nDistanceBetween) -- local nAPIDistanceBetween = Token.getDistanceBetween(tokenSource, tokenTarget); -- Debug.console("manager_token_adnd.lua","getTokenDistanceBetween","nAPIDistanceBetween",nAPIDistanceBetween) return nDistanceBetween,bValidDistance; end
Last edited by celestian; January 27th, 2021 at 21:28.
---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
January 27th, 2021, 21:30 #13---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
January 27th, 2021, 22:19 #14
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,668
I'll need to look at your token distance feedback in more detail while reviewing the code. I see what you're saying; and I think I agree that the "distance" values returned and tokens within distance should factor in token grid size. I wouldn't incorporate the APIs yet until I get a chance to make that determination; since I'll probably change the way they work to match. I definitely appreciate you taking a look.
Regards,
JPG
-
January 27th, 2021, 22:41 #15---
Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
Documentation for AD&D 2E ruleset FGU Reference Module, or Web.
Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.
-
January 27th, 2021, 22:50 #16
- Join Date
- Apr 2011
- Posts
- 2,260
Thanks for adding the distance calculations between tokens. I haven't had a chance to test it yet but I saw the same issues as celestian when I was implementing range calculations in the RMC ruleset when comparing to the targeting distance lines. The issue is much easier to see when you put larger opponents next to smaller ones and ones that are the same size. Basically range increases especially on the diagonal measurements.
-
January 28th, 2021, 02:47 #17
For the distance functions, I wonder if there is a difference in interpretation based on the ruleset. Looking at the image Celestian provided, 10 ft. would be the expected distance in a 5e game. Scaling through the 5e standard NPC sizes, Medium, Large, Huge, and using the 5 foot grid, the expected ranges would look like this
For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e
-
January 28th, 2021, 04:01 #18
- Join Date
- Apr 2011
- Posts
- 2,260
The issue that I encountered was those distances weren't consistent with different sized tokens because like celestian I noticed that FG is measuring to a distance into the squares you are showing. It became an issue because even if it was adjacent to the larger token at the corners the distance would be greater than it was from 2 medium size tokens.
-
January 28th, 2021, 23:51 #19
Just to throw my oar in, the distance between tokens, I'd like the idea we can have the distance with/without tokens sizes, for example I could use the 10ft as shown to know a character is within the blast range of a grenade in Traveller as that feels fairer than being 5 fit away, and just to throw a difference in, Traveller tends to use hexes, so I think it's fair middle of base -> middle of base.
Cheers,
MBMRuleset and much more content built for FGU.
Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!
-
January 29th, 2021, 02:52 #20
I would think center to center and then a token size attribute would be more flexible. It would then let the calculation be left up to the ruleset. Don't forget, their is the whole diagonal distance calulation things that is ruleset and rule option specific.
Problems? See; How to Report Issues, Bugs & Problems
On Licensing & Distributing Community Content
Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
Note, I am not a SmiteWorks employee or representative, I'm just a user like you.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks