added well connected to list of supported cards

This commit is contained in:
Chr1Z93 2024-06-26 00:19:37 +02:00
parent 03d5613570
commit 7a1f67d89f

View File

@ -1,10 +1,8 @@
require("playercards/CardsWithHelper")
local playmatApi = require("playermat/PlaymatApi")
local modValue, loopId
local buttonParameters = {
click_function = "toggleCounter",
tooltip = "disable counter",
click_function = "shutOff",
function_owner = self,
position = { 0.88, 0.5, -1.33 },
font_size = 150,
@ -12,7 +10,14 @@ local buttonParameters = {
height = 175
}
function onSave() return JSON.encode({ loopId = loopId }) end
local modValue, loopId
function updateSave()
self.script_state = JSON.encode({
isHelperEnabled = isHelperEnabled,
loopId = loopId
})
end
function onLoad(savedData)
-- use metadata to detect level and adjust modValue accordingly
@ -22,30 +27,31 @@ function onLoad(savedData)
modValue = 4
end
if savedData ~= "" then
self.addTag("CardWithHelper")
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
if loadedData.loopId then
isHelperEnabled = loadedData.isHelperEnabled
loopId = loadedData.loopId
end
checkOptionPanel()
updateDisplay()
end
function initialize()
self.createButton(buttonParameters)
loopId = Wait.time(updateDisplay, 2, -1)
end
updateButton()
loopId = Wait.time(updateButton, 2, -1)
end
self.addContextMenuItem("Toggle Counter", toggleCounter)
end
function toggleCounter()
if loopId ~= nil then
function shutOff()
if loopId then
Wait.stop(loopId)
loopId = nil
self.clearButtons()
else
self.createButton(buttonParameters)
updateDisplay()
loopId = Wait.time(updateDisplay, 2, -1)
end
self.clearButtons()
end
function updateDisplay()
function updateButton()
local matColor = playmatApi.getMatColorByPosition(self.getPosition())
local resources = playmatApi.getCounterValue(matColor, "ResourceCounter")
local count = tostring(math.floor(resources / modValue))