From b2d6548fce65f284d3581f1e0d90d84bf177a0c2 Mon Sep 17 00:00:00 2001 From: Regalis11 Date: Wed, 12 Aug 2015 19:35:43 +0300 Subject: [PATCH] Changes to settings/contentpackage exception handling --- Subsurface/Source/ContentPackage.cs | 5 ++-- Subsurface/Source/GameSettings.cs | 30 ++++++++++++-------- Subsurface/Source/Items/Components/Turret.cs | 17 ----------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/Subsurface/Source/ContentPackage.cs b/Subsurface/Source/ContentPackage.cs index 16f2dd94b..98501441d 100644 --- a/Subsurface/Source/ContentPackage.cs +++ b/Subsurface/Source/ContentPackage.cs @@ -54,13 +54,14 @@ namespace Subsurface { XDocument doc = ToolBox.TryLoadXml(filePath); + Path = filePath; + if (doc==null) { DebugConsole.ThrowError("Couldn't load content package ''"+filePath+"''!"); return; } - Path = filePath; name = ToolBox.GetAttributeString(doc.Root, "name", ""); @@ -78,7 +79,7 @@ namespace Subsurface public static ContentPackage CreatePackage(string name) { - ContentPackage newPackage = new ContentPackage(); + ContentPackage newPackage = new ContentPackage("Content/Data/"+name); newPackage.name = name; list.Add(newPackage); diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index 088b0489f..c9d28a2b6 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -45,23 +45,30 @@ namespace Subsurface public void Load(string filePath) { XDocument doc = ToolBox.TryLoadXml(filePath); - try - { - XElement graphicsMode = doc.Root.Element("graphicsmode"); - GraphicsWidth = int.Parse(graphicsMode.Attribute("width").Value); - GraphicsHeight = int.Parse(graphicsMode.Attribute("height").Value); - - FullScreenEnabled = graphicsMode.Attribute("fullscreen").Value == "true"; - } - catch + + if (doc == null) { + DebugConsole.ThrowError("No config file found"); + GraphicsWidth = 1024; - GraphicsHeight = 768; + GraphicsHeight = 678; + + MasterServerUrl = ""; + + SelectedContentPackage = new ContentPackage(""); + + return; } + XElement graphicsMode = doc.Root.Element("graphicsmode"); + GraphicsWidth = int.Parse(graphicsMode.Attribute("width").Value); + GraphicsHeight = int.Parse(graphicsMode.Attribute("height").Value); + + FullScreenEnabled = graphicsMode.Attribute("fullscreen").Value == "true"; MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", ""); + foreach (XElement subElement in doc.Root.Elements()) { switch (subElement.Name.ToString().ToLower()) @@ -73,8 +80,7 @@ namespace Subsurface if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path); break; } - } - + } } public void Save(string filePath) diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index 4a3ef3a9d..5f7a6fc76 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -99,23 +99,8 @@ namespace Subsurface.Items.Components } rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f); - - } - //public override void SecondaryUse(float deltaTime, Character character = null) - //{ - // if (character == null) return; - - // Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); - - // if (character == Character.Controlled && cam!=null) - // { - // Lights.LightManager.ViewPos = centerPos; - // cam.TargetPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y); - // } - //} - public override bool Use(float deltaTime, Character character = null) { if (reload > 0.0f) return false; @@ -176,8 +161,6 @@ namespace Subsurface.Items.Components projectile.body.Enabled = true; projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation); - //if (useSounds.Count() > 0) useSounds[Game1.localRandom.Next(useSounds.Count())].Play(1.0f, 800.0f, item.body.FarseerBody); - projectileComponent.Use(deltaTime); item.RemoveContained(projectile);