Merge pull request #999 from argonui/globalapi
Moving Token-Detaching to GlobalApi
This commit is contained in:
commit
1df5bfa889
@ -208,7 +208,7 @@ function tryObjectEnterContainer(container, object)
|
|||||||
-- stop mini cards from forming decks
|
-- stop mini cards from forming decks
|
||||||
if object.hasTag("Minicard") and container.hasTag("Minicard") then
|
if object.hasTag("Minicard") and container.hasTag("Minicard") then
|
||||||
return false
|
return false
|
||||||
elseif object.getName() ~= "Atlach-Nacha" and next(object.getAttachments()) ~= nil then
|
elseif object.type == "Card" and object.getName() ~= "Atlach-Nacha" then
|
||||||
handleTokenDetaching({ card = object })
|
handleTokenDetaching({ card = object })
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -312,34 +312,7 @@ function onPlayerAction(player, action, targets)
|
|||||||
if #pickedCards > 5 then return end
|
if #pickedCards > 5 then return end
|
||||||
|
|
||||||
for _, pickedCard in ipairs(pickedCards) do
|
for _, pickedCard in ipairs(pickedCards) do
|
||||||
local searchResult = searchLib.onObject(pickedCard, "isTileOrToken", 0.95)
|
handleTokenAttaching({ player = player, card = pickedCard })
|
||||||
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
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -2876,27 +2849,66 @@ function tableContains(thisTable, thisElement)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function handleTokenDetaching(params)
|
function handleTokenAttaching(params)
|
||||||
local pickedCard = params["card"]
|
local card = params.card
|
||||||
if cardSetting[pickedCard] ~= nil then
|
local player = params.player
|
||||||
local pickedCardSetting = cardSetting[pickedCard]
|
local searchResult = searchLib.onObject(card, "isTileOrToken", 0.95)
|
||||||
pickedCard.hide_when_face_down = pickedCardSetting["hideFacedown"]
|
if card.is_face_down and next(searchResult) ~= nil then
|
||||||
pickedCard.tooltip = pickedCardSetting["tooltip"]
|
cardSetting[card] = {
|
||||||
cardSetting[pickedCard] = nil
|
hideFacedown = card.hide_when_face_down,
|
||||||
|
tooltip = card.tooltip
|
||||||
|
}
|
||||||
|
card.hide_when_face_down = false
|
||||||
|
card.tooltip = false
|
||||||
end
|
end
|
||||||
|
|
||||||
local removedTokens = pickedCard.removeAttachments()
|
for _, token in ipairs(searchResult) do
|
||||||
|
if not token.locked then
|
||||||
|
card.addAttachment(token)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Wait.condition(
|
||||||
|
function()
|
||||||
|
if card ~= nil then
|
||||||
|
handleTokenDetaching(card)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function()
|
||||||
|
if card ~= nil and player ~= nil and player.seated then
|
||||||
|
return card.resting and not tableContains(player.getHoldingObjects(), card)
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function handleTokenDetaching(params)
|
||||||
|
local card = params.card
|
||||||
|
if next(card.getAttachments()) == nil then return end
|
||||||
|
|
||||||
|
-- restore card settings
|
||||||
|
if cardSetting[card] ~= nil then
|
||||||
|
card.hide_when_face_down = cardSetting[card]["hideFacedown"]
|
||||||
|
card.tooltip = cardSetting[card]["tooltip"]
|
||||||
|
cardSetting[card] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove attachments
|
||||||
|
local removedTokens = card.removeAttachments()
|
||||||
for _, token in ipairs(removedTokens) do
|
for _, token in ipairs(removedTokens) do
|
||||||
if token.getPosition().y < pickedCard.getPosition().y then
|
if token.getPosition().y < card.getPosition().y then
|
||||||
local posY = pickedCard.getPosition().y + 0.05
|
local posY = card.getPosition().y + 0.05
|
||||||
token.setPosition(token.getPosition():setAt("y", posY))
|
token.setPosition(token.getPosition():setAt("y", posY))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if pickedCard.hasTag("CardThatSeals") then
|
-- redraw token xml
|
||||||
local func = pickedCard.getVar("updateStackSize") -- make sure function exists
|
if card.hasTag("CardThatSeals") then
|
||||||
|
local func = card.getVar("updateStackSize") -- make sure function exists
|
||||||
if func ~= nil then
|
if func ~= nil then
|
||||||
pickedCard.call("updateStackSize")
|
card.call("updateStackSize")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,6 +53,12 @@ do
|
|||||||
Global.call("handVisibilityToggle", { playerColor = playerColor, handColor = handColor })
|
Global.call("handVisibilityToggle", { playerColor = playerColor, handColor = handColor })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- handles token detaching for cards
|
||||||
|
---@param card tts__Object Card that should get tokens detached
|
||||||
|
function GlobalApi.handleTokenDetaching(card)
|
||||||
|
Global.call("handleTokenDetaching", { card = card })
|
||||||
|
end
|
||||||
|
|
||||||
-- loads saved options
|
-- loads saved options
|
||||||
---@param options table Set a new state for the option table
|
---@param options table Set a new state for the option table
|
||||||
function GlobalApi.loadOptionPanelSettings(options)
|
function GlobalApi.loadOptionPanelSettings(options)
|
||||||
|
@ -105,9 +105,7 @@ function onCollisionEnter(collisionInfo)
|
|||||||
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
|
if inArea(localPos, ENCOUNTER_DECK_AREA) or inArea(localPos, ENCOUNTER_DISCARD_AREA) then
|
||||||
-- reset spawned tokens and remove tokens from cards in encounter deck / discard area
|
-- reset spawned tokens and remove tokens from cards in encounter deck / discard area
|
||||||
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
|
Wait.frames(function() tokenSpawnTrackerApi.resetTokensSpawned(object) end, 1)
|
||||||
if next(object.getAttachments()) ~= nil then
|
GlobalApi.handleTokenDetaching(object)
|
||||||
Global.call("handleTokenDetaching", { card = object })
|
|
||||||
end
|
|
||||||
removeTokensFromObject(object)
|
removeTokensFromObject(object)
|
||||||
|
|
||||||
elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then
|
elseif inArea(localPos, SCENARIO_REFERENCE_AREA) then
|
||||||
|
@ -1298,9 +1298,7 @@ function onCollisionEnter(collisionInfo)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif inArea(localCardPos, DECK_DISCARD_AREA) then
|
elseif inArea(localCardPos, DECK_DISCARD_AREA) then
|
||||||
if next(object.getAttachments()) ~= nil then
|
GlobalApi.handleTokenDetaching(object)
|
||||||
Global.call("handleTokenDetaching", { card = object })
|
|
||||||
end
|
|
||||||
tokenSpawnTrackerApi.resetTokensSpawned(object)
|
tokenSpawnTrackerApi.resetTokensSpawned(object)
|
||||||
removeTokensFromObject(object)
|
removeTokensFromObject(object)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user