Unstable 0.17.0.0
This commit is contained in:
@@ -22,14 +22,14 @@ namespace Barotrauma
|
||||
|
||||
public bool IgnoreInEditor { get; set; }
|
||||
|
||||
private string[] excludedIdentifiers;
|
||||
private Identifier[] excludedIdentifiers;
|
||||
|
||||
private RelationType type;
|
||||
|
||||
public List<StatusEffect> statusEffects;
|
||||
|
||||
public string Msg;
|
||||
public string MsgTag;
|
||||
public LocalizedString Msg;
|
||||
public Identifier MsgTag;
|
||||
|
||||
/// <summary>
|
||||
/// Should broken (0 condition) items be excluded
|
||||
@@ -55,15 +55,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
Identifiers = value.Split(',');
|
||||
for (int i = 0; i < Identifiers.Length; i++)
|
||||
{
|
||||
Identifiers[i] = Identifiers[i].Trim().ToLowerInvariant();
|
||||
}
|
||||
Identifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public string[] Identifiers { get; private set; }
|
||||
public Identifier[] Identifiers { get; private set; }
|
||||
|
||||
public string JoinedExcludedIdentifiers
|
||||
{
|
||||
@@ -72,11 +68,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
excludedIdentifiers = value.Split(',');
|
||||
for (int i = 0; i < excludedIdentifiers.Length; i++)
|
||||
{
|
||||
excludedIdentifiers[i] = excludedIdentifiers[i].Trim().ToLowerInvariant();
|
||||
}
|
||||
excludedIdentifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,28 +76,19 @@ namespace Barotrauma
|
||||
{
|
||||
if (item == null) { return false; }
|
||||
if (excludedIdentifiers.Any(id => item.Prefab.Identifier == id || item.HasTag(id))) { return false; }
|
||||
return Identifiers.Any(id => item.Prefab.Identifier == id || item.HasTag(id) || (AllowVariants && item.Prefab.VariantOf?.Identifier == id));
|
||||
return Identifiers.Any(id => item.Prefab.Identifier == id || item.HasTag(id) || (AllowVariants && !item.Prefab.VariantOf.IsEmpty && item.Prefab.VariantOf == id));
|
||||
}
|
||||
public bool MatchesItem(ItemPrefab itemPrefab)
|
||||
{
|
||||
if (itemPrefab == null) { return false; }
|
||||
if (excludedIdentifiers.Any(id => itemPrefab.Identifier == id || itemPrefab.Tags.Contains(id))) { return false; }
|
||||
return Identifiers.Any(id => itemPrefab.Identifier == id || itemPrefab.Tags.Contains(id) || (AllowVariants && itemPrefab.VariantOf?.Identifier == id));
|
||||
return Identifiers.Any(id => itemPrefab.Identifier == id || itemPrefab.Tags.Contains(id) || (AllowVariants && !itemPrefab.VariantOf.IsEmpty && itemPrefab.VariantOf == id));
|
||||
}
|
||||
|
||||
public RelatedItem(string[] identifiers, string[] excludedIdentifiers)
|
||||
public RelatedItem(Identifier[] identifiers, Identifier[] excludedIdentifiers)
|
||||
{
|
||||
for (int i = 0; i < identifiers.Length; i++)
|
||||
{
|
||||
identifiers[i] = identifiers[i].Trim().ToLowerInvariant();
|
||||
}
|
||||
this.Identifiers = identifiers;
|
||||
|
||||
for (int i = 0; i < excludedIdentifiers.Length; i++)
|
||||
{
|
||||
excludedIdentifiers[i] = excludedIdentifiers[i].Trim().ToLowerInvariant();
|
||||
}
|
||||
this.excludedIdentifiers = excludedIdentifiers;
|
||||
this.Identifiers = identifiers.Select(id => id.Value.Trim().ToIdentifier()).ToArray();
|
||||
this.excludedIdentifiers = excludedIdentifiers.Select(id => id.Value.Trim().ToIdentifier()).ToArray();
|
||||
|
||||
statusEffects = new List<StatusEffect>();
|
||||
}
|
||||
@@ -178,22 +161,22 @@ namespace Barotrauma
|
||||
element.Add(new XAttribute("excludedidentifiers", JoinedExcludedIdentifiers));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Msg)) { element.Add(new XAttribute("msg", string.IsNullOrEmpty(MsgTag) ? Msg : MsgTag)); }
|
||||
if (!Msg.IsNullOrWhiteSpace()) { element.Add(new XAttribute("msg", MsgTag.IsEmpty ? Msg : MsgTag.Value)); }
|
||||
}
|
||||
|
||||
public static RelatedItem Load(XElement element, bool returnEmpty, string parentDebugName)
|
||||
public static RelatedItem Load(ContentXElement element, bool returnEmpty, string parentDebugName)
|
||||
{
|
||||
string[] identifiers;
|
||||
Identifier[] identifiers;
|
||||
if (element.Attribute("name") != null)
|
||||
{
|
||||
//backwards compatibility + a console warning
|
||||
DebugConsole.ThrowError("Error in RelatedItem config (" + (string.IsNullOrEmpty(parentDebugName) ? element.ToString() : parentDebugName) + ") - use item tags or identifiers instead of names.");
|
||||
string[] itemNames = element.GetAttributeStringArray("name", new string[0]);
|
||||
Identifier[] itemNames = element.GetAttributeIdentifierArray("name", Array.Empty<Identifier>());
|
||||
//attempt to convert to identifiers and tags
|
||||
List<string> convertedIdentifiers = new List<string>();
|
||||
foreach (string itemName in itemNames)
|
||||
List<Identifier> convertedIdentifiers = new List<Identifier>();
|
||||
foreach (Identifier itemName in itemNames)
|
||||
{
|
||||
var matchingItem = ItemPrefab.Prefabs.Find(me => me.Name == itemName);
|
||||
var matchingItem = ItemPrefab.Prefabs.Find(me => me.Name == itemName.Value);
|
||||
if (matchingItem != null)
|
||||
{
|
||||
convertedIdentifiers.Add(matchingItem.Identifier);
|
||||
@@ -208,24 +191,24 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
identifiers = element.GetAttributeStringArray("items", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("item", null, convertToLowerInvariant: true);
|
||||
identifiers = element.GetAttributeIdentifierArray("items", null) ?? element.GetAttributeIdentifierArray("item", null);
|
||||
if (identifiers == null)
|
||||
{
|
||||
identifiers = element.GetAttributeStringArray("identifiers", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("tags", null, convertToLowerInvariant: true);
|
||||
identifiers = element.GetAttributeIdentifierArray("identifiers", null) ?? element.GetAttributeIdentifierArray("tags", null);
|
||||
if (identifiers == null)
|
||||
{
|
||||
identifiers = element.GetAttributeStringArray("identifier", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("tag", new string[0], convertToLowerInvariant: true);
|
||||
identifiers = element.GetAttributeIdentifierArray("identifier", null) ?? element.GetAttributeIdentifierArray("tag", Array.Empty<Identifier>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string[] excludedIdentifiers = element.GetAttributeStringArray("excludeditems", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("excludeditem", null, convertToLowerInvariant: true);
|
||||
Identifier[] excludedIdentifiers = element.GetAttributeIdentifierArray("excludeditems", null) ?? element.GetAttributeIdentifierArray("excludeditem", null);
|
||||
if (excludedIdentifiers == null)
|
||||
{
|
||||
excludedIdentifiers = element.GetAttributeStringArray("excludedidentifiers", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("excludedtags", null, convertToLowerInvariant: true);
|
||||
excludedIdentifiers = element.GetAttributeIdentifierArray("excludedidentifiers", null) ?? element.GetAttributeIdentifierArray("excludedtags", null);
|
||||
if (excludedIdentifiers == null)
|
||||
{
|
||||
excludedIdentifiers = element.GetAttributeStringArray("excludedidentifier", null, convertToLowerInvariant: true) ?? element.GetAttributeStringArray("excludedtag", new string[0], convertToLowerInvariant: true);
|
||||
excludedIdentifiers = element.GetAttributeIdentifierArray("excludedidentifier", null) ?? element.GetAttributeIdentifierArray("excludedtag", Array.Empty<Identifier>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,24 +240,24 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
|
||||
ri.MsgTag = element.GetAttributeString("msg", "");
|
||||
string msg = TextManager.Get(ri.MsgTag, true);
|
||||
if (msg == null)
|
||||
ri.MsgTag = element.GetAttributeIdentifier("msg", Identifier.Empty);
|
||||
LocalizedString msg = TextManager.Get(ri.MsgTag);
|
||||
if (!msg.Loaded)
|
||||
{
|
||||
ri.Msg = ri.MsgTag;
|
||||
ri.Msg = ri.MsgTag.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if CLIENT
|
||||
foreach (InputType inputType in Enum.GetValues(typeof(InputType)))
|
||||
{
|
||||
msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameMain.Config.KeyBindText(inputType));
|
||||
msg = msg.Replace("[" + inputType.ToString().ToLowerInvariant() + "]", GameSettings.CurrentConfig.KeyMap.KeyBindText(inputType));
|
||||
}
|
||||
ri.Msg = msg;
|
||||
#endif
|
||||
}
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
if (!subElement.Name.ToString().Equals("statuseffect", StringComparison.OrdinalIgnoreCase)) { continue; }
|
||||
ri.statusEffects.Add(StatusEffect.Load(subElement, parentDebugName));
|
||||
|
||||
Reference in New Issue
Block a user