mist_run_utils/
run.rs

1#[cfg(feature = "msf")]
2use serde::{Deserialize, Serialize};
3
4#[cfg_attr(feature = "msf", derive(Serialize, Deserialize))]
5#[derive(Debug)]
6pub struct Run {
7    game_title: String,
8    category: String,
9    offset: Option<u128>,
10    pb: u128,
11    splits: Vec<String>,
12    pb_times: Vec<u128>,
13    gold_times: Vec<u128>,
14}
15
16impl Run {
17    pub fn new(game_title: String, category: String, offset: Option<u128>, pb: u128, splits: Vec<String>, pb_times: Vec<u128>, gold_times: Vec<u128>) -> Self {
18	Run {
19		game_title,
20		category,
21		offset,
22		pb,
23		splits,
24		pb_times,
25		gold_times
26    	}
27    }
28    pub fn set_times(&mut self, splits: &Vec<u128>) {
29        self.pb_times = splits.to_vec();
30    }
31    pub fn get_times(&self) -> &Vec<u128> {
32        &self.pb_times
33    }
34    pub fn pb(&self) -> u128 {
35        self.pb
36    }
37    pub fn set_pb(&mut self, pb: u128) {
38        self.pb = pb;
39    }
40    pub fn get_golds(&self) -> &Vec<u128> {
41	&self.gold_times
42    }
43    pub fn gold_time(&self, index: usize) -> u128 {
44        self.gold_times[index]
45    }
46    pub fn set_gold_time(&mut self, index: usize, time: u128) {
47        self.gold_times[index] = time;
48    }
49    pub fn offset(&self) -> Option<u128> {
50        self.offset
51    }
52    pub fn split_names(&self) -> &Vec<String> {
53        &self.splits
54    }
55    pub fn set_name(&mut self, name: String, index: usize) {
56	self.splits[index] = name;
57    }
58    pub fn set_time(&mut self, time: u128, index: usize) {
59	self.pb_times[index] = time;
60    }
61}
62
63/// create an empty run
64impl Default for Run {
65    fn default() -> Self {
66        Run {
67            game_title: "".to_string(),
68            category: "".to_string(),
69            offset: None,
70            pb: 0,
71            splits: vec![],
72            pb_times: vec![],
73            gold_times: vec![],
74        }
75    }
76}