Ejemplo n.º 1
0
        private void hitObjectParse(string data)
        {
            string[] tokens = data.Split(',');

            if (tokens.Length < 5)
            {
                Debug.WriteLine("osuBMParser: Invalid HitObject line, no further information available");
                return; //Not possible to have less arguments than this
            }

            //Create bit array for checking type
            BitArray typeBitArray = new BitArray(new int[] { toInt(tokens[3]) });

            bool[] typeBits = new bool[typeBitArray.Count];
            typeBitArray.CopyTo(typeBits, 0);

            //Create hitObject of correct type
            HitObject hitObject = null;

            if (typeBits[0])
            {
                hitObject = new HitCircle();
            }
            else if (typeBits[1])
            {
                hitObject = new HitSlider();
            }
            else if (typeBits[3])
            {
                hitObject = new HitSpinner();
            }
            else
            {
                Debug.WriteLine("osuBMParser: Invalid HitObject line at timestamp: " + tokens[2] + " | Type = " + tokens[3]);
                return; //This type does not exist
            }

            //Parse all information for the hitObject

            //Global stuff first
            hitObject.Position = new Vector2(toFloat(tokens[0]), toFloat(tokens[1]));
            hitObject.Time     = toInt(tokens[2]);
            //hitObject.HitSound = toInt(tokens[4]);
            hitObject.IsNewCombo = typeBits[2];

            //Specific stuff

            if (hitObject is HitCircle)
            {
                if (tokens.Length >= 6 && tokens[5] != null) //Additions
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[5]));
                }
            }

            if (hitObject is HitSlider)
            {
                if (tokens.Length >= 6 && tokens[5] != null) //SliderType and HitSliderSegments
                {
                    string[] hitSliderSegments = tokens[5].Split('|');
                    ((HitSlider)hitObject).Type = HitSlider.parseSliderType(hitSliderSegments[0]);
                    foreach (string hitSliderSegmentPosition in hitSliderSegments.Skip(1))
                    {
                        string[] positionTokens = hitSliderSegmentPosition.Split(':');
                        if (positionTokens.Length == 2)
                        {
                            ((HitSlider)hitObject).HitSliderSegments.Add(new HitSliderSegment(new Vector2(toFloat(positionTokens[0]), toFloat(positionTokens[1]))));
                        }
                    }
                }

                if (tokens.Length >= 7 && tokens[6] != null)
                {
                    ((HitSlider)hitObject).Repeat = toInt(tokens[6]);
                }

                if (tokens.Length >= 8 && tokens[7] != null)
                {
                    ((HitSlider)hitObject).PixelLength = toFloat(tokens[7]);
                }

                if (tokens.Length >= 9 && tokens[8] != null)
                {
                    //((HitSlider)hitObject).EdgeHitSound = toInt(tokens[8]);
                }

                if (tokens.Length >= 10 && tokens[9] != null)
                {
                    //((HitSlider)hitObject).EdgeAddition = new List<int>(getAdditionsAsIntArray(tokens[9]));
                }

                if (tokens.Length >= 11 && tokens[10] != null)
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[10]));
                }
            }

            if (hitObject is HitSpinner)
            {
                if (tokens.Length >= 6 && tokens[5] != null)
                {
                    ((HitSpinner)hitObject).EndTime = toInt(tokens[5]);
                }

                if (tokens.Length >= 7 && tokens[6] != null)
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[6]));
                }
            }

            beatmap.HitObjects.Add(hitObject);
        }
Ejemplo n.º 2
0
        private void hitObjectParse(string data)
        {

            string[] tokens = data.Split(',');

            if (tokens.Length < 5)
            {
                Debug.WriteLine("osuBMParser: Invalid HitObject line, no further information available");
                return; //Not possible to have less arguments than this
            }

            //Create bit array for checking type
            BitArray typeBitArray = new BitArray(new int[] { toInt(tokens[3]) });
            bool[] typeBits = new bool[typeBitArray.Count];
            typeBitArray.CopyTo(typeBits, 0);

            //Create hitObject of correct type
            HitObject hitObject = null;

            if (typeBits[0])
            {
                hitObject = new HitCircle();
            }
            else if (typeBits[1])
            {
                hitObject = new HitSlider();
            }
            else if (typeBits[3])
            {
                hitObject = new HitSpinner();
            }
            else
            {
                Debug.WriteLine("osuBMParser: Invalid HitObject line at timestamp: " + tokens[2] + " | Type = " + tokens[3]);
                return; //This type does not exist
            }

            //Parse all information for the hitObject

            //Global stuff first
            hitObject.Position = new Vector2(toFloat(tokens[0]), toFloat(tokens[1]));
            hitObject.Time = toInt(tokens[2]);
            //hitObject.HitSound = toInt(tokens[4]);
            hitObject.IsNewCombo = typeBits[2];

            //Specific stuff

            if (hitObject is HitCircle)
            {

                if (tokens.Length >= 6 && tokens[5] != null) //Additions
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[5]));
                }

            }

            if (hitObject is HitSlider)
            {

                if (tokens.Length >= 6 && tokens[5] != null) //SliderType and HitSliderSegments
                {
                    string[] hitSliderSegments = tokens[5].Split('|');
                    ((HitSlider)hitObject).Type = HitSlider.parseSliderType(hitSliderSegments[0]);
                    foreach (string hitSliderSegmentPosition in hitSliderSegments.Skip(1))
                    {
                        string[] positionTokens = hitSliderSegmentPosition.Split(':');
                        if (positionTokens.Length == 2)
                        {
                            ((HitSlider)hitObject).HitSliderSegments.Add(new HitSliderSegment(new Vector2(toFloat(positionTokens[0]), toFloat(positionTokens[1]))));
                        }
                    }
                }

                if (tokens.Length >= 7 && tokens[6] != null)
                {
                    ((HitSlider)hitObject).Repeat = toInt(tokens[6]);
                }

                if (tokens.Length >= 8 && tokens[7] != null)
                {
                    ((HitSlider)hitObject).PixelLength = toFloat(tokens[7]);
                }

                if (tokens.Length >= 9 && tokens[8] != null)
                {
                    //((HitSlider)hitObject).EdgeHitSound = toInt(tokens[8]);
                }

                if (tokens.Length >= 10 && tokens[9] != null)
                {
                    //((HitSlider)hitObject).EdgeAddition = new List<int>(getAdditionsAsIntArray(tokens[9]));
                }

                if (tokens.Length >= 11 && tokens[10] != null)
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[10]));
                }

            }

            if (hitObject is HitSpinner)
            {

                if (tokens.Length >= 6 && tokens[5] != null)
                {
                    ((HitSpinner)hitObject).EndTime = toInt(tokens[5]);
                }

                if (tokens.Length >= 7 && tokens[6] != null)
                {
                    //hitObject.Addition = new List<int>(getAdditionsAsIntArray(tokens[6]));
                }

            }

            beatmap.HitObjects.Add(hitObject);

        }