From 58dd1e79af560cfce04fa180c65ec22cae8b74c6 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 12 Nov 2024 23:03:44 +0100 Subject: [PATCH 1/3] fixed handling for non-downloaded campaign boxes --- src/accessories/CampaignImporterExporter.ttslua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index d08ba39d..167b73c4 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -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 From 1cbb7e2aa7e8e22ff66725c6814cb4e6b6e94eda Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 12 Nov 2024 23:16:45 +0100 Subject: [PATCH 2/3] store clean up helper settings --- .../CampaignImporterExporter.ttslua | 14 ++++++++ src/accessories/CleanUpHelper.ttslua | 33 ++++++++++++------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index 167b73c4..f554da87 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -177,6 +177,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 +299,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() diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index aa24f127..b4620aa4 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -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 From 2d1de89ab0271be4bf934951a761d52737c0d133 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 12 Nov 2024 23:25:51 +0100 Subject: [PATCH 3/3] merge additional player cards --- .../CampaignImporterExporter.ttslua | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index f554da87..656bbd48 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -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