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
@@ -93,13 +93,13 @@ namespace Barotrauma
public static Sound Load(XElement element, bool destroyOnGameEnd = true)
{
string filePath = ToolBox.GetAttributeString(element, "file", "");
string filePath = element.GetAttributeString("file", "");
var newSound = new Sound(filePath, destroyOnGameEnd);
if (newSound != null)
{
newSound.baseVolume = ToolBox.GetAttributeFloat(element, "volume", 1.0f);
newSound.range = ToolBox.GetAttributeFloat(element, "range", 1000.0f);
newSound.baseVolume = element.GetAttributeFloat("volume", 1.0f);
newSound.range = element.GetAttributeFloat("range", 1000.0f);
}
return newSound;
@@ -99,7 +99,7 @@ namespace Barotrauma
{
OverrideMusicType = null;
XDocument doc = ToolBox.TryLoadXml("Content/Sounds/sounds.xml");
XDocument doc = XMLExtensions.TryLoadXml("Content/Sounds/sounds.xml");
if (doc == null) yield return CoroutineStatus.Failure;
SoundCount = 16 + doc.Root.Elements().Count();
@@ -134,9 +134,9 @@ namespace Barotrauma
int i = 0;
foreach (XElement element in xMusic)
{
string file = ToolBox.GetAttributeString(element, "file", "");
string type = ToolBox.GetAttributeString(element, "type", "").ToLowerInvariant();
Vector2 priority = ToolBox.GetAttributeVector2(element, "priorityrange", new Vector2(0.0f, 100.0f));
string file = element.GetAttributeString("file", "");
string type = element.GetAttributeString("type", "").ToLowerInvariant();
Vector2 priority = element.GetAttributeVector2("priorityrange", new Vector2(0.0f, 100.0f));
musicClips[i] = new BackgroundMusic(file, type, priority);
@@ -158,21 +158,21 @@ namespace Barotrauma
case "music":
continue;
case "damagesound":
Sound damageSound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false);
Sound damageSound = Sound.Load(subElement.GetAttributeString("file", ""), false);
if (damageSound == null) continue;
DamageSoundType damageSoundType = DamageSoundType.None;
Enum.TryParse<DamageSoundType>(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType);
Enum.TryParse<DamageSoundType>(subElement.GetAttributeString("damagesoundtype", "None"), false, out damageSoundType);
damageSounds.Add(new DamageSound(
damageSound,
ToolBox.GetAttributeVector2(subElement, "damagerange", new Vector2(0.0f, 100.0f)),
subElement.GetAttributeVector2("damagerange", new Vector2(0.0f, 100.0f)),
damageSoundType,
ToolBox.GetAttributeString(subElement, "requiredtag", "")));
subElement.GetAttributeString("requiredtag", "")));
break;
default:
Sound sound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false);
Sound sound = Sound.Load(subElement.GetAttributeString("file", ""), false);
if (sound != null)
{
miscSoundList.Add(new KeyValuePair<string, Sound>(subElement.Name.ToString().ToLowerInvariant(), sound));