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