Merge pull request #940 from argonui/remove-use
Updates to "Remove a use" hotkey
This commit is contained in:
commit
5fc31a8f68
@ -274,16 +274,27 @@ function removeOneUse(playerColor, hoveredObject)
|
|||||||
if hoveredObject.type == "Tile" then
|
if hoveredObject.type == "Tile" then
|
||||||
targetObject = hoveredObject
|
targetObject = hoveredObject
|
||||||
elseif hoveredObject.type == "Card" then
|
elseif hoveredObject.type == "Card" then
|
||||||
-- we're only searching 80% of the cards area to avoid matching tokens on other cards
|
local cardPos = hoveredObject.getPosition()
|
||||||
local searchResult = searchLib.onObject(hoveredObject, "isTileOrToken", 0.8)
|
local searchRot = hoveredObject.getRotation()
|
||||||
|
local searchSize = hoveredObject.getBounds().size:scale(0.8):setAt("y", 1)
|
||||||
|
|
||||||
|
-- if this card is on a playermat, search an upright box
|
||||||
|
local owner = guidReferenceApi.getOwnerOfObject(hoveredObject)
|
||||||
|
if owner ~= "Mythos" then
|
||||||
|
searchRot = playermatApi.returnRotation(owner)
|
||||||
|
|
||||||
|
-- we're only searching 90% of the cards area to avoid matching tokens on other cards
|
||||||
|
searchSize = Vector( 2, 1, 3.2 ) * 0.9
|
||||||
|
end
|
||||||
|
|
||||||
|
local searchResult = searchLib.inArea(cardPos, searchRot, searchSize, "isTileOrToken")
|
||||||
|
|
||||||
if #searchResult == 0 then
|
if #searchResult == 0 then
|
||||||
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
broadcastToColor("No tokens found!", playerColor, "Yellow")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- index the found tokens by memo (store the token closest to the card for each memo)
|
-- index the found tokens by memo (store the token furthest to the card for each memo)
|
||||||
local cardPos = hoveredObject.getPosition()
|
|
||||||
local indexByMemo = {}
|
local indexByMemo = {}
|
||||||
local distanceByMemo = {}
|
local distanceByMemo = {}
|
||||||
for _, obj in ipairs(searchResult) do
|
for _, obj in ipairs(searchResult) do
|
||||||
@ -291,7 +302,7 @@ function removeOneUse(playerColor, hoveredObject)
|
|||||||
local objPos = obj.getPosition()
|
local objPos = obj.getPosition()
|
||||||
local distance = Vector.between(cardPos, objPos):magnitude()
|
local distance = Vector.between(cardPos, objPos):magnitude()
|
||||||
local memo = obj.memo or "NO_MEMO"
|
local memo = obj.memo or "NO_MEMO"
|
||||||
if distanceByMemo[memo] == nil or distanceByMemo[memo] > distance then
|
if distanceByMemo[memo] == nil or distanceByMemo[memo] < distance then
|
||||||
indexByMemo[memo] = obj
|
indexByMemo[memo] = obj
|
||||||
distanceByMemo[memo] = distance
|
distanceByMemo[memo] = distance
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user