From d7f098fcc5ce6f7f49810e97888952e8af851e3e Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 1 Mar 2023 23:35:04 +0100 Subject: [PATCH] adding MythosAreaAPI --- src/accessories/TokenArranger.ttslua | 11 +++++------ src/accessories/TokenArrangerApi.ttslua | 8 ++------ src/core/MythosArea.ttslua | 12 +++++++++++- src/core/MythosAreaApi.ttslua | 11 +++++++++++ 4 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 src/core/MythosAreaApi.ttslua diff --git a/src/accessories/TokenArranger.ttslua b/src/accessories/TokenArranger.ttslua index 0fef4e24..f3f6ace5 100644 --- a/src/accessories/TokenArranger.ttslua +++ b/src/accessories/TokenArranger.ttslua @@ -1,3 +1,5 @@ +local mythosAreaApi = require("core/MythosAreaApi") + -- common parameters local buttonParameters = {} buttonParameters.function_owner = self @@ -89,10 +91,7 @@ function onLoad(saveState) end) -- grab token metadata from mythos area - local mythosArea = getObjectFromGUID("9f334f") - Wait.time(function() mythosArea.call("fireTokenDataChangedEvent") end, 0.5) - - Wait.time(layout, 2) + Wait.time(function() onTokenDataChanged(mythosAreaApi.returnTokenData()) end, 0.5) end -- delete temporary tokens when destroyed @@ -263,10 +262,10 @@ end function onTokenDataChanged(parameters) local tokenData = parameters.tokenData or {} local currentScenario = parameters.currentScenario or "" - local useFrontData = parameters.useFrontData or "true" + local useFrontData = parameters.useFrontData or true -- only update if this data is new - local info = currentScenario .. useFrontData + local info = currentScenario .. tostring(useFrontData) if latestLoad == info then return end latestLoad = info diff --git a/src/accessories/TokenArrangerApi.ttslua b/src/accessories/TokenArrangerApi.ttslua index 6df8298c..b61aee5f 100644 --- a/src/accessories/TokenArrangerApi.ttslua +++ b/src/accessories/TokenArrangerApi.ttslua @@ -13,12 +13,8 @@ do -- updates the token modifiers with the provided data ---@param tokenData Table Contains the chaos token metadata - TokenArrangerApi.onTokenDataChanged = function(tokenData, currentScenario, useFrontData) - callIfExistent("onTokenDataChanged", { - tokenData = tokenData, - currentScenario = currentScenario, - useFrontData = useFrontData - }) + TokenArrangerApi.onTokenDataChanged = function(fullData) + callIfExistent("onTokenDataChanged", fullData) end -- deletes already laid out tokens diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 1bf037e1..81bbd4f3 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -91,7 +91,17 @@ end -- fires if the scenario title or the difficulty changes function fireTokenDataChangedEvent() - tokenArrangerApi.onTokenDataChanged(tokenData, currentScenario, tostring(useFrontData)) + local fullData = returnTokenData() + tokenArrangerApi.onTokenDataChanged(fullData) +end + +-- returns the chaos token metadata (if provided) +function returnTokenData() + return { + tokenData = tokenData, + currentScenario = currentScenario, + useFrontData = useFrontData + } end -- Simple method to check if the given point is in a specified area. Local use only, diff --git a/src/core/MythosAreaApi.ttslua b/src/core/MythosAreaApi.ttslua new file mode 100644 index 00000000..cf26f065 --- /dev/null +++ b/src/core/MythosAreaApi.ttslua @@ -0,0 +1,11 @@ +do + local MythosAreaApi = {} + local MYTHOS_AREA_GUID = "9f334f" + + -- returns the chaos token metadata (if provided through scenario reference card) + MythosAreaApi.returnTokenData = function() + return getObjectFromGUID("9f334f").call("returnTokenData") + end + + return MythosAreaApi +end