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
@@ -10,7 +10,7 @@ namespace Barotrauma.Particles
public DecalManager(string configFile)
{
XDocument doc = ToolBox.TryLoadXml(configFile);
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null || doc.Root == null) return;
prefabs = new Dictionary<string, DecalPrefab>();
@@ -31,11 +31,11 @@ namespace Barotrauma.Particles
}
}
Color = new Color(ToolBox.GetAttributeVector4(element, "color", Vector4.One));
Color = new Color(element.GetAttributeVector4("color", Vector4.One));
LifeTime = ToolBox.GetAttributeFloat(element, "lifetime", 10.0f);
FadeOutTime = Math.Min(LifeTime, ToolBox.GetAttributeFloat(element, "fadeouttime", 1.0f));
FadeInTime = Math.Min(LifeTime - FadeOutTime, ToolBox.GetAttributeFloat(element, "fadeintime", 0.0f));
LifeTime = element.GetAttributeFloat("lifetime", 10.0f);
FadeOutTime = Math.Min(LifeTime, element.GetAttributeFloat("fadeouttime", 1.0f));
FadeInTime = Math.Min(LifeTime - FadeOutTime, element.GetAttributeFloat("fadeintime", 0.0f));
}
}
}
@@ -95,16 +95,16 @@ namespace Barotrauma.Particles
{
Name = element.Name.ToString();
ParticlePrefab = GameMain.ParticleManager.FindPrefab(ToolBox.GetAttributeString(element, "particle", ""));
ParticlePrefab = GameMain.ParticleManager.FindPrefab(element.GetAttributeString("particle", ""));
if (element.Attribute("startrotation") == null)
{
AngleMin = ToolBox.GetAttributeFloat(element, "anglemin", 0.0f);
AngleMax = ToolBox.GetAttributeFloat(element, "anglemax", 0.0f);
AngleMin = element.GetAttributeFloat("anglemin", 0.0f);
AngleMax = element.GetAttributeFloat("anglemax", 0.0f);
}
else
{
AngleMin = ToolBox.GetAttributeFloat(element, "angle", 0.0f);
AngleMin = element.GetAttributeFloat("angle", 0.0f);
AngleMax = AngleMin;
}
@@ -118,23 +118,23 @@ namespace Barotrauma.Particles
}
else
{
ScaleMin = ToolBox.GetAttributeFloat(element,"scalemin",1.0f);
ScaleMax = Math.Max(ScaleMin, ToolBox.GetAttributeFloat(element, "scalemax", 1.0f));
ScaleMin = element.GetAttributeFloat("scalemin",1.0f);
ScaleMax = Math.Max(ScaleMin, element.GetAttributeFloat("scalemax", 1.0f));
}
if (element.Attribute("velocity") == null)
{
VelocityMin = ToolBox.GetAttributeFloat(element, "velocitymin", 0.0f);
VelocityMax = ToolBox.GetAttributeFloat(element, "velocitymax", 0.0f);
VelocityMin = element.GetAttributeFloat("velocitymin", 0.0f);
VelocityMax = element.GetAttributeFloat("velocitymax", 0.0f);
}
else
{
VelocityMin = ToolBox.GetAttributeFloat(element, "velocity", 0.0f);
VelocityMin = element.GetAttributeFloat("velocity", 0.0f);
VelocityMax = VelocityMin;
}
ParticlesPerSecond = ToolBox.GetAttributeInt(element, "particlespersecond", 0);
ParticleAmount = ToolBox.GetAttributeInt(element, "particleamount", 0);
ParticlesPerSecond = element.GetAttributeInt("particlespersecond", 0);
ParticleAmount = element.GetAttributeInt("particleamount", 0);
}
}
}
@@ -30,7 +30,7 @@ namespace Barotrauma.Particles
particles = new Particle[MaxParticles];
XDocument doc = ToolBox.TryLoadXml(configFile);
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null || doc.Root == null) return;
prefabs = new Dictionary<string, ParticlePrefab>();
@@ -69,17 +69,17 @@ namespace Barotrauma.Particles
}
}
AnimDuration = ToolBox.GetAttributeFloat(element, "animduration", 1.0f);
LoopAnim = ToolBox.GetAttributeBool(element, "loopanim", true);
AnimDuration = element.GetAttributeFloat("animduration", 1.0f);
LoopAnim = element.GetAttributeBool("loopanim", true);
if (element.Attribute("angularvelocity") == null)
{
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocitymin", 0.0f);
AngularVelocityMax = ToolBox.GetAttributeFloat(element, "angularvelocitymax", 0.0f);
AngularVelocityMin = element.GetAttributeFloat("angularvelocitymin", 0.0f);
AngularVelocityMax = element.GetAttributeFloat("angularvelocitymax", 0.0f);
}
else
{
AngularVelocityMin = ToolBox.GetAttributeFloat(element, "angularvelocity", 0.0f);
AngularVelocityMin = element.GetAttributeFloat("angularvelocity", 0.0f);
AngularVelocityMax = AngularVelocityMin;
}
@@ -88,33 +88,33 @@ namespace Barotrauma.Particles
if (element.Attribute("startsize") == null)
{
StartSizeMin = ToolBox.GetAttributeVector2(element, "startsizemin", Vector2.One);
StartSizeMax = ToolBox.GetAttributeVector2(element, "startsizemax", Vector2.One);
StartSizeMin = element.GetAttributeVector2("startsizemin", Vector2.One);
StartSizeMax = element.GetAttributeVector2("startsizemax", Vector2.One);
}
else
{
StartSizeMin = ToolBox.GetAttributeVector2(element, "startsize", Vector2.One);
StartSizeMin = element.GetAttributeVector2("startsize", Vector2.One);
StartSizeMax = StartSizeMin;
}
if (element.Attribute("sizechange") == null)
{
SizeChangeMin = ToolBox.GetAttributeVector2(element, "sizechangemin", Vector2.Zero);
SizeChangeMax = ToolBox.GetAttributeVector2(element, "sizechangemax", Vector2.Zero);
SizeChangeMin = element.GetAttributeVector2("sizechangemin", Vector2.Zero);
SizeChangeMax = element.GetAttributeVector2("sizechangemax", Vector2.Zero);
}
else
{
SizeChangeMin = ToolBox.GetAttributeVector2(element, "sizechange", Vector2.Zero);
SizeChangeMin = element.GetAttributeVector2("sizechange", Vector2.Zero);
SizeChangeMax = SizeChangeMin;
}
Drag = ToolBox.GetAttributeFloat(element, "drag", 0.0f);
WaterDrag = ToolBox.GetAttributeFloat(element, "waterdrag", 0.0f);
Drag = element.GetAttributeFloat("drag", 0.0f);
WaterDrag = element.GetAttributeFloat("waterdrag", 0.0f);
Friction = ToolBox.GetAttributeFloat(element, "friction", 0.5f);
Restitution = ToolBox.GetAttributeFloat(element, "restitution", 0.5f);
Friction = element.GetAttributeFloat("friction", 0.5f);
Restitution = element.GetAttributeFloat("restitution", 0.5f);
switch (ToolBox.GetAttributeString(element, "blendstate", "alphablend"))
switch (element.GetAttributeString("blendstate", "alphablend"))
{
case "alpha":
case "alphablend":
@@ -130,42 +130,41 @@ namespace Barotrauma.Particles
break;
}
GrowTime = ToolBox.GetAttributeFloat(element, "growtime", 0.0f);
GrowTime = element.GetAttributeFloat("growtime", 0.0f);
if (element.Attribute("startrotation") == null)
{
StartRotationMin = ToolBox.GetAttributeFloat(element, "startrotationmin", 0.0f);
StartRotationMax = ToolBox.GetAttributeFloat(element, "startrotationmax", 0.0f);
StartRotationMin = element.GetAttributeFloat("startrotationmin", 0.0f);
StartRotationMax = element.GetAttributeFloat("startrotationmax", 0.0f);
}
else
{
StartRotationMin = ToolBox.GetAttributeFloat(element, "startrotation", 0.0f);
StartRotationMin = element.GetAttributeFloat("startrotation", 0.0f);
StartRotationMax = StartRotationMin;
}
StartRotationMin = MathHelper.ToRadians(StartRotationMin);
StartRotationMax = MathHelper.ToRadians(StartRotationMax);
StartColor = new Color(ToolBox.GetAttributeVector4(element, "startcolor", Vector4.One));
StartAlpha = ToolBox.GetAttributeFloat(element, "startalpha", 1.0f);
StartColor = new Color(element.GetAttributeVector4("startcolor", Vector4.One));
StartAlpha = element.GetAttributeFloat("startalpha", 1.0f);
DeleteOnCollision = ToolBox.GetAttributeBool(element, "deleteoncollision", false);
CollidesWithWalls = ToolBox.GetAttributeBool(element, "collideswithwalls", false);
DeleteOnCollision = element.GetAttributeBool("deleteoncollision", false);
CollidesWithWalls = element.GetAttributeBool("collideswithwalls", false);
CollisionRadius = ToolBox.GetAttributeFloat(element,
"collisionradius",
CollisionRadius = element.GetAttributeFloat("collisionradius",
Sprites.Count > 0 ? 1 : Sprites[0].SourceRect.Width / 2.0f);
ColorChange = ToolBox.GetAttributeVector4(element, "colorchange", Vector4.Zero);
ColorChange = element.GetAttributeVector4("colorchange", Vector4.Zero);
LifeTime = ToolBox.GetAttributeFloat(element, "lifetime", 5.0f);
LifeTime = element.GetAttributeFloat("lifetime", 5.0f);
VelocityChange = ToolBox.GetAttributeVector2(element, "velocitychange", Vector2.Zero);
VelocityChange = element.GetAttributeVector2("velocitychange", Vector2.Zero);
VelocityChange = ConvertUnits.ToDisplayUnits(VelocityChange);
RotateToDirection = ToolBox.GetAttributeBool(element, "rotatetodirection", false);
RotateToDirection = element.GetAttributeBool("rotatetodirection", false);
switch (ToolBox.GetAttributeString(element, "drawtarget", "air").ToLowerInvariant())
switch (element.GetAttributeString("drawtarget", "air").ToLowerInvariant())
{
case "air":
default: