Skip to content

Commit e365e15

Browse files
Merge pull request #106 from zelzmiy/docs
Docs for custom traits
2 parents 102eb56 + 9eb7f0d commit e365e15

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ pnpm-debug.log*
1919

2020
# macOS-specific files
2121
.DS_Store
22+
23+
.idea

src/content/docs/index.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ import { LinkCard, CardGrid } from "@astrojs/starlight/components";
2828
<LinkCard title="Custom Item" href="/reference/items/" />
2929
<LinkCard title="Custom Crops" href="/reference/crops/" />
3030
<LinkCard title="Custom Food" href="/reference/food/" />
31-
<LinkCard title="Modded Localization" href="/reference/localization/" />
31+
<LinkCard title="Custom Localization" href="/reference/localization/" />
3232
<LinkCard title="Custom Objectives" href="/reference/objectives/" />
33-
<LinkCard title="Modded Save Data" href="/reference/save-data/" />
34-
<LinkCard title="Modded Settings" href="/reference/settings/" />
33+
<LinkCard title="Custom Save Data" href="/reference/save-data/" />
34+
<LinkCard title="Custom Traits" href="/reference/traits/" />
35+
<LinkCard title="Custom Settings" href="/reference/settings/" />
3536
</CardGrid>
3637

3738
## Experimental Features
@@ -44,5 +45,5 @@ import { LinkCard, CardGrid } from "@astrojs/starlight/components";
4445
<LinkCard title="Custom Structures" href="/reference/structures/" />
4546
<LinkCard title="Custom Tarot Cards" href="/reference/tarot-cards/" />
4647
<LinkCard title="Custom Follower Task" href="/reference/tasks/" />
47-
<LinkCard title="Modded UI" href="/reference/ui/" />
48+
<LinkCard title="Custom UI" href="/reference/ui/" />
4849
</CardGrid>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Traits
3+
description: Documentation on how to add a custom trait using Cult of the Lamb API
4+
---
5+
6+
## Creating Traits
7+
8+
To create an trait, you first need to make a class overriding `CustomTrait`.
9+
Example:
10+
11+
```csharp
12+
using COTL_API.CustomTraits;
13+
using UnityEngine;
14+
using System.IO;
15+
```
16+
17+
```csharp
18+
[HarmonyPatch]
19+
internal class ExampleTrait : CustomTrait
20+
{
21+
public override string InternalName => "ExampleTrait";
22+
23+
public override bool Positive => true;
24+
25+
// exclusive traits are traits that can't appear along with this trait!
26+
// if they are also custom defined trait, you only need to exclude it on
27+
// one of the traits.
28+
public override List<FollowerTrait.TraitType> ExclusiveTraits =>
29+
[
30+
FollowerTrait.TraitType.RoyalPooper
31+
];
32+
33+
public override TraitFlags TraitFlags => TraitFlags.RareStartingTrait;
34+
35+
public override string LocalizedTitle() => "Example Trait";
36+
37+
public override string LocalizedDescription() => "this trait is just an example :).";
38+
39+
public override Sprite Icon => TextureHelper.CreateSpriteFromPath(Path.Combine(Plugin.PluginPath, "Assets", "ExampleTrait.png"));
40+
41+
// by default, no behaviour for custom traits is added. use patches check in
42+
// your own code for the presence of the trait, and change the game's
43+
// behvaiour accordingly.
44+
[HarmonyPatch(typeof(FollowerBrain), nameof(FollowerBrain.GetPoopType))]
45+
[HarmonyPrefix]
46+
private static bool FollowerBrain_GetPoopType(ref FollowerBrain __instance, ref StructureBrain.TYPES __result)
47+
{
48+
if (!__instance.Info.Traits.Contains(Plugin.ExampleTrait)) return true;
49+
50+
__result = StructureBrain.TYPES.POOP_RAINBOW;
51+
DataManager.Instance.DaySinceLastSpecialPoop = TimeManager.CurrentDay;
52+
return false;
53+
54+
}
55+
}
56+
```
57+
58+
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.
59+
60+
`CustomTrait` supports the following overrides:
61+
| Type | Name | Default |
62+
|-|-|-|
63+
| string | InternalName | \[REQUIRED\] |
64+
|bool|Positive| true|
65+
|bool|IsTraitUnavailable()|false|
66+
|Sprite|Icon|TextureHelper.CreateSpriteFromPath(PluginPaths.ResolveAssetPath("placeholder.png"));|
67+
|List<FollowerTrait.TraitType>| ExclusiveTraits|[]|
68+
TraitFlags|TraitFlags|TraitFlags.None|
69+
|string|LocalizedTitle()|LocalizationManager.GetTranslation($"Traits/{ModPrefix}.{InternalName}")|
70+
|string|LocalizedDescription()|LocalizationManager.GetTranslation($"Traits/{InternalName}.description")|
71+
72+
## Adding Traits
73+
74+
To add a trait to the game, simply use `CustomTraitManager.Add()`.
75+
Example:
76+
77+
```csharp
78+
using COTL_API.CustomTraits;
79+
public static FollowerTrait.TraitType ExampleTrait { get; private set; }
80+
```
81+
82+
```csharp
83+
private void Awake()
84+
{
85+
ExampleTrait = CustomTraitManager.Add(new ExampleTrait());
86+
}
87+
```
88+
89+
Assigning the result of `CustomTraitManager.Add()` allows you to reference that trait elsewhere in your code using `Plugin.ExampleTrait`.
90+
91+
## Final Steps
92+
93+
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
94+
Directory structure:
95+
96+
```
97+
📂plugins
98+
┣📂Assets
99+
┃ ┗🖼️ExampleTrait.png
100+
┗📜mod_name.dll
101+
```

0 commit comments

Comments
 (0)