Merge pull request #122 from argonui/shortsupply
Card: Short Supply - Moved function from "Hand Helper" directly to card // PlaymatAPI: New functions for playermat getting
This commit is contained in:
commit
861ea501d4
@ -33,8 +33,8 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScriptState": "",
|
||||
"LuaScript_path": "AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
"Nickname": "Short Supply",
|
||||
|
36
objects/AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua
Normal file
36
objects/AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua
Normal file
@ -0,0 +1,36 @@
|
||||
local playmatAPI = require("playermat/PlaymatApi")
|
||||
|
||||
function onLoad()
|
||||
self.addContextMenuItem("Discard 10 cards", shortSupply)
|
||||
end
|
||||
|
||||
-- called by context menu entry
|
||||
function shortSupply(color)
|
||||
local matColor = playmatAPI.getMatColorByPosition(self.getPosition())
|
||||
|
||||
-- get draw deck and discard position
|
||||
local drawDeck = playmatAPI.getDrawDeck(matColor)
|
||||
local discardPos = playmatAPI.getDiscardPosition(matColor)
|
||||
|
||||
-- error handling
|
||||
if discardPos == nil then
|
||||
broadcastToColor("Couldn't retrieve discard position from playermat!", color, "Red")
|
||||
return
|
||||
end
|
||||
|
||||
if drawDeck == nil then
|
||||
broadcastToColor("Deck not found!", color, "Yellow")
|
||||
return
|
||||
elseif drawDeck.tag ~= "Deck" then
|
||||
broadcastToColor("Deck only contains a single card!", color, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- discard cards
|
||||
broadcastToColor("Discarding top 10 cards for player color '" .. matColor .. "'.", color, "White")
|
||||
discardPos.y = 0.5
|
||||
for i = 1, 10 do
|
||||
discardPos.y = discardPos.y + 0.05 * i
|
||||
drawDeck.takeObject({ flip = true, position = discardPos })
|
||||
end
|
||||
end
|
@ -41,6 +41,7 @@
|
||||
"Snap": true,
|
||||
"Sticky": true,
|
||||
"Tags": [
|
||||
"CleanUpHelper_ignore",
|
||||
"displacement_excluded"
|
||||
],
|
||||
"Tooltip": true,
|
||||
|
@ -40,6 +40,10 @@
|
||||
"Nickname": "Hand Helper",
|
||||
"Snap": true,
|
||||
"Sticky": true,
|
||||
"Tags": [
|
||||
"CleanUpHelper_ignore",
|
||||
"displacement_excluded"
|
||||
],
|
||||
"Tooltip": true,
|
||||
"Transform": {
|
||||
"posX": 37.613,
|
||||
|
@ -1,7 +1,7 @@
|
||||
MAT_GUIDS = { "8b081b", "bd0ff4", "383d8b", "0840d5" }
|
||||
local playmatAPI = require("playermat/PlaymatApi")
|
||||
|
||||
local BUTTON_PARAMETERS = {}
|
||||
BUTTON_PARAMETERS.function_owner = self
|
||||
local buttonParamaters = {}
|
||||
buttonParamaters.function_owner = self
|
||||
|
||||
-- saving "playerColor" and "des"
|
||||
function onSave() return JSON.encode({ playerColor, des}) end
|
||||
@ -13,41 +13,41 @@ function onLoad(saved_data)
|
||||
des = loaded_data[2] or false
|
||||
|
||||
-- index 0: button as hand size label
|
||||
BUTTON_PARAMETERS.hover_color = "White"
|
||||
BUTTON_PARAMETERS.click_function = "none"
|
||||
BUTTON_PARAMETERS.position = { 0, 0.1, -0.4 }
|
||||
BUTTON_PARAMETERS.height = 0
|
||||
BUTTON_PARAMETERS.width = 0
|
||||
BUTTON_PARAMETERS.font_size = 500
|
||||
BUTTON_PARAMETERS.font_color = "White"
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.hover_color = "White"
|
||||
buttonParamaters.click_function = "none"
|
||||
buttonParamaters.position = { 0, 0.11, -0.4 }
|
||||
buttonParamaters.height = 0
|
||||
buttonParamaters.width = 0
|
||||
buttonParamaters.font_size = 500
|
||||
buttonParamaters.font_color = "White"
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 1: button to toggle "des"
|
||||
BUTTON_PARAMETERS.label = "DES: " .. (des and "✓" or "✗")
|
||||
BUTTON_PARAMETERS.click_function = "toggleDES"
|
||||
BUTTON_PARAMETERS.position = { 0.475, 0.1, 0.25 }
|
||||
BUTTON_PARAMETERS.height = 175
|
||||
BUTTON_PARAMETERS.width = 440
|
||||
BUTTON_PARAMETERS.font_size = 90
|
||||
BUTTON_PARAMETERS.font_color = "Black"
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = "DES: " .. (des and "✓" or "✗")
|
||||
buttonParamaters.click_function = "toggleDES"
|
||||
buttonParamaters.position = { 0.475, 0.11, 0.25 }
|
||||
buttonParamaters.height = 175
|
||||
buttonParamaters.width = 440
|
||||
buttonParamaters.font_size = 90
|
||||
buttonParamaters.font_color = "Black"
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 2: button to discard a card
|
||||
BUTTON_PARAMETERS.label = "discard random card"
|
||||
BUTTON_PARAMETERS.click_function = "discardRandom"
|
||||
BUTTON_PARAMETERS.position = { 0, 0.1, 0.7 }
|
||||
BUTTON_PARAMETERS.width = 900
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = "discard random card"
|
||||
buttonParamaters.click_function = "discardRandom"
|
||||
buttonParamaters.position = { 0, 0.11, 0.7 }
|
||||
buttonParamaters.width = 900
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- index 3: button to select color
|
||||
BUTTON_PARAMETERS.label = playerColor
|
||||
BUTTON_PARAMETERS.color = playerColor
|
||||
BUTTON_PARAMETERS.hover_color = playerColor
|
||||
BUTTON_PARAMETERS.click_function = "changeColor"
|
||||
BUTTON_PARAMETERS.tooltip = "change color"
|
||||
BUTTON_PARAMETERS.position = { -0.475, 0.1, 0.25 }
|
||||
BUTTON_PARAMETERS.width = 440
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
buttonParamaters.label = playerColor
|
||||
buttonParamaters.color = playerColor
|
||||
buttonParamaters.hover_color = playerColor
|
||||
buttonParamaters.click_function = "changeColor"
|
||||
buttonParamaters.tooltip = "change color"
|
||||
buttonParamaters.position = { -0.475, 0.11, 0.25 }
|
||||
buttonParamaters.width = 440
|
||||
self.createButton(buttonParamaters)
|
||||
|
||||
-- start loop to update card count
|
||||
loopId = Wait.time(||updateValue(), 1, -1)
|
||||
@ -71,14 +71,6 @@ function onLoad(saved_data)
|
||||
end
|
||||
|
||||
function onObjectHover(hover_color, obj)
|
||||
-- error handling
|
||||
if obj == nil then return end
|
||||
|
||||
-- add context menu to "short supply"
|
||||
if obj.getName() == "Short Supply" then
|
||||
obj.addContextMenuItem("Discard 10 (" .. playerColor .. ")", shortSupply)
|
||||
end
|
||||
|
||||
-- only continue if correct player hovers over "self"
|
||||
if obj ~= self or hover_color ~= playerColor then return end
|
||||
|
||||
@ -151,11 +143,11 @@ function changeColor(_, _, isRightClick, color)
|
||||
end
|
||||
|
||||
-- update "change color" button (note: remove and create instantly updates hover_color)
|
||||
BUTTON_PARAMETERS.label = playerColor
|
||||
BUTTON_PARAMETERS.color = playerColor
|
||||
BUTTON_PARAMETERS.hover_color = playerColor
|
||||
buttonParamaters.label = playerColor
|
||||
buttonParamaters.color = playerColor
|
||||
buttonParamaters.hover_color = playerColor
|
||||
self.removeButton(3)
|
||||
self.createButton(BUTTON_PARAMETERS)
|
||||
self.createButton(buttonParamaters)
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
@ -169,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")
|
||||
@ -184,38 +177,6 @@ function discardRandom()
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- discards the top 10 cards of your deck
|
||||
---------------------------------------------------------
|
||||
function shortSupply(color)
|
||||
local mat = getPlayermat(playerColor)
|
||||
if mat == nil then return end
|
||||
|
||||
-- get draw deck and discard pile
|
||||
mat.call("getDrawDiscardDecks")
|
||||
drawDeck = mat.getVar("drawDeck")
|
||||
local discardPos = mat.getTable("DISCARD_PILE_POSITION")
|
||||
if discardPos == nil then
|
||||
broadcastToAll("Couldn't retrieve discard position from playermat!", "Red")
|
||||
return
|
||||
end
|
||||
|
||||
if drawDeck == nil then
|
||||
broadcastToColor("Deck not found!", color, "Yellow")
|
||||
return
|
||||
elseif drawDeck.tag ~= "Deck" then
|
||||
broadcastToColor("Deck only contains a single card!", color, "Yellow")
|
||||
return
|
||||
end
|
||||
|
||||
-- discard cards
|
||||
discardPos[2] = 0.5
|
||||
for i = 1, 10 do
|
||||
discardPos[2] = discardPos[2] + 0.05 * i
|
||||
drawDeck.takeObject({ flip = true; position = discardPos })
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------
|
||||
-- helper functions
|
||||
---------------------------------------------------------
|
||||
@ -232,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
|
||||
|
@ -3,26 +3,59 @@ do
|
||||
local internal = { }
|
||||
|
||||
local MAT_IDS = {
|
||||
White = "8b081b",
|
||||
White = "8b081b",
|
||||
Orange = "bd0ff4",
|
||||
Green = "383d8b",
|
||||
Red = "0840d5"
|
||||
Green = "383d8b",
|
||||
Red = "0840d5"
|
||||
}
|
||||
|
||||
local CLUE_COUNTER_GUIDS = {
|
||||
White = "37be78",
|
||||
White = "37be78",
|
||||
Orange = "1769ed",
|
||||
Green = "032300",
|
||||
Red = "d86b7c"
|
||||
Green = "032300",
|
||||
Red = "d86b7c"
|
||||
}
|
||||
|
||||
local CLUE_CLICKER_GUIDS = {
|
||||
White = "db85d6",
|
||||
White = "db85d6",
|
||||
Orange = "3f22e5",
|
||||
Green = "891403",
|
||||
Red = "4111de"
|
||||
Green = "891403",
|
||||
Red = "4111de"
|
||||
}
|
||||
|
||||
-- Returns the color of the by position requested playermat as string
|
||||
---@param startPos Table Position of the search, table get's roughly cut into 4 quarters to assign a playermat
|
||||
PlaymatApi.getMatColorByPosition = function(startPos)
|
||||
if startPos.x < -42 then
|
||||
if startPos.z > 0 then
|
||||
return "White"
|
||||
else
|
||||
return "Orange"
|
||||
end
|
||||
else
|
||||
if startPos.z > 0 then
|
||||
return "Green"
|
||||
else
|
||||
return "Red"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the draw deck of the requested playmat
|
||||
---@param matColor String Color of the playermat
|
||||
PlaymatApi.getDrawDeck = function(matColor)
|
||||
local mat = getObjectFromGUID(MAT_IDS[matColor])
|
||||
mat.call("getDrawDiscardDecks")
|
||||
return mat.getVar("drawDeck")
|
||||
end
|
||||
|
||||
-- Returns the position of the discard pile of the requested playmat
|
||||
---@param matColor String Color of the playermat
|
||||
PlaymatApi.getDiscardPosition = function(matColor)
|
||||
local mat = getObjectFromGUID(MAT_IDS[matColor])
|
||||
return mat.getTable("DISCARD_PILE_POSITION")
|
||||
end
|
||||
|
||||
-- Sets the requested playermat'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
|
||||
-- investigator area point will only snap Investigators. If matchTypes is false, snap points will
|
||||
@ -79,7 +112,7 @@ do
|
||||
-- Convenience function to look up a mat's object by color, or get all mats.
|
||||
---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also
|
||||
-- accepts "All" as a special value which will return all four mats.
|
||||
---@return Array of playermat objects. If a single mat is requested, will return a single-element
|
||||
---@return: Array of playermat objects. If a single mat is requested, will return a single-element
|
||||
-- array to simplify processing by consumers.
|
||||
internal.getMatForColor = function(matColor)
|
||||
local targetMatGuid = MAT_IDS[matColor]
|
||||
|
Loading…
x
Reference in New Issue
Block a user