From 441cc8cb24ac7dc08802aed28e9223c2c37d7e45 Mon Sep 17 00:00:00 2001 From: aprzn Date: Fri, 17 Feb 2023 21:16:48 -0500 Subject: [PATCH] barely any progress --- rust-toolchain | 1 + src/gd.rs | 4 ++-- src/main.rs | 43 +++++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..bf867e0 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly diff --git a/src/gd.rs b/src/gd.rs index d866e06..a732634 100644 --- a/src/gd.rs +++ b/src/gd.rs @@ -21,7 +21,7 @@ pub enum Song { Unknown, } -pub struct SongResponse([String; 9]); +pub struct SongResponse([Option; 9]); struct Level { outer: OuterLevel, @@ -60,7 +60,7 @@ impl Song { .split("~|~") .array_chunks() .try_for_each(|[id, value]| -> Result<(), SongRequestError> { - out.0[id.parse::()?] = value.into(); + out.0[id.parse::()?] = Some(value.into()); Ok(()) }) .map(|_| out) diff --git a/src/main.rs b/src/main.rs index 6ab9110..94f9b3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,12 +57,14 @@ struct Song { #[derive(Error, Debug)] enum SongError { - #[error("Unknown song")] - Unknown, - #[error("Official level song")] - Official, + #[error("Not a Newgrounds song")] + NotNewgrounds, #[error("Song mp3 not downloaded")] - MissingFile, + MissingFile(#[from] std::io::Error), + #[error("Couldn't decode mp3 file")] + BrokenSong(#[from] rodio::decoder::DecoderError), + #[error("Couldn't access song data on servers")] + ServerError(#[from] gd::SongRequestError) } struct BeatRateWidget<'a> { @@ -101,24 +103,21 @@ impl From for eframe::epaint::Color32 { impl Song { pub fn try_new(gd_song: gd::Song) -> Result { - match gd_song { - gd::Song::Official { id: _ } => Err(SongError::Official), - gd::Song::Unknown => Err(SongError::Unknown), + match &gd_song { gd::Song::Newgrounds { id } => { - let file_result = { - let mut path = gd::gd_path(); - path.push(format!("{}.mp3", id)); - File::open(path) - }; - match file_result { - Ok(file) => Ok(Song { - name: unimplemented!(), - id, - decoder: unimplemented!(), - }), - Err(err) => Err(SongError::MissingFile), - } - } + let song_data = gd_song.get_response()?; + file::open(gd::gd_path().join(format!("{}.mp3", id))) + .or_else(|_| { + + }) + todo!("if file is missing, try to download it from the SongResponse. If that fails, return an error. Otherwise, return file info") + // Ok(Song { + // name: todo!(), + // id, + // decoder: rodio::Decoder::new_mp3(file)? + // }) + }, + _ => Err(SongError::NotNewgrounds) } } }