Class SUG
Self Updating Gauge, extends Geyser.Gauge
Info:
- Copyright: 2020 Damian Monogue
- License: MIT, see LICENSE.lua
- Author: Damian Monogue
Methods
sug:new(cons, container) | Creates a new Self Updating Gauge. |
sug:setUpdateTime(time) | Set how often to update the gauge on a timer |
sug:setUpdateEvent(event) | Set the event to listen for to update the gauge |
sug:setCurrentVariable(variableName) | Set the name of the variable the Self Updating Gauge watches for the 'current' value of the gauge |
sug:setMaxVariable(variableName) | Set the name of the variable the Self Updating Gauge watches for the 'max' value of the gauge |
sug:setTextTemplate(template) | Set the template for the Self Updating Gauge to set the text with. |
sug:setUpdateHook(func) | Set the updateHook function which is run just prior to the gauge updating |
sug:stop() | Stops the Self Updating Gauge from updating |
sug:start() | Starts the Self Updating Gauge updating. |
sug:update() | Reads the values from currentVariable and maxVariable, and updates the gauge's value and text. |
Methods
- sug:new(cons, container) line 91
-
Creates a new Self Updating Gauge.
Parameters:
- cons
table
table of options which control the Gauge's behaviour. In addition to all valid contraints for Geyser.Gauge, SUG adds:
name description default active boolean, if true starts the timer updating true updateTime How often should the gauge autoupdate? Milliseconds. 0 to disable the timer but still allow event updates 333 currentVariable What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "currentHP" or "gmcp.Char.Vitals.hp" "" maxVariable What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "maxHP" or "gmcp.Char.Vitals.maxhp" "" textTemplate Template to use for the text on the gauge. "|c" replaced with current value, "|m" replaced with max value, "|p" replaced with the % full the gauge should be " |c/|m |p%" defaultCurrent What value to use if the currentVariable points to nil or something which cannot be made a number? 50 defaultMax What value to use if the maxVariable points to nil or something which cannot be made a number? 100 updateEvent The name of an event to listen for to perform an update. Can be run alongside or instead of the timer updates. Empty string to turn off "" updateHook A function which is run each time the gauge updates. Should take 3 arguments, the gauge itself, current value, and max value. You can return new current and max values to be used, for example `return 34, 120` would cause the gauge to use 34 for current and 120 for max regardless of what the variables it reads say. - container The Geyser container for this gauge
Usage:
local SUG = require("MDK.sug") --the following will watch "gmcp.Char.Vitals.hp" and "gmcp.Char.Vitals.maxhp" and update itself every 333 milliseconds myGauge = SUG:new({ name = "myGauge", currentVariable = "gmcp.Char.Vitals.hp", --if this is nil, it will use the defaultCurrent of 50 maxVariable = "gmcp.Char.Vitals.maxhp", --if this is nil, it will use the defaultMax of 100. height = 50, })
- cons
table
table of options which control the Gauge's behaviour. In addition to all valid contraints for Geyser.Gauge, SUG adds:
- sug:setUpdateTime(time) line 115
-
Set how often to update the gauge on a timer
Parameters:
- time number time in milliseconds. 0 to disable the timer
- sug:setUpdateEvent(event) line 126
-
Set the event to listen for to update the gauge
Parameters:
- event string the name of the event to listen for, use "" to disable events without stopping any existing timers
- sug:setCurrentVariable(variableName) line 137
-
Set the name of the variable the Self Updating Gauge watches for the 'current' value of the gauge
Parameters:
- variableName string The name of the variable to get the current value for the gauge. For instance "currentHP", "gmcp.Char.Vitals.hp" etc
- sug:setMaxVariable(variableName) line 152
-
Set the name of the variable the Self Updating Gauge watches for the 'max' value of the gauge
Parameters:
- variableName string The name of the variable to get the max value for the gauge. For instance "maxHP", "gmcp.Char.Vitals.maxhp" etc. Set to "" to only check the current value
- sug:setTextTemplate(template) line 172
-
Set the template for the Self Updating Gauge to set the text with. "|c" is replaced by the current value, "|m" is replaced by the max value, and "|p" is replaced by the percentage current/max
Parameters:
- template string The template to use for the text on the gauge. If the max value is 200 and current is 68, then |c will be replace by 68, |m replaced by 200, and |p replaced by 34.
- sug:setUpdateHook(func) line 182
-
Set the updateHook function which is run just prior to the gauge updating
Parameters:
- func function The function which will be called when the gauge updates. It should take 3 arguments, the gauge itself, the current value, and the max value. If you wish to override the current or max values used for the gauge, you can return new current and max values, like `return newCurrent newMax`
- sug:stop() line 191
- Stops the Self Updating Gauge from updating
- sug:start() line 204
- Starts the Self Updating Gauge updating. If it is already updating, it will restart it.
- sug:update() line 218
- Reads the values from currentVariable and maxVariable, and updates the gauge's value and text.