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: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)
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 ""
  • 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,
    })
SUG:setUpdateTime(time)
Set how often to update the gauge on a timer

Parameters:

  • time number time in milliseconds. 0 to disable the timer
SUG:setUpdateEvent(event)
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)
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)
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)
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:stop()
Stops the Self Updating Gauge from updating
SUG:start()
Starts the Self Updating Gauge updating. If it is already updating, it will restart it.
SUG:update()
Reads the values from currentVariable and maxVariable, and updates the gauge's value and text.
generated by LDoc 1.4.6 Last updated 2021-08-31 18:42:52