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 optionPanelApi = require("core/OptionPanelApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local tokenChecker = require("core/token/TokenChecker")
local victoryDisplayApi = require("core/VictoryDisplayApi") local victoryDisplayApi = require("core/VictoryDisplayApi")
function onLoad() function onLoad()
@ -265,7 +266,7 @@ function removeOneUse(playerColor, hoveredObject)
for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do for _, obj in ipairs(searchLib.onObject(hoveredObject, "isTileOrToken")) do
if not obj.locked and obj.memo ~= "resourceCounter" then if not obj.locked and obj.memo ~= "resourceCounter" then
-- check for matching object, otherwise use the first hit -- check for matching object, otherwise use the first hit
if obj.memo == searchForType then if obj.memo and obj.memo == searchForType then
targetObject = obj targetObject = obj
break break
elseif not targetObject then elseif not targetObject then
@ -275,6 +276,15 @@ function removeOneUse(playerColor, hoveredObject)
end end
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 -- error handling
if not targetObject then if not targetObject then
broadcastToColor("No tokens found!", playerColor, "Yellow") broadcastToColor("No tokens found!", playerColor, "Yellow")

View File

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

View File

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