pub fn from_file_dat(filename: &str) -> Result<Beatmap, Box<dyn Error>> {
        // Get Info from info.dat
        let info_contents = std::fs::read_to_string(filename)?;
        let info: Info = serde_json::from_str(&info_contents)?;

        // Get the directory containing the map
        let beatmap_dir = Path::new(filename).parent().unwrap_or(Path::new("."));

        let mut difficulties: DifficultyHashMap = HashMap::new();
        // For each characteristic, get the difficulty ranks
        for difficulty_beatmap_set in &info.difficulty_beatmap_sets {
            let mut sub_difficulties = HashMap::new();
            // For each difficulty rank, get the difficulty from its file
            for difficulty_beatmap in &difficulty_beatmap_set.difficulty_beatmaps {
                let difficulty_filename =
                    Path::new(beatmap_dir).join(&difficulty_beatmap.beatmap_filename);
                let difficulty_contents = std::fs::read_to_string(difficulty_filename)?;
                let difficulty: Difficulty = serde_json::from_str(&difficulty_contents)?;

                sub_difficulties.insert(difficulty_beatmap.difficulty_rank.clone(), difficulty);
            }

            difficulties.insert(
                difficulty_beatmap_set.beatmap_characteristic_name.clone(),
                sub_difficulties,
            );
        }

        // Calculate the audio file length
        #[cfg(feature = "audio")]
        let mut length = 0.0;
        #[cfg(feature = "audio")]
        {
            let audio_filename = Path::new(beatmap_dir).join(&info.song_filename);
            let mut audio_file = File::open(audio_filename)?;
            let formats = ogg_metadata::read_format(&mut audio_file)?;

            length = Beatmap::calculate_ogg_length(formats, length);
        }

        // Create the Beatmap and return it
        Ok(Beatmap {
            info,
            difficulties,
            #[cfg(feature = "beatsaver")]
            key: None,
            #[cfg(feature = "audio")]
            length,
        })
    }
/// Returns a new Beatmap instance from an `info.dat` file
Returns a new Beatmap instance from an `info.dat` file
Returns a new Beatmap instance from an ` info . dat ` file
pub fn from_file_dat(filename: &str) -> Result<Beatmap, Box<dyn Error>> {
        // Get Info from info.dat
        let info_contents = std::fs::read_to_string(filename)?;
        let info: Info = serde_json::from_str(&info_contents)?;
        // Get the directory containing the map
        let beatmap_dir = Path::new(filename).parent().unwrap_or(Path::new("."));
        let mut difficulties: DifficultyHashMap = HashMap::new();
        // For each characteristic, get the difficulty ranks
        for difficulty_beatmap_set in &info.difficulty_beatmap_sets {
            let mut sub_difficulties = HashMap::new();
            // For each difficulty rank, get the difficulty from its file
            for difficulty_beatmap in &difficulty_beatmap_set.difficulty_beatmaps {
                let difficulty_filename =
                    Path::new(beatmap_dir).join(&difficulty_beatmap.beatmap_filename);
                let difficulty_contents = std::fs::read_to_string(difficulty_filename)?;
                let difficulty: Difficulty = serde_json::from_str(&difficulty_contents)?;
                sub_difficulties.insert(difficulty_beatmap.difficulty_rank.clone(), difficulty);
            }
            difficulties.insert(
                difficulty_beatmap_set.beatmap_characteristic_name.clone(),
                sub_difficulties,
            );
        }
        // Calculate the audio file length
        #[cfg(feature = "audio")]
        let mut length = 0.0;
        #[cfg(feature = "audio")]
        {
            let audio_filename = Path::new(beatmap_dir).join(&info.song_filename);
            let mut audio_file = File::open(audio_filename)?;
            let formats = ogg_metadata::read_format(&mut audio_file)?;
            length = Beatmap::calculate_ogg_length(formats, length);
        }
        // Create the Beatmap and return it
        Ok(Beatmap {
            info,
            difficulties,
            #[cfg(feature = "beatsaver")]
            key: None,
            #[cfg(feature = "audio")]
            length,
        })
    }
pub fn from_file_dat ( filename : & str ) -> Result < Beatmap , Box < dyn Error > > { // Get Info from info.dat let info_contents = std :: fs :: read_to_string ( filename ) ? ; let info : Info = serde_json :: from_str ( & info_contents ) ? ; // Get the directory containing the map let beatmap_dir = Path :: new ( filename ) . parent ( ) . unwrap_or ( Path :: new ( " " ) ) ; let mut difficulties : DifficultyHashMap = HashMap :: new ( ) ; // For each characteristic, get the difficulty ranks for difficulty_beatmap_set in & info . difficulty_beatmap_sets { let mut sub_difficulties = HashMap :: new ( ) ; // For each difficulty rank, get the difficulty from its file for difficulty_beatmap in & difficulty_beatmap_set . difficulty_beatmaps { let difficulty_filename = Path :: new ( beatmap_dir ) . join ( & difficulty_beatmap . beatmap_filename ) ; let difficulty_contents = std :: fs :: read_to_string ( difficulty_filename ) ? ; let difficulty : Difficulty = serde_json :: from_str ( & difficulty_contents ) ? ; sub_difficulties . insert ( difficulty_beatmap . difficulty_rank . clone ( ) , difficulty ) ; } difficulties . insert ( difficulty_beatmap_set . beatmap_characteristic_name . clone ( ) , sub_difficulties , ) ; } // Calculate the audio file length # [ cfg ( feature " " ) ] let mut length = 0.0 ; # [ cfg ( feature " " ) ] { let audio_filename = Path :: new ( beatmap_dir ) . join ( & info . song_filename ) ; let mut audio_file = File :: open ( audio_filename ) ? ; let formats = ogg_metadata :: read_format ( & mut audio_file ) ? ; length = Beatmap :: calculate_ogg_length ( formats , length ) ; } // Create the Beatmap and return it Ok ( Beatmap { info , difficulties , # [ cfg ( feature " " ) ] key : None , # [ cfg ( feature " " ) ] length , } ) }
Returns a new Beatmap instance from an `info.dat` file
Returns a new Beatmap instance from an ` info . dat ` file
filename
&str