diff --git a/MiraAPI/Hud/CustomButtonManager.cs b/MiraAPI/Hud/CustomButtonManager.cs
index 9ea1953..b1e0977 100644
--- a/MiraAPI/Hud/CustomButtonManager.cs
+++ b/MiraAPI/Hud/CustomButtonManager.cs
@@ -21,16 +21,14 @@ public static class CustomButtonManager
///
/// Gets a list of all registered button-specific s.
///
- public static ReadOnlyDictionary EventTypes { get; internal set; } = new(
- new Dictionary
- { });
+ public static ReadOnlyDictionary EventTypes { get; internal set; } = new(new Dictionary
+ { });
///
/// Gets a list of all registered button-specific s.
///
- public static ReadOnlyDictionary CancelledEventTypes { get; internal set; } = new(
- new Dictionary
- { });
+ public static ReadOnlyDictionary CancelledEventTypes { get; internal set; } = new(new Dictionary
+ { });
internal static readonly List CustomButtons = [];
internal static readonly Dictionary ButtonEventTypes = [];
diff --git a/MiraAPI/Roles/CustomRoleManager.cs b/MiraAPI/Roles/CustomRoleManager.cs
index 91c3763..763f5d0 100644
--- a/MiraAPI/Roles/CustomRoleManager.cs
+++ b/MiraAPI/Roles/CustomRoleManager.cs
@@ -141,18 +141,13 @@ public static class CustomRoleManager
roleBehaviour.CanVent = customRole.Configuration.CanUseVent || customRole.Configuration.GetsVentData;
roleBehaviour.DefaultGhostRole = customRole.Configuration.GhostRole;
roleBehaviour.MaxCount = customRole.Configuration.MaxRoleCount;
- if (customRole.Configuration.OptionsScreenshot != null)
- {
- roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot.LoadAsset();
- }
- else
- {
- roleBehaviour.RoleScreenshot = Sprite.Create(
+ roleBehaviour.RoleScreenshot = customRole.Configuration.OptionsScreenshot != null
+ ? customRole.Configuration.OptionsScreenshot.LoadAsset()
+ : Sprite.Create(
null,
new Rect(0, 0, 370, 230),
Vector2.one / 2,
100);
- }
_emptySettings ??= new(0);
_emptyKillAnimations ??= new(0);
diff --git a/MiraAPI/Utilities/Assets/LoadableBundleSubAsset.cs b/MiraAPI/Utilities/Assets/LoadableBundleSubAsset.cs
index ef7aea3..1ff0558 100644
--- a/MiraAPI/Utilities/Assets/LoadableBundleSubAsset.cs
+++ b/MiraAPI/Utilities/Assets/LoadableBundleSubAsset.cs
@@ -27,11 +27,12 @@ public class LoadableBundleSubAsset(string name, LoadableBundleSubAssetHolder as
var loadedAsset = assetHolder.SubSprites.FirstOrDefault(x => x.name == name);
- if (loadedAsset == null)
+ if (!loadedAsset)
{
throw new InvalidOperationException($"INVALID ASSETS: {name}");
}
- LoadedAsset = loadedAsset;
+
+ LoadedAsset = loadedAsset!;
return LoadedAsset;
}
}
diff --git a/MiraAPI/Utilities/Assets/LoadableBundleSubAssetHolder.cs b/MiraAPI/Utilities/Assets/LoadableBundleSubAssetHolder.cs
index 3b84d8d..19f968c 100644
--- a/MiraAPI/Utilities/Assets/LoadableBundleSubAssetHolder.cs
+++ b/MiraAPI/Utilities/Assets/LoadableBundleSubAssetHolder.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using HarmonyLib;
using Il2CppInterop.Runtime;
@@ -12,6 +13,14 @@ namespace MiraAPI.Utilities.Assets;
///
public class LoadableBundleSubAssetHolder
{
+ private readonly string[] spriteNames;
+ private readonly AssetBundle bundle;
+
+ ///
+ /// Gets the sprites contained within the asset.
+ ///
+ public Sprite[] SubSprites { get; private set; }
+
///
/// Initializes a new instance of the class.
///
@@ -19,8 +28,8 @@ public class LoadableBundleSubAssetHolder
/// The that contains the assets.
public LoadableBundleSubAssetHolder(string[] names, AssetBundle bundle)
{
- Bundle = bundle;
- SpriteNames = names;
+ this.bundle = bundle;
+ spriteNames = names;
}
///
@@ -30,26 +39,30 @@ public class LoadableBundleSubAssetHolder
/// The that contains the assets.
public LoadableBundleSubAssetHolder(string name, AssetBundle bundle)
{
- Bundle = bundle;
- SpriteNames = [name];
+ this.bundle = bundle;
+ spriteNames = [name];
}
- internal string[] SpriteNames = [];
- internal AssetBundle Bundle;
- public Sprite[] SubSprites = [];
+ ///
+ /// Attempts to load all of the sprite assets within the sprite sheet.
+ ///
+ /// Thrown if the asset is not actually a sprite sheet.
+ [SuppressMessage("Style", "IDE0270:Use coalesce expression", Justification = "Null coalescing bypasses Unity lifetime checks.")]
public void TryInit()
{
if (SubSprites.Length == 0)
{
var newSprites = Array.Empty();
- foreach (var name in SpriteNames)
+
+ foreach (var name in spriteNames)
{
- var loadedAssets = Bundle.LoadAssetWithSubAssets(name, Il2CppType.From(typeof(Sprite))).ToArray();
+ var loadedAssets = bundle.LoadAssetWithSubAssets(name, Il2CppType.From(typeof(Sprite))).ToArray();
if (loadedAssets == null)
{
throw new InvalidOperationException($"INVALID ASSETS: {name}");
}
+
foreach (var obj in loadedAssets)
{
var img = obj.TryCast();