Skip to main content

to_osu/
to_osu.rs

1use rotterna_lib::structs::{SmFile, OsuSettings};
2use rotterna_lib::converter::osu::create_basic_osu;
3use std::path::PathBuf;
4use std::fs;
5
6fn main() {
7    // Load MEGALOVANIA.sm file
8    let sm_path = PathBuf::from("assets/MEGALOVANIA.sm");
9    
10    println!("Loading SM file: {:?}", sm_path);
11    
12    let sm_file = match SmFile::from_file(sm_path) {
13        Ok(file) => file,
14        Err(e) => {
15            eprintln!("Error loading SM file: {}", e);
16            std::process::exit(1);
17        }
18    };
19    println!("Offset: {}", sm_file.offset);
20    println!("Loaded {} chart(s)", sm_file.charts.len());
21    
22    // Convert each chart to .osu format
23    for (chart_idx, chart) in sm_file.charts.iter().enumerate() {
24        println!("\nConverting chart {}: {} ({})", 
25            chart_idx + 1, 
26            chart.difficulty.trim_end_matches(':'),
27            chart.stepstype.trim_end_matches(':')
28        );
29        
30        // Create OsuSettings (you can adjust these values)
31        let settings = OsuSettings {
32            hp: 5.0,  // HP Drain Rate
33            od: 8.0,  // Overall Difficulty
34        };
35        
36        // Convert to .osu format
37        match create_basic_osu(&sm_file, chart, &settings) {
38            Ok(osu_content) => {
39                // Generate output filename
40                let difficulty_name = chart.difficulty.trim_end_matches(':');
41                let sanitized_name = difficulty_name
42                    .chars()
43                    .map(|c| if c.is_alphanumeric() || c == '-' || c == '_' { c } else { '_' })
44                    .collect::<String>();
45                
46                let output_path = format!("output/MEGALOVANIA_{}.osu", sanitized_name);
47                
48                // Create output directory if it doesn't exist
49                if let Some(parent) = PathBuf::from(&output_path).parent() {
50                    fs::create_dir_all(parent).expect("Failed to create output directory");
51                }
52                
53                // Write .osu file
54                fs::write(&output_path, osu_content)
55                    .expect("Failed to write .osu file");
56                
57                println!("  ✓ Saved to: {}", output_path);
58            }
59            Err(e) => {
60                eprintln!("  ✗ Error converting chart: {}", e);
61            }
62        }
63    }
64    
65    println!("\nConversion complete!");
66}
67