use base64::prelude::*;
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_STANDARD.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_STANDARD.encode(profile_toml.as_bytes())
}
pub fn directory(&self) -> String {
self.name.to_lowercase().replace(r"[^a-z0-9]+", "-")
}
}