Clear vector lines from cards when they're not being dragged

The events which can indicate a drag stop are varied:
- Drag a card into another on the table (tryObjectEnterContainer)
- Drag multiple cards into another on the table (onCollisionEnter, tryObjectEnterContainer)
- Group multiple cards while holding them (tryObjectEnterContainer)
This commit is contained in:
Buhallin 2023-01-11 13:42:58 -08:00
parent 6b52e412e9
commit e6854801fb
No known key found for this signature in database
GPG Key ID: DB3C362823852294
3 changed files with 35 additions and 3 deletions

View File

@ -184,6 +184,14 @@ function onObjectSearchEnd(object, playerColor)
end
end
-- Pass object enter container events to the PlayArea to clear vector lines from dragged cards.
-- This requires the try method as cards won't exist any more after they enter a deck, so the lines
-- can't be cleared.
function tryObjectEnterContainer(container, object)
playAreaAPI.tryObjectEnterContainer(container, object)
return true
end
function drawEncountercard(params)
local position = params[1]
local rotation = params[2]

View File

@ -103,7 +103,12 @@ function onCollisionEnter(collisionInfo)
if shouldSpawnTokens(card) then
tokenManager.spawnForCard(card)
end
draggingGuids[card.getGUID()] = nil
-- If this card was being dragged, clear the dragging connections. A multi-drag/drop may send
-- the dropped card immediately into a deck, so this has to be done here
if draggingGuids[card.getGUID()] ~= nil then
card.setVectorLines(nil)
draggingGuids[card.getGUID()] = nil
end
maybeTrackLocation(card)
end
@ -202,6 +207,18 @@ function maybeUntrackLocation(card)
end
end
-- Global event handler, delegated from Global. Clears any connection lines from dragged cards
-- before they are destroyed by entering a deck. Removal of the card from the dragging list will
-- be handled during the next onUpdate() call.
function tryObjectEnterContainer(params)
for draggedGuid, _ in pairs(draggingGuids) do
local draggedObj = getObjectFromGUID(draggedGuid)
if draggedObj ~= nil then
draggedObj.setVectorLines(nil)
end
end
end
-- Builds a list of GUID to GUID connection information based on the currently tracked locations.
-- This will update the connection information and store it in the locationConnections data member,
-- but does not draw those connections. This should often be followed by a call to

View File

@ -48,5 +48,12 @@ do
getObjectFromGUID(PLAY_AREA_GUID).call("setLimitSnapsByType", matchCardTypes)
end
-- Receiver for the Global tryObjectEnterContainer event. Used to clear vector lines from dragged
-- cards before they're destroyed by entering the container
PlayAreaApi.tryObjectEnterContainer = function(container, object)
getObjectFromGUID(PLAY_AREA_GUID).call("tryObjectEnterContainer",
{ container = container, object = object })
end
return PlayAreaApi
end