Merge branch 'api-updates' into entrox-main

This commit is contained in:
Entrox-Licher 2023-08-10 17:10:04 -04:00 committed by GitHub
commit 0204622176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 230 additions and 108 deletions

View File

@ -34,6 +34,7 @@ buttonParameters.height = 300
local name
local tokens = {}
local chaosBagApi = require("chaosbag/ChaosBagApi")
function onLoad()
-- create buttons for tokens
@ -60,11 +61,11 @@ function buttonClick(index, isRightClick)
local tokenId = TOKEN_IDS[index]
if isRightClick then
Global.call("removeChaosToken", tokenId)
chaosBagApi.removeChaosToken(tokenId)
else
local tokens = {}
local name = BUTTON_TOOLTIP[index]
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == name then table.insert(tokens, v.guid) end
@ -76,7 +77,7 @@ function buttonClick(index, isRightClick)
return
end
Global.call("spawnChaosToken", tokenId)
chaosBagApi.spawnChaosToken(tokenId)
printToAll("Adding " .. name .. " token (in bag: " .. #tokens + 1 .. ")", "White")
end
end

View File

@ -8,6 +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")
-- these objects will be ignored
local IGNORE_GUIDS = {
@ -230,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 = playArea.getVar("customDataHelper")
local customDataHelper = playAreaApi.getCustomDataHelper()
if customDataHelper then table.insert(IGNORE_GUIDS, customDataHelper.getGUID()) end
end

View File

@ -37,6 +37,8 @@ local TOKEN_NAMES = {
""
}
local chaosBagApi = require("chaosbag/ChaosBagApi")
-- saving the precedence settings and information on the most recently loaded data
function onSave()
return JSON.encode({
@ -287,7 +289,7 @@ function layout(_, _, isRightClick)
return
end
local chaosBag = Global.call("findChaosBag")
local chaosBag = chaosBagApi.findChaosBag()
local data = {}
-- clone tokens from chaos bag (default position above trash can)

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -23,6 +23,8 @@ local FONT_COLOR = {
local whitespace = " "
local updating
local chaosBagApi = require("chaosbag/ChaosBagApi")
---------------------------------------------------------
-- creating buttons and menus + initializing tables
---------------------------------------------------------
@ -79,7 +81,7 @@ function initializeState()
resetTables()
-- count tokens in the bag
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
local tokens = {}
for _, v in ipairs(chaosbag.getObjects()) do
if v.name == "Bless" then
@ -117,7 +119,7 @@ end
-- context menu function 1
function doRemove(color)
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
-- remove tokens from chaos bag
local count = { Bless = 0, Curse = 0 }
@ -224,7 +226,7 @@ end
-- function that is called by click_functions 1+2 and calls the other functions
function callFunctions(token, isRightClick)
if not Global.call("canTouchChaosTokens") then
if not chaosBagApi.canTouchChaosTokens() then
return
end
local success
@ -286,11 +288,11 @@ function addToken(type)
end
numInPlay[type] = numInPlay[type] + 1
printToAll("Adding " .. type .. " token " .. formatTokenCount(type))
return Global.call("spawnChaosToken", type)
return chaosBagApi.spawnChaosToken(type)
end
function takeToken(type, remove)
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
if not remove and not SEAL_CARD_MESSAGE then
broadcastToColor("For sealing tokens on cards try right-clicking on the card for seal options.", playerColor)
SEAL_CARD_MESSAGE = true
@ -335,7 +337,7 @@ function returnToken(type)
printToColor("Couldn't find token " .. guid .. ", not returning to bag", playerColor)
return 0
end
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
if chaosbag == nil then
return 0
end
@ -382,7 +384,7 @@ function addMenuOptions(parameters)
end
function sealToken(type, playerColor, enemy)
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
if chaosbag == nil then return end
local pos = enemy.getPosition()
@ -407,7 +409,7 @@ function sealToken(type, playerColor, enemy)
end
function releaseToken(type, playerColor, enemy)
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
if chaosbag == nil then return end
local tokens = sealedTokens[enemy.getGUID()]
if tokens == nil or #tokens == 0 then return end

View File

@ -28,5 +28,37 @@ do
return Global.call("releaseAllSealedTokens", playerColor)
end
-- removes the specified chaos token from the chaos bag
---@param id String ID of the chaos token
ChaosBagApi.removeChaosToken = function(id)
return Global.call("removeChaosToken", id)
end
-- spawns the specified chaos token and puts it into the chaos bag
---@param id String ID of the chaos token
ChaosBagApi.spawnChaosToken = function(id)
return Global.call("spawnChaosToken", id)
end
-- Checks to see if the chaos bag can be manipulated. If a player is searching the bag when tokens
-- are drawn or replaced a TTS bug can cause those tokens to vanish. Any functions which change the
-- contents of the bag should check this method before doing so.
-- This method will broadcast a message to all players if the bag is being searched.
---@return Boolean. True if the bag is manipulated, false if it should be blocked.
ChaosBagApi.canTouchChaosTokens = function()
return Global.call("canTouchChaosTokens")
end
-- called by playermats (by the "Draw chaos token" button)
ChaosBagApi.drawChaosToken = function(params)
return Global.call("drawChaosToken", params)
end
-- returns a Table List of chaos token ids in the current chaos bag
-- requires copying the data into a new table because TTS is weird about handling table return values in Global
ChaosBagApi.getIdUrlMap = function()
return Global.getTable("ID_URL_MAP")
end
return ChaosBagApi
end

View File

@ -1,6 +1,7 @@
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local playmatApi = require("playermat/PlaymatApi")
local victoryDisplayApi = require("core/VictoryDisplayApi")
local optionPanelApi = require("core/OptionPanelApi")
function onLoad()
addHotkey("Add Doom to Agenda", addDoomToAgenda)
@ -98,15 +99,19 @@ function takeClueFromLocation(playerColor, hoveredObject)
return
end
local clickableClues = optionPanelApi.getOptions()["useClueClickers"]
local playerName = Player[playerColor].steam_name
local matColor = playmatApi.getMatColor(playerColor)
local pos = playmatApi.transformLocalPosition({x = -1.12, y = 0.05, z = 0.7}, matColor)
local rot = playmatApi.returnRotation(matColor)
if cardName == "" or cardName == nil then
cardName = "nameless card"
local pos = nil
if clickableClues then
pos = {x = 0.49, y = 2.66, z = 0.00}
playmatApi.updateClueClicker(playerColor, playmatApi.getClueCount(clickableClues, playerColor) + 1)
else
pos = playmatApi.transformLocalPosition({x = -1.12, y = 0.05, z = 0.7}, matColor)
end
local rot = playmatApi.returnRotation(matColor)
-- check if found clue is a stack or single token
if clue.getQuantity() > 1 then
clue.takeObject({position = pos, rotation = rot})

View File

@ -504,20 +504,6 @@ function shiftContents(playerColor, direction)
Wait.time(drawBaseConnections, 0.1)
end
-- Returns the current value of the investigator counter from the playmat
---@return. Number of investigators currently set on the counter
function getInvestigatorCount()
local investigatorCounter = getObjectFromGUID("f182ee")
return investigatorCounter.getVar("val")
end
-- Updates the current value of the investigator counter from the playmat
---@param count Number of investigators to set on the counter
function setInvestigatorCount(count)
local investigatorCounter = getObjectFromGUID("f182ee")
return investigatorCounter.call("updateVal", count)
end
-- Check to see if the given object is within the bounds of the play area, based solely on the X and
-- Z coordinates, ignoring height
---@param object Object Object to check

View File

@ -2,19 +2,20 @@ do
local PlayAreaApi = { }
local PLAY_AREA_GUID = "721ba2"
local INVESTIGATOR_COUNTER_GUID = "f182ee"
local IMAGE_SWAPPER = "b7b45b"
-- Returns the current value of the investigator counter from the playmat
---@return Integer. Number of investigators currently set on the counter
PlayAreaApi.getInvestigatorCount = function()
return getObjectFromGUID(PLAY_AREA_GUID).call("getInvestigatorCount")
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).getVar("val")
end
-- Updates the current value of the investigator counter from the playmat
---@param count Number of investigators to set on the counter
PlayAreaApi.setInvestigatorCount = function(count)
return getObjectFromGUID(PLAY_AREA_GUID).call("setInvestigatorCount", count)
return getObjectFromGUID(INVESTIGATOR_COUNTER_GUID).call("updateVal", count)
end
-- Move all contents on the play area (cards, tokens, etc) one slot in the given direction. Certain
@ -93,5 +94,28 @@ do
return getObjectFromGUID(IMAGE_SWAPPER).call("updateSurface", url)
end
-- Called by Custom Data Helpers to push their location data into the Data Helper. This adds the
-- data to the local token manager instance.
---@param args Table Single-value array holding the GUID of the Custom Data Helper making the call
PlayAreaApi.updateLocations = function(args)
getObjectFromGUID(PLAY_AREA_GUID).call("updateLocations", args)
end
PlayAreaApi.getCustomDataHelper = function()
return getObjectFromGUID(PLAY_AREA_GUID).getVar("customDataHelper")
end
PlayAreaApi.getCustomObject = function()
return getObjectFromGUID(PLAY_AREA_GUID).getCustomObject()
end
PlayAreaApi.setCustomObject = function(customInfo)
return getObjectFromGUID(PLAY_AREA_GUID).setCustomObject(customInfo)
end
PlayAreaApi.reload = function()
return getObjectFromGUID(PLAY_AREA_GUID).reload()
end
return PlayAreaApi
end

View File

@ -1,5 +1,6 @@
local controlActive = false
local DEFAULT_URL = "http://cloud-3.steamusercontent.com/ugc/998015670465071049/FFAE162920D67CF38045EFBD3B85AD0F916147B2/"
local playAreaAPI = require("core/PlayAreaApi")
-- parameters for open/close button for reusing
local buttonParameters = {}
@ -70,8 +71,7 @@ function none() end
-- main function (can be called by other objects)
function updateSurface(newURL)
local playArea = getObjectFromGUID("721ba2")
local customInfo = playArea.getCustomObject()
local customInfo = playAreaAPI.getCustomObject()
if newURL ~= "" and newURL ~= nil and newURL ~= DEFAULT_URL then
customInfo.image = newURL
@ -81,17 +81,17 @@ function updateSurface(newURL)
broadcastToAll("Default Playmat Image Applied", { 0.2, 0.9, 0.2 })
end
playArea.setCustomObject(customInfo)
playAreaAPI.setCustomObject(customInfo)
-- get custom data helper and call the playarea with it after reloading
local customDataHelper = playArea.getVar("customDataHelper")
local customDataHelper = playAreaAPI.getCustomDataHelper()
local guid
if customDataHelper then guid = customDataHelper.getGUID() end
playArea = playArea.reload()
playAreaAPI.reload()
if guid ~= nil then
Wait.time(function() playArea.call("updateLocations", { guid }) end, 1)
Wait.time(function() playAreaAPI.updateLocations({ guid }) end, 1)
end
end

View File

@ -8,6 +8,7 @@ local highlightMissing = false
local highlightCounted = false
local TRASHCAN
local TRASHCAN_GUID = "70b9f6"
local chaosBagApi = require("chaosbag/ChaosBagApi")
-- button creation when loading the game
function onLoad()
@ -276,7 +277,7 @@ function placeCard(card)
if obj.tag == "Deck" or obj.tag == "Card" then
-- put chaos tokens back into bag
elseif tokenChecker.isChaosToken(obj) then
local chaosBag = Global.call("findChaosBag")
local chaosBag = chaosBagApi.findChaosBag()
chaosBag.putObject(obj)
elseif obj.memo ~= nil and obj.getLock() == false then
TRASHCAN.putObject(obj)

View File

@ -1,6 +1,7 @@
do
local tokenSpawnTracker = require("core/token/TokenSpawnTrackerApi")
local playArea = require("core/PlayAreaApi")
local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
local playAreaApi = require("core/PlayAreaApi")
local optionPanelApi = require("core/OptionPanelApi")
local PLAYER_CARD_TOKEN_OFFSETS = {
[1] = {
@ -141,7 +142,7 @@ do
---@param extraUses Table A table of <use type>=<count> which will modify the number of tokens
--- spawned for that type. e.g. Akachi's playmat should pass "Charge"=1
TokenManager.spawnForCard = function(card, extraUses)
if tokenSpawnTracker.hasSpawnedTokens(card.getGUID()) then
if tokenSpawnTrackerApi.hasSpawnedTokens(card.getGUID()) then
return
end
local metadata = JSON.decode(card.getGMNotes())
@ -161,7 +162,7 @@ do
---@param shiftDown Number An offset for the z-value of this group of tokens
---@param subType Number Subtype of token to spawn. This will only differ from the tokenName for resource tokens
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown, subType)
local optionPanel = Global.getTable("optionPanel")
local optionPanel = optionPanelApi.getOptions()
if tokenType == "damage" or tokenType == "horror" then
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
@ -303,7 +304,7 @@ do
-- callers.
---@param card Object Card object to reset the tokens for
TokenManager.resetTokensSpawned = function(card)
tokenSpawnTracker.resetTokensSpawned(card.getGUID())
tokenSpawnTrackerApi.resetTokensSpawned(card.getGUID())
end
-- Pushes new player card data into the local copy of the Data Helper player data.
@ -369,14 +370,14 @@ do
type = useInfo.type
token = useInfo.token
tokenCount = (useInfo.count or 0)
+ (useInfo.countPerInvestigator or 0) * playArea.getInvestigatorCount()
+ (useInfo.countPerInvestigator or 0) * playAreaApi.getInvestigatorCount()
if extraUses ~= nil and extraUses[type] ~= nil then
tokenCount = tokenCount + extraUses[type]
end
-- Shift each spawned group after the first down so they don't pile on each other
TokenManager.spawnTokenGroup(card, token, tokenCount, (i - 1) * 0.8, type)
end
tokenSpawnTracker.markTokensSpawned(card.getGUID())
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
end
-- Spawn tokens for a card based on the data helper data. This will consider the face up/down state
@ -403,7 +404,7 @@ do
tokenCount = playerData.tokenCount
--log("Spawning data helper tokens for "..card.getName()..'['..card.getDescription()..']: '..tokenCount.."x "..token)
TokenManager.spawnTokenGroup(card, token, tokenCount)
tokenSpawnTracker.markTokensSpawned(card.getGUID())
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
end
-- Spawn tokens for a location using data retrieved from the Data Helper.
@ -414,7 +415,7 @@ do
local clueCount = internal.getClueCountFromData(card, locationData)
if clueCount > 0 then
TokenManager.spawnTokenGroup(card, "clue", clueCount)
tokenSpawnTracker.markTokensSpawned(card.getGUID())
tokenSpawnTrackerApi.markTokensSpawned(card.getGUID())
end
end
@ -440,7 +441,7 @@ do
if locationData.type == 'fixed' then
return locationData.value
elseif locationData.type == 'perPlayer' then
return locationData.value * playArea.getInvestigatorCount()
return locationData.value * playAreaApi.getInvestigatorCount()
end
error('unexpected location type: ' .. locationData.type)
end

View File

@ -0,0 +1,72 @@
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

View File

@ -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
@ -102,14 +102,13 @@ function search()
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

View File

@ -70,6 +70,7 @@ Thus it should be implemented like this:
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local tokenArrangerApi = require("accessories/TokenArrangerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi")
local sealedTokens = {}
local ID_URL_MAP = {}
local tokensInBag = {}
@ -78,7 +79,7 @@ function onSave() return JSON.encode(sealedTokens) end
function onLoad(savedData)
sealedTokens = JSON.decode(savedData) or {}
ID_URL_MAP = Global.getTable("ID_URL_MAP")
ID_URL_MAP = chaosBagApi.getIdUrlMap()
generateContextMenu()
self.addTag("CardThatSeals")
end
@ -129,7 +130,7 @@ end
-- generates a list of chaos tokens that is in the chaos bag
function readBag()
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
tokensInBag = {}
for _, token in ipairs(chaosbag.getObjects()) do
@ -148,8 +149,8 @@ end
-- seals the named token on this card
function sealToken(name, playerColor)
if not Global.call("canTouchChaosTokens") then return end
local chaosbag = Global.call("findChaosBag")
if not chaosBagApi.canTouchChaosTokens() then return end
local chaosbag = chaosBagApi.findChaosBag()
for i, obj in ipairs(chaosbag.getObjects()) do
if obj.name == name then
chaosbag.takeObject({
@ -174,7 +175,7 @@ end
-- release the last sealed token
function releaseOneToken(playerColor)
if not Global.call("canTouchChaosTokens") then return end
if not chaosBagApi.canTouchChaosTokens() then return end
if #sealedTokens == 0 then
printToColor("No sealed token(s) found", playerColor)
else
@ -197,7 +198,7 @@ end
-- releases all sealed tokens
function releaseAllTokens(playerColor)
if not Global.call("canTouchChaosTokens") then return end
if not chaosBagApi.canTouchChaosTokens() then return end
if #sealedTokens == 0 then
printToColor("No sealed token(s) found", playerColor)
else
@ -215,7 +216,7 @@ function putTokenAway(guid)
if not token then return end
local name = token.getName()
local chaosbag = Global.call("findChaosBag")
local chaosbag = chaosBagApi.findChaosBag()
chaosbag.putObject(token)
tokenArrangerApi.layout()
if name == "Bless" or name == "Curse" then

View File

@ -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

View File

@ -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

View File

@ -56,6 +56,8 @@ local TRASHCAN
local STAT_TRACKER
local RESOURCE_COUNTER
local chaosBagApi = require("chaosbag/ChaosBagApi")
-- global variable so it can be reset by the Clean Up Helper
activeInvestigatorId = "00000"
local isDrawButtonVisible = false
@ -210,7 +212,7 @@ function makeDiscardHandlerFor(searchPosition, discardPosition)
end
-- put chaos tokens back into bag (e.g. Unrelenting)
elseif tokenChecker.isChaosToken(obj) then
local chaosBag = Global.call("findChaosBag")
local chaosBag = chaosBagApi.findChaosBag()
chaosBag.putObject(obj)
-- don't touch the table or this playmat itself
elseif obj.guid ~= "4ee1f2" and obj ~= self then
@ -772,7 +774,7 @@ end
---------------------------------------------------------
function drawChaosTokenButton(_, _, isRightClick)
Global.call("drawChaosToken", {self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick})
chaosBagApi.drawChaosToken({self, DRAWN_CHAOS_TOKEN_OFFSET, isRightClick})
end
function drawEncountercard(_, _, isRightClick)

View File

@ -191,6 +191,10 @@ do
end
end
PlaymatApi.updateClueClicker = function(playerColor, val)
return getObjectFromGUID(CLUE_CLICKER_GUIDS[playerColor]).call("updateVal", val)
end
-- Convenience function to look up a mat's object by color, or get all mats.
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
-- accepts "All" as a special value which will return all four mats.