added multi trait search
This commit is contained in:
parent
fd9e7e6c86
commit
27c96df747
@ -380,9 +380,9 @@ end
|
|||||||
|
|
||||||
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
|
-- 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
|
-- 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
|
---@return table: Array of weakness IDs which are valid to choose from
|
||||||
function buildAvailableWeaknesses(trait)
|
function buildAvailableWeaknesses(traits)
|
||||||
local weaknessesInPlay = {}
|
local weaknessesInPlay = {}
|
||||||
local allObjects = getAllObjects()
|
local allObjects = getAllObjects()
|
||||||
for _, object in ipairs(allObjects) do
|
for _, object in ipairs(allObjects) do
|
||||||
@ -400,11 +400,22 @@ function buildAvailableWeaknesses(trait)
|
|||||||
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
|
if (weaknessesInPlay[weaknessId] ~= nil and weaknessesInPlay[weaknessId] > 0) then
|
||||||
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
|
weaknessesInPlay[weaknessId] = weaknessesInPlay[weaknessId] - 1
|
||||||
else
|
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
|
-- make sure the trait is present on the weakness
|
||||||
local card = cardIdIndex[weaknessId]
|
local card = cardIdIndex[weaknessId]
|
||||||
if string.contains(string.lower(card.metadata.traits), string.lower(trait)) then
|
for _, allowedTrait in ipairs(allowedTraits) do
|
||||||
table.insert(availableWeaknesses, weaknessId)
|
if string.contains(string.lower(card.metadata.traits), allowedTrait) then
|
||||||
|
table.insert(availableWeaknesses, weaknessId)
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(availableWeaknesses, weaknessId)
|
table.insert(availableWeaknesses, weaknessId)
|
||||||
|
@ -82,10 +82,10 @@ do
|
|||||||
|
|
||||||
-- Constructs a list of available basic weaknesses by starting with the full pool of basic
|
-- 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
|
-- 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
|
---@return table: Array of weakness IDs which are valid to choose from
|
||||||
AllCardsBagApi.buildAvailableWeaknesses = function(trait)
|
AllCardsBagApi.buildAvailableWeaknesses = function(traits)
|
||||||
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", trait))
|
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", traits))
|
||||||
end
|
end
|
||||||
|
|
||||||
AllCardsBagApi.getUniqueWeaknesses = function()
|
AllCardsBagApi.getUniqueWeaknesses = function()
|
||||||
|
@ -789,7 +789,7 @@ function spawnRandomWeakness(_, playerColor, isRightClick)
|
|||||||
spawnSingleWeakness(weaknessId)
|
spawnSingleWeakness(weaknessId)
|
||||||
end
|
end
|
||||||
else
|
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)
|
function(text)
|
||||||
lastWeaknessTrait = text
|
lastWeaknessTrait = text
|
||||||
local availableWeaknesses = allCardsBagApi.buildAvailableWeaknesses(text)
|
local availableWeaknesses = allCardsBagApi.buildAvailableWeaknesses(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user