v0.13.0.11
This commit is contained in:
@@ -84,6 +84,22 @@ namespace Barotrauma
|
||||
return retval;
|
||||
}
|
||||
|
||||
public override int Next(int minValue, int maxValue)
|
||||
{
|
||||
int range = maxValue - minValue;
|
||||
return minValue + Next(range);
|
||||
}
|
||||
|
||||
public override void NextBytes(byte[] buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void NextBytes(Span<byte> buffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random value is greater or equal than 0 and less than maxValue
|
||||
/// </summary>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -723,7 +724,7 @@ namespace Barotrauma
|
||||
return wrappedPoints;
|
||||
}
|
||||
|
||||
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount)
|
||||
public static List<Vector2[]> GenerateJaggedLine(Vector2 start, Vector2 end, int iterations, float offsetAmount, Rectangle? bounds = null)
|
||||
{
|
||||
List<Vector2[]> segments = new List<Vector2[]>
|
||||
{
|
||||
@@ -745,6 +746,26 @@ namespace Barotrauma
|
||||
normal = new Vector2(-normal.Y, normal.X);
|
||||
midPoint += normal * Rand.Range(-offsetAmount, offsetAmount, Rand.RandSync.Server);
|
||||
|
||||
if (bounds.HasValue)
|
||||
{
|
||||
if (midPoint.X < bounds.Value.X)
|
||||
{
|
||||
midPoint.X = bounds.Value.X + (bounds.Value.X - midPoint.X);
|
||||
}
|
||||
else if (midPoint.X > bounds.Value.Right)
|
||||
{
|
||||
midPoint.X = bounds.Value.Right - (midPoint.X - bounds.Value.Right);
|
||||
}
|
||||
if (midPoint.Y < bounds.Value.Y)
|
||||
{
|
||||
midPoint.Y = bounds.Value.Y + (bounds.Value.Y - midPoint.Y);
|
||||
}
|
||||
else if (midPoint.Y > bounds.Value.Bottom)
|
||||
{
|
||||
midPoint.Y = bounds.Value.Bottom - (midPoint.Y - bounds.Value.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
segments.Insert(i, new Vector2[] { startSegment, midPoint });
|
||||
segments.Insert(i + 1, new Vector2[] { midPoint, endSegment });
|
||||
|
||||
@@ -900,6 +921,8 @@ namespace Barotrauma
|
||||
return (float)Math.Pow(f, p);
|
||||
}
|
||||
|
||||
public static float Pow2(float f) => f * f;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the alignment to a vector where -1,-1 is the top-left corner, 0,0 the center and 1,1 bottom-right
|
||||
/// </summary>
|
||||
@@ -930,12 +953,10 @@ namespace Barotrauma
|
||||
/// Modified from:
|
||||
/// http://www.gamefromscratch.com/post/2012/11/24/GameDev-math-recipes-Rotating-one-point-around-another-point.aspx
|
||||
/// </summary>
|
||||
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float degrees, bool clockWise = true)
|
||||
public static Vector2 RotatePointAroundTarget(Vector2 point, Vector2 target, float radians, bool clockWise = true)
|
||||
{
|
||||
// (Math.PI / 180) * degrees
|
||||
var angle = MathHelper.ToRadians(degrees);
|
||||
var sin = Math.Sin(angle);
|
||||
var cos = Math.Cos(angle);
|
||||
var sin = Math.Sin(radians);
|
||||
var cos = Math.Cos(radians);
|
||||
if (!clockWise)
|
||||
{
|
||||
sin = -sin;
|
||||
@@ -1046,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>
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace Barotrauma
|
||||
public Color? Color;
|
||||
public string Metadata;
|
||||
|
||||
public float Alpha = 1.0f;
|
||||
|
||||
private const char definitionIndicator = '‖';
|
||||
private const char attributeSeparator = ';';
|
||||
private const char keyValueSeparator = ':';
|
||||
|
||||
@@ -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>
|
||||
@@ -449,6 +481,7 @@ namespace Barotrauma
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new instance of the class with all properties and fields copied.
|
||||
/// </summary>
|
||||
@@ -490,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