new function for playermat api

This commit is contained in:
Chr1Z93 2022-12-22 13:45:47 +01:00
parent ee6925bf0d
commit a55d1dff58
3 changed files with 35 additions and 47 deletions

View File

@ -7,7 +7,7 @@ end
-- called by context menu entry
function shortSupply(color)
local cardPos = self.getPosition()
local mat = playmatAPI.getMatbyColor(getMatColor(cardPos))
local mat = playmatAPI.getMatbyPosition(cardPos)
if mat == nil then return end
-- get draw deck and discard pile
@ -37,22 +37,3 @@ function shortSupply(color)
})
end
end
-- helper to find playermat color based on position
function getMatColor(cardPos)
local color
if cardPos.x < -42 then
if cardPos.z > 0 then
color = "White"
else
color = "Orange"
end
else
if cardPos.z > 0 then
color = "Green"
else
color = "Red"
end
end
return color
end

View File

@ -1,4 +1,4 @@
MAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
local playmatAPI = require("playermat/PlaymatApi")
local buttonParamaters = {}
buttonParamaters.function_owner = self
@ -161,7 +161,8 @@ function discardRandom()
if #hand == 0 then
broadcastToAll("Cannot discard from empty hand!", "Red")
else
local mat = getPlayermat(playerColor)
local searchPos = Player[playerColor].getHandTransform().position
local mat = playmatAPI.getMatbyPosition(searchPos)
if mat == nil then return end
local discardPos = mat.getTable("DISCARD_PILE_POSITION")
@ -192,27 +193,3 @@ function playerExists(color)
local COLORS = Player.getAvailableColors()
return indexOf(COLORS, color) and true or false
end
-- helper to find playermat based on hand position
function getPlayermat(color)
local pos = Player[playerColor].getHandTransform().position
if pos.x < -30 then
if pos.z > 0 then
playerNumber = 1
else
playerNumber = 2
end
else
if pos.z > 0 then
playerNumber = 3
else
playerNumber = 4
end
end
local mat = getObjectFromGUID(MAT_GUIDS[playerNumber])
if mat == nil then
broadcastToAll(playerColor .. " playermat could not be found!", "Yellow")
end
return mat
end

View File

@ -26,7 +26,37 @@ do
-- Returns the by color requested playermat as object
---@param matColor String Color of the playermat to return
PlaymatApi.getMatbyColor = function(matColor)
return getObjectFromGUID(MAT_IDS[matColor])
local mat = getObjectFromGUID(MAT_IDS[matColor])
if mat == nil then
broadcastToAll(playerColor .. " playermat could not be found!", "Yellow")
end
return mat
end
-- Returns the by position requested playermat as object
---@param startPos Table Position of the search, table get's roughly cut into 4 quarters to assign a playermat
PlaymatApi.getMatbyPosition = function(startPos)
local matColor
if startPos.x < -42 then
if startPos.z > 0 then
matColor = "White"
else
matColor = "Orange"
end
else
if startPos.z > 0 then
matColor = "Green"
else
matColor = "Red"
end
end
local mat = getObjectFromGUID(MAT_IDS[matColor])
if mat == nil then
broadcastToAll(playerColor .. " playermat could not be found!", "Yellow")
end
return mat
end
-- Sets the requested playermat's snap points to limit snapping to matching card types or not. If