Draw encounter cards to the first empty slot from the right

This commit is contained in:
Chr1Z93 2024-04-18 23:31:45 +02:00
parent e0689dc90c
commit dde7c420b7
2 changed files with 27 additions and 13 deletions

View File

@ -14,6 +14,7 @@ local ENCOUNTER_DISCARD_AREA = {
upperLeft = { x = 1.62, z = 0.42 },
lowerRight = { x = 1.58, z = 0.38 },
}
local DRAWN_ENCOUNTER_CARD_OFFSET = {1.365, 0.5, -0.625}
-- global position of encounter deck and discard pile
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
@ -174,19 +175,32 @@ function drawEncounterCard(params)
end
function actualEncounterCardDraw(card, params)
local metadata = JSON.decode(card.getGMNotes()) or {}
local faceUpRotation = 0
if not params.alwaysFaceUp then
local metadata = JSON.decode(card.getGMNotes()) or {}
if metadata.hidden or DATA_HELPER.call('checkHiddenCard', card.getName()) then
faceUpRotation = 180
if metadata.hidden or DATA_HELPER.call('checkHiddenCard', card.getName()) then
faceUpRotation = 180
end
local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET)
-- get first empty slot in threat area (right to left)
if not params.stack then
local searchPos = Vector(-0.91, 0.5, -0.625)
for i = 1, 5 do
local globalSearchPos = params.mat.positionToWorld(searchPos)
local searchResult = searchLib.atPosition(globalSearchPos, "isCardOrDeck")
if #searchResult == 0 then
pos = globalSearchPos
break
else
searchPos.x = searchPos.x + 0.455
end
end
end
local DRAWN_ENCOUNTER_CARD_OFFSET = {1.365, 0.5, -0.625}
local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET)
local rotY = params.mat.getRotation().y
deckLib.placeOrMergeIntoDeck(card, pos, { 0, rotY, faceUpRotation })
local rot = { 0, params.mat.getRotation().y, faceUpRotation }
deckLib.placeOrMergeIntoDeck(card, pos, rot)
end
function reshuffleEncounterDeck()

View File

@ -16,11 +16,11 @@ do
return getMythosArea().call("getEncounterDeck")
end
-- draw an encounter card for the requesting mat
-- draw an encounter card for the requesting mat to the first empty spot from the right
---@param mat tts__Object Playermat that triggered this
---@param alwaysFaceUp boolean Whether the card should be drawn face-up
MythosAreaApi.drawEncounterCard = function(mat, alwaysFaceUp)
getMythosArea().call("drawEncounterCard", {mat = mat, alwaysFaceUp = alwaysFaceUp})
---@param stack boolean Whether the card should instead be placed right next to the button (and even stack with other cards)
MythosAreaApi.drawEncounterCard = function(mat, stack)
getMythosArea().call("drawEncounterCard", { mat = mat, stack = stack })
end
-- reshuffle the encounter deck