2020-12-22 03:13:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public static partial class Util
|
|
|
|
|
{
|
|
|
|
|
public static List<ComboItem> GetCountryRegionList(string textFile, string lang)
|
|
|
|
|
{
|
|
|
|
|
string[] inputCSV = GetStringList(textFile);
|
|
|
|
|
int index = GeoLocation.GetLanguageIndex(lang);
|
2021-05-09 22:47:21 +00:00
|
|
|
|
var list = GetCBListFromCSV(inputCSV, index + 1);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
list.Sort(Comparer);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<ComboItem> GetCBListFromCSV(IReadOnlyList<string> inputCSV, int index)
|
|
|
|
|
{
|
2021-05-09 22:47:21 +00:00
|
|
|
|
var arr = new List<ComboItem>(inputCSV.Count);
|
2021-05-19 16:36:20 +00:00
|
|
|
|
foreach (var line in inputCSV)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
{
|
2021-05-14 22:30:55 +00:00
|
|
|
|
var val = line[..3];
|
2021-05-09 22:47:21 +00:00
|
|
|
|
var text = StringUtil.GetNthEntry(line, index, 4);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
var item = new ComboItem(text, Convert.ToInt32(val));
|
|
|
|
|
arr.Add(item);
|
|
|
|
|
}
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 06:26:38 +00:00
|
|
|
|
public static List<ComboItem> GetCBList(ReadOnlySpan<string> inStrings)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
{
|
2021-05-07 06:26:38 +00:00
|
|
|
|
var list = new List<ComboItem>(inStrings.Length);
|
|
|
|
|
for (int i = 0; i < inStrings.Length; i++)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
list.Add(new ComboItem(inStrings[i], i));
|
|
|
|
|
list.Sort(Comparer);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<ComboItem> GetCBList(IReadOnlyList<string> inStrings, IReadOnlyList<ushort> allowed)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<ComboItem>(allowed.Count + 1) { new(inStrings[0], 0) };
|
|
|
|
|
foreach (var index in allowed)
|
|
|
|
|
list.Add(new ComboItem(inStrings[index], index));
|
|
|
|
|
list.Sort(Comparer);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<ComboItem> GetCBList(IReadOnlyList<string> inStrings, int index, int offset = 0)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<ComboItem>();
|
|
|
|
|
AddCBWithOffset(list, inStrings, offset, index);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 21:32:36 +00:00
|
|
|
|
public static IReadOnlyList<ComboItem> GetUnsortedCBList(IReadOnlyList<string> inStrings, IReadOnlyList<byte> allowed)
|
|
|
|
|
{
|
|
|
|
|
var count = allowed.Count;
|
|
|
|
|
var list = new ComboItem[count];
|
|
|
|
|
for (var i = 0; i < allowed.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var index = allowed[i];
|
|
|
|
|
var item = new ComboItem(inStrings[index], index);
|
|
|
|
|
list[i] = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 06:26:38 +00:00
|
|
|
|
public static List<ComboItem> GetCBList(IReadOnlyList<string> inStrings, int[] allowed)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
{
|
2021-05-07 06:26:38 +00:00
|
|
|
|
var list = new List<ComboItem>(allowed.Length);
|
|
|
|
|
AddCB(list, inStrings, allowed);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddCBWithOffset(List<ComboItem> list, IReadOnlyList<string> inStrings, int offset, int index)
|
|
|
|
|
{
|
|
|
|
|
var item = new ComboItem(inStrings[index - offset], index);
|
|
|
|
|
list.Add(item);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 06:26:38 +00:00
|
|
|
|
public static void AddCBWithOffset(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int offset, int[] allowed)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
{
|
|
|
|
|
int beginCount = cbList.Count;
|
2021-06-03 19:04:19 +00:00
|
|
|
|
cbList.Capacity += allowed.Length;
|
2020-12-22 03:13:18 +00:00
|
|
|
|
foreach (var index in allowed)
|
|
|
|
|
{
|
|
|
|
|
var item = new ComboItem(inStrings[index - offset], index);
|
|
|
|
|
cbList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
cbList.Sort(beginCount, allowed.Length, Comparer);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 06:26:38 +00:00
|
|
|
|
public static void AddCBWithOffset(List<ComboItem> cbList, Span<string> inStrings, int offset)
|
|
|
|
|
{
|
|
|
|
|
int beginCount = cbList.Count;
|
2021-06-03 19:04:19 +00:00
|
|
|
|
cbList.Capacity += inStrings.Length;
|
2021-05-07 06:26:38 +00:00
|
|
|
|
for (int i = 0; i < inStrings.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var x = inStrings[i];
|
|
|
|
|
var item = new ComboItem(x, i + offset);
|
|
|
|
|
cbList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
cbList.Sort(beginCount, inStrings.Length, Comparer);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-22 03:13:18 +00:00
|
|
|
|
public static void AddCB(List<ComboItem> cbList, IReadOnlyList<string> inStrings, int[] allowed)
|
|
|
|
|
{
|
|
|
|
|
int beginCount = cbList.Count;
|
2021-06-03 19:04:19 +00:00
|
|
|
|
cbList.Capacity += allowed.Length;
|
2020-12-22 03:13:18 +00:00
|
|
|
|
foreach (var index in allowed)
|
|
|
|
|
{
|
|
|
|
|
var item = new ComboItem(inStrings[index], index);
|
|
|
|
|
cbList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
cbList.Sort(beginCount, allowed.Length, Comparer);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 19:04:19 +00:00
|
|
|
|
public static ComboItem[] GetVariedCBListBall(string[] inStrings, ushort[] stringNum, byte[] stringVal)
|
2020-12-22 03:13:18 +00:00
|
|
|
|
{
|
|
|
|
|
const int forcedTop = 3; // 3 Balls are preferentially first
|
2021-06-03 19:04:19 +00:00
|
|
|
|
var list = new ComboItem[forcedTop + stringNum.Length];
|
|
|
|
|
list[0] = new ComboItem(inStrings[4], (int)Ball.Poke);
|
|
|
|
|
list[1] = new ComboItem(inStrings[3], (int)Ball.Great);
|
|
|
|
|
list[2] = new ComboItem(inStrings[2], (int)Ball.Ultra);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < stringNum.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int index = stringNum[i];
|
|
|
|
|
var val = stringVal[i];
|
|
|
|
|
var txt = inStrings[index];
|
2021-06-03 19:04:19 +00:00
|
|
|
|
list[i + 3] = new ComboItem(txt, val);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 19:04:19 +00:00
|
|
|
|
Array.Sort(list, 3, list.Length - 3, Comparer);
|
2020-12-22 03:13:18 +00:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly FunctorComparer<ComboItem> Comparer =
|
|
|
|
|
new((a, b) => string.CompareOrdinal(a.Text, b.Text));
|
|
|
|
|
|
|
|
|
|
private sealed class FunctorComparer<T> : IComparer<T>
|
|
|
|
|
{
|
|
|
|
|
private readonly Comparison<T> Comparison;
|
|
|
|
|
public FunctorComparer(Comparison<T> comparison) => Comparison = comparison;
|
|
|
|
|
public int Compare(T x, T y) => Comparison(x, y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|