adds context menu option to 'Well Connected' player cards to display skill boost value right on the card

This commit is contained in:
bankey 2023-08-29 15:56:12 -04:00
parent bc6c405abe
commit 7f58638ef8
6 changed files with 120 additions and 2 deletions

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/WellConnected\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -33,7 +33,7 @@
"IgnoreFoW": false, "IgnoreFoW": false,
"LayoutGroupSortIndex": 0, "LayoutGroupSortIndex": 0,
"Locked": false, "Locked": false,
"LuaScript": "", "LuaScript": "require(\"playercards/cards/WellConnected3\")",
"LuaScriptState": "", "LuaScriptState": "",
"MeasureMovement": false, "MeasureMovement": false,
"Name": "Card", "Name": "Card",

View File

@ -0,0 +1,52 @@
local playmatApi = require("playermat/PlaymatApi")
local display = false
local count = 0
local modValue = 5
local loopId = nil
local b_display = {
index = 0,
click_function = 'none',
function_owner = self,
position = {-0.25,1,-0.75},
font_color = {1,1,1,100},
font_size = 250,
width = 0,
height = 0
}
function onLoad()
self.addContextMenuItem('Toggle Counter', toggleCounter)
end
function toggleCounter()
display = not display
if display then
createUpdateDisplay()
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
else
Wait.stop(loopId)
self.clearButtons()
loopId = nil
end
end
function createUpdateDisplay()
count = math.max(math.floor(getPlayerResources() / modValue), 0)
b_display.label = tostring(count)
if loopId == nil then
self.createButton(b_display)
else
self.editButton(b_display)
end
end
function getPlayerResources()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
return playmatApi.getResourceCount(matColor)
end

View File

@ -0,0 +1,52 @@
local playmatApi = require("playermat/PlaymatApi")
local display = false
local count = 0
local modValue = 4
local loopId = nil
local b_display = {
index = 0,
click_function = 'none',
function_owner = self,
position = {-0.25,1,-0.75},
font_color = {1,1,1,100},
font_size = 250,
width = 0,
height = 0
}
function onLoad()
self.addContextMenuItem('Toggle Counter', toggleCounter)
end
function toggleCounter()
display = not display
if display then
createUpdateDisplay()
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
else
Wait.stop(loopId)
self.clearButtons()
loopId = nil
end
end
function createUpdateDisplay()
count = math.max(math.floor(getPlayerResources() / modValue), 0)
b_display.label = tostring(count)
if loopId == nil then
self.createButton(b_display)
else
self.editButton(b_display)
end
end
function getPlayerResources()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
return playmatApi.getResourceCount(matColor)
end

View File

@ -361,6 +361,11 @@ function gainResources(amount)
RESOURCE_COUNTER.call("updateVal", count + add) RESOURCE_COUNTER.call("updateVal", count + add)
end end
-- returns the resource counter amount
function getResourceCount()
return RESOURCE_COUNTER.getVar("val")
end
-- function for "draw 1 button" (that can be added via option panel) -- function for "draw 1 button" (that can be added via option panel)
function doDrawOne(_, color) function doDrawOne(_, color)
-- send messages to player who clicked button if no seated player found -- send messages to player who clicked button if no seated player found

View File

@ -178,6 +178,15 @@ do
end end
end end
-- Returns the resource counter amount for the requested playermat
PlaymatApi.getResourceCount = function(matColor)
local resources = 0
for _, mat in ipairs(internal.getMatForColor(matColor)) do
resources = resources + mat.call("getResourceCount")
end
return resources
end
-- Discard a non-hidden card from the corresponding player's hand -- Discard a non-hidden card from the corresponding player's hand
PlaymatApi.doDiscardOne = function(matColor) PlaymatApi.doDiscardOne = function(matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do for _, mat in ipairs(internal.getMatForColor(matColor)) do