Crate livesplit_core

source ·
Expand description

livesplit-core is a library that provides a lot of functionality for creating a speedrun timer.

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);

Re-exports

pub use crate::layout::Editor as LayoutEditor;
pub use crate::layout::Layout;
pub use crate::run::Editor as RunEditor;
pub use crate::run::Run;
pub use livesplit_hotkey as hotkey;

Modules

The analysis module provides a variety of functions for calculating information about a Run.
The auto splitting module provides a runtime for running auto splitters that can control the Timer. These auto splitters are provided as WebAssembly modules.
The comparison module provides all the different automatically generated comparisons, like BestSegments and AverageSegments. Additionally, functions for dealing with comparisons, like shortening a comparison, are provided.
The component module provides all available components. A Component allows querying different kinds of information from a Timer. This information is provided as state objects in a way that can easily be visualized by any kind of User Interface.
The layout module provides everything necessary for working with a Layout. A Layout allows you to combine multiple components together to visualize a variety of information the runner is interested in.
The networking module provides functionality to communicate with various speedrunning related websites, such as Splits.io to upload and download runs and Speedrun.com to query and submit to the leaderboards of most games. The module is optional and is not compiled in by default.
The rendering module provides a SceneManager, that when provided with a LayoutState, places Entities into a Scene and updates it accordingly as the LayoutState changes. It is up to a specific renderer to then take the Scene and render out the Entities. There is a ResourceAllocator trait that defines the types of resources an Entity consists of. A specific renderer can then provide an implementation that provides the resources it can render out. Those resources are images, paths, i.e. lines, quadratic and cubic bezier curves, fonts and labels. An optional software renderer is available behind the software-rendering feature that uses tiny-skia to efficiently render the paths on the CPU. It is surprisingly fast and can be considered the default renderer.
The run module provides everything necessary for working with a Run, like parsing and saving or editing them.
The Settings module provides the ability to customize a Component and various other settings.
The timing module provides everything necessary for working with times and measuring them.
Various utilities used in this crate.

Structs

An Atomic Date Time represents a UTC DateTime that tries to be as close to an atomic clock as possible.
An Attempt describes information about an attempt to run a specific category by a specific runner in the past. Every time a new attempt is started and then reset, an Attempt describing general information about it is created.
Represents a TimeSpan intended to be used for describing game time.
The general settings of a Layout that apply to all components.
The configuration to use for a HotkeySystem. It describes which Hotkey to use as hotkeys for the different actions.
With a HotkeySystem the runner can use hotkeys on their keyboard to control the Timer. The hotkeys are global, so the application doesn’t need to be in focus. The behavior of the hotkeys depends on the platform and is stubbed out on platforms that don’t support hotkeys. You can turn off a HotkeySystem temporarily. By default the HotkeySystem is activated.
Represents a TimeSpan intended to be used for describing real time.
The RunMetadata struct stores optional information about a run, like the platform and region of the game.
A Segment describes a point in a speedrun that is suitable for storing a split time. This stores the name of that Segment, an icon, the split times of different comparisons, and a history of segment times.
Stores the Segment times achieved for a certain segment. Each Segment is tagged with an index. Only segment times with an index larger than 0 are considered times actually achieved by the runner, while the others are artifacts of route changes and similar algorithmic changes.
A time that can store a Real Time and a Game Time. Both of them are optional.
A TimeSpan represents a certain span of time.
A TimeStamp stores a point in time that can be used to calculate a TimeSpan.
A Timer provides all the capabilities necessary for doing speedrun attempts.

Enums

A Component provides information about a run in a way that is easy to visualize. This type can store any of the components provided by this crate.
Describes which phase the timer is currently in. This tells you if there’s an active speedrun attempt and whether it is paused or it ended.
A TimingMethod describes which form of timing is used. This can either be TimingMethod::RealTime or TimingMethod::GameTime.

Type Definitions

A SharedTimer is a wrapper around the Timer that can be shared across multiple threads with multiple owners.