(d9829ac) v0.9.4.0

This commit is contained in:
Regalis
2019-10-24 18:05:42 +02:00
parent 9aa12bcac2
commit b39922a074
319 changed files with 12516 additions and 6815 deletions
@@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection;
using System.Xml.Linq;
namespace Barotrauma
{
[AttributeUsage(AttributeTargets.Property)]
@@ -21,10 +20,13 @@ namespace Barotrauma
public float MinValueFloat = float.MinValue, MaxValueFloat = float.MaxValue;
public float ValueStep;
public string ToolTip;
public string DisplayName;
/// <summary>
/// Currently implemented only for int fields. TODO: implement the remaining types (SerializableEntityEditor)
/// </summary>
public bool ReadOnly;
public Editable(int maxLength = 20)
{
MaxLength = maxLength;
@@ -57,6 +59,8 @@ namespace Barotrauma
public bool isSaveable;
public string translationTextTag;
public string Description;
/// <summary>
/// Makes the property serializable to/from XML
/// </summary>
@@ -64,11 +68,12 @@ namespace Barotrauma
/// <param name="isSaveable">Is the value saved to XML when serializing.</param>
/// <param name="translationTextTag">If set to anything else than null, SerializableEntityEditors will show what the text gets translated to or warn if the text is not found in the language files.
/// Setting the value to a non-empty string will let the user select the text from one whose tag starts with the given string (e.g. RoomName. would show all texts with a RoomName.* tag)</param>
public Serialize(object defaultValue, bool isSaveable, string translationTextTag = null)
public Serialize(object defaultValue, bool isSaveable, string description = "", string translationTextTag = null)
{
this.defaultValue = defaultValue;
this.isSaveable = isSaveable;
this.translationTextTag = translationTextTag;
this.Description = description;
}
}
@@ -684,18 +689,26 @@ namespace Barotrauma
{
if (subElement.Name.ToString().ToLowerInvariant() != "upgrade") { continue; }
var upgradeVersion = new Version(subElement.GetAttributeString("gameversion", "0.0.0.0"));
if (savedVersion < upgradeVersion)
if (savedVersion >= upgradeVersion) { continue; }
foreach (XAttribute attribute in subElement.Attributes())
{
foreach (XAttribute attribute in subElement.Attributes())
string attributeName = attribute.Name.ToString().ToLowerInvariant();
if (attributeName == "gameversion") { continue; }
if (entity.SerializableProperties.TryGetValue(attributeName, out SerializableProperty property))
{
string attributeName = attribute.Name.ToString().ToLowerInvariant();
if (attributeName == "gameversion") { continue; }
if (entity.SerializableProperties.TryGetValue(attributeName, out SerializableProperty property))
property.TrySetValue(entity, attribute.Value);
}
else if (entity is Item item)
{
foreach (ISerializableEntity component in item.AllPropertyObjects)
{
property.TrySetValue(entity, attribute.Value);
if (component.SerializableProperties.TryGetValue(attributeName, out SerializableProperty componentProperty))
{
componentProperty.TrySetValue(component, attribute.Value);
}
}
}
}
}
}
}
}
@@ -12,14 +12,7 @@ namespace Barotrauma
{
public static class XMLExtensions
{
public static string ParseContentPathFromUri(this XObject element)
{
string[] splitted = element.BaseUri.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
string currentFolder = Environment.CurrentDirectory.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }).Last();
// Filter out the current folder -> result is "Content/blaahblaah" or "Mods/blaahblaah" etc.
IEnumerable<string> filtered = splitted.SkipWhile(part => part != currentFolder).Skip(1);
return string.Join("/", filtered);
}
public static string ParseContentPathFromUri(this XObject element) => ToolBox.ConvertAbsoluteToRelativePath(element.BaseUri);
public static XDocument TryLoadXml(string filePath)
{
@@ -34,9 +27,11 @@ namespace Barotrauma
DebugConsole.ThrowError("Couldn't load xml document \"" + filePath + "\"!", e);
return null;
}
if (doc.Root == null) return null;
if (doc?.Root == null)
{
DebugConsole.ThrowError("File \"" + filePath + "\" could not be loaded: Document or the root element is invalid!");
return null;
}
return doc;
}
@@ -559,5 +554,19 @@ namespace Barotrauma
return floatArray;
}
public static bool IsOverride(this XElement element) => element.Name.ToString().Equals("override", StringComparison.OrdinalIgnoreCase);
public static XElement FirstElement(this XElement element) => element.Elements().FirstOrDefault();
/// <summary>
/// Returns the first child element that matches the name using the provided comparison method.
/// </summary>
public static XElement GetChildElement(this XContainer container, string name, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => container.Elements().FirstOrDefault(e => e.Name.ToString().Equals(name, comparisonMethod));
/// <summary>
/// Returns all child elements that match the name using the provided comparison method.
/// </summary>
public static IEnumerable<XElement> GetChildElements(this XContainer container, string name, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => container.Elements().Where(e => e.Name.ToString().Equals(name, comparisonMethod));
}
}