code improvement by api addition
This commit is contained in:
parent
3beb85d633
commit
76e5d3e5f6
@ -219,40 +219,42 @@ function switchSeat(playerColor, direction)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get legal colors
|
-- sort function for matcolors based on hand position (Green, White, Orange, Red)
|
||||||
local seatList = Player.getAvailableColors()
|
|
||||||
|
|
||||||
-- sort colors on hand position (Green, White, Orange, Red)
|
|
||||||
local function sortByHandPosition(color1, color2)
|
local function sortByHandPosition(color1, color2)
|
||||||
local pos1 = Player[color1].getHandTransform().position
|
local pos1 = Player[color1].getHandTransform().position
|
||||||
local pos2 = Player[color2].getHandTransform().position
|
local pos2 = Player[color2].getHandTransform().position
|
||||||
return pos1.z > pos2.z
|
return pos1.z > pos2.z
|
||||||
end
|
end
|
||||||
table.sort(seatList, sortByHandPosition)
|
|
||||||
|
-- get used playermats
|
||||||
|
local usedColors = playmatApi.getUsedMatColors()
|
||||||
|
table.sort(usedColors, sortByHandPosition)
|
||||||
|
|
||||||
-- get current seat index
|
-- get current seat index
|
||||||
local index
|
local index
|
||||||
for i, color in ipairs(seatList) do
|
for i, color in ipairs(usedColors) do
|
||||||
if color == playerColor then
|
if color == playerColor then
|
||||||
index = i
|
index = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not index then
|
if not index then
|
||||||
broadcastToColor("Couldn't find position of seated color.", playerColor, "Orange")
|
broadcastToColor("Couldn't detect investigator.", playerColor, "Orange")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get next color
|
-- get next color
|
||||||
index = index + ((direction == "clockwise") and -1 or 1)
|
index = index + ((direction == "clockwise") and -1 or 1)
|
||||||
if index == 0 then
|
if index == 0 then
|
||||||
index = #seatList
|
index = #usedColors
|
||||||
elseif index > #seatList then
|
elseif index > #usedColors then
|
||||||
index = 1
|
index = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- swap color
|
-- swap color
|
||||||
Player[playerColor].changeColor(seatList[index])
|
local newMatColor = usedColors[index]
|
||||||
|
local newHandColor = playmatApi.getMatColorByPosition(Player[newMatColor].getHandTransform().position)
|
||||||
|
Player[playerColor].changeColor(newHandColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- takes a clue from a location, player needs to hover the clue directly or the location
|
-- 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
|
-- only continue for decks or cards
|
||||||
if hoveredObject.type ~= "Deck" and hoveredObject.type ~= "Card" then return end
|
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
|
-- 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)
|
local deckAreaObjects = playmatApi.getDeckAreaObjects(color)
|
||||||
if deckAreaObjects.topCard == hoveredObject or deckAreaObjects.draw == hoveredObject then
|
if deckAreaObjects.topCard == hoveredObject or deckAreaObjects.draw == hoveredObject then
|
||||||
playmatApi.drawCardsWithReshuffle(color, number)
|
playmatApi.drawCardsWithReshuffle(color, number)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
do
|
do
|
||||||
local PlaymatApi = {}
|
local PlaymatApi = {}
|
||||||
local guidReferenceApi = require("core/GUIDReferenceApi")
|
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.
|
-- 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
|
---@param matColor String Color of the playmat - White, Orange, Green, Red or All
|
||||||
@ -198,6 +199,22 @@ do
|
|||||||
end
|
end
|
||||||
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"
|
-- 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user