Unstable 0.1400.0.0

This commit is contained in:
Markus Isberg
2021-05-11 15:47:47 +03:00
parent 3f324b14e8
commit 92f0264af2
247 changed files with 8238 additions and 1911 deletions
@@ -0,0 +1,62 @@
using System;
namespace Barotrauma
{
public abstract class Either<T, U>
{
public static implicit operator Either<T, U>(T t) => new EitherT<T, U>(t);
public static implicit operator Either<T, U>(U u) => new EitherU<T, U>(u);
public static explicit operator T(Either<T, U> e) => e.TryGet(out T t) ? t : throw new InvalidCastException($"Contained object is not of type {typeof(T).Name}");
public static explicit operator U(Either<T, U> e) => e.TryGet(out U u) ? u : throw new InvalidCastException($"Contained object is not of type {typeof(U).Name}");
public abstract bool TryGet(out T t);
public abstract bool TryGet(out U u);
public abstract bool TryCast<V>(out V v);
public abstract override string ToString();
}
public sealed class EitherT<T, U> : Either<T, U>
{
public readonly T Value;
public EitherT(T value) { Value = value; }
public override string ToString()
{
return Value.ToString();
}
public override bool TryGet(out T t) { t = Value; return true; }
public override bool TryGet(out U u) { u = default(U); return false; }
public override bool TryCast<V>(out V v)
{
if (Value is V result) { v = result; return true; }
else { v = default(V); return false; }
}
}
public sealed class EitherU<T, U> : Either<T, U>
{
public readonly U Value;
public EitherU(U value) { Value = value; }
public override string ToString()
{
return Value.ToString();
}
public override bool TryGet(out T t) { t = default(T); return false; }
public override bool TryGet(out U u) { u = Value; return true; }
public override bool TryCast<V>(out V v)
{
if (Value is V result) { v = result; return true; }
else { v = default(V); return false; }
}
}
}
@@ -26,6 +26,7 @@ namespace Barotrauma
sanitizedText = text;
if (!string.IsNullOrEmpty(text) && text.Contains(definitionIndicator))
{
text = text.Replace("\r", "");
string[] segments = text.Split(definitionIndicator);
sanitizedText = string.Empty;
@@ -391,7 +391,7 @@ namespace Barotrauma
}
private static Dictionary<string, List<string>> cachedLines = new Dictionary<string, List<string>>();
public static string GetRandomLine(string filePath)
public static string GetRandomLine(string filePath, Rand.RandSync randSync = Rand.RandSync.Server)
{
List<string> lines;
if (cachedLines.ContainsKey(filePath))
@@ -418,7 +418,7 @@ namespace Barotrauma
}
if (lines.Count == 0) return "";
return lines[Rand.Range(0, lines.Count, Rand.RandSync.Server)];
return lines[Rand.Range(0, lines.Count, randSync)];
}
/// <summary>