Пример #1
0
 public static void PathOutline(ref PathOutline obj, string nextVal)
 {
     obj = new PathOutline();
     float[]   xArray;
     float[]   yArray;
     Vector2[] points;
     CustomConversions.DPathToPoints(nextVal, out xArray, out yArray, out points);
     obj.points = points;
 }
Пример #2
0
        public static void translate(ref GameObjectData obj, string nextVal)
        {
            string[] vals = nextVal.Split('(', ')', ','); // Questioning if i should split for empty spaces..
            if (vals[0] == "matrix")
            {
                float[] matrix = new float[vals.Length - 1];

                for (int i = 1; i < vals.Length - 1; i++)
                {
                    matrix[i - 1] = float.Parse(vals[i]);
                }
                Vector2 posDelta, size, skew = Vector2.Zero;
                CustomConversions.GetVarsFromMatrix(matrix, out posDelta, out size, out skew);
                //float rotation;



                // Consider making the offset center and push everything by 0.5?
                obj.offset = Vector2.Zero;
                //
                obj.position += new Vector2(0.5f, 0);
                obj.rotAngle  = -45;

                // This parent rotates the object correctly depending on its skew value
                var parent = new GameObjectData();
                parent.size     = new Vector2(skew.X / 90f, skew.Y / 90f);
                parent.rotAngle = CustomMath.Matrix.GetRotationDegFromSkewDeg(skew.X > skew.Y ? skew.X : skew.Y);
                // This parent flips the object on axis if needed.
                parent.MakeParent(new GameObjectData()
                {
                    sizeX = size.X < 0? -1 : 1,
                    sizeY = size.Y < 0? -1 : 1
                });
                obj.MakeParent(parent);
            }
            else if (vals[0] == "rotate")
            {
                obj.rotAngle = float.Parse(vals[1]);
            }
        }
Пример #3
0
        public static void D(ref GameObjectData obj, string nextVal, out Shapes?shape)
        {
            shape = null;

            float[]   xArray; // Array of X values
            float[]   yArray; // Array of Y values
            Vector2[] points; // Array of points
            CustomConversions.DPathToPoints(nextVal, out xArray, out yArray, out points);

            float SizeMultiplier = 1;

            // Analyze the number of points. We multiply by two because its split up by float, not by vector / float[2] then add two because of [M x y]
            switch (points.Length)
            {
            case 3:
                shape          = Shapes.Triangle;
                SizeMultiplier = 2;
                break;

            case 4: shape = Shapes.Square; break;

            case 6: shape = Shapes.Hexagon; break;
            }

            // Get min and max
            float[] min = new float[] { xArray.Min(), yArray.Min() }; // float[2]
            float[] max = new float[] { xArray.Max(), yArray.Max() }; // float[2]

            // Get center and size
            float[] center = CustomMath.GetCenter(min, max);

            // Everything with final means its been rotated.
            Vector2[] finalPoints;
            float     finalRotation;
            bool      isRightTriangle;

            CustomMath.Rotations.GetRotatedShape(1f, CustomConversions.Float2ToVect(center), points, out finalPoints, out finalRotation, out isRightTriangle);

            if (isRightTriangle && points.Length == 3)
            {
                obj.isRightTriangle = true;
                obj.ShapeVariant    = 2;
            }

            float[] finalXPoints = CustomConversions.VectIndexToFloatList(0, finalPoints);
            float[] finalYPoints = CustomConversions.VectIndexToFloatList(1, finalPoints);

            float[] finalMin = new float[] { finalXPoints.Min(), finalYPoints.Min() }; // float[2]
            float[] finalMax = new float[] { finalXPoints.Max(), finalYPoints.Max() }; // float[2]

            float[] finalSize = CustomMath.GetSize(finalMin, finalMax);                // float[2]
            // Questioning if I should use Vector or Point instead of float[2]

            LineWriter.WriteLine(center[0]);
            LineWriter.WriteLine(center[1]);
            LineWriter.WriteLine(finalSize[0]);
            LineWriter.WriteLine(finalSize[1]);

            // Apply center and size
            obj.position = new Vector2(
                center[0],
                center[1]
                );
            obj.size = new Vector2(
                finalSize[0] * SizeMultiplier,
                finalSize[1] * SizeMultiplier
                );
            obj.rotAngle = finalRotation;
        }
Пример #4
0
 public ConfigurationReader SetupCustomConverter <T>(Func <string, T> conversion)
 {
     CustomConversions.Add(typeof(T), source => conversion(source) as object);
     return(this);
 }