Merge remote-tracking branch 'upstream/master' into develop

This commit is contained in:
EvilFactory
2024-04-24 12:20:11 -03:00
397 changed files with 15250 additions and 6473 deletions

View File

@@ -175,5 +175,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();
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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)