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

View File

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

View File

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

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,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)

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

View File

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

View File

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