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

Updated Clean Up Helper
This commit is contained in:
dscarpac 2024-06-28 16:30:49 -05:00 committed by GitHub
commit cc86d223d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,16 +17,17 @@ local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi")
local IGNORE_TAG = "CleanUpHelper_ignore" local IGNORE_TAG = "CleanUpHelper_ignore"
-- colors and order for following tables -- colors and order for following tables
local COLORS = { "White", "Orange", "Green", "Red", "Mythos" } local COLORS = { "White", "Orange", "Green", "Red" }
local campaignLog local campaignLog
local RESET_VALUES = {} local RESET_VALUES = {}
local loadingFailedBefore = false local loadingFailedBefore = false
local optionsVisible = false local optionsVisible = false
local options = {
local options = {} ["importTrauma"] = true,
options["importTrauma"] = true ["tidyPlayermats"] = true,
options["tidyPlayermats"] = true ["removeDrawnLines"] = false
options["removeDrawnLines"] = false }
local removeIgnoreLater = {}
-- don't clean playermats for preludes -- don't clean playermats for preludes
local scenarioName local scenarioName
@ -153,9 +154,9 @@ function updateCounters()
playermatApi.updateCounter("All", "ClickableClueCounter", 0) playermatApi.updateCounter("All", "ClickableClueCounter", 0)
playermatApi.resetSkillTracker("All") playermatApi.resetSkillTracker("All")
for i = 1, 4 do for i, color in ipairs(COLORS) do
playermatApi.updateCounter(COLORS[i], "DamageCounter", RESET_VALUES.Damage[i]) playermatApi.updateCounter(color, "DamageCounter", RESET_VALUES.Damage[i])
playermatApi.updateCounter(COLORS[i], "HorrorCounter", RESET_VALUES.Horror[i]) playermatApi.updateCounter(color, "HorrorCounter", RESET_VALUES.Horror[i])
end end
end end
@ -269,12 +270,13 @@ end
-- discard all hand objects -- discard all hand objects
function discardHands() function discardHands()
if not getOptionValue() then return end if not getOptionValue() then return end
for i = 1, 4 do for _, color in ipairs(COLORS) do
local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash")
if trash == nil then return end if trash then
local hand = Player[playermatApi.getPlayerColor(COLORS[i])].getHandObjects() local hand = Player[playermatApi.getPlayerColor(color)].getHandObjects()
for j = #hand, 1, -1 do for j = #hand, 1, -1 do
trash.putObject(hand[j]) trash.putObject(hand[j])
end
end end
end end
end end
@ -284,8 +286,8 @@ function maybeIgnoreTekeliliCards()
local tekeliliHelper = getTekeliliHelper() local tekeliliHelper = getTekeliliHelper()
if tekeliliHelper then if tekeliliHelper then
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck") removeIgnoreLater = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(searchResult) do for _, obj in ipairs(removeIgnoreLater) do
obj.addTag(IGNORE_TAG) obj.addTag(IGNORE_TAG)
end end
end end
@ -329,65 +331,64 @@ end
function tidyPlayerMatCoroutine() function tidyPlayerMatCoroutine()
local tekeliliHelper = getTekeliliHelper() local tekeliliHelper = getTekeliliHelper()
for i = 1, 5 do if getOptionValue() then
-- only continue for playermat (1-4) if option enabled for _, color in ipairs(COLORS) do
if getOptionValue() or i == 5 then
-- delay for animation purpose -- delay for animation purpose
for k = 1, 30 do for k = 1, 20 do
coroutine.yield(0) coroutine.yield(0)
end end
-- get respective trash -- get respective trash
local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash")
if trash == nil then if trash == nil then
printToAll("Trashcan for " .. COLORS[i] .. " playermat could not be found! Skipping this playermat.", "Yellow") printToAll("Trashcan for " .. color .. " playermat could not be found! Skipping this playermat.", "Yellow")
goto continue goto continue
end end
-- maybe store tekelili cards -- maybe store tekelili cards
if tekeliliHelper and i ~= 5 then if tekeliliHelper then
tekeliliHelper.call("storeTekelili", COLORS[i]) tekeliliHelper.call("storeTekelili", color)
end end
local objList -- remove objects (with exceptions)
if i < 5 then for _, obj in ipairs(playermatApi.searchAroundPlayermat(color)) do
objList = playermatApi.searchAroundPlayermat(COLORS[i]) maybeTrashObject(obj, trash)
else
-- Victory Display + Mythos Area
objList = searchLib.inArea({ -2, 2, 10 }, { 0, 270, 0 }, { 55, 1, 13.5 })
end end
for _, obj in ipairs(objList) do -- reset "activeInvestigatorId" and "...class"
-- ignore these elements local mat = guidReferenceApi.getObjectByOwnerAndType(color, "Playermat")
if obj.hasTag(IGNORE_TAG) == false mat.setVar("activeInvestigatorId", "00000")
and obj.hasTag("UniversalToken") == false mat.setVar("activeInvestigatorClass", "Neutral")
and obj.hasTag("chaosBag") == false mat.call("updateTexture")
and (obj.locked == false or obj.hasTag("Investigator"))
and obj.interactable == true then for k = 1, 5 do
trash.putObject(obj) coroutine.yield(0)
end
end end
-- maybe respawn tekelili cards -- maybe respawn tekelili cards
if tekeliliHelper and i ~= 5 then if tekeliliHelper then
tekeliliHelper.call("spawnStoredTekelili", COLORS[i]) tekeliliHelper.call("spawnStoredTekelili", color)
end end
end end
::continue:: ::continue::
end end
-- maybe remove ignore tag from cards / decks on the tekelili helper -- mythos area cleanup
if tekeliliHelper then local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck") if trash then
for _, obj in ipairs(searchResult) do for _, obj in ipairs(searchLib.inArea({ -2, 2, 10 }, { 0, 270, 0 }, { 55, 1, 13.5 })) do
obj.removeTag(IGNORE_TAG) maybeTrashObject(obj, trash)
end end
end end
-- reset "activeInvestigatorId" -- maybe remove ignore tag from cards / decks on the tekelili helper
local playerMats = guidReferenceApi.getObjectsByType("Playermat") if removeIgnoreLater then
for _, mat in pairs(playerMats) do for _, obj in ipairs(removeIgnoreLater) do
mat.setVar("activeInvestigatorId", "00000") if obj ~= nil then
obj.removeTag(IGNORE_TAG)
end
end
removeIgnoreLater = {}
end end
-- reset spawned data -- reset spawned data
@ -404,10 +405,21 @@ end
-- used to detect the "Tekeli-li Helper" for Edge of the Earth -- used to detect the "Tekeli-li Helper" for Edge of the Earth
function getTekeliliHelper() function getTekeliliHelper()
for _, obj in ipairs(getObjects()) do for _, obj in ipairs(getObjects()) do
if obj.getName() == "Tekeli-li Helper" then if obj ~= nil and obj.getName() == "Tekeli-li Helper" then
return obj return obj
end end
end end
return nil
end
function maybeTrashObject(obj, trash)
if not obj.hasTag(IGNORE_TAG)
and (not obj.hasTag("UniversalToken") or obj.getScale().x < 0.4)
and not obj.hasTag("chaosBag")
and (not obj.locked or obj.hasTag("Investigator"))
and obj.interactable then
trash.putObject(obj)
end
end end
-- get value with respect to override value -- get value with respect to override value