diff --git a/src/accessories/CampaignImporterExporter.ttslua b/src/accessories/CampaignImporterExporter.ttslua index b04af58a..7d596895 100644 --- a/src/accessories/CampaignImporterExporter.ttslua +++ b/src/accessories/CampaignImporterExporter.ttslua @@ -83,7 +83,7 @@ end --------------------------------------------------------- function importFromToken() - broadcastToAll("Campaign Import initiated") + broadcastToAll("Import initiated") local importData = JSON.decode(coin.getGMNotes()) -- import the campaign data @@ -194,8 +194,15 @@ function importFromToken() end end + -- enable Token Removers + if importData["enableTokenRemover"] then + for _, obj in ipairs(guidReferenceApi.getObjectsByType("TokenRemover")) do + obj.call("enable") + end + end + coin.destruct() - broadcastToAll("Campaign successfully imported!", "Green") + broadcastToAll("Import completed!", "Green") return 1 end @@ -206,7 +213,7 @@ end -- creates a campaign token with save data encoded into GM Notes based on the current state of the table function exportToToken() - broadcastToAll("Campaign Export initiated") + broadcastToAll("Export initiated") local dataToSave = {} @@ -294,15 +301,24 @@ function exportToToken() dataToSave.removePhaseTracker = true end + -- check if Token Removers are enabled + local tokenRemoverList = guidReferenceApi.getObjectsByType("TokenRemover") + if #tokenRemoverList > 0 then + local zoneGUID = tokenRemoverList[1].call("onSave") + if getObjectFromGUID(zoneGUID) ~= nil then + dataToSave.enableTokenRemover = true + end + end + -- finish the data for the campaign token saveTokenData.GMNotes = JSON.encode(dataToSave) - saveTokenData.Nickname = os.date("%Y-%m-%d") .. " Save" + saveTokenData.Nickname = os.date("%Y_%m_%d") .. " Save" if campaignBox then - saveTokenData.Nickname = saveTokenData.Nickname .. " " .. campaignBox.getName() + saveTokenData.Nickname = saveTokenData.Nickname .. " (" .. campaignBox.getName() .. ")" end spawnObjectData({ data = saveTokenData }) - broadcastToAll("Campaign successfully exported! Save coin object to import on a different save.", "Green") + broadcastToAll("Export completed! Save coin object to import on a different save.", "Green") return 1 end @@ -324,9 +340,9 @@ function findUniqueObjectWithTag(tag) if #objects == 1 then return objects[1] elseif #objects == 0 then - broadcastToAll("No " .. tag .. " detected; ensure it has the correct tag.", "Red") + broadcastToAll("No " .. tag .. " detected; ensure it has the correct tag.", "Orange") else - broadcastToAll("More than one " .. tag .. " detected; delete all but one.", "Red") + broadcastToAll("More than one " .. tag .. " detected; delete all but one.", "Orange") end end diff --git a/src/accessories/TokenArranger.ttslua b/src/accessories/TokenArranger.ttslua index c1fedbab..69d9eae5 100644 --- a/src/accessories/TokenArranger.ttslua +++ b/src/accessories/TokenArranger.ttslua @@ -63,7 +63,7 @@ function loadData(loadedData) includeDrawnTokens = loadedData.includeDrawnTokens updateUI() - layout() + Wait.time(layout, 1.5) end -- saving the precedence settings and information on the most recently loaded data diff --git a/src/accessories/TokenArrangerApi.ttslua b/src/accessories/TokenArrangerApi.ttslua index cf381905..728f101b 100644 --- a/src/accessories/TokenArrangerApi.ttslua +++ b/src/accessories/TokenArrangerApi.ttslua @@ -2,13 +2,27 @@ do local TokenArrangerApi = {} local guidReferenceApi = require("core/GUIDReferenceApi") + -- internal function to create a copy of the table to avoid operating on variables owned by different objects + local function deepCopy(data) + if type(data) ~= "table" then return data end + local copiedList = {} + for key, value in pairs(data) do + if type(value) == "table" then + copiedList[key] = deepCopy(value) + else + copiedList[key] = value + end + end + return copiedList + end + -- local function to call the token arranger, if it is on the table ---@param functionName string Name of the function to cal ---@param argument? table Parameter to pass local function callIfExistent(functionName, argument) local tokenArranger = guidReferenceApi.getObjectByOwnerAndType("Mythos", "TokenArranger") if tokenArranger ~= nil then - tokenArranger.call(functionName, argument) + return tokenArranger.call(functionName, argument) end end @@ -29,7 +43,7 @@ do end TokenArrangerApi.getSaveData = function() - return callIfExistent("getSaveData") + return deepCopy(callIfExistent("getSaveData")) end TokenArrangerApi.loadData = function(loadedData) diff --git a/src/core/GUIDReferenceHandler.ttslua b/src/core/GUIDReferenceHandler.ttslua index 92359c2a..a273cf3b 100644 --- a/src/core/GUIDReferenceHandler.ttslua +++ b/src/core/GUIDReferenceHandler.ttslua @@ -85,6 +85,7 @@ local GuidReferences = { RulesReference = "d99993", SoundCube = "3c988f", TokenArranger = "022907", + TokenRemover = "0a5a29", TokenSource = "124381", TokenSpawnTracker = "e3ffc9", TourStarter = "0e5aa8", diff --git a/src/core/NavigationOverlayApi.ttslua b/src/core/NavigationOverlayApi.ttslua index ab396a8b..5b9bfefe 100644 --- a/src/core/NavigationOverlayApi.ttslua +++ b/src/core/NavigationOverlayApi.ttslua @@ -6,6 +6,20 @@ do return guidReferenceApi.getObjectByOwnerAndType("Mythos", "NavigationOverlayHandler") end + -- internal function to create a copy of the table to avoid operating on variables owned by different objects + local function deepCopy(data) + if type(data) ~= "table" then return data end + local copiedList = {} + for key, value in pairs(data) do + if type(value) == "table" then + copiedList[key] = deepCopy(value) + else + copiedList[key] = value + end + end + return copiedList + end + -- copies the visibility for the Navigation overlay ---@param startColor string Color of the player to copy from ---@param targetColor string Color of the targeted player @@ -33,7 +47,7 @@ do end NavigationOverlayApi.getSaveData = function() - return getNOHandler().call("getSaveData") + return deepCopy(getNOHandler().call("getSaveData")) end NavigationOverlayApi.loadData = function(loadedData) diff --git a/src/util/TokenRemover.ttslua b/src/util/TokenRemover.ttslua index fe71d950..fb08c072 100644 --- a/src/util/TokenRemover.ttslua +++ b/src/util/TokenRemover.ttslua @@ -1,6 +1,3 @@ -local zone - --- general code function onSave() return JSON.encode(zone and zone.getGUID()) end @@ -12,8 +9,11 @@ function onLoad(savedData) setMenu(zone == nil) end --- context menu functions function enable() + if zone ~= nil then + zone.destruct() + end + local scale = self.getScale() zone = spawnObject({ type = "ScriptingTrigger", @@ -26,11 +26,13 @@ function enable() end function disable() - if zone ~= nil then zone.destruct() end + if zone ~= nil then + zone.destruct() + zone = nil + end setMenu(true) end --- core functions function setMenu(isEnabled) self.clearContextMenu() if isEnabled then