by mattekure
Description
This extension adds a timer capability into FG. While the extension may be useful for some purely for its timer function, it is also intended for other extension authors which can tie into the timer system. The inspiration for this came from the Combat Timer extension, but its implementation is entirely different.
Details (for extension authors)
Description: This extension uses the Interface.openURL() function to create an internal counter. To reduce CPU and Network usage, it uses calls to my own web service which provides a delay. The response is discarded without processing, and the clock updated using the os.time() functions. Due to the asynchronous nature of that function call, it is possible to recursively call it without much impact to FG performance. The counter has a resolution of 1 second. When the timer is started, it continuously counts up. There is a button in the sidebar to open the timer window. The timer will continue running even if the window is closed. You can also start/stop the timer using the slash command /timer [start|stop]
Extension Authors
One of my goals in creating this extension is to make it useful for other extension authors to have a way to hook into a timer. For that reason, I am leaving it installed to the extensions directory so anyone can take a look at how I made it. I have also included an API to hook into the timers. At any time, there should only ever be 1 timer running. For other extensions, they should use the register/unregister api functions below to hook into the running timer. All of the code in this extension is free to use in any way you wish.
If anyone has any suggestions for improving it, I'd love to hear it.
API Functions
TimerManager.startTimer() - Begins the timer.
Parameters: none
Return Value: none
TimerManager.stopTimer() - Stops the timer
Parameters: None
Return Value: None
TimerManager.registerTimerAction(fn, delay) - Register a callback function to occur when the timer updates its value. (I typically register this in a windows onInit()). When the callback function is called, it includes a single parameter which is the current value of the timer clock in seconds.
Parameters:
fn - The function to call
delay - An integer number of seconds between calls. Min 1. A value of 1 will call the registered callback function once per second. a value of 2 will occur every 2 seconds, etc.
Return Value: none
TimerManager.unregisterTimerAction(fn, delay) - Unregister a previously registered function. If you have functions registered by a window, I highly recommend to unregister all actions when the window is closed to avoid having old or unlinked entries in the callback list. Examples in the timerwindow in the extension. the parameters must match exactly for it to unregister properly.
Parameters:
fn - the function previously registered.
delay - the delay value previously registered.
TimerManager.outputTime(nTime) - Output the current timer value in HRS:MIN:SEC to the chat.
Parameters: nTime - the integer value of the time to display in seconds.
UUID 53d84db6-e29a-11ec-8c52-0050562be458