first step of GlobalApi

This commit is contained in:
Chr1Z93 2024-08-03 20:08:17 +02:00
parent 0a7dd79199
commit 82344361df
9 changed files with 69 additions and 58 deletions

View File

@ -1,8 +1,8 @@
local blessCurseApi = require("chaosbag/BlessCurseManagerApi") local blessCurseApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi") local chaosBagApi = require("chaosbag/ChaosBagApi")
local deckImporterApi = require("arkhamdb/DeckImporterApi") local deckImporterApi = require("arkhamdb/DeckImporterApi")
local GlobalApi = require("core/GlobalApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
@ -30,11 +30,7 @@ local campaignTokenData = {
MaterialIndex = 2, MaterialIndex = 2,
TypeIndex = 6, TypeIndex = 6,
CustomShader = { CustomShader = {
SpecularColor = { SpecularColor = { r = 0.72, g = 0.51, b = 0.34 },
r = 0.72,
g = 0.51,
b = 0.34
},
SpecularIntensity = 0.4, SpecularIntensity = 0.4,
SpecularSharpness = 7.0, SpecularSharpness = 7.0,
FresnelStrength = 0.0 FresnelStrength = 0.0
@ -58,7 +54,8 @@ end
function onObjectLeaveContainer(container) function onObjectLeaveContainer(container)
if container.hasTag("ImporterToken") then 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
end end
@ -178,7 +175,7 @@ function restoreCampaignData(importData, coin)
end end
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 -- destroy Tour Starter token
local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter") local tourStarter = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TourStarter")
@ -236,7 +233,7 @@ function createCampaignToken(_, playerColor, _)
campaignData.decks = deckImporterApi.getUiState() campaignData.decks = deckImporterApi.getUiState()
campaignData.clueCount = playAreaApi.getInvestigatorCount() campaignData.clueCount = playAreaApi.getInvestigatorCount()
campaignData.playarea = playAreaApi.getSurface() campaignData.playarea = playAreaApi.getSurface()
campaignData.options = optionPanelApi.getOptions() campaignData.options = GlobalApi.getOptionPanelState()
-- save campaign log if present -- save campaign log if present
local campaignLog = findUniqueObjectWithTag("CampaignLog") local campaignLog = findUniqueObjectWithTag("CampaignLog")

View File

@ -1,3 +1,5 @@
local GlobalApi = require("core/GlobalApi")
function onLoad() function onLoad()
-- make sure the model is loaded so that we can use the bounds -- make sure the model is loaded so that we can use the bounds
Wait.condition(buttonCreation, function() return not self.loading_custom end) Wait.condition(buttonCreation, function() return not self.loading_custom end)
@ -27,9 +29,8 @@ function buttonCreation()
end end
function buttonClick_download(_, playerColor) function buttonClick_download(_, playerColor)
Global.call('placeholder_download', { local url = self.getGMNotes()
url = self.getGMNotes(), local player = playerColor and Player[playerColor] or nil
player = playerColor and Player[playerColor] or nil, local replace = self.guid
replace = self.guid GlobalApi.placeholderDownload(url, player, replace)
})
end end

View File

@ -1,8 +1,8 @@
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local GlobalApi = require("core/GlobalApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local mythosAreaApi = require("core/MythosAreaApi") local mythosAreaApi = require("core/MythosAreaApi")
local navigationOverlayApi = require("core/NavigationOverlayApi") local navigationOverlayApi = require("core/NavigationOverlayApi")
local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
@ -502,7 +502,7 @@ function takeClueFromLocation(playerColor, hoveredObject)
return return
end end
local clickableClues = optionPanelApi.getOptions()["useClueClickers"] local clickableClues = GlobalApi.getOptionPanelState()["useClueClickers"]
-- handling for calling this for a specific mat via hotkey -- handling for calling this for a specific mat via hotkey
local matColor, pos local matColor, pos

28
src/core/GlobalApi.ttslua Normal file
View File

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

View File

@ -1,4 +1,5 @@
local deckLib = require("util/DeckLib") local deckLib = require("util/DeckLib")
local GlobalApi = require("core/GlobalApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
@ -108,7 +109,7 @@ end
-- fires if the scenario title changes -- fires if the scenario title changes
function fireScenarioChangedEvent() function fireScenarioChangedEvent()
-- maybe show the title splash screen -- 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) -- set the scenario for the playarea (connections might be disabled)
playAreaApi.onScenarioChanged(currentScenario) playAreaApi.onScenarioChanged(currentScenario)

View File

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

View File

@ -1,5 +1,5 @@
require("core/PlayAreaImageData") -- this fills the variable "PLAYAREA_IMAGE_DATA" 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 playAreaApi = require("core/PlayAreaApi")
local typeIndex, selectionIndex, plainNameCache local typeIndex, selectionIndex, plainNameCache
@ -155,7 +155,7 @@ end
function maybeUpdatePlayAreaImage(scenarioName) function maybeUpdatePlayAreaImage(scenarioName)
-- check if option is enabled -- check if option is enabled
local optionPanelState = optionPanelApi.getOptions() local optionPanelState = GlobalApi.getOptionPanelState()
if not optionPanelState["changePlayAreaImage"] then return end if not optionPanelState["changePlayAreaImage"] then return end
-- initialize cache if nil -- initialize cache if nil

View File

@ -1,6 +1,6 @@
do do
local GlobalApi = require("core/GlobalApi")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local optionPanelApi = require("core/OptionPanelApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playermatApi = require("playermat/PlayermatApi") local playermatApi = require("playermat/PlayermatApi")
local searchLib = require("util/SearchLib") 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 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 ---@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) TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown, subType)
local optionPanel = optionPanelApi.getOptions() local optionPanel = GlobalApi.getOptionPanelState()
if tokenType == "damage" or tokenType == "horror" then if tokenType == "damage" or tokenType == "horror" then
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown) TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)

View File

@ -13,12 +13,12 @@ isHelperEnabled = false (default state of the helper, should be 'false')
2) In 'onLoad()'', call 'syncDisplayWithOptionPanel()' 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 -- if the respective option is enabled in onLoad(), enable the helper
function syncDisplayWithOptionPanel() function syncDisplayWithOptionPanel()
self.addTag("CardWithHelper") self.addTag("CardWithHelper")
local options = optionPanelApi.getOptions() local options = GlobalApi.getOptionPanelState()
if options.enableCardHelpers then if options.enableCardHelpers then
setHelperState(true) setHelperState(true)
else else