-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from zelzmiy/docs
Docs for custom traits
- Loading branch information
Showing
3 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ pnpm-debug.log* | |
|
||
# macOS-specific files | ||
.DS_Store | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
title: Traits | ||
description: Documentation on how to add a custom trait using Cult of the Lamb API | ||
--- | ||
|
||
## Creating Traits | ||
|
||
To create an trait, you first need to make a class overriding `CustomTrait`. | ||
Example: | ||
|
||
```csharp | ||
using COTL_API.CustomTraits; | ||
using UnityEngine; | ||
using System.IO; | ||
``` | ||
|
||
```csharp | ||
[HarmonyPatch] | ||
internal class ExampleTrait : CustomTrait | ||
{ | ||
public override string InternalName => "ExampleTrait"; | ||
|
||
public override bool Positive => true; | ||
|
||
// exclusive traits are traits that can't appear along with this trait! | ||
// if they are also custom defined trait, you only need to exclude it on | ||
// one of the traits. | ||
public override List<FollowerTrait.TraitType> ExclusiveTraits => | ||
[ | ||
FollowerTrait.TraitType.RoyalPooper | ||
]; | ||
|
||
public override TraitFlags TraitFlags => TraitFlags.RareStartingTrait; | ||
|
||
public override string LocalizedTitle() => "Example Trait"; | ||
|
||
public override string LocalizedDescription() => "this trait is just an example :)."; | ||
|
||
public override Sprite Icon => TextureHelper.CreateSpriteFromPath(Path.Combine(Plugin.PluginPath, "Assets", "ExampleTrait.png")); | ||
|
||
// by default, no behaviour for custom traits is added. use patches check in | ||
// your own code for the presence of the trait, and change the game's | ||
// behvaiour accordingly. | ||
[HarmonyPatch(typeof(FollowerBrain), nameof(FollowerBrain.GetPoopType))] | ||
[HarmonyPrefix] | ||
private static bool FollowerBrain_GetPoopType(ref FollowerBrain __instance, ref StructureBrain.TYPES __result) | ||
{ | ||
if (!__instance.Info.Traits.Contains(Plugin.ExampleTrait)) return true; | ||
|
||
__result = StructureBrain.TYPES.POOP_RAINBOW; | ||
DataManager.Instance.DaySinceLastSpecialPoop = TimeManager.CurrentDay; | ||
return false; | ||
|
||
} | ||
} | ||
``` | ||
|
||
There is no diffrence between cult traits and regular traits. Cult traits are added by `FollowerTrait.AddCultTrait(FollowerTrait.TraitType);` and regular ones by `followerBrain.AddTrait(FollowerTrait.TraitType);` on a follower's brain. | ||
|
||
`CustomTrait` supports the following overrides: | ||
| Type | Name | Default | | ||
|-|-|-| | ||
| string | InternalName | \[REQUIRED\] | | ||
|bool|Positive| true| | ||
|bool|IsTraitUnavailable()|false| | ||
|Sprite|Icon|TextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath("placeholder.png"));| | ||
|List<FollowerTrait.TraitType>| ExclusiveTraits|[]| | ||
TraitFlags|TraitFlags|TraitFlags.None| | ||
|string|LocalizedTitle()|LocalizationManager.GetTranslation($"Traits/{ModPrefix}.{InternalName}")| | ||
|string|LocalizedDescription()|LocalizationManager.GetTranslation($"Traits/{InternalName}.description")| | ||
|
||
## Adding Traits | ||
|
||
To add a trait to the game, simply use `CustomTraitManager.Add()`. | ||
Example: | ||
|
||
```csharp | ||
using COTL_API.CustomTraits; | ||
public static FollowerTrait.TraitType ExampleTrait { get; private set; } | ||
``` | ||
|
||
```csharp | ||
private void Awake() | ||
{ | ||
ExampleTrait = CustomTraitManager.Add(new ExampleTrait()); | ||
} | ||
``` | ||
|
||
Assigning the result of `CustomTraitManager.Add()` allows you to reference that trait elsewhere in your code using `Plugin.ExampleTrait`. | ||
|
||
## Final Steps | ||
|
||
For the icon to load, you need to put it in the appropriate location. For the example, this would be `/Assets/ExampleTrait.png` relative to the root folder containing the .dll | ||
Directory structure: | ||
|
||
``` | ||
📂plugins | ||
┣📂Assets | ||
┃ ┗🖼️ExampleTrait.png | ||
┗📜mod_name.dll | ||
``` |