use std::collections::HashMap;
use std::io::Read;
use flate2::read::GzDecoder;
use super::DATA_GZ;
pub struct Themes(pub HashMap<String, HashMap<String, Vec<String>>>);
pub struct Parts(pub HashMap<String, HashMap<String, String>>);
pub fn parse() -> (Themes, Parts) {
let mut themes: HashMap<String, HashMap<String, Vec<String>>> = HashMap::new();
let mut parts: HashMap<String, HashMap<String, String>> = HashMap::new();
let mut decoder = GzDecoder::new(DATA_GZ);
let mut content = String::new();
decoder
.read_to_string(&mut content)
.expect("解压 multiavatar-data.gz 失败");
if !content.is_ascii() && !content.is_empty() {
}
for line in content.lines() {
if line.is_empty() {
continue;
}
let kind = line.as_bytes()[0];
if kind == b'T' {
let mut it = line[2..].splitn(3, '|');
let part_key = it.next().unwrap_or("").to_string();
let part_name = it.next().unwrap_or("").to_string();
let colors = it
.next()
.unwrap_or("")
.split(',')
.map(|s| s.to_string())
.collect::<Vec<_>>();
themes
.entry(part_key)
.or_default()
.insert(part_name, colors);
} else {
let mut it = line[2..].splitn(3, '|');
let part_key = it.next().unwrap_or("").to_string();
let part_name = it.next().unwrap_or("").to_string();
let body = it.next().unwrap_or("").to_string();
let svg = match body.split_once(':') {
Some((_len, s)) => s.to_string(),
None => body,
};
parts
.entry(part_key)
.or_default()
.insert(part_name, svg);
}
}
(Themes(themes), Parts(parts))
}