(a00338777) v0.9.2.1

This commit is contained in:
Joonas Rikkonen
2019-08-26 19:58:19 +03:00
parent 0f63da27b2
commit 80698b58b0
311 changed files with 11763 additions and 4507 deletions
@@ -12,7 +12,7 @@ using System.Xml.Linq;
namespace Barotrauma
{
[AttributeUsage(AttributeTargets.Property)]
public class Editable : Attribute
class Editable : Attribute
{
public int MaxLength;
public int DecimalCount = 1;
@@ -45,7 +45,7 @@ namespace Barotrauma
}
[AttributeUsage(AttributeTargets.Property)]
public class InGameEditable : Editable
class InGameEditable : Editable
{
}
@@ -166,7 +166,6 @@ namespace Barotrauma
try
{
switch (typeName)
{
case "bool":
@@ -175,20 +174,26 @@ namespace Barotrauma
propertyInfo.SetValue(parentObject, boolValue, null);
break;
case "int":
int intVal;
if (int.TryParse(value, out intVal))
if (int.TryParse(value, out int intVal))
{
if (TrySetValueWithoutReflection(parentObject, intVal)) { return true; }
propertyInfo.SetValue(parentObject, intVal, null);
}
else
{
return false;
}
break;
case "float":
float floatVal;
if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out floatVal))
if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out float floatVal))
{
if (TrySetValueWithoutReflection(parentObject, floatVal)) { return true; }
propertyInfo.SetValue(parentObject, floatVal, null);
}
else
{
return false;
}
break;
case "string":
propertyInfo.SetValue(parentObject, value, null);
@@ -420,6 +425,9 @@ namespace Barotrauma
case "Charge":
if (parentObject is PowerContainer powerContainer) { return powerContainer.Charge; }
break;
case "Overload":
if (parentObject is PowerTransfer powerTransfer) { return powerTransfer.Overload; }
break;
case "AvailableFuel":
{ if (parentObject is Reactor reactor) { return reactor.AvailableFuel; } }
break;
@@ -662,5 +670,33 @@ namespace Barotrauma
element.SetAttributeValue(property.NameToLowerInvariant, stringValue);
}
}
/// <summary>
/// Upgrade the properties of an entity saved with an older version of the game. Properties that should be upgraded are defined using "Upgrade" elements in the config file.
/// for example, <Upgrade gameversion="0.9.2.0" scale="0.5"/> would force the scale of the entity to 0.5 if it was saved with a version prior to 0.9.2.0.
/// </summary>
/// <param name="entity">The entity to upgrade</param>
/// <param name="configElement">The XML element to get the upgrade instructions from (e.g. the config of an item prefab)</param>
/// <param name="savedVersion">The game version the entity was saved with</param>
public static void UpgradeGameVersion(ISerializableEntity entity, XElement configElement, Version savedVersion)
{
foreach (XElement subElement in configElement.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "upgrade") { continue; }
var upgradeVersion = new Version(subElement.GetAttributeString("gameversion", "0.0.0.0"));
if (savedVersion < upgradeVersion)
{
foreach (XAttribute attribute in subElement.Attributes())
{
string attributeName = attribute.Name.ToString().ToLowerInvariant();
if (attributeName == "gameversion") { continue; }
if (entity.SerializableProperties.TryGetValue(attributeName, out SerializableProperty property))
{
property.TrySetValue(entity, attribute.Value);
}
}
}
}
}
}
}