From e97b07d137e2d22482686f97554c688457a84a94 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 6 Apr 2024 00:10:10 +0200 Subject: [PATCH] added context menu function to tekelili cards to place below deck --- src/accessories/CleanUpHelper.ttslua | 21 +++++++++++++-------- src/playercards/cards/Tekeli-li.ttslua | 13 +++++++++++++ src/util/DeckLib.ttslua | 16 ++++++++++------ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/accessories/CleanUpHelper.ttslua b/src/accessories/CleanUpHelper.ttslua index 2397e488..0f5acde6 100644 --- a/src/accessories/CleanUpHelper.ttslua +++ b/src/accessories/CleanUpHelper.ttslua @@ -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 diff --git a/src/playercards/cards/Tekeli-li.ttslua b/src/playercards/cards/Tekeli-li.ttslua index 38d142b5..ef52a20e 100644 --- a/src/playercards/cards/Tekeli-li.ttslua +++ b/src/playercards/cards/Tekeli-li.ttslua @@ -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 diff --git a/src/util/DeckLib.ttslua b/src/util/DeckLib.ttslua index 69d85851..c818dead 100644 --- a/src/util/DeckLib.ttslua +++ b/src/util/DeckLib.ttslua @@ -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