Replaced instances where MapEntityPrefabs are searched for based on the name with a static Find method that takes the aliases of the prefabs into account.

This commit is contained in:
Joonas Rikkonen
2017-11-14 21:40:43 +02:00
parent d072713936
commit 5f4bf48449
17 changed files with 141 additions and 130 deletions
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Barotrauma
@@ -191,6 +192,43 @@ namespace Barotrauma
}
}
public static MapEntityPrefab Find(string name, bool caseSensitive = false)
{
if (caseSensitive)
{
foreach (MapEntityPrefab prefab in list)
{
if (prefab.name == name || (prefab.Aliases != null && prefab.Aliases.Contains(name))) return prefab;
}
}
else
{
name = name.ToLowerInvariant();
foreach (MapEntityPrefab prefab in list)
{
if (prefab.name.ToLowerInvariant() == name || (prefab.Aliases != null && prefab.Aliases.Any(a => a.ToLowerInvariant() == name))) return prefab;
}
}
return null;
}
/// <summary>
/// Check if the name or any of the aliases of this prefab match the given name.
/// </summary>
public bool NameMatches(string name, bool caseSensitive = false)
{
if (caseSensitive)
{
return this.name == name || (Aliases != null && Aliases.Any(a => a == name));
}
else
{
name = name.ToLowerInvariant();
return this.name.ToLowerInvariant() == name || (Aliases != null && Aliases.Any(a => a.ToLowerInvariant() == name));
}
}
//a method that allows the GUIListBoxes to check through a delegate if the entityprefab is still selected
public static object GetSelected()
{