mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
fix examples and readme
This commit is contained in:
1 parent
2fb9d426c7
commit
d8ed4f387d
12 files changed
+35
-22
No files matched your search
@@ -12,7 +12,7 @@ public class ExampleButton : CustomActionButton
|
||||
public override float Cooldown => 5f;
|
||||
public override float EffectDuration => 0f;
|
||||
public override int MaxUses => 5;
|
||||
public override LoadableAsset<Sprite> Sprite { get; } = new LoadableResourceAsset("MiraAPI.Resources.ExampleButton.png");
|
||||
public override LoadableAsset<Sprite> Sprite { get; } = ExampleAssets.ExampleButton;
|
||||
|
||||
protected override void OnClick()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using MiraAPI.Utilities.Assets;
|
||||
|
||||
namespace MiraAPI.Example;
|
||||
|
||||
public static class ExampleAssets
|
||||
{
|
||||
public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png");
|
||||
public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.png");
|
||||
}
|
||||
@@ -23,7 +23,12 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MiraAPI\MiraAPI.csproj" />
|
||||
<ProjectReference Include="..\MiraAPI\MiraAPI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\ExampleButton.png" />
|
||||
<EmbeddedResource Include="Resources\FortniteBanner.jpeg" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
File renamed without changes.
@@ -12,6 +12,6 @@ public class CustomRole : ImpostorRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Orange;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => MiraAssets.Banner;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
}
|
||||
@@ -12,6 +12,6 @@ public class CustomRole2 : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.AcceptedGreen;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => MiraAssets.Banner;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
}
|
||||
@@ -12,6 +12,6 @@ public class CustomRole3 : CrewmateRole, ICustomRole
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Brown;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => MiraAssets.Banner;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => ExampleAssets.Banner;
|
||||
|
||||
}
|
||||
@@ -13,10 +13,8 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\Cog.png" />
|
||||
<EmbeddedResource Include="Resources\CogActive.png" />
|
||||
<EmbeddedResource Include="Resources\FortniteBanner.jpeg" />
|
||||
<EmbeddedResource Include="Resources\NextButton.png" />
|
||||
<EmbeddedResource Include="Resources\NextButtonActive.png" />
|
||||
<EmbeddedResource Include="Resources\ExampleButton.png" />
|
||||
<EmbeddedResource Include="Resources\Empty.png" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB |
@@ -7,5 +7,4 @@ public static class MiraAssets
|
||||
public static readonly LoadableResourceAsset NextButton = new("MiraAPI.Resources.NextButton.png");
|
||||
public static readonly LoadableResourceAsset NextButtonActive = new("MiraAPI.Resources.NextButtonActive.png");
|
||||
public static readonly LoadableResourceAsset Cog = new("MiraAPI.Resources.Cog.png");
|
||||
public static readonly LoadableResourceAsset Banner = new("MiraAPI.Resources.FortniteBanner.jpeg");
|
||||
}
|
||||
@@ -27,28 +27,28 @@ Roles are very simple in Mira API. There are 3 things you need to do to create a
|
||||
2. Implement the `ICustomRole` interface from Mira API.
|
||||
3. Add the `[RegisterCustomRole]` attribute to the class.
|
||||
|
||||
See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/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.
|
||||
|
||||
## Options
|
||||
Options are also very simple in Mira API. Options are split up into Groups and Options. Every Option needs to be in a Group.
|
||||
|
||||
To create a group, you need to create a class that implements the `IModdedOptionGroup` interface. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required.
|
||||
To create a group, you need to create a class that inherits from the `AbstractOptionGroup` abstract class. Groups contain 4 properties, `GroupName`, `GroupColor`, `GroupVisible`, and `AdvancedRole`. Only the `GroupName` is required.
|
||||
|
||||
Here is an example of a group class:
|
||||
```csharp
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
public class MyOptionsGroup : AbstractOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options"; // this is required
|
||||
public override string GroupName => "My Options"; // this is required
|
||||
|
||||
[ModdedNumberOption("My Number Option", min: 0, max: 10)]
|
||||
public float MyNumberOption { get; set; } = 5f;
|
||||
}
|
||||
```
|
||||
|
||||
You can access any group class using the `ModdedGroupSingleton` class like this:
|
||||
You can access any group class using the `OptionGroupSingleton` class like this:
|
||||
```
|
||||
// MyOptionsGroup is a class that implements IModdedOptionGroup
|
||||
var myGroup = ModdedGroupSingleton<MyOptionsGroup>.Instance; // gets the instance of the group
|
||||
// MyOptionsGroup is a class that inherits from AbstractOptionGroup
|
||||
var myGroup = OptionGroupSingleton<MyOptionsGroup>.Instance; // gets the instance of the group
|
||||
System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console
|
||||
```
|
||||
|
||||
@@ -74,7 +74,7 @@ Here is a full list of ModdedOption classes you can use:
|
||||
- `ModdedStringOption`
|
||||
- `ModdedToggleOption`
|
||||
|
||||
To see a full example of an options class, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleOptions.cs).
|
||||
To see a full example of an options class, see [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/ExampleOptions.cs).
|
||||
|
||||
### Role Options
|
||||
|
||||
@@ -82,10 +82,10 @@ You can also specify a role type for an option or option group.
|
||||
|
||||
To set the role type for an entire group, set the `AdvancedRole` property on that group like this:
|
||||
```csharp
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
public class MyOptionsGroup : AbstractOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options";
|
||||
public Type AdvancedRole => typeof(MyRole); // this is the role that will have these options
|
||||
public override string GroupName => "My Options";
|
||||
public override Type AdvancedRole => typeof(MyRole); // this is the role that will have these options
|
||||
|
||||
[ModdedNumberOption("Ability Uses", min: 0, max: 10)]
|
||||
public float AbilityUses { get; set; } = 5f;
|
||||
@@ -95,9 +95,9 @@ public class MyOptionsGroup : IModdedOptionGroup
|
||||
To set the role type for individual options, specify the `roleType` parameter in the option like this:
|
||||
```csharp
|
||||
// this group doesnt specify a role, so it will show up in the global settings
|
||||
public class MyOptionsGroup : IModdedOptionGroup
|
||||
public class MyOptionsGroup : AbstractOptionGroup
|
||||
{
|
||||
public string GroupName => "My Options";
|
||||
public override string GroupName => "My Options";
|
||||
|
||||
// this option will only show up in the settings for MyRole
|
||||
[ModdedNumberOption("Ability Uses", min: 0, max: 10, roleType: typeof(MyRole))]
|
||||
@@ -115,7 +115,7 @@ Mira API provides a simple interface for adding ability buttons to the game. The
|
||||
|
||||
The button API is simple, but provides a lot of flexibility. There are various methods you can override to customize the behaviour of your button. See [this file](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI/Hud/CustomActionButton.cs) for a full list of methods you can override.
|
||||
|
||||
An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleButton.cs).
|
||||
An example button can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Buttons/ExampleButton.cs).
|
||||
|
||||
## Assets
|
||||
|
||||
@@ -138,6 +138,8 @@ LoadableAsset<Sprite> buttonAsset = new LoadableResourceAsset("ExampleMod.Resour
|
||||
Sprite button = buttonSpriteAsset.LoadAsset();
|
||||
```
|
||||
|
||||
You can view an example file [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/ExampleAssets.cs).
|
||||
|
||||
You can create your own asset loaders by inheriting from `LoadableAsset<T>` and implementing the `LoadAsset` method.
|
||||
|
||||
# Disclaimer
|
||||
|
||||
Reference in new issue
Block a user