more features

This commit is contained in:
Chr1Z93 2024-10-05 21:27:36 +02:00
parent aa635226d1
commit aa989d7b91
6 changed files with 65 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -85,6 +85,7 @@ local GuidReferences = {
RulesReference = "d99993",
SoundCube = "3c988f",
TokenArranger = "022907",
TokenRemover = "0a5a29",
TokenSource = "124381",
TokenSpawnTracker = "e3ffc9",
TourStarter = "0e5aa8",

View File

@ -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)

View File

@ -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