import type { Game } from './game.js'; import { Signal } from './signal.js'; import { TimerEvent } from './timer_event.js'; import type { Callback } from './callback.js'; export declare class Timer { game: Game; running: boolean; autoDestroy: boolean; expired: boolean; elapsed: number; events: TimerEvent[]; onComplete: Signal; nextTick: number; timeCap: number; paused: boolean; _codePaused: boolean; _started: number; _pauseStarted: number; _pauseTotal: number; _now: number; _len: number; _marked: number; _i: number; _diff: number; _newTick: number; /** * Creates a new Timer instance. * @param {Game} game - The game instance. * @param {boolean} autoDestroy - Whether to automatically destroy the timer when it completes. */ constructor(game: Game, autoDestroy?: boolean); /** * Creates a new TimerEvent. * @param {number} delay - The delay in milliseconds before the event fires. * @param {boolean} loop - Whether the event should loop indefinitely. * @param {number} repeatCount - The number of times to repeat the event (0 = infinite). * @param {Function} callback - The function to call when the event fires. * @param {object} callbackContext - The context in which to call the callback. * @param {...any} args - Arguments to pass to the callback function. * @returns {TimerEvent} The created TimerEvent. */ create(delay: number, loop: boolean, repeatCount: number, callback: Callback, callbackContext?: unknown, args?: unknown[]): TimerEvent; /** * Creates a new TimerEvent that runs once. * @param {number} delay - The delay in milliseconds before the event fires. * @param {Function} callback - The function to call when the event fires. * @param {object} callbackContext - The context in which to call the callback. * @param {...any} args - Arguments to pass to the callback function. * @returns {TimerEvent} The created TimerEvent. */ add(delay: number, callback: Callback, callbackContext?: unknown, ...args: unknown[]): TimerEvent; /** * Creates a new async TimerEvent that runs once. * @template T * @param {number} delay - The delay in milliseconds before the promise resolves. * @param {...T} args - Arguments to pass to the resolve function. * @returns {Promise} The created Promise. */ wait(delay: number, ...args: unknown[]): Promise; /** * Creates a new TimerEvent that repeats a specified number of times. * @param {number} delay - The delay in milliseconds before the event fires. * @param {number} repeatCount - The number of times to repeat the event (0 = infinite). * @param {Function} callback - The function to call when the event fires. * @param {object} callbackContext - The context in which to call the callback. * @param {...any} args - Arguments to pass to the callback function. * @returns {TimerEvent} The created TimerEvent. */ repeat(delay: number, repeatCount: number, callback: Callback, callbackContext?: unknown, ...args: unknown[]): TimerEvent; /** * Creates a new TimerEvent that loops indefinitely. * @param {number} delay - The delay in milliseconds before the event fires. * @param {Function} callback - The function to call when the event fires. * @param {object} callbackContext - The context in which to call the callback. * @param {...any} args - Arguments to pass to the callback function. * @returns {TimerEvent} The created TimerEvent. */ loop(delay: number, callback: Callback, callbackContext?: unknown, ...args: unknown[]): TimerEvent; /** * Starts the timer. * @param {number} delay - The delay in milliseconds before starting (optional). */ start(delay?: number): void; /** * Stops the timer. * @param {boolean} clearEvents - Whether to clear all events (default: true). */ stop(clearEvents?: boolean): void; /** * Removes a TimerEvent from the timer. * @param {TimerEvent | null | undefined} event - The TimerEvent to remove. * @returns {boolean} True if the event was removed, false otherwise. */ remove(event: TimerEvent | null | undefined): boolean; /** * Orders the timer events by their next tick time. */ order(): void; /** * Sorts TimerEvents by their tick time. * @param {TimerEvent} a - First TimerEvent to compare. * @param {TimerEvent} b - Second TimerEvent to compare. * @returns {number} Comparison result (-1, 0, or 1). */ sortHandler(a: TimerEvent, b: TimerEvent): 1 | -1 | 0; /** * Clears pending events from the timer. */ clearPendingEvents(): void; /** * Updates the timer state at a given time. * @param {number} time - The current time in milliseconds. * @returns {boolean} True if the timer should continue running, false if it should be destroyed. */ update(time: number): boolean; /** * Pauses the timer. */ pause(): void; /** * Internal pause method for the timer. */ _pause(): void; /** * Adjusts timer events when time has jumped (e.g., when tab is switched). * @param {number} baseTime - The time to adjust from. */ adjustEvents(baseTime: number): void; /** * Resumes the timer. */ resume(): void; /** * Internal resume method for the timer. */ _resume(): void; /** * Removes all events from the timer. */ removeAll(): void; /** * Destroys the timer and cleans up resources. */ destroy(): void; /** * Gets the next tick time for the timer. * @returns {number} The next tick time in milliseconds. */ get next(): number; /** * Gets the duration until the next event. * @returns {number} The duration in milliseconds. */ get duration(): number; /** * Gets the number of active events in the timer. * @returns {number} The number of events. */ get length(): number; /** * Gets the elapsed time since the timer started. * @returns {number} The elapsed time in milliseconds. */ get ms(): number; /** * Gets the elapsed time in seconds since the timer started. * @returns {number} The elapsed time in seconds. */ get seconds(): number; } //# sourceMappingURL=timer.d.ts.map