v1.4.4.1 (Blood in the Water Update)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
@@ -108,5 +108,54 @@ namespace Barotrauma
|
||||
result += $"<{string.Join(", ", t.GetGenericArguments().Select(NameWithGenerics))}>";
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a type by its name, with backwards compatibility for types that have been renamed.
|
||||
/// <see cref="TypePreviouslyKnownAs"/>
|
||||
/// </summary>
|
||||
public static Type? GetTypeWithBackwardsCompatibility(string nameSpace, string typeName, bool throwOnError, bool ignoreCase)
|
||||
{
|
||||
if (Assembly.GetEntryAssembly() is not { } entryAssembly) { return null; }
|
||||
var types = entryAssembly
|
||||
.GetTypes()
|
||||
.Where(t => NameMatches(t.Namespace, nameSpace, ignoreCase));
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (NameMatches(type.Name, typeName, ignoreCase))
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
if (type.GetCustomAttribute<TypePreviouslyKnownAs>() is { } knownAsAttribute)
|
||||
{
|
||||
if (NameMatches(knownAsAttribute.PreviousName, typeName, ignoreCase))
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (throwOnError)
|
||||
{
|
||||
throw new TypeLoadException($"Could not find the type {typeName} in namespace {nameSpace}");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
static bool NameMatches(string? name1, string? name2, bool ignoreCase)
|
||||
=> string.Equals(name1, name2, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The names of generic types include the arity at the end (fancy way of saying the number of parameters, e.g. GUISelectionCarousel<T> would be GUISelectionCarousel`1)
|
||||
/// This method strips that part out.
|
||||
/// </summary>
|
||||
public static Identifier GetTypeNameWithoutGenericArity(Type type)
|
||||
{
|
||||
string name = type.Name;
|
||||
int index = name.IndexOf('`');
|
||||
return (index == -1 ? name : name.Substring(0, index)).ToIdentifier();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
/// <summary>
|
||||
/// This attribute is used to indicate that a class was previously known by a different name.
|
||||
/// This is used for backwards compatibility when we have types that are loaded from XML using reflection.
|
||||
///
|
||||
/// Only works in cases where we use <see cref="ReflectionUtils.GetTypeWithBackwardsCompatibility"/> to load the type.
|
||||
///
|
||||
/// If you wish to use this, you will need to replace the call to Type.GetType() in the load method with
|
||||
/// ReflectionUtils.GetTypeWithBackwardsCompatibility().
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class TypePreviouslyKnownAs : Attribute
|
||||
{
|
||||
public string PreviousName { get; }
|
||||
|
||||
public TypePreviouslyKnownAs(string previousName)
|
||||
{
|
||||
PreviousName = previousName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,14 @@ namespace Microsoft.Xna.Framework.Input
|
||||
_map.Add(1073742097, Keys.BrowserRefresh);
|
||||
_map.Add(1073742098, Keys.BrowserFavorites);
|
||||
_map.Add(1073742106, Keys.Sleep);
|
||||
// Map keys on an Azerty layout to the corresponding keys on a US layout
|
||||
_map.Add(178, Keys.OemTilde); // ²
|
||||
_map.Add(41, Keys.OemMinus); // )
|
||||
_map.Add(36, Keys.Add); // $
|
||||
_map.Add(249, Keys.OemQuotes); // ù
|
||||
_map.Add(42, Keys.OemPipe); // *
|
||||
_map.Add(58, Keys.OemPeriod); // :
|
||||
_map.Add(33, Keys.OemQuestion); // !
|
||||
}
|
||||
|
||||
public static Keys ToXna(int key)
|
||||
|
||||
Reference in New Issue
Block a user