added multi trait search

This commit is contained in:
Chr1Z93 2024-06-27 15:09:04 +02:00
parent fd9e7e6c86
commit 27c96df747
3 changed files with 20 additions and 9 deletions

View File

@ -380,9 +380,9 @@ end
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
-- weaknesses then removing any which are currently in the play or deck construction areas
---@param trait? string Trait to use as filter
---@param traits? string Trait(s) to use as filter
---@return table: Array of weakness IDs which are valid to choose from
function buildAvailableWeaknesses(trait)
function buildAvailableWeaknesses(traits)
local weaknessesInPlay = {}
local allObjects = getAllObjects()
for _, object in ipairs(allObjects) do
@ -400,11 +400,22 @@ function buildAvailableWeaknesses(trait)
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
else
if trait then
if traits then
-- split the string into separate traits (separated by "|")
local allowedTraits = {}
for str in traits:gmatch("([^|]+)") do
-- make sure string ends with a dot
str = string.lower(str:gsub("[%.]", "") .. ".")
table.insert(allowedTraits, str)
end
-- make sure the trait is present on the weakness
local card = cardIdIndex[weaknessId]
if string.contains(string.lower(card.metadata.traits), string.lower(trait)) then
for _, allowedTrait in ipairs(allowedTraits) do
if string.contains(string.lower(card.metadata.traits), allowedTrait) then
table.insert(availableWeaknesses, weaknessId)
break
end
end
else
table.insert(availableWeaknesses, weaknessId)

View File

@ -82,10 +82,10 @@ do
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
-- weaknesses then removing any which are currently in the play or deck construction areas
---@param trait? string Trait to use as filter
---@param traits? string Trait(s) to use as filter
---@return table: Array of weakness IDs which are valid to choose from
AllCardsBagApi.buildAvailableWeaknesses = function(trait)
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", trait))
AllCardsBagApi.buildAvailableWeaknesses = function(traits)
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", traits))
end
AllCardsBagApi.getUniqueWeaknesses = function()

View File

@ -789,7 +789,7 @@ function spawnRandomWeakness(_, playerColor, isRightClick)
spawnSingleWeakness(weaknessId)
end
else
Player[playerColor].showInputDialog("Specify a trait for the weakness:", lastWeaknessTrait,
Player[playerColor].showInputDialog("Specify a trait for the weakness (split multiple eligible traits with '|'):", lastWeaknessTrait,
function(text)
lastWeaknessTrait = text
local availableWeaknesses = allCardsBagApi.buildAvailableWeaknesses(text)