Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Timer

A Timer provides all the capabilities necessary for doing speedrun attempts.

Hierarchy

Index

Constructors

constructor

  • new Timer(ptr: number): Timer
  • This constructor is an implementation detail. Do not use this.

    Parameters

    • ptr: number

    Returns Timer

Properties

ptr

ptr: number

Methods

currentComparison

  • currentComparison(): string
  • Returns the current comparison that is being compared against. This may be a custom comparison or one of the Comparison Generators.

    Returns string

currentPhase

  • currentPhase(): number
  • Returns the current Timer Phase.

    Returns number

currentSplitIndex

  • currentSplitIndex(): number
  • Accesses the index of the split the attempt is currently on. If there's no attempt in progress, -1 is returned instead. This returns an index that is equal to the amount of segments when the attempt is finished, but has not been reset. So you need to be careful when using this value for indexing.

    Returns number

currentTime

  • Returns the current time of the Timer. The Game Time is null if the Game Time has not been initialized.

    Returns TimeRef

currentTimingMethod

  • currentTimingMethod(): number

deinitializeGameTime

  • deinitializeGameTime(): void

dispose

  • dispose(): void
  • Disposes the object, allowing it to clean up all of its memory. You need to call this for every object that you don't use anymore and hasn't already been disposed.

    Returns void

getRun

  • Accesses the Run in use by the Timer.

    Returns RunRef

initializeGameTime

  • initializeGameTime(): void
  • Initializes Game Time for the current attempt. Game Time automatically gets uninitialized for each new attempt.

    Returns void

intoRun

  • intoRun(updateSplits: boolean): Run
  • Takes out the Run from the Timer and resets the current attempt if there is one in progress. If the splits are to be updated, all the information of the current attempt is stored in the Run's history. Otherwise the current attempt's information is discarded.

    Parameters

    • updateSplits: boolean

    Returns Run

intoShared

  • Consumes the Timer and creates a Shared Timer that can be shared across multiple threads with multiple owners.

    Returns SharedTimer

isGameTimeInitialized

  • isGameTimeInitialized(): boolean
  • Returns whether Game Time is currently initialized. Game Time automatically gets uninitialized for each new attempt.

    Returns boolean

isGameTimePaused

  • isGameTimePaused(): boolean
  • Returns whether the Game Timer is currently paused. If the Game Timer is not paused, it automatically increments similar to Real Time.

    Returns boolean

loadingTimes

  • Accesses the loading times. Loading times are defined as Game Time - Real Time.

    Returns TimeSpanRef

markAsUnmodified

  • markAsUnmodified(): void
  • Marks the Run as unmodified, so that it is known that all the changes have been saved.

    Returns void

pause

  • pause(): void
  • Pauses an active attempt that is not paused.

    Returns void

pauseGameTime

  • pauseGameTime(): void
  • Pauses the Game Timer such that it doesn't automatically increment similar to Real Time.

    Returns void

printDebug

  • printDebug(): void
  • Prints out debug information representing the whole state of the Timer. This is being written to stdout.

    Returns void

replaceRun

  • replaceRun(run: RunRefMut, updateSplits: boolean): boolean
  • Replaces the Run object used by the Timer with the Run object provided. If the Run provided contains no segments, it can't be used for timing and is not being modified. Otherwise the Run that was in use by the Timer gets stored in the Run object provided. Before the Run is returned, the current attempt is reset and the splits are being updated depending on the update_splits parameter. The return value indicates whether the Run got replaced successfully.

    Parameters

    Returns boolean

reset

  • reset(updateSplits: boolean): void
  • Resets the current attempt if there is one in progress. If the splits are to be updated, all the information of the current attempt is stored in the Run's history. Otherwise the current attempt's information is discarded.

    Parameters

    • updateSplits: boolean

    Returns void

resetAndSetAttemptAsPb

  • resetAndSetAttemptAsPb(): void
  • Resets the current attempt if there is one in progress. The splits are updated such that the current attempt's split times are being stored as the new Personal Best.

    Returns void

resume

  • resume(): void
  • Resumes an attempt that is paused.

    Returns void

resumeGameTime

  • resumeGameTime(): void
  • Resumes the Game Timer such that it automatically increments similar to Real Time, starting from the Game Time it was paused at.

    Returns void

saveAsLss

  • saveAsLss(): string
  • Saves the Run in use by the Timer as a LiveSplit splits file (*.lss).

    Returns string

setCurrentTimingMethod

  • setCurrentTimingMethod(method: number): void
  • Sets the current Timing Method to the Timing Method provided.

    Parameters

    • method: number

    Returns void

setGameTime

  • Sets the Game Time to the time specified. This also works if the Game Time is paused, which can be used as a way of updating the Game Timer periodically without it automatically moving forward. This ensures that the Game Timer never shows any time that is not coming from the game.

    Parameters

    Returns void

setLoadingTimes

  • Instead of setting the Game Time directly, this method can be used to just specify the amount of time the game has been loading. The Game Time is then automatically determined by Real Time - Loading Times.

    Parameters

    Returns void

setRun

  • Sets the Run object used by the Timer with the Run object provided. If the Run provided contains no segments, it can't be used for timing and gets returned again. If the Run object can be set, the original Run object in use by the Timer is disposed by this method and null is returned.

    Parameters

    Returns Run

skipSplit

  • skipSplit(): void
  • Skips the current split if an attempt is in progress and the current split is not the last split.

    Returns void

split

  • split(): void
  • If an attempt is in progress, stores the current time as the time of the current split. The attempt ends if the last split time is stored.

    Returns void

splitOrStart

  • splitOrStart(): void
  • Starts a new attempt or stores the current time as the time of the current split. The attempt ends if the last split time is stored.

    Returns void

start

  • start(): void
  • Starts the Timer if there is no attempt in progress. If that's not the case, nothing happens.

    Returns void

switchToNextComparison

  • switchToNextComparison(): void

switchToPreviousComparison

  • switchToPreviousComparison(): void

togglePause

  • togglePause(): void
  • Toggles an active attempt between Paused and Running.

    Returns void

togglePauseOrStart

  • togglePauseOrStart(): void
  • Toggles an active attempt between Paused and Running or starts an attempt if there's none in progress.

    Returns void

undoAllPauses

  • undoAllPauses(): void
  • Removes all the pause times from the current time. If the current attempt is paused, it also resumes that attempt. Additionally, if the attempt is finished, the final split time is adjusted to not include the pause times as well.

    Warning

    This behavior is not entirely optimal, as generally only the final split time is modified, while all other split times are left unmodified, which may not be what actually happened during the run.

    Returns void

undoSplit

  • undoSplit(): void
  • Removes the split time from the last split if an attempt is in progress and there is a previous split. The Timer Phase also switches to Running if it previously was Ended.

    Returns void

with

  • with<T>(closure: (obj: Timer) => T): T
  • Allows for scoped usage of the object. The object is guaranteed to get disposed once this function returns. You are free to dispose the object early yourself anywhere within the scope. The scope's return value gets carried to the outside of this function.

    Type parameters

    • T

    Parameters

    Returns T

Static new

  • Creates a new Timer based on a Run object storing all the information about the splits. The Run object needs to have at least one segment, so that the Timer can store the final time. If a Run object with no segments is provided, the Timer creation fails and null is returned.

    Parameters

    Returns Timer

Generated using TypeDoc