diff --git a/src/gui.rs b/src/gui.rs index e57b235..46c0de7 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -17,9 +17,8 @@ use std::f32::consts::PI; use crate::Polymusic; -pub fn music_view(app: &Polymusic) -> iced::Element { +pub fn music_view(app: &Polymusic) -> iced::Element<'_, Message> { let mut i = 0; - let entries = app.all_sounds.clone(); //Create all polygon options let polygon_rows: Vec> = app .music @@ -202,7 +201,7 @@ pub fn music_view(app: &Polymusic) -> iced::Element { .into() } -pub fn load_file_view(app: &Polymusic) -> iced::Element { +pub fn load_file_view() -> iced::Element<'static, Message> { Container::new( column![ text("Polymusic").size(42), diff --git a/src/main.rs b/src/main.rs index 2380e21..0014ab2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,6 @@ struct Polymusic { time_last_frame: Instant, paused: bool, audio_manager: AudioManager, - all_sounds: Vec, all_saves: Vec, current_delta: f32, str_music_length: String, @@ -97,7 +96,6 @@ impl Polymusic { time_last_frame: Instant::now(), audio_manager: manager, paused: true, - all_sounds: load_path_sounds(), all_saves: load_path_saves(), music: Music::default(), current_delta: 0.0, @@ -178,29 +176,26 @@ impl Polymusic { .add_filter("Audio Files", &["mp3", "wav", "ogg"]) .set_directory("./") .pick_file(); - match file { - Some(s) => { - let root_path = PathBuf::from(&self.root); - let relative_path = diff_paths(&s, &root_path) - .expect("Impossible de calculer le chemin relatif"); - let path_string = relative_path.to_string_lossy().into_owned(); - let sound = StaticSoundData::from_file(format!( - "{0}/{1}", - self.root, - path_string.clone() - )) - .expect("Fail to load audio"); - let old_sound = - self.music - .set_sound(self.current_delta, i, sound, path_string.clone()); - self.already_save = false; - self.historic.add( - Message::ReChangeSound(i, old_sound), - Message::ReChangeSound(i, path_string), - self.current_delta, - ); - } - none => eprintln!("fail to load file"), + if let Some(s) = file { + let root_path = PathBuf::from(&self.root); + let relative_path = diff_paths(&s, &root_path) + .expect("Impossible de calculer le chemin relatif"); + let path_string = relative_path.to_string_lossy().into_owned(); + let sound = StaticSoundData::from_file(format!( + "{0}/{1}", + self.root, + path_string.clone() + )) + .expect("Fail to load audio"); + let old_sound = + self.music + .set_sound(self.current_delta, i, sound, path_string.clone()); + self.already_save = false; + self.historic.add( + Message::ReChangeSound(i, old_sound), + Message::ReChangeSound(i, path_string), + self.current_delta, + ); } } Message::Save => { @@ -422,11 +417,11 @@ impl Polymusic { } } - fn view(&self) -> iced::Element { + fn view(&self) -> iced::Element<'_, Message> { if !self.mode_file_load { music_view(self) } else { - load_file_view(self) + load_file_view() } } @@ -501,16 +496,6 @@ impl Polymusic { } } -fn load_path_sounds() -> Vec { - let mut entries: Vec = fs::read_dir("./assets") - .unwrap() - .filter_map(|res| res.ok()) - .map(|e| e.path().file_name().unwrap().to_str().unwrap().to_string()) - .collect(); - entries.sort(); - entries -} - fn load_path_saves() -> Vec { fs::create_dir_all("./saves").expect("fail to creat 'saves' !"); let mut saves: Vec = fs::read_dir("./saves") diff --git a/src/polygon_draw.rs b/src/polygon_draw.rs index 9492888..997a9a0 100644 --- a/src/polygon_draw.rs +++ b/src/polygon_draw.rs @@ -1,4 +1,3 @@ -use crate::utils::string_to_color; use crate::color::color_serde; use std::f32::consts::PI; diff --git a/src/utils.rs b/src/utils.rs index 137571c..cdddc7b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,4 @@ use crate::Polygon; -use iced::Color; use kira::sound::static_sound::StaticSoundData; use regex::Regex; @@ -7,16 +6,6 @@ pub fn is_delta_format_valid(str: &str) -> bool { let re = Regex::new(r"^\d{1,2}:\d{1,2}:\d{1,2}$").unwrap(); re.is_match(str) } -pub fn string_to_color>(s: S) -> Color { - match s.as_ref() { - "Green" => Color::from_rgb(0.0, 1.0, 0.0), - "Blue" => Color::from_rgb(0.0, 0.0, 1.0), - "Cyan" => Color::from_rgb(0.0, 1.0, 1.0), - "Yellow" => Color::from_rgb(1.0, 1.0, 0.0), - "Pink" => Color::from_rgb(1.0, 0.0, 1.0), - _ => Color::BLACK, - } -} pub fn delta_to_string(delta: f32) -> String { let time = [