working on loading the song, need to figure out how to get name

main
aprzn
parent 5c764b5f8d
commit 407079548a

1
Cargo.lock generated

@ -1772,6 +1772,7 @@ dependencies = [
"home",
"ordered-float",
"rodio",
"thiserror",
]
[[package]]

@ -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"}

@ -12,7 +12,7 @@ struct User {
id: Option<u64>,
}
enum Song {
pub enum Song {
Official { id: i32 /*k8*/ },
Newgrounds { id: i32 /*k45*/ },
Unknown,

@ -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<Message>,
@ -47,7 +49,18 @@ struct GdlData {
struct Song {
name: String,
id: u32,
id: i32,
decoder: rodio::Decoder<File>,
}
#[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<Color> for eframe::epaint::Color32 {
}
}
impl Song {
pub fn try_new(gd_song: gd::Song) -> Result<Self, SongError> {
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 {

Loading…
Cancel
Save