Bugfix for location lines

- Fixes a timing issue which would cause shadow lines to appear when hovering on a snap point
- Fixes a missing nil check that would cause errors during onUpdate if the card had no connections
This commit is contained in:
Buhallin 2023-01-13 11:08:55 -08:00
parent 31006694b8
commit 8ca3ac9247
No known key found for this signature in database
GPG Key ID: DB3C362823852294

View File

@ -136,18 +136,25 @@ function onObjectPickUp(player, object)
local objType = object.name local objType = object.name
if objType ~= "Card" and objType ~= "CardCustom" then return end if objType ~= "Card" and objType ~= "CardCustom" then return end
-- onCollisionExit fires first, so we have to check the card to see if it's a location we should -- onCollisionExit USUALLY fires first, so we have to check the card to see if it's a location we
-- be tracking -- should be tracking
if showLocationLinks() and isInPlayArea(object) and object.getGMNotes() ~= nil and object.getGMNotes() ~= "" then if showLocationLinks() and isInPlayArea(object) and object.getGMNotes() ~= nil and object.getGMNotes() ~= "" then
local pickedUpGuid = object.getGUID() local pickedUpGuid = object.getGUID()
local metadata = JSON.decode(object.getGMNotes()) local metadata = JSON.decode(object.getGMNotes())
if (metadata.type == "Location") then if (metadata.type == "Location") then
-- onCollisionExit sometimes comes 1 frame after onObjectPickUp (rather than before it or in
-- the same frame). This causes a mismatch in the data between dragging the on-table, and
-- that one frame draws connectors on the card which then show up as shadows for snap points.
-- Waiting ensures we always do thing in the expected Exit->PickUp order
Wait.frames(function()
draggingGuids[pickedUpGuid] = metadata draggingGuids[pickedUpGuid] = metadata
rebuildConnectionList() rebuildConnectionList()
end, 2)
end end
end end
end end
function onUpdate() function onUpdate()
-- Due to the frequence of onUpdate calls, ensure that we only process any changes to the -- Due to the frequence of onUpdate calls, ensure that we only process any changes to the
-- connection list once, and only redraw once -- connection list once, and only redraw once
@ -356,7 +363,7 @@ function drawDraggingConnections()
-- Objects should reliably exist at this point, but since this can be called during onUpdate the -- Objects should reliably exist at this point, but since this can be called during onUpdate the
-- object checks are conservative just to make sure. -- object checks are conservative just to make sure.
local origin = getObjectFromGUID(originGuid) local origin = getObjectFromGUID(originGuid)
if draggingGuids[originGuid] and origin != nil then if draggingGuids[originGuid] and origin ~= nil and targetGuids ~= nil then
ownedVectors[originGuid] = { } ownedVectors[originGuid] = { }
for targetGuid, direction in pairs(targetGuids) do for targetGuid, direction in pairs(targetGuids) do
local target = getObjectFromGUID(targetGuid) local target = getObjectFromGUID(targetGuid)