code improvement by api addition
This commit is contained in:
parent
3beb85d633
commit
76e5d3e5f6
@ -219,40 +219,42 @@ function switchSeat(playerColor, direction)
|
||||
return
|
||||
end
|
||||
|
||||
-- get legal colors
|
||||
local seatList = Player.getAvailableColors()
|
||||
|
||||
-- sort colors on hand position (Green, White, Orange, Red)
|
||||
-- sort function for matcolors based on hand position (Green, White, Orange, Red)
|
||||
local function sortByHandPosition(color1, color2)
|
||||
local pos1 = Player[color1].getHandTransform().position
|
||||
local pos2 = Player[color2].getHandTransform().position
|
||||
return pos1.z > pos2.z
|
||||
end
|
||||
table.sort(seatList, sortByHandPosition)
|
||||
|
||||
-- get used playermats
|
||||
local usedColors = playmatApi.getUsedMatColors()
|
||||
table.sort(usedColors, sortByHandPosition)
|
||||
|
||||
-- get current seat index
|
||||
local index
|
||||
for i, color in ipairs(seatList) do
|
||||
for i, color in ipairs(usedColors) do
|
||||
if color == playerColor then
|
||||
index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if not index then
|
||||
broadcastToColor("Couldn't find position of seated color.", playerColor, "Orange")
|
||||
broadcastToColor("Couldn't detect investigator.", playerColor, "Orange")
|
||||
return
|
||||
end
|
||||
|
||||
-- get next color
|
||||
index = index + ((direction == "clockwise") and -1 or 1)
|
||||
if index == 0 then
|
||||
index = #seatList
|
||||
elseif index > #seatList then
|
||||
index = #usedColors
|
||||
elseif index > #usedColors then
|
||||
index = 1
|
||||
end
|
||||
|
||||
-- swap color
|
||||
Player[playerColor].changeColor(seatList[index])
|
||||
local newMatColor = usedColors[index]
|
||||
local newHandColor = playmatApi.getMatColorByPosition(Player[newMatColor].getHandTransform().position)
|
||||
Player[playerColor].changeColor(newHandColor)
|
||||
end
|
||||
|
||||
-- takes a clue from a location, player needs to hover the clue directly or the location
|
||||
|
@ -206,26 +206,8 @@ function onObjectNumberTyped(hoveredObject, playerColor, number)
|
||||
-- only continue for decks or cards
|
||||
if hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Card" then return end
|
||||
|
||||
-- get playmat colors with an investigator card
|
||||
local localInvestigatorPosition = { x = -1.17, y = 1, z = -0.01 }
|
||||
local matColors = { "White", "Orange", "Green", "Red" }
|
||||
local legalColors = {}
|
||||
|
||||
for _, color in ipairs(matColors) do
|
||||
local mat = guidReferenceApi.getObjectByOwnerAndType(color, "Playermat")
|
||||
if mat ~= nil then
|
||||
local searchPos = mat.positionToWorld(localInvestigatorPosition)
|
||||
local searchResult = searchLib.atPosition(searchPos, "isCardOrDeck")
|
||||
|
||||
if #searchResult > 0 then
|
||||
table.insert(legalColors, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #legalColors == 0 then return end
|
||||
|
||||
-- check whether the hovered object is part of a players draw objects
|
||||
for _, color in ipairs(legalColors) do
|
||||
for _, color in ipairs(playmatApi.getUsedMatColors()) do
|
||||
local deckAreaObjects = playmatApi.getDeckAreaObjects(color)
|
||||
if deckAreaObjects.topCard == hoveredObject or deckAreaObjects.draw == hoveredObject then
|
||||
playmatApi.drawCardsWithReshuffle(color, number)
|
||||
|
@ -1,6 +1,7 @@
|
||||
do
|
||||
local PlaymatApi = {}
|
||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
||||
local searchLib = require("util/SearchLib")
|
||||
|
||||
-- Convenience function to look up a mat's object by color, or get all mats.
|
||||
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||
@ -198,6 +199,22 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- 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
|
||||
end
|
||||
return usedColors
|
||||
end
|
||||
|
||||
-- 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)
|
||||
|
Loading…
Reference in New Issue
Block a user