Merge pull request #340 from argonui/clean-up-helper

Clean Up Helper: updated trauma getting
This commit is contained in:
BootleggerFinn 2023-09-25 20:00:03 -05:00 committed by GitHub
commit df32b9942d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 - 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 - puts everything on playmats and hands into respective trashcans
- use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")]] - use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")]]
@ -36,6 +35,7 @@ local DAMAGE_HORROR_GUIDS = {
"468e88", "0257d9", "7b5729", "beb964", "468e88", "0257d9", "7b5729", "beb964",
} }
local campaignLog
local RESET_VALUES = {} local RESET_VALUES = {}
-- GUIDS of objects (in order of ownership relating to 'COLORS') -- GUIDS of objects (in order of ownership relating to 'COLORS')
@ -56,7 +56,14 @@ local PHYSICS_POSITION = {
{ -00.0, 2, -27 } { -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 = { local PHYSICS_SCALE = {
{ 36.6, 1, 14.5 }, { 36.6, 1, 14.5 },
@ -76,6 +83,8 @@ options["removeDrawnLines"] = false
local buttonParameters = {} local buttonParameters = {}
buttonParameters.function_owner = self buttonParameters.function_owner = self
local loadingFailedBefore = false
--------------------------------------------------------- ---------------------------------------------------------
-- option loading and GUI setup -- option loading and GUI setup
--------------------------------------------------------- ---------------------------------------------------------
@ -166,9 +175,14 @@ function cleanUp(_, color)
soundCubeApi.playSoundByName("Vacuum") soundCubeApi.playSoundByName("Vacuum")
ignoreCustomDataHelper() ignoreCustomDataHelper()
getTrauma() getTrauma()
updateCounters(DAMAGE_HORROR_GUIDS, RESET_VALUES, "Damage / Horror")
updateCounters(RESOURCE_GUIDS, 5, "Resources") -- delay to account for potential state change
updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clickers") 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() resetSkillTrackers()
resetDoomCounter() resetDoomCounter()
blessCurseManagerApi.removeAll(color) blessCurseManagerApi.removeAll(color)
@ -185,20 +199,16 @@ end
-- modular functions, called by other functions -- modular functions, called by other functions
--------------------------------------------------------- ---------------------------------------------------------
function updateCounters(tableOfGUIDs, tableOfNewValues, info) function updateCounters(tableOfGUIDs, newValues, info)
if tonumber(tableOfNewValues) then -- instead of a table, this will be used if just a single value is provided
local value = tableOfNewValues local singleValue = tonumber(newValues)
tableOfNewValues = {}
for i = 1, #tableOfGUIDs do
table.insert(tableOfNewValues, value)
end
end
for i, guid in ipairs(tableOfGUIDs) do for i, guid in ipairs(tableOfGUIDs) do
local TOKEN = getObjectFromGUID(guid) local TOKEN = getObjectFromGUID(guid)
local newValue = singleValue or newValues[i]
if TOKEN ~= nil then if TOKEN ~= nil then
TOKEN.call("updateVal", tableOfNewValues[i]) TOKEN.call("updateVal", newValue)
else else
printToAll(info .. ": No. " .. i .. " could not be found.", "Yellow") printToAll(info .. ": No. " .. i .. " could not be found.", "Yellow")
end end
@ -220,10 +230,10 @@ end
-- reset doom on agenda -- reset doom on agenda
function resetDoomCounter() function resetDoomCounter()
local doomcounter = getObjectFromGUID("85c4c6") local doomCounter = getObjectFromGUID("85c4c6")
if doomcounter ~= nil then if doomCounter ~= nil then
doomcounter.call("updateVal") doomCounter.call("updateVal")
else else
printToAll("Doom counter could not be found.", "Yellow") printToAll("Doom counter could not be found.", "Yellow")
end end
@ -232,7 +242,9 @@ end
-- gets the GUID of a custom data helper (if present) and adds it to the ignore list -- gets the GUID of a custom data helper (if present) and adds it to the ignore list
function ignoreCustomDataHelper() function ignoreCustomDataHelper()
local customDataHelper = playAreaApi.getCustomDataHelper() 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 end
-- read values for trauma from campaign log if enabled -- read values for trauma from campaign log if enabled
@ -249,24 +261,40 @@ function getTrauma()
end end
-- get campaign log -- get campaign log
local campaignLog = findObjects(6)[1] campaignLog = findObjects(6)[1]
if campaignLog == nil then if campaignLog == nil then
printToAll("Campaign log not found in standard position!", "Yellow") printToAll("Campaign log not found in standard position!", "Yellow")
printToAll("Default values for health and sanity loaded.", "Yellow") printToAll("Default values for health and sanity loaded.", "Yellow")
return return
end end
campaignLog = campaignLog.hit_object
loadTrauma()
end
-- get data from campaign log if possible -- gets data from campaign log if possible
local counterData = campaignLog.hit_object.getVar("ref_buttonData") function loadTrauma()
if counterData ~= nil then -- 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") printToAll("Trauma values found in campaign log!", "Green")
for i = 1, 10, 3 do RESET_VALUES = campaignLog.call("returnTrauma")
RESET_VALUES[1 + (i - 1) / 3] = counterData.counter[i].value loadingFailedBefore = false
RESET_VALUES[5 + (i - 1) / 3] = counterData.counter[i + 1].value elseif loadingFailedBefore then
end
else
printToAll("Trauma values could not be found in campaign log!", "Yellow") printToAll("Trauma values could not be found in campaign log!", "Yellow")
printToAll("Default values for health and sanity loaded.", "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
Wait.time(loadTrauma, 0.1)
end end
end end