updates and remove one use change

This commit is contained in:
dscarpac 2024-07-07 17:35:04 -05:00
parent 55654a288a
commit 58d4b4d292
3 changed files with 24 additions and 15 deletions

View File

@ -5,6 +5,7 @@ local navigationOverlayApi = require("core/NavigationOverlayApi")
local optionPanelApi = require("core/OptionPanelApi")
local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib")
local tokenChecker = require("core/token/TokenChecker")
local victoryDisplayApi = require("core/VictoryDisplayApi")
function onLoad()
@ -265,7 +266,7 @@ function removeOneUse(playerColor, hoveredObject)
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
if not obj.locked and obj.memo ~= "resourceCounter" then
-- check for matching object, otherwise use the first hit
if obj.memo == searchForType then
if obj.memo and obj.memo == searchForType then
targetObject = obj
break
elseif not targetObject then
@ -275,6 +276,15 @@ function removeOneUse(playerColor, hoveredObject)
end
end
-- release sealed token if card has one and no uses
if tokenChecker.isChaosToken(targetObject) and hoveredObject.hasTag("CardThatSeals") then
local func = hoveredObject.getVar("releaseOneToken") -- check if function exists
if func ~= nil then
hoveredObject.call("releaseOneToken", playerColor)
return
end
end
-- error handling
if not targetObject then
broadcastToColor("No tokens found!", playerColor, "Yellow")

View File

@ -424,7 +424,7 @@ function returnAndRedraw(_, tokenGUID)
-- perform the actual token replacing
trackChaosToken(tokenName, mat.getGUID(), true)
params = {token = returnedToken, fromBag = true}
local params = {token = returnedToken, fromBag = true}
returnChaosTokenToBag(params)
chaosTokens[indexOfReturnedToken] = drawChaosToken({

View File

@ -86,7 +86,6 @@ local guidReferenceApi = require("core/GUIDReferenceApi")
local playermatApi = require("playermat/PlayermatApi")
local tokenArrangerApi = require("accessories/TokenArrangerApi")
local MAX_SEALED = MAX_SEALED or nil
local sealedTokens = {}
local ID_URL_MAP = {}
local tokensInBag = {}
@ -116,7 +115,6 @@ end
-- builds the context menu
function generateContextMenu()
self.addContextMenuItem("Release one token", releaseOneToken)
-- conditional release options
@ -200,7 +198,7 @@ end
-- seals the named token on this card
function sealToken(name, playerColor)
if #sealedTokens == MAX_SEALED then
if #sealedTokens >= MAX_SEALED then
printToColor("Cannot seal any more tokens on this card", playerColor, "Red")
return
end
@ -223,7 +221,11 @@ function sealToken(name, playerColor)
-- destroy XML on just covered token
if #sealedTokens > 1 then
local coveredToken = getObjectFromGUID(sealedTokens[#sealedTokens - 1])
if coveredToken ~= nil then
coveredToken.UI.setXml("")
else
table.remove(sealedTokens, #sealedTokens - 1)
end
end
updateStackSize()
end
@ -253,16 +255,13 @@ function releaseMultipleTokens(playerColor)
end
if #sealedTokens < SHOW_MULTI_RELEASE then
local numRemoved = #sealedTokens
else
local numRemoved = SHOW_MULTI_RELEASE
end
for i = 1, numRemoved do
putTokenAway(table.remove(sealedTokens))
end
printToColor("Releasing " .. numRemoved .. " tokens", playerColor)
else
for i = 1, SHOW_MULTI_RELEASE do
putTokenAway(table.remove(sealedTokens))
end
printToColor("Releasing " .. SHOW_MULTI_RELEASE .. " tokens", playerColor)
end
end
-- releases all sealed tokens