[][src]Struct livesplit_core::Timer

pub struct Timer { /* fields omitted */ }

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

Examples

use livesplit_core::{Run, Segment, Timer, TimerPhase};

// Create a run object that we can use with at least one segment.
let mut run = Run::new();
run.set_game_name("Super Mario Odyssey");
run.set_category_name("Any%");
run.push_segment(Segment::new("Cap Kingdom"));

// Create the timer from the run.
let mut timer = Timer::new(run).expect("Run with at least one segment provided");

// Start a new attempt.
timer.start();
assert_eq!(timer.current_phase(), TimerPhase::Running);

// Create a split.
timer.split();

// The run should be finished now.
assert_eq!(timer.current_phase(), TimerPhase::Ended);

// Reset the attempt and confirm that we want to store the attempt.
timer.reset(true);

// The attempt is now over.
assert_eq!(timer.current_phase(), TimerPhase::NotRunning);

Methods

impl Timer[src]

pub fn new(run: Run) -> Result<Self, CreationError>[src]

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.

pub fn into_shared(self) -> SharedTimer[src]

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

pub fn into_run(self, update_splits: bool) -> Run[src]

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.

pub fn replace_run(&mut self, run: Run, update_splits: bool) -> Result<Run, Run>[src]

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 returned as the Err case of the Result. Otherwise the Run that was in use by the Timer is being returned. Before the Run is returned, the current attempt is reset and the splits are being updated depending on the update_splits parameter.

pub fn set_run(&mut self, run: Run) -> Result<(), Run>[src]

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 is returned as the Err case of the Result. The Run object in use by the Timer is dropped by this method.

pub fn run(&self) -> &Run[src]

Accesses the Run in use by the Timer.

pub fn mark_as_unmodified(&mut self)[src]

Marks the Run as unmodified, so that it is known that all the changes have been saved.

pub fn current_phase(&self) -> TimerPhase[src]

Returns the current Timer Phase.

pub fn current_time(&self) -> Time[src]

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

pub fn current_timing_method(&self) -> TimingMethod[src]

Returns the currently selected Timing Method.

pub fn set_current_timing_method(&mut self, method: TimingMethod)[src]

Sets the current Timing Method to the Timing Method provided.

pub fn toggle_timing_method(&mut self)[src]

Toggles between the Real Time and Game Time timing methods.

pub fn current_comparison(&self) -> &str[src]

Returns the current comparison that is being compared against. This may be a custom comparison or one of the Comparison Generators.

pub fn set_current_comparison<S: AsRef<str>>(
    &mut self,
    comparison: S
) -> Result<(), ()>
[src]

Tries to set the current comparison to the comparison specified. If the comparison doesn't exist Err is returned.

pub fn current_split(&self) -> Option<&Segment>[src]

Accesses the split the attempt is currently on. If there's no attempt in progress or the run finished, None is returned instead.

pub fn current_split_index(&self) -> Option<usize>[src]

Accesses the index of the split the attempt is currently on. If there's no attempt in progress, None is returned instead.

pub fn start(&mut self)[src]

Starts the Timer if there is no attempt in progress. If that's not the case, nothing happens.

pub fn split(&mut self)[src]

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.

pub fn split_or_start(&mut self)[src]

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.

pub fn skip_split(&mut self)[src]

Skips the current split if an attempt is in progress and the current split is not the last split.

pub fn undo_split(&mut self)[src]

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.

pub fn reset(&mut self, update_splits: bool)[src]

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.

pub fn reset_and_set_attempt_as_pb(&mut self)[src]

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.

pub fn pause(&mut self)[src]

Pauses an active attempt that is not paused.

pub fn resume(&mut self)[src]

Resumes an attempt that is paused.

pub fn toggle_pause(&mut self)[src]

Toggles an active attempt between Paused and Running.

pub fn toggle_pause_or_start(&mut self)[src]

Toggles an active attempt between Paused and Running or starts an attempt if there's none in progress.

pub fn undo_all_pauses(&mut self)[src]

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.

pub fn switch_to_next_comparison(&mut self)[src]

Switches the current comparison to the next comparison in the list.

pub fn switch_to_previous_comparison(&mut self)[src]

Switches the current comparison to the previous comparison in the list.

pub fn current_attempt_duration(&self) -> TimeSpan[src]

Returns the total duration of the current attempt. This is not affected by the start offset of the run. So if the start offset is -10s and the start() method was called 2s ago, the current time is -8s but the current attempt duration is 2s. If the timer is then however paused for 5s, the current attempt duration is still 2s. So the current attempt duration only counts the time the Timer Phase has actually been Running.

pub fn get_pause_time(&self) -> Option<TimeSpan>[src]

Returns the total amount of time the current attempt has been paused for. None is returned if there have not been any pauses.

pub fn is_game_time_initialized(&self) -> bool[src]

Returns whether Game Time is currently initialized. Game Time automatically gets uninitialized for each new attempt.

pub fn initialize_game_time(&mut self)[src]

Initializes Game Time for the current attempt. Game Time automatically gets uninitialized for each new attempt.

pub fn deinitialize_game_time(&mut self)[src]

Deinitializes Game Time for the current attempt.

pub fn is_game_time_paused(&self) -> bool[src]

Returns whether the Game Timer is currently paused. If the Game Timer is not paused, it automatically increments similar to Real Time.

pub fn pause_game_time(&mut self)[src]

Pauses the Game Timer such that it doesn't automatically increment similar to Real Time.

pub fn resume_game_time(&mut self)[src]

Resumes the Game Timer such that it automatically increments similar to Real Time, starting from the Game Time it was paused at.

pub fn set_game_time(&mut self, game_time: TimeSpan)[src]

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.

pub fn loading_times(&self) -> TimeSpan[src]

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

pub fn set_loading_times(&mut self, time: TimeSpan)[src]

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.

Trait Implementations

impl TotalPlaytime for Timer[src]

impl Clone for Timer[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Timer[src]

Auto Trait Implementations

impl Send for Timer

impl Sync for Timer

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

fn adapt_into(self) -> D[src]

Convert the source color to the destination color using the bradford method by default Read more

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.