public static Simfile.Chart ConvertChart(
            Beatmap bm,
            BasicSongInfo info,
            Move[] moves,
            int diff)
        {
            var lines = new List <Simfile.Chart.NoteLine>();

            for (int i = 0; i < moves.Length; i++)
            {
                int[] notes = new int[4];
                for (int foot = 0; foot < 2; foot++)
                {
                    if (moves[i].Pos(foot) != -1)
                    {
                        notes[moves[i].Pos(foot)] = 1;
                    }
                }
                lines.Add(new Simfile.Chart.NoteLine
                {
                    Time  = info.NoteTimes[i],
                    Notes = notes,
                });
            }
            return(new Simfile.Chart
            {
                Type = "dance-single",
                Maker = bm.MetadataSection.Version,
                Difficulty = diffs[Math.Min(diff, diffs.Length - 1)],

                Level = diff + 5,
                Lines = lines,
                PPQ = info.PPQ,
            });
        }
 public static Simfile Convert(
     Beatmap bm,
     BasicSongInfo info,
     List <Simfile.Chart> charts
     )
 {
     return(new Simfile
     {
         Artist = bm.MetadataSection.Artist,
         Music = bm.GeneralSection.AudioFilename,
         Offset = -info.AudioOffset / 1000d,
         Title = bm.MetadataSection.Title,
         BPMs = info.TimingPoints.ConvertAll(x => new Simfile.TimingPoint
         {
             Beat = x.Time / (double)info.PPQ,
             BPM = 60 * 1000.0 / x.Tempo,
         }),
         Charts = charts,
     });
 }
Beispiel #3
0
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        // [STAThread]
        static void Main()
        {
            var         osuPath   = @"C:\Users\sunny\Programs\osu!\";
            var         songsPath = Path.Join(osuPath, "Songs");
            var         simPath   = @"C:\Users\sunny\Programs\StepMania 5.1\Songs\Test";
            var         osuDbPath = Path.Join(osuPath, "osu!.db");
            OsuDatabase db        = DatabaseDecoder.DecodeOsu(osuDbPath);
            var         songs     = Directory.GetDirectories(songsPath);

            Dictionary <int, List <DbBeatmap> > bms = db.Beatmaps
                                                      .GroupBy(x => x.BeatmapSetId, x => x)
                                                      .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var songPath in songs)
            {
                var songFolder = Path.GetFileName(songPath);
                Console.WriteLine(songFolder);


                var     maps = Directory.GetFiles(Path.Join(songsPath, songFolder), "*.osu");
                Simfile s    = null;

                List <DbBeatmap> bs = null;


                foreach (var mapPath in maps)
                {
                    var songName = Path.GetFileNameWithoutExtension(mapPath);
                    Console.WriteLine(" " + songName);
                    Beatmap beatmap = BeatmapDecoder.Decode(Path.Join(songsPath, songFolder, songName + ".osu"));

                    if (bs == null)
                    {
                        bs = bms[beatmap.MetadataSection.BeatmapSetID];
                        bs.Sort((x, y) => x.CirclesCount
                                .CompareTo(y.CirclesCount));
                    }

                    BasicSongInfo      songInfo = OsuToAlgorithm.Convert(beatmap);
                    Random             rng      = new Random(beatmap.MetadataSection.BeatmapID);
                    StepScoreGenerator sg       = new StepScoreGenerator
                    {
                        Rng = rng,
                    };
                    Algorithm a = new Algorithm
                    {
                        Info             = songInfo,
                        RecoveryInterval = songInfo.PPQ / 2 / 8,
                        StepScore        = sg.RandomStepScore(songInfo),
                    };
                    if (s == null)
                    {
                        s = AlgorithmToSimfile.Convert(beatmap, songInfo, new List <Simfile.Chart>());
                    }

                    var x     = a.Run();
                    var chart = AlgorithmToSimfile.ConvertChart(beatmap, songInfo, x,
                                                                diff: bs.FindIndex(y => y.BeatmapId == beatmap.MetadataSection.BeatmapID)

                                                                );
                    s.Charts.Add(chart);
                }
                Directory.CreateDirectory(Path.Join(simPath, songFolder));

                var sb = new StringBuilder();
                s.Append(sb);
                File.WriteAllText(Path.Join(simPath, songFolder, songFolder + ".sm"), sb.ToString());

                File.Copy(Path.Join(songsPath, songFolder, s.Music),
                          Path.Join(simPath, songFolder, s.Music), true);
            }
            //Application.SetHighDpiMode(HighDpiMode.SystemAware);
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }