1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use base64;
use serde_derive::{Deserialize, Serialize};
use std::str;
#[derive(Deserialize, Serialize)]
pub struct Profile {
pub name: String,
pub level: usize,
pub maximus_oxidus: bool,
}
impl Profile {
pub fn new(name: String) -> Profile {
Profile {
name,
level: 1,
maximus_oxidus: false,
}
}
pub fn increment_level(&mut self) {
self.level += 1;
}
pub fn from_toml(contents: &str) -> Profile {
let err = "failed to parse .profile";
let bytes = base64::decode(contents).expect(err);
let decoded = str::from_utf8(&bytes).expect(err);
toml::from_str(decoded).expect(err)
}
pub fn to_toml(&self) -> String {
let profile_toml = toml::to_string(&self).unwrap();
base64::encode(&profile_toml.as_bytes())
}
pub fn directory(&self) -> String {
self.name.to_lowercase().replace(r"[^a-z0-9]+", "-")
}
}