Пример #1
0
        public override void Match(string line)
        {
            if (line.StartsWith("//"))
            {
                var section = line.Trim();
                switch (section)
                {
                case SectionBgVideo:
                    _currentSection = SectionBgVideo;
                    break;

                case SectionBreak:
                    _currentSection = SectionBreak;
                    break;

                case SectionSbSamples:
                    if (!_options.StoryboardIgnored)
                    {
                        ElementGroup = ElementGroup.ParseFromText(_sbInfo.ToString().Trim('\r', '\n'));
                    }
                    _currentSection = SectionSbSamples;
                    break;

                default:
                    if (section.StartsWith(SectionStoryboard))
                    {
                        _currentSection = SectionStoryboard;
                        _sbInfo.AppendLine(line);
                    }
                    else
                    {
                        _currentSection = section;
                        _unknownSection.Add(section, new StringBuilder());
                    }
                    break;
                }
            }
            else
            {
                switch (_currentSection)
                {
                case SectionBgVideo:
                    // https://osu.ppy.sh/help/wiki/osu!_File_Formats/Osu_(file_format)#videos
                    if (line.StartsWith("Video,") || line.StartsWith("1,"))
                    {
                        var infos = line.Split(',');
                        VideoInfo = new VideoData {
                            Offset = double.Parse(infos[1]), Filename = infos[2].Trim('"')
                        };
                    }
                    else
                    {
                        var    infos = line.Split(',');
                        double x = 0, y = 0;
                        if (infos.Length > 3)
                        {
                            x = double.Parse(infos[3]);
                            y = double.Parse(infos[4]);
                        }

                        BackgroundInfo = new BackgroundData
                        {
                            Unknown1 = infos[0],
                            Unknown2 = infos[1],
                            Filename = infos[2].Trim('"'),
                            X        = x,
                            Y        = y
                        };
                    }
                    break;

                case SectionBreak:
                {
                    var infos = line.Split(',');
                    Breaks.Add(new RangeValue <int>(int.Parse(infos[1]), int.Parse(infos[2])));
                }
                break;

                case SectionSbSamples:
                    if (!_options.SampleIgnored)
                    {
                        if (line.StartsWith("Sample,") || line.StartsWith("5,"))
                        {
                            var infos = line.Split(',');
                            SampleInfo.Add(new StoryboardSampleData
                            {
                                Offset     = int.Parse(infos[1]),
                                MagicalInt = int.Parse(infos[2]),
                                Filename   = infos[3].Trim('"'),
                                Volume     = infos.Length > 4 ? int.Parse(infos[4]) : 0,
                            });
                        }
                    }
                    break;

                case SectionStoryboard:
                    if (!_options.StoryboardIgnored)
                    {
                        _sbInfo.AppendLine(line);
                    }
                    break;

                default:
                    _unknownSection[_currentSection].AppendLine(line);
                    break;
                }
            }
        }
Пример #2
0
        public void Match(string line)
        {
            if (line.StartsWith("//"))
            {
                var section = line.Trim();
                switch (section)
                {
                case SectionBgVideo:
                    _currentSection = SectionBgVideo;
                    break;

                case SectionBreak:
                    _currentSection = SectionBreak;
                    break;

                case SectionSbSamples:
                    //todo: use OsbLib like: "ElementGroup eg = new ElementGroup(_sbInfo.ToString());"
                    _currentSection = SectionSbSamples;
                    break;

                default:
                    if (section.StartsWith(SectionStoryboard))
                    {
                        _currentSection = SectionStoryboard;
                        _sbInfo.AppendLine(line);
                    }
                    else
                    {
                        _currentSection = section;
                        _unknownSection.Add(section, new StringBuilder());
                    }
                    break;
                }
            }
            else
            {
                switch (_currentSection)
                {
                case SectionBgVideo:
                    if (line.StartsWith("Video,"))
                    {
                        var infos = line.Split(',');
                        VideoInfo = new VideoInfo {
                            Offset = double.Parse(infos[1]), Filename = infos[2].Trim('"')
                        };
                    }
                    else
                    {
                        var    infos = line.Split(',');
                        double x = 0, y = 0;
                        if (infos.Length > 3)
                        {
                            x = double.Parse(infos[3]);
                            y = double.Parse(infos[4]);
                        }

                        BackgroundInfo = new BackgroundInfo
                        {
                            Unknown1 = infos[0],
                            Unknown2 = infos[1],
                            Filename = infos[2].Trim('"'),
                            X        = x,
                            Y        = y
                        };
                    }
                    break;

                case SectionBreak:
                {
                    var infos = line.Split(',');
                    Breaks.Add(new OsuFile.TimeRange(double.Parse(infos[1]), double.Parse(infos[2])));
                }
                break;

                case SectionSbSamples:
                    if (line.StartsWith("Sample,"))
                    {
                        var infos = line.Split(',');
                        SampleInfo.Add(new SbSampleInfo
                        {
                            Offset     = int.Parse(infos[1]),
                            MagicalInt = int.Parse(infos[2]),
                            Filename   = infos[3].Trim('"'),
                            Volume     = int.Parse(infos[4]),
                        });
                    }
                    break;

                case SectionStoryboard:
                    _sbInfo.AppendLine(line);
                    break;

                default:
                    _unknownSection[_currentSection].AppendLine(line);
                    break;
                }
            }
        }