Replaced manual rect parsing in a bunch of places with an extension method

This commit is contained in:
Joonas Rikkonen
2017-11-14 21:09:07 +02:00
parent 913a102591
commit d072713936
6 changed files with 24 additions and 53 deletions
@@ -654,17 +654,11 @@ namespace Barotrauma
if (element.Attribute("rect") != null)
{
string rectString = element.GetAttributeString("rect", "0,0,0,0");
string[] rectValues = rectString.Split(',');
rect = new Rectangle(
int.Parse(rectValues[0]),
int.Parse(rectValues[1]),
int.Parse(rectValues[2]),
int.Parse(rectValues[3]));
rect = element.GetAttributeRect("rect", Rectangle.Empty);
}
else
{
//backwards compatibility
rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
int.Parse(element.Attribute("y").Value),
@@ -708,20 +708,13 @@ namespace Barotrauma
public static void Load(XElement element, Submarine submarine)
{
Rectangle rect = Rectangle.Empty;
if (element.Attribute("rect") != null)
{
string rectString = element.GetAttributeString("rect", "0,0,0,0");
string[] rectValues = rectString.Split(',');
rect = new Rectangle(
int.Parse(rectValues[0]),
int.Parse(rectValues[1]),
int.Parse(rectValues[2]),
int.Parse(rectValues[3]));
rect = element.GetAttributeRect("rect", Rectangle.Empty);
}
else
{
//backwards compatibility
rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
int.Parse(element.Attribute("y").Value),
@@ -824,14 +824,7 @@ namespace Barotrauma
public static void Load(XElement element, Submarine submarine)
{
string rectString = element.GetAttributeString("rect", "0,0,0,0");
string[] rectValues = rectString.Split(',');
Rectangle rect = new Rectangle(
int.Parse(rectValues[0]),
int.Parse(rectValues[1]),
int.Parse(rectValues[2]),
int.Parse(rectValues[3]));
Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty);
string name = element.Attribute("name").Value;