Unstable 0.17.1.0

This commit is contained in:
Markus Isberg
2022-03-17 01:25:04 +09:00
parent 3974067915
commit 6d410cc1b7
302 changed files with 5878 additions and 3317 deletions
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
namespace Barotrauma
{
internal sealed class NamedEvent<T> : IDisposable
{
private readonly Dictionary<Identifier, Action<T>> events = new Dictionary<Identifier, Action<T>>();
~NamedEvent()
{
ReleaseUnmanagedResources();
}
public void Register(Identifier identifier, Action<T> action)
{
if (HasEvent(identifier))
{
throw new ArgumentException($"Event with the identifier \"{identifier}\" has already been registered.", nameof(identifier));
}
events.Add(identifier, action);
}
public void RegisterOverwriteExisting(Identifier identifier, Action<T> action)
{
if (HasEvent(identifier))
{
Deregister(identifier);
}
Register(identifier, action);
}
public void Deregister(Identifier identifier)
{
events.Remove(identifier);
}
public bool HasEvent(Identifier identifier) => events.ContainsKey(identifier);
public void Invoke(T data)
{
foreach (var (_, action) in events)
{
action?.Invoke(data);
}
}
private void ReleaseUnmanagedResources()
{
events.Clear();
}
public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
}
}
@@ -1,3 +1,5 @@
using System;
namespace Barotrauma
{
/// <summary>
@@ -10,5 +12,15 @@ namespace Barotrauma
{
public static Option<T> Some(T value) => Some<T>.Create(value);
public static Option<T> None() => None<T>.Create();
public bool IsNone() => this is None<T>;
public bool IsSome() => this is Some<T>;
public Option<TType> Select<TType>(Func<T, TType> selector) =>
this switch
{
Some<T> { Value: var value } => Option<TType>.Some(selector.Invoke(value)),
None<T> _ => Option<TType>.None(),
_ => throw new ArgumentOutOfRangeException()
};
}
}
@@ -49,7 +49,7 @@ namespace Barotrauma
string[] attributes = segments[i].Split(attributeSeparator);
for (int j = 0; j < attributes.Length; j++)
{
if (attributes[j].Contains(endDefinition))
if (attributes[j].Contains(endDefinition, System.StringComparison.OrdinalIgnoreCase))
{
if (tempData != null)
{
@@ -59,7 +59,7 @@ namespace Barotrauma
}
tempData = null;
}
else if (attributes[j].StartsWith(colorDefinition))
else if (attributes[j].StartsWith(colorDefinition, System.StringComparison.OrdinalIgnoreCase))
{
if (tempData == null) { tempData = new RichTextData(); }
string valueStr = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
@@ -72,7 +72,7 @@ namespace Barotrauma
tempData.Color = XMLExtensions.ParseColor(valueStr);
}
}
else if (attributes[j].StartsWith(metadataDefinition))
else if (attributes[j].StartsWith(metadataDefinition, System.StringComparison.OrdinalIgnoreCase))
{
if (tempData == null) { tempData = new RichTextData(); }
tempData.Metadata = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);