Addressed the last of PR suggestions, fixing several issues with option panel importing

This commit is contained in:
Entrox-Licher 2023-06-19 01:46:11 -04:00
parent 609c54738e
commit ec28088945
3 changed files with 29 additions and 8 deletions

View File

@ -46,10 +46,10 @@ local DAMAGE_HORROR_GUIDS = {
"468e88"; "0257d9"; "7b5729"; "beb964"; "468e88"; "0257d9"; "7b5729"; "beb964";
} }
local deckImporterApi
local chaosBagApi local chaosBagApi
local playAreaAPI local playAreaAPI
local optionPanelApi
local deckImporterApi
local campaignBoxGUID local campaignBoxGUID
@ -57,13 +57,14 @@ function onLoad(save_state)
chaosBagApi = require("chaosbag/ChaosBagApi") chaosBagApi = require("chaosbag/ChaosBagApi")
playAreaAPI = require("core/PlayAreaApi") playAreaAPI = require("core/PlayAreaApi")
deckImporterApi = require("arkhamdb/DeckImporterApi") deckImporterApi = require("arkhamdb/DeckImporterApi")
optionPanelApi = require("core/OptionPanelApi")
campaignBoxGUID = "" campaignBoxGUID = ""
self.createButton({ self.createButton({
click_function = "findCampaignFromToken", click_function = "findCampaignFromToken",
function_owner = self, function_owner = self,
label = "Import", label = "Import",
tooltip = "Create a campaign save token!\n\n(Ensure all chaos tokens have been unsealed!)", tooltip = "Load in a campaign save from a token!\n\n(Token can be anywhere on the table, but ensure there is only 1!)",
position = {x=-1, y=0.2, z=0}, position = {x=-1, y=0.2, z=0},
font_size = 400, font_size = 400,
width = 1400, width = 1400,
@ -74,7 +75,7 @@ function onLoad(save_state)
click_function = "createCampaignToken", click_function = "createCampaignToken",
function_owner = self, function_owner = self,
label = "Export", label = "Export",
tooltip = "Load in a campaign save from a token!", tooltip = "Create a campaign save token!\n\n(Ensure all chaos tokens have been unsealed!)",
position = {x=1, y=0.2, z=0}, position = {x=1, y=0.2, z=0},
font_size = 400, font_size = 400,
width = 1400, width = 1400,
@ -167,7 +168,10 @@ function createCampaignFromToken(importData)
end end
) )
end end
Global.call("loadSettings", importData["options"]) Wait.time(
function() optionPanelApi.loadSettings(importData["options"]) end,
0.5
)
broadcastToAll("Campaign successfully imported!", Color.Green) broadcastToAll("Campaign successfully imported!", Color.Green)
end end
@ -217,7 +221,7 @@ function createCampaignToken(_, _, _)
decks = deckImporterApi.getUiState(), decks = deckImporterApi.getUiState(),
clueCount = playAreaAPI.getInvestigatorCount(), clueCount = playAreaAPI.getInvestigatorCount(),
guide = campaignGuidePage, guide = campaignGuidePage,
options = Global.getTable("optionPanel") options = optionPanelApi.getOptionPanel()
} }
campaignTokenData.GMNotes = JSON.encode(campaignData) campaignTokenData.GMNotes = JSON.encode(campaignData)
campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save" campaignTokenData.Nickname = os.date("%b %d ") .. getObjectFromGUID(campaignBoxGUID).getName() .. " Save"

View File

@ -550,7 +550,6 @@ end
function getChaosBagState() function getChaosBagState()
local tokens = {} local tokens = {}
local invertedTable = createChaosTokenNameLookupTable() local invertedTable = createChaosTokenNameLookupTable()
log(invertedTable)
local chaosbag = findChaosBag() local chaosbag = findChaosBag()
for _, v in ipairs(chaosbag.getObjects()) do for _, v in ipairs(chaosbag.getObjects()) do
@ -969,7 +968,9 @@ end
---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0}) ---@param rotation Vector Rotation of the object for spawning (default: {0, 270, 0})
---@return. GUID of the spawnedObj (or nil if object was removed) ---@return. GUID of the spawnedObj (or nil if object was removed)
function spawnOrRemoveHelper(state, name, position, rotation) function spawnOrRemoveHelper(state, name, position, rotation)
if state then if (type(state) == "table" and #state == 0) then
return removeHelperObject(name)
elseif state then
Player.getPlayers()[1].pingTable(position) Player.getPlayers()[1].pingTable(position)
return spawnHelperObject(name, position, rotation).getGUID() return spawnHelperObject(name, position, rotation).getGUID()
else else

View File

@ -0,0 +1,16 @@
do
local OptionPanelApi = {}
-- loads saved options
---@param options Table New options table
OptionPanelApi.loadSettings = function(options)
return Global.call("loadSettings", options)
end
-- returns option panel table
OptionPanelApi.getOptionPanel = function()
return Global.getTable("optionPanel")
end
return OptionPanelApi
end