Animated timers using Geyser

Share your scripts and packages with other Mudlet users.

Animated timers using Geyser

Postby demonnic » Wed Jan 30, 2013 9:53 am

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, 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

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.

Syntax: [ Download ] [ Hide ]
Using lua Syntax Highlighting
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.
Attachments
animated-timers2.0.zip
(1.4 KiB) Downloaded 149 times
User avatar
demonnic
 
Posts: 402
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Postby Vadi » Sat Feb 02, 2013 9:43 am

Is it possible not to have the text be shown on the gauge?
User avatar
Vadi
 
Posts: 3641
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Postby Vadi » Sat Feb 02, 2013 10:09 am

How can I cancel a timer early as well?
User avatar
Vadi
 
Posts: 3641
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Postby demonnic » Sat Feb 02, 2013 2:15 pm

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: 402
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Postby demonnic » Sat Feb 02, 2013 3:03 pm

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
demonnic
 
Posts: 402
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Postby Vadi » Mon Feb 04, 2013 12:01 am

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
Vadi
 
Posts: 3641
Joined: Sat Mar 14, 2009 3:13 pm

Re: Animated timers using Geyser

Postby demonnic » Thu Feb 07, 2013 4:12 pm

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)
User avatar
demonnic
 
Posts: 402
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Postby Silvine » Sun Mar 03, 2013 11:14 am

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

Thanks

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

Re: Animated timers using Geyser

Postby demonnic » Mon Mar 04, 2013 5:18 pm

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
User avatar
demonnic
 
Posts: 402
Joined: Sat Dec 05, 2009 3:19 pm

Re: Animated timers using Geyser

Postby Silvine » Mon Mar 04, 2013 10:00 pm

That would be great, thanks!
Going chat/timer crazy over here, love your work.
Silvine
 
Posts: 119
Joined: Sat Oct 23, 2010 2:36 pm

Next

Return to Scripts & Packages

Who is online

Users browsing this forum: No registered users and 2 guests