55 lines
1.7 KiB
Lua
55 lines
1.7 KiB
Lua
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
|
|
return tokenArranger.call(functionName, argument)
|
|
end
|
|
end
|
|
|
|
-- updates the token modifiers with the provided data
|
|
---@param fullData table Contains the chaos token metadata
|
|
TokenArrangerApi.onTokenDataChanged = function(fullData)
|
|
callIfExistent("onTokenDataChanged", fullData)
|
|
end
|
|
|
|
-- deletes already laid out tokens
|
|
TokenArrangerApi.deleteCopiedTokens = function()
|
|
callIfExistent("deleteCopiedTokens")
|
|
end
|
|
|
|
-- updates the laid out tokens
|
|
TokenArrangerApi.layout = function()
|
|
Wait.time(function() callIfExistent("layout") end, 0.1)
|
|
end
|
|
|
|
TokenArrangerApi.getSaveData = function()
|
|
return deepCopy(callIfExistent("getSaveData"))
|
|
end
|
|
|
|
TokenArrangerApi.loadData = function(loadedData)
|
|
callIfExistent("loadData", loadedData)
|
|
end
|
|
|
|
return TokenArrangerApi
|
|
end
|