Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for custom traits #106

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
Loading