diff --git a/Cargo.lock b/Cargo.lock index f26cc09..f9f0cb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1772,6 +1772,7 @@ dependencies = [ "home", "ordered-float", "rodio", + "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 61dca13..9778afe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ flate2 = {version = "1.0.25"} gd_plist = {git = "https://github.com/Syudagye/gd-plist.git", version = "1.4.0"} chrono = {version = "0.4.23"} ordered-float = {version = "3.4.0"} +thiserror = {version = "1.0.38"} diff --git a/src/gd.rs b/src/gd.rs index 54ec6a2..e77b7e6 100644 --- a/src/gd.rs +++ b/src/gd.rs @@ -12,7 +12,7 @@ struct User { id: Option, } -enum Song { +pub enum Song { Official { id: i32 /*k8*/ }, Newgrounds { id: i32 /*k45*/ }, Unknown, diff --git a/src/main.rs b/src/main.rs index f3ba112..5570b49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ use eframe; use eframe::egui; use std::boxed::Box; use std::collections::VecDeque; +use std::fs::File; +use thiserror::Error; struct PipeDash { msg_queue: VecDeque, @@ -47,7 +49,18 @@ struct GdlData { struct Song { name: String, - id: u32, + id: i32, + decoder: rodio::Decoder, +} + +#[derive(Error, Debug)] +enum SongError { + #[error("Unknown song")] + Unknown, + #[error("Official level song")] + Official, + #[error("Song mp3 not downloaded")] + MissingFile, } struct BeatRateWidget<'a> { @@ -84,6 +97,28 @@ 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), + 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) + } + } + } + } +} + impl Editor { pub fn beat_rate_widget(&mut self) -> BeatRateWidget { BeatRateWidget {