From 62ec462e796fd83cecf064faceb3359a65f10669 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:55:11 -0400 Subject: [PATCH] readme updates --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fbf2979..de4f261 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,25 @@ Options are also very simple in Mira API. Options are split up into Groups and O 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. +Here is an example of a group class: +```csharp +public class MyOptionsGroup : IModdedOptionGroup +{ + public 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: ``` // MyOptionsGroup is a class that implements IModdedOptionGroup -var myGroup = ModdedGroupSingleton.Instance; +var myGroup = ModdedGroupSingleton.Instance; // gets the instance of the group +System.Out.Console.WriteLine(myGroup.MyNumberOption); // prints the value of the option to the console ``` -There are two ways to make options inside a group: +Once you have an options group, there are two ways to make the actual options: - Use an Option Attribute with a property. - Create a ModdedOption property. @@ -66,7 +78,32 @@ To see a full example of an options class, see [this file](https://github.com/Al ### Role Options -Options can also be used within a Role class to show up in that Role's settings. To set the role for an entire group, set the `AdvancedRole` property on that group. To set the role for individual options, specify the `roleType` parameter in the option. +Options can also be used within a Role class to show up in that Role's settings. + +To set the role for an entire group, set the `AdvancedRole` property on that group like this: +```csharp +public class MyOptionsGroup : IModdedOptionGroup +{ + public string GroupName => "My Options"; + public 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; +} +``` + +To set the role 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 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))] + public float AbilityUses { get; set; } = 5f; +} +``` An example can be found [here](https://github.com/All-Of-Us-Mods/MiraAPI/blob/master/MiraAPI.Example/Options/Roles/CustomRoleSettings.cs).