Exemplo n.º 1
0
        /// <summary>
        /// Loads the level logic type from the package Xml.
        /// </summary>
        /// <param name="xml">Xml element holding the data for this level logic type.</param>
        /// <param name="package">The source package of the Xml.</param>
        public void Load(XElement xml, GamePack package)
        {
            Package = package;

            string   assemblyPath  = null;
            XElement extensionElem = null;

            try {
                ID            = XmlHelpers.GetID(xml);
                Name          = XmlHelpers.GetName(xml);
                assemblyPath  = XmlHelpers.GetPath(xml.Element(LevelLogicTypeXml.Inst.AssemblyPath));
                extensionElem = xml.Element(LevelLogicTypeXml.Inst.Extension);
            }
            catch (Exception e) {
                LoadError($"Level logic type loading failed: Invalid XML of the package {package.Name}", e);
            }

            try {
                Plugin = TypePlugin.LoadTypePlugin <LevelLogicTypePlugin>(assemblyPath,
                                                                          package,
                                                                          Name,
                                                                          ID,
                                                                          extensionElem);
            }
            catch (Exception e) {
                LoadError($"Level logic type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the PlayerType contents from the <paramref name="xml"/>.
        /// </summary>
        /// <param name="xml">The xml data to load.</param>
        /// <param name="package">Tha source package of the xml.</param>
        public void Load(XElement xml, GamePack package)
        {
            Package = package;

            string   path          = null;
            XElement extensionElem = null;

            try {
                ID            = XmlHelpers.GetID(xml);
                Category      = StringToCategory(xml.Attribute("category").Value);
                Name          = XmlHelpers.GetName(xml);
                IconRectangle = XmlHelpers.GetIconRectangle(xml);
                path          = XmlHelpers.GetPath(xml.Element(PlayerAITypeXml.Inst.AssemblyPath));
                extensionElem = XmlHelpers.GetExtensionElement(xml);
            }
            catch (Exception e) {
                LoadError($"Player type loading failed: Invalid XML of the package {package.Name}", e);
            }

            try {
                Plugin = TypePlugin.LoadTypePlugin <PlayerAITypePlugin>(path, package, Name, ID, extensionElem);
            }
            catch (Exception e) {
                LoadError($"Player type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
            }
        }