diff --git a/MiraAPI.Example/Roles/ChameleonRole.cs b/MiraAPI.Example/Roles/ChameleonRole.cs
index 13db85a..e3eb6c4 100644
--- a/MiraAPI.Example/Roles/ChameleonRole.cs
+++ b/MiraAPI.Example/Roles/ChameleonRole.cs
@@ -15,7 +15,6 @@ public class ChameloenRole : CrewmateRole, ICustomRole
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
{
- MaxRoleCount = 0,
OptionsScreenshot = ExampleAssets.Banner,
};
diff --git a/MiraAPI/Roles/CustomRoleSingleton.cs b/MiraAPI/Roles/CustomRoleSingleton.cs
new file mode 100644
index 0000000..808202c
--- /dev/null
+++ b/MiraAPI/Roles/CustomRoleSingleton.cs
@@ -0,0 +1,19 @@
+using System.Linq;
+
+namespace MiraAPI.Roles;
+
+///
+/// A utility class to get the instance of a custom role.
+///
+/// The role you are trying to access.
+public static class CustomRoleSingleton where T : ICustomRole
+{
+ private static ICustomRole? _instance;
+
+ ///
+ /// Gets the instance of the role.
+ ///
+#pragma warning disable CA1000
+ public static ICustomRole Instance => _instance ??= CustomRoleManager.CustomRoles.Values.OfType().Single();
+#pragma warning restore CA1000
+}
diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs
index 53b7798..b7adf66 100644
--- a/MiraAPI/Roles/ICustomRole.cs
+++ b/MiraAPI/Roles/ICustomRole.cs
@@ -37,18 +37,11 @@ public interface ICustomRole
///
ModdedRoleTeams Team { get; }
+ ///
+ /// Configure advanced settings of the role.
+ ///
CustomRoleConfiguration Configuration { get; }
- ///
- /// Gets the BepInEx ConfigDefinition for the amount of players that can have this role.
- ///
- ConfigDefinition NumConfigDefinition => new("Roles", $"Num {GetType().FullName}");
-
- ///
- /// Gets the BepInEx ConfigDefinition for the chance of this role being selected.
- ///
- ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}");
-
///
/// Gets the parent mod of this role.
///
@@ -62,6 +55,36 @@ public interface ICustomRole
{
}
+ internal ConfigDefinition NumConfigDefinition => new("Roles", $"Num {GetType().FullName}");
+ internal ConfigDefinition ChanceConfigDefinition => new("Roles", $"Chance {GetType().FullName}");
+
+ ///
+ /// Get the role chance option.
+ ///
+ /// The role chance option.
+ public int? GetChance()
+ {
+ if (ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out ConfigEntry entry))
+ {
+ return Mathf.Clamp(entry.Value, 0, 100);
+ }
+
+ return null;
+ }
+
+ ///
+ /// Get the role count option.
+ ///
+ /// The role count option.
+ public int? GetCount()
+ {
+ if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry entry))
+ {
+ return Mathf.Clamp(entry.Value, 0, Configuration.MaxRoleCount);
+ }
+
+ return null;
+ }
///
/// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role.
///
diff --git a/MiraAPI/Roles/RoleHintType.cs b/MiraAPI/Roles/RoleHintType.cs
index f3d5cc6..d00c5da 100644
--- a/MiraAPI/Roles/RoleHintType.cs
+++ b/MiraAPI/Roles/RoleHintType.cs
@@ -16,7 +16,7 @@ public enum RoleHintType
TaskHint,
///
- /// Use custom role tab.
+ /// Use Mira's custom role tab.
///
RoleTab,
}