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
@@ -20,7 +20,7 @@ namespace Barotrauma
public ArtifactEvent(XElement element)
: base(element)
{
string itemName = ToolBox.GetAttributeString(element, "itemname", "");
string itemName = element.GetAttributeString("itemname", "");
itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;
@@ -18,7 +18,7 @@ namespace Barotrauma
{
itemConfig = element.Element("Items");
requiredDeliveryAmount = ToolBox.GetAttributeInt(element, "requireddeliveryamount", 0);
requiredDeliveryAmount = element.GetAttributeInt("requireddeliveryamount", 0);
}
private void InitItems()
@@ -41,7 +41,7 @@ namespace Barotrauma
private void LoadItemAsChild(XElement element, Item parent)
{
string itemName = ToolBox.GetAttributeString(element, "name", "");
string itemName = element.GetAttributeString("name", "");
ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;
if (itemPrefab==null)
@@ -79,7 +79,7 @@ namespace Barotrauma
foreach (XElement subElement in element.Elements())
{
int amount = ToolBox.GetAttributeInt(subElement, "amount", 1);
int amount = subElement.GetAttributeInt("amount", 1);
for (int i = 0; i < amount; i++)
{
LoadItemAsChild(subElement, item);
@@ -58,9 +58,9 @@ namespace Barotrauma
{
descriptions = new string[]
{
ToolBox.GetAttributeString(element, "descriptionneutral", ""),
ToolBox.GetAttributeString(element, "description1", ""),
ToolBox.GetAttributeString(element, "description2", "")
element.GetAttributeString("descriptionneutral", ""),
element.GetAttributeString("description1", ""),
element.GetAttributeString("description2", "")
};
for (int i = 0; i < descriptions.Length; i++)
@@ -73,8 +73,8 @@ namespace Barotrauma
teamNames = new string[]
{
ToolBox.GetAttributeString(element, "teamname1", "Team A"),
ToolBox.GetAttributeString(element, "teamname2", "Team B")
element.GetAttributeString("teamname1", "Team A"),
element.GetAttributeString("teamname2", "Team B")
};
}
@@ -78,7 +78,7 @@ namespace Barotrauma
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.Missions);
foreach (string file in files)
{
XDocument doc = ToolBox.TryLoadXml(file);
XDocument doc = XMLExtensions.TryLoadXml(file);
if (doc == null || doc.Root == null) continue;
foreach (XElement element in doc.Root.Elements())
@@ -94,26 +94,26 @@ namespace Barotrauma
public Mission(XElement element, Location[] locations)
{
name = ToolBox.GetAttributeString(element, "name", "");
name = element.GetAttributeString("name", "");
description = ToolBox.GetAttributeString(element, "description", "");
description = element.GetAttributeString("description", "");
reward = ToolBox.GetAttributeInt(element, "reward", 1);
reward = element.GetAttributeInt("reward", 1);
successMessage = ToolBox.GetAttributeString(element, "successmessage",
successMessage = element.GetAttributeString("successmessage",
"Mission completed successfully");
failureMessage = ToolBox.GetAttributeString(element, "failuremessage",
failureMessage = element.GetAttributeString("failuremessage",
"Mission failed");
radarLabel = ToolBox.GetAttributeString(element, "radarlabel", "");
radarLabel = element.GetAttributeString("radarlabel", "");
messages = new List<string>();
headers = new List<string>();
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "message") continue;
headers.Add(ToolBox.GetAttributeString(subElement, "header", ""));
messages.Add(ToolBox.GetAttributeString(subElement, "text", ""));
headers.Add(subElement.GetAttributeString("header", ""));
messages.Add(subElement.GetAttributeString("text", ""));
}
for (int n = 0; n < 2; n++)
@@ -137,7 +137,7 @@ namespace Barotrauma
var files = GameMain.SelectedPackage.GetFilesOfType(ContentType.Missions);
string configFile = files[rand.Next(files.Count)];
XDocument doc = ToolBox.TryLoadXml(configFile);
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null) return null;
int eventCount = doc.Root.Elements().Count();
@@ -167,17 +167,17 @@ namespace Barotrauma
if (isSinglePlayer)
{
matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "multiplayeronly", false));
matchingElements.RemoveAll(m => m.GetAttributeBool("multiplayeronly", false));
}
else
{
matchingElements.RemoveAll(m => ToolBox.GetAttributeBool(m, "singleplayeronly", false));
matchingElements.RemoveAll(m => m.GetAttributeBool("singleplayeronly", false));
}
int i = 0;
foreach (XElement element in matchingElements)
{
eventProbability[i] = ToolBox.GetAttributeInt(element, "commonness", 1);
eventProbability[i] = element.GetAttributeInt("commonness", 1);
probabilitySum += eventProbability[i];
@@ -21,7 +21,7 @@ namespace Barotrauma
public MonsterMission(XElement element, Location[] locations)
: base(element, locations)
{
monsterFile = ToolBox.GetAttributeString(element, "monsterfile", "");
monsterFile = element.GetAttributeString("monsterfile", "");
}
@@ -26,11 +26,11 @@ namespace Barotrauma
public SalvageMission(XElement element, Location[] locations)
: base(element, locations)
{
string itemName = ToolBox.GetAttributeString(element, "itemname", "");
string itemName = element.GetAttributeString("itemname", "");
itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab;
string spawnPositionTypeStr = ToolBox.GetAttributeString(element, "spawntype", "");
string spawnPositionTypeStr = element.GetAttributeString("spawntype", "");
if (string.IsNullOrWhiteSpace(spawnPositionTypeStr) ||
!Enum.TryParse<Level.PositionType>(spawnPositionTypeStr, true, out spawnPositionType))
@@ -39,14 +39,14 @@ namespace Barotrauma
public MonsterEvent(XElement element)
: base (element)
{
characterFile = ToolBox.GetAttributeString(element, "characterfile", "");
characterFile = element.GetAttributeString("characterfile", "");
int defaultAmount = ToolBox.GetAttributeInt(element, "amount", 1);
int defaultAmount = element.GetAttributeInt("amount", 1);
minAmount = ToolBox.GetAttributeInt(element, "minamount", defaultAmount);
maxAmount = Math.Max(ToolBox.GetAttributeInt(element, "maxamount", 1), minAmount);
minAmount = element.GetAttributeInt("minamount", defaultAmount);
maxAmount = Math.Max(element.GetAttributeInt("maxamount", 1), minAmount);
var spawnPosTypeStr = ToolBox.GetAttributeString(element, "spawntype", "");
var spawnPosTypeStr = element.GetAttributeString("spawntype", "");
if (string.IsNullOrWhiteSpace(spawnPosTypeStr) ||
!Enum.TryParse<Level.PositionType>(spawnPosTypeStr, true, out spawnPosType))
@@ -54,9 +54,9 @@ namespace Barotrauma
spawnPosType = Level.PositionType.MainPath;
}
spawnDeep = ToolBox.GetAttributeBool(element, "spawndeep", false);
spawnDeep = element.GetAttributeBool("spawndeep", false);
repeat = ToolBox.GetAttributeBool(element, "repeat", repeat);
repeat = element.GetAttributeBool("repeat", repeat);
if (GameMain.NetworkMember != null)
{
@@ -56,13 +56,13 @@ namespace Barotrauma
{
configElement = element;
name = ToolBox.GetAttributeString(element, "name", "");
description = ToolBox.GetAttributeString(element, "description", "");
name = element.GetAttributeString("name", "");
description = element.GetAttributeString("description", "");
minEventCount = ToolBox.GetAttributeInt(element, "mineventcount", 0);
maxEventCount = ToolBox.GetAttributeInt(element, "maxeventcount", 0);
minEventCount = element.GetAttributeInt("mineventcount", 0);
maxEventCount = element.GetAttributeInt("maxeventcount", 0);
MusicType = ToolBox.GetAttributeString(element, "musictype", "default");
MusicType = element.GetAttributeString("musictype", "default");
overrideMinEventCount = new Dictionary<string, int>();
overrideMaxEventCount = new Dictionary<string, int>();
@@ -72,11 +72,11 @@ namespace Barotrauma
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "overrideeventcount":
string levelType = ToolBox.GetAttributeString(subElement, "leveltype", "");
string levelType = subElement.GetAttributeString("leveltype", "");
if (!overrideMinEventCount.ContainsKey(levelType))
{
overrideMinEventCount.Add(levelType, ToolBox.GetAttributeInt(subElement, "min", 0));
overrideMaxEventCount.Add(levelType, ToolBox.GetAttributeInt(subElement, "max", 0));
overrideMinEventCount.Add(levelType, subElement.GetAttributeInt("min", 0));
overrideMaxEventCount.Add(levelType, subElement.GetAttributeInt("max", 0));
}
break;
}
@@ -111,7 +111,7 @@ namespace Barotrauma
foreach (string configFile in configFiles)
{
XDocument doc = ToolBox.TryLoadXml(configFile);
XDocument doc = XMLExtensions.TryLoadXml(configFile);
if (doc == null) continue;
foreach (XElement element in doc.Root.Elements())