public ShipDefinition GetShipDefinition(string shipname) { ShipDefinition ship = null; foreach (ShipDefinition sp in shipsDefinitions) { if (sp.GetShipName() == shipname) { ship = sp; } } return(ship); }
void LoadShipsDefinitions(string path) { if (File.Exists(path)) { XDocument xmlGame = XDocument.Load(path); IEnumerable <XElement> elements = xmlGame.Element("DataForge").Elements(); foreach (var el in elements) { string[] words = el.Name.ToString().Split('.'); if (words.Length == 2) { string classDef = words[0]; string itemName = words[1]; if (classDef == "EntityClassDefinition") { if (el.Attribute("__path").Value.StartsWith("libs/foundry/records/vehicle/spaceship")) { Console.Write("."); string __path = el.Attribute("__path").Value; string manufacturer = Path.GetFileName(Path.GetDirectoryName(__path)); string vehicleType = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(__path))); ShipDefinition shipDef = new ShipDefinition(el, manufacturer, vehicleType, items); if ((shipDef.GetShipImplementation() != null) && (shipDef.GetLoadout() != null)) { shipsDefinitions.Add(shipDef); } } if (el.Attribute("__path").Value.StartsWith("libs/foundry/records/vehicle/groundvehicle")) { Console.Write("."); string __path = el.Attribute("__path").Value; string manufacturer = Path.GetFileName(Path.GetDirectoryName(__path)); string vehicleType = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(__path))); ShipDefinition shipDef = new ShipDefinition(el, manufacturer, vehicleType, items); if ((shipDef.GetShipImplementation() != null) && (shipDef.GetLoadout() != null)) { shipsDefinitions.Add(shipDef); } } } } } Console.WriteLine(); } }
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); }