made rating_icons an optional value in Config
This commit is contained in:
parent
bb8f359f6d
commit
5fe9ef131b
|
|
@ -55,7 +55,7 @@ pub struct Config {
|
|||
pub render_prefix: bool,
|
||||
pub break_character: Option<char>,
|
||||
pub player_priorities: Vec<String>,
|
||||
pub rating_icons: Rating,
|
||||
pub rating_icons: Option<Rating>,
|
||||
pub metadata_fields: Vec<Field>,
|
||||
pub player_prefixes: HashMap<String, char>,
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ impl Default for Config {
|
|||
fuzzy: false,
|
||||
render_prefix: true,
|
||||
metadata_fields: Config::default_metadata_fields(),
|
||||
rating_icons: Rating::default(),
|
||||
rating_icons: Some(Rating::default()),
|
||||
player_priorities: Config::default_player_priorities(),
|
||||
break_character: Some('-'),
|
||||
player_prefixes: Config::default_player_prefixes(),
|
||||
|
|
|
|||
|
|
@ -28,12 +28,19 @@ fn value_to_string(v: &MetadataValue, sep: char) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
fn rating_to_string(r: Option<&MetadataValue>, map: &Rating) -> Option<String> {
|
||||
fn rating_to_string(r: Option<&MetadataValue>, opt: Option<&Rating>) -> Option<String> {
|
||||
let def = Rating::default();
|
||||
let map: &Rating;
|
||||
match opt {
|
||||
Some(m) => map = m,
|
||||
None => map = &def,
|
||||
}
|
||||
|
||||
match r {
|
||||
Some(rating) => {
|
||||
if let Some(f) = rating.as_f64() {
|
||||
let i = (f * 10_f64).round() as i64;
|
||||
match i {
|
||||
match i { //TODO: refactor this
|
||||
0 => Some(Rating::repeat(map.nil, 5)),
|
||||
1 => Some(format!("{}{}", Rating::repeat(map.half, 1), Rating::repeat(map.nil, 4))),
|
||||
2 => Some(format!("{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.nil, 4))),
|
||||
|
|
@ -63,7 +70,7 @@ pub fn update_message(cfg: &Config, data: &mut Data) {
|
|||
for field in &cfg.metadata_fields {
|
||||
let key = field.field.clone();
|
||||
if field.field.eq("xesam:userRating") {
|
||||
if let Some(rating_string) = rating_to_string(meta.get(&key), &cfg.rating_icons) {
|
||||
if let Some(rating_string) = rating_to_string(meta.get(&key), cfg.rating_icons.as_ref()) {
|
||||
data.display_text.insert(key, rating_string);
|
||||
} else {
|
||||
data.display_text.remove(&key);
|
||||
|
|
|
|||
Loading…
Reference in New Issue