From 7ce31704ce7ba3a2bd9e04898d26fe2d1ca7cffb Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Fri, 3 May 2024 09:57:18 +0200 Subject: [PATCH] updated plamatapi for explore / tekeli-li helper --- src/core/MythosArea.ttslua | 24 +++--------------------- src/core/MythosAreaApi.ttslua | 8 ++++---- src/playermat/Playmat.ttslua | 29 +++++++++++++++++++++++++++-- src/playermat/PlaymatApi.ttslua | 23 +++++++++++++++-------- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 4b2fcdad..fba282a8 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -1,6 +1,7 @@ local deckLib = require("util/DeckLib") local guidReferenceApi = require("core/GUIDReferenceApi") local playAreaApi = require("core/PlayAreaApi") +local playmatApi = require("playermat/PlaymatApi") local searchLib = require("util/SearchLib") local tokenArrangerApi = require("accessories/TokenArrangerApi") local tokenChecker = require("core/token/TokenChecker") @@ -14,7 +15,6 @@ 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 } @@ -186,26 +186,8 @@ function actualEncounterCardDraw(card, params) faceUpRotation = 180 end - -- get position and rotation for the specific playmat - local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) - local rot = { 0, params.mat.getRotation().y, faceUpRotation } - - -- maybe override position with 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 - - deckLib.placeOrMergeIntoDeck(card, pos, rot) + local rot = playmatApi.returnRotation(params.matColor):setAt("z", faceUpRotation) + deckLib.placeOrMergeIntoDeck(card, params.position, rot) end function reshuffleEncounterDeck() diff --git a/src/core/MythosAreaApi.ttslua b/src/core/MythosAreaApi.ttslua index ab951641..b0cc2dc3 100644 --- a/src/core/MythosAreaApi.ttslua +++ b/src/core/MythosAreaApi.ttslua @@ -17,10 +17,10 @@ do end -- 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 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 }) + ---@param matColor string Playermat that triggered this + ---@param position tts__Vector Position for the encounter card + MythosAreaApi.drawEncounterCard = function(matColor, position) + getMythosArea().call("drawEncounterCard", { matColor = matColor, position = position }) end -- reshuffle the encounter deck diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index fe387f1e..933a463b 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -37,9 +37,10 @@ local DECK_DISCARD_AREA = { size = { x = 0.4, y = 3, z = 1.1 } } --- local position of draw and discard pile +-- local positions local DRAW_DECK_POSITION = { x = -1.82, y = 0.1, z = 0 } local DISCARD_PILE_POSITION = { x = -1.82, y = 0.1, z = 0.61 } +local DRAWN_ENCOUNTER_POSITION = { x = 1.365, y = 0.5, z = -0.625 } -- global position of encounter discard pile local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1.5, z = 10.38 } @@ -951,7 +952,8 @@ function drawChaosTokenButton(_, _, isRightClick) end function drawEncounterCard(_, _, isRightClick) - mythosAreaApi.drawEncounterCard(self, isRightClick) + local drawPos = getEncounterCardDrawPosition(isRightClick) + mythosAreaApi.drawEncounterCard(matColor, drawPos) end function returnGlobalDiscardPosition() @@ -962,6 +964,29 @@ function returnGlobalDrawPosition() return self.positionToWorld(DRAW_DECK_POSITION) end +-- returns the position for encounter card drawing +---@param stack boolean If true, returns the leftmost position instead of the first empty from the right +function getEncounterCardDrawPosition(stack) + local drawPos = self.positionToWorld(DRAWN_ENCOUNTER_POSITION) + + -- maybe override position with first empty slot in threat area (right to left) + if not stack then + local searchPos = Vector(-0.91, 0.5, -0.625) + for i = 1, 5 do + local globalSearchPos = self.positionToWorld(searchPos) + local searchResult = searchLib.atPosition(globalSearchPos, "isCardOrDeck") + if #searchResult == 0 then + drawPos = globalSearchPos + break + else + searchPos.x = searchPos.x + 0.455 + end + end + end + + return drawPos +end + -- creates / removes the draw 1 button ---@param visible boolean Whether the draw 1 button should be visible function showDrawButton(visible) diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 5df6e249..17af3a37 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -150,6 +150,15 @@ do end end + -- Returns the position for encounter card drawing + ---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All") + ---@param stack boolean If true, returns the leftmost position instead of the first empty from the right + PlaymatApi.getEncounterCardDrawPosition = function(matColor, stack) + for _, mat in pairs(getMatForColor(matColor)) do + return Vector(mat.call("getEncounterCardDrawPosition", stack)) + end + end + -- Sets the requested playmat's snap points to limit snapping to matching card types or not. If -- matchTypes is true, the main card slot snap points will only snap assets, while the -- investigator area point will only snap Investigators. If matchTypes is false, snap points will @@ -198,7 +207,7 @@ do return count end - -- updates the specified owned counter + -- Updates the specified owned counter ---@param matColor string Color of the playmat - White, Orange, Green, Red or All ---@param type string Counter to target ---@param newValue number Value to set the counter to @@ -209,7 +218,7 @@ do end end - -- triggers the draw function for the specified playmat + -- Triggers the draw function for the specified playmat ---@param matColor string Color of the playmat - White, Orange, Green, Red or All ---@param number number Amount of cards to draw PlaymatApi.drawCardsWithReshuffle = function(matColor, number) @@ -218,7 +227,7 @@ do end end - -- returns the resource counter amount + -- Returns the resource counter amount ---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All") ---@param type string Counter to target PlaymatApi.getCounterValue = function(matColor, type) @@ -227,15 +236,13 @@ do end end - -- returns a list of mat colors that have an investigator placed + -- Returns a list of mat colors that have an investigator placed PlaymatApi.getUsedMatColors = function() local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 } local usedColors = {} - for matColor, mat in pairs(getMatForColor("All")) do local searchPos = mat.positionToWorld(localInvestigatorPosition) local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck") - if #searchResult > 0 then table.insert(usedColors, matColor) end @@ -243,7 +250,7 @@ do return usedColors end - -- resets the specified skill tracker to "1, 1, 1, 1" + -- Resets the specified skill tracker to "1, 1, 1, 1" ---@param matColor string Color of the playmat - White, Orange, Green, Red or All PlaymatApi.resetSkillTracker = function(matColor) for _, mat in pairs(getMatForColor(matColor)) do @@ -251,7 +258,7 @@ do end end - -- finds all objects on the playmat and associated set aside zone and returns a table + -- Finds all objects on the playmat and associated set aside zone and returns a table ---@param matColor string Color of the playmat - White, Orange, Green, Red or All ---@param filter string Name of the filte function (see util/SearchLib) PlaymatApi.searchAroundPlaymat = function(matColor, filter)