/* TShock, a server mod for Terraria Copyright (C) 2011-2019 Pryaxis & TShock Contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; using System.Collections.Generic; using System.Linq; using Terraria; using Terraria.ID; using Terraria.Initializers; using Terraria.Localization; using Terraria.UI.Chat; 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(); private static readonly Dictionary Buffs = new Dictionary(); private static readonly Dictionary VanillaCommandsPrefixs = new Dictionary(); internal static void Initialize() { var culture = Language.ActiveCulture; var skip = culture == GameCulture.FromCultureName(GameCulture.CultureName.English); try { if (!skip) { LanguageManager.Instance.SetLanguage(GameCulture.FromCultureName(GameCulture.CultureName.English)); } for (var i = -48; i < ItemID.Count; i++) { ItemNames.Add(i, Lang.GetItemNameValue(i)); } for (var i = -17; i < NPCID.Count; i++) { NpcNames.Add(i, Lang.GetNPCNameValue(i)); } for (var i = 0; i < BuffID.Count; i++) { Buffs.Add(i, Lang.GetBuffName(i)); } foreach (var field in typeof(PrefixID) .GetFields().Where(f => !f.Name.Equals("Count", StringComparison.Ordinal))) { var i = (int)field.GetValue(null); Prefixs.Add(i, Lang.prefix[i].Value); } ChatInitializer.Load(); foreach (var command in ChatManager.Commands._localizedCommands) { if (VanillaCommandsPrefixs.ContainsKey(command.Value._name)) continue; VanillaCommandsPrefixs.Add(command.Value._name,command.Key.Value); } ChatManager.Commands._localizedCommands.Clear(); } 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; } /// /// Get buff name in English /// /// Buff Id /// Buff name in English public static string GetBuffNameById(int id) { string buff; if (Buffs.TryGetValue(id, out buff)) return buff; return null; } /// /// Get vanilla command prefix in English /// /// vanilla command name /// vanilla command prefix in English public static string GetCommandPrefixByName(string name) { string commandText; if (VanillaCommandsPrefixs.TryGetValue(name, out commandText)) return commandText; return null; } } }