PDA

View Full Version : Exact scale formula for token+image control in respect to grid.



Ken L
April 27th, 2018, 22:02
- resolved -

YAKO SOMEDAKY
April 27th, 2018, 22:14
So what's the formula?
Is there any way to make horse type creatures like 2 hexagons?

Ken L
April 27th, 2018, 22:50
Oddly, there is none. There's some black box code after some logic that simply sets a global script value, then undoes it. All that you need to provide is the number of grid units of space you want the token to occupy.

scripts/manager_token.lua


function setDragTokenUnits(nUnits)
nTokenDragUnits = nUnits;
end
function endDragTokenWithUnits()
nTokenDragUnits = nil;
end


campaign/scripts/image.lua @onDrop(x, y, draginfo)


-- Add it to the image at the drop coordinates
TokenManager.setDragTokenUnits(DB.getValue(v.getDa tabaseNode(), "space"));
local tokenMap = addToken(tokenproto, x, y);
TokenManager.endDragTokenWithUnits();

https://www.reactiongifs.com/r/mgc.gif

Moon Wizard
April 28th, 2018, 05:41
Lol, totally magic.

The TokenManager.autoTokenScale function will calculate the size that the token should be based on these pieces of information:
* Image grid size
* Image tokenscale (image to token scale factor on a pixel basis)
* Token size (in pixels)
* Desired number of spaces (usually 1 by default, but can be larger by ruleset (Large, Huge, Gargantuan, etc.))

Based on these pieces of information the desired token scale is calculated as:
* DesiredTokenScale = min((Spaces * ImageGridSize * ImageTokenScale) / TokenWidth, (Spaces * ImageGridSize * ImageTokenScale) / TokenHeight)

There can be cases where the image token scale is not set already (first time image is used with tokens), and the token scale must be set in order to perform token scaling.

The ImageTokenScale sets the relative pixel ratios between the image pixels and the token pixels.
The IndividualTokenScale is a straight multiplier applied to the TokenHeight and TokenWidth.

Regards,
JPG

Ken L
April 28th, 2018, 05:59
I missed the autoTokenScale call apparently. I was looking for a quick fix and I just replicated behavior as my game was coming up. Just checked and all the ducks line up.