Update Docs Again

This commit is contained in:
Ben C 2022-08-29 17:31:01 -04:00
parent 6aad0edd33
commit 1c99f6c3d4
No known key found for this signature in database
GPG Key ID: 7F8F04504B670474
2 changed files with 12 additions and 9 deletions

View File

@ -52,9 +52,14 @@ public interface INewHorizons
UnityEvent<string> GetBodyLoadedEvent(); UnityEvent<string> GetBodyLoadedEvent();
/// <summary> /// <summary>
/// Gets an object in the `extras` object of a config, returns null if the key doesn't exist /// Gets an object in the `extras` object of a body config, returns null if the key doesn't exist
/// </summary> /// </summary>
object GetExtraModule(Type moduleType, string extrasModuleName, string planetName); object GetExtraModuleForBody(Type moduleType, string extrasModuleName, string planetName);
/// <summary>
/// Gets an object in the `extras` object of a system config, returns null if the key doesn't exist
/// </summary>
object GetExtraModuleForSystem(Type moduleType, string extrasModuleName, string systemName);
/// <summary> /// <summary>
/// Allows you to overwrite the default system. This is where the player is respawned after dying. /// Allows you to overwrite the default system. This is where the player is respawned after dying.

View File

@ -4,8 +4,6 @@ Description: A guide on extending config files with the New Horizons API
Sort_Priority: 5 Sort_Priority: 5
--- ---
<!-- TODO: When I do systems, some methods will probably be renamed so make sure to update this tutorial -->
# Extending Configs # Extending Configs
This guide will explain how to use the API to add new features to New Horizons. This guide will explain how to use the API to add new features to New Horizons.
@ -25,9 +23,9 @@ Addon developers will add a key to the `extras` object in the root of the config
} }
``` ```
**It's up to the addon dev to list your mod as a dependency!** Your mod will then use the API's `GetExtraModuleForBody` method to obtain the `myCoolExtensionData` object.
Your mod will then use the API's `GetExtraModule` method to obtain the `myCoolExtensionData` object. **It's up to the addon dev to list your mod as a dependency!**
## Extending Planets ## Extending Planets
@ -48,13 +46,13 @@ public class MyCoolExtensionData {
} }
``` ```
Then, use the `GetExtraModule` method: Then, use the `GetExtraModuleForBody` method:
```cs ```cs
var api = ModHelper.Interactions.TryGetModApi<INewHorizons>("xen.NewHorizons"); var api = ModHelper.Interactions.TryGetModApi<INewHorizons>("xen.NewHorizons");
api.GetBodyLoadedEvent().AddListener((name) => { api.GetBodyLoadedEvent().AddListener((name) => {
ModHelper.Console.WriteLine($"Body: {name} Loaded!"); ModHelper.Console.WriteLine($"Body: {name} Loaded!");
var potentialData = api.GetExtraModule(typeof(MyCoolExtensionData), "myCoolExtensionData", name); var potentialData = api.GetExtraModuleForBody(typeof(MyCoolExtensionData), "myCoolExtensionData", name);
// Makes sure the module is valid and not null // Makes sure the module is valid and not null
if (potentialData is MyCoolExtensionData data) { if (potentialData is MyCoolExtensionData data) {
ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!"); ModHelper.Console.WriteLine($"myCoolExtensionProperty for {name} is {data.myCoolExtensionProperty}!");
@ -64,4 +62,4 @@ api.GetBodyLoadedEvent().AddListener((name) => {
## Extending Systems ## Extending Systems
<!-- TODO --> Extending systems is the exact same as extending planets, except you use the `GetExtraModuleForSystem` method instead.