Merge pull request #368 from bankey1443/scriptedWellConnected
Scripted Well Connected
This commit is contained in:
commit
f8c8ff2774
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/WellConnected\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"IgnoreFoW": false,
|
||||
"LayoutGroupSortIndex": 0,
|
||||
"Locked": false,
|
||||
"LuaScript": "",
|
||||
"LuaScript": "require(\"playercards/cards/WellConnected\")",
|
||||
"LuaScriptState": "",
|
||||
"MeasureMovement": false,
|
||||
"Name": "Card",
|
||||
|
72
src/playercards/cards/WellConnected.ttslua
Normal file
72
src/playercards/cards/WellConnected.ttslua
Normal file
@ -0,0 +1,72 @@
|
||||
-- this script is shared between both the level 0 and the upgraded level 3 version of the card
|
||||
local playmatApi = require("playermat/PlaymatApi")
|
||||
|
||||
local display = false
|
||||
local count = 0
|
||||
local modValue = 5 -- level 0 Well Connected
|
||||
local loopId = nil
|
||||
|
||||
local b_display = {
|
||||
click_function = "toggleCounter",
|
||||
function_owner = self,
|
||||
position = {0.88,0.5,-1.33},
|
||||
font_size = 150,
|
||||
width = 175,
|
||||
height = 175
|
||||
}
|
||||
|
||||
function onLoad(saved_data)
|
||||
local notes = JSON.decode(self.getGMNotes())
|
||||
|
||||
if notes.id == "54006" then -- hardcoded card id for upgraded Well Connected (3)
|
||||
modValue = 4 -- Well Connected (3)
|
||||
end
|
||||
|
||||
if saved_data != '' then
|
||||
local loaded_data = JSON.decode(saved_data)
|
||||
display = not loaded_data.saved_display
|
||||
|
||||
self.clearButtons()
|
||||
toggleCounter()
|
||||
end
|
||||
|
||||
self.addContextMenuItem('Toggle Counter', toggleCounter)
|
||||
end
|
||||
|
||||
function onSave()
|
||||
return JSON.encode({saved_display = display})
|
||||
end
|
||||
|
||||
function toggleCounter()
|
||||
display = not display
|
||||
|
||||
if display then
|
||||
createUpdateDisplay()
|
||||
loopId = Wait.time(|| createUpdateDisplay(), 2, -1)
|
||||
else
|
||||
if loopId ~= nil then
|
||||
Wait.stop(loopId)
|
||||
end
|
||||
|
||||
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
|
@ -361,6 +361,11 @@ function gainResources(amount)
|
||||
RESOURCE_COUNTER.call("updateVal", count + add)
|
||||
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 doDrawOne(_, color)
|
||||
-- send messages to player who clicked button if no seated player found
|
||||
|
@ -178,6 +178,12 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the resource counter amount for the requested playermat
|
||||
PlaymatApi.getResourceCount = function(matColor)
|
||||
local mat = getObjectFromGUID(MAT_IDS[matColor])
|
||||
return mat.call("getResourceCount")
|
||||
end
|
||||
|
||||
-- Discard a non-hidden card from the corresponding player's hand
|
||||
PlaymatApi.doDiscardOne = function(matColor)
|
||||
for _, mat in ipairs(internal.getMatForColor(matColor)) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user