Skip to content

Commit

Permalink
Merge pull request #106 from zelzmiy/docs
Browse files Browse the repository at this point in the history
Docs for custom traits
  • Loading branch information
InfernoDragon0 authored Jan 16, 2025
2 parents 1f8ad63 + 0291f67 commit f1dc188
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ pnpm-debug.log*

# macOS-specific files
.DS_Store

.idea
9 changes: 5 additions & 4 deletions src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import { LinkCard, CardGrid } from "@astrojs/starlight/components";
<LinkCard title="Custom Item" href="/reference/items/" />
<LinkCard title="Custom Crops" href="/reference/crops/" />
<LinkCard title="Custom Food" href="/reference/food/" />
<LinkCard title="Modded Localization" href="/reference/localization/" />
<LinkCard title="Custom Localization" href="/reference/localization/" />
<LinkCard title="Custom Objectives" href="/reference/objectives/" />
<LinkCard title="Modded Save Data" href="/reference/save-data/" />
<LinkCard title="Modded Settings" href="/reference/settings/" />
<LinkCard title="Custom Save Data" href="/reference/save-data/" />
<LinkCard title="Custom Traits" href="/reference/traits/" />
<LinkCard title="Custom Settings" href="/reference/settings/" />
</CardGrid>

## Experimental Features
Expand All @@ -44,5 +45,5 @@ import { LinkCard, CardGrid } from "@astrojs/starlight/components";
<LinkCard title="Custom Structures" href="/reference/structures/" />
<LinkCard title="Custom Tarot Cards" href="/reference/tarot-cards/" />
<LinkCard title="Custom Follower Task" href="/reference/tasks/" />
<LinkCard title="Modded UI" href="/reference/ui/" />
<LinkCard title="Custom UI" href="/reference/ui/" />
</CardGrid>
101 changes: 101 additions & 0 deletions src/content/docs/reference/traits.md
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
```

0 comments on commit f1dc188

Please sign in to comment.