Changes to settings/contentpackage exception handling

This commit is contained in:
Regalis11
2015-08-12 19:35:43 +03:00
parent 5771bc7e02
commit b2d6548fce
3 changed files with 21 additions and 31 deletions
+3 -2
View File
@@ -54,13 +54,14 @@ namespace Subsurface
{ {
XDocument doc = ToolBox.TryLoadXml(filePath); XDocument doc = ToolBox.TryLoadXml(filePath);
Path = filePath;
if (doc==null) if (doc==null)
{ {
DebugConsole.ThrowError("Couldn't load content package ''"+filePath+"''!"); DebugConsole.ThrowError("Couldn't load content package ''"+filePath+"''!");
return; return;
} }
Path = filePath;
name = ToolBox.GetAttributeString(doc.Root, "name", ""); name = ToolBox.GetAttributeString(doc.Root, "name", "");
@@ -78,7 +79,7 @@ namespace Subsurface
public static ContentPackage CreatePackage(string name) public static ContentPackage CreatePackage(string name)
{ {
ContentPackage newPackage = new ContentPackage(); ContentPackage newPackage = new ContentPackage("Content/Data/"+name);
newPackage.name = name; newPackage.name = name;
list.Add(newPackage); list.Add(newPackage);
+18 -12
View File
@@ -45,23 +45,30 @@ namespace Subsurface
public void Load(string filePath) public void Load(string filePath)
{ {
XDocument doc = ToolBox.TryLoadXml(filePath); XDocument doc = ToolBox.TryLoadXml(filePath);
try
{ if (doc == null)
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
{ {
DebugConsole.ThrowError("No config file found");
GraphicsWidth = 1024; 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", ""); MasterServerUrl = ToolBox.GetAttributeString(doc.Root, "masterserverurl", "");
foreach (XElement subElement in doc.Root.Elements()) foreach (XElement subElement in doc.Root.Elements())
{ {
switch (subElement.Name.ToString().ToLower()) switch (subElement.Name.ToString().ToLower())
@@ -73,8 +80,7 @@ namespace Subsurface
if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path); if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path);
break; break;
} }
} }
} }
public void Save(string filePath) public void Save(string filePath)
@@ -99,23 +99,8 @@ namespace Subsurface.Items.Components
} }
rotation = MathUtils.CurveAngle(rotation, targetRotation, 0.05f); 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) public override bool Use(float deltaTime, Character character = null)
{ {
if (reload > 0.0f) return false; if (reload > 0.0f) return false;
@@ -176,8 +161,6 @@ namespace Subsurface.Items.Components
projectile.body.Enabled = true; projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation); 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); projectileComponent.Use(deltaTime);
item.RemoveContained(projectile); item.RemoveContained(projectile);