From e670244dc8d54aa718fc906608d30424d076da93 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 18 Jun 2023 21:50:15 +0200 Subject: [PATCH 1/5] return sealed tokens to chaos bag before cleanup --- src/accessories/CleanUpHelper.ttslua | 1 + src/core/Global.ttslua | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 2b1711fa..50da370e 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -172,6 +172,7 @@ function cleanUp(_, color) removeLines() discardHands() tokenSpawnTrackerApi.resetAll() + Global.call("returnChaosTokens") printToAll("Tidying main play area...", "White") startLuaCoroutine(self, "tidyPlayareaCoroutine") diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 020abc1a..365f2da7 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -39,6 +39,7 @@ local mythosAreaApi = require("core/MythosAreaApi") local tokenArrangerApi = require("accessories/TokenArrangerApi") local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local navigationOverlayApi = require("core/NavigationOverlayApi") +local tokenChecker = require("core/token/TokenChecker") -- online functionality related variables local MOD_VERSION = "3.1.0" @@ -645,6 +646,16 @@ function emptyChaosBag() end end +-- return chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) +function returnChaosTokens() + local chaosbag = findChaosBag() + for _, obj in ipairs(getObjects()) do + if tokenChecker.isChaosToken(obj) and not obj.hasTag("tempToken") then + chaosbag.putObject(obj) + end + end +end + --------------------------------------------------------- -- Content Importing and XML functions --------------------------------------------------------- From 9dd8fe8ad6f7acd933dcf43f99827eb7d191300c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 19 Jun 2023 15:58:09 +0200 Subject: [PATCH 2/5] rename function --- src/accessories/CleanUpHelper.ttslua | 2 +- src/core/Global.ttslua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 50da370e..aee6731c 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -172,7 +172,7 @@ function cleanUp(_, color) removeLines() discardHands() tokenSpawnTrackerApi.resetAll() - Global.call("returnChaosTokens") + Global.call("findAllChaosTokens") printToAll("Tidying main play area...", "White") startLuaCoroutine(self, "tidyPlayareaCoroutine") diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 365f2da7..20b21edd 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -646,8 +646,8 @@ function emptyChaosBag() end end --- return chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) -function returnChaosTokens() +-- find all chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) +function findAllChaosTokens() local chaosbag = findChaosBag() for _, obj in ipairs(getObjects()) do if tokenChecker.isChaosToken(obj) and not obj.hasTag("tempToken") then From f82d29b9e049538956cf0e635bd51b32c750833a Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 22 Jun 2023 12:07:24 +0200 Subject: [PATCH 3/5] exclusion of bless/curse tokens for findAllTokens --- src/accessories/CleanUpHelper.ttslua | 15 +++------------ src/chaosbag/BlessCurseManager.ttslua | 22 +++++++++++++--------- src/chaosbag/BlessCurseManagerApi.ttslua | 6 ++++++ src/core/Global.ttslua | 8 ++++++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index aee6731c..d970e096 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -6,6 +6,7 @@ Cleans up the table for the next scenario in a campaign: local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") local soundCubeApi = require("core/SoundCubeApi") local playmatApi = require("playermat/PlaymatApi") +local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") -- these objects will be ignored local IGNORE_GUIDS = { @@ -168,7 +169,7 @@ function cleanUp(_, color) updateCounters(CLUE_CLICKER_GUIDS, 0, "Clue clickers") resetSkillTrackers() resetDoomCounter() - removeBlessCurse(color) + blessCurseManagerApi.removeAll(color) removeLines() discardHands() tokenSpawnTrackerApi.resetAll() @@ -181,6 +182,7 @@ end --------------------------------------------------------- -- modular functions, called by other functions --------------------------------------------------------- + function updateCounters(tableOfGUIDs, tableOfNewValues, info) if tonumber(tableOfNewValues) then local value = tableOfNewValues @@ -267,17 +269,6 @@ function getTrauma() end end --- get rid of bless/curse tokens via bless/curse manager -function removeBlessCurse(color) - local BlessCurseManager = getObjectFromGUID("5933fb") - - if BlessCurseManager ~= nil then - BlessCurseManager.call("doRemove", color) - else - printToAll("Bless / Curse manager could not be found and thus bless/curse tokens were skipped.", "Yellow") - end -end - -- remove drawn lines function removeLines() if options["removeDrawnLines"] then diff --git a/src/chaosbag/BlessCurseManager.ttslua b/src/chaosbag/BlessCurseManager.ttslua index faf3258a..ce9eafc3 100644 --- a/src/chaosbag/BlessCurseManager.ttslua +++ b/src/chaosbag/BlessCurseManager.ttslua @@ -63,14 +63,21 @@ function onLoad(saved_state) self.addContextMenuItem("Remove all", doRemove) self.addContextMenuItem("Reset", doReset) - -- initializing tables + -- initializing tables + initializeState() + broadcastCount("Curse") + broadcastCount("Bless") +end + +function resetTables() numInPlay = { Bless = 0, Curse = 0 } tokensTaken = { Bless = {}, Curse = {} } sealedTokens = {} - Wait.time(initializeState, 1) end function initializeState() + resetTables() + -- count tokens in the bag local chaosbag = Global.call("findChaosBag") local tokens = {} @@ -95,9 +102,6 @@ function initializeState() end end end - - broadcastCount("Curse") - broadcastCount("Bless") end function broadcastCount(token) @@ -133,15 +137,15 @@ function doRemove(color) broadcastToColor("Removed " .. removeTakenTokens("Bless") .. " Bless and " .. removeTakenTokens("Curse") .. " Curse tokens from play.", color, "White") - doReset(color) + resetTables() + tokenArrangerApi.layout() end -- context menu function 2 function doReset(color) - playerColor = color - numInPlay = { Bless = 0, Curse = 0 } - tokensTaken = { Bless = {}, Curse = {} } initializeState() + broadcastCount("Curse") + broadcastCount("Bless") tokenArrangerApi.layout() end diff --git a/src/chaosbag/BlessCurseManagerApi.ttslua b/src/chaosbag/BlessCurseManagerApi.ttslua index 3e35b801..694e98b2 100644 --- a/src/chaosbag/BlessCurseManagerApi.ttslua +++ b/src/chaosbag/BlessCurseManagerApi.ttslua @@ -26,6 +26,12 @@ do getObjectFromGUID(MANAGER_GUID).call("broadcastStatus", playerColor) end + -- removes all bless / curse tokens from the chaos bag and play + ---@param playerColor String Color of the player to show the broadcast to + BlessCurseManagerApi.removeAll = function(playerColor) + getObjectFromGUID(MANAGER_GUID).call("doRemove", playerColor) + end + -- adds Wendy's menu to the hovered card (allows sealing of tokens) ---@param color String Color of the player to show the broadcast to BlessCurseManagerApi.addWendysMenu = function(playerColor, hoveredObject) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 20b21edd..24ec2368 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -646,11 +646,15 @@ function emptyChaosBag() end end --- find all chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) +-- move all regular chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) function findAllChaosTokens() local chaosbag = findChaosBag() for _, obj in ipairs(getObjects()) do - if tokenChecker.isChaosToken(obj) and not obj.hasTag("tempToken") then + local name = obj.getName() + if tokenChecker.isChaosToken(obj) and + not obj.hasTag("tempToken") and + name ~= "Bless" and + name ~= "Curse" then chaosbag.putObject(obj) end end From 57cdd5ef714e242997b93dfc7fffbd8572904dc3 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 27 Jun 2023 10:09:50 +0200 Subject: [PATCH 4/5] renamed function, limited it to sealed tokens --- src/accessories/CleanUpHelper.ttslua | 2 +- src/core/Global.ttslua | 13 +++++-------- src/playercards/CardsThatSealTokens.ttslua | 4 +++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index d970e096..d719d488 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -173,7 +173,7 @@ function cleanUp(_, color) removeLines() discardHands() tokenSpawnTrackerApi.resetAll() - Global.call("findAllChaosTokens") + Global.call("releaseAllSealedTokens", color) printToAll("Tidying main play area...", "White") startLuaCoroutine(self, "tidyPlayareaCoroutine") diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 24ec2368..b74211b1 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -646,16 +646,13 @@ function emptyChaosBag() end end --- move all regular chaos tokens that are on the table to the chaos bag (e.g. sealed on cards) -function findAllChaosTokens() +-- returns all sealed tokens on cards to the chaos bag +function releaseAllSealedTokens(playerColor) local chaosbag = findChaosBag() for _, obj in ipairs(getObjects()) do - local name = obj.getName() - if tokenChecker.isChaosToken(obj) and - not obj.hasTag("tempToken") and - name ~= "Bless" and - name ~= "Curse" then - chaosbag.putObject(obj) + local sealedTokens = obj.getTable("sealedTokens") + if sealedTokens ~= nil and #sealedTokens > 0 then + obj.call("releaseAllTokens", playerColor) end end end diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index cbcc0a2b..56a331ab 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -70,10 +70,12 @@ Thus it should be implemented like this: local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local tokenArrangerApi = require("accessories/TokenArrangerApi") -local sealedTokens = {} local ID_URL_MAP = {} local tokensInBag = {} +-- this is intentionally global so that it can be accessed for clean up +sealedTokens = {} + function onSave() return JSON.encode(sealedTokens) end function onLoad(savedData) From 9fa5c4545232c60da74e7ed4f26d55b72a1a406c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 27 Jun 2023 12:10:32 +0200 Subject: [PATCH 5/5] add tag to cards that seal --- src/core/Global.ttslua | 7 ++----- src/playercards/CardsThatSealTokens.ttslua | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index b74211b1..68c413de 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -649,11 +649,8 @@ end -- returns all sealed tokens on cards to the chaos bag function releaseAllSealedTokens(playerColor) local chaosbag = findChaosBag() - for _, obj in ipairs(getObjects()) do - local sealedTokens = obj.getTable("sealedTokens") - if sealedTokens ~= nil and #sealedTokens > 0 then - obj.call("releaseAllTokens", playerColor) - end + for _, obj in ipairs(getObjectsWithTag("CardThatSeals")) do + obj.call("releaseAllTokens", playerColor) end end diff --git a/src/playercards/CardsThatSealTokens.ttslua b/src/playercards/CardsThatSealTokens.ttslua index 56a331ab..03c09c3a 100644 --- a/src/playercards/CardsThatSealTokens.ttslua +++ b/src/playercards/CardsThatSealTokens.ttslua @@ -70,18 +70,17 @@ Thus it should be implemented like this: local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi") local tokenArrangerApi = require("accessories/TokenArrangerApi") +local sealedTokens = {} local ID_URL_MAP = {} local tokensInBag = {} --- this is intentionally global so that it can be accessed for clean up -sealedTokens = {} - function onSave() return JSON.encode(sealedTokens) end function onLoad(savedData) sealedTokens = JSON.decode(savedData) or {} ID_URL_MAP = Global.getTable("ID_URL_MAP") generateContextMenu() + self.addTag("CardThatSeals") end -- builds the context menu