Implemented AllCardsBagApi
Caught all (hopefully) references to the AllCardsBag and refactored to utilize the new AllCardsBagApi.
This commit is contained in:
parent
1213771ef9
commit
da06070311
@ -8,7 +8,7 @@ local soundCubeApi = require("core/SoundCubeApi")
|
||||
local playmatApi = require("playermat/PlaymatApi")
|
||||
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
|
||||
local chaosBagApi = require("chaosbag/ChaosBagApi")
|
||||
local playAreaAPI = require("core/PlayAreaApi")
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
|
||||
-- these objects will be ignored
|
||||
local IGNORE_GUIDS = {
|
||||
@ -231,8 +231,7 @@ end
|
||||
|
||||
-- gets the GUID of a custom data helper (if present) and adds it to the ignore list
|
||||
function ignoreCustomDataHelper()
|
||||
local playArea = getObjectFromGUID("721ba2")
|
||||
local customDataHelper = playAreaAPI.getCustomDataHelper()
|
||||
local customDataHelper = playAreaApi.getCustomDataHelper()
|
||||
if customDataHelper then table.insert(IGNORE_GUIDS, customDataHelper.getGUID()) end
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
do
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
local ArkhamDb = { }
|
||||
local internal = { }
|
||||
|
||||
@ -56,8 +57,7 @@ do
|
||||
callback)
|
||||
-- Get a simple card to see if the bag indexes are complete. If not, abort
|
||||
-- the deck load. The called method will handle player notification.
|
||||
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
|
||||
local checkCard = allCardsBag.call("getCardById", { id = "01001" })
|
||||
local checkCard = allCardsBagApi.getCardById({ id = "01001" })
|
||||
if (checkCard ~= nil and checkCard.data == nil) then
|
||||
return
|
||||
end
|
||||
@ -166,7 +166,6 @@ do
|
||||
---@param playerColor String Color of the player this deck is being loaded for. Used for broadcast
|
||||
--- if a weakness is added.
|
||||
internal.maybeDrawRandomWeakness = function(slots, playerColor)
|
||||
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
|
||||
local hasRandomWeakness = false
|
||||
for cardId, cardCount in pairs(slots) do
|
||||
if cardId == RANDOM_WEAKNESS_ID then
|
||||
@ -175,7 +174,7 @@ do
|
||||
end
|
||||
end
|
||||
if hasRandomWeakness then
|
||||
local weaknessId = allCardsBag.call("getRandomWeaknessId")
|
||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
||||
slots[weaknessId] = 1
|
||||
slots[RANDOM_WEAKNESS_ID] = nil
|
||||
internal.maybePrint("Random basic weakness added to deck", playerColor)
|
||||
@ -240,10 +239,9 @@ do
|
||||
---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the number
|
||||
-- of those cards which will be spawned
|
||||
internal.maybeAddCustomizeUpgradeSheets = function(slots)
|
||||
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
|
||||
for cardId, _ in pairs(slots) do
|
||||
-- upgrade sheets for customizable cards
|
||||
local upgradesheet = allCardsBag.call("getCardById", { id = cardId .. "-c" })
|
||||
local upgradesheet = allCardsBagApi.getCardById({ id = cardId .. "-c" })
|
||||
if upgradesheet ~= nil then
|
||||
slots[cardId .. "-c"] = 1
|
||||
end
|
||||
@ -280,12 +278,11 @@ do
|
||||
-- Process the slot list and looks for any cards which are bonded to those in the deck. Adds those cards to the slot list.
|
||||
---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the number of those cards which will be spawned
|
||||
internal.extractBondedCards = function(slots)
|
||||
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
|
||||
-- Create a list of bonded cards first so we don't modify slots while iterating
|
||||
local bondedCards = { }
|
||||
local bondedList = { }
|
||||
for cardId, cardCount in pairs(slots) do
|
||||
local card = allCardsBag.call("getCardById", { id = cardId })
|
||||
local card = allCardsBagApi.getCardById({ id = cardId })
|
||||
if (card ~= nil and card.metadata.bonded ~= nil) then
|
||||
for _, bond in ipairs(card.metadata.bonded) do
|
||||
bondedCards[bond.id] = bond.count
|
||||
@ -309,15 +306,14 @@ do
|
||||
---@param slots Table The slot list for cards in this deck. Table key is the cardId, value is the number of those cards which will be spawned
|
||||
internal.checkTaboos = function(tabooId, slots, playerColor)
|
||||
if tabooId then
|
||||
local allCardsBag = getObjectFromGUID(configuration.card_bag_guid)
|
||||
for cardId, _ in pairs(tabooList[tabooId].cards) do
|
||||
if slots[cardId] ~= nil then
|
||||
-- Make sure there's a taboo version of the card before we replace it
|
||||
-- SCED only maintains the most recent taboo cards. If a deck is using
|
||||
-- an older taboo list it's possible the card isn't a taboo any more
|
||||
local tabooCard = allCardsBag.call("getCardById", { id = cardId .. "-t" })
|
||||
local tabooCard = allCardsBagApi.getCardById({ id = cardId .. "-t" })
|
||||
if tabooCard == nil then
|
||||
local basicCard = allCardsBag.call("getCardById", { id = cardId })
|
||||
local basicCard = allCardsBagApi.getCardById({ id = cardId })
|
||||
internal.maybePrint("Taboo version for " .. basicCard.data.Nickname .. " is not available. Using standard version", playerColor)
|
||||
else
|
||||
slots[cardId .. "-t"] = slots[cardId]
|
||||
|
@ -3,11 +3,10 @@ require("playercards/PlayerCardSpawner")
|
||||
|
||||
local playmatApi = require("playermat/PlaymatApi")
|
||||
local playAreaApi = require("core/PlayAreaApi")
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
local arkhamDb = require("arkhamdb/ArkhamDb")
|
||||
local zones = require("playermat/Zones")
|
||||
|
||||
local ALL_CARDS_GUID = "15bb07"
|
||||
|
||||
function onLoad(script_state)
|
||||
initializeUi(JSON.decode(script_state))
|
||||
math.randomseed(os.time())
|
||||
@ -72,11 +71,10 @@ end
|
||||
---@param loadAltInvestigator String Contains the name of alternative art for the investigator ("normal", "revised" or "promo")
|
||||
function loadCards(slots, investigatorId, bondedList, customizations, playerColor, loadAltInvestigator)
|
||||
function coinside()
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
|
||||
local yPos = {}
|
||||
local cardsToSpawn = {}
|
||||
for cardId, cardCount in pairs(slots) do
|
||||
local card = allCardsBag.call("getCardById", { id = cardId })
|
||||
local card = allCardsBagApi.getCardById({ id = cardId })
|
||||
if card ~= nil then
|
||||
local cardZone = getDefaultCardZone(card.metadata, bondedList)
|
||||
for i = 1, cardCount do
|
||||
@ -185,8 +183,7 @@ end
|
||||
-- Returns the simple name of a card given its ID. This will find the card and strip any trailing
|
||||
-- SCED-specific suffixes such as (Taboo) or (Level)
|
||||
function getCardName(cardId)
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
|
||||
local card = allCardsBag.call("getCardById", { id = cardId })
|
||||
local card = allCardsBagApi.getCardById({ id = cardId })
|
||||
if (card ~= nil) then
|
||||
local name = card.data.Nickname
|
||||
if (string.find(name, " %(")) then
|
||||
|
@ -23,6 +23,8 @@ local privateDeck = true
|
||||
local loadNewestDeck = true
|
||||
local loadInvestigators = false
|
||||
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
|
||||
-- Returns a table with the full state of the UI, including options and deck IDs.
|
||||
-- This can be used to persist via onSave(), or provide values for a load operation
|
||||
-- Table values:
|
||||
@ -218,8 +220,7 @@ function loadDecks()
|
||||
-- Method in DeckImporterMain, visible due to inclusion
|
||||
|
||||
-- TODO: Make this use the configuration ID for the all cards bag
|
||||
local allCardsBag = getObjectFromGUID("15bb07")
|
||||
local indexReady = allCardsBag.call("isIndexReady")
|
||||
local indexReady = allCardsBagApi.isIndexReady()
|
||||
if (not indexReady) then
|
||||
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
|
||||
return
|
||||
|
@ -6,7 +6,9 @@
|
||||
-- Tells the All Cards Bag to recreate its indexes. The All Cards Bag may
|
||||
-- ignore this request; see the rebuildIndexForHotfix() method in the All Cards
|
||||
-- Bag for details.
|
||||
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
|
||||
function onLoad()
|
||||
local allCardsBag = getObjectFromGUID("15bb07")
|
||||
allCardsBag.call("rebuildIndexForHotfix")
|
||||
allCardsBagApi.rebuildIndexForHotfix()
|
||||
end
|
||||
|
@ -2,7 +2,71 @@ do
|
||||
local AllCardsBagApi = {}
|
||||
local ALL_CARDS_BAG_GUID = "15bb07"
|
||||
|
||||
|
||||
-- Returns a specific card from the bag, based on ArkhamDB ID
|
||||
-- @param table:
|
||||
-- id: String ID of the card to retrieve
|
||||
-- @return: If the indexes are still being constructed, an empty table is
|
||||
-- returned. Otherwise, a single table with the following fields
|
||||
-- cardData: TTS object data, suitable for spawning the card
|
||||
-- cardMetadata: Table of parsed metadata
|
||||
AllCardsBagApi.getCardById = function(params)
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardById", params)
|
||||
end
|
||||
|
||||
-- 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 are rebuilt, which will refresh the list to include all
|
||||
-- weaknesses.
|
||||
-- @return: String ID of the selected weakness.
|
||||
AllCardsBagApi.getRandomWeaknessId = function()
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getRandomWeaknessId")
|
||||
end
|
||||
|
||||
AllCardsBagApi.isIndexReady = function()
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("isIndexReady")
|
||||
end
|
||||
|
||||
-- Called by Hotfix bags when they load. If we are still loading indexes, then
|
||||
-- the all cards and hotfix bags are being loaded together, and we can ignore
|
||||
-- this call as the hotfix will be included in the initial indexing. If it is
|
||||
-- called once indexing is complete it means the hotfix bag has been added
|
||||
-- later, and we should rebuild the index to integrate the hotfix bag.
|
||||
AllCardsBagApi.rebuildIndexForHotfix = function()
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("rebuildIndexForHotfix")
|
||||
end
|
||||
|
||||
-- Searches the bag for cards which match the given name and returns a list. Note that this is
|
||||
-- an O(n) search without index support. It may be slow.
|
||||
-- @param array must contain these fields to define the search:
|
||||
-- name String or string fragment to search for names
|
||||
-- exact Whether the name match should be exact
|
||||
AllCardsBagApi.getCardsByName = function(params)
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardsByName", params)
|
||||
end
|
||||
|
||||
AllCardsBagApi.isBagPresent = function()
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID) and true
|
||||
end
|
||||
|
||||
-- Returns a list of cards from the bag matching a class and level (0 or upgraded)
|
||||
-- @param table:
|
||||
-- class: String class to retrieve ("Guardian", "Seeker", etc)
|
||||
-- isUpgraded: true for upgraded cards (Level 1-5), false for Level 0
|
||||
-- @return: If the indexes are still being constructed, returns an empty table.
|
||||
-- Otherwise, a list of tables, each with the following fields
|
||||
-- cardData: TTS object data, suitable for spawning the card
|
||||
-- cardMetadata: Table of parsed metadata
|
||||
AllCardsBagApi.getCardsByClassAndLevel = function(params)
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardsByClassAndLevel", params)
|
||||
end
|
||||
|
||||
AllCardsBagApi.getCardsByCycle = function(cycle)
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardsByCycle", cycle)
|
||||
end
|
||||
|
||||
AllCardsBagApi.getUniqueWeaknesses = function()
|
||||
return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getUniqueWeaknesses")
|
||||
end
|
||||
|
||||
return AllCardsBagApi
|
||||
end
|
@ -8,6 +8,8 @@ information = {
|
||||
|
||||
require("playercards/PlayerCardSpawner")
|
||||
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
|
||||
local buttonParameters = {}
|
||||
buttonParameters.function_owner = self
|
||||
buttonParameters.height = 200
|
||||
@ -32,8 +34,6 @@ inputParameters.width = 1200
|
||||
inputParameters.height = 130
|
||||
inputParameters.font_size = 107
|
||||
|
||||
local ALL_CARDS_GUID = "15bb07"
|
||||
|
||||
-- main code
|
||||
function onSave() return JSON.encode({ spawnAll, searchExact, inputParameters.value }) end
|
||||
|
||||
@ -101,15 +101,14 @@ function search()
|
||||
printToAll("Please enter a longer search string.", "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
|
||||
if allCardsBag == nil then
|
||||
|
||||
if not allCardsBagApi.isBagPresent() then
|
||||
printToAll("Player card bag couldn't be found.", "Red")
|
||||
return
|
||||
end
|
||||
|
||||
-- search all objects in bag
|
||||
local cardList = allCardsBag.call("getCardsByName", { name = inputParameters.value, exact = searchExact })
|
||||
local cardList = allCardsBagApi.getCardsByName({ name = inputParameters.value, exact = searchExact })
|
||||
if cardList == nil or #cardList == 0 then
|
||||
printToAll("No match found.", "Red")
|
||||
return
|
||||
|
@ -1,6 +1,7 @@
|
||||
require("playercards/PlayerCardPanelData")
|
||||
local spawnBag = require("playercards/SpawnBag")
|
||||
local arkhamDb = require("arkhamdb/ArkhamDb")
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
|
||||
-- Size and position information for the three rows of class buttons
|
||||
local CIRCLE_BUTTON_SIZE = 250
|
||||
@ -21,8 +22,6 @@ local CYCLE_COLUMN_COUNT = 3
|
||||
local CYCLE_BUTTONS_X_OFFSET = 0.267
|
||||
local CYCLE_BUTTONS_Z_OFFSET = 0.2665
|
||||
|
||||
local ALL_CARDS_BAG_GUID = "15bb07"
|
||||
|
||||
local STARTER_DECK_MODE_SELECTED_COLOR = { 0.2, 0.2, 0.2, 0.8 }
|
||||
local TRANSPARENT = { 0, 0, 0, 0 }
|
||||
local STARTER_DECK_MODE_STARTERS = "starters"
|
||||
@ -579,19 +578,18 @@ end
|
||||
---@param cardClass String. Class to place ("Guardian", "Seeker", etc)
|
||||
---@param isUpgraded Boolean. If true, spawn the Level 1-5 cards. Otherwise, Level 0.
|
||||
function placeClassCards(cardClass, isUpgraded)
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_BAG_GUID)
|
||||
local indexReady = allCardsBag.call("isIndexReady")
|
||||
local indexReady = allCardsBagApi.isIndexReady()
|
||||
if (not indexReady) then
|
||||
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
|
||||
return
|
||||
end
|
||||
local cardIdList = allCardsBag.call("getCardsByClassAndLevel", {class = cardClass, upgraded = isUpgraded})
|
||||
local cardIdList = allCardsBagApi.getCardsByClassAndLevel({class = cardClass, upgraded = isUpgraded})
|
||||
|
||||
local skillList = { }
|
||||
local eventList = { }
|
||||
local assetList = { }
|
||||
for _, cardId in ipairs(cardIdList) do
|
||||
local cardMetadata = allCardsBag.call("getCardById", { id = cardId }).metadata
|
||||
local cardMetadata = allCardsBagApi.getCardById({ id = cardId }).metadata
|
||||
if (cardMetadata.type == "Skill") then
|
||||
table.insert(skillList, cardId)
|
||||
elseif (cardMetadata.type == "Event") then
|
||||
@ -640,13 +638,12 @@ end
|
||||
function spawnCycle(cycle)
|
||||
prepareToPlaceCards()
|
||||
spawnInvestigators(cycle)
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_BAG_GUID)
|
||||
local indexReady = allCardsBag.call("isIndexReady")
|
||||
local indexReady = allCardsBagApi.isIndexReady()
|
||||
if (not indexReady) then
|
||||
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
|
||||
return
|
||||
end
|
||||
local cycleCardList = allCardsBag.call("getCardsByCycle", cycle)
|
||||
local cycleCardList = allCardsBagApi.getCardsByCycle(cycle)
|
||||
local copiedList = { }
|
||||
for i, id in ipairs(cycleCardList) do
|
||||
copiedList[i] = id
|
||||
@ -694,17 +691,16 @@ end
|
||||
-- Clears the current cards, and places all basic weaknesses on the table.
|
||||
function spawnWeaknesses()
|
||||
prepareToPlaceCards()
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_BAG_GUID)
|
||||
local indexReady = allCardsBag.call("isIndexReady")
|
||||
local indexReady = allCardsBagApi.isIndexReady()
|
||||
if (not indexReady) then
|
||||
broadcastToAll("Still loading player cards, please try again in a few seconds", {0.9, 0.2, 0.2})
|
||||
return
|
||||
end
|
||||
local weaknessIdList = allCardsBag.call("getUniqueWeaknesses")
|
||||
local weaknessIdList = allCardsBagApi.getUniqueWeaknesses()
|
||||
local basicWeaknessList = { }
|
||||
local otherWeaknessList = { }
|
||||
for i, id in ipairs(weaknessIdList) do
|
||||
local cardMetadata = allCardsBag.call("getCardById", { id = id }).metadata
|
||||
local cardMetadata = allCardsBagApi.getCardById({ id = id }).metadata
|
||||
if cardMetadata.basicWeaknessCount ~= nil and cardMetadata.basicWeaknessCount > 0 then
|
||||
table.insert(basicWeaknessList, id)
|
||||
elseif excludedNonBasicWeaknesses[id] == nil then
|
||||
@ -742,8 +738,7 @@ end
|
||||
|
||||
function spawnRandomWeakness()
|
||||
prepareToPlaceCards()
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_BAG_GUID)
|
||||
local weaknessId = allCardsBag.call("getRandomWeaknessId")
|
||||
local weaknessId = allCardsBagApi.getRandomWeaknessId()
|
||||
if (weaknessId == nil) then
|
||||
broadcastToAll("All basic weaknesses are in play!", {0.9, 0.2, 0.2})
|
||||
return
|
||||
|
@ -29,7 +29,7 @@ do
|
||||
-- To assist debugging, will draw a box around the recall zone when it's set up
|
||||
local SHOW_RECALL_ZONE = false
|
||||
|
||||
local ALL_CARDS_GUID = "15bb07"
|
||||
local allCardsBagApi = require("playercards/AllCardsBagApi")
|
||||
|
||||
-- Distance to expand the recall zone around any added object.
|
||||
local RECALL_BUFFER_X = 0.9
|
||||
@ -90,10 +90,9 @@ do
|
||||
return
|
||||
end
|
||||
local cardsToSpawn = { }
|
||||
local allCardsBag = getObjectFromGUID(ALL_CARDS_GUID)
|
||||
local cardList = spawnSpec.cards
|
||||
for _, cardId in ipairs(cardList) do
|
||||
local cardData = allCardsBag.call("getCardById", { id = cardId })
|
||||
local cardData = allCardsBagApi.getCardById({ id = cardId })
|
||||
if (cardData ~= nil) then
|
||||
table.insert(cardsToSpawn, cardData)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user