/// <summary> /// Provided for construction of mock types for auxiliary uses. /// </summary> /// <param name="id">Identifier.</param> /// <param name="name">Name.</param> /// <param name="package">Package.</param> /// <param name="assets">Asset container.</param> /// <param name="iconRectangle">Icon rectangle in the <see cref="GamePack.UnitIconTexture"/></param> /// <param name="plugin">Plugin.</param> public UnitType(int id, string name, GamePack package, AssetContainer assets, IntRect iconRectangle, UnitTypePlugin plugin) { this.ID = id; this.Name = name; this.Package = package; this.Assets = assets; this.IconRectangle = iconRectangle; this.Plugin = plugin; }
/// <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); } }