示例#1
0
        public static HitObject Parse(string line)
        {
            var parts      = line.Split(Constants.Splitter.Comma, StringSplitOptions.RemoveEmptyEntries);
            var position   = Position.FromHitobject(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]));
            var time       = Convert.ToInt32(parts[2]);
            var type       = (HitObjectType)Convert.ToInt32(parts[3]);
            var isNewCombo = type.IsType(HitObjectType.NewCombo);
            var hitsound   = (HitObjectSoundType)Convert.ToInt32(parts[4]);


            if (type.IsType(HitObjectType.HitCircle)) //Make HitCircle
            {
                var h = new HitCircle(position, time, isNewCombo, type, hitsound);
                if (parts.Length > 5)
                {
                    GetAdditions(parts[5], h);
                }
                return(h);
            }
            if (type.IsType(HitObjectType.Spinner))
            {
                //Make Spinner
                var sp = new Spinner(position, time, int.Parse(parts[5]), isNewCombo, hitsound);
                if (parts.Length > 6)
                {
                    GetAdditions(parts[6], sp);
                }
                return(sp);
            }
            if (type.IsType(HitObjectType.HoldCircle))
            {
                //Make HoldCircle
                //float endtime = parts[5]
                var hc = new HoldCircle(position, time, int.Parse(parts[5]), isNewCombo, type, hitsound);
                if (parts.Length > 6)
                {
                    GetAdditions(parts[6], hc);
                }
                return(hc);
            }
            if (!type.IsType(HitObjectType.Slider))
            {
                return(null);
            }
            var s      = new Slider(position, time, isNewCombo, type, hitsound);
            var repeat = Convert.ToInt32(parts[6]);
            var length = Convert.ToDouble(parts[7], Constants.IO.CULTUREINFO);

            s.SegmentCount = repeat;
            s.Length       = length;
            var        points = parts[5].Split(Constants.Splitter.Pipe);
            SliderType sliderType;

            switch (points[0])
            {
            case "C":
                sliderType = SliderType.Catmull;
                break;

            case "B":
                sliderType = SliderType.Bezier;
                break;

            case "L":
                sliderType = SliderType.Linear;
                break;

            case "P":
                sliderType = SliderType.PerfectCurve;
                break;

            default:
                sliderType = SliderType.Linear;
                break;
            }
            s.SliderType = sliderType;
            var pointPositions = new Position[points.Length];

            pointPositions[0] = s.StartPosition;
            for (var i = 1; i < points.Length; i++)
            {
                var p = points[i].Split(Constants.Splitter.Colon).Select(int.Parse).ToArray();
                pointPositions[i] = Position.FromHitobject(p[0], p[1]);
            }
            s.ControlPoints = pointPositions;
            var pointHitsounds = Enumerable.Range(1, repeat + 1).Select(i => new Slider.PointHitsound()).ToList();

            if (parts.Length > 8)
            {
                var soundTypeParts = parts[8].Split(Constants.Splitter.Pipe);
                var soundTypeCount = soundTypeParts.Length;
                for (int i = 0; i < repeat + 1; i++)
                {
                    if (i > soundTypeCount)
                    {
                        break;
                    }
                    pointHitsounds[i].SoundType = (HitObjectSoundType)int.Parse(soundTypeParts[i]);
                }
                var sampleParts = parts[9].Split(Constants.Splitter.Pipe);
                var sampleCount = sampleParts.Length;
                for (var i = 0; i < repeat + 1; i++)
                {
                    if (i >= sampleCount)
                    {
                        break;
                    }
                    var sampleSplit = sampleParts[i].Split(':');
                    pointHitsounds[i].SampleSet         = (SampleSet)int.Parse(sampleSplit[0]);
                    pointHitsounds[i].AdditionSampleSet = (SampleSet)int.Parse(sampleSplit[1]);
                }
                s.PointHitsounds = pointHitsounds;
                if (parts.Length > 9)
                {
                    GetAdditions(parts[10], s);
                }
            }
            return(s);
        }
示例#2
0
        public static HitObject Parse(string line)
        {
            var parts      = line.Split(','.AsArray(), StringSplitOptions.RemoveEmptyEntries);
            var position   = Position.FromHitobject(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1]));
            var time       = Convert.ToInt32(parts[2]);
            var type       = (HitObjectType)Convert.ToInt32(parts[3]);
            var isNewCombo = type.IsType(HitObjectType.NewCombo);
            var hitsound   = (HitObjectSoundType)Convert.ToInt32(parts[4]);

            if (type.IsType(HitObjectType.HitCircle)) //Make HitCircle
            {
                var h = new HitCircle(position, time, isNewCombo, type, hitsound);
                if (parts.Length > 5)
                {
                    GetAdditions(parts[5], h);
                }
                return(h);
            }
            if (type.IsType(HitObjectType.Spinner))
            {
                //Make Spinner
                var sp = new Spinner(position, time, int.Parse(parts[5]), type, hitsound);
                if (parts.Length > 6)
                {
                    GetAdditions(parts[6], sp);
                }
                return(sp);
            }
            if (type.IsType(HitObjectType.HoldCircle))
            {
                //Make HoldCircle
                var hc = new HoldCircle(position, time, time, isNewCombo, type, hitsound);
                if (parts.Length < 6)
                {
                    return(hc);
                }

                var endstring      = parts[5];
                var endstringparts = endstring.Split(':'.AsArray(), StringSplitOptions.RemoveEmptyEntries);
                hc.EndTime = int.Parse(endstringparts[0]);
                GetAdditions(endstring.Substring(endstring.IndexOf(':')), hc);

                return(hc);
            }
            if (!type.IsType(HitObjectType.Slider))
            {
                return(null);
            }
            var s = new Slider(position, time, isNewCombo, type, hitsound);
            //type and points
            var        points = parts[5].Split('|');
            SliderType sliderType;

            switch (points[0])
            {
            case "C":
                sliderType = SliderType.Catmull;
                break;

            case "B":
                sliderType = SliderType.Bezier;
                break;

            case "L":
                sliderType = SliderType.Linear;
                break;

            case "P":
                sliderType = SliderType.PerfectCurve;
                break;

            default:
                sliderType = SliderType.Linear;
                break;
            }
            s.SliderType = sliderType;
            var pointPositions = new Position[points.Length];

            pointPositions[0] = s.StartPosition;
            for (var i = 1; i < points.Length; i++)
            {
                var p = points[i].Split(':').Select(int.Parse).ToArray();
                pointPositions[i] = Position.FromHitobject(p[0], p[1], false);
            }
            s.ControlPoints = pointPositions;
            //repeat count
            s.SegmentCount = int.Parse(parts[6]);
            var pointcount = s.SegmentCount + 1;

            //length
            if (parts.Length > 7)
            {
                s.Length = Convert.ToDouble(parts[7], Constants.CULTUREINFO);
            }
            //hitsounds
            var pointHitsounds = Enumerable.Range(1, pointcount).Select(i => new Slider.PointHitsound()).ToList();

            if (parts.Length < 9)
            {
                return(s);
            }
            var soundTypeParts = parts[8].Split('|');

            for (var i = 0; i < pointcount + 1; i++)
            {
                if (i >= soundTypeParts.Length)
                {
                    break;
                }
                pointHitsounds[i].SoundType = (HitObjectSoundType)int.Parse(soundTypeParts[i]);
            }
            s.PointHitsounds = pointHitsounds;
            //point samplesets
            if (parts.Length < 10)
            {
                return(s);
            }
            var sampleParts = parts[9].Split('|');

            for (var i = 0; i < pointcount + 1; i++)
            {
                if (i >= sampleParts.Length)
                {
                    break;
                }
                var sampleSplit = sampleParts[i].Split(':');
                pointHitsounds[i].SampleSet         = (SampleSet)int.Parse(sampleSplit[0]);
                pointHitsounds[i].AdditionSampleSet = (SampleSet)int.Parse(sampleSplit[1]);
            }
            //slider samplesets
            if (parts.Length > 10)
            {
                GetAdditions(parts[10], s);
            }
            return(s);
        }