From 7b8750a17832062ed12d0544c7eb48127c283cfb Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 3 Apr 2023 12:56:47 +0200 Subject: [PATCH 1/2] auto-remove tokens --- SCED.wiki | 1 + src/playermat/Playmat.ttslua | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 160000 SCED.wiki diff --git a/SCED.wiki b/SCED.wiki new file mode 160000 index 00000000..01065bfc --- /dev/null +++ b/SCED.wiki @@ -0,0 +1 @@ +Subproject commit 01065bfc202457c2c2edc4e8fa9a2385a4e3ecd5 diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index fbd6c9db..51d9550b 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -567,6 +567,7 @@ function onCollisionEnter(collision_info) if isInDeckZone(object) then tokenManager.resetTokensSpawned(object) + removeTokensFromObject(object) elseif shouldSpawnTokens(object) then spawnTokensFor(object) end @@ -577,28 +578,35 @@ function onCollisionExit(collision_info) if collision_info.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end end +-- checks if tokens should be spawned for the provided card function shouldSpawnTokens(card) if card.is_face_down then return false end + local localCardPos = self.positionToLocal(card.getPosition()) local metadata = JSON.decode(card.getGMNotes()) + -- If no metadata we don't know the type, so only spawn in the main area if metadata == nil then return inArea(localCardPos, MAIN_PLAY_AREA) end - -- Spawn tokens for assets and events on the main area, and all encounter types in the threat area + + -- Spawn tokens for assets and events on the main area if inArea(localCardPos, MAIN_PLAY_AREA) and (metadata.type == "Asset" or metadata.type == "Event") then return true end + + -- Spawn tokens for all encounter types in the threat area if inArea(localCardPos, THREAT_AREA) and (metadata.type == "Treachery" or metadata.type == "Enemy" or metadata.weakness) then return true end + return false end @@ -609,14 +617,17 @@ end function resetTokensIfInDeckZone(container, object) if isInDeckZone(container) then tokenManager.resetTokensSpawned(object) + removeTokensFromObject(container) end end +-- checks if an object is in this mats deckzone function isInDeckZone(checkObject) local deckZone = getObjectFromGUID(zoneID) if deckZone == nil then return false end + for _, obj in ipairs(deckZone.getObjects()) do if obj == checkObject then return true @@ -626,6 +637,20 @@ function isInDeckZone(checkObject) return false end +-- removes tokens from the provided card/deck +function removeTokensFromObject(object) + for _, v in ipairs(searchArea(object.getPosition(), { 3, 1, 4 })) do + local obj = v.hit_object + if obj.getGUID() ~= "4ee1f2" and + obj ~= self and + obj.type ~= "Deck" and + obj.type ~= "Card" and + not tokenChecker.isChaosToken(obj) then + TRASHCAN.putObject(obj) + end + end +end + --------------------------------------------------------- -- investigator ID grabbing and skill tracker --------------------------------------------------------- From 1527b023c080e34ab38a6b77bbbe4be2c5e3486c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 4 Apr 2023 17:09:28 +0200 Subject: [PATCH 2/2] added comment --- src/playermat/Playmat.ttslua | 1 + 1 file changed, 1 insertion(+) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 51d9550b..98dbb7e2 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -641,6 +641,7 @@ end function removeTokensFromObject(object) for _, v in ipairs(searchArea(object.getPosition(), { 3, 1, 4 })) do local obj = v.hit_object + -- don't remove the table surface, self, any decks/cards or chaos tokens if obj.getGUID() ~= "4ee1f2" and obj ~= self and obj.type ~= "Deck" and