mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
fix warnings
scav you have committed a war crime. C# =/= python
This commit is contained in:
17 files changed
+52
-33
No files matched your search
@@ -35,4 +35,4 @@ public class ThinkButton : CustomActionButton
|
||||
{
|
||||
return role != null && role.IsImpostor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
|
||||
@@ -7,4 +7,4 @@ namespace MiraAPI.Example;
|
||||
public static class ExampleKeybinds
|
||||
{
|
||||
public static MiraKeybind NeutralWinKeybind { get; } = new("Neutral Win", KeyboardKeyCode.C, ControllerButton.RightStick, [ModifierKey.Shift]);
|
||||
}
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public abstract class CustomActionButton
|
||||
{
|
||||
ActiveInputManager.InputType.Keyboard when Keybind.CurrentKey != KeyboardKeyCode.None => Keybind.CurrentKey.ToString(),
|
||||
ActiveInputManager.InputType.Joystick => Keybind.CurrentControllerButton,
|
||||
_ => string.Empty
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
KeybindText.text = text;
|
||||
@@ -516,7 +516,8 @@ public abstract class CustomActionButton
|
||||
/// Custom action button that has a target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the target object.</typeparam>
|
||||
public abstract class CustomActionButton<T> : CustomActionButton where T : MonoBehaviour
|
||||
public abstract class CustomActionButton<T> : CustomActionButton
|
||||
where T : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the target <typeparamref name="T"/> of the button.
|
||||
@@ -576,4 +577,4 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
|
||||
SetOutline(false);
|
||||
Target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,4 +79,4 @@ public class BaseKeybind
|
||||
Handler -= action;
|
||||
#pragma warning restore CS8601 // Possible null reference assignment
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ public static class KeybindManager
|
||||
/// </summary>
|
||||
public static List<MiraKeybind> Keybinds { get; } = [];
|
||||
|
||||
[HideFromIl2Cpp] internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; set; } = [];
|
||||
[HideFromIl2Cpp]
|
||||
internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; set; } = [];
|
||||
|
||||
internal static void RewiredInit()
|
||||
{
|
||||
@@ -63,7 +64,7 @@ public static class KeybindManager
|
||||
_elementIdentifierId = elementId,
|
||||
_elementType = elementType,
|
||||
_axisRange = AxisRange.Positive,
|
||||
_axisContribution = Pole.Positive
|
||||
_axisContribution = Pole.Positive,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -154,9 +155,11 @@ public static class KeybindManager
|
||||
{
|
||||
var all = new List<MiraKeybind>();
|
||||
foreach (var keybind in Keybinds)
|
||||
{
|
||||
if (keybind.CurrentKey == keyCode && (keybind.Exclusive || !exclusiveCheck))
|
||||
all.Add(keybind);
|
||||
}
|
||||
|
||||
return [.. all];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public static class KeybindUtils
|
||||
"square" => "□",
|
||||
"circle" => "○",
|
||||
"triangle" => "△",
|
||||
_ => name
|
||||
_ => name,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -112,4 +112,4 @@ public static class KeybindUtils
|
||||
|
||||
return KeyboardKeyCode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,4 @@ public static class MiraGlobalKeybinds
|
||||
/// Gets the keybind for Tertiary modifier abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind ModifierTertiaryAbility { get; } = new("Modifier Tertiary Ability", KeyboardKeyCode.P);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,8 @@ public class MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ModifierK
|
||||
/// <param name="defaultControllerButton">The default controller button.</param>
|
||||
/// <param name="modifierKeys">Up to 3 optional <see cref="ModifierKey"/>s for the keyboard binding.</param>
|
||||
/// <param name="exclusive">Is exclusive.</param>
|
||||
public MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ControllerButton defaultControllerButton, ModifierKey[]? modifierKeys = null, bool exclusive = true) : this(name, defaultKeycode, modifierKeys, exclusive)
|
||||
public MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ControllerButton defaultControllerButton, ModifierKey[]? modifierKeys = null, bool exclusive = true)
|
||||
: this(name, defaultKeycode, modifierKeys, exclusive)
|
||||
{
|
||||
DefaultControllerButton = defaultControllerButton;
|
||||
}
|
||||
@@ -59,4 +60,4 @@ public class MiraKeybind(string name, KeyboardKeyCode? defaultKeycode, ModifierK
|
||||
{
|
||||
return $"{Name} ({Id})";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,4 @@ namespace MiraAPI.Keybinds;
|
||||
/// Used to mark a class for <see cref="MiraKeybind"/>s registration.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterCustomKeybindsAttribute : Attribute;
|
||||
public class RegisterCustomKeybindsAttribute : Attribute;
|
||||
@@ -21,4 +21,4 @@ public class VanillaKeybind : BaseKeybind
|
||||
RewiredInputAction = KeybindUtils.GetInputActionById(id);
|
||||
Id = RewiredInputAction != null ? RewiredInputAction.name : id.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ namespace MiraAPI.Keybinds;
|
||||
/// Singleton for getting a <see cref="VanillaKeybind"/> by <see cref="ActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"><see cref="ActionButton"/> type.</typeparam>
|
||||
public static class VanillaKeybinding<T> where T : ActionButton
|
||||
public static class VanillaKeybinding<T>
|
||||
where T : ActionButton
|
||||
{
|
||||
[SuppressMessage("Major Code Smell", "S2743:Static fields should not be used in generic types", Justification = "The instance holds a reference to the button that defines the class's type parameter.")]
|
||||
private static VanillaKeybind? _instance;
|
||||
@@ -16,4 +17,4 @@ public static class VanillaKeybinding<T> where T : ActionButton
|
||||
/// </summary>
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a vanilla keybind.")]
|
||||
public static VanillaKeybind Instance => _instance ??= KeybindManager.VanillaKeybinds[typeof(T)];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
@@ -43,6 +42,7 @@ public static class HudManagerPatches
|
||||
if (!_storedButtonsParent) _storedButtonsParent = HudManager.Instance.transform.FindChild("Buttons");
|
||||
|
||||
if (_storedButtonsParent)
|
||||
{
|
||||
foreach (var aspect in _storedButtonsParent.GetComponentsInChildren<AspectPosition>(true))
|
||||
{
|
||||
if (!aspect.gameObject) continue;
|
||||
@@ -55,6 +55,7 @@ public static class HudManagerPatches
|
||||
aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor);
|
||||
aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var button in HudManager.Instance.GetComponentsInChildren<ActionButton>(true))
|
||||
{
|
||||
@@ -181,7 +182,7 @@ public static class HudManagerPatches
|
||||
{
|
||||
ButtonLocation.BottomLeft => BottomLeft.transform,
|
||||
ButtonLocation.BottomRight => BottomRight,
|
||||
_ => null
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (location is null) continue;
|
||||
@@ -212,7 +213,7 @@ public static class HudManagerPatches
|
||||
{ __instance.ReportButton.gameObject, 7 },
|
||||
{ __instance.ImpostorVentButton.gameObject, 50 },
|
||||
{ __instance.SabotageButton.gameObject, 4 },
|
||||
{ __instance.AbilityButton.gameObject, 49 }
|
||||
{ __instance.AbilityButton.gameObject, 49 },
|
||||
};
|
||||
|
||||
foreach (var kvp in vanillaButtons)
|
||||
@@ -253,6 +254,7 @@ public static class HudManagerPatches
|
||||
if (localPlayer.Data == null) return;
|
||||
|
||||
foreach (var button in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
try
|
||||
{
|
||||
button.SetActive(isActive, role);
|
||||
@@ -261,6 +263,7 @@ public static class HudManagerPatches
|
||||
{
|
||||
Error($"Failed to set custom button {button.GetType().Name} active: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(HudManager.Update))]
|
||||
@@ -279,11 +282,15 @@ public static class HudManagerPatches
|
||||
|
||||
var player = ReInput.players.GetPlayer(0);
|
||||
foreach (var entry in KeybindManager.Keybinds)
|
||||
{
|
||||
if (entry.RewiredInputAction != null && player.GetButtonDown(entry.RewiredInputAction.id))
|
||||
entry.Invoke();
|
||||
}
|
||||
|
||||
foreach (var entry in KeybindManager.VanillaKeybinds.Values)
|
||||
{
|
||||
if (player.GetButtonDown(entry.Id))
|
||||
entry.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public static class ControlMapperPatches
|
||||
{
|
||||
ControllerType.Keyboard => conflicts.ContainsKey(map.keyboardKeyCode),
|
||||
ControllerType.Joystick => controllerConflicts.Any(x => x.controllerMap.id == map.controllerMap.id && x.id == map.id),
|
||||
_ => false
|
||||
_ => false,
|
||||
};
|
||||
if (hasConflict)
|
||||
{
|
||||
@@ -79,4 +79,4 @@ public static class ControlMapperPatches
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public static class KeybindMenuPatch
|
||||
{ typeof(ReportButton), new VanillaKeybind(7) },
|
||||
{ typeof(VentButton), new VanillaKeybind(50) },
|
||||
{ typeof(SabotageButton), new VanillaKeybind(4) },
|
||||
{ typeof(AbilityButton), new VanillaKeybind(49) }
|
||||
{ typeof(AbilityButton), new VanillaKeybind(49) },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,4 @@ public static class OptionsMenuBehaviourPatch
|
||||
_remapRollover.OverColor = conflicts ? new Color32(255, 55, 55, 255) : Palette.AcceptedGreen;
|
||||
if (!conflicts && _remapBackground.color == Color.red) _remapBackground.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,8 +316,10 @@ public static class Extensions
|
||||
try
|
||||
{
|
||||
foreach (var mat in renderer.materials)
|
||||
{
|
||||
if (mat != null)
|
||||
UnityEngine.Object.Destroy(mat);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -437,6 +439,7 @@ public static class Extensions
|
||||
tie = true;
|
||||
var result = new KeyValuePair<byte, int>(byte.MaxValue, int.MinValue);
|
||||
foreach (var keyValuePair in self)
|
||||
{
|
||||
if (keyValuePair.Value > result.Value)
|
||||
{
|
||||
result = keyValuePair;
|
||||
@@ -446,6 +449,7 @@ public static class Extensions
|
||||
{
|
||||
tie = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -461,6 +465,7 @@ public static class Extensions
|
||||
tie = true;
|
||||
var result = new KeyValuePair<byte, float>(byte.MaxValue, int.MinValue);
|
||||
foreach (var keyValuePair in self)
|
||||
{
|
||||
if (keyValuePair.Value > result.Value)
|
||||
{
|
||||
result = keyValuePair;
|
||||
@@ -470,6 +475,7 @@ public static class Extensions
|
||||
{
|
||||
tie = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -687,7 +693,8 @@ public static class Extensions
|
||||
/// <param name="predicate">Optional predicate to test if the <typeparamref name="T"/> is valid.</param>
|
||||
/// <typeparam name="T">The type of the object.</typeparam>
|
||||
/// <returns>The <typeparamref name="T"/> if it was found, or <see langword="null"/> if there is none within the radius.</returns>
|
||||
public static T? GetNearestObjectOfType<T>(this PlayerControl playerControl, float radius, ContactFilter2D filter, string? colliderTag = null, Predicate<T>? predicate = null) where T : Component
|
||||
public static T? GetNearestObjectOfType<T>(this PlayerControl playerControl, float radius, ContactFilter2D filter, string? colliderTag = null, Predicate<T>? predicate = null)
|
||||
where T : Component
|
||||
{
|
||||
return Helpers.GetNearestObjectsOfType<T>(playerControl.GetTruePosition(), radius, filter, colliderTag).Find(predicate ?? (component => component));
|
||||
}
|
||||
@@ -709,7 +716,7 @@ public static class Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fixed version of <see cref="Reactor.Utilities.Extensions.UnityExtensions.SetOutline(Renderer, Color?)"/>.
|
||||
/// Fixed version of <see cref="UnityExtensions.SetOutline(Renderer, Color?)"/>.
|
||||
/// </summary>
|
||||
/// <param name="renderer">The <see cref="Renderer"/> you want to update the outline for.</param>
|
||||
/// <param name="color">The outline <see cref="Color"/>.</param>
|
||||
@@ -752,7 +759,7 @@ public static class Extensions
|
||||
_actionId = action.id,
|
||||
_elementType = ControllerElementType.Button,
|
||||
_axisContribution = Pole.Positive,
|
||||
_keyboardKeyCode = key
|
||||
_keyboardKeyCode = key,
|
||||
};
|
||||
|
||||
if (modifiers != null)
|
||||
@@ -765,4 +772,4 @@ public static class Extensions
|
||||
userData.keyboardMaps[0].actionElementMaps.Add(map);
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user