Merge pull request #660 from argonui/encounter-card-drawing

Draw encounter cards to the first empty slot from the right
This commit is contained in:
BootleggerFinn 2024-04-20 21:19:35 -05:00 committed by GitHub
commit dff8662707
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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