diff --git a/src/accessories/ChaosBagManager.ttslua b/src/accessories/ChaosBagManager.ttslua index 96fdced9..2fc700d7 100644 --- a/src/accessories/ChaosBagManager.ttslua +++ b/src/accessories/ChaosBagManager.ttslua @@ -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 diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 031c79f6..b621febe 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -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 diff --git a/src/accessories/TokenArranger.ttslua b/src/accessories/TokenArranger.ttslua index 86a57721..eea3f167 100644 --- a/src/accessories/TokenArranger.ttslua +++ b/src/accessories/TokenArranger.ttslua @@ -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) diff --git a/src/arkhamdb/ArkhamDb.ttslua b/src/arkhamdb/ArkhamDb.ttslua index 34645a5e..f28d13cc 100644 --- a/src/arkhamdb/ArkhamDb.ttslua +++ b/src/arkhamdb/ArkhamDb.ttslua @@ -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("01001") if (checkCard ~= nil and checkCard.data == nil) then return end @@ -167,13 +167,12 @@ 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 randomWeaknessAmount = slots[RANDOM_WEAKNESS_ID] or 0 slots[RANDOM_WEAKNESS_ID] = nil if randomWeaknessAmount ~= 0 then for i=1, randomWeaknessAmount do - local weaknessId = allCardsBag.call("getRandomWeaknessId") + local weaknessId = allCardsBagApi.getRandomWeaknessId() slots[weaknessId] = (slots[weaknessId] or 0) + 1 end internal.maybePrint("Added " .. randomWeaknessAmount .. " random basic weakness(es) to deck", playerColor) @@ -239,10 +238,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(cardId .. "-c") if upgradesheet ~= nil then slots[cardId .. "-c"] = 1 end @@ -288,12 +286,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(cardId) if (card ~= nil and card.metadata.bonded ~= nil) then for _, bond in ipairs(card.metadata.bonded) do bondedCards[bond.id] = bond.count @@ -317,15 +314,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(cardId .. "-t") if tabooCard == nil then - local basicCard = allCardsBag.call("getCardById", { id = cardId }) + local basicCard = allCardsBagApi.getCardById(cardId) internal.maybePrint("Taboo version for " .. basicCard.data.Nickname .. " is not available. Using standard version", playerColor) else slots[cardId .. "-t"] = slots[cardId] diff --git a/src/arkhamdb/DeckImporterMain.ttslua b/src/arkhamdb/DeckImporterMain.ttslua index 16d508ce..916cc30d 100644 --- a/src/arkhamdb/DeckImporterMain.ttslua +++ b/src/arkhamdb/DeckImporterMain.ttslua @@ -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(cardId) if card ~= nil then local cardZone = getDefaultCardZone(card.metadata, bondedList) for i = 1, cardCount do @@ -186,8 +184,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(cardId) if (card ~= nil) then local name = card.data.Nickname if (string.find(name, " %(")) then diff --git a/src/arkhamdb/DeckImporterUi.ttslua b/src/arkhamdb/DeckImporterUi.ttslua index e227588b..59ad1ac8 100644 --- a/src/arkhamdb/DeckImporterUi.ttslua +++ b/src/arkhamdb/DeckImporterUi.ttslua @@ -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: @@ -217,9 +219,7 @@ function loadDecks() -- testLoadLotsOfDecks() -- 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 diff --git a/src/arkhamdb/HotfixBag.ttslua b/src/arkhamdb/HotfixBag.ttslua index 6d6c53bd..cbbb9088 100644 --- a/src/arkhamdb/HotfixBag.ttslua +++ b/src/arkhamdb/HotfixBag.ttslua @@ -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 diff --git a/src/chaosbag/BlessCurseManager.ttslua b/src/chaosbag/BlessCurseManager.ttslua index ce9eafc3..696df8a6 100644 --- a/src/chaosbag/BlessCurseManager.ttslua +++ b/src/chaosbag/BlessCurseManager.ttslua @@ -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 diff --git a/src/chaosbag/ChaosBagApi.ttslua b/src/chaosbag/ChaosBagApi.ttslua index e2d0a1ae..e0252266 100644 --- a/src/chaosbag/ChaosBagApi.ttslua +++ b/src/chaosbag/ChaosBagApi.ttslua @@ -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(mat, tokenOffset, isRightClick) + return Global.call("drawChaosToken", {mat, tokenOffset, isRightClick}) + 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 \ No newline at end of file diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index f43ddbea..58452e60 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -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,14 +99,18 @@ 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 matColor = playmatApi.getMatColor(playerColor) + 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 diff --git a/src/core/PlayArea.ttslua b/src/core/PlayArea.ttslua index 11934eb3..54e09d5a 100644 --- a/src/core/PlayArea.ttslua +++ b/src/core/PlayArea.ttslua @@ -28,6 +28,8 @@ local collisionEnabled = false -- used for recreating the link to a custom data helper after image change customDataHelper = nil +local DEFAULT_URL = "http://cloud-3.steamusercontent.com/ugc/998015670465071049/FFAE162920D67CF38045EFBD3B85AD0F916147B2/" + local SHIFT_OFFSETS = { left = { x = 0.00, y = 0, z = 7.67 }, right = { x = 0.00, y = 0, z = -7.67 }, @@ -94,6 +96,29 @@ function updateLocations(args) end end +function updateSurface(newURL) + local customInfo = self.getCustomObject() + + if newURL ~= "" and newURL ~= nil and newURL ~= DEFAULT_URL then + customInfo.image = newURL + broadcastToAll("New Playmat Image Applied", { 0.2, 0.9, 0.2 }) + else + customInfo.image = DEFAULT_URL + broadcastToAll("Default Playmat Image Applied", { 0.2, 0.9, 0.2 }) + end + + self.setCustomObject(customInfo) + + local guid = nil + + if customDataHelper then guid = customDataHelper.getGUID() end + self.reload() + + if guid ~= nil then + Wait.time(function() updateLocations({ guid }) end, 1) + end +end + function onCollisionEnter(collisionInfo) local obj = collisionInfo.collision_object local objType = obj.name @@ -504,20 +529,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 diff --git a/src/core/PlayAreaApi.ttslua b/src/core/PlayAreaApi.ttslua index c141c61a..66784904 100644 --- a/src/core/PlayAreaApi.ttslua +++ b/src/core/PlayAreaApi.ttslua @@ -2,19 +2,18 @@ do local PlayAreaApi = { } local PLAY_AREA_GUID = "721ba2" - - local IMAGE_SWAPPER = "b7b45b" + local INVESTIGATOR_COUNTER_GUID = "f182ee" -- 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 @@ -90,7 +89,18 @@ do end PlayAreaApi.updateSurface = function(url) - return getObjectFromGUID(IMAGE_SWAPPER).call("updateSurface", url) + return getObjectFromGUID(PLAY_AREA_GUID).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 return PlayAreaApi diff --git a/src/core/PlayAreaSelector.ttslua b/src/core/PlayAreaSelector.ttslua index 0029c4fb..84749458 100644 --- a/src/core/PlayAreaSelector.ttslua +++ b/src/core/PlayAreaSelector.ttslua @@ -1,5 +1,5 @@ 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 = {} @@ -62,39 +62,16 @@ end -- click function for apply button function click_applySurface(_, _, isRightClick) - updateSurface(isRightClick and "" or self.getInputs()[1].value) + playAreaApi.updateSurface(isRightClick and "" or self.getInputs()[1].value) +end + +function updateSurface(newURL) + playAreaApi.updateSurface(newURL) end -- input function for the input box function none() end --- main function (can be called by other objects) -function updateSurface(newURL) - local playArea = getObjectFromGUID("721ba2") - local customInfo = playArea.getCustomObject() - - if newURL ~= "" and newURL ~= nil and newURL ~= DEFAULT_URL then - customInfo.image = newURL - broadcastToAll("New Playmat Image Applied", { 0.2, 0.9, 0.2 }) - else - customInfo.image = DEFAULT_URL - broadcastToAll("Default Playmat Image Applied", { 0.2, 0.9, 0.2 }) - end - - playArea.setCustomObject(customInfo) - - -- get custom data helper and call the playarea with it after reloading - local customDataHelper = playArea.getVar("customDataHelper") - local guid - - if customDataHelper then guid = customDataHelper.getGUID() end - playArea = playArea.reload() - - if guid ~= nil then - Wait.time(function() playArea.call("updateLocations", { guid }) end, 1) - end -end - -- creates the main button function createOpenCloseButton() buttonParameters.tooltip = (controlActive and "Close" or "Open") .. " Playmat Panel" diff --git a/src/core/VictoryDisplay.ttslua b/src/core/VictoryDisplay.ttslua index eaaebac8..ebdb9faf 100644 --- a/src/core/VictoryDisplay.ttslua +++ b/src/core/VictoryDisplay.ttslua @@ -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) diff --git a/src/core/token/TokenManager.ttslua b/src/core/token/TokenManager.ttslua index 235e8c58..7a8a2442 100644 --- a/src/core/token/TokenManager.ttslua +++ b/src/core/token/TokenManager.ttslua @@ -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 = 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 diff --git a/src/playercards/AllCardsBagApi.ttslua b/src/playercards/AllCardsBagApi.ttslua new file mode 100644 index 00000000..c9223331 --- /dev/null +++ b/src/playercards/AllCardsBagApi.ttslua @@ -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(id) + return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardById", {id = id}) + 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 + -- name String or string fragment to search for names + -- exact Whether the name match should be exact + AllCardsBagApi.getCardsByName = function(name, exact) + return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardsByName", {name = name, exact = exact}) + 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 + -- class: String class to retrieve ("Guardian", "Seeker", etc) + -- upgraded: 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(class, upgraded) + return getObjectFromGUID(ALL_CARDS_BAG_GUID).call("getCardsByClassAndLevel", {class = class, upgraded = upgraded}) + 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 \ No newline at end of file diff --git a/src/playercards/CardSearch.ttslua b/src/playercards/CardSearch.ttslua index 9c179f1d..fd4f7e3d 100644 --- a/src/playercards/CardSearch.ttslua +++ b/src/playercards/CardSearch.ttslua @@ -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(inputParameters.value, searchExact) if cardList == nil or #cardList == 0 then printToAll("No match found.", "Red") return diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index 03c09c3a..bc18d9d6 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -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 diff --git a/src/playercards/PlayerCardPanel.ttslua b/src/playercards/PlayerCardPanel.ttslua index 90e58924..135699ab 100644 --- a/src/playercards/PlayerCardPanel.ttslua +++ b/src/playercards/PlayerCardPanel.ttslua @@ -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(cardClass, 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(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).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 diff --git a/src/playercards/SpawnBag.ttslua b/src/playercards/SpawnBag.ttslua index d6cf00c6..5591ec53 100644 --- a/src/playercards/SpawnBag.ttslua +++ b/src/playercards/SpawnBag.ttslua @@ -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(cardId) if (cardData ~= nil) then table.insert(cardsToSpawn, cardData) else diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index ed9b74dd..ca349567 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -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) diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 39c51f86..84a1ffd0 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -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.