XElement addObjectsFromObjectContainers(XElement el, ShipImplementation ship, string parentid, string layerid)
        {
            XElement Object = el;

            layerid = Guid.NewGuid().ToString();
            foreach (ObjectContainer oc in ship.objectContainers)
            {
                foreach (PrefabObject po in oc.prefabObjects)
                {
                    if (po.Geometry != null)
                    {
                        string   layername = oc.name;
                        XElement obj1      = new XElement("Object");
                        string   entid     = genID();
                        string   prefid    = genID();

                        obj1.Add(new XAttribute("Name", po.Name));
                        obj1.Add(new XAttribute("LinkedTo", parentid));
                        obj1.Add(new XAttribute("Id", entid));
                        obj1.Add(new XAttribute("LayerGUID", layerid));
                        obj1.Add(new XAttribute("Geometry", po.Geometry));
                        obj1.Add(new XAttribute("AttachmentType", "CharacterBone"));
                        obj1.Add(new XAttribute("AttachmentTarget", oc.portName));
                        obj1.Add(new XAttribute("Layer", "Main"));
                        if (po.Pos != null)
                        {
                            obj1.Add(new XAttribute("Pos", po.Pos));
                        }
                        if (po.Rotate != null)
                        {
                            obj1.Add(new XAttribute("Rotate", po.Rotate));
                        }
                        obj1.Add(new XAttribute("Type", "GeomEntity"));
                        obj1.Add(new XAttribute("EntityClass", "GeomEntity"));
                        obj1.Add(new XAttribute("LodRatio", "10"));

                        XElement Components = new XElement("Components");
                        XElement Component  = new XElement("Component");
                        Component.Add(new XAttribute("typeId", "ec0cd266-a6d1-4774-b499-690bd6fb61ee"));
                        Component.Add(new XAttribute("guid", genID()));
                        Component.Add(new XAttribute("CryXmlVersion", "2"));
                        Component.Add(new XAttribute("Geometry", po.Geometry));
                        Component.Add(new XAttribute("Physicalize", "ePhysicalizationType_Static"));
                        Component.Add(new XAttribute("ReceiveCollisionEvents", "false"));
                        Component.Add(new XAttribute("Mass", "1"));
                        Component.Add(new XAttribute("Animation", ""));
                        Component.Add(new XAttribute("Speed", "1"));
                        Component.Add(new XAttribute("Loop", "true"));
                        Components.Add(Component);
                        obj1.Add(Components);
                        Object.Add(obj1);
                    }
                }
            }

            return(Object);
        }
        public List <AttachmentPoint> GetAllAttachmentPoints(ShipImplementation shipp)
        {
            List <AttachmentPoint> attPoints = new List <AttachmentPoint>();

            //foreach (shipp.)
            //{
            //    attPoints.Add();
            //}
            return(attPoints);
        }
Ejemplo n.º 3
0
        void LoadShipImplementation(string path)
        {
            string filePath   = "./data/" + path;
            string fileFolder = Path.GetDirectoryName(filePath);

            if (File.Exists(filePath))
            {
                XDocument xmlDoc = XDocumentHelper.Load(filePath);
                shipImplementation = new ShipImplementation(xmlDoc, fileFolder, itemsList);
            }
        }
Ejemplo n.º 4
0
        public ShipImplementation GetShipImplementation(string shipname)
        {
            ShipImplementation ship = null;

            foreach (ShipImplementation sp in shipsImplementations)
            {
                if (sp.name == shipname)
                {
                    ship = sp;
                }
            }
            return(ship);
        }
Ejemplo n.º 5
0
        static string PromtPaints(ShipImplementation ship)
        {
            string selectedPaint = null;

            if (ship.paints.Count > 0)
            {
                Console.WriteLine("Available paints:");
                foreach (Paint pt in ship.paints)
                {
                    Console.WriteLine("{0}|{1}", pt.name, pt.material);
                }
                Console.WriteLine("Enter paint name:");
                selectedPaint = Convert.ToString(Console.ReadLine()).Trim();
            }
            return(selectedPaint);
        }
        public XDocument generateShip(string shipName)
        {
            //shipName = "AEGS_Gladius";
            XDocument xml         = new XDocument();
            string    loadoutName = "Default_Loadout_" + shipName;

            XElement PrefabsLibrary = new XElement("PrefabsLibrary");

            //PrefabsLibrary.Attribute("Name").Value = shipName+"_Ship";
            //PrefabsLibrary.Add(new XAttribute("Name", shipName + "_Ship"));
            PrefabsLibrary.Add(new XAttribute("Name", shipName));

            XElement Prefab   = new XElement("Prefab");
            string   prefabId = genPrefabID();

            //Prefab.Add(new XAttribute("Name", shipName));
            Prefab.Add(new XAttribute("Name", "Ship"));
            Prefab.Add(new XAttribute("Id", prefabId));
            // Prefab.Add(new XAttribute("Library", shipName + "_Ship"));
            Prefab.Add(new XAttribute("Library", shipName));

            XElement Objects = new XElement("Objects");

            ShipImplementation ship    = exporter.GetShipImplementation(shipName);
            Loadout            loadout = exporter.GetLoadout(loadoutName);

            Console.WriteLine(loadout.name);


            XElement Object   = new XElement("Object");
            string   partid   = genID();
            string   layerid  = genID();
            string   parentid = "0";

            parentid = partid;

            Object = addObjects(Object, ship.parts.First(), loadout, parentid, partid, layerid);
            //Object = addPrefabsFromObjectContainers(Object, ship, parentid, layerid);
            Object = addObjectsFromObjectContainers(Object, ship, parentid, layerid);

            if (Object.Attribute("Name") != null)
            {
                Objects.Add(Object);
            }
            //Objects.Add(Object);

            XElement ObjectsNew = new XElement("Objects");

            foreach (XElement obj in Objects.Descendants("Object"))
            {
                XElement ObjectNew = new XElement("Object");
                ObjectNew.Add(new XElement("Properties"));
                foreach (XAttribute atr in obj.Attributes())
                {
                    ObjectNew.Add(atr);
                }
                if (obj.Element("Components") != null)
                {
                    ObjectNew.Add(obj.Element("Components"));
                }

                if (ObjectNew.Attribute("Name") != null)
                {
                    ObjectsNew.Add(ObjectNew);
                }
            }

            Prefab.Add(ObjectsNew);
            PrefabsLibrary.Add(Prefab);
            foreach (XElement pr in prefabs)
            {
                PrefabsLibrary.Add(pr);
            }
            xml.Add(PrefabsLibrary);

            //XDocument xmlpreflib = XDocument.Load(prefablib);
            //XElement preflibel = xmlpreflib.Element("PrefabsLibrary");
            //xml.Add(preflibel);

            return(xml);
        }
        XElement addPrefabsFromObjectContainers(XElement el, ShipImplementation ship, string parentid, string layerid)
        {
            XElement Object = el;

            layerid = Guid.NewGuid().ToString();
            foreach (ObjectContainer oc in ship.objectContainers)
            {
                string layername = oc.name;
                //layerid = stringToNumbers(layername);
                //Console.WriteLine(at.name);
                XElement obj1   = new XElement("Object");
                string   entid  = genID();
                string   prefid = genID();
                obj1.Add(new XAttribute("Type", "Entity"));
                obj1.Add(new XAttribute("Name", oc.portName));
                obj1.Add(new XAttribute("LinkedTo", parentid));
                obj1.Add(new XAttribute("Id", entid));
                obj1.Add(new XAttribute("LayerGUID", layerid));
                obj1.Add(new XAttribute("AttachmentType", "CharacterBone"));
                obj1.Add(new XAttribute("AttachmentTarget", oc.portName));
                obj1.Add(new XAttribute("Layer", layername));
                obj1.Add(new XAttribute("EntityClass", "FlowgraphEntity"));
                Object.Add(obj1);

                //PrefabAttachment prefabAtt = item.getAttachment(at.name);
                //XElement obj2 = getPrefab(prefabAtt.prefabLibrary, prefabAtt.prefabName);
                XElement obj2          = new XElement("Object");
                string   id            = genID();
                string   prefablibname = ship.name;
                obj2.Add(new XAttribute("Type", "Prefab"));
                obj2.Add(new XAttribute("Name", oc.name));
                obj2.Add(new XAttribute("LinkedTo", entid));
                obj2.Add(new XAttribute("Id", id));
                obj2.Add(new XAttribute("LayerGUID", layerid));
                obj2.Add(new XAttribute("Layer", layername));
                obj2.Add(new XAttribute("PrefabGUID", prefid));
                obj2.Add(new XAttribute("PrefabLibrary", prefablibname));
                obj2.Add(new XAttribute("PrefabName", "ObjectContainers." + oc.name));
                //prefablib = prefabAtt.prefabLibrary;
                prefabs.Add(oc.GetAsPrefab(prefablibname, layerid, prefid, layername));
                Object.Add(obj2);

                foreach (Child child in oc.childs)
                {
                    ObjectContainer ocChild = child.Soc;
                    prefid = genID();
                    XElement obj3           = new XElement("Object");
                    string   id2            = genID();
                    string   prefablibname2 = ship.name;
                    obj3.Add(new XAttribute("Type", "Prefab"));
                    obj3.Add(new XAttribute("Name", ocChild.name));
                    obj3.Add(new XAttribute("LinkedTo", entid));
                    obj3.Add(new XAttribute("Id", id2));
                    obj3.Add(new XAttribute("LayerGUID", layerid));
                    obj3.Add(new XAttribute("Layer", layername));
                    obj3.Add(new XAttribute("PrefabGUID", prefid));
                    obj3.Add(new XAttribute("PrefabLibrary", prefablibname2));
                    obj3.Add(new XAttribute("PrefabName", "ObjectContainers." + ocChild.name));
                    //prefablib = prefabAtt.prefabLibrary;
                    prefabs.Add(ocChild.GetAsPrefab(prefablibname2, layerid, prefid, layername));
                    Object.Add(obj3);
                }
            }
            return(Object);
        }
        public XDocument GenerateShipOLD(GenerateOptions genOptions)
        {
            string             shipName = genOptions.shipName;
            ShipImplementation ship     = exporter.GetShipImplementation(shipName);
            Paint paint = ship.GetPaintByName(genOptions.paintName);
            //shipName = "AEGS_Gladius";
            XDocument xml         = new XDocument();
            string    loadoutName = null;

            if (genOptions.loadoutName != null)
            {
                loadoutName = genOptions.loadoutName;
            }
            else
            {
                loadoutName = "Default_Loadout_" + shipName;
            }

            string prefLibName = "";

            if (paint != null)
            {
                prefLibName = shipName + "-" + paint.name;
            }
            else
            {
                prefLibName = shipName;
            }
            prefLibName = "ships/" + prefLibName;
            XElement PrefabsLibrary = new XElement("PrefabsLibrary");

            //PrefabsLibrary.Attribute("Name").Value = shipName+"_Ship";
            //PrefabsLibrary.Add(new XAttribute("Name", shipName + "_Ship"));
            PrefabsLibrary.Add(new XAttribute("Name", prefLibName));

            XElement Prefab   = new XElement("Prefab");
            string   prefabId = GuidUtility.GenPrefabID(prefLibName);

            //Prefab.Add(new XAttribute("Name", shipName));
            Prefab.Add(new XAttribute("Name", "Ship"));
            Prefab.Add(new XAttribute("Id", prefabId));
            // Prefab.Add(new XAttribute("Library", shipName + "_Ship"));
            Prefab.Add(new XAttribute("Library", prefLibName));

            XElement Objects = new XElement("Objects");


            Loadout loadout = exporter.GetLoadout(loadoutName);

            Console.WriteLine(loadout.name);


            XElement Object = new XElement("Object");
            //string partid = GuidUtility.GenID("jhk777gt" + shipName  );
            //string layerid = GuidUtility.GenID("ghjg557kk" + shipName  );
            string partid   = GuidUtility.GenID();
            string layerid  = GuidUtility.GenID();
            string parentid = "0";

            parentid = partid;

            Object = AddObjects(Object, ship.parts.First(), loadout, parentid, partid, layerid, paint);
            i      = 0;
            //Object = AddPrefabsFromObjectContainers(Object, ship, parentid, layerid);
            Object = AddObjectsFromObjectContainers(Object, ship.objectContainers, parentid, layerid);

            if (Object.Attribute("Name") != null)
            {
                Objects.Add(Object);
            }
            //Objects.Add(Object);

            XElement ObjectsNew = new XElement("Objects");

            foreach (XElement obj in Objects.Descendants("Object"))
            {
                XElement ObjectNew = new XElement("Object");
                //ObjectNew.Add(new XElement("Properties"));
                if (obj.Element("Properties") != null)
                {
                    ObjectNew.Add(obj.Element("Properties"));
                }
                foreach (XAttribute atr in obj.Attributes())
                {
                    ObjectNew.Add(atr);
                }
                if (obj.Element("Components") != null)
                {
                    ObjectNew.Add(obj.Element("Components"));
                }

                if (obj.Element("Points") != null)
                {
                    ObjectNew.Add(obj.Element("Points"));
                }

                if (ObjectNew.Attribute("Name") != null)
                {
                    ObjectsNew.Add(ObjectNew);
                }
            }

            Prefab.Add(ObjectsNew);
            PrefabsLibrary.Add(Prefab);
            foreach (XElement pr in prefabs)
            {
                PrefabsLibrary.Add(pr);
            }
            xml.Add(PrefabsLibrary);

            //XDocument xmlpreflib = XDocument.Load(prefablib);
            //XElement preflibel = xmlpreflib.Element("PrefabsLibrary");
            //xml.Add(preflibel);

            return(xml);
        }
        public XDocument GenerateShip(ShipDefinition ship)
        {
            XDocument          xml                = new XDocument();
            string             shipName           = ship.GetShipName();
            ShipImplementation shipImplementation = ship.GetShipImplementation();

            if (shipImplementation != null)
            {
                Paint paint = ship.GetShipPaint();
                //shipName = "AEGS_Gladius";

                string prefLibName = "";
                prefLibName = shipName;
                prefLibName = ship.GetVehicleType() + "/" + ship.GetManufacturer() + "/" + prefLibName;
                XElement PrefabsLibrary = new XElement("PrefabsLibrary");
                //PrefabsLibrary.Attribute("Name").Value = shipName+"_Ship";
                //PrefabsLibrary.Add(new XAttribute("Name", shipName + "_Ship"));
                PrefabsLibrary.Add(new XAttribute("Name", prefLibName));

                XElement Prefab   = new XElement("Prefab");
                string   prefabId = GuidUtility.GenPrefabID(prefLibName);
                //Prefab.Add(new XAttribute("Name", shipName));
                Prefab.Add(new XAttribute("Name", "Ship"));
                Prefab.Add(new XAttribute("Id", prefabId));
                // Prefab.Add(new XAttribute("Library", shipName + "_Ship"));
                Prefab.Add(new XAttribute("Library", prefLibName));

                XElement Objects = new XElement("Objects");


                Loadout loadout = ship.GetLoadout();
                //Console.WriteLine(loadout.name);


                XElement Object = new XElement("Object");
                //string partid = GuidUtility.GenID("jhk777gt" + shipName  );
                //string layerid = GuidUtility.GenID("ghjg557kk" + shipName  );
                string partid   = GuidUtility.GenID();
                string layerid  = GuidUtility.GenID();
                string parentid = "0";
                parentid = partid;

                Object = AddObjects(Object, shipImplementation.parts.First(), loadout, parentid, partid, layerid, paint);
                i      = 0;
                //Object = AddPrefabsFromObjectContainers(Object, ship, parentid, layerid);
                Object = AddObjectsFromObjectContainers(Object, shipImplementation.objectContainers, parentid, layerid);

                if (Object.Attribute("Name") != null)
                {
                    Objects.Add(Object);
                }
                //Objects.Add(Object);

                XElement ObjectsNew = new XElement("Objects");
                foreach (XElement obj in Objects.Descendants("Object"))
                {
                    XElement ObjectNew = new XElement("Object");
                    //ObjectNew.Add(new XElement("Properties"));
                    if (obj.Element("Properties") != null)
                    {
                        ObjectNew.Add(obj.Element("Properties"));
                    }
                    foreach (XAttribute atr in obj.Attributes())
                    {
                        ObjectNew.Add(atr);
                    }
                    if (obj.Element("Components") != null)
                    {
                        ObjectNew.Add(obj.Element("Components"));
                    }

                    if (obj.Element("Points") != null)
                    {
                        ObjectNew.Add(obj.Element("Points"));
                    }

                    if (ObjectNew.Attribute("Name") != null)
                    {
                        ObjectsNew.Add(ObjectNew);
                    }
                }

                Prefab.Add(ObjectsNew);
                PrefabsLibrary.Add(Prefab);
                foreach (XElement pr in prefabs)
                {
                    PrefabsLibrary.Add(pr);
                }
                xml.Add(PrefabsLibrary);

                //XDocument xmlpreflib = XDocument.Load(prefablib);
                //XElement preflibel = xmlpreflib.Element("PrefabsLibrary");
                //xml.Add(preflibel);
            }

            return(xml);
        }
        public XDocument GenerateShipModification(GenerateOptions genOptions)
        {
            string shipName         = genOptions.shipName;
            string modificationName = genOptions.modificationName;

            XDocument xml = new XDocument();

            ShipImplementation ship           = exporter.GetShipImplementation(shipName);
            Paint        paint                = ship.GetPaintByName(genOptions.paintName);
            Modification shipModification     = ship.GetModificationByName(modificationName);
            string       modificationTrueName = shipModification.trueName;
            string       loadoutName          = null;

            if (genOptions.loadoutName != null)
            {
                loadoutName = genOptions.loadoutName;
            }
            else
            {
                loadoutName = "Default_Loadout_" + modificationTrueName;
            }
            Loadout loadout = exporter.GetLoadout(loadoutName);

            Console.WriteLine(loadout.name);

            string prefLibName = "";

            if (paint != null)
            {
                prefLibName = modificationTrueName + "-" + paint.name;
            }
            else
            {
                prefLibName = modificationTrueName;
            }
            prefLibName = "ships/Variants/" + prefLibName;
            XElement PrefabsLibrary = new XElement("PrefabsLibrary");

            PrefabsLibrary.Add(new XAttribute("Name", prefLibName));
            XElement Prefab   = new XElement("Prefab");
            string   prefabId = GuidUtility.GenPrefabID(prefLibName);

            Prefab.Add(new XAttribute("Name", "Ship"));
            Prefab.Add(new XAttribute("Id", prefabId));
            Prefab.Add(new XAttribute("Library", prefLibName));

            XElement Objects  = new XElement("Objects");
            XElement Object   = new XElement("Object");
            string   partid   = GuidUtility.GenID("werw34" + shipName + modificationName + prefLibName);
            string   layerid  = GuidUtility.GenID("dsfhf555hyyh" + shipName + modificationName + prefLibName);
            string   parentid = "0";

            parentid = partid;

            if (shipModification.parts.Count != 0)
            {
                Object = AddObjects(Object, shipModification.parts.First(), loadout, parentid, partid, layerid, paint);
                Object = AddObjectsFromObjectContainers(Object, shipModification.objectContainers, parentid, layerid);
            }
            else
            {
                Object = AddObjects(Object, ship.parts.First(), loadout, parentid, partid, layerid, paint);
                Object = AddObjectsFromObjectContainers(Object, ship.objectContainers, parentid, layerid);
            }
            i = 0;


            if (Object.Attribute("Name") != null)
            {
                Objects.Add(Object);
            }

            XElement ObjectsNew = new XElement("Objects");

            foreach (XElement obj in Objects.Descendants("Object"))
            {
                XElement ObjectNew = new XElement("Object");
                if (obj.Element("Properties") != null)
                {
                    ObjectNew.Add(obj.Element("Properties"));
                }
                foreach (XAttribute atr in obj.Attributes())
                {
                    ObjectNew.Add(atr);
                }
                if (obj.Element("Components") != null)
                {
                    ObjectNew.Add(obj.Element("Components"));
                }

                if (ObjectNew.Attribute("Name") != null)
                {
                    ObjectsNew.Add(ObjectNew);
                }
            }

            Prefab.Add(ObjectsNew);
            PrefabsLibrary.Add(Prefab);
            foreach (XElement pr in prefabs)
            {
                PrefabsLibrary.Add(pr);
            }
            xml.Add(PrefabsLibrary);

            return(xml);
        }