diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 3f3ab79f..c8c30eb5 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -1,8 +1,8 @@ local blessCurseApi = require("chaosbag/BlessCurseManagerApi") local chaosBagApi = require("chaosbag/ChaosBagApi") local deckImporterApi = require("arkhamdb/DeckImporterApi") +local GlobalApi = require("core/GlobalApi") local guidReferenceApi = require("core/GUIDReferenceApi") -local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local playermatApi = require("playermat/PlayermatApi") @@ -30,11 +30,7 @@ local campaignTokenData = { MaterialIndex = 2, TypeIndex = 6, CustomShader = { - SpecularColor = { - r = 0.72, - g = 0.51, - b = 0.34 - }, + SpecularColor = { r = 0.72, g = 0.51, b = 0.34 }, SpecularIntensity = 0.4, SpecularSharpness = 7.0, FresnelStrength = 0.0 @@ -58,7 +54,8 @@ end function onObjectLeaveContainer(container) if container.hasTag("ImporterToken") then - broadcastToAll("Removing objects from the Save Coin bag will break functionality. Please return the removed objects.", "Yellow") + broadcastToAll( + "Removing objects from the Save Coin bag will break functionality. Please return the removed objects.", "Yellow") end end @@ -178,7 +175,7 @@ function restoreCampaignData(importData, coin) end end - Wait.time(function() optionPanelApi.loadSettings(importData["options"]) end, 0.5) + Wait.time(function() GlobalApi.loadOptionPanelSettings(importData["options"]) end, 0.5) -- destroy Tour Starter token local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter") @@ -231,15 +228,15 @@ function createCampaignToken(_, playerColor, _) chaosBagApi.releaseAllSealedTokens(playerColor) -- main data collection - campaignData.box = campaignBox.getGUID() - campaignData.bag = chaosBagApi.getChaosBagState() - campaignData.decks = deckImporterApi.getUiState() + campaignData.box = campaignBox.getGUID() + campaignData.bag = chaosBagApi.getChaosBagState() + campaignData.decks = deckImporterApi.getUiState() campaignData.clueCount = playAreaApi.getInvestigatorCount() - campaignData.playarea = playAreaApi.getSurface() - campaignData.options = optionPanelApi.getOptions() + campaignData.playarea = playAreaApi.getSurface() + campaignData.options = GlobalApi.getOptionPanelState() -- save campaign log if present - local campaignLog = findUniqueObjectWithTag("CampaignLog") + local campaignLog = findUniqueObjectWithTag("CampaignLog") if campaignLog then local logData = campaignLog.getData() logData.Locked = false diff --git a/src/core/DownloadBox.ttslua b/src/core/DownloadBox.ttslua index a0c3c742..3526b977 100644 --- a/src/core/DownloadBox.ttslua +++ b/src/core/DownloadBox.ttslua @@ -1,3 +1,5 @@ +local GlobalApi = require("core/GlobalApi") + function onLoad() -- make sure the model is loaded so that we can use the bounds Wait.condition(buttonCreation, function() return not self.loading_custom end) @@ -27,9 +29,8 @@ function buttonCreation() end function buttonClick_download(_, playerColor) - Global.call('placeholder_download', { - url = self.getGMNotes(), - player = playerColor and Player[playerColor] or nil, - replace = self.guid - }) + local url = self.getGMNotes() + local player = playerColor and Player[playerColor] or nil + local replace = self.guid + GlobalApi.placeholderDownload(url, player, replace) end diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index 7b99970e..1957cc37 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -1,8 +1,8 @@ local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") +local GlobalApi = require("core/GlobalApi") local guidReferenceApi = require("core/GUIDReferenceApi") local mythosAreaApi = require("core/MythosAreaApi") local navigationOverlayApi = require("core/NavigationOverlayApi") -local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local playermatApi = require("playermat/PlayermatApi") local searchLib = require("util/SearchLib") @@ -502,7 +502,7 @@ function takeClueFromLocation(playerColor, hoveredObject) return end - local clickableClues = optionPanelApi.getOptions()["useClueClickers"] + local clickableClues = GlobalApi.getOptionPanelState()["useClueClickers"] -- handling for calling this for a specific mat via hotkey local matColor, pos diff --git a/src/core/GlobalApi.ttslua b/src/core/GlobalApi.ttslua new file mode 100644 index 00000000..e40189ab --- /dev/null +++ b/src/core/GlobalApi.ttslua @@ -0,0 +1,28 @@ +do + local GlobalApi = {} + + function GlobalApi.placeholderDownload(url, player, replace) + Global.call("placeholder_download", { + url = url, + player = player, + replace = replace + }) + end + + function GlobalApi.titleSplash(scenarioName) + Global.call("titleSplash", scenarioName) + end + + -- loads saved options + ---@param options table Set a new state for the option table + function GlobalApi.loadOptionPanelSettings(options) + return Global.call("loadSettings", options) + end + + ---@return any: Table of option panel state + function GlobalApi.getOptionPanelState() + return Global.getTable("optionPanel") + end + + return GlobalApi +end diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 83a10cf6..c7e4e1d4 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -1,26 +1,27 @@ -local deckLib = require("util/DeckLib") -local guidReferenceApi = require("core/GUIDReferenceApi") -local playAreaApi = require("core/PlayAreaApi") -local playermatApi = require("playermat/PlayermatApi") -local searchLib = require("util/SearchLib") -local tokenArrangerApi = require("accessories/TokenArrangerApi") -local tokenChecker = require("core/token/TokenChecker") -local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") +local deckLib = require("util/DeckLib") +local GlobalApi = require("core/GlobalApi") +local guidReferenceApi = require("core/GUIDReferenceApi") +local playAreaApi = require("core/PlayAreaApi") +local playermatApi = require("playermat/PlayermatApi") +local searchLib = require("util/SearchLib") +local tokenArrangerApi = require("accessories/TokenArrangerApi") +local tokenChecker = require("core/token/TokenChecker") +local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") -local ENCOUNTER_DECK_AREA = { +local ENCOUNTER_DECK_AREA = { upperLeft = { x = 1.05, z = 0.15 }, lowerRight = { x = 0.70, z = 0.59 } } -local ENCOUNTER_DISCARD_AREA = { +local ENCOUNTER_DISCARD_AREA = { upperLeft = { x = 1.77, z = 0.15 }, lowerRight = { x = 1.42, z = 0.59 } } -- global position of encounter deck and discard pile -local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 } +local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 } local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1, z = 10.38 } -local isReshuffling = false -local collisionEnabled = false +local isReshuffling = false +local collisionEnabled = false local currentScenario, useFrontData, tokenData function onSave() @@ -108,7 +109,7 @@ end -- fires if the scenario title changes function fireScenarioChangedEvent() -- maybe show the title splash screen - Wait.frames(function() Global.call('titleSplash', currentScenario) end, 20) + Wait.frames(function() GlobalApi.titleSplash(currentScenario) end, 20) -- set the scenario for the playarea (connections might be disabled) playAreaApi.onScenarioChanged(currentScenario) diff --git a/src/core/OptionPanelApi.ttslua b/src/core/OptionPanelApi.ttslua deleted file mode 100644 index acca1fb4..00000000 --- a/src/core/OptionPanelApi.ttslua +++ /dev/null @@ -1,16 +0,0 @@ -do - local OptionPanelApi = {} - - -- loads saved options - ---@param options table Set a new state for the option table - OptionPanelApi.loadSettings = function(options) - return Global.call("loadSettings", options) - end - - ---@return any: Table of option panel state - OptionPanelApi.getOptions = function() - return Global.getTable("optionPanel") - end - - return OptionPanelApi -end \ No newline at end of file diff --git a/src/core/PlayAreaSelector.ttslua b/src/core/PlayAreaSelector.ttslua index 0824dde9..ef4b55a2 100644 --- a/src/core/PlayAreaSelector.ttslua +++ b/src/core/PlayAreaSelector.ttslua @@ -1,5 +1,5 @@ require("core/PlayAreaImageData") -- this fills the variable "PLAYAREA_IMAGE_DATA" -local optionPanelApi = require("core/OptionPanelApi") +local GlobalApi = require("core/GlobalApi") local playAreaApi = require("core/PlayAreaApi") local typeIndex, selectionIndex, plainNameCache @@ -155,7 +155,7 @@ end function maybeUpdatePlayAreaImage(scenarioName) -- check if option is enabled - local optionPanelState = optionPanelApi.getOptions() + local optionPanelState = GlobalApi.getOptionPanelState() if not optionPanelState["changePlayAreaImage"] then return end -- initialize cache if nil @@ -165,7 +165,7 @@ function maybeUpdatePlayAreaImage(scenarioName) for j, dataForCycle in pairs(dataForType) do for k, data in ipairs(dataForCycle) do local plainName = getPlainName(data.Name) - + -- override plainName for all images in the "Other Images" category (except the default image) if i == "Other Images" and data.Name ~= "Default Image" then plainName = "Generic" diff --git a/src/core/token/TokenManager.ttslua b/src/core/token/TokenManager.ttslua index 12e76422..bd0c5911 100644 --- a/src/core/token/TokenManager.ttslua +++ b/src/core/token/TokenManager.ttslua @@ -1,6 +1,6 @@ do + local GlobalApi = require("core/GlobalApi") local guidReferenceApi = require("core/GUIDReferenceApi") - local optionPanelApi = require("core/OptionPanelApi") local playAreaApi = require("core/PlayAreaApi") local playermatApi = require("playermat/PlayermatApi") local searchLib = require("util/SearchLib") @@ -91,7 +91,7 @@ do ---@param shiftDown? number An offset for the z-value of this group of tokens ---@param subType? string 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 = optionPanelApi.getOptions() + local optionPanel = GlobalApi.getOptionPanelState() if tokenType == "damage" or tokenType == "horror" then TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown) diff --git a/src/playercards/CardsWithHelper.ttslua b/src/playercards/CardsWithHelper.ttslua index dc67ee1b..5b1ea3c0 100644 --- a/src/playercards/CardsWithHelper.ttslua +++ b/src/playercards/CardsWithHelper.ttslua @@ -13,12 +13,12 @@ isHelperEnabled = false (default state of the helper, should be 'false') 2) In 'onLoad()'', call 'syncDisplayWithOptionPanel()' ----------------------------------------------------------]] -local optionPanelApi = require("core/OptionPanelApi") +local GlobalApi = require("core/GlobalApi") -- if the respective option is enabled in onLoad(), enable the helper function syncDisplayWithOptionPanel() self.addTag("CardWithHelper") - local options = optionPanelApi.getOptions() + local options = GlobalApi.getOptionPanelState() if options.enableCardHelpers then setHelperState(true) else