コード例 #1
0
ファイル: BuildingType.cs プロジェクト: MK4H/MHUrho
        /// <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
ファイル: BuildingType.cs プロジェクト: MK4H/MHUrho
 /// <summary>
 /// This constructor enables creation of mock instances, that are not loaded from package and have other uses.
 /// </summary>
 /// <param name="id">Identifier of the building type.</param>
 /// <param name="name">Name of the building type.</param>
 /// <param name="package">The package the building type is loaded from.</param>
 /// <param name="assets">The assets added to every instance of building of this type.</param>
 /// <param name="iconRectangle">Part of the <see cref="GamePack.BuildingIconTexture"/> representing this type.</param>
 /// <param name="size">Size of the buildings of this type in number of tiles.</param>
 /// <param name="plugin">Type plugin of this building type.</param>
 protected BuildingType(int id,
                        string name,
                        GamePack package,
                        AssetContainer assets,
                        IntRect iconRectangle,
                        IntVector2 size,
                        BuildingTypePlugin plugin)
 {
     this.ID            = id;
     this.Name          = name;
     this.Package       = package;
     this.Assets        = assets;
     this.IconRectangle = iconRectangle;
     this.Size          = size;
     this.Plugin        = plugin;
 }