changes to update_message

This commit is contained in:
Djairo Hougee 2023-05-08 19:37:35 +02:00
parent 9874686595
commit 3be9b6ccea
3 changed files with 26 additions and 36 deletions

View File

@ -23,7 +23,7 @@ fn cutoff(fields: &Vec<Field>, brk: char, strings: &mut HashMap<String, String>)
fn build_string(cfg: &Config, data: &mut Data) -> String { fn build_string(cfg: &Config, data: &mut Data) -> String {
let mut b = Builder::default(); let mut b = Builder::default();
if cfg.hide_output && data.current_player.is_none() { if cfg.hide_output && data.current_player.is_none() {
b.append(' '); b.append(' ');
} else { } else {
cutoff(&cfg.metadata_fields, cfg.break_character, &mut data.display_text); cutoff(&cfg.metadata_fields, cfg.break_character, &mut data.display_text);

View File

@ -46,25 +46,28 @@ 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>, map: &Rating) -> Option<String> {
match r { match r {
Some(rating) => { Some(rating) => {
let f = (rating.as_f64().unwrap() * 10_f64).round() as i64; if let Some(f) = rating.as_f64() {
match f { //todo: refactor let i = (f * 10_f64.round()) as i64;
0 => Some(Rating::repeat(map.nil, 5)), match i {
1 => Some(format!("{}{}", Rating::repeat(map.half, 1), Rating::repeat(map.nil, 4))), 0 => Some(Rating::repeat(map.nil, 5)),
2 => Some(format!("{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.nil, 4))), 1 => Some(format!("{}{}", Rating::repeat(map.half, 1), Rating::repeat(map.nil, 4))),
3 => Some(format!("{}{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 3))), 2 => Some(format!("{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.nil, 4))),
4 => Some(format!("{}{}", Rating::repeat(map.full, 2), Rating::repeat(map.nil, 3))), 3 => Some(format!("{}{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 3))),
5 => Some(format!("{}{}{}", Rating::repeat(map.full, 2), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 2))), 4 => Some(format!("{}{}", Rating::repeat(map.full, 2), Rating::repeat(map.nil, 3))),
6 => Some(format!("{}{}", Rating::repeat(map.full, 3), Rating::repeat(map.nil, 2))), 5 => Some(format!("{}{}{}", Rating::repeat(map.full, 2), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 2))),
7 => Some(format!("{}{}{}", Rating::repeat(map.full, 3), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 1))), 6 => Some(format!("{}{}", Rating::repeat(map.full, 3), Rating::repeat(map.nil, 2))),
8 => Some(format!("{}{}", Rating::repeat(map.full, 4), Rating::repeat(map.nil, 1))), 7 => Some(format!("{}{}{}", Rating::repeat(map.full, 3), Rating::repeat(map.half, 1), Rating::repeat(map.nil, 1))),
9 => Some(format!("{}{}", Rating::repeat(map.full, 4), Rating::repeat(map.half, 1))), 8 => Some(format!("{}{}", Rating::repeat(map.full, 4), Rating::repeat(map.nil, 1))),
10.. => Some(Rating::repeat(map.full, 5)), 9 => Some(format!("{}{}", Rating::repeat(map.full, 4), Rating::repeat(map.half, 1))),
_ => Some(format!("Invalid rating!")) 10.. => Some(Rating::repeat(map.full, 5)),
_ => Some(format!("Invalid rating!"))
}
} else {
None
} }
}, },
None => { None => {
None None
// Rating::repeat(map.nil, 5)
}, },
} }
} }

View File

@ -10,32 +10,19 @@ pub fn update_players(
if players.is_empty() { if players.is_empty() {
data.current_player = None; data.current_player = None;
} else { } else {
let mut active: Vec<Vec<(i32, String)>> = vec![Vec::new(), Vec::new(), Vec::new()]; let mut active: Vec<(i32, String)> = Vec::new();
for player in players { for player in players {
if cfg.player_priorities.contains(&player.identity().to_owned().to_ascii_lowercase()) { if let Ok(mpris::PlaybackStatus::Playing) = player.get_playback_status() {
let name = player.identity(); let name = player.identity();
let idx = cfg.find_player_priorities_idx(name); let idx = cfg.find_player_priorities_idx(name);
if let Ok(status) = player.get_playback_status() { active.push((idx, name.to_owned()));
match status {
mpris::PlaybackStatus::Playing => active[0].push((idx, name.to_owned())),
mpris::PlaybackStatus::Paused => active[1].push((idx, name.to_owned())),
mpris::PlaybackStatus::Stopped => active[2].push((idx, name.to_owned())),
};
}
} }
} }
if !active[0].is_empty() {
data.current_player = Some(get_lowest(&active[0])); if !active.is_empty() {
} else if !active[1].is_empty() { data.current_player = Some(get_lowest(&active));
data.current_player = Some(get_lowest(&active[1]));
} else if !active[2].is_empty() {
data.current_player = Some(get_lowest(&active[2]));
} else { } else {
if let Ok(player) = pf.find_active() { data.current_player = None;
data.current_player = Some(player.identity().to_owned());
} else {
data.current_player = None;
}
} }
} }
} }