Unstable 0.17.1.0
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user