Converted the GetAttribute methods in the ToolBox class to extension methods

This commit is contained in:
Joonas Rikkonen
2017-10-04 18:38:40 +03:00
parent 6c7c97a875
commit 1ff2054ca8
99 changed files with 854 additions and 875 deletions
@@ -33,7 +33,7 @@ namespace Barotrauma
if (prefab.LevelTriggerElement != null)
{
Vector2 triggerPosition = ToolBox.GetAttributeVector2(prefab.LevelTriggerElement, "position", Vector2.Zero) * scale;
Vector2 triggerPosition = prefab.LevelTriggerElement.GetAttributeVector2("position", Vector2.Zero) * scale;
if (rotation != 0.0f)
{
@@ -110,7 +110,7 @@ namespace Barotrauma
{
try
{
XDocument doc = ToolBox.TryLoadXml(configPath);
XDocument doc = XMLExtensions.TryLoadXml(configPath);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
@@ -40,16 +40,16 @@ namespace Barotrauma
public BackgroundSpritePrefab(XElement element)
{
string alignmentStr = ToolBox.GetAttributeString(element, "alignment", "");
string alignmentStr = element.GetAttributeString("alignment", "");
if (string.IsNullOrEmpty(alignmentStr) || !Enum.TryParse(alignmentStr, out Alignment))
{
Alignment = Alignment.Top | Alignment.Bottom | Alignment.Left | Alignment.Right;
}
Commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
Commonness = element.GetAttributeInt("commonness", 1);
string[] spawnPosStrs = ToolBox.GetAttributeString(element, "spawnpos", "Wall").Split(',');
string[] spawnPosStrs = element.GetAttributeString("spawnpos", "Wall").Split(',');
foreach (string spawnPosStr in spawnPosStrs)
{
SpawnPosType parsedSpawnPos;
@@ -59,18 +59,18 @@ namespace Barotrauma
}
}
Scale.X = ToolBox.GetAttributeFloat(element, "minsize", 1.0f);
Scale.Y = ToolBox.GetAttributeFloat(element, "maxsize", 1.0f);
Scale.X = element.GetAttributeFloat("minsize", 1.0f);
Scale.Y = element.GetAttributeFloat("maxsize", 1.0f);
DepthRange = ToolBox.GetAttributeVector2(element, "depthrange", new Vector2(0.0f, 1.0f));
DepthRange = element.GetAttributeVector2("depthrange", new Vector2(0.0f, 1.0f));
AlignWithSurface = ToolBox.GetAttributeBool(element, "alignwithsurface", false);
AlignWithSurface = element.GetAttributeBool("alignwithsurface", false);
RandomRotation = ToolBox.GetAttributeVector2(element, "randomrotation", Vector2.Zero);
RandomRotation = element.GetAttributeVector2("randomrotation", Vector2.Zero);
RandomRotation.X = MathHelper.ToRadians(RandomRotation.X);
RandomRotation.Y = MathHelper.ToRadians(RandomRotation.Y);
SwingAmount = MathHelper.ToRadians(ToolBox.GetAttributeFloat(element, "swingamount", 0.0f));
SwingAmount = MathHelper.ToRadians(element.GetAttributeFloat("swingamount", 0.0f));
OverrideCommonness = new Dictionary<string, int>();
@@ -82,10 +82,10 @@ namespace Barotrauma
Sprite = new Sprite(subElement);
break;
case "overridecommonness":
string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
string levelType = subElement.GetAttributeString("leveltype", "");
if (!OverrideCommonness.ContainsKey(levelType))
{
OverrideCommonness.Add(levelType, ToolBox.GetAttributeInt(subElement, "commonness", 1));
OverrideCommonness.Add(levelType, subElement.GetAttributeInt("commonness", 1));
}
break;
case "leveltrigger":
@@ -101,11 +101,11 @@ namespace Barotrauma
}
ParticleEmitterPrefabs.Add(new Particles.ParticleEmitterPrefab(subElement));
EmitterPositions.Add(ToolBox.GetAttributeVector2(subElement, "position", Vector2.Zero));
EmitterPositions.Add(subElement.GetAttributeVector2("position", Vector2.Zero));
break;
case "sound":
SoundElement = subElement;
SoundPosition = ToolBox.GetAttributeVector2(subElement, "position", Vector2.Zero);
SoundPosition = subElement.GetAttributeVector2("position", Vector2.Zero);
break;
#endif
}
@@ -28,10 +28,10 @@ namespace Barotrauma
public Biome(XElement element)
{
Name = ToolBox.GetAttributeString(element, "name", "Biome");
Description = ToolBox.GetAttributeString(element, "description", "");
Name = element.GetAttributeString("name", "Biome");
Description = element.GetAttributeString("description", "");
string[] placementsStrs = ToolBox.GetAttributeString(element, "MapPlacement", "Default").Split(',');
string[] placementsStrs = element.GetAttributeString("MapPlacement", "Default").Split(',');
foreach (string placementStr in placementsStrs)
{
MapPlacement parsedPlacement;
@@ -280,21 +280,21 @@ namespace Barotrauma
Name = element == null ? "default" : element.Name.ToString();
ObjectProperties = ObjectProperty.InitProperties(this, element);
Vector3 colorVector = ToolBox.GetAttributeVector3(element, "BackgroundColor", new Vector3(50, 46, 20));
Vector3 colorVector = element.GetAttributeVector3("BackgroundColor", new Vector3(50, 46, 20));
BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);
colorVector = ToolBox.GetAttributeVector3(element, "WallColor", new Vector3(255,255,255));
colorVector = element.GetAttributeVector3("WallColor", new Vector3(255,255,255));
WallColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);
VoronoiSiteInterval = ToolBox.GetAttributeVector2(element, "VoronoiSiteInterval", new Vector2(3000, 3000));
VoronoiSiteInterval = element.GetAttributeVector2("VoronoiSiteInterval", new Vector2(3000, 3000));
VoronoiSiteVariance = ToolBox.GetAttributeVector2(element, "VoronoiSiteVariance", new Vector2(voronoiSiteInterval.X, voronoiSiteInterval.Y) * 0.4f);
VoronoiSiteVariance = element.GetAttributeVector2("VoronoiSiteVariance", new Vector2(voronoiSiteInterval.X, voronoiSiteInterval.Y) * 0.4f);
MainPathNodeIntervalRange = ToolBox.GetAttributeVector2(element, "MainPathNodeIntervalRange", new Vector2(5000.0f, 10000.0f));
MainPathNodeIntervalRange = element.GetAttributeVector2("MainPathNodeIntervalRange", new Vector2(5000.0f, 10000.0f));
SmallTunnelLengthRange = ToolBox.GetAttributeVector2(element, "SmallTunnelLengthRange", new Vector2(5000.0f, 10000.0f));
SmallTunnelLengthRange = element.GetAttributeVector2("SmallTunnelLengthRange", new Vector2(5000.0f, 10000.0f));
string biomeStr = ToolBox.GetAttributeString(element, "biomes", "");
string biomeStr = element.GetAttributeString("biomes", "");
if (string.IsNullOrWhiteSpace(biomeStr))
{
@@ -334,7 +334,7 @@ namespace Barotrauma
foreach (string file in files)
{
XDocument doc = ToolBox.TryLoadXml(file);
XDocument doc = XMLExtensions.TryLoadXml(file);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())
@@ -57,9 +57,9 @@ namespace Barotrauma
physicsBody.SetTransform(ConvertUnits.ToSimUnits(position), rotation);
cameraShake = ToolBox.GetAttributeFloat(element, "camerashake", 0.0f);
cameraShake = element.GetAttributeFloat("camerashake", 0.0f);
force = ToolBox.GetAttributeVector2(element, "force", Vector2.Zero);
force = element.GetAttributeVector2("force", Vector2.Zero);
foreach (XElement subElement in element.Elements())
{
@@ -27,7 +27,7 @@ namespace Barotrauma.RuinGeneration
private RuinStructure(XElement element)
{
string prefab = ToolBox.GetAttributeString(element, "prefab", "").ToLowerInvariant();
string prefab = element.GetAttributeString("prefab", "").ToLowerInvariant();
Prefab = MapEntityPrefab.list.Find(s => s.Name.ToLowerInvariant() == prefab);
if (Prefab == null)
@@ -36,21 +36,21 @@ namespace Barotrauma.RuinGeneration
return;
}
string alignmentStr = ToolBox.GetAttributeString(element,"alignment","Bottom");
string alignmentStr = element.GetAttributeString("alignment","Bottom");
if (!Enum.TryParse<Alignment>(alignmentStr, true, out Alignment))
{
DebugConsole.ThrowError("Error in ruin structure \""+prefab+"\" - "+alignmentStr+" is not a valid alignment");
}
string typeStr = ToolBox.GetAttributeString(element,"type","");
string typeStr = element.GetAttributeString("type","");
if (!Enum.TryParse<RuinStructureType>(typeStr,true, out Type))
{
DebugConsole.ThrowError("Error in ruin structure \"" + prefab + "\" - " + typeStr + " is not a valid type");
return;
}
commonness = ToolBox.GetAttributeInt(element, "commonness", 1);
commonness = element.GetAttributeInt("commonness", 1);
list.Add(this);
}
@@ -59,7 +59,7 @@ namespace Barotrauma.RuinGeneration
{
list = new List<RuinStructure>();
XDocument doc = ToolBox.TryLoadXml(ConfigFile);
XDocument doc = XMLExtensions.TryLoadXml(ConfigFile);
if (doc == null || doc.Root == null) return;
foreach (XElement element in doc.Root.Elements())