using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
///
/// Miscellaneous setup utility for legality checking data sources.
///
internal static class EncounterUtil
{
///
/// Gets the relevant objects that appear in the relevant game.
///
/// Table of valid encounters that appear for the game pairing
/// Game to filter for
/// Array of encounter objects that can be encountered in the input game
internal static T[] GetEncounters(T[] source, GameVersion game) where T : EncounterStatic
{
return Array.FindAll(source, s => s.Version.Contains(game));
}
///
/// Loads the language string lists into the objects.
///
/// Encounter template type
/// Trade templates
/// Localization strings, grouped by language.
///
/// The first half of strings in the language resource array are
/// The second half of strings in the language resource strings are
///
internal static void MarkEncounterTradeStrings(T[] table, string[][] strings) where T : EncounterTrade
{
uint languageCount = (uint)strings[1].Length / 2;
for (uint i = 0; i < languageCount; i++)
{
var t = table[i];
t.Nicknames = GetNamesForLanguage(strings, i);
t.TrainerNames = GetNamesForLanguage(strings, languageCount + i);
}
}
///
/// Loads the language string lists into the objects.
///
/// Encounter template type
/// Trade templates
/// Localization strings, grouped by language.
internal static void MarkEncounterTradeNicknames(T[] table, string[][] strings) where T : EncounterTrade
{
for (uint i = 0; i < table.Length; i++)
{
var t = table[i];
t.Nicknames = GetNamesForLanguage(strings, i);
}
}
///
/// Grabs the localized names for individual templates for all languages from the specified of the list.
///
/// Arrays of strings grouped by language
/// Index to grab from the language arrays
/// Row of localized strings for the template.
private static string[] GetNamesForLanguage(IReadOnlyList names, uint index)
{
var result = new string[names.Count];
for (int i = 0; i < result.Length; i++)
{
var arr = names[i];
result[i] = index < arr.Length ? arr[index] : string.Empty;
}
return result;
}
}
}