store clean up helper settings

This commit is contained in:
Chr1Z93 2024-11-12 23:16:45 +01:00
parent 58dd1e79af
commit 1cbb7e2aa7
2 changed files with 36 additions and 11 deletions

View File

@ -177,6 +177,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 +299,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

@ -45,20 +45,30 @@ 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 end
function onLoad(savedData) function updateSave()
if savedData ~= nil then self.script_state = JSON.encode(getSaveData())
local loadedData = JSON.decode(savedData) end
-- loads data and updates the UI to match
function loadData(loadedData)
if not loadedData then return end
options = loadedData.options options = loadedData.options
-- update UI to match saved state
for id, state in pairs(options) do for id, state in pairs(options) do
self.UI.setAttribute(id, "image", state and "option_on" or "option_off") self.UI.setAttribute(id, "image", state and "option_on" or "option_off")
end end
end end
function onLoad(savedData)
if savedData ~= nil and savedData ~= "" then
loadData(JSON.decode(savedData))
end
-- index 0: button as label -- index 0: button as label
buttonParameters.label = "Clean Up Helper" buttonParameters.label = "Clean Up Helper"
buttonParameters.click_function = "none" buttonParameters.click_function = "none"
@ -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