-
Notifications
You must be signed in to change notification settings - Fork 2
Mod Call
This wiki is dedicated to fellow mod developers with chat tags in your mods. After following this guide, your mod will have full support for the autocompletion feature offered by Chat+. To get started, follow the guide below. If you get stuck, you can view the example code or example demo.
The RegisterTag call supports adding a custom tag and a list of tags. It accepts the following arguments.
string - The first argument needed is the message type, which is always simply "RegisterTag".
string - The second argument is the tag type, which is the tag you registered in ChatManager, e.g t.
IEnumerable<string> - The third and final argument is the collection of tags to display. Please remember to supply the full tag, e.g new[] { "[t:one]", "[t:two]" }, ....
public class TagExampleSystem : ModSystem
{
public static Dictionary<string, string> ExampleMap = new()
{ // A simple mapping that transforms "smile" to ":)" and "sad" to ":(".
["smile"] = ":)",
["sad"] = ":("
};
public override void PostSetupContent()
{
ChatManager.Register<ExampleTagHandler>(["t"]); // Make [t:xxx] a valid chat tag.
Mod ChatPlus = ModLoader.GetMod("ChatPlus"); // Get ChatPlus
IEnumerable<string> tags =
[
"[t:smile]",
"[t:sad]",
];
// Register tags with ChatPlus
ChatPlus.Call
(
"RegisterTag",
"t", // enter the tag exactly as registered with ChatManager
tags // the collection of tags to register
);
}
}
public class ExampleTagHandler : ITagHandler
{
public TextSnippet Parse(string text, Color baseColor = default, string options = null)
{
// Parse e.g [t:smile] to ":)"
if (TagExampleSystem.ExampleMap.TryGetValue(text, out string mapped))
return new TextSnippet(mapped);
return new TextSnippet(text);
}
}
dotnet_Zd1iMXUQdK.mp4
On request, to provide more flexible autocomplete support, an additional Mod.Call was added called RegisterTagProvider.
See more details in the official implementation here: ChatPlus:Mod.Call()