示例#1
0
        /// <summary>
        /// Loads building type from the given <paramref name="xml"/> element.
        /// Expects that the <paramref name="xml"/> is validated against the <see cref="PackageManager.schemas"/>.
        /// </summary>
        /// <param name="xml">The XML element to load the building from.</param>
        /// <param name="package">The package this Xml element is from.</param>
        public void Load(XElement xml, GamePack package)
        {
            Package = package;

            XElement extensionElem = null;
            string   assemblyPath  = null;

            try {
                ID            = XmlHelpers.GetID(xml);
                Name          = XmlHelpers.GetName(xml);
                IconRectangle = XmlHelpers.GetIconRectangle(xml);
                Size          = XmlHelpers.GetIntVector2(xml.Element(BuildingTypeXml.Inst.Size));
                assemblyPath  = XmlHelpers.GetPath(xml.Element(BuildingTypeXml.Inst.AssemblyPath));
                extensionElem = XmlHelpers.GetExtensionElement(xml);
            }
            catch (Exception e) {
                LoadError($"Building type loading failed: Invalid XML of the package {package.Name}", e);
            }

            try {
                Assets = AssetContainer.FromXml(xml.Element(BuildingTypeXml.Inst.Assets), package);
            }
            catch (Exception e) {
                LoadError($"Building type \"{Name}\"[{ID}] loading failed: Asset instantiation failed with exception: {e.Message}", e);
            }

            try {
                Plugin = TypePlugin.LoadTypePlugin <BuildingTypePlugin>(assemblyPath, package, Name, ID, extensionElem);
            }
            catch (Exception e) {
                LoadError($"Building type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e);
            }
        }
示例#2
0
        /// <summary>
        /// Loads the standard data of the unitType from the xml
        ///
        /// THE STANDARD DATA cannot reference any other types, it would cause infinite cycles
        ///
        /// After this loading, you should register this type so it can be referenced, and then call
        /// <see cref="UnitType.ParseExtensionData(XElement, GamePack)"/>
        /// </summary>
        /// <param name="xml">xml element describing the type, according to <see cref="PackageManager.XMLNamespace"/> schema</param>
        /// <param name="package">Package this unitType belongs to</param>
        /// <returns>UnitType with filled standard members</returns>
        public void Load(XElement xml, GamePack package)
        {
            Package = package;

            //The XML should be validated, there should be no errors
            string   assemblyPath  = null;
            XElement assetsElement = null;
            XElement extensionElem = null;

            try {
                ID            = XmlHelpers.GetID(xml);
                Name          = XmlHelpers.GetName(xml);
                IconRectangle = XmlHelpers.GetIconRectangle(xml);
                assemblyPath  = XmlHelpers.GetPath(xml.Element(UnitTypeXml.Inst.AssemblyPath));
                assetsElement = xml.Element(UnitTypeXml.Inst.Assets);
                extensionElem = XmlHelpers.GetExtensionElement(xml);
            }
            catch (Exception e) {
                LoadError($"Unit type loading failed: Invalid XML of the package {package.Name}", e);
            }

            try
            {
                Assets = AssetContainer.FromXml(assetsElement, package);
            }
            catch (Exception e)
            {
                LoadError($"Unit type \"{Name}\"[{ID}] loading failed: Asset instantiation failed with exception: {e.Message}", e);
            }

            try {
                Plugin = TypePlugin.LoadTypePlugin <UnitTypePlugin>(assemblyPath, package, Name, ID, extensionElem);
            }
            catch (Exception e) {
                LoadError($"Unit type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e);
            }
        }