private static List<TemplateEntity> LoadEntities() { var entities = new List<TemplateEntity>(); // ReSharper disable JoinDeclarationAndInitializer string inputPath; // ReSharper restore JoinDeclarationAndInitializer inputPath = GetExecutablePath(); inputPath = Path.Combine(inputPath, "space_entities.xml"); if (File.Exists(inputPath) == false) { return entities; } using (var input = File.OpenRead(inputPath)) { var doc = new XPathDocument(input); var nav = doc.CreateNavigator(); var nodes = nav.Select("/entities/entity"); while (nodes.MoveNext() == true) { var current = nodes.Current; if (current == null) { throw new InvalidOperationException(); } var category = current.GetAttribute("category", ""); var x = current.GetAttribute("x", ""); var y = current.GetAttribute("x", ""); var width = current.GetAttribute("width", ""); var height = current.GetAttribute("height", ""); var blo = current.GetAttribute("blo", ""); var cfs = current.GetAttribute("cfs", ""); var entity = new TemplateEntity( string.IsNullOrWhiteSpace(x) ? 0 : int.Parse(x), string.IsNullOrWhiteSpace(y) ? 0 : int.Parse(y), int.Parse(width), int.Parse(height), category, blo, cfs); var physics = current.SelectSingleNode("physics"); if (physics != null) { entity.SetupPhysics(physics.Value); } var vision = current.SelectSingleNode("vision"); if (vision != null) { entity.SetupVision(vision.Value); } entities.Add(entity); } } return entities; }
private static List <TemplateEntity> LoadEntities() { var entities = new List <TemplateEntity>(); // ReSharper disable JoinDeclarationAndInitializer string inputPath; // ReSharper restore JoinDeclarationAndInitializer inputPath = GetExecutablePath(); inputPath = Path.Combine(inputPath, "space_entities.xml"); if (File.Exists(inputPath) == false) { return(entities); } using (var input = File.OpenRead(inputPath)) { var doc = new XPathDocument(input); var nav = doc.CreateNavigator(); var nodes = nav.Select("/entities/entity"); while (nodes.MoveNext() == true) { var current = nodes.Current; if (current == null) { throw new InvalidOperationException(); } var category = current.GetAttribute("category", ""); var x = current.GetAttribute("x", ""); var y = current.GetAttribute("x", ""); var width = current.GetAttribute("width", ""); var height = current.GetAttribute("height", ""); var blo = current.GetAttribute("blo", ""); var cfs = current.GetAttribute("cfs", ""); var entity = new TemplateEntity( string.IsNullOrWhiteSpace(x) ? 0 : int.Parse(x), string.IsNullOrWhiteSpace(y) ? 0 : int.Parse(y), int.Parse(width), int.Parse(height), category, blo, cfs); var physics = current.SelectSingleNode("physics"); if (physics != null) { entity.SetupPhysics(physics.Value); } var vision = current.SelectSingleNode("vision"); if (vision != null) { entity.SetupVision(vision.Value); } entities.Add(entity); } } return(entities); }