(3dc4135ce) v0.9.5.1
This commit is contained in:
@@ -689,7 +689,8 @@ namespace Barotrauma
|
||||
{
|
||||
if (subElement.Name.ToString().ToLowerInvariant() != "upgrade") { continue; }
|
||||
var upgradeVersion = new Version(subElement.GetAttributeString("gameversion", "0.0.0.0"));
|
||||
if (savedVersion >= upgradeVersion) { continue; }
|
||||
if (savedVersion >= upgradeVersion) { continue; }
|
||||
|
||||
foreach (XAttribute attribute in subElement.Attributes())
|
||||
{
|
||||
string attributeName = attribute.Name.ToString().ToLowerInvariant();
|
||||
@@ -698,9 +699,9 @@ namespace Barotrauma
|
||||
{
|
||||
property.TrySetValue(entity, attribute.Value);
|
||||
}
|
||||
else if (entity is Item item)
|
||||
else if (entity is Item item1)
|
||||
{
|
||||
foreach (ISerializableEntity component in item.AllPropertyObjects)
|
||||
foreach (ISerializableEntity component in item1.AllPropertyObjects)
|
||||
{
|
||||
if (component.SerializableProperties.TryGetValue(attributeName, out SerializableProperty componentProperty))
|
||||
{
|
||||
@@ -708,7 +709,28 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity is Item item2)
|
||||
{
|
||||
XElement componentElement = subElement.FirstElement();
|
||||
if (componentElement == null) continue;
|
||||
ItemComponent itemComponent = item2.Components.First(c => c.Name == componentElement.Name.ToString());
|
||||
if (itemComponent == null) continue;
|
||||
foreach (XElement element in componentElement.Elements())
|
||||
{
|
||||
switch (element.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "requireditem":
|
||||
case "requireditems":
|
||||
itemComponent.requiredItems.Clear();
|
||||
itemComponent.DisabledRequiredItems.Clear();
|
||||
|
||||
itemComponent.SetRequiredItems(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,42 @@ namespace Barotrauma
|
||||
return val;
|
||||
}
|
||||
|
||||
public static UInt64 GetAttributeUInt64(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
val = UInt64.Parse(element.Attribute(name).Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public static UInt64 GetAttributeSteamID(this XElement element, string name, UInt64 defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
|
||||
UInt64 val = defaultValue;
|
||||
|
||||
try
|
||||
{
|
||||
val = Steam.SteamManager.SteamIDStringToUInt64(element.Attribute(name).Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in " + element + "! ", e);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public static int[] GetAttributeIntArray(this XElement element, string name, int[] defaultValue)
|
||||
{
|
||||
if (element?.Attribute(name) == null) return defaultValue;
|
||||
@@ -497,27 +533,54 @@ namespace Barotrauma
|
||||
|
||||
Color color = Color.White;
|
||||
|
||||
if (strComponents.Length < 3)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
return Color.White;
|
||||
}
|
||||
|
||||
float[] components = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
for (int i = 0; i < 4 && i < strComponents.Length; i++)
|
||||
{
|
||||
float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
|
||||
}
|
||||
|
||||
if (components.Any(c => c > 1.0f))
|
||||
if (strComponents.Length == 1)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
bool hexFailed = true;
|
||||
stringColor = stringColor.Trim();
|
||||
if (stringColor[0]=='#')
|
||||
{
|
||||
components[i] = components[i] / 255.0f;
|
||||
stringColor = stringColor.Substring(1);
|
||||
|
||||
int colorInt = 0;
|
||||
if (int.TryParse(stringColor, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out colorInt))
|
||||
{
|
||||
if (stringColor.Length == 6)
|
||||
{
|
||||
colorInt = (colorInt << 8) | 0xff;
|
||||
}
|
||||
components[0] = ((float)((colorInt & 0xff000000) >> 24)) / 255.0f;
|
||||
components[1] = ((float)((colorInt & 0x00ff0000) >> 16)) / 255.0f;
|
||||
components[2] = ((float)((colorInt & 0x0000ff00) >> 8)) / 255.0f;
|
||||
components[3] = ((float)(colorInt & 0x000000ff)) / 255.0f;
|
||||
|
||||
hexFailed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hexFailed)
|
||||
{
|
||||
if (errorMessages) DebugConsole.ThrowError("Failed to parse the string \"" + stringColor + "\" to Color");
|
||||
return Color.White;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 4 && i < strComponents.Length; i++)
|
||||
{
|
||||
float.TryParse(strComponents[i], NumberStyles.Float, CultureInfo.InvariantCulture, out components[i]);
|
||||
}
|
||||
|
||||
if (components.Any(c => c > 1.0f))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
components[i] = components[i] / 255.0f;
|
||||
}
|
||||
//alpha defaults to 1.0 if not given
|
||||
if (strComponents.Length < 4) components[3] = 1.0f;
|
||||
}
|
||||
//alpha defaults to 255 if not given
|
||||
if (strComponents.Length < 4) components[3] = 255;
|
||||
}
|
||||
|
||||
return new Color(components[0], components[1], components[2], components[3]);
|
||||
|
||||
Reference in New Issue
Block a user