updated code for better functionality part 4

This commit is contained in:
Zerino 2024-11-18 11:16:22 -03:00
parent dc2ac54923
commit a8a67872de
4 changed files with 36 additions and 36 deletions

View File

@ -74,7 +74,7 @@ local handVisibility = {}
local blurseVisibility = {}
-- track cards' settings
cardSetting = {}
local cardSetting = {}
---------------------------------------------------------
-- data for tokens
@ -309,37 +309,37 @@ function onPlayerAction(player, action, targets)
table.insert(pickedCards, target)
end
end
if #pickedCards < 6 then
for _, pickedCard in ipairs(pickedCards) do
local searchResult = searchLib.onObject(pickedCard, "isTileOrToken", 0.95)
if pickedCard.is_face_down and next(searchResult) ~= nil then
cardSetting[pickedCard] = {
hideFacedown = pickedCard.hide_when_face_down,
tooltip = pickedCard.tooltip
}
pickedCard.hide_when_face_down = false
pickedCard.tooltip = false
end
for _, token in ipairs(searchResult) do
if not token.locked then
pickedCard.addAttachment(token)
end
end
Wait.condition(
function()
if pickedCard ~= nil then
handleTokenDetaching({ card = pickedCard })
end
end,
function()
if pickedCard ~= nil and player ~= nil and player.seated then
return pickedCard.resting and not tableContains(player.getHoldingObjects(), pickedCard)
else
return true
end
end
)
if #pickedCards > 5 then return end
for _, pickedCard in ipairs(pickedCards) do
local searchResult = searchLib.onObject(pickedCard, "isTileOrToken", 0.95)
if pickedCard.is_face_down and next(searchResult) ~= nil then
cardSetting[pickedCard] = {
hideFacedown = pickedCard.hide_when_face_down,
tooltip = pickedCard.tooltip
}
pickedCard.hide_when_face_down = false
pickedCard.tooltip = false
end
for _, token in ipairs(searchResult) do
if not token.locked then
pickedCard.addAttachment(token)
end
end
Wait.condition(
function()
if pickedCard ~= nil then
handleTokenDetaching({ card = pickedCard })
end
end,
function()
if pickedCard ~= nil and player ~= nil and player.seated then
return pickedCard.resting and not tableContains(player.getHoldingObjects(), pickedCard)
else
return true
end
end
)
end
end
return true
@ -2884,6 +2884,7 @@ function handleTokenDetaching(params)
pickedCard.tooltip = pickedCardSetting["tooltip"]
cardSetting[pickedCard] = nil
end
local removedTokens = pickedCard.removeAttachments()
for _, token in ipairs(removedTokens) do
if token.getPosition().y < pickedCard.getPosition().y then

View File

@ -97,7 +97,7 @@ function onCollisionEnter(collisionInfo)
-- only continue if card didn't already collide
if collisionTable[object] ~= nil then return end
collisionTable[object] = 1
collisionTable[object] = true
Wait.frames(function() collisionTable[object] = nil end, 1)
local localPos = self.positionToLocal(object.getPosition())

View File

@ -1266,7 +1266,7 @@ function onCollisionEnter(collisionInfo)
-- only continue if card didn't already collide
if collisionTable[object] ~= nil then return end
collisionTable[object] = 1
collisionTable[object] = true
Wait.frames(function() collisionTable[object] = nil end, 1)
local md = JSON.decode(object.getGMNotes()) or {}

View File

@ -46,9 +46,8 @@ do
-- searches the area on an object
function SearchLib.onObject(obj, filter, scale)
scale = scale or 1
local sizeY = obj.getBounds().size.y
local pos = obj.getPosition() + Vector(0, sizeY, 0)
local size = obj.getBounds().size:scale(scale):setAt("y", sizeY)
local pos = obj.getPosition() + Vector(0, 1, 0) -- offset by half the cast's height
local size = obj.getBounds().size:scale(scale):setAt("y", 2)
return returnSearchResult(pos, _, size, filter)
end