fix usage of shiftDown

This commit is contained in:
Chr1Z93 2023-01-01 22:22:31 +01:00
parent 5511c57bf3
commit eac84f583d

View File

@ -150,7 +150,7 @@ do
---@param shiftDown Number An offset for the z-value of this group of tokens
TokenManager.spawnTokenGroup = function(card, tokenType, tokenCount, shiftDown)
if tokenType == "damage" or tokenType == "horror" then
TokenManager.spawnCounterToken(card, tokenType, tokenCount)
TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown)
else
TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown)
end
@ -162,10 +162,10 @@ do
---@param tokenType String type of token to spawn, valid values are "damage" and "horror". Other
-- types should use spawnMultipleTokens()
---@param tokenValue Number Value to set the damage/horror to
TokenManager.spawnCounterToken = function(card, tokenType, tokenValue)
TokenManager.spawnCounterToken = function(card, tokenType, tokenValue, shiftDown)
if tokenValue < 1 or tokenValue > 50 then return end
local pos = card.getPosition() + Vector(0, 0.2, 0)
local pos = card.positionToWorld(card.positionToLocal(card.getPosition()) + Vector(0, 0.2, shiftDown))
local rot = card.getRotation()
TokenManager.spawnToken(pos, tokenType, rot, function(spawned)
spawned.setState(tokenValue)
@ -175,18 +175,17 @@ do
-- Spawns a number of tokens.
---@param tokenType String type of token to spawn, valid values are resource", "doom", or "clue".
-- Other types should use spawnCounterToken()
---@param tokenCount How many tokens to spawn. For damage or horror this value will be set to the
-- spawned state object rather than spawning multiple tokens
---@param shiftDown An offset for the z-value of this group of tokens
---@param tokenCount Number How many tokens to spawn
---@param shiftDown Number An offset for the z-value of this group of tokens
TokenManager.spawnMultipleTokens = function(card, tokenType, tokenCount, shiftDown)
if tokenCount < 1 or tokenCount > 12 then
return
end
local offsets
local offsets = {}
if tokenType == "clue" then
offsets = internal.buildClueOffsets(card, tokenCount)
else
offsets = { }
for i = 1, tokenCount do
offsets[i] = card.positionToWorld(PLAYER_CARD_TOKEN_OFFSETS[tokenCount][i])
-- Fix the y-position for the spawn, since positionToWorld considers rotation which can
@ -194,7 +193,7 @@ do
offsets[i].y = card.getPosition().y + 0.15
end
end
-- end
if shiftDown ~= nil then
-- Copy the offsets to make sure we don't change the static values
local baseOffsets = offsets
@ -204,8 +203,10 @@ do
offsets[i][3] = offsets[i][3] + shiftDown
end
end
if offsets == nil then
error("couldn't find offsets for " .. tokenCount .. ' tokens')
return
end
for i = 1, tokenCount do
@ -219,7 +220,7 @@ do
-- "resource", "doom", or "clue"
---@param rotation Vector Rotation to be used for the new token. Only the y-value will be used,
-- x and z will use the default rotation from the source bag
---@param callback A callback function triggered after the new token is spawned
---@param callback function A callback function triggered after the new token is spawned
TokenManager.spawnToken = function(position, tokenType, rotation, callback)
internal.initTokenTemplates()
if tokenTemplates[tokenType] == nil then
@ -227,19 +228,12 @@ do
return
end
local tokenTemplate = tokenTemplates[tokenType]
-- Take ONLY the Y-value for rotation, so we don't flip the token coming out of the bag
local rot = Vector(tokenTemplate.Transform.rotX,
tokenTemplate.Transform.rotY,
tokenTemplate.Transform.rotZ)
if rotation ~= nil then
rot.y = rotation.y
else
rot.y = 270
end
return spawnObjectData({
data = tokenTemplate,
position = position,
rotation = rot,
rotation = Vector(tokenTemplate.Transform.rotX, rotation.y or 270, tokenTemplate.Transform.rotZ),
callback_function = callback
})
end
@ -382,7 +376,7 @@ do
end
internal.getPlayerCardData = function(card)
return playerCardData[card.getName()..':'..card.getDescription()]
return playerCardData[card.getName() .. ':' .. card.getDescription()]
or playerCardData[card.getName()]
end