bugfix for discarding from hands

This commit is contained in:
Chr1Z93 2023-10-18 00:04:31 +02:00
parent b1e754bc09
commit 039488d48b

View File

@ -245,39 +245,37 @@ 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)
-- continue if the card stops smooth moving
Wait.condition(
function()
obj.use_hands = true
-- this avoids a TTS bug that merges unrelated cards that are not resting -- this avoids a TTS bug that merges unrelated cards that are not resting
if deck then if #searchResult == 1 then
Wait.time(function() deck.putObject(obj) end, 0.3) searchResult[1].putObject(obj)
elseif card then
Wait.time(function() obj.setPosition(newPos) end, 0.3)
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)