updated deck importer
This commit is contained in:
parent
10df46854a
commit
893bd05801
@ -191,11 +191,11 @@ do
|
|||||||
slots[RANDOM_WEAKNESS_ID] = nil
|
slots[RANDOM_WEAKNESS_ID] = nil
|
||||||
|
|
||||||
if randomWeaknessAmount > 0 then
|
if randomWeaknessAmount > 0 then
|
||||||
for i = 1, randomWeaknessAmount do
|
local weaknessIds = allCardsBagApi.getRandomWeaknessIds(randomWeaknessAmount, restrictions)
|
||||||
local weaknessId = allCardsBagApi.getRandomWeaknessId(restrictions)
|
for _, weaknessId in ipairs(weaknessIds) do
|
||||||
slots[weaknessId] = (slots[weaknessId] or 0) + 1
|
slots[weaknessId] = (slots[weaknessId] or 0) + 1
|
||||||
end
|
end
|
||||||
internal.maybePrint("Added " .. randomWeaknessAmount .. " random basic weakness(es) to deck", playerColor)
|
internal.maybePrint("Added " .. #weaknessIds .. " random basic weakness(es) to deck", playerColor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ local STANDALONE_TOGGLE_LABELS = {}
|
|||||||
STANDALONE_TOGGLE_LABELS[true] = "Yes"
|
STANDALONE_TOGGLE_LABELS[true] = "Yes"
|
||||||
STANDALONE_TOGGLE_LABELS[false] = "No"
|
STANDALONE_TOGGLE_LABELS[false] = "No"
|
||||||
|
|
||||||
local redDeckId = ""
|
redDeckId = ""
|
||||||
local orangeDeckId = ""
|
orangeDeckId = ""
|
||||||
local whiteDeckId = ""
|
whiteDeckId = ""
|
||||||
local greenDeckId = ""
|
greenDeckId = ""
|
||||||
|
|
||||||
local privateDeck = true
|
local privateDeck = true
|
||||||
local loadNewestDeck = true
|
local loadNewestDeck = true
|
||||||
@ -123,7 +123,7 @@ function makeDeckIdFields()
|
|||||||
iParams.width = INPUT_FIELD_WIDTH
|
iParams.width = INPUT_FIELD_WIDTH
|
||||||
iParams.height = INPUT_FIELD_HEIGHT
|
iParams.height = INPUT_FIELD_HEIGHT
|
||||||
iParams.font_size = 320
|
iParams.font_size = 320
|
||||||
iParams.tooltip = "Deck ID from ArkhamDB URL of the deck\nPublic URL: 'https://arkhamdb.com/decklist/view/101/knowledge-overwhelming-solo-deck-1.0' = '101'\nPrivate URL: 'https://arkhamdb.com/deck/view/102' = '102'\n\nAlso supports the deck ID from shared decks from arkham.build!"
|
iParams.tooltip = "Deck ID from ArkhamDB URL of the deck\nPublished URL: 'https://arkhamdb.com/decklist/view/101/knowledge-overwhelming-solo-deck-1.0' = '101'\nPrivate URL: 'https://arkhamdb.com/deck/view/102' = '102'\n\nAlso supports the deck ID from shared decks from arkham.build!"
|
||||||
iParams.alignment = 3 -- Center
|
iParams.alignment = 3 -- Center
|
||||||
iParams.color = FIELD_COLOR
|
iParams.color = FIELD_COLOR
|
||||||
iParams.font_color = { 0, 0, 0 }
|
iParams.font_color = { 0, 0, 0 }
|
||||||
@ -190,19 +190,28 @@ function standaloneChanged()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function loadDecks()
|
function loadDecks()
|
||||||
|
co = coroutine.create(loadDecksCoroutine)
|
||||||
|
resumeLoadDecks()
|
||||||
|
end
|
||||||
|
|
||||||
|
function loadDecksCoroutine()
|
||||||
if not allCardsBagApi.isIndexReady() then return end
|
if not allCardsBagApi.isIndexReady() then return end
|
||||||
matsWithInvestigator = playermatApi.getUsedMatColors()
|
matsWithInvestigator = playermatApi.getUsedMatColors()
|
||||||
if redDeckId ~= nil and redDeckId ~= "" then
|
|
||||||
buildDeck("Red", redDeckId)
|
for _, matColor in ipairs({"White", "Orange", "Green", "Red"}) do
|
||||||
|
local deckId = _G[string.lower(matColor) .. "DeckId"]
|
||||||
|
if deckId ~= nil and deckId ~= "" then
|
||||||
|
buildDeck(matColor, deckId)
|
||||||
|
coroutine.yield()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if orangeDeckId ~= nil and orangeDeckId ~= "" then
|
end
|
||||||
buildDeck("Orange", orangeDeckId)
|
|
||||||
end
|
function resumeLoadDecks()
|
||||||
if whiteDeckId ~= nil and whiteDeckId ~= "" then
|
log("resume")
|
||||||
buildDeck("White", whiteDeckId)
|
if co and coroutine.status(co) ~= "dead" then
|
||||||
end
|
local status, err = coroutine.resume(co)
|
||||||
if greenDeckId ~= nil and greenDeckId ~= "" then
|
if not status then error(err) end
|
||||||
buildDeck("Green", greenDeckId)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -345,6 +354,7 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo
|
|||||||
if (not hadError) then
|
if (not hadError) then
|
||||||
printToAll("Deck loaded successfully!", playerColor)
|
printToAll("Deck loaded successfully!", playerColor)
|
||||||
end
|
end
|
||||||
|
resumeLoadDecks()
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -370,18 +370,34 @@ end
|
|||||||
-- Gets a random basic weakness from the bag. Once a given ID has been returned it will be
|
-- Gets a random basic weakness from the bag. Once a given ID has been returned it will be
|
||||||
-- removed from the list and cannot be selected again until a reload occurs or the indexes
|
-- removed from the list and cannot be selected again until a reload occurs or the indexes
|
||||||
-- are rebuilt, which will refresh the list to include all weaknesses.
|
-- are rebuilt, which will refresh the list to include all weaknesses.
|
||||||
---@param restrictions? table Additional restrictions:
|
---@param params table Bundled parameters:
|
||||||
--- class string Class to restrict weakness to
|
--- count number Number of weaknesses
|
||||||
--- standalone boolean Whether 'Campaign only' weaknesses should be exluded
|
--- restrictions table Additional restrictions:
|
||||||
--- traits? string Trait(s) to use as filter
|
--- class string Class to restrict weakness to
|
||||||
---@return string: ID of the selected weakness
|
--- standalone boolean Whether 'Campaign only' weaknesses should be exluded
|
||||||
function getRandomWeaknessId(restrictions)
|
--- traits? string Trait(s) to use as filter
|
||||||
local availableWeaknesses = buildAvailableWeaknesses(restrictions)
|
---@return table: Table with IDs of the selected weaknesses
|
||||||
if #availableWeaknesses > 0 then
|
function getRandomWeaknessIds(params)
|
||||||
return availableWeaknesses[math.random(#availableWeaknesses)]
|
params.count = params.count or 1
|
||||||
else
|
local availableWeaknesses = buildAvailableWeaknesses(params.restrictions)
|
||||||
broadcastToAll("No basic weakness available!", { 0.9, 0.2, 0.2 })
|
|
||||||
|
-- check if enough weaknesses are available
|
||||||
|
local missingWeaknesses = params.count - #availableWeaknesses
|
||||||
|
if missingWeaknesses > 0 then
|
||||||
|
broadcastToAll("Not enough basic weaknesses available! (" .. missingWeaknesses .. " missing)", { 0.9, 0.2, 0.2 })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local drawnWeaknesses = {}
|
||||||
|
|
||||||
|
-- Fisher-Yates shuffle algorithm
|
||||||
|
local n = #availableWeaknesses
|
||||||
|
for i = 1, math.min(params.count, n) do
|
||||||
|
local index = math.random(i, n)
|
||||||
|
table.insert(drawnWeaknesses, availableWeaknesses[index])
|
||||||
|
availableWeaknesses[index], availableWeaknesses[i] = availableWeaknesses[i], availableWeaknesses[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
return drawnWeaknesses
|
||||||
end
|
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
|
||||||
|
@ -28,13 +28,14 @@ do
|
|||||||
-- Gets a random basic weakness from the bag. Once a given ID has been returned it
|
-- Gets a random basic weakness from the bag. Once a given ID has been returned it
|
||||||
-- will be removed from the list and cannot be selected again until a reload occurs
|
-- will be removed from the list and cannot be selected again until a reload occurs
|
||||||
-- or the indexes are rebuilt, which will refresh the list to include all weaknesses.
|
-- or the indexes are rebuilt, which will refresh the list to include all weaknesses.
|
||||||
|
---@param count number Number of weaknesses
|
||||||
---@param restrictions table Additional restrictions:
|
---@param restrictions table Additional restrictions:
|
||||||
--- class string Class to restrict weakness to
|
--- class string Class to restrict weakness to
|
||||||
--- standalone boolean Whether 'Campaign only' weaknesses should be exluded
|
--- standalone boolean Whether 'Campaign only' weaknesses should be exluded
|
||||||
--- traits? string Trait(s) to use as filter
|
--- traits? string Trait(s) to use as filter
|
||||||
---@return string: ID of the selected weakness
|
---@return table: Table with IDs of the selected weaknesses
|
||||||
AllCardsBagApi.getRandomWeaknessId = function(restrictions)
|
AllCardsBagApi.getRandomWeaknessIds = function(count, restrictions)
|
||||||
return getAllCardsBag().call("getRandomWeaknessId", restrictions)
|
return returnCopyOfList(getAllCardsBag().call("getRandomWeaknessIds", {count = count, restrictions = restrictions}))
|
||||||
end
|
end
|
||||||
|
|
||||||
AllCardsBagApi.isIndexReady = function()
|
AllCardsBagApi.isIndexReady = function()
|
||||||
|
@ -782,17 +782,17 @@ function spawnRandomWeakness(_, playerColor, isRightClick)
|
|||||||
prepareToPlaceCards()
|
prepareToPlaceCards()
|
||||||
|
|
||||||
if not isRightClick then
|
if not isRightClick then
|
||||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
local weaknessIds = allCardsBagApi.getRandomWeaknessIds(1)
|
||||||
if weaknessId then
|
if weaknessIds[1] then
|
||||||
spawnSingleWeakness(weaknessId)
|
spawnSingleWeakness(weaknessIds[1])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Player[playerColor].showInputDialog("Specify a trait for the weakness (split multiple eligible traits with '|'):", 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 weaknessId = allCardsBagApi.getRandomWeaknessId({ traits = text })
|
local weaknessIds = allCardsBagApi.getRandomWeaknessIds(1, { traits = text })
|
||||||
if weaknessId then
|
if weaknessIds[1] then
|
||||||
spawnSingleWeakness(weaknessId)
|
spawnSingleWeakness(weaknessIds[1])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user