mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
modifiers README
This commit is contained in:
1 parent
892c5c7c70
commit
87a1be7410
8 files changed
+37
-16
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
using MiraAPI.Hud;
|
using MiraAPI.Example.Modifiers;
|
||||||
|
using MiraAPI.Hud;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
@@ -23,6 +24,6 @@ public class ExampleButton : CustomActionButton
|
|||||||
|
|
||||||
public override bool Enabled(RoleBehaviour role)
|
public override bool Enabled(RoleBehaviour role)
|
||||||
{
|
{
|
||||||
return PlayerControl.LocalPlayer.HasModifier<ModifierExample>();
|
return PlayerControl.LocalPlayer.HasModifier<GameModifierExample>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using Reactor.Utilities.Attributes;
|
using Reactor.Utilities.Attributes;
|
||||||
using Reactor.Utilities.ImGui;
|
using Reactor.Utilities.ImGui;
|
||||||
using System;
|
using System;
|
||||||
|
using MiraAPI.Example.Modifiers;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example;
|
||||||
|
|||||||
+5
-4
@@ -1,11 +1,12 @@
|
|||||||
using MiraAPI.Modifiers.Types;
|
using MiraAPI.Modifiers;
|
||||||
|
using MiraAPI.Modifiers.Types;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example.Modifiers;
|
||||||
|
|
||||||
[RegisterModifier]
|
[RegisterModifier]
|
||||||
public class ModifierExample : GameModifier
|
public class GameModifierExample : GameModifier
|
||||||
{
|
{
|
||||||
public override string ModifierName => "Example Modifier";
|
public override string ModifierName => "Example Game Modifier";
|
||||||
|
|
||||||
public override bool CanVent()
|
public override bool CanVent()
|
||||||
{
|
{
|
||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
using MiraAPI.Modifiers.Types;
|
using MiraAPI.Modifiers;
|
||||||
|
using MiraAPI.Modifiers.Types;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example.Modifiers;
|
||||||
|
|
||||||
[RegisterModifier]
|
[RegisterModifier]
|
||||||
public class ModifierTimerExample : TimedModifier
|
public class ModifierTimerExample : TimedModifier
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
namespace MiraAPI.Modifiers;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class RegisterModifierAttribute : Attribute;
|
public class RegisterModifierAttribute : Attribute;
|
||||||
@@ -223,7 +223,7 @@ public static class RoleSettingMenuPatches
|
|||||||
{
|
{
|
||||||
ICustomRole customRole = role as ICustomRole;
|
ICustomRole customRole = role as ICustomRole;
|
||||||
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
__instance.roleDescriptionText.text = customRole.RoleLongDescription;
|
||||||
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(role.StringName, Array.Empty<Il2CppSystem.Object>());
|
__instance.roleTitleText.text = DestroyableSingleton<TranslationController>.Instance.GetString(role.StringName, []);
|
||||||
__instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100);
|
__instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100);
|
||||||
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
|
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
|
||||||
__instance.roleHeaderSprite.color = customRole.RoleColor;
|
__instance.roleHeaderSprite.color = customRole.RoleColor;
|
||||||
|
|||||||
@@ -71,14 +71,14 @@ public static class Extensions
|
|||||||
return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour.Equals(optionBehaviour));
|
return ModdedOptionsManager.ModdedOptions.Values.Any(opt => opt.OptionBehaviour && opt.OptionBehaviour.Equals(optionBehaviour));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModifierComponent GetModifierComponent(this PlayerControl player)
|
public static ModifierComponent? GetModifierComponent(this PlayerControl player)
|
||||||
{
|
{
|
||||||
return player.GetComponent<ModifierComponent>();
|
return player.GetComponent<ModifierComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<T> Randomize<T>(this List<T> list)
|
public static List<T> Randomize<T>(this List<T> list)
|
||||||
{
|
{
|
||||||
List<T> randomizedList = new List<T>();
|
List<T> randomizedList = [];
|
||||||
System.Random rnd = new();
|
System.Random rnd = new();
|
||||||
while (list.Count > 0)
|
while (list.Count > 0)
|
||||||
{
|
{
|
||||||
@@ -89,13 +89,13 @@ public static class Extensions
|
|||||||
return randomizedList;
|
return randomizedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasModifier<T>(this PlayerControl player) where T : BaseModifier
|
public static bool HasModifier<T>(this PlayerControl? player) where T : BaseModifier
|
||||||
{
|
{
|
||||||
return player is not null && player.GetModifierComponent() is not null && player.GetModifierComponent().ActiveModifiers.Exists(x => x is T);
|
return player?.GetModifierComponent() != null && player.GetModifierComponent().ActiveModifiers.Exists(x => x is T);
|
||||||
}
|
}
|
||||||
public static bool HasModifier(this PlayerControl player, uint id)
|
public static bool HasModifier(this PlayerControl? player, uint id)
|
||||||
{
|
{
|
||||||
return player is not null && player.GetModifierComponent() is not null && player.GetModifierComponent().ActiveModifiers.Exists(x => x.ModifierId == id);
|
return player?.GetModifierComponent() != null && player.GetModifierComponent().ActiveModifiers.Exists(x => x.ModifierId == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddModifier<T>(this PlayerControl player) where T : BaseModifier
|
public static void AddModifier<T>(this PlayerControl player) where T : BaseModifier
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
A thorough, but simple, Among Us modding API and utility library that covers:
|
A thorough, but simple, Among Us modding API and utility library that covers:
|
||||||
- Roles
|
- Roles
|
||||||
- Options
|
- Options
|
||||||
|
- Modifiers
|
||||||
- Buttons
|
- Buttons
|
||||||
- Assets
|
- Assets
|
||||||
- Compatibility
|
- Compatibility
|
||||||
- ~~Modifiers~~ (coming soon)
|
|
||||||
- ~~Game Modes~~ (coming soon)
|
- ~~Game Modes~~ (coming soon)
|
||||||
|
|
||||||
Mira API strives to be simple and easy to use, while also using as many base game elements as possible. The result is a less intrusive, better modding API that covers general use cases.
|
Mira API strives to be simple and easy to use, while also using as many base game elements as possible. The result is a less intrusive, better modding API that covers general use cases.
|
||||||
@@ -62,6 +62,21 @@ Mira API handles everything else, from adding the proper options to the settings
|
|||||||
|
|
||||||
See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Roles/CustomRole.cs) for a code example.
|
See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Roles/CustomRole.cs) for a code example.
|
||||||
|
|
||||||
|
## Modifiers
|
||||||
|
Mira API uses a different definition of 'modifiers' than other Among Us mods. For example, in Town Of Us, a modifier is an extra "ability" that is applied on top of the base role. However, in Mira API, modifiers are very flexible. A modifier is anything that "modifiers" a player's abilities or interactions.
|
||||||
|
|
||||||
|
Mira provides 3 classes for working with modifiers:
|
||||||
|
- `BaseModifier`: The base for every modifier. You MUST add and remove this modifier from a player manually!
|
||||||
|
- `TimedModifier`: A modifier that has a time limit. This modifier has to be added manually, but will automatically remove itself after the time limit
|
||||||
|
- `GameModifier`: This works like the typical TOU modifier, where it is automatically applied at the beginning of the game, then removed at the end.
|
||||||
|
|
||||||
|
Modifiers provide various overridable functions and properties for custom behaviour. They can also be used for "tagging" a player. You can check if a player has a modifier through the extension method `HasModifier` on a `PlayerControl` object.
|
||||||
|
|
||||||
|
To start using a modifier, pick one of the base classes above and create a class that inherits from it. Implement the properties and methods you would like, then add the `[RegisterModifier]` attribute to the class.
|
||||||
|
|
||||||
|
An example Game modifier can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Modifiers/ExampleGameModifier.cs).
|
||||||
|
An example Timer modifier can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Modifiers/ModifierTimerExample.cs).
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
Options are also very simple in Mira API. Mira API handles all the hard work behind the scenes, so developers only have to follow a few steps to create their custom options. The Options API is split up into Groups and Options. Every Option needs to be in a Group.
|
Options are also very simple in Mira API. Mira API handles all the hard work behind the scenes, so developers only have to follow a few steps to create their custom options. The Options API is split up into Groups and Options. Every Option needs to be in a Group.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user