Unstable 1.1.14.0
This commit is contained in:
@@ -20,5 +20,35 @@ namespace Barotrauma.Extensions
|
||||
{
|
||||
return new Color(color.R, color.G, color.B, (byte)255);
|
||||
}
|
||||
|
||||
private static bool IsFirstColorChannelDominant(byte first, byte second, byte third, float minimumRatio = 2)
|
||||
=> first > second * minimumRatio && first > third * minimumRatio;
|
||||
|
||||
/// <summary>
|
||||
/// Is the value of the red channel at least 'minimumRatio' larger than the blue and green
|
||||
/// </summary>
|
||||
public static bool IsRedDominant(Color color, float minimumRatio = 2, byte minimumAlpha = 0)
|
||||
=> color.A > minimumAlpha &&
|
||||
IsFirstColorChannelDominant(
|
||||
first: color.R,
|
||||
color.G, color.B, minimumRatio);
|
||||
|
||||
/// <summary>
|
||||
/// Is the value of the green channel at least 'minimumRatio' larger than the red and blue
|
||||
/// </summary>
|
||||
public static bool IsGreenDominant(Color color, float minimumRatio = 2, byte minimumAlpha = 0)
|
||||
=> color.A > minimumAlpha &&
|
||||
IsFirstColorChannelDominant(
|
||||
first: color.G,
|
||||
color.R, color.B, minimumRatio);
|
||||
|
||||
/// <summary>
|
||||
/// Is the value of the blue channel at least 'minimumRatio' larger than the red and green
|
||||
/// </summary>
|
||||
public static bool IsBlueDominant(Color color, float minimumRatio = 2, byte minimumAlpha = 0)
|
||||
=> color.A > minimumAlpha &&
|
||||
IsFirstColorChannelDominant(
|
||||
first: color.B,
|
||||
color.G, color.R, minimumRatio);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,27 +101,9 @@ namespace Barotrauma.Extensions
|
||||
return source.Where(predicate).OrderBy(p => p.UintIdentifier).ToArray().GetRandom(randSync);
|
||||
}
|
||||
|
||||
|
||||
public static T RandomElementByWeight<T>(this IList<T> source, Func<T, float> weightSelector, Rand.RandSync randSync = Rand.RandSync.Unsynced)
|
||||
public static T GetRandomByWeight<T>(this IEnumerable<T> source, Func<T, float> weightSelector, Rand.RandSync randSync)
|
||||
{
|
||||
float totalWeight = source.Sum(weightSelector);
|
||||
|
||||
float itemWeightIndex = Rand.Range(0f, 1f, randSync) * totalWeight;
|
||||
float currentWeightIndex = 0;
|
||||
|
||||
for (int i = 0; i < source.Count; i++)
|
||||
{
|
||||
T weightedItem = source[i];
|
||||
float weight = weightSelector(weightedItem);
|
||||
currentWeightIndex += weight;
|
||||
|
||||
if (currentWeightIndex >= itemWeightIndex)
|
||||
{
|
||||
return weightedItem;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
return ToolBox.SelectWeightedRandom(source, weightSelector, randSync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Barotrauma
|
||||
|
||||
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)]this string? s) => string.IsNullOrEmpty(s);
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)]this string? s) => string.IsNullOrWhiteSpace(s);
|
||||
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)]this ContentPath? p) => p?.IsNullOrEmpty() ?? true;
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)]this ContentPath? p) => p?.IsNullOrWhiteSpace() ?? true;
|
||||
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)]this ContentPath? p) => p?.IsPathNullOrEmpty() ?? true;
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)]this ContentPath? p) => p?.IsPathNullOrWhiteSpace() ?? true;
|
||||
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)]this LocalizedString? s) => s is null || string.IsNullOrEmpty(s.Value);
|
||||
public static bool IsNullOrWhiteSpace([NotNullWhen(returnValue: false)]this LocalizedString? s) => s is null || string.IsNullOrWhiteSpace(s.Value);
|
||||
public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)]this RichString? s) => s is null || s.NestedStr.IsNullOrEmpty();
|
||||
|
||||
Reference in New Issue
Block a user