Merge pull request #419 from argonui/discard-fix

Bugfix for discarding from hands
This commit is contained in:
Entrox-Licher 2023-10-20 09:57:52 -04:00 committed by GitHub
commit 97a0e1fe41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -256,39 +256,38 @@ function placeOrMergeIntoDeck(obj, pos, rot)
if not pos then return end if not pos then return end
local offset = 0.5 local offset = 0.5
local deck, card, newPos
-- search the new position for existing card/deck -- search the new position for existing card/deck
local searchResult = searchArea(pos, { 1, 1, 1 }, isCardOrDeck) local searchResult = searchArea(pos, { 1, 1, 1 }, isCardOrDeck)
if #searchResult == 1 then
local match = searchResult[1]
if match.type == 'Card' then
card = match
elseif match.type == 'Deck' then
deck = match
end
end
-- update vertical component of new position -- get new position
if card or deck then local newPos
if #searchResult == 1 then
local bounds = searchResult[1].getBounds() local bounds = searchResult[1].getBounds()
newPos = Vector(pos):setAt("y", bounds.center.y + bounds.size.y / 2 + offset) newPos = Vector(pos):setAt("y", bounds.center.y + bounds.size.y / 2 + offset)
else else
newPos = Vector(pos) + Vector(0, offset, 0) newPos = Vector(pos) + Vector(0, offset, 0)
end end
-- actual movement of the object -- allow moving the objects smoothly out of the hand
obj.use_hands = false
if rot then if rot then
obj.setRotationSmooth(rot, false, true) obj.setRotationSmooth(rot, false, true)
end end
obj.setPositionSmooth(newPos, false, true) obj.setPositionSmooth(newPos, false, true)
-- this avoids a TTS bug that merges unrelated cards that are not resting -- continue if the card stops smooth moving
if deck then Wait.condition(
Wait.time(function() deck.putObject(obj) end, 0.3) function()
elseif card then obj.use_hands = true
Wait.time(function() obj.setPosition(newPos) end, 0.3) -- this avoids a TTS bug that merges unrelated cards that are not resting
end if #searchResult == 1 then
-- call this with avoiding errors (physics is sometimes too fast so the object doesn't exist for the put)
pcall(function() searchResult[1].putObject(obj) end)
end
end,
function() return not obj.isSmoothMoving() end, 3)
end end
-- build a discard button to discard from searchPosition (number must be unique) -- build a discard button to discard from searchPosition (number must be unique)