Animated timers using Geyser

Share your scripts and packages with other Mudlet users.
User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Animated timers using Geyser

Post by demonnic »

You should look at http://github.com/demonnic/animatedtimers for up to date information. The constructor below will only work up to 2.2, the readme at the repo has the new constructor for 3.0+ Everything below here is out of date


So I was working on a project and had a need for a basic cooldown timer. After a bit of browsing/searching around I didn't find anything that did everything I needed, but I did find the following POST. So I spent a bit of time rewriting it to use Geyser. If you reuse a name, it will reuse the gauge associated with it, giving it the new constructor information, adding it to the proper container (or removing it from all containers, if no container is passed), time, etc. This means if you recall the same timer with the same arguments, it will essentially reset even if it's not finished running from the first time. It also means if you give it different arguments (such as a new position or size) then it will use these when it resets.

Big thanks to Lin of Aetolia, most of the core logic to the algorithm really didn't get changed. I just gussied it up a bit.

EDIT: There is now a video demo at http://www.youtube.com/watch?v=NlL0H_SjnPs
Usage:
demonnic.anitimer:new(name, constructor, time, container, showTime, timerCaption, css, cssback)

name: any name you wish to give the timer in string format

constructor: The same constructor you would pass to Geyser.Gauge:new(). This is where you specify your coordinates, height, width, etc.

time: How long in seconds you want the cooldown to run. Accepts decimal values

container: Optional argument. Give the timer a Geyser container to bind to. If you don't wish to bind to a container, but do wish to set up a stylesheet or turn off the display of the timeleft, then pass the empty string for this argument.

showTime: Optional argument, except if you want to pass further arguments. I may try to restructure this soon. This determines whether or not the time remaining is shown on the timer. Defaults to true if you leave it empty

timerCaption: Optional argument, except if you want to pass further arguments. This provides a way to give a caption to the timer, so that you can label it with something other than the time

css: Optional argument. The stylesheet to apply to the front portion of the gauge.

cssback: Optional argument. The stylesheet to apply to the back portion of the gauge.
Usage
demonnic.anitimer:stop(name)

name: the name of the timer you want to remove/stop
Here are the contents of a sort of example alias to show some different timers, with and without css and container binding. For my own testing I just put it in an alias with pattern ^animateme$ . The gauges themselves aren't fancy, but that's because I slapped thew alias together in a few seconds. Using CSS you could do some pretty wicked things with these.
Code: [show] | [select all] lua
demonnic.newContainer = demonnic.newContainer or Geyser.Container:new({x=0, y=0, height=400, width = 200})
myCss1 = [[
border-width: 4px;
border-radius: 7;
border-color: red;
background-color: green;
]]
myCss2 = [[
border-width: 4px;
border-radius: 7;
border-color: green;
background-color: red;
]]
demonnic.anitimer:new("Test1", {x=200, y=100, height = 30, width = 300, color="red"}, 5)
demonnic.anitimer:new("Test2", {x = 0, y="50%", height = 20, width = "100%"}, 10, demonnic.newContainer, true, myCss1, myCss2)
demonnic.anitimer:new("Test3", {x = 500, y = 300, height = 40, width = 100}, 8, "", myCss2, myCss1)
demonnic.anitimer:new("Test4", {x=-20, y=0, height = 20, width = "100%"}, 18, demonnic.newContainer, false)
CHANGELOG
2.0 - added :stop(name) function. Also, when a timer expires or is stopped it will stop the stop watch. Added argument for whether to display the time on the timer or not.
2.1 - Added option to provide a caption for the timer, such that the text appears after the time (if showTime is true) or just as the text on the gauge (if showTime is false)
Attachments
animated-timers2.1.zip
(1.93 KiB) Downloaded 717 times

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Post by Vadi »

Is it possible not to have the text be shown on the gauge?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Post by Vadi »

How can I cancel a timer early as well?

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Post by demonnic »

Both good questions. Download animatedtimers-2.0, coming soon!

In all seriousness, forgot to put that in. Fixing it up now and will post soon

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Post by demonnic »

Check original post, I've added demonnic.anitimer:stop(name) as well as a new argument to the :new() function, for whether you wish to show the time remaining on the timer or not.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Post by Vadi »

demonnic.anitimer:stop() errors if you use it on something that doesn't exist, but since the API doesn't return you an object, you can't really check for it... I think it shouldn't error ala Mudlets API.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Post by demonnic »

Video demo up at: http://www.youtube.com/watch?v=NlL0H_SjnPs

It uses the alias which I included code for in the original post.

New version coming soon with some new support (pause, listing of timers, stopping/pausing all timers)

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Animated timers using Geyser

Post by Silvine »

Hi,
Is there an option to add some text to the timer?

Thanks

Silv

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Post by demonnic »

I haven't put anything in for that as yet, but I'm certain I could add it. I will add it before dropping the next version

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Animated timers using Geyser

Post by Silvine »

That would be great, thanks!
Going chat/timer crazy over here, love your work.

Post Reply