many updates

This commit is contained in:
dscarpac 2024-07-07 16:00:14 -05:00
parent 289f786eb2
commit 55654a288a
12 changed files with 49 additions and 61 deletions

View File

@ -47,8 +47,9 @@ do
-- returns a chaos token to the bag and calls all relevant functions -- returns a chaos token to the bag and calls all relevant functions
---@param token tts__Object Chaos token to return ---@param token tts__Object Chaos token to return
ChaosBagApi.returnChaosTokenToBag = function(token) ---@param fromBag boolean whether or not the token to return was in the middle of being drawn (true) or elsewhere (false)
return Global.call("returnChaosTokenToBag", token) ChaosBagApi.returnChaosTokenToBag = function(token, fromBag)
return Global.call("returnChaosTokenToBag", { token = token, fromBag = fromBag })
end end
-- spawns the specified chaos token and puts it into the chaos bag -- spawns the specified chaos token and puts it into the chaos bag

View File

@ -207,6 +207,12 @@ function onObjectEnterZone(zone, object)
object.clearContextMenu() object.clearContextMenu()
object.call("shutOff") object.call("shutOff")
end end
if object.hasTag("CardThatSeals") then
local func = object.getVar("resetSealedTokens") -- check if function exists (it won't for older custom content)
if func ~= nil then
object.call("resetSealedTokens")
end
end
end end
end end
@ -301,13 +307,13 @@ function returnChaosTokens()
end end
-- returns a single chaos token to the bag and calls respective functions -- returns a single chaos token to the bag and calls respective functions
function returnChaosTokenToBag(token) function returnChaosTokenToBag(params)
local name = token.getName() local name = params.token.getName()
local chaosBag = findChaosBag() local chaosBag = findChaosBag()
chaosBag.putObject(token) chaosBag.putObject(params.token)
tokenArrangerApi.layout() tokenArrangerApi.layout()
if name == "Bless" or name == "Curse" then if name == "Bless" or name == "Curse" then
blessCurseManagerApi.releasedToken(name, token.getGUID(), true) blessCurseManagerApi.releasedToken(name, params.token.getGUID(), params.fromBag)
end end
end end
@ -418,7 +424,8 @@ function returnAndRedraw(_, tokenGUID)
-- perform the actual token replacing -- perform the actual token replacing
trackChaosToken(tokenName, mat.getGUID(), true) trackChaosToken(tokenName, mat.getGUID(), true)
returnChaosTokenToBag(returnedToken) params = {token = returnedToken, fromBag = true}
returnChaosTokenToBag(params)
chaosTokens[indexOfReturnedToken] = drawChaosToken({ chaosTokens[indexOfReturnedToken] = drawChaosToken({
mat = mat, mat = mat,

View File

@ -1,7 +1,16 @@
--[[ Library for cards that seal tokens --[[ Library for cards that seal tokens
This file is used to add sealing option to cards' context menu. This file is used to add sealing option to cards' context menu.
NOTE: all cards are allowed to release a single token to enable Hallow and A Watchful Peace,
and to release all sealed tokens to allow for cards that might leave play with sealed tokens on them.
Valid options (set before requiring this file): Valid options (set before requiring this file):
MAX_SEALED --@type: number (maximum number of tokens allowable by the card to be sealed)
- required for all cards
- if MAX_SEALED is more than 1, then an XML label is created for the topmost token indicating the number of sealed tokens
- gives an error if user tries to seal additional tokens on the card
- example usage: "The Chthonian Stone"
> MAX_SEALED = 1
UPDATE_ON_HOVER --@type: boolean UPDATE_ON_HOVER --@type: boolean
- automatically updates the context menu options when the card is hovered - automatically updates the context menu options when the card is hovered
- the "Read Bag" function reads the content of the chaos bag to update the context menu - the "Read Bag" function reads the content of the chaos bag to update the context menu
@ -12,23 +21,12 @@ KEEP_OPEN --@type: boolean
- makes the context menu stay open after selecting an option - makes the context menu stay open after selecting an option
- example usage: "Unrelenting" - example usage: "Unrelenting"
SHOW_SINGLE_RELEASE --@type: boolean SHOW_MULTI_RELEASE --@type: number (maximum amount of tokens to release at once)
- enables an entry in the context menu
- this entry allows releasing a single token
- example usage: "Holy Spear" (to keep the other tokens and just release one)
SHOW_UP_TO_MULTI_RELEASE --@type: number (maximum amount of tokens to release at once)
- enables an entry in the context menu - enables an entry in the context menu
- this entry allows releasing of multiple tokens at once, to the maximum number - this entry allows releasing of multiple tokens at once, to the maximum number
- does not fail if there are fewer than the maximum sealed - does not fail if there are fewer than the maximum sealed
- example usage: "Nephthys" (to release up to 3 bless tokens at once) - example usage: "Nephthys" (to release up to 3 bless tokens at once)
SHOW_MULTI_RELEASE --@type: number (amount of tokens to release at once)
- enables an entry in the context menu
- this entry allows releasing of multiple tokens at once
- fails if not enough tokens are sealed
- example usage: Maybe a Custom Card?
SHOW_MULTI_RETURN --@type: number (amount of tokens to return to pool at once) SHOW_MULTI_RETURN --@type: number (amount of tokens to return to pool at once)
- enables an entry in the context menu - enables an entry in the context menu
- this entry allows returning tokens to the token pool - this entry allows returning tokens to the token pool
@ -66,6 +64,7 @@ Thus it should be implemented like this:
> ["+1"] = true, > ["+1"] = true,
> ["Elder Sign"] = true > ["Elder Sign"] = true
> } > }
> MAX_SEALED = 1
> require... > require...
---------------------------------------------------------- ----------------------------------------------------------
Example 2: Holy Spear Example 2: Holy Spear
@ -76,8 +75,8 @@ Thus it should be implemented like this:
> VALID_TOKENS = { > VALID_TOKENS = {
> ["Bless"] = true > ["Bless"] = true
> } > }
> SHOW_SINGLE_RELEASE = true
> SHOW_MULTI_SEAL = 2 > SHOW_MULTI_SEAL = 2
> MAX_SEALED = 10
> require... > require...
----------------------------------------------------------]] ----------------------------------------------------------]]
@ -117,18 +116,18 @@ end
-- builds the context menu -- builds the context menu
function generateContextMenu() function generateContextMenu()
-- conditional single or multi release options
self.addContextMenuItem("Release one token", releaseOneToken)
-- conditional release options
if MAX_SEALED > 1 then if MAX_SEALED > 1 then
self.addContextMenuItem("Release one token", releaseOneToken)
end
if SHOW_UP_TO_MULTI_RELEASE then
self.addContextMenuItem("Release max " .. SHOW_UP_TO_MULTI_RELEASE .. " tokens", releaseUpToMultipleTokens)
elseif SHOW_MULTI_RELEASE then
self.addContextMenuItem("Release " .. SHOW_MULTI_RELEASE .. " token(s)", releaseMultipleTokens)
else
self.addContextMenuItem("Release all tokens", releaseAllTokens) self.addContextMenuItem("Release all tokens", releaseAllTokens)
end end
if SHOW_MULTI_RELEASE then
self.addContextMenuItem("Release " .. SHOW_MULTI_RELEASE .. " token(s)", releaseMultipleTokens)
end
if RESOLVE_TOKEN then if RESOLVE_TOKEN then
local firstTokenType local firstTokenType
for tokenType, val in pairs(VALID_TOKENS) do for tokenType, val in pairs(VALID_TOKENS) do
@ -246,35 +245,23 @@ function releaseOneToken(playerColor)
end end
end end
-- release multiple tokens at once
function releaseMultipleTokens(playerColor)
if SHOW_MULTI_RELEASE <= #sealedTokens then
for i = 1, SHOW_MULTI_RELEASE do
putTokenAway(table.remove(sealedTokens))
end
printToColor("Releasing " .. SHOW_MULTI_RELEASE .. " tokens", playerColor)
else
printToColor("Not enough tokens sealed.", playerColor)
end
end
-- release up to multiple tokens at once with no minimum -- release up to multiple tokens at once with no minimum
function releaseUpToMultipleTokens(playerColor) function releaseMultipleTokens(playerColor)
if #sealedTokens == 0 then if #sealedTokens == 0 then
printToColor("Not enough tokens sealed.", playerColor) printToColor("Not enough tokens sealed.", playerColor)
return return
end end
if #sealedTokens < SHOW_UP_TO_MULTI_RELEASE then if #sealedTokens < SHOW_MULTI_RELEASE then
local numRemoved = #sealedTokens local numRemoved = #sealedTokens
for i = 1, #sealedTokens 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 else
for i = 1, SHOW_UP_TO_MULTI_RELEASE do for i = 1, SHOW_MULTI_RELEASE do
putTokenAway(table.remove(sealedTokens)) putTokenAway(table.remove(sealedTokens))
end end
printToColor("Releasing " .. SHOW_UP_TO_MULTI_RELEASE .. " tokens", playerColor) printToColor("Releasing " .. SHOW_MULTI_RELEASE .. " tokens", playerColor)
end end
end end
@ -341,19 +328,20 @@ function resolveSealed()
local closestMatColor = playermatApi.getMatColorByPosition(self.getPosition()) local closestMatColor = playermatApi.getMatColorByPosition(self.getPosition())
local mat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat") local mat = guidReferenceApi.getObjectByOwnerAndType(closestMatColor, "Playermat")
local guidToBeResolved = table.remove(sealedTokens) local guidToBeResolved = table.remove(sealedTokens)
local token = getObjectFromGUID(guidToBeResolved) local resolvedToken = getObjectFromGUID(guidToBeResolved)
token.UI.setXml("") resolvedToken.UI.setXml("")
updateStackSize() updateStackSize()
chaosBagApi.drawChaosToken(mat, true, _, guidToBeResolved) chaosBagApi.drawChaosToken(mat, true, _, guidToBeResolved)
end end
function updateStackSize() function updateStackSize()
if MAX_SEALED == 1 then return end if MAX_SEALED == 1 then return end
if #sealedTokens == 0 then return end
-- get topmost sealed token -- get topmost sealed token
local token = getObjectFromGUID(sealedTokens[#sealedTokens]) local topToken = getObjectFromGUID(sealedTokens[#sealedTokens])
local name = token.getName() local name = topToken.getName()
token.UI.setXmlTable({ topToken.UI.setXmlTable({
{ {
tag = "Panel", tag = "Panel",
attributes = { attributes = {

View File

@ -2,7 +2,6 @@ VALID_TOKENS = {
["Curse"] = true ["Curse"] = true
} }
SHOW_SINGLE_RELEASE = true
KEEP_OPEN = true KEEP_OPEN = true
MAX_SEALED = 3 MAX_SEALED = 3
RESOLVE_TOKEN = true RESOLVE_TOKEN = true

View File

@ -2,7 +2,6 @@ VALID_TOKENS = {
["Bless"] = true ["Bless"] = true
} }
SHOW_SINGLE_RELEASE = true
KEEP_OPEN = true KEEP_OPEN = true
MAX_SEALED = 3 MAX_SEALED = 3
RESOLVE_TOKEN = true RESOLVE_TOKEN = true

View File

@ -2,7 +2,6 @@ VALID_TOKENS = {
["Curse"] = true ["Curse"] = true
} }
SHOW_SINGLE_RELEASE = true
MAX_SEALED = 10 MAX_SEALED = 10
KEEP_OPEN = true KEEP_OPEN = true

View File

@ -2,7 +2,6 @@ VALID_TOKENS = {
["Bless"] = true ["Bless"] = true
} }
SHOW_SINGLE_RELEASE = true
SHOW_MULTI_SEAL = 2 SHOW_MULTI_SEAL = 2
MAX_SEALED = 10 MAX_SEALED = 10

View File

@ -3,8 +3,7 @@ VALID_TOKENS = {
} }
KEEP_OPEN = true KEEP_OPEN = true
SHOW_SINGLE_RELEASE = true SHOW_MULTI_RELEASE = 3
SHOW_UP_TO_MULTI_RELEASE = 3
SHOW_MULTI_RETURN = 3 SHOW_MULTI_RETURN = 3
MAX_SEALED = 10 MAX_SEALED = 10

View File

@ -3,7 +3,6 @@ VALID_TOKENS = {
} }
KEEP_OPEN = true KEEP_OPEN = true
SHOW_SINGLE_RELEASE = true
MAX_SEALED = 5 MAX_SEALED = 5
require("playercards/CardsThatSealTokens") require("playercards/CardsThatSealTokens")

View File

@ -2,7 +2,6 @@ VALID_TOKENS = {
["0"] = true ["0"] = true
} }
SHOW_SINGLE_RELEASE = true
MAX_SEALED = 4 -- Core Set is component-limited to 4 '0' tokens MAX_SEALED = 4 -- Core Set is component-limited to 4 '0' tokens
require("playercards/CardsThatSealTokens") require("playercards/CardsThatSealTokens")

View File

@ -3,7 +3,6 @@ VALID_TOKENS = {
} }
KEEP_OPEN = true KEEP_OPEN = true
SHOW_SINGLE_RELEASE = true
MAX_SEALED = 5 MAX_SEALED = 5
require("playercards/CardsThatSealTokens") require("playercards/CardsThatSealTokens")

View File

@ -260,7 +260,7 @@ function discardListOfObjects(objList)
end end
elseif tokenChecker.isChaosToken(obj) then elseif tokenChecker.isChaosToken(obj) then
-- put chaos tokens back into bag (e.g. Unrelenting) -- put chaos tokens back into bag (e.g. Unrelenting)
chaosBagApi.returnChaosTokenToBag(obj) chaosBagApi.returnChaosTokenToBag(obj, false)
elseif not obj.getLock() and not obj.hasTag("DontDiscard") then elseif not obj.getLock() and not obj.hasTag("DontDiscard") then
-- don't touch locked objects (like the table etc.) or specific objects (like key tokens) -- don't touch locked objects (like the table etc.) or specific objects (like key tokens)
ownedObjects.Trash.putObject(obj) ownedObjects.Trash.putObject(obj)
@ -878,7 +878,7 @@ function removeTokensFromObject(object)
for _, obj in ipairs(searchLib.onObject(object)) do for _, obj in ipairs(searchLib.onObject(object)) do
if tokenChecker.isChaosToken(obj) then if tokenChecker.isChaosToken(obj) then
chaosBagApi.returnChaosTokenToBag(obj) chaosBagApi.returnChaosTokenToBag(obj, false)
elseif obj.getGUID() ~= "4ee1f2" and -- table elseif obj.getGUID() ~= "4ee1f2" and -- table
obj ~= self and obj ~= self and
obj.type ~= "Deck" and obj.type ~= "Deck" and