From abc291fd5ccf3782bb51b4c02a047f414f5e0229 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Sat, 5 Oct 2024 09:50:42 -0500 Subject: [PATCH] tokens spawn on card --- src/core/Global.ttslua | 13 +++++++--- src/core/token/TokenManagerApi.ttslua | 6 +++-- src/playercards/cards/TheRedClock.ttslua | 30 ++---------------------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index e64c064c..2e2446b7 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2050,6 +2050,7 @@ function TokenManager.spawnTokenGroup(params) local tokenCount = params.tokenCount local shiftDown = params.shiftDown local subType = params.subType + local temporary = params.temporary if tokenType == "damage" or tokenType == "horror" then TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown) @@ -2058,7 +2059,7 @@ function TokenManager.spawnTokenGroup(params) elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "custom" and tokenCount == 0 then TokenManager.spawnResourceCounterToken(card, tokenCount) else - TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType) + TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType, temporary) end end @@ -2089,7 +2090,8 @@ end ---@param tokenCount number How many tokens to spawn ---@param shiftDown? number An offset for the z-value of this group of tokens ---@param subType? string Subtype of token to spawn. This will only differ from the tokenName for resource or action tokens -function TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType) +---@param temporary? boolean If present adds the temporary tag to an action token +function TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType, temporary) if tokenCount < 1 then return end local offsets = {} @@ -2124,6 +2126,7 @@ function TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown end -- this is used to load the correct state for additional resource tokens (e.g. "Ammo") + log(temporary) local callbackName = nil local callbackParams = nil local stateID = stateTable[string.lower(subType or "")] @@ -2134,7 +2137,11 @@ function TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown local matColor = playermatApi.getMatColorByPosition(card.getPosition()) local activeInvestigatorData = playermatApi.getActiveInvestigatorData(matColor) callbackName = "updateUniversalActionAbilityToken" - callbackParams = { class = activeInvestigatorData.class, symbol = subType or activeInvestigatorData.class } + if temporary then + callbackParams = { class = activeInvestigatorData.class, symbol = subType or activeInvestigatorData.class, addTag = "Temporary" } + else + callbackParams = { class = activeInvestigatorData.class, symbol = subType or activeInvestigatorData.class} + end end for i = 1, tokenCount do diff --git a/src/core/token/TokenManagerApi.ttslua b/src/core/token/TokenManagerApi.ttslua index f9a87e70..1894a09c 100644 --- a/src/core/token/TokenManagerApi.ttslua +++ b/src/core/token/TokenManagerApi.ttslua @@ -70,7 +70,8 @@ do -- spawned state object rather than spawning multiple tokens ---@param shiftDown? number An offset for the z-value of this group of tokens ---@param subType? string Subtype of token to spawn. This will only differ from the tokenName for resource tokens - function TokenManagerApi.spawnTokenGroup(card, tokenType, tokenCount, shiftDown, subType) + ---@param temporary? boolean If present adds the temporary tag to an action token + function TokenManagerApi.spawnTokenGroup(card, tokenType, tokenCount, shiftDown, subType, temporary) Global.call("callTable", { { "TokenManager", "spawnTokenGroup" }, { @@ -78,7 +79,8 @@ do tokenType = tokenType, tokenCount = tokenCount, shiftDown = shiftDown, - subType = subType + subType = subType, + temporary = temporary } }) end diff --git a/src/playercards/cards/TheRedClock.ttslua b/src/playercards/cards/TheRedClock.ttslua index dbaf7e17..3fc2cd4b 100644 --- a/src/playercards/cards/TheRedClock.ttslua +++ b/src/playercards/cards/TheRedClock.ttslua @@ -92,33 +92,7 @@ function spawnActionToken(numTokens) local position = self.getPosition() local matColor = playermatApi.getMatColorByPosition(position) local mat = guidReferenceApi.getObjectByOwnerAndType(matColor, "Playermat") - local rotation = mat.getRotation() - -- find empty action token slots by checking snap points - local snaps = mat.getSnapPoints() - - -- get empty slots - local emptyPositions = {} - for i, snap in ipairs(snaps) do - if i > 1 then - if snap.tags[1] == "UniversalToken" then - local snapPos = mat.positionToWorld(snap.position) - local searchResult = searchLib.atPosition(snapPos, "isUniversalToken") - if #searchResult == 0 then - table.insert(emptyPositions, snapPos) - end - end - end - end - - local activeInvestigatorData = playermatApi.getActiveInvestigatorData(matColor) - local callbackParams = { class = activeInvestigatorData.class, symbol = activeInvestigatorData.class, addTag = "Temporary" } - local callbackName = "updateUniversalActionAbilityToken" - for i = 1, numTokens do - if emptyPositions[i] ~= nil then - tokenManagerApi.spawnToken(emptyPositions[i] + Vector(0, 0.7, 0), "universalActionAbility", rotation, callbackName, callbackParams) - else - tokenManagerApi.spawnToken(position + Vector(0, 0.7, 0), "universalActionAbility", rotation, callbackName, callbackParams) - end - end + tokenManagerApi.spawnTokenGroup(self, "universalActionAbility", numTokens, 0.8, _, true) + end