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
interfaceJust create a class implementing INameProvider
and add it to RogueFramework
:
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); } }}
If the original NameDB.GetName
returned an error string (with E_
prefix), result
is set to null
.
[RLSetup]public static void Setup(){ RogueFramework.NameProviders.Add(new MyNameProvider());}
Here's a practical and useful example, that is already implemented in RogueLibs:
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.