Merge branch 'argonui:main' into kohaku

This commit is contained in:
dscarpac 2024-06-29 07:38:13 -05:00 committed by GitHub
commit 05fcead3d1
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"
-- 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
local optionsVisible = false
local options = {}
options["importTrauma"] = true
options["tidyPlayermats"] = true
options["removeDrawnLines"] = false
local options = {
["importTrauma"] = true,
["tidyPlayermats"] = true,
["removeDrawnLines"] = false
}
local removeIgnoreLater = {}
-- don't clean playermats for preludes
local scenarioName
@ -153,9 +154,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 +270,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
@ -284,8 +286,8 @@ function maybeIgnoreTekeliliCards()
local tekeliliHelper = getTekeliliHelper()
if tekeliliHelper then
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(searchResult) do
removeIgnoreLater = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(removeIgnoreLater) do
obj.addTag(IGNORE_TAG)
end
end
@ -329,65 +331,64 @@ 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, 5 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
-- maybe remove ignore tag from cards / decks on the tekelili helper
if tekeliliHelper then
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(searchResult) do
obj.removeTag(IGNORE_TAG)
-- 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
-- reset "activeInvestigatorId"
local playerMats = guidReferenceApi.getObjectsByType("Playermat")
for _, mat in pairs(playerMats) do
mat.setVar("activeInvestigatorId", "00000")
-- maybe remove ignore tag from cards / decks on the tekelili helper
if removeIgnoreLater then
for _, obj in ipairs(removeIgnoreLater) do
if obj ~= nil then
obj.removeTag(IGNORE_TAG)
end
end
removeIgnoreLater = {}
end
-- reset spawned data
@ -404,10 +405,21 @@ end
-- used to detect the "Tekeli-li Helper" for Edge of the Earth
function getTekeliliHelper()
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
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
-- get value with respect to override value