barely any progress

main
aprzn 2 years ago
parent 4d019d68d7
commit 441cc8cb24

@ -0,0 +1 @@
nightly

@ -21,7 +21,7 @@ pub enum Song {
Unknown, Unknown,
} }
pub struct SongResponse([String; 9]); pub struct SongResponse([Option<String>; 9]);
struct Level { struct Level {
outer: OuterLevel, outer: OuterLevel,
@ -60,7 +60,7 @@ impl Song {
.split("~|~") .split("~|~")
.array_chunks() .array_chunks()
.try_for_each(|[id, value]| -> Result<(), SongRequestError> { .try_for_each(|[id, value]| -> Result<(), SongRequestError> {
out.0[id.parse::<usize>()?] = value.into(); out.0[id.parse::<usize>()?] = Some(value.into());
Ok(()) Ok(())
}) })
.map(|_| out) .map(|_| out)

@ -57,12 +57,14 @@ struct Song {
#[derive(Error, Debug)] #[derive(Error, Debug)]
enum SongError { enum SongError {
#[error("Unknown song")] #[error("Not a Newgrounds song")]
Unknown, NotNewgrounds,
#[error("Official level song")]
Official,
#[error("Song mp3 not downloaded")] #[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> { struct BeatRateWidget<'a> {
@ -101,24 +103,21 @@ impl From<Color> for eframe::epaint::Color32 {
impl Song { impl Song {
pub fn try_new(gd_song: gd::Song) -> Result<Self, SongError> { pub fn try_new(gd_song: gd::Song) -> Result<Self, SongError> {
match gd_song { match &gd_song {
gd::Song::Official { id: _ } => Err(SongError::Official),
gd::Song::Unknown => Err(SongError::Unknown),
gd::Song::Newgrounds { id } => { gd::Song::Newgrounds { id } => {
let file_result = { let song_data = gd_song.get_response()?;
let mut path = gd::gd_path(); file::open(gd::gd_path().join(format!("{}.mp3", id)))
path.push(format!("{}.mp3", id)); .or_else(|_| {
File::open(path)
}; })
match file_result { todo!("if file is missing, try to download it from the SongResponse. If that fails, return an error. Otherwise, return file info")
Ok(file) => Ok(Song { // Ok(Song {
name: unimplemented!(), // name: todo!(),
id, // id,
decoder: unimplemented!(), // decoder: rodio::Decoder::new_mp3(file)?
}), // })
Err(err) => Err(SongError::MissingFile), },
} _ => Err(SongError::NotNewgrounds)
}
} }
} }
} }

Loading…
Cancel
Save