mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-17 08:42:59 -05:00
82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace NHSE.Core
|
|
{
|
|
public sealed class GameStrings
|
|
{
|
|
private readonly string lang;
|
|
|
|
public readonly string[] villagers;
|
|
public readonly string[] itemlist;
|
|
public readonly string[] itemlistdisplay;
|
|
public readonly Dictionary<string, string> VillagerMap;
|
|
public readonly List<ComboItem> ItemDataSource;
|
|
|
|
private string[] Get(string ident) => GameLanguage.GetStrings(ident, lang);
|
|
|
|
public GameStrings(string l)
|
|
{
|
|
lang = l;
|
|
villagers = Get("villager");
|
|
VillagerMap = GetMap(villagers);
|
|
itemlist = Get("item");
|
|
itemlistdisplay = GetItemDisplayList(itemlist);
|
|
ItemDataSource = CreateItemDataSource(itemlistdisplay);
|
|
}
|
|
|
|
private List<ComboItem> CreateItemDataSource(string[] strings)
|
|
{
|
|
var dataSource = ComboItemUtil.GetArray(strings);
|
|
|
|
// load special
|
|
dataSource.Add(new ComboItem(itemlist[0], Item.NONE));
|
|
dataSource.SortByText();
|
|
|
|
return dataSource;
|
|
}
|
|
|
|
private static Dictionary<string, string> GetMap(IReadOnlyCollection<string> arr)
|
|
{
|
|
var map = new Dictionary<string, string>(arr.Count);
|
|
foreach (var kvp in arr)
|
|
{
|
|
var split = kvp.Split('\t');
|
|
map.Add(split[0], split[1]);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
public string GetVillager(string name)
|
|
{
|
|
return VillagerMap.TryGetValue(name, out var result) ? result : "???";
|
|
}
|
|
|
|
public static string[] GetItemDisplayList(string[] items)
|
|
{
|
|
items = (string[])items.Clone();
|
|
items[0] = string.Empty;
|
|
var set = new HashSet<string>();
|
|
for (int i = 0; i < items.Length; i++)
|
|
{
|
|
var item = items[i];
|
|
if (string.IsNullOrEmpty(item))
|
|
items[i] = $"(Item #{i:000})";
|
|
else if (set.Contains(item))
|
|
items[i] += $" (#{i:000})";
|
|
else
|
|
set.Add(item);
|
|
}
|
|
return items;
|
|
}
|
|
|
|
public string GetItemName(ushort index)
|
|
{
|
|
if (index == Item.NONE)
|
|
return itemlist[0];
|
|
if (index >= itemlistdisplay.Length)
|
|
return "???";
|
|
return itemlistdisplay[index];
|
|
}
|
|
}
|
|
}
|