diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index e43a79e7..cee2f990 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -17,7 +17,7 @@ local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") local IGNORE_TAG = "CleanUpHelper_ignore" -- colors and order for following tables -local COLORS = { "White", "Orange", "Green", "Red", "Mythos" } +local COLORS = { "White", "Orange", "Green", "Red" } local campaignLog local RESET_VALUES = {} local loadingFailedBefore = false @@ -153,9 +153,9 @@ function updateCounters() playermatApi.updateCounter("All", "ClickableClueCounter", 0) playermatApi.resetSkillTracker("All") - for i = 1, 4 do - playermatApi.updateCounter(COLORS[i], "DamageCounter", RESET_VALUES.Damage[i]) - playermatApi.updateCounter(COLORS[i], "HorrorCounter", RESET_VALUES.Horror[i]) + for i, color in ipairs(COLORS) do + playermatApi.updateCounter(color, "DamageCounter", RESET_VALUES.Damage[i]) + playermatApi.updateCounter(color, "HorrorCounter", RESET_VALUES.Horror[i]) end end @@ -269,12 +269,13 @@ end -- discard all hand objects function discardHands() if not getOptionValue() then return end - for i = 1, 4 do - local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") - if trash == nil then return end - local hand = Player[playermatApi.getPlayerColor(COLORS[i])].getHandObjects() - for j = #hand, 1, -1 do - trash.putObject(hand[j]) + for _, color in ipairs(COLORS) do + local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash") + if trash then + local hand = Player[playermatApi.getPlayerColor(color)].getHandObjects() + for j = #hand, 1, -1 do + trash.putObject(hand[j]) + end end end end @@ -329,53 +330,56 @@ end function tidyPlayerMatCoroutine() local tekeliliHelper = getTekeliliHelper() - for i = 1, 5 do - -- only continue for playermat (1-4) if option enabled - if getOptionValue() or i == 5 then + if getOptionValue() then + for _, color in ipairs(COLORS) do -- delay for animation purpose - for k = 1, 30 do + for k = 1, 20 do coroutine.yield(0) end -- get respective trash - local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash") + local trash = guidReferenceApi.getObjectByOwnerAndType(color, "Trash") 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 end -- maybe store tekelili cards - if tekeliliHelper and i ~= 5 then - tekeliliHelper.call("storeTekelili", COLORS[i]) + if tekeliliHelper then + tekeliliHelper.call("storeTekelili", color) end - local objList - if i < 5 then - objList = playermatApi.searchAroundPlayermat(COLORS[i]) - else - -- Victory Display + Mythos Area - objList = searchLib.inArea({ -2, 2, 10 }, { 0, 270, 0 }, { 55, 1, 13.5 }) + -- remove objects (with exceptions) + for _, obj in ipairs(playermatApi.searchAroundPlayermat(color)) do + maybeTrashObject(obj, trash) end - for _, obj in ipairs(objList) do - -- ignore these elements - if obj.hasTag(IGNORE_TAG) == false - and obj.hasTag("UniversalToken") == false - and obj.hasTag("chaosBag") == false - and (obj.locked == false or obj.hasTag("Investigator")) - and obj.interactable == true then - trash.putObject(obj) - end + -- reset "activeInvestigatorId" and "...class" + local mat = guidReferenceApi.getObjectByOwnerAndType(color, "Playermat") + mat.setVar("activeInvestigatorId", "00000") + mat.setVar("activeInvestigatorClass", "Neutral") + mat.call("updateTexture") + + for k = 1, 10 do + coroutine.yield(0) end -- maybe respawn tekelili cards - if tekeliliHelper and i ~= 5 then - tekeliliHelper.call("spawnStoredTekelili", COLORS[i]) + if tekeliliHelper then + tekeliliHelper.call("spawnStoredTekelili", color) end end ::continue:: end + -- mythos area cleanup + local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash") + if trash then + for _, obj in ipairs(searchLib.inArea({ -2, 2, 10 }, { 0, 270, 0 }, { 55, 1, 13.5 })) do + maybeTrashObject(obj, trash) + end + end + -- maybe remove ignore tag from cards / decks on the tekelili helper if tekeliliHelper then local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck") @@ -384,12 +388,6 @@ function tidyPlayerMatCoroutine() end end - -- reset "activeInvestigatorId" - local playerMats = guidReferenceApi.getObjectsByType("Playermat") - for _, mat in pairs(playerMats) do - mat.setVar("activeInvestigatorId", "00000") - end - -- reset spawned data tokenSpawnTrackerApi.resetAll() local datahelper = guidReferenceApi.getObjectByOwnerAndType("Mythos", "DataHelper") @@ -410,6 +408,16 @@ function getTekeliliHelper() end 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 + -- get value with respect to override value function getOptionValue() -- don't clean up playermats if playing a prelude from the list