using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.Localization;
namespace TShockAPI.Localization
{
///
/// Provides a series of methods that give English texts
///
public static class EnglishLanguage
{
private static readonly Dictionary ItemNames = new Dictionary();
private static readonly Dictionary NpcNames = new Dictionary();
private static readonly Dictionary Prefixs = new Dictionary();
internal static void Initialize()
{
var culture = Language.ActiveCulture;
var skip = culture == GameCulture.English;
try
{
if (!skip)
{
LanguageManager.Instance.SetLanguage(GameCulture.English);
}
for (var i = -48; i < Main.maxItemTypes; i++)
{
ItemNames.Add(i, Lang.GetItemNameValue(i));
}
for (var i = -17; i < Main.maxNPCTypes; i++)
{
NpcNames.Add(i, Lang.GetNPCNameValue(i));
}
foreach (var field in typeof(Main).Assembly.GetType("Terraria.ID.PrefixID")
.GetFields().Where(f => !f.Name.Equals("Count", StringComparison.Ordinal)))
{
Prefixs.Add((int) field.GetValue(null), field.Name);
}
}
finally
{
if (!skip)
{
LanguageManager.Instance.SetLanguage(culture);
}
}
}
///
/// Get the english name of an item
///
/// Id of the item
/// Item name in English
public static string GetItemNameById(int id)
{
string itemName;
if (ItemNames.TryGetValue(id, out itemName))
return itemName;
return null;
}
///
/// Get the english name of a npc
///
/// Id of the npc
/// Npc name in English
public static string GetNpcNameById(int id)
{
string npcName;
if (NpcNames.TryGetValue(id, out npcName))
return npcName;
return null;
}
///
/// Get prefix in English
///
/// Prefix Id
/// Prefix in English
public static string GetPrefixById(int id)
{
string prefix;
if (Prefixs.TryGetValue(id, out prefix))
return prefix;
return null;
}
}
}