Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Up Helper: Misc updates #705

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions src/accessories/CleanUpHelper.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
local chaosBagApi = require("chaosbag/ChaosBagApi")
local guidReferenceApi = require("core/GUIDReferenceApi")
local mythosAreaApi = require("core/MythosAreaApi")
local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local searchLib = require("util/SearchLib")
Expand All @@ -27,6 +28,12 @@ options["importTrauma"] = true
options["tidyPlayermats"] = true
options["removeDrawnLines"] = false

-- don't clean playmats for preludes
local scenarioName
local preludeList = {
["Prelude: Welcome to Hemlock Vale!"] = true
}

local buttonParameters = {}
buttonParameters.function_owner = self

Expand Down Expand Up @@ -109,6 +116,7 @@ function cleanUp(_, color)
printToAll("Clean up started!", "Orange")
printToAll("Resetting counters...", "White")

getScenarioName()
soundCubeApi.playSoundByName("Vacuum")
ignoreCustomDataHelper()
getTrauma()
Expand All @@ -119,6 +127,7 @@ function cleanUp(_, color)
resetDoomCounter()
blessCurseManagerApi.removeAll(color)
removeLines()
returnMiniCards()
discardHands()
chaosBagApi.returnChaosTokens()
chaosBagApi.releaseAllSealedTokens(color)
Expand All @@ -132,7 +141,14 @@ end
-- modular functions, called by other functions
---------------------------------------------------------

function getScenarioName()
local tokenData = mythosAreaApi.returnTokenData()
scenarioName = tokenData.currentScenario
end

function updateCounters()
if not getOptionValue() then return end

playmatApi.updateCounter("All", "ResourceCounter", 5)
playmatApi.updateCounter("All", "ClickableClueCounter", 0)
playmatApi.resetSkillTracker("All")
Expand Down Expand Up @@ -226,9 +242,33 @@ function removeLines()
end
end

-- returns the mini cards back to the owning mat
function returnMiniCards()
-- stop if playermats get tidied anyway
if getOptionValue() then return end

-- get mini cards in play
local miniCardIndex = {}
for _, obj in ipairs(getObjectsWithTag("Minicard")) do
local notes = JSON.decode(obj.getGMNotes())
if notes ~= nil and notes.id then
miniCardIndex[notes.id] = obj
end
end

-- move mini cards
for _, mat in pairs(guidReferenceApi.getObjectsByType("Playermat")) do
local miniId = mat.getVar("activeInvestigatorId") .. "-m"
if miniCardIndex[miniId] then
local pos = mat.positionToWorld(Vector(-1.36, 0, -0.625)):setAt("y", 1.67)
miniCardIndex[miniId].setPosition(pos)
end
end
end

-- discard all hand objects
function discardHands()
if not options["tidyPlayermats"] then return end
if not getOptionValue() then return end
for i = 1, 4 do
local trash = guidReferenceApi.getObjectByOwnerAndType(COLORS[i], "Trash")
if trash == nil then return end
Expand All @@ -253,6 +293,11 @@ end

-- clean up for play area
function tidyPlayareaCoroutine()
-- small wait to allow other operations to finish
for k = 1, 10 do
coroutine.yield(0)
end

local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
local playAreaZone = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlayAreaZone")

Expand Down Expand Up @@ -286,7 +331,7 @@ function tidyPlayerMatCoroutine()

for i = 1, 5 do
-- only continue for playermat (1-4) if option enabled
if options["tidyPlayermats"] or i == 5 then
if getOptionValue() or i == 5 then
-- delay for animation purpose
for k = 1, 30 do
coroutine.yield(0)
Expand Down Expand Up @@ -364,3 +409,13 @@ function getTekeliliHelper()
end
end
end

-- get value with respect to override value
function getOptionValue()
-- don't clean up playermats if playing a prelude from the list
if preludeList[scenarioName] then
return false
else
return options["tidyPlayermats"]
end
end
6 changes: 3 additions & 3 deletions src/core/MythosAreaApi.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ do
MythosAreaApi.returnTokenData = function()
return getMythosArea().call("returnTokenData")
end

---@return any: Object reference to the encounter deck
MythosAreaApi.getEncounterDeck = function()
return getMythosArea().call("getEncounterDeck")
end

-- draw an encounter card for the requesting mat to the first empty spot from the right
-- draw an encounter card for the requesting mat to the first empty spot from the right
---@param matColor string Playermat that triggered this
---@param position tts__Vector Position for the encounter card
MythosAreaApi.drawEncounterCard = function(matColor, position)
Expand All @@ -27,6 +27,6 @@ do
MythosAreaApi.reshuffleEncounterDeck = function()
getMythosArea().call("reshuffleEncounterDeck")
end

return MythosAreaApi
end
Loading