diff --git a/src/core/GenericCounter.ttslua b/src/core/GenericCounter.ttslua index 3400d123..d21ff1c7 100644 --- a/src/core/GenericCounter.ttslua +++ b/src/core/GenericCounter.ttslua @@ -1,5 +1,5 @@ -MIN_VALUE = -99 -MAX_VALUE = 999 +MIN_VALUE = 0 +MAX_VALUE = 99 val = 0 function onSave() return JSON.encode(val) end @@ -33,23 +33,15 @@ function onLoad(savedData) color = { 0, 0, 0, 0 } }) - if name == "Resource Counter" then - self.addContextMenuItem("Set to description", function(color) setToDescription(color) end) - end -end - -function setToDescription(color) - local newVal = tonumber(self.getDescription()) - if type(newVal) == "number" and newVal <= 99 and newVal >= 0 then - updateVal(newVal) - else - printToColor("Description does not contain a valid number!", color, "Orange") - end + 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) end function updateVal(newVal) if tonumber(newVal) then - val = newVal + val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE) self.editButton({ index = 0, label = tostring(val) }) end end