public static SpaceEffect FromXml(XmlResource Xml, SpaceEffect DstObject) { if (Xml == null) { throw new ArgumentNullException(nameof(Xml)); } SpaceEffect Result = DstObject; if (DstObject == null) { Result = new SpaceEffect(); } Result = SpaceObject.FromXml(Xml, Result) as SpaceEffect; XmlNode obj = Xml.Xml.LastChild; string baseName = GetXmlText(obj, "Base", string.Empty); SpaceEffect baseObject = Result; if (!string.IsNullOrEmpty(baseName)) { try { baseObject = SpaceEffect.FromXml(ResourceManager.Get <XmlResource>(baseName), null); } catch (KeyNotFoundException e) { baseObject = Result; Debug.WriteLine("XML Error: Failed to locate XML base " + baseName + ". " + e.Message); } } Result.Lifespan = GetXmlValue(obj, "Lifespan", baseObject.Lifespan); Result.MaxParticles = (int)GetXmlValue(obj, "MaxParticles", baseObject.MaxParticles); Result.MinParticles = (int)GetXmlValue(obj, "MinParticles", baseObject.MinParticles); Result.ParticleSpawnRadius = GetXmlValue(obj, "ParticleSpawnRadius", baseObject.ParticleSpawnRadius); Result.MaxParticleLife = GetXmlValue(obj, "MaxParticleLife", baseObject.MaxParticleLife); Result.MinParticleLife = GetXmlValue(obj, "MinParticleLife", baseObject.MinParticleLife); Result.MaxParticleScale = GetXmlValue(obj, "MaxParticleScale", baseObject.MaxParticleScale); Result.MinParticleScale = GetXmlValue(obj, "MinParticleScale", baseObject.MinParticleScale); Result.MaxParticleRotation = GetXmlValue(obj, "MaxParticleRotation", baseObject.MaxParticleRotation); Result.MinParticleRotation = GetXmlValue(obj, "MinParticleRotation", baseObject.MinParticleRotation); Result.MaxParticleAlpha = GetXmlValue(obj, "MaxParticleAlpha", baseObject.MaxParticleAlpha); Result.MinParticleAlpha = GetXmlValue(obj, "MinParticleAlpha", baseObject.MinParticleAlpha); Result.MaxParticleDirection = GetXmlValue(obj, "MaxParticleDirection", baseObject.MaxParticleDirection); Result.MinParticleDirection = GetXmlValue(obj, "MinParticleDirection", baseObject.MinParticleDirection); Result.MaxParticleAngle = GetXmlValue(obj, "MaxParticleAngle", baseObject.MaxParticleAngle); Result.MinParticleAngle = GetXmlValue(obj, "MinParticleAngle", baseObject.MinParticleAngle); Result.MaxParticleSpeed = GetXmlValue(obj, "MaxParticleSpeed", baseObject.MaxParticleSpeed); Result.MinParticleSpeed = GetXmlValue(obj, "MinParticleSpeed", baseObject.MinParticleSpeed); Result.ParticleFade = GetXmlBool(obj, "ParticleFade", baseObject.ParticleFade); Result.ParticleDrag = GetXmlValue(obj, "ParticleDrag", baseObject.ParticleDrag); Result.Children = GetXmlChildrenEffect(obj, "ChildEffect", baseObject.Children); return(Result); }
public static SpaceObject FromXml(XmlResource Xml, SpaceObject DstObject) { if (Xml == null) { throw new ArgumentNullException(nameof(Xml)); } SpaceObject Result = DstObject; if (DstObject == null) { Result = new SpaceObject(); } Result.XmlSource = Xml.Name; XmlNode obj = Xml.Xml.LastChild; string baseName = GetXmlText(obj, "Base", string.Empty); SpaceObject baseObject = Result; if (!string.IsNullOrEmpty(baseName)) { try { baseObject = SpaceObject.FromXml(ResourceManager.Get <XmlResource>(baseName), new SpaceObject()); } catch (KeyNotFoundException e) { baseObject = Result; Debug.WriteLine("XML Error: Failed to locate XML base " + baseName); } } Result.Mass = GetXmlValue(obj, "Mass", baseObject.Mass); Result.Depth = GetXmlValue(obj, "Depth", baseObject.Depth); Result.AngularDrag = GetXmlValue(obj, "AngularDrag", baseObject.AngularDrag); Result.Drag = GetXmlValue(obj, "Drag", baseObject.Drag); Result.Scale = (float)GetXmlValue(obj, "Scale", baseObject.Scale); try { Result.Texture = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", @"images\ui\error")); } catch (KeyNotFoundException e) { Result.Texture = ResourceManager.Get <TextureResource>(@"images\ui\error"); Result.Scale = 1; } Result.tickScript = GetXmlScript(obj, "Tick", baseObject.tickScript); Result.drawScript = GetXmlScript(obj, "Draw", baseObject.drawScript); Result.spawnScript = GetXmlScript(obj, "Spawn", baseObject.spawnScript); Result.destroyScript = GetXmlScript(obj, "Destroy", baseObject.destroyScript); return(Result); }
public static SpaceShip FromXml(XmlResource Xml, SpaceShip DstObject) { if (Xml == null) { throw new ArgumentNullException("Xml"); } SpaceShip Result = DstObject; if (DstObject == null) { Result = new SpaceShip(); } Result = SpaceObject.FromXml(Xml, Result) as SpaceShip; XmlNode obj = Xml.Xml.LastChild; string baseName = GetXmlText(obj, "Base", string.Empty); SpaceShip baseObject = Result; if (!string.IsNullOrEmpty(baseName)) { try { baseObject = SpaceShip.FromXml(ResourceManager.Get <XmlResource>(baseName), null); } catch (KeyNotFoundException e) { baseObject = Result; Console.WriteLine("XML Error: Failed to locate XML base " + baseName); } } Result.Hull = GetXmlValue(obj, "Hull", baseObject.Hull); Result.Shield = GetXmlValue(obj, "Shield", baseObject.Shield); Result.MaxHull = GetXmlValue(obj, "MaxHull", baseObject.MaxHull); Result.MaxShield = GetXmlValue(obj, "MaxShield", baseObject.MaxShield); Result.ShieldRegen = GetXmlValue(obj, "ShieldRegen", baseObject.ShieldRegen); Result.MaxThrust = GetXmlValue(obj, "MaxThrust", baseObject.MaxThrust); Result.TurnSpeed = GetXmlValue(obj, "TurnSpeed", baseObject.TurnSpeed); Result.RateOfFire = GetXmlValue(obj, "RateOfFire", baseObject.RateOfFire); Result.ShieldRebootProbability = (int)GetXmlValue(obj, "ShieldRebootProbability", baseObject.ShieldRebootProbability); Result.Texture = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", baseObject.Texture.Name)); //Result.Hitbox = Hitbox.Automatic(Result.Texture, (int)Math.Max(2, Result.Scale * Result.Texture.Texture.height / 8)); List <SpaceObject> hardpoints = GetXmlNested(obj, "Hardpoints", null); if (hardpoints != null && hardpoints.Count > 0) { Result.Hardpoints = new List <SpaceShipHardpoint>(); foreach (SpaceObject o in hardpoints) { SpaceShipHardpoint hp = o as SpaceShipHardpoint; if (hp != null) { hp.Parent = Result; hp.Depth += Result.Depth; hp.Scale *= Result.Scale; Result.Hardpoints.Add(hp); } } Debug.WriteLine("Loaded hardpoints"); } return(Result); }