Saagael
February 10th, 2023, 15:43
In an extension I'm working on I'm trying to implement behavior wherein a user double-clicks on a token, and that token toggles between two different tokens images. To do this, I'm trying to create a brand new token with the same scaling and orientation as the original, then delete the original so that I'm left with the new token. However! I'm encounter two different (but possibly related) issues that might be bugs. They might also be me doing something wrong, but they definitely feel like bugs. Also, this is all the LIVE branch.
Attached to this post is a gif of the two issues on display. Below is the function I'm using to create do the work, with the relevant part in the middle bolded. Lastly, these tokens are not mapped to actors on the CT so I can't use the ct entry's space property to resize.
function flipCardOnTable(token, image, cardnode, sIdentity)
_bFlipping = true;
-- First update the node backing the token
CardsManager.flipCardFacing(cardnode, sIdentity, {})
local sNewToken = CardsManager.getCardFacingImage(cardnode);
local x, y = token.getPosition();
local newToken = Token.addToken(DB.getPath(token.getContainerNode() ), sNewToken, x, y);
local nScale = token.getScale();
newToken.setScale(nScale)
Debug.chat('old scale: ' .. nScale)
Debug.chat('new scale: ' .. newToken.getScale())
newToken.setOrientation(token.getOrientation());
CardTable.updateTokenName(cardnode, newToken);
token.delete();
CardTable.setCardTokenId(cardnode, newToken.getId());
_bFlipping = false;
end
The first bit of weird is that whenever the new token is created it is automatically scaled down by a factor of 1.414. At first I thought this was because some other handler was detecting a new token and applying a scale to it. But this happens when I turn off the game option to automatically scale tokens. It happens when I override TokenManager.autoTokenScale so it does nothing. I even opened up CoreRPG, commented out TokenManager.autoTokenScale, and yet the created tokens still get scaled down. I have no idea what's doing this scaling, but it feels like it shouldn't be happening.
The attached gif is me double-clicking on a token consecutively to 'flip' between a card being face and face down on an image. Every time the new token comes in, it's smaller than the original.
This is where the second bit of weird comes in. In the script you can see I've put two Debug statements to display the old token's scale as well as the new token's scale. When I create the new token, the new scale is always set to 1, no matter what the old token's scale is set at. In the gif you can see this. Every time the new token comes in, getScale() reports that its scale is 1, but the old token's scale is correctly reported at whatever it actually was. This makes me think that something in setScale() isn't hooked up quite correctly, but I can't say for sure.
56141
Attached to this post is a gif of the two issues on display. Below is the function I'm using to create do the work, with the relevant part in the middle bolded. Lastly, these tokens are not mapped to actors on the CT so I can't use the ct entry's space property to resize.
function flipCardOnTable(token, image, cardnode, sIdentity)
_bFlipping = true;
-- First update the node backing the token
CardsManager.flipCardFacing(cardnode, sIdentity, {})
local sNewToken = CardsManager.getCardFacingImage(cardnode);
local x, y = token.getPosition();
local newToken = Token.addToken(DB.getPath(token.getContainerNode() ), sNewToken, x, y);
local nScale = token.getScale();
newToken.setScale(nScale)
Debug.chat('old scale: ' .. nScale)
Debug.chat('new scale: ' .. newToken.getScale())
newToken.setOrientation(token.getOrientation());
CardTable.updateTokenName(cardnode, newToken);
token.delete();
CardTable.setCardTokenId(cardnode, newToken.getId());
_bFlipping = false;
end
The first bit of weird is that whenever the new token is created it is automatically scaled down by a factor of 1.414. At first I thought this was because some other handler was detecting a new token and applying a scale to it. But this happens when I turn off the game option to automatically scale tokens. It happens when I override TokenManager.autoTokenScale so it does nothing. I even opened up CoreRPG, commented out TokenManager.autoTokenScale, and yet the created tokens still get scaled down. I have no idea what's doing this scaling, but it feels like it shouldn't be happening.
The attached gif is me double-clicking on a token consecutively to 'flip' between a card being face and face down on an image. Every time the new token comes in, it's smaller than the original.
This is where the second bit of weird comes in. In the script you can see I've put two Debug statements to display the old token's scale as well as the new token's scale. When I create the new token, the new scale is always set to 1, no matter what the old token's scale is set at. In the gif you can see this. Every time the new token comes in, getScale() reports that its scale is 1, but the old token's scale is correctly reported at whatever it actually was. This makes me think that something in setScale() isn't hooked up quite correctly, but I can't say for sure.
56141