2023-01-05 20:02:24 -05:00
|
|
|
local playmatAPI = require("playermat/PlaymatApi")
|
2022-11-11 02:59:55 -05:00
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- forward declaration of variables that are used across functions
|
|
|
|
local matColor
|
|
|
|
local setAsidePosition
|
|
|
|
local setAsideRotation
|
|
|
|
local drawDeckPosition
|
|
|
|
|
|
|
|
local quickParameters = {}
|
|
|
|
quickParameters.function_owner = self
|
2023-01-06 04:36:57 -05:00
|
|
|
quickParameters.font_size = 165
|
2023-01-05 20:02:24 -05:00
|
|
|
quickParameters.width = 275
|
|
|
|
quickParameters.height = 275
|
|
|
|
quickParameters.color = "White"
|
2022-11-11 02:59:55 -05:00
|
|
|
|
|
|
|
-- common parameters
|
2022-11-12 09:36:48 -05:00
|
|
|
local buttonParameters = {}
|
|
|
|
buttonParameters.function_owner = self
|
|
|
|
buttonParameters.font_size = 125
|
|
|
|
buttonParameters.width = 650
|
|
|
|
buttonParameters.height = 225
|
2023-01-05 20:02:24 -05:00
|
|
|
buttonParameters.color = "White"
|
2022-11-12 09:36:48 -05:00
|
|
|
|
|
|
|
local inputParameters = {}
|
|
|
|
inputParameters.function_owner = self
|
|
|
|
inputParameters.input_function = "updateSearchNumber"
|
2023-01-05 20:02:24 -05:00
|
|
|
inputParameters.tooltip = "custom search amount"
|
2022-11-12 09:36:48 -05:00
|
|
|
inputParameters.label = "#"
|
|
|
|
inputParameters.font_size = 175
|
|
|
|
inputParameters.width = 400
|
|
|
|
inputParameters.height = inputParameters.font_size + 23
|
|
|
|
inputParameters.position = { 0, 0.11, 0 }
|
|
|
|
inputParameters.alignment = 3
|
|
|
|
inputParameters.validation = 2
|
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
function onLoad()
|
|
|
|
normalView()
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- regular view with search box
|
2022-11-11 02:59:55 -05:00
|
|
|
function normalView()
|
2023-01-05 20:02:24 -05:00
|
|
|
self.clearButtons()
|
|
|
|
self.clearInputs()
|
|
|
|
self.createInput(inputParameters)
|
|
|
|
|
|
|
|
-- create custom search button
|
|
|
|
buttonParameters.click_function = "searchCustom"
|
|
|
|
buttonParameters.tooltip = "Search the entered number of cards"
|
|
|
|
buttonParameters.position = { 0, 0.11, 0.65 }
|
|
|
|
buttonParameters.label = "Search"
|
|
|
|
self.createButton(buttonParameters)
|
|
|
|
|
|
|
|
-- create buttons to search 3, 6 or 9 cards
|
2023-01-06 04:36:57 -05:00
|
|
|
quickParameters.click_function = "search3"
|
|
|
|
quickParameters.label = "3"
|
|
|
|
quickParameters.position = { -0.65, 0.11, -0.65 }
|
|
|
|
self.createButton(quickParameters)
|
2022-11-11 02:59:55 -05:00
|
|
|
|
2023-01-06 04:36:57 -05:00
|
|
|
quickParameters.click_function = "search6"
|
|
|
|
quickParameters.label = "6"
|
|
|
|
quickParameters.position = { 0, 0.11, -0.65 }
|
|
|
|
self.createButton(quickParameters)
|
|
|
|
|
|
|
|
quickParameters.click_function = "search9"
|
|
|
|
quickParameters.label = "9"
|
|
|
|
quickParameters.position = { 0.65, 0.11, -0.65 }
|
|
|
|
self.createButton(quickParameters)
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
2023-01-06 04:36:57 -05:00
|
|
|
-- click functions
|
|
|
|
function search3(_, playerColor) startSearch(playerColor, 3) end
|
|
|
|
function search6(_, playerColor) startSearch(playerColor, 6) end
|
|
|
|
function search9(_, playerColor) startSearch(playerColor, 9) end
|
|
|
|
|
2022-11-11 02:59:55 -05:00
|
|
|
-- view during a search with "done" buttons
|
|
|
|
function searchView()
|
2023-01-05 20:02:24 -05:00
|
|
|
self.clearButtons()
|
|
|
|
self.clearInputs()
|
|
|
|
|
|
|
|
-- create the "End Search" button
|
|
|
|
buttonParameters.click_function = "endSearch"
|
|
|
|
buttonParameters.tooltip = "Left-click: Return cards and shuffle\nRight-click: Return cards without shuffling"
|
|
|
|
buttonParameters.position = { 0, 0.11, 0 }
|
|
|
|
buttonParameters.label = "End Search"
|
|
|
|
self.createButton(buttonParameters)
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
-- input_function to get number of cards to search
|
|
|
|
function updateSearchNumber(_, _, input)
|
2023-01-05 20:02:24 -05:00
|
|
|
inputParameters.value = tonumber(input)
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- starts the search with the number from the input field
|
|
|
|
function searchCustom(_, messageColor)
|
|
|
|
local number = inputParameters.value
|
|
|
|
if number ~= nil then
|
|
|
|
startSearch(messageColor, number)
|
|
|
|
else
|
|
|
|
printToColor("Enter the number of cards to search in the textbox.", messageColor, "Orange")
|
|
|
|
end
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- start the search (change UI, set handCards aside, draw cards)
|
|
|
|
function startSearch(messageColor, number)
|
|
|
|
matColor = playmatAPI.getMatColorByPosition(self.getPosition())
|
|
|
|
|
|
|
|
-- get draw deck
|
|
|
|
local drawDeck = playmatAPI.getDrawDeck(matColor)
|
|
|
|
if drawDeck == nil then
|
|
|
|
printToColor(matColor .. " draw deck could not be found!", messageColor, "Red")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
drawDeckPosition = drawDeck.getPosition()
|
|
|
|
printToColor("Place target(s) of search on set aside hand.", messageColor, "Green")
|
|
|
|
|
|
|
|
-- get playmat orientation
|
|
|
|
local offset = -15
|
|
|
|
if matColor == "Orange" or matColor == "Red" then
|
|
|
|
offset = 15
|
|
|
|
end
|
|
|
|
|
|
|
|
-- get position and rotation for set aside cards
|
|
|
|
local handData = Player[matColor].getHandTransform()
|
|
|
|
local handCards = Player[matColor].getHandObjects()
|
|
|
|
setAsidePosition = handData.position + offset * handData.right
|
|
|
|
setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 }
|
|
|
|
|
|
|
|
for i = #handCards, 1, -1 do
|
|
|
|
handCards[i].setPosition(setAsidePosition - Vector(0, i * 0.3, 0))
|
|
|
|
handCards[i].setRotation(setAsideRotation)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- handling for Norman Withers
|
|
|
|
for _, v in ipairs(searchArea(drawDeckPosition)) do
|
|
|
|
local object = v.hit_object
|
|
|
|
if object.tag == "Card" and not object.is_face_down then
|
|
|
|
object.flip()
|
|
|
|
Wait.time(function() drawDeck = playmatAPI.getDrawDeck(matColor) end, 1)
|
|
|
|
break
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
2023-01-05 20:02:24 -05:00
|
|
|
end
|
2022-11-11 02:59:55 -05:00
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
Wait.time(function() drawDeck.deal(number, matColor) end, 1)
|
|
|
|
searchView()
|
|
|
|
end
|
2022-11-11 02:59:55 -05:00
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- place handCards back into deck and optionally shuffle
|
|
|
|
function endSearch(_, _, isRightClick)
|
|
|
|
local handCards = Player[matColor].getHandObjects()
|
|
|
|
|
|
|
|
for i = #handCards, 1, -1 do
|
|
|
|
handCards[i].setPosition(drawDeckPosition + Vector(0, 6 - i * 0.3, 0))
|
|
|
|
handCards[i].setRotation(setAsideRotation)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not isRightClick then
|
|
|
|
Wait.time(function()
|
|
|
|
local deck = playmatAPI.getDrawDeck(matColor)
|
|
|
|
if deck ~= nil then
|
|
|
|
deck.shuffle()
|
|
|
|
end
|
|
|
|
end, 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- draw set aside cards (from the ground!)
|
|
|
|
for _, v in ipairs(searchArea(setAsidePosition - Vector(0, 5, 0))) do
|
|
|
|
local obj = v.hit_object
|
|
|
|
if obj.tag == "Deck" then
|
|
|
|
Wait.time(function()
|
|
|
|
obj.deal(#obj.getObjects(), matColor)
|
|
|
|
end, 1)
|
|
|
|
break
|
|
|
|
elseif obj.tag == "Card" then
|
|
|
|
obj.setPosition(Player[matColor].getHandTransform().position)
|
|
|
|
obj.flip()
|
|
|
|
break
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
2023-01-05 20:02:24 -05:00
|
|
|
end
|
2022-11-11 02:59:55 -05:00
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
normalView()
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|
|
|
|
|
2023-01-05 20:02:24 -05:00
|
|
|
-- utility function
|
|
|
|
function searchArea(position)
|
|
|
|
return Physics.cast({
|
|
|
|
origin = position,
|
|
|
|
direction = { 0, 1, 0 },
|
|
|
|
type = 3,
|
|
|
|
size = { 2, 2, 2 },
|
|
|
|
max_distance = 0
|
|
|
|
})
|
2022-11-11 02:59:55 -05:00
|
|
|
end
|