Beispiel #1
0
        //Send line data to the right parse method
        private void parseLine(OsuFileSection section, string data)
        {
            switch (section)
            {
            case OsuFileSection.FORMAT:
                beatmap.FormatVersion = data;
                break;

            case OsuFileSection.GENERAL:
            case OsuFileSection.EDITOR:
            case OsuFileSection.METADATA:
            case OsuFileSection.DIFFICULTY:
                normalParse(data);
                break;

            case OsuFileSection.EVENTS:
                eventParse(data);
                break;

            case OsuFileSection.TIMINGPOINTS:
                timingPointParse(data);
                break;

            case OsuFileSection.COLOURS:
                colourParse(data);
                break;

            case OsuFileSection.HITOBJECTS:
                hitObjectParse(data);
                break;
            }
        }
Beispiel #2
0
        internal void parse(OsuFileSection sections)
        {
            //Read in file. Exceptions here are to be handled by the devs who use this library.
            string[] lines;
            try
            {
                lines = File.ReadAllLines(path);
            }
            catch (IOException)
            {
                throw;
            }

            //First line is always file format version
            OsuFileSection currentSection = OsuFileSection.FORMAT;

            foreach (string line in lines)
            {
                //Skip line if empty
                if (!string.IsNullOrWhiteSpace(line))
                {
                    //Test for new section, otherwise, parse normally.
                    OsuFileSection sectionTest = testNewSection(line);
                    if (sectionTest != OsuFileSection.NONE)
                    {
                        currentSection = sectionTest;
                    }
                    //If the currentSection is a member of sections (user-defined), parse it
                    else if ((currentSection & sections) == currentSection)
                    {
                        Debug.WriteLine("Parsing" + currentSection.ToString());
                        parseLine(currentSection, line);
                    }
                }
            }

            //Process default values (if they were not set)

            //General
            if (beatmap.PreviewTime == 0)
            {
                beatmap.PreviewTime = -1;
            }
            if (String.IsNullOrWhiteSpace(beatmap.SampleSet))
            {
                beatmap.SampleSet = "Normal";
            }
            if (beatmap.StackLeniency == 0)
            {
                beatmap.StackLeniency = 0.7f;
            }

            //Editor
            if (beatmap.DistanceSpacing == 0)
            {
                beatmap.DistanceSpacing = 1f;
            }
            if (beatmap.BeatDivisor == 0)
            {
                beatmap.BeatDivisor = 4;
            }
            if (beatmap.GridSize == 0)
            {
                beatmap.GridSize = 4;
            }
            if (beatmap.TimelineZoom == 0)
            {
                beatmap.TimelineZoom = 1;
            }

            //Difficulty
            if (beatmap.HpDrainRate == 0)
            {
                beatmap.HpDrainRate = 5f;
            }
            if (beatmap.CircleSize == 0)
            {
                beatmap.CircleSize = 5f;
            }
            if (beatmap.OverallDifficulty == 0)
            {
                beatmap.OverallDifficulty = 5f;
            }
            if (beatmap.ApproachRate == 0)
            {
                beatmap.ApproachRate = beatmap.OverallDifficulty;
            }
            if (beatmap.SliderMultiplier == 0)
            {
                beatmap.SliderMultiplier = 1.4f;
            }
            if (beatmap.SliderTickRate == 0)
            {
                beatmap.SliderTickRate = 1f;
            }

            Debug.WriteLine("osuBMParser: Finished beatmap parsing");
        }
        internal void parse(OsuFileSection sections)
        {

            //Read in file. Exceptions here are to be handled by the devs who use this library.
            string[] lines;
            try
            {
                lines = File.ReadAllLines(path);
            }
            catch (IOException)
            {
                throw;
            }

            //First line is always file format version
            OsuFileSection currentSection = OsuFileSection.FORMAT;

            foreach (string line in lines)
            {
                //Skip line if empty
                if (!string.IsNullOrWhiteSpace(line))
                {
                    //Test for new section, otherwise, parse normally.
                    OsuFileSection sectionTest = testNewSection(line);
                    if (sectionTest != OsuFileSection.NONE)
                    {
                        currentSection = sectionTest;
                    }
                    //If the currentSection is a member of sections (user-defined), parse it
                    else if ((currentSection & sections) == currentSection)
                    {
                        Debug.WriteLine("Parsing" + currentSection.ToString());
                        parseLine(currentSection, line);
                    }
                }
            }

            //Process default values (if they were not set)

            //General
            if (beatmap.PreviewTime == 0) beatmap.PreviewTime = -1;
            if (String.IsNullOrWhiteSpace(beatmap.SampleSet)) beatmap.SampleSet = "Normal";
            if (beatmap.StackLeniency == 0) beatmap.StackLeniency = 0.7f;

            //Editor
            if (beatmap.DistanceSpacing == 0) beatmap.DistanceSpacing = 1f;
            if (beatmap.BeatDivisor == 0) beatmap.BeatDivisor = 4;
            if (beatmap.GridSize == 0) beatmap.GridSize = 4;
            if (beatmap.TimelineZoom == 0) beatmap.TimelineZoom = 1;

            //Difficulty
            if (beatmap.HpDrainRate == 0) beatmap.HpDrainRate = 5f;
            if (beatmap.CircleSize == 0) beatmap.CircleSize = 5f;
            if (beatmap.OverallDifficulty == 0) beatmap.OverallDifficulty = 5f;
            if (beatmap.ApproachRate == 0) beatmap.ApproachRate = beatmap.OverallDifficulty;
            if (beatmap.SliderMultiplier == 0) beatmap.SliderMultiplier = 1.4f;
            if (beatmap.SliderTickRate == 0) beatmap.SliderTickRate = 1f;

            Debug.WriteLine("osuBMParser: Finished beatmap parsing");

        }
 //Send line data to the right parse method
 private void parseLine(OsuFileSection section, string data)
 {
     switch (section)
     {
         case OsuFileSection.FORMAT:
             beatmap.FormatVersion = data;
             break;
         case OsuFileSection.GENERAL:
         case OsuFileSection.EDITOR:
         case OsuFileSection.METADATA:
         case OsuFileSection.DIFFICULTY:
             normalParse(data);
             break;
         case OsuFileSection.TIMINGPOINTS:
             timingPointParse(data);
             break;
         case OsuFileSection.COLOURS:
             colourParse(data);
             break;
         case OsuFileSection.HITOBJECTS:
             hitObjectParse(data);
             break;
     }
 }