From a7dcf7c893efefadc673744edd97ae28a54c3831 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 19 Nov 2024 18:58:04 +0100 Subject: [PATCH] code update --- src/core/Global.ttslua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 51bc4cee..cfdffb8a 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2867,7 +2867,7 @@ function moveCardWithTokens(params) -- wait for the card to finish moving, update token position/rotation regularly Wait.condition( - function() cardTokens[card] = nil end, + function() stopTokenTransformUpdating(card) end, function() if card ~= nil and cardTokens[card] ~= nil and #cardTokens[card] ~= 0 then updateTokenTransform(card) @@ -2880,12 +2880,19 @@ function moveCardWithTokens(params) end function storeTokenTransform(card) + if cardTokens[card] ~= nil then + stopTokenTransformUpdating(card) + end + cardTokens[card] = {} local cardRot = card.getRotation() for _, token in ipairs(searchLib.onObject(card, "isTileOrToken", 0.95)) do if not token.locked then - local tokenPos = token.getPosition() + Vector(0, 0.1, 0) -- small offset so tokens don't collide with card + -- offset to stop the token from colliding with the card + local tokenPos = token.getPosition() + Vector(0, 0.01, 0) token.setPosition(tokenPos) + + -- store local transform data table.insert(cardTokens[card], { token = token, localPos = card.positionToLocal(tokenPos), @@ -2899,9 +2906,17 @@ function updateTokenTransform(card) for _, tokenData in ipairs(cardTokens[card] or {}) do tokenData.token.setPosition(card.positionToWorld(tokenData.localPos)) tokenData.token.setRotation(card.getRotation() + tokenData.localRot) + tokenData.token.locked = true end end +function stopTokenTransformUpdating(card) + for _, tokenData in ipairs(cardTokens[card] or {}) do + tokenData.token.locked = false + end + cardTokens[card] = nil +end + -- removes tokens from the provided card/deck function removeTokensFromObject(params) local object = params.object