Merge branch 'main' into clean-up-helper
This commit is contained in:
commit
55aaf7df51
@ -380,8 +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 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()
|
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
|
||||||
@ -399,7 +400,32 @@ function buildAvailableWeaknesses()
|
|||||||
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
|
||||||
table.insert(availableWeaknesses, weaknessId)
|
if traits then
|
||||||
|
-- split the string into separate traits (separated by "|")
|
||||||
|
local allowedTraits = {}
|
||||||
|
for str in traits:gmatch("([^|]+)") do
|
||||||
|
-- remove dots
|
||||||
|
str = str:gsub("[%.]", "")
|
||||||
|
|
||||||
|
-- remove leading and trailing whitespace
|
||||||
|
str = str:match("^%s*(.-)%s*$")
|
||||||
|
|
||||||
|
-- make sure string ends with a dot
|
||||||
|
str = string.lower(str .. ".")
|
||||||
|
table.insert(allowedTraits, str)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- make sure the trait is present on the weakness
|
||||||
|
local card = cardIdIndex[weaknessId]
|
||||||
|
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)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return availableWeaknesses
|
return availableWeaknesses
|
||||||
|
@ -80,6 +80,14 @@ do
|
|||||||
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
|
return returnCopyOfList(getAllCardsBag().call("getCardsByCycle", { cycle = cycle, sortByMetadata = sortByMetadata }))
|
||||||
end
|
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 traits? string Trait(s) to use as filter
|
||||||
|
---@return table: Array of weakness IDs which are valid to choose from
|
||||||
|
AllCardsBagApi.buildAvailableWeaknesses = function(traits)
|
||||||
|
return returnCopyOfList(getAllCardsBag().call("buildAvailableWeaknesses", traits))
|
||||||
|
end
|
||||||
|
|
||||||
AllCardsBagApi.getUniqueWeaknesses = function()
|
AllCardsBagApi.getUniqueWeaknesses = function()
|
||||||
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
|
return returnCopyOfList(getAllCardsBag().call("getUniqueWeaknesses"))
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,8 @@ local allCardsBagApi = require("playercards/AllCardsBagApi")
|
|||||||
local arkhamDb = require("arkhamdb/ArkhamDb")
|
local arkhamDb = require("arkhamdb/ArkhamDb")
|
||||||
local spawnBag = require("playercards/SpawnBag")
|
local spawnBag = require("playercards/SpawnBag")
|
||||||
|
|
||||||
|
local lastWeaknessTrait = "Madness"
|
||||||
|
|
||||||
-- Size and position information for the three rows of class buttons
|
-- Size and position information for the three rows of class buttons
|
||||||
local CIRCLE_BUTTON_SIZE = 250
|
local CIRCLE_BUTTON_SIZE = 250
|
||||||
local CLASS_BUTTONS_X_OFFSET = 0.1325
|
local CLASS_BUTTONS_X_OFFSET = 0.1325
|
||||||
@ -224,9 +226,10 @@ function createWeaknessButtons()
|
|||||||
weaknessButtonParams.tooltip = "All Weaknesses"
|
weaknessButtonParams.tooltip = "All Weaknesses"
|
||||||
weaknessButtonParams.position = buttonPos
|
weaknessButtonParams.position = buttonPos
|
||||||
self.createButton(weaknessButtonParams)
|
self.createButton(weaknessButtonParams)
|
||||||
|
|
||||||
buttonPos.x = buttonPos.x + MISC_BUTTONS_X_OFFSET
|
buttonPos.x = buttonPos.x + MISC_BUTTONS_X_OFFSET
|
||||||
weaknessButtonParams.click_function = "spawnRandomWeakness"
|
weaknessButtonParams.click_function = "spawnRandomWeakness"
|
||||||
weaknessButtonParams.tooltip = "Random Basic Weakness"
|
weaknessButtonParams.tooltip = "Random Basic Weakness\nRight-click to specify a trait"
|
||||||
weaknessButtonParams.position = buttonPos
|
weaknessButtonParams.position = buttonPos
|
||||||
self.createButton(weaknessButtonParams)
|
self.createButton(weaknessButtonParams)
|
||||||
end
|
end
|
||||||
@ -361,9 +364,9 @@ function createXML(showOtherCardsButton)
|
|||||||
alignment = "MiddleLeft",
|
alignment = "MiddleLeft",
|
||||||
horizontalOverflow = "wrap",
|
horizontalOverflow = "wrap",
|
||||||
text = "• Select a group to place cards\n" ..
|
text = "• Select a group to place cards\n" ..
|
||||||
"• Copy the cards you want for your deck\n" ..
|
"• Copy the cards you want for your deck\n" ..
|
||||||
"• Select a new group to clear the placed cards and see new ones\n" ..
|
"• Select a new group to clear the placed cards and see new ones\n" ..
|
||||||
"• Clear to remove all cards"
|
"• Clear to remove all cards"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,13 +778,32 @@ function spawnWeaknesses()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function spawnRandomWeakness()
|
function spawnRandomWeakness(_, playerColor, isRightClick)
|
||||||
prepareToPlaceCards()
|
prepareToPlaceCards()
|
||||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
|
||||||
if (weaknessId == nil) then
|
if not isRightClick then
|
||||||
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
|
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
||||||
return
|
if weaknessId == nil then
|
||||||
|
broadcastToAll("All basic weaknesses are in play!", { 0.9, 0.2, 0.2 })
|
||||||
|
else
|
||||||
|
spawnSingleWeakness(weaknessId)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Player[playerColor].showInputDialog("Specify a trait for the weakness (split multiple eligible traits with '|'):", lastWeaknessTrait,
|
||||||
|
function(text)
|
||||||
|
lastWeaknessTrait = text
|
||||||
|
local availableWeaknesses = allCardsBagApi.buildAvailableWeaknesses(text)
|
||||||
|
if #availableWeaknesses > 0 then
|
||||||
|
spawnSingleWeakness(availableWeaknesses[math.random(#availableWeaknesses)])
|
||||||
|
else
|
||||||
|
broadcastToAll("No matching weakness available!", { 0.9, 0.2, 0.2 })
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- spawn the random weakness
|
||||||
|
function spawnSingleWeakness(weaknessId)
|
||||||
spawnBag.spawn({
|
spawnBag.spawn({
|
||||||
name = "randomWeakness",
|
name = "randomWeakness",
|
||||||
cards = { weaknessId },
|
cards = { weaknessId },
|
||||||
|
Loading…
Reference in New Issue
Block a user