TimerPlugin
Defined in: plugins/TimerPlugin.ts:641
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”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TimerPlugin():
TimerPlugin
Defined in: plugins/TimerPlugin.ts:658
Returns
Section titled “Returns”TimerPlugin
Overrides
Section titled “Overrides”Properties
Section titled “Properties”__dill_pixel_method_binding_root
Section titled “__dill_pixel_method_binding_root”__dill_pixel_method_binding_root:
boolean
Defined in: plugins/Plugin.ts:39
Inherited from
Section titled “Inherited from”Plugin
.__dill_pixel_method_binding_root
id:
string
='Plugin'
Defined in: plugins/Plugin.ts:48
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”onAllTimersPaused
Section titled “onAllTimersPaused”
readonly
onAllTimersPaused:Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:655
Signal emitted when all timers are paused.
Example
Section titled “Example”this.app.timers.onAllTimersPaused.connect(() => { console.log('All timers paused');});
Implementation of
Section titled “Implementation of”ITimerPlugin
.onAllTimersPaused
onAllTimersResumed
Section titled “onAllTimersResumed”
readonly
onAllTimersResumed:Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:656
Signal emitted when all timers are resumed.
Example
Section titled “Example”this.app.timers.onAllTimersResumed.connect(() => { console.log('All timers resumed');});
Implementation of
Section titled “Implementation of”ITimerPlugin
.onAllTimersResumed
onTimerCreated
Section titled “onTimerCreated”
readonly
onTimerCreated:Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:653
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()}`);});
Implementation of
Section titled “Implementation of”onTimerDestroyed
Section titled “onTimerDestroyed”
readonly
onTimerDestroyed:Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:654
Signal emitted when a timer is destroyed.
Example
Section titled “Example”this.app.timers.onTimerDestroyed.connect((timer) => { console.log(`Timer destroyed: ${timer.getId()}`);});
Implementation of
Section titled “Implementation of”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get app():
A
Defined in: plugins/Plugin.ts:53
Returns
Section titled “Returns”A
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”hasWorkerSupport
Section titled “hasWorkerSupport”Get Signature
Section titled “Get Signature”get hasWorkerSupport():
boolean
Defined in: plugins/TimerPlugin.ts:649
Returns
Section titled “Returns”boolean
options
Section titled “options”Get Signature
Section titled “Get Signature”get options():
O
Defined in: plugins/Plugin.ts:44
Returns
Section titled “Returns”O
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”addSignalConnection()
Section titled “addSignalConnection()”addSignalConnection(…
args
):void
Defined in: plugins/Plugin.ts:79
Add signal connections to the container.
Parameters
Section titled “Parameters”…SignalConnection
[]
The signal connections to add.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ITimerPlugin
.addSignalConnection
Inherited from
Section titled “Inherited from”adjustWorkerTimer()
Section titled “adjustWorkerTimer()”adjustWorkerTimer(
timerId
,timeAdjustment
):void
Defined in: plugins/TimerPlugin.ts:832
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
Implementation of
Section titled “Implementation of”ITimerPlugin
.adjustWorkerTimer
clearSignalConnections()
Section titled “clearSignalConnections()”clearSignalConnections():
void
Defined in: plugins/Plugin.ts:85
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ITimerPlugin
.clearSignalConnections
Inherited from
Section titled “Inherited from”createTimer()
Section titled “createTimer()”createTimer(
options?
):Timer
Defined in: plugins/TimerPlugin.ts:782
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`); }});
Implementation of
Section titled “Implementation of”destroy()
Section titled “destroy()”destroy():
void
Defined in: plugins/TimerPlugin.ts:765
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”destroyAllTimers()
Section titled “destroyAllTimers()”destroyAllTimers():
void
Defined in: plugins/TimerPlugin.ts:826
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();
Implementation of
Section titled “Implementation of”destroyTimer()
Section titled “destroyTimer()”destroyTimer(
timer
):void
Defined in: plugins/TimerPlugin.ts:796
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);
Implementation of
Section titled “Implementation of”initialize()
Section titled “initialize()”initialize(
options?
,_app?
):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:61
Parameters
Section titled “Parameters”options?
Section titled “options?”Partial
<any
>
IApplication
<DataSchema
, ActionContext
, Action
>
Returns
Section titled “Returns”void
| Promise
<void
>
Implementation of
Section titled “Implementation of”Inherited from
Section titled “Inherited from”pauseAllTimers()
Section titled “pauseAllTimers()”pauseAllTimers():
void
Defined in: plugins/TimerPlugin.ts:810
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();};
Implementation of
Section titled “Implementation of”postInitialize()
Section titled “postInitialize()”postInitialize():
void
Defined in: plugins/TimerPlugin.ts:677
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Overrides
Section titled “Overrides”resetWorkerTimer()
Section titled “resetWorkerTimer()”resetWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:756
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());
Implementation of
Section titled “Implementation of”resumeAllTimers()
Section titled “resumeAllTimers()”resumeAllTimers():
void
Defined in: plugins/TimerPlugin.ts:818
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();};
Implementation of
Section titled “Implementation of”startWorkerTimer()
Section titled “startWorkerTimer()”startWorkerTimer(
timerId
,options
):void
Defined in: plugins/TimerPlugin.ts:731
Parameters
Section titled “Parameters”timerId
Section titled “timerId”string
options
Section titled “options”Returns
Section titled “Returns”void
stopWorkerTimer()
Section titled “stopWorkerTimer()”stopWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:746
Parameters
Section titled “Parameters”timerId
Section titled “timerId”string
Returns
Section titled “Returns”void