Merge pull request #673 from argonui/api-additions

Updated PlaymatApi for Explore and Tekeli-li helpers
This commit is contained in:
Chr1Z 2024-05-09 19:25:09 +02:00 committed by GitHub
commit 444146a2a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 35 deletions

View File

@ -1,6 +1,7 @@
local deckLib = require("util/DeckLib") local deckLib = require("util/DeckLib")
local guidReferenceApi = require("core/GUIDReferenceApi") local guidReferenceApi = require("core/GUIDReferenceApi")
local playAreaApi = require("core/PlayAreaApi") local playAreaApi = require("core/PlayAreaApi")
local playmatApi = require("playermat/PlaymatApi")
local searchLib = require("util/SearchLib") local searchLib = require("util/SearchLib")
local tokenArrangerApi = require("accessories/TokenArrangerApi") local tokenArrangerApi = require("accessories/TokenArrangerApi")
local tokenChecker = require("core/token/TokenChecker") local tokenChecker = require("core/token/TokenChecker")
@ -14,7 +15,6 @@ local ENCOUNTER_DISCARD_AREA = {
upperLeft = { x = 1.62, z = 0.42 }, upperLeft = { x = 1.62, z = 0.42 },
lowerRight = { x = 1.58, z = 0.38 } 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 -- global position of encounter deck and discard pile
local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 } local ENCOUNTER_DECK_POS = { x = -3.93, y = 1, z = 5.76 }
@ -186,26 +186,8 @@ function actualEncounterCardDraw(card, params)
faceUpRotation = 180 faceUpRotation = 180
end end
-- get position and rotation for the specific playmat local rot = playmatApi.returnRotation(params.matColor):setAt("z", faceUpRotation)
local pos = params.mat.positionToWorld(DRAWN_ENCOUNTER_CARD_OFFSET) deckLib.placeOrMergeIntoDeck(card, params.position, rot)
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)
end end
function reshuffleEncounterDeck() function reshuffleEncounterDeck()

View File

@ -17,10 +17,10 @@ do
end end
-- draw an encounter card for the requesting mat to the first empty spot from the right -- 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 matColor string 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) ---@param position tts__Vector Position for the encounter card
MythosAreaApi.drawEncounterCard = function(mat, stack) MythosAreaApi.drawEncounterCard = function(matColor, position)
getMythosArea().call("drawEncounterCard", { mat = mat, stack = stack }) getMythosArea().call("drawEncounterCard", { matColor = matColor, position = position })
end end
-- reshuffle the encounter deck -- reshuffle the encounter deck

View File

@ -37,9 +37,10 @@ local DECK_DISCARD_AREA = {
size = { x = 0.4, y = 3, z = 1.1 } 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 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 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 -- global position of encounter discard pile
local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1.5, z = 10.38 } local ENCOUNTER_DISCARD_POSITION = { x = -3.85, y = 1.5, z = 10.38 }
@ -951,7 +952,8 @@ function drawChaosTokenButton(_, _, isRightClick)
end end
function drawEncounterCard(_, _, isRightClick) function drawEncounterCard(_, _, isRightClick)
mythosAreaApi.drawEncounterCard(self, not isRightClick) local drawPos = getEncounterCardDrawPosition(not isRightClick)
mythosAreaApi.drawEncounterCard(matColor, drawPos)
end end
function returnGlobalDiscardPosition() function returnGlobalDiscardPosition()
@ -962,6 +964,29 @@ function returnGlobalDrawPosition()
return self.positionToWorld(DRAW_DECK_POSITION) return self.positionToWorld(DRAW_DECK_POSITION)
end 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 -- creates / removes the draw 1 button
---@param visible boolean Whether the draw 1 button should be visible ---@param visible boolean Whether the draw 1 button should be visible
function showDrawButton(visible) function showDrawButton(visible)

View File

@ -150,6 +150,15 @@ do
end end
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 -- 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 -- 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 -- investigator area point will only snap Investigators. If matchTypes is false, snap points will
@ -198,7 +207,7 @@ do
return count return count
end 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 matColor string Color of the playmat - White, Orange, Green, Red or All
---@param type string Counter to target ---@param type string Counter to target
---@param newValue number Value to set the counter to ---@param newValue number Value to set the counter to
@ -209,7 +218,7 @@ do
end end
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 matColor string Color of the playmat - White, Orange, Green, Red or All
---@param number number Amount of cards to draw ---@param number number Amount of cards to draw
PlaymatApi.drawCardsWithReshuffle = function(matColor, number) PlaymatApi.drawCardsWithReshuffle = function(matColor, number)
@ -218,7 +227,7 @@ do
end end
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 matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
---@param type string Counter to target ---@param type string Counter to target
PlaymatApi.getCounterValue = function(matColor, type) PlaymatApi.getCounterValue = function(matColor, type)
@ -227,15 +236,13 @@ do
end end
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() PlaymatApi.getUsedMatColors = function()
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 } local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
local usedColors = {} local usedColors = {}
for matColor, mat in pairs(getMatForColor("All")) do for matColor, mat in pairs(getMatForColor("All")) do
local searchPos = mat.positionToWorld(localInvestigatorPosition) local searchPos = mat.positionToWorld(localInvestigatorPosition)
local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck") local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck")
if #searchResult > 0 then if #searchResult > 0 then
table.insert(usedColors, matColor) table.insert(usedColors, matColor)
end end
@ -243,7 +250,7 @@ do
return usedColors return usedColors
end 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 ---@param matColor string Color of the playmat - White, Orange, Green, Red or All
PlaymatApi.resetSkillTracker = function(matColor) PlaymatApi.resetSkillTracker = function(matColor)
for _, mat in pairs(getMatForColor(matColor)) do for _, mat in pairs(getMatForColor(matColor)) do
@ -251,7 +258,7 @@ do
end end
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 matColor string Color of the playmat - White, Orange, Green, Red or All
---@param filter string Name of the filte function (see util/SearchLib) ---@param filter string Name of the filte function (see util/SearchLib)
PlaymatApi.searchAroundPlaymat = function(matColor, filter) PlaymatApi.searchAroundPlaymat = function(matColor, filter)