From b595462bb414488ab560fb5bb3fbf73578bcb3a9 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 13 Aug 2024 23:36:16 +0200 Subject: [PATCH 1/2] Remove closest uses first --- src/core/GameKeyHandler.ttslua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index b83e64ad..43edb90b 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -275,14 +275,18 @@ function removeOneUse(playerColor, hoveredObject) return end - -- index the found tokens by memo (only the first of each type) + -- index the found tokens by memo (store the token closest to the card for each memo) + local cardPos = hoveredObject.getPosition() local indexByMemo = {} + local distanceByMemo = {} for _, obj in ipairs(searchResult) do if not obj.locked then - if obj.memo and indexByMemo[obj.memo] == nil then - indexByMemo[obj.memo] = obj - elseif indexByMemo["NO_MEMO"] == nil then - indexByMemo["NO_MEMO"] = obj + local objPos = obj.getPosition() + local distance = Vector.between(cardPos, objPos):magnitude() + local memo = obj.memo or "NO_MEMO" + if distanceByMemo[memo] == nil or distanceByMemo[memo] > distance then + indexByMemo[memo] = obj + distanceByMemo[memo] = distance end end end From d3b56a40838806d1b74cf7361c418d2d144ace49 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 14 Aug 2024 09:29:17 +0200 Subject: [PATCH 2/2] fixed wrong require and annotations --- src/arkhamdb/ArkhamDb.ttslua | 2 -- src/core/GlobalApi.ttslua | 2 +- src/core/token/TokenManagerApi.ttslua | 2 +- src/playercards/CardsThatRedrawTokens.ttslua | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/arkhamdb/ArkhamDb.ttslua b/src/arkhamdb/ArkhamDb.ttslua index 1e9bfcbd..6a9e1812 100644 --- a/src/arkhamdb/ArkhamDb.ttslua +++ b/src/arkhamdb/ArkhamDb.ttslua @@ -47,8 +47,6 @@ do --- investigatorCode String. ID of the investigator in this deck --- customizations table The decoded table of customization upgrades in this deck --- playerColor String. Color this deck is being loaded for - ---@return boolean - ---@return string ArkhamDb.getDecklist = function( playerColor, deckId, diff --git a/src/core/GlobalApi.ttslua b/src/core/GlobalApi.ttslua index 22dbee5d..96db7cdb 100644 --- a/src/core/GlobalApi.ttslua +++ b/src/core/GlobalApi.ttslua @@ -26,7 +26,7 @@ do ---@param owner? tts__Object Object that owns the XML (or nil if Global) ---@return boolean visible Returns the new state of the visibility function GlobalApi.changeWindowVisibility(playerColor, windowId, overrideState, owner) - Global.call("changeWindowVisibilityForColorWrapper", { + return Global.call("changeWindowVisibilityForColorWrapper", { color = playerColor, windowId = windowId, overrideState = overrideState, diff --git a/src/core/token/TokenManagerApi.ttslua b/src/core/token/TokenManagerApi.ttslua index abd1f424..42b6e51c 100644 --- a/src/core/token/TokenManagerApi.ttslua +++ b/src/core/token/TokenManagerApi.ttslua @@ -14,7 +14,7 @@ do ---@param card tts__Object Card to check for data ---@return boolean: True if this card has data in the helper, false otherwise function TokenManagerApi.hasLocationData(card) - Global.call("callTable", { + return Global.call("callTable", { { "TokenManager", "hasLocationData" }, card }) diff --git a/src/playercards/CardsThatRedrawTokens.ttslua b/src/playercards/CardsThatRedrawTokens.ttslua index 7ddf0078..962f1275 100644 --- a/src/playercards/CardsThatRedrawTokens.ttslua +++ b/src/playercards/CardsThatRedrawTokens.ttslua @@ -51,7 +51,7 @@ As a nice reminder the XML button takes on the Frost color and icon with the tex > require... ----------------------------------------------------------]] -local chaosBagApi = require("chaosBag/ChaosBagApi") +local chaosBagApi = require("chaosbag/ChaosBagApi") -- intentionally global hasXML = true