use super::TimeType;
#[cfg(feature = "ser")]
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "ser", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct Run {
game_title: String,
category: String,
offset: TimeType,
pb: TimeType,
splits: Vec<String>,
pb_times: Vec<TimeType>,
gold_times: Vec<TimeType>,
sum_times: Vec<(u128, TimeType)>,
}
impl Run {
pub fn empty() -> Self {
Run {
game_title: String::new(),
category: String::new(),
offset: TimeType::None,
pb: TimeType::None,
splits: vec![],
pb_times: vec![],
gold_times: vec![],
sum_times: vec![],
}
}
#[allow(clippy::too_many_arguments)]
pub fn new<S>(
game_title: S,
category: S,
offset: TimeType,
pb: TimeType,
splits: &[String],
pb_times: &[TimeType],
gold_times: &[TimeType],
sum_times: &[(u128, TimeType)],
) -> Self
where
S: ToString,
{
Run {
game_title: game_title.to_string(),
category: category.to_string(),
offset,
pb,
splits: splits.to_owned(),
pb_times: pb_times.to_owned(),
gold_times: gold_times.to_owned(),
sum_times: sum_times.to_owned(),
}
}
pub fn game_title(&self) -> &str {
&self.game_title
}
pub fn category(&self) -> &str {
&self.category
}
pub fn offset(&self) -> TimeType {
self.offset
}
pub fn pb(&self) -> TimeType {
self.pb
}
pub fn splits(&self) -> &Vec<String> {
&self.splits
}
pub fn pb_times(&self) -> &Vec<TimeType> {
&self.pb_times
}
pub fn pb_times_u128(&self) -> Vec<u128> {
self.pb_times.iter().map(|t| t.raw()).collect()
}
pub fn gold_times(&self) -> &Vec<TimeType> {
&self.gold_times
}
pub fn gold_times_u128(&self) -> Vec<u128> {
self.gold_times.iter().map(|t| t.val()).collect()
}
pub fn sum_times(&self) -> &Vec<(u128, TimeType)> {
&self.sum_times
}
pub fn set_game_title<S>(&mut self, new: S)
where
S: ToString,
{
self.game_title = new.to_string();
}
pub fn set_category<S>(&mut self, new: S)
where
S: ToString,
{
self.category = new.to_string();
}
pub fn set_offset(&mut self, new: TimeType) {
self.offset = new;
}
pub fn set_pb(&mut self, new: TimeType) {
self.pb = new;
}
pub fn set_splits(&mut self, new: &[String]) {
self.splits = new.to_owned();
}
pub fn set_split<S>(&mut self, idx: usize, new: S)
where
S: ToString,
{
self.splits[idx] = new.to_string();
}
pub fn set_pb_times(&mut self, new: &[TimeType]) {
self.pb_times = new.to_owned();
}
pub fn set_pb_time(&mut self, idx: usize, new: TimeType) {
self.pb_times[idx] = new;
}
pub fn set_gold_times(&mut self, new: &[TimeType]) {
self.gold_times = new.to_owned();
}
pub fn set_gold_time(&mut self, idx: usize, new: TimeType) {
self.gold_times[idx] = new;
}
pub fn set_sum_times(&mut self, new: &[(u128, TimeType)]) {
self.sum_times = new.to_owned();
}
pub fn set_sum_time(&mut self, idx: usize, new: (u128, TimeType)) {
self.sum_times[idx] = new
}
pub fn add_split(&mut self, index: usize) {
self.pb_times.insert(index, TimeType::None);
self.gold_times.insert(index, TimeType::None);
self.splits.insert(index, String::new());
self.sum_times.insert(index, (1, TimeType::None));
}
pub fn remove_split(&mut self, index: usize) {
self.pb_times.remove(index);
self.gold_times.remove(index);
self.splits.remove(index);
self.sum_times.remove(index);
}
}