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
-- 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")
coWaitFrames(5)
end
@ -111,7 +111,28 @@ function importFromToken()
if objData.Nickname == "Additional Player Cards" then
local additionalIndex = guidReferenceApi.getObjectByOwnerAndType("Mythos", "AdditionalPlayerCardsBag")
if additionalIndex then
objData.GUID = additionalIndex.getGUID()
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()
end
else
@ -177,6 +198,14 @@ function importFromToken()
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
if importData["NavigationOverlayState"] then
navigationOverlayApi.loadData(importData["NavigationOverlayState"])
@ -291,6 +320,12 @@ function exportToToken()
dataToSave.slotData[matColor] = slotData
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
dataToSave.NavigationOverlayState = navigationOverlayApi.getSaveData()

View File

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