ITimerPlugin
Defined in: plugins/TimerPlugin.ts:492
Interface for the Timer Plugin which manages both main-thread and web worker timers.
The Timer Plugin provides functionality for:
- Creating and managing countdown and count-up timers
- Running timers in a web worker for better performance
- Pausing and resuming all timers
- Handling timer lifecycle events
Example
Section titled “Example”// Create a 5-second countdown timerconst countdown = this.app.timers.createTimer({ duration: 5000, autoStart: true, onTick: (remaining) => { console.log(`Time remaining: ${formatTime(remaining, 'mm:ss')}`); }, onComplete: () => { console.log('Timer completed!'); }});
// Create a count-up timer in a web workerconst stopwatch = this.app.timers.createTimer({ useWorker: true, workerInterval: 100, // Update every 100ms onTick: (elapsed) => { console.log(`Time elapsed: ${formatTime(elapsed, 'mm:ss')}`); }});
// Pause all timersthis.app.timers.pauseAllTimers();
// Resume all timersthis.app.timers.resumeAllTimers();
Extends
Section titled “Extends”Properties
Section titled “Properties”app:
IApplication
Defined in: plugins/Plugin.ts:10
Inherited from
Section titled “Inherited from”id:
string
Defined in: plugins/Plugin.ts:8
Inherited from
Section titled “Inherited from”onAllTimersPaused
Section titled “onAllTimersPaused”onAllTimersPaused:
Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:524
Signal emitted when all timers are paused.
Example
Section titled “Example”this.app.timers.onAllTimersPaused.connect(() => { console.log('All timers paused');});
onAllTimersResumed
Section titled “onAllTimersResumed”onAllTimersResumed:
Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:535
Signal emitted when all timers are resumed.
Example
Section titled “Example”this.app.timers.onAllTimersResumed.connect(() => { console.log('All timers resumed');});
onTimerCreated
Section titled “onTimerCreated”onTimerCreated:
Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:502
Signal emitted when a new timer is created.
Example
Section titled “Example”this.app.timers.onTimerCreated.connect((timer) => { console.log(`New timer created with ID: ${timer.getId()}`);});
onTimerDestroyed
Section titled “onTimerDestroyed”onTimerDestroyed:
Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:513
Signal emitted when a timer is destroyed.
Example
Section titled “Example”this.app.timers.onTimerDestroyed.connect((timer) => { console.log(`Timer destroyed: ${timer.getId()}`);});
options
Section titled “options”
readonly
options:Partial
<O
>
Defined in: plugins/Plugin.ts:12
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”addSignalConnection()
Section titled “addSignalConnection()”addSignalConnection(…
args
):void
Defined in: plugins/Plugin.ts:20
Parameters
Section titled “Parameters”…SignalConnection
[]
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”adjustWorkerTimer()
Section titled “adjustWorkerTimer()”adjustWorkerTimer(
timerId
,timeAdjustment
):void
Defined in: plugins/TimerPlugin.ts:638
Adjusts the time of a worker timer. This is primarily used internally by the Timer class.
Parameters
Section titled “Parameters”timerId
Section titled “timerId”string
The ID of the worker timer to adjust
timeAdjustment
Section titled “timeAdjustment”number
The amount of time to add (positive) or remove (negative) in milliseconds
Returns
Section titled “Returns”void
Example
Section titled “Example”// This is typically called internally by the Timer classthis.app.timers.adjustWorkerTimer(timer.getId(), 5000); // Add 5 seconds
clearSignalConnections()
Section titled “clearSignalConnections()”clearSignalConnections():
void
Defined in: plugins/Plugin.ts:22
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”IPlugin
.clearSignalConnections
createTimer()
Section titled “createTimer()”createTimer(
options?
):Timer
Defined in: plugins/TimerPlugin.ts:556
Creates a new timer with the specified options.
Parameters
Section titled “Parameters”options?
Section titled “options?”Configuration options for the timer
Returns
Section titled “Returns”A new Timer instance
Example
Section titled “Example”// Create a looping timer that runs in a web workerconst timer = this.app.timers.createTimer({ duration: 1000, loop: true, useWorker: true, onTick: (remaining) => { console.log(`${remaining}ms remaining`); }});
destroy()
Section titled “destroy()”destroy():
void
Defined in: plugins/Plugin.ts:18
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”destroyAllTimers()
Section titled “destroyAllTimers()”destroyAllTimers():
void
Defined in: plugins/TimerPlugin.ts:609
Destroys all active timers, both main thread and worker timers . This will remove all timers from the plugin and stop them.
Returns
Section titled “Returns”void
Example
Section titled “Example”this.app.timers.destroyAllTimers();
destroyTimer()
Section titled “destroyTimer()”destroyTimer(
timer
):void
Defined in: plugins/TimerPlugin.ts:570
Destroys a timer, cleaning up all resources and removing it from the plugin.
Parameters
Section titled “Parameters”The timer instance to destroy
Returns
Section titled “Returns”void
Example
Section titled “Example”const timer = this.app.timers.createTimer({ duration: 5000 });// ... later ...this.app.timers.destroyTimer(timer);
initialize()
Section titled “initialize()”initialize(
options
,app
):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:14
Parameters
Section titled “Parameters”options
Section titled “options”Partial
<O
>
Returns
Section titled “Returns”void
| Promise
<void
>
Inherited from
Section titled “Inherited from”pauseAllTimers()
Section titled “pauseAllTimers()”pauseAllTimers():
void
Defined in: plugins/TimerPlugin.ts:584
Pauses all active timers, both main thread and worker timers. Timers will maintain their current state and can be resumed later.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Pause all timers when the game loses focuswindow.onblur = () => { this.app.timers.pauseAllTimers();};
postInitialize()
Section titled “postInitialize()”postInitialize(
_app
):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:16
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
| Promise
<void
>
Inherited from
Section titled “Inherited from”registerCoreFunctions()
Section titled “registerCoreFunctions()”registerCoreFunctions():
void
Defined in: plugins/Plugin.ts:24
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”registerCoreSignals()
Section titled “registerCoreSignals()”registerCoreSignals():
void
Defined in: plugins/Plugin.ts:26
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”resetWorkerTimer()
Section titled “resetWorkerTimer()”resetWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:623
Resets a worker timer to its initial state. This is primarily used internally by the Timer class.
Parameters
Section titled “Parameters”timerId
Section titled “timerId”string
The ID of the worker timer to reset
Returns
Section titled “Returns”void
Example
Section titled “Example”// This is typically called internally by the Timer classthis.app.timers.resetWorkerTimer(timer.getId());
resumeAllTimers()
Section titled “resumeAllTimers()”resumeAllTimers():
void
Defined in: plugins/TimerPlugin.ts:598
Resumes all paused timers, both main thread and worker timers. Timers will continue from their paused state.
Returns
Section titled “Returns”void
Example
Section titled “Example”// Resume all timers when the game regains focuswindow.onfocus = () => { this.app.timers.resumeAllTimers();};