예제 #1
0
        public BeatmapInfo(string filename)
        {
            List <Note>     notes;
            List <LongNote> lns;

            //  Load, and parse.
            if (File.Exists(filename))
            {
                if (filename.Split('.')[filename.Split('.').Length - 1] != "osu")
                {
                    throw new InvalidBeatmapException("Unknown file format.");
                }

                Data = MetadataParser.Parse(filename);
                HitObjectParser.Parse(filename, out notes, out lns, Data.Keys);
            }
            else
            {
                throw new FileNotFoundException();
            }

            //  Calculate densities.
            JenksDensity = DensityCalculator.GetJenksDensity(ref notes, ref lns, Data.Keys);
            JenksSpeed   = DensityCalculator.GetJenksSpeed(ref notes, ref lns);

            //  Copy data.
            Notes = notes;
            LNs   = lns;
        }
예제 #2
0
        public BeatmapInfo(string filename)
        {
            List <Note>     notes;
            List <LongNote> lns;

            //  Load, and parse.
            if (File.Exists(filename))
            {
                if (filename.Split('.')[filename.Split('.').Length - 1] != "osu")
                {
                    throw new InvalidBeatmapException("Unknown file format.");
                }

                Data = MetadataParser.Parse(filename);
                HitObjectParser.Parse(filename, out notes, out lns, Data.Keys);
            }
            else
            {
                throw new FileNotFoundException();
            }

            //  Calculate densities.
            var orgDen = DensityCalculator.GetDensity(ref notes, ref lns);
            var corDen = DensityCalculator.GetCorrectedDensity(ref notes, ref lns, Data.Keys);

            //  Copy data.
            Notes = notes;
            LNs   = lns;

            MaxDen    = orgDen.Item1;
            AvgDen    = orgDen.Item2;
            CorMaxDen = corDen.Item1;
            CorAvgDen = corDen.Item2;
        }
예제 #3
0
        protected override void ParseFile(StreamReader stream, Sheetmusic sheetmusic) // 解碼
        {
            sheetmusic.SheetmusicInfo.SheetmusicVersion = sheetmusicVersion;

            Section section          = Section.None;
            bool    hasCustomColours = false;

            string line;

            while ((line = stream.ReadLine()) != null)
            {
                if (line.Equals(" ") || line.Equals(""))
                {
                    continue;
                }

                if (line.StartsWith("//"))
                {
                    continue;
                }

                if (line.StartsWith(@"straight file format v"))
                {
                    sheetmusic.SheetmusicInfo.SheetmusicVersion = int.Parse(line.Substring(13));
                    continue;
                }

                if (line.StartsWith(@"[") && line.EndsWith(@"]"))
                {
                    section = (Section)Enum.Parse(typeof(Section), line.Substring(1, line.Length - 2));
                    continue;
                }

                switch (section)
                {
                case Section.General:
                    handleGeneral(sheetmusic, line);
                    break;

                case Section.Metadata:
                    handleMetadata(sheetmusic, line);
                    break;

                case Section.Difficulty:
                    handleDifficulty(sheetmusic, line);
                    break;

                //case Section.Events:
                //    handleEvents(sheetmusic, line, ref storyboardSprite, ref timelineGroup);
                //    break;
                case Section.TimingPoints:
                    handleTimingPoints(sheetmusic, line);
                    break;

                //case Section.Colours:
                //    handleColours(sheetmusic, line, ref hasCustomColours);
                //    break;
                case Section.HitObjects:

                    // If the ruleset wasn't specified, assume the osu!standard ruleset.
                    if (parser == null)
                    {
                        parser = new Rulesets.Objects.Parsers.ConvertHitObjectParser();
                    }

                    var obj = parser.Parse(line);

                    if (obj != null)
                    {
                        sheetmusic.HitObjects.Add(obj);
                    }

                    break;
                    //case Section.Variables:
                    //    handleVariables(line);
                    //    break;
                }
            }

            foreach (var hitObject in sheetmusic.HitObjects)
            {
                hitObject.ApplyDefaults(sheetmusic.ControlPointInfo, sheetmusic.SheetmusicInfo.BaseDifficulty);
            }
        }
예제 #4
0
        protected override Beatmap ParseFile(TextReader stream)
        {
            var beatmap = new Beatmap
            {
                HitObjects    = new List <HitObject>(),
                ControlPoints = new List <ControlPoint>(),
                ComboColors   = new List <Color4>(),
                BeatmapInfo   = new BeatmapInfo
                {
                    Metadata       = new BeatmapMetadata(),
                    BaseDifficulty = new BaseDifficulty(),
                },
            };

            HitObjectParser parser = null;

            var    section = Section.None;
            string line;

            while (true)
            {
                line = stream.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.StartsWith(@"osu file format v"))
                {
                    continue;
                }

                if (line.StartsWith(@"[") && line.EndsWith(@"]"))
                {
                    if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
                    {
                        throw new InvalidDataException($@"Unknown osu section {line}");
                    }
                    continue;
                }

                string val = line, key = null;
                if (section != Section.Events && section != Section.TimingPoints && section != Section.HitObjects)
                {
                    key = val.Remove(val.IndexOf(':')).Trim();
                    val = val.Substring(val.IndexOf(':') + 1).Trim();
                }
                switch (section)
                {
                case Section.General:
                    handleGeneral(beatmap, key, val);
                    parser = Ruleset.GetRuleset(beatmap.BeatmapInfo.Mode).CreateHitObjectParser();
                    break;

                case Section.Editor:
                    handleEditor(beatmap, key, val);
                    break;

                case Section.Metadata:
                    handleMetadata(beatmap, key, val);
                    break;

                case Section.Difficulty:
                    handleDifficulty(beatmap, key, val);
                    break;

                case Section.Events:
                    handleEvents(beatmap, val);
                    break;

                case Section.TimingPoints:
                    handleTimingPoints(beatmap, val);
                    break;

                case Section.Colours:
                    handleColours(beatmap, key, val);
                    break;

                case Section.HitObjects:
                    var obj = parser?.Parse(val);

                    if (obj != null)
                    {
                        obj.SetDefaultsFromBeatmap(beatmap);
                        beatmap.HitObjects.Add(obj);
                    }
                    break;
                }
            }

            return(beatmap);
        }