general purpose timer
A while ago, I noticed that the memory game uses a timer that is tied to the library closely. It cannot be used for anything else. I decided to create something like a general purpose timer for H5P. And here it is: https://github.com/otacke/h5p-timer. You will also find it attached to this post as an h5p file. It is not a content type, so don't expect it to do anything on its own ;-)
The timer is not intended for time critical applications, but it can easily be used to keep track of time in games, to set a time limit for tasks, or to create other innovative content libraries that need triggers based on time. What about a mod-player that can handle ProTracker files for example? ;-) Also, it might reduce some redundancies across different h5p libraries under the hood.
- can count up and down
- can use milliseconds internally but only "displays" tenths of seconds and above
- can be paused
- keeps track of three different types of counters: clock time (can be modified even if running, e.g to give a time bonus), playing time (the amount of time that the clock has been ticking), and running time (the total running time ignoring pauses)
- offers three types of notifications using callback functions for each type of counter: notification at a particular point in time, notification after a certain time period has passed, and recurring notifications in fixed intervals
- offers some static utility functions: check if something is a timecode, convert timecodes to milliseconds and vice versa, extract single time elements like days or seconds from timecode or milliseconds
It may still contain bugs, but I think that someone else should have a closer look at it. I hope that my comments are good enough to help you. Your feedback is highly appreciated!