Beispiel #1
0
        public void Parse()
        {
            int bias = 1;
            int pos  = 0;

            using (var ms = new MemoryStream(RawData))
            {
                using (var sr = new StreamReader(ms))
                {
                    string blockName = "";
                    while (!sr.EndOfStream)
                    {
                        string rawLine = sr.ReadLine();
                        Debug.Assert(rawLine != null, nameof(rawLine) + " != null");
                        int rawLineLen = Encoding.UTF8.GetByteCount(rawLine) + bias;

                        string line = rawLine.Trim();

                        if (line.StartsWith("["))
                        {
                            blockName = line.Substring(1, line.Length - 2).Trim();
                            if (blockName == "HitObjects")
                            {
                                _beatmapHeaderSpan.Length = pos + rawLineLen;
                            }
                        }
                        else if (!string.IsNullOrEmpty(line) && (blockName == "General" || blockName == "Difficulty"))
                        {
                            GetPropertyString(line, out var prop, out var val);

                            switch (prop)
                            {
                            case "Mode":
                                OsuPlayMode mode = (OsuPlayMode)int.Parse(val);
                                if (mode != OsuPlayMode.Mania && Mode == (int)OsuPlayMode.Mania)
                                {
                                    Sync.Tools.IO.CurrentIO.WriteColor("[RTPPD::Beatmap]Only support mania beatmap.", ConsoleColor.Yellow);
                                    Mode = (int)mode;
                                }
                                else if (mode == OsuPlayMode.Mania && Mode != (int)OsuPlayMode.Mania)
                                {
                                    Mode = (int)mode;
                                }
                                break;

                            case "ApproachRate":
                                ApproachRate = double.Parse(val, CultureInfo.InvariantCulture);
                                break;

                            case "OverallDifficulty":
                                OverallDifficulty = double.Parse(val, CultureInfo.InvariantCulture);
                                break;

                            case "HPDrainRate":
                                HpDrainRate = double.Parse(val, CultureInfo.InvariantCulture);
                                break;

                            case "CircleSize":
                                CircleSize = double.Parse(val, CultureInfo.InvariantCulture);
                                if (Mode == (int)OsuPlayMode.Mania)
                                {
                                    KeyCount = int.Parse(val);
                                }
                                break;
                            }
                        }
                        else if (!string.IsNullOrEmpty(line) && blockName == "HitObjects")
                        {
                            BeatmapObject obj;

                            switch (Mode)
                            {
                            case (int)OsuPlayMode.Mania:
                                obj = new ManiaBeatmapObject(line, pos, rawLineLen, this);
                                break;

                            case (int)OsuPlayMode.CatchTheBeat:
                            case (int)OsuPlayMode.Osu:
                            case (int)OsuPlayMode.Taiko:
                                obj = new BeatmapObject(line, pos, rawLineLen, this);
                                break;

                            default:
                                obj = null;
                                break;
                            }

                            Objects.Add(obj);
                        }

                        pos += rawLineLen;
                    }
                }
            }

            if (Mode == (int)OsuPlayMode.Mania)
            {
                Objects.Sort((a, b) => a.StartTime - b.StartTime);
            }
        }
Beispiel #2
0
        public void Parse()
        {
            int bias = 2;

            int pos = Array.IndexOf(RawData, (byte)'\n');

            if (RawData[pos - 1] != '\r')
            {
                bias = 1;
            }

            pos = 0;

            using (var ms = new MemoryStream(RawData))
            {
                using (var sr = new StreamReader(ms))
                {
                    string block_name = "";
                    while (!sr.EndOfStream)
                    {
                        string raw_line     = sr.ReadLine();
                        int    raw_line_len = Encoding.UTF8.GetByteCount(raw_line) + bias;

                        string line = raw_line.Trim();

                        if (line.StartsWith("["))
                        {
                            block_name = line.Substring(1, line.Length - 2).Trim();
                            if (block_name == "HitObjects")
                            {
                                m_beatmap_header_span.Length = pos + raw_line_len;
                            }
                        }
                        else if (!string.IsNullOrEmpty(line) && (block_name == "General" || block_name == "Difficulty"))
                        {
                            GetPropertyString(line, out var prop, out var val);

                            switch (prop)
                            {
                            case "Mode":
                                OsuPlayMode mode = (OsuPlayMode)int.Parse(val);
                                if (mode != OsuPlayMode.Mania && Mode == OsuPlayMode.Mania)
                                {
                                    Sync.Tools.IO.CurrentIO.WriteColor($"[RTPPD::Beatmap]Only support mania beatmap.", ConsoleColor.Yellow);
                                    Mode = mode;
                                }
                                else if (mode == OsuPlayMode.Mania && Mode != OsuPlayMode.Mania)
                                {
                                    Mode = mode;
                                }
                                break;

                            case "OverallDifficulty":
                                OverallDifficulty = double.Parse(val, CultureInfo.InvariantCulture);
                                break;

                            case "HPDrainRate":
                                HPDrainRate = double.Parse(val, CultureInfo.InvariantCulture);
                                break;

                            case "CircleSize":
                                CircleSize = double.Parse(val, CultureInfo.InvariantCulture);
                                if (Mode == OsuPlayMode.Mania)
                                {
                                    KeyCount = int.Parse(val);
                                }
                                break;
                            }
                        }
                        else if (!string.IsNullOrEmpty(line) && block_name == "HitObjects")
                        {
                            BeatmapObject obj;
                            if (Mode != OsuPlayMode.Mania)
                            {
                                obj = new BeatmapObject(line, pos, raw_line_len, this);
                            }
                            else
                            {
                                obj = new ManiaBeatmapObject(line, pos, raw_line_len, this);
                            }

                            Objects.Add(obj);
                        }

                        pos += raw_line_len;
                    }
                }
            }

            if (Mode == OsuPlayMode.Mania)
            {
                Objects.Sort((a, b) => a.StartTime - b.StartTime);
            }
        }