Unstable v0.1300.0.1
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -1066,6 +1067,16 @@ namespace Barotrauma
|
||||
if (diff == 0) { return v >= max ? 1f : 0f; }
|
||||
return MathHelper.Clamp((v - min) / diff, 0f, 1f);
|
||||
}
|
||||
|
||||
public static float Min(params float[] vals)
|
||||
{
|
||||
return vals.Min();
|
||||
}
|
||||
|
||||
public static float Max(params float[] vals)
|
||||
{
|
||||
return vals.Max();
|
||||
}
|
||||
}
|
||||
|
||||
class CompareCCW : IComparer<Vector2>
|
||||
|
||||
@@ -7,7 +7,10 @@ namespace Barotrauma.IO
|
||||
{
|
||||
static readonly string[] unwritableDirs = new string[] { "Content", "Data/ContentPackages" };
|
||||
|
||||
public static bool DevException;
|
||||
/// <summary>
|
||||
/// When set to true, the game is allowed to modify the vanilla content in debug builds. Has no effect in non-debug builds.
|
||||
/// </summary>
|
||||
public static bool SkipValidationInDebugBuilds;
|
||||
|
||||
public static bool CanWrite(string path)
|
||||
{
|
||||
@@ -20,7 +23,7 @@ namespace Barotrauma.IO
|
||||
if (path.StartsWith(dir, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
#if DEBUG
|
||||
return DevException;
|
||||
return SkipValidationInDebugBuilds;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@@ -37,7 +40,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot save XML document to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot save XML document to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
doc.Save(path);
|
||||
@@ -47,7 +50,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot save XML element to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot save XML element to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
element.Save(path);
|
||||
@@ -72,7 +75,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write XML document to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot write XML document to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
Writer = null;
|
||||
return;
|
||||
}
|
||||
@@ -222,7 +225,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot create directory \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot create directory \"{path}\": modifying the contents of the folder is not allowed.");
|
||||
return null;
|
||||
}
|
||||
return System.IO.Directory.CreateDirectory(path);
|
||||
@@ -232,7 +235,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{path}\": modifying the contents of the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
//TODO: validate recursion?
|
||||
@@ -251,7 +254,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot copy \"{src}\" to \"{dest}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot copy \"{src}\" to \"{dest}\": modifying the contents of the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Copy(src, dest, overwrite);
|
||||
@@ -261,12 +264,12 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(src))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": src failed validation");
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": modifying the contents of the source folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": dest failed validation");
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": modifying the contents of the destination folder is not allowed");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Move(src, dest);
|
||||
@@ -276,7 +279,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{path}\": modifying the contents of the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Delete(path);
|
||||
@@ -298,7 +301,7 @@ namespace Barotrauma.IO
|
||||
case System.IO.FileMode.Truncate:
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot open \"{path}\" in {mode} mode: failed validation");
|
||||
DebugConsole.ThrowError($"Cannot open \"{path}\" in {mode} mode: modifying the contents of the folder is not allowed.");
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
@@ -328,7 +331,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all bytes to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot write all bytes to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllBytes(path, contents);
|
||||
@@ -338,7 +341,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all text to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot write all text to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllText(path, contents, encoding ?? System.Text.Encoding.UTF8);
|
||||
@@ -348,7 +351,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all lines to \"{path}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot write all lines to \"{path}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllLines(path, contents, encoding ?? System.Text.Encoding.UTF8);
|
||||
@@ -420,7 +423,7 @@ namespace Barotrauma.IO
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write to file \"{fileName}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot write to file \"{fileName}\": modifying the files in the folder is not allowed.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,7 +490,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{Name}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{Name}\": modifying the contents of the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
innerInfo.Delete();
|
||||
@@ -523,7 +526,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot set read-only to {value} for \"{Name}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot set read-only to {value} for \"{Name}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
innerInfo.IsReadOnly = value;
|
||||
@@ -534,7 +537,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot copy \"{Name}\" to \"{dest}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot copy \"{Name}\" to \"{dest}\": modifying the contents of the destination folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
innerInfo.CopyTo(dest, overwriteExisting);
|
||||
@@ -544,7 +547,7 @@ namespace Barotrauma.IO
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{Name}\": failed validation");
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{Name}\": modifying the files in the folder is not allowed.");
|
||||
return;
|
||||
}
|
||||
innerInfo.Delete();
|
||||
|
||||
@@ -224,6 +224,38 @@ namespace Barotrauma
|
||||
return inputType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a HSV value into a RGB value.
|
||||
/// </summary>
|
||||
/// <param name="hue">Value between 0 and 360</param>
|
||||
/// <param name="saturation">Value between 0 and 1</param>
|
||||
/// <param name="value">Value between 0 and 1</param>
|
||||
/// <see href="https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB">Reference</see>
|
||||
/// <returns></returns>
|
||||
public static Color HSVToRGB(float hue, float saturation, float value)
|
||||
{
|
||||
float c = value * saturation;
|
||||
|
||||
float h = Math.Clamp(hue, 0, 360) / 60f;
|
||||
|
||||
float x = c * (1 - Math.Abs(h % 2 - 1));
|
||||
|
||||
float r = 0,
|
||||
g = 0,
|
||||
b = 0;
|
||||
|
||||
if (0 <= h && h <= 1) { r = c; g = x; b = 0; }
|
||||
else if (1 < h && h <= 2) { r = x; g = c; b = 0; }
|
||||
else if (2 < h && h <= 3) { r = 0; g = c; b = x; }
|
||||
else if (3 < h && h <= 4) { r = 0; g = x; b = c; }
|
||||
else if (4 < h && h <= 5) { r = x; g = 0; b = c; }
|
||||
else if (5 < h && h <= 6) { r = c; g = 0; b = x; }
|
||||
|
||||
float m = value - c;
|
||||
|
||||
return new Color(r + m, g + m, b + m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns either a green [x] or a red [o]
|
||||
/// </summary>
|
||||
@@ -491,6 +523,30 @@ namespace Barotrauma
|
||||
return destination;
|
||||
}
|
||||
|
||||
public static void SiftElement<T>(this List<T> list, int from, int to)
|
||||
{
|
||||
if (from < 0 || from >= list.Count) { throw new ArgumentException($"from parameter out of range (from={from}, range=[0..{list.Count - 1}])"); }
|
||||
if (to < 0 || to >= list.Count) { throw new ArgumentException($"to parameter out of range (to={to}, range=[0..{list.Count - 1}])"); }
|
||||
|
||||
T elem = list[from];
|
||||
if (from > to)
|
||||
{
|
||||
for (int i = from; i > to; i--)
|
||||
{
|
||||
list[i] = list[i - 1];
|
||||
}
|
||||
list[to] = elem;
|
||||
}
|
||||
else if (from < to)
|
||||
{
|
||||
for (int i = from; i < to; i++)
|
||||
{
|
||||
list[i] = list[i + 1];
|
||||
}
|
||||
list[to] = elem;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||
|
||||
Reference in New Issue
Block a user