Merge pull request #981 from argonui/importer-exporter

Updated Campaign Importer/Exporter
This commit is contained in:
dscarpac 2024-11-17 09:46:20 -06:00 committed by GitHub
commit d8639aff3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 12 deletions

View File

@ -97,7 +97,7 @@ function importFromToken()
end end
-- trigger the place function of the memory bag -- trigger the place function of the memory bag
if campaignBox and #campaignBox.getObjects() > 0 then if campaignBox and campaignBox.type == "Bag" and #campaignBox.getObjects() > 0 then
campaignBox.call("buttonClick_place") campaignBox.call("buttonClick_place")
coWaitFrames(5) coWaitFrames(5)
end end
@ -111,7 +111,28 @@ function importFromToken()
if objData.Nickname == "Additional Player Cards" then if objData.Nickname == "Additional Player Cards" then
local additionalIndex = guidReferenceApi.getObjectByOwnerAndType("Mythos", "AdditionalPlayerCardsBag") local additionalIndex = guidReferenceApi.getObjectByOwnerAndType("Mythos", "AdditionalPlayerCardsBag")
if additionalIndex then if additionalIndex then
objData.GUID = additionalIndex.getGUID()
spawnData.position = additionalIndex.getPosition() spawnData.position = additionalIndex.getPosition()
-- merge contained objects
local existingIndexData = additionalIndex.getData()
objData.ContainedObjects = objData.ContainedObjects or {}
-- lookup table by Nickname
local containedObjectLookUp = {}
for _, deepData in ipairs(objData.ContainedObjects) do
if deepData.Nickname ~= "" then
containedObjectLookUp[deepData.Nickname] = true
end
end
-- add existing objects to new box
for _, deepData in ipairs(existingIndexData.ContainedObjects or {}) do
if deepData.Nickname ~= "" and containedObjectLookUp[deepData.Nickname] ~= true then
table.insert(objData.ContainedObjects, deepData)
end
end
additionalIndex.destruct() additionalIndex.destruct()
end end
else else
@ -177,6 +198,14 @@ function importFromToken()
end end
end end
-- restore Clean Up Helper state
if importData["CleanUpHelperState"] then
local cleanUpHelper = guidReferenceApi.getObjectByOwnerAndType("Mythos", "CleanUpHelper")
if cleanUpHelper ~= nil then
cleanUpHelper.call("loadData", importData["CleanUpHelperState"])
end
end
-- restore Navigation Overlay state -- restore Navigation Overlay state
if importData["NavigationOverlayState"] then if importData["NavigationOverlayState"] then
navigationOverlayApi.loadData(importData["NavigationOverlayState"]) navigationOverlayApi.loadData(importData["NavigationOverlayState"])
@ -291,6 +320,12 @@ function exportToToken()
dataToSave.slotData[matColor] = slotData dataToSave.slotData[matColor] = slotData
end end
-- get Clean Up Helper settings
local cleanUpHelper = guidReferenceApi.getObjectByOwnerAndType("Mythos", "CleanUpHelper")
if cleanUpHelper ~= nil then
dataToSave.CleanUpHelperState = cleanUpHelper.call("getSaveData", {})
end
-- get Navigation Overlay settings -- get Navigation Overlay settings
dataToSave.NavigationOverlayState = navigationOverlayApi.getSaveData() dataToSave.NavigationOverlayState = navigationOverlayApi.getSaveData()

View File

@ -22,8 +22,8 @@ local RESET_VALUES = {}
local loadingFailedBefore = false local loadingFailedBefore = false
local optionsVisible = false local optionsVisible = false
local options = { local options = {
["importTrauma"] = true, ["importTrauma"] = true,
["tidyPlayermats"] = true, ["tidyPlayermats"] = true,
["removeDrawnLines"] = false ["removeDrawnLines"] = false
} }
local removeIgnoreLater = {} local removeIgnoreLater = {}
@ -45,18 +45,28 @@ buttonParameters.function_owner = self
-- option loading and GUI setup -- option loading and GUI setup
--------------------------------------------------------- ---------------------------------------------------------
function onSave() function getSaveData()
return JSON.encode({ options = options }) return { options = options }
end
function updateSave()
self.script_state = JSON.encode(getSaveData())
end
-- loads data and updates the UI to match
function loadData(loadedData)
if not loadedData then return end
options = loadedData.options
for id, state in pairs(options) do
self.UI.setAttribute(id, "image", state and "option_on" or "option_off")
end
end end
function onLoad(savedData) function onLoad(savedData)
if savedData ~= nil then if savedData ~= nil and savedData ~= "" then
local loadedData = JSON.decode(savedData) loadData(JSON.decode(savedData))
options = loadedData.options
-- update UI to match saved state
for id, state in pairs(options) do
self.UI.setAttribute(id, "image", state and "option_on" or "option_off")
end
end end
-- index 0: button as label -- index 0: button as label
@ -98,6 +108,7 @@ function optionButtonClick(_, id)
local newState = (currentState and "option_off" or "option_on") local newState = (currentState and "option_off" or "option_on")
options[id] = not currentState options[id] = not currentState
self.UI.setAttribute(id, "image", newState) self.UI.setAttribute(id, "image", newState)
updateSave()
end end
-- shows or hides the option panel -- shows or hides the option panel