RogueLibs' logo

Custom Name Providers

If you have some kind of a complicated localization logic, then you might want to create your own INameProvider. This way you can control what strings are returned by NameDB.GetName in a more generic way. You can even hook up your localization provider, if you don't like the localization system provided by RogueLibs.

INameProvider interface

Just create a class implementing INameProvider and add it to RogueFramework:

/MyAwesomeProject/MyAwesomeNameProvider.cs
public class MyAwesomeNameProvider : INameProvider{    public void GetName(string name, string type, ref string? result)    {        if (name.StartsWith("fake_"))        {            string sub = name.Substring("fake_".Length);            result = LanguageService.NameDB.GetName(sub, type);        }    }}
info

If the original NameDB.GetName returned an error string (with E_ prefix), result is set to null.

/MyAwesomeProject/MyAwesomeNameProvider.cs
[RLSetup]public static void Setup(){    RogueFramework.NameProviders.Add(new MyNameProvider());}

Examples

Here's a practical and useful example, that is already implemented in RogueLibs:

/RogueLibsCore/Names/Provides/DialogueNameProvider.cs
public class DialogueNameProvider : INameProvider{    public void GetName(string name, string type, ref string? result)    {        if (result is null && type == "Dialogue" && name.StartsWith("NA_"))        {            string sub = name.Substring("NA_".Length);            string newResult = LanguageService.NameDB.GetName(sub, type);            if (!newResult.StartsWith("E_")) result = newResult;        }    }}

Normally, the game looks for dialogue names of the following format: <AgentName>_<DialogueName>. If such a name doesn't exist, then NA_<DialogueName> (NA - No Agent) is used instead. This name provider will also look for a name with just the dialogue name. This allows the developers to write dialogue names without that annoying and often confusing NA_ prefix.