added context menu function to tekelili cards to place below deck

This commit is contained in:
Chr1Z93 2024-04-06 00:10:10 +02:00
parent 34b820e97e
commit e97b07d137
3 changed files with 36 additions and 14 deletions

View File

@ -122,6 +122,7 @@ function cleanUp(_, color)
discardHands()
chaosBagApi.returnChaosTokens()
chaosBagApi.releaseAllSealedTokens(color)
maybeIgnoreTekeliliCards()
printToAll("Tidying main play area...", "White")
startLuaCoroutine(self, "tidyPlayareaCoroutine")
@ -238,6 +239,18 @@ function discardHands()
end
end
-- maybe ignore cards / decks on the tekelili helper
function maybeIgnoreTekeliliCards()
local tekeliliHelper = getTekeliliHelper()
if tekeliliHelper then
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(searchResult) do
obj.addTag(IGNORE_TAG)
end
end
end
-- clean up for play area
function tidyPlayareaCoroutine()
local trash = guidReferenceApi.getObjectByOwnerAndType("Mythos", "Trash")
@ -271,14 +284,6 @@ end
function tidyPlayerMatCoroutine()
local tekeliliHelper = getTekeliliHelper()
-- maybe ignore cards / decks on the tekelili helper
if tekeliliHelper then
local searchResult = searchLib.onObject(tekeliliHelper, "isCardOrDeck")
for _, obj in ipairs(searchResult) do
obj.addTag(IGNORE_TAG)
end
end
for i = 1, 5 do
-- only continue for playermat (1-4) if option enabled
if options["tidyPlayermats"] or i == 5 then

View File

@ -1,5 +1,9 @@
local playmatApi = require("playermat/PlaymatApi")
local deckLib = require("util/DeckLib")
function onLoad()
self.addContextMenuItem("Return this card", returnSelf)
self.addContextMenuItem("Place below my deck", placeBelowDeck)
end
-- uses the tekeli-li helper to place this card at the bottom of the deck
@ -12,6 +16,15 @@ function returnSelf()
end
end
-- places this card below the deck of the player that triggered it
function placeBelowDeck(playerColor)
local matColor = playmatApi.getMatColor(playerColor)
local deckPos = playmatApi.getDrawPosition(matColor)
local deckRot = playmatApi.returnRotation(matColor)
deckRot = deckRot:setAt("z", 180)
deckLib.placeOrMergeIntoDeck(self, Vector(deckPos), deckRot, true)
end
-- used to detect the "Tekeli-li Helper" for Edge of the Earth
function getTekeliliHelper()
for _, obj in ipairs(getObjects()) do

View File

@ -5,21 +5,25 @@ do
-- places a card/deck at a position or merges into an existing deck
---@param obj tts__Object Object to move
---@param pos table New position for the object
---@param rot table New rotation for the object (optional)
DeckLib.placeOrMergeIntoDeck = function(obj, pos, rot)
---@param rot? table New rotation for the object
---@param below? boolean Should the object be placed below an existing deck?
DeckLib.placeOrMergeIntoDeck = function(obj, pos, rot, below)
if obj == nil or pos == nil then return end
-- search the new position for existing card/deck
local searchResult = searchLib.atPosition(pos, "isCardOrDeck")
-- get new position
local newPos
local offset = 0.5
local newPos = Vector(pos) + Vector(0, offset, 0)
if #searchResult == 1 then
local bounds = searchResult[1].getBounds()
newPos = Vector(pos):setAt("y", bounds.center.y + bounds.size.y / 2 + offset)
else
newPos = Vector(pos) + Vector(0, offset, 0)
if below then
newPos = Vector(pos):setAt("y", bounds.center.y - bounds.size.y / 2)
else
newPos = Vector(pos):setAt("y", bounds.center.y + bounds.size.y / 2 + offset)
end
end
-- allow moving the objects smoothly out of the hand