예제 #1
0
파일: Slider.cs 프로젝트: Austech/OsuBot
        protected override void Parse(System.IO.StreamReader reader, string line)
        {
            if (line != null)
            {
                string curveData = "";
                if (line.Contains("B|"))
                {
                    curveData = line.Substring(line.IndexOf(',', line.IndexOf("B|") - 1));
                }
                else if (line.Contains("C|"))
                {
                    curveData = line.Substring(line.IndexOf(',', line.IndexOf("C|") - 1));
                }
                else if (line.Contains("|"))
                {
                    curveData = line.Substring(line.IndexOf(',', line.IndexOf("|") - 2));
                }
                int points = curveData.Count(f => f == ':');
                double[] data = Parsers.NumbersFromString.Parse(curveData);

                WinAPI.POINT startPoint = new WinAPI.POINT();
                startPoint.x = HitData.X;
                startPoint.y = HitData.Y;
                m_points.Add(startPoint);

                for (int i = 0; i < points; i++)
                {
                    WinAPI.POINT point = new WinAPI.POINT();
                    point.x = (int)data[i * 2];
                    point.y = (int)data[i * 2 + 1];
                    m_points.Add(point);
                }

                m_useCount = (int)data[(points * 2)];
                m_distance = (int)data[(points * 2) + 1];

                double[] dPoints = new double[m_points.Count * 2];
                for (int i = 0; i < m_points.Count; i++)
                {
                    dPoints[i * 2] = m_points[i].x;
                    dPoints[i * 2 + 1] = m_points[i].y;
                }

                double[] dCurvePoints = new double[dPoints.Length];
                Curves.BezierCurve bCurve = new Curves.BezierCurve();
                bCurve.Bezier2D(dPoints, m_points.Count, dCurvePoints);

                for (int i = 0; i < dCurvePoints.Length / 2; i++)
                {
                    WinAPI.POINT point = new WinAPI.POINT();
                    point.x = (int)dCurvePoints[i * 2];
                    point.y = (int)dCurvePoints[i * 2 + 1];
                    m_curvePoints.Add(point);
                }

                for (int i = 0; i < m_curvePoints.Count; i++)
                {
                    if (i > 0)
                    {
                        int disX = Math.Abs(m_curvePoints[i].x) - Math.Abs(m_curvePoints[i - 1].x);
                        int disY = Math.Abs(m_curvePoints[i].y) - Math.Abs(m_curvePoints[i - 1].y);
                        float add = (float)Math.Sqrt((disX * disX) + (disY * disY));
                        m_totalDistance += add;
                    }
                }
            }
        }