Esempio n. 1
0
        public void AddToList(ref List <GameObjectData> list)
        {
            LineWriter.WriteLine("START PATH OUTLINE {{{{");
            GameObjectData obj;

            for (int i = 0; i < points.Length; i++)
            {
                Vector2 nextpoint = i + 1 >= points.Length ? points[0] : points[i + 1];
                Vector2 target    = nextpoint - points[i];
                target.Y    *= -1;
                obj          = new GameObjectData();
                obj.ID       = Program.GenerateID(1000).ToString();
                obj.colorNum = this.colorNum;
                obj.position = new Vector2(
                    points[i].X + (target.Normalize().X *outlineSize *Input.sizeMultiplier),
                    points[i].Y + (target.Normalize().Y *outlineSize *Input.sizeMultiplier)
                    );
                obj.size = new Vector2(
                    target.Magnitude(),                // Length of this part of the path
                    outlineSize * Input.sizeMultiplier // Size of outline
                    );
                obj.Shape    = Shapes.Square;
                obj.rotAngle = Custom.CustomMath.Rotations.GetRotationFromVector(
                    new Vector2(points[i].X, -points[i].Y),
                    new Vector2(nextpoint.X, -nextpoint.Y)
                    );
                obj.offset         = new Vector2(0.5f, 0);
                obj.isShapeUnknown = false;
                list.Add(obj);
                LineWriter.WriteLine(obj.ToString());
            }
            ;
            LineWriter.WriteLine("}}}}");
        }
Esempio n. 2
0
        static void XMLToGameObjectData(string _path, out List <GameObjectData> gameObjectsData, out List <PathOutline> pathOutlinesData)
        {
            gameObjectsData  = new List <GameObjectData>();
            pathOutlinesData = new List <PathOutline>();

            string      xml = File.ReadAllText(_path);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            var nodes = doc.LastChild.ChildNodes;

            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes.Item(i).Name == "g")
                {
                    nodes = nodes.Item(i).ChildNodes;
                }
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                var item = nodes.Item(i);
                if (isTypeConvertableToPAObject(item.Name))
                {
                    var  attributes = nodes.Item(i).Attributes;
                    bool isShapeNull;
                    gameObjectsData.Add(new GameObjectData()
                    {
                        ID             = GenerateID(999).ToString(),
                        Shape          = GetVarFromShapeName.Shape(item.Name, out isShapeNull),
                        offset         = GetVarFromShapeName.Offset(item.Name),
                        isShapeUnknown = isShapeNull
                    });
                    if (nodes.Item(i).Name == "path")
                    {
                        pathOutlinesData.Add(new PathOutline());
                    }
                    else
                    {
                        pathOutlinesData.Add(null);
                    }

                    GameObjectData obj = gameObjectsData[gameObjectsData.Count - 1];
                    PathOutline    pO  = pathOutlinesData[pathOutlinesData.Count - 1];
                    for (int a = 0; a < attributes.Count; a++)
                    {
                        LineWriter.WriteLine(attributes.Item(a).Name + ", " + attributes.Item(a).Value);
                        float valuef = GameObjectData.IsFloatAttribute(attributes.Item(a).Value) ? float.Parse(attributes.Item(a).Value) : 0;
                        DataAppliers.ApplyThisAttributeValue(ref obj, ref pO, attributes.Item(a).Name, attributes.Item(a).Value, valuef);
                    }
                    gameObjectsData[i]  = obj;
                    pathOutlinesData[i] = pO;
                }
                LineWriter.WriteLine("NEW OBJECT!! type:{" + item.Name + "}" + i);
            }
        }
Esempio n. 3
0
        public static void Process()
        {
            // XML -> GameObjectData[] {Custom Class}
            List <GameObjectData> gameObjectDataList;
            List <PathOutline>    pathOutlineList;

            XMLToGameObjectData(Input.svgPath, out gameObjectDataList, out pathOutlineList);

            foreach (var data in gameObjectDataList)
            {
                LineWriter.WriteLine(data.ToString());
            }
            foreach (var pathOutline in pathOutlineList)
            {
                if (pathOutline != null)
                {
                    pathOutline.AddToList(ref gameObjectDataList);
                }
            }

            for (int i = 0; i < gameObjectDataList.Count; i++)
            {
                if (gameObjectDataList[i].isShapeUnknown)
                {
                    gameObjectDataList.RemoveAt(i);
                    i--;
                }
            }
            foreach (var data in externalGameObjectDatas)
            {
                gameObjectDataList.Add(data);                                           // External GameObjects
            }
            // GameObjectData[] -> GameObject[]
            GameObject[] objects = gameObjectDataList.ToArray <GameObject>();

            // GameObject[] -> Prefab!
            PrefabBuilder pb = new PrefabBuilder(Input.prefabName, Input.prefabType, 0);

            for (int i = 0; i < objects.Length; i++)
            {
                if (objects[i] != null)
                {
                    objects[i].Bin   = i;
                    objects[i].Depth = 30 - i > -1 ? 30 - i : 0;
                    pb.Objects.Add(objects[i]);
                }
            }
            // Prefab -> Project Arrythmia!!
            pb.Export(Input.prefabPath);
        }
Esempio n. 4
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;
        }