From dfbbff0b9191a58f96c332bdc9e29c1292dc3813 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 30 Jul 2023 03:05:13 +0200 Subject: [PATCH 1/6] utilization of returnTrauma function in campaignlogs --- src/accessories/CleanUpHelper.ttslua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index d719d488..9bf710dc 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -254,15 +254,19 @@ function getTrauma() printToAll("Default values for health and sanity loaded.", "Yellow") return end + campaignLog = campaignLog.hit_object + + -- set campaign log to first state + local stateId = campaignLog.getStateId() + if stateId ~= 1 then + campaignLog.setState(1) + end -- get data from campaign log if possible - local counterData = campaignLog.hit_object.getVar("ref_buttonData") - if counterData ~= nil then + local trauma = campaignLog.getVar("returnTrauma") + if trauma ~= nil then printToAll("Trauma values found in campaign log!", "Green") - for i = 1, 10, 3 do - RESET_VALUES[1 + (i - 1) / 3] = counterData.counter[i].value - RESET_VALUES[5 + (i - 1) / 3] = counterData.counter[i + 1].value - end + RESET_VALUES = campaignLog.call("returnTrauma") else printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow") From 5a14ec4346608748cb66459be698dac5f6e4ecf1 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 30 Jul 2023 03:09:07 +0200 Subject: [PATCH 2/6] bugfix --- src/accessories/CleanUpHelper.ttslua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 9bf710dc..0683229b 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -259,7 +259,7 @@ function getTrauma() -- set campaign log to first state local stateId = campaignLog.getStateId() if stateId ~= 1 then - campaignLog.setState(1) + campaignLog = campaignLog.setState(1) end -- get data from campaign log if possible From 6f0073459a1b9465304b8e21a6a02a09807897fc Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 30 Jul 2023 03:23:27 +0200 Subject: [PATCH 3/6] added delay to account for state loading --- src/accessories/CleanUpHelper.ttslua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 0683229b..cecd053e 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -34,6 +34,7 @@ local DAMAGE_HORROR_GUIDS = { "468e88", "0257d9", "7b5729", "beb964", } +local campaignLog local RESET_VALUES = {} -- GUIDS of objects (in order of ownership relating to 'COLORS') @@ -164,7 +165,6 @@ function cleanUp(_, color) soundCubeApi.playSoundByName("Vacuum") ignoreCustomDataHelper() getTrauma() - updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror") updateCounters(RESOURCE_GUIDS, 5, "Resources") updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clickers") resetSkillTrackers() @@ -248,7 +248,7 @@ function getTrauma() end -- get campaign log - local campaignLog = findObjects(6)[1] + campaignLog = findObjects(6)[1] if campaignLog == nil then printToAll("Campaign log not found in standard position!", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow") @@ -262,11 +262,18 @@ function getTrauma() campaignLog = campaignLog.setState(1) end - -- get data from campaign log if possible + -- small delay to account for potential state change + Wait.time(loadTrauma, 0.1) +end + +-- gets data from campaign log if possible +function loadTrauma() + -- check if "returnTrauma" function exists to avoid calling nil local trauma = campaignLog.getVar("returnTrauma") if trauma ~= nil then printToAll("Trauma values found in campaign log!", "Green") RESET_VALUES = campaignLog.call("returnTrauma") + updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror") else printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow") From 8a64f762ad0a69274ee6062b01cee6d3776a9231 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 2 Aug 2023 11:09:54 +0200 Subject: [PATCH 4/6] added variable name --- src/accessories/CleanUpHelper.ttslua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index cecd053e..5b997650 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -263,7 +263,8 @@ function getTrauma() end -- small delay to account for potential state change - Wait.time(loadTrauma, 0.1) + local spawnDelay = 0.1 + Wait.time(loadTrauma, spawnDelay) end -- gets data from campaign log if possible From 5bf34b8cdbbbf022da48c6176564b1866363967c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 28 Aug 2023 11:44:20 +0200 Subject: [PATCH 5/6] account for multiple pages with trauma values --- src/accessories/CleanUpHelper.ttslua | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index a3b959db..ee9662bd 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -1,5 +1,4 @@ ---[[ -Cleans up the table for the next scenario in a campaign: +--[[ Cleans up the table for the next scenario in a campaign: - sets counters to default values (resources and doom) or trauma values (health and sanity, if not disabled) from campaign log - puts everything on playmats and hands into respective trashcans - use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")]] @@ -57,7 +56,14 @@ local PHYSICS_POSITION = { { -00.0, 2, -27 } } -local PHYSICS_ROTATION = { 270, 270, 0, 180, 270, 0 } +local PHYSICS_ROTATION = { + 270, + 270, + 0, + 180, + 270, + 0 +} local PHYSICS_SCALE = { { 36.6, 1, 14.5 }, @@ -77,6 +83,8 @@ options["removeDrawnLines"] = false local buttonParameters = {} buttonParameters.function_owner = self +local loadingFailedBefore = false + --------------------------------------------------------- -- option loading and GUI setup --------------------------------------------------------- @@ -256,16 +264,7 @@ function getTrauma() return end campaignLog = campaignLog.hit_object - - -- set campaign log to first state - local stateId = campaignLog.getStateId() - if stateId ~= 1 then - campaignLog = campaignLog.setState(1) - end - - -- small delay to account for potential state change - local spawnDelay = 0.1 - Wait.time(loadTrauma, spawnDelay) + loadTrauma() end -- gets data from campaign log if possible @@ -276,9 +275,21 @@ function loadTrauma() printToAll("Trauma values found in campaign log!", "Green") RESET_VALUES = campaignLog.call("returnTrauma") updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror") - else + loadingFailedBefore = false + elseif loadingFailedBefore then printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow") + loadingFailedBefore = false + else + -- set campaign log to first state + local stateId = campaignLog.getStateId() + if stateId ~= 1 then + campaignLog = campaignLog.setState(1) + end + loadingFailedBefore = true + -- small delay to account for potential state change + local spawnDelay = 0.1 + Wait.time(loadTrauma, spawnDelay) end end From e85d5bc05d87e3dd3c510cd7788520d80970123c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 6 Sep 2023 10:15:59 +0200 Subject: [PATCH 6/6] script update --- src/accessories/CleanUpHelper.ttslua | 45 +++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index ee9662bd..4200bf7a 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -175,8 +175,14 @@ function cleanUp(_, color) soundCubeApi.playSoundByName("Vacuum") ignoreCustomDataHelper() getTrauma() - updateCounters(RESOURCE_GUIDS, 5, "Resources") - updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clickers") + + -- delay to account for potential state change + Wait.time(function() + updateCounters(RESOURCE_GUIDS, 5, "Resource") + updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clicker") + updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror") + end, 0.2) + resetSkillTrackers() resetDoomCounter() blessCurseManagerApi.removeAll(color) @@ -193,20 +199,16 @@ end -- modular functions, called by other functions --------------------------------------------------------- -function updateCounters(tableOfGUIDs, tableOfNewValues, info) - if tonumber(tableOfNewValues) then - local value = tableOfNewValues - tableOfNewValues = {} - for i = 1, #tableOfGUIDs do - table.insert(tableOfNewValues, value) - end - end +function updateCounters(tableOfGUIDs, newValues, info) + -- instead of a table, this will be used if just a single value is provided + local singleValue = tonumber(newValues) for i, guid in ipairs(tableOfGUIDs) do local TOKEN = getObjectFromGUID(guid) + local newValue = singleValue or newValues[i] if TOKEN ~= nil then - TOKEN.call("updateVal", tableOfNewValues[i]) + TOKEN.call("updateVal", newValue) else printToAll(info .. ": No. " .. i .. " could not be found.", "Yellow") end @@ -228,10 +230,10 @@ end -- reset doom on agenda function resetDoomCounter() - local doomcounter = getObjectFromGUID("85c4c6") + local doomCounter = getObjectFromGUID("85c4c6") - if doomcounter ~= nil then - doomcounter.call("updateVal") + if doomCounter ~= nil then + doomCounter.call("updateVal") else printToAll("Doom counter could not be found.", "Yellow") end @@ -240,7 +242,9 @@ end -- gets the GUID of a custom data helper (if present) and adds it to the ignore list function ignoreCustomDataHelper() local customDataHelper = playAreaApi.getCustomDataHelper() - if customDataHelper then table.insert(IGNORE_GUIDS, customDataHelper.getGUID()) end + if customDataHelper then + table.insert(IGNORE_GUIDS, customDataHelper.getGUID()) + end end -- read values for trauma from campaign log if enabled @@ -271,25 +275,26 @@ end function loadTrauma() -- check if "returnTrauma" function exists to avoid calling nil local trauma = campaignLog.getVar("returnTrauma") + if trauma ~= nil then printToAll("Trauma values found in campaign log!", "Green") RESET_VALUES = campaignLog.call("returnTrauma") - updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror") - loadingFailedBefore = false + loadingFailedBefore = false elseif loadingFailedBefore then printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow") - loadingFailedBefore = false + loadingFailedBefore = false else -- set campaign log to first state local stateId = campaignLog.getStateId() + if stateId ~= 1 then campaignLog = campaignLog.setState(1) end loadingFailedBefore = true + -- small delay to account for potential state change - local spawnDelay = 0.1 - Wait.time(loadTrauma, spawnDelay) + Wait.time(loadTrauma, 0.1) end end