SCED/src/core/GenericCounter.ttslua

55 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-01-04 00:36:55 +01:00
MIN_VALUE = 0
MAX_VALUE = 99
2022-11-19 00:33:21 +01:00
val = 0
function onSave() return JSON.encode(val) end
2023-01-03 23:47:34 +01:00
function onLoad(savedData)
if savedData ~= nil then
val = JSON.decode(savedData)
end
local name = self.getName()
local position = {}
if name == "Damage" or name == "Resources" or name == "Resource Counter" then
position = { 0, 0.06, 0.1 }
elseif name == "Horror" then
position = { -0.025, 0.06, -0.025 }
2023-10-08 10:37:05 +02:00
elseif name == "Elder Sign Counter" or name == "Auto-fail Counter" then
position = { 0, 0.1, 0 }
2023-01-03 23:47:34 +01:00
else
position = { 0, 0.06, 0 }
end
self.createButton({
label = tostring(val),
click_function = "addOrSubtract",
function_owner = self,
position = position,
height = 600,
width = 1000,
scale = { 1.5, 1.5, 1.5 },
font_size = 600,
font_color = { 1, 1, 1, 100 },
color = { 0, 0, 0, 0 }
})
2023-01-04 00:36:55 +01:00
self.addContextMenuItem("Add 5", function() updateVal(val + 5) end)
self.addContextMenuItem("Subtract 5", function() updateVal(val - 5) end)
self.addContextMenuItem("Add 10", function() updateVal(val + 10) end)
self.addContextMenuItem("Subtract 10", function() updateVal(val - 10) end)
2022-11-19 00:33:21 +01:00
end
2023-01-03 23:47:34 +01:00
function updateVal(newVal)
if tonumber(newVal) then
2023-01-04 00:36:55 +01:00
val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE)
2022-11-19 00:33:21 +01:00
self.editButton({ index = 0, label = tostring(val) })
2023-01-03 23:47:34 +01:00
end
end
function addOrSubtract(_, _, isRightClick)
val = math.min(math.max(val + (isRightClick and -1 or 1), MIN_VALUE), MAX_VALUE)
self.editButton({ index = 0, label = tostring(val) })
2022-11-19 00:33:21 +01:00
end