STAR TREK 2d20
Page 2 of 8 First 1234 ... Last
  1. #11
    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

  2. #12
    Quote Originally Posted by Moon Wizard View Post
    imagecontrol
    getTokensWithinDistance(token/{x=#,y=#}, #) -> (table of tokens)
    getDistanceBetween(token/{x=#,y=#}, token/{x=#,y=#}) -> (number/nil)

    Token
    getTokensWithinDistance(token, #) -> (table of tokens)
    getDistanceBetween(token, token) -> (number/nil)
    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
    Quote Originally Posted by Moon Wizard View Post
    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.
    Understood, thanks for the insight and consideration for this.
    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.
    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.

  3. #13
    Quote Originally Posted by Moon Wizard View Post
    Just to clarify, there is a very specific format that the encoding supports for Lua tables in order to allow bi-directional translation of data. It's not meant (at least at this point) to be some sort of general purpose convert "any" Lua table to XML. It could be something to enhance later.

    Within the table, all XML child tags are referred to by number indicating their child sibling order pointing to a table that must include a "name" variable. This is the XML "tag". You can also specify an "attr" table for the tag, as well a numerical children. This is to deal with the fact that XML child tags can have the same name; mirrors the format used for controls to access XML tags; and matches up with a common Lua library used for XML processing.

    Here's an example:
    That would make importing XML really easy. Nice!
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    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.

  4. #14
    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

  5. #15
    Quote Originally Posted by Moon Wizard View Post
    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
    Understood, I'll comment out the usage for now, thanks for the new features!
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    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.

  6. #16
    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.

  7. #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

  8. #18
    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.

  9. #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,
    MBM
    Ruleset and much more content built for FGU.
    Come join me on Twitter at: https://twitter.com/MadBeardMan to see what I'm up to!

  10. #20
    LordEntrails's Avatar
    Join Date
    May 2015
    Location
    -7 UTC
    Posts
    17,153
    Blog Entries
    9
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in