From e6854801fb838df522ff4bc2943be44c61412c4a Mon Sep 17 00:00:00 2001 From: Buhallin Date: Wed, 11 Jan 2023 13:42:58 -0800 Subject: [PATCH] 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) --- src/core/Global.ttslua | 10 +++++++++- src/core/PlayArea.ttslua | 19 ++++++++++++++++++- src/core/PlayAreaApi.ttslua | 9 ++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 6ede2b21..abac3231 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -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] @@ -875,7 +883,7 @@ function applyOptionPanelChange(id, state) -- option: Show CYOA campaign guides elseif id == "showCYOA" then optionPanel[id] = spawnOrRemoveHelper(state, "CYOA Campaign Guides", {65, 1.6, -11}) - + -- option: Show custom playmat images elseif id == "showCustomPlaymatImages" then optionPanel[id] = spawnOrRemoveHelper(state, "Custom Playmat Images", {67.5, 1.6, 37}) diff --git a/src/core/PlayArea.ttslua b/src/core/PlayArea.ttslua index e0f7cd94..10de9821 100644 --- a/src/core/PlayArea.ttslua +++ b/src/core/PlayArea.ttslua @@ -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 diff --git a/src/core/PlayAreaApi.ttslua b/src/core/PlayAreaApi.ttslua index 157cc600..65ac8487 100644 --- a/src/core/PlayAreaApi.ttslua +++ b/src/core/PlayAreaApi.ttslua @@ -47,6 +47,13 @@ do PlayAreaApi.setLimitSnapsByType = function(matchCardTypes) 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