using System; using System.Collections.Generic; namespace PKHeX.Core; /// /// Miscellaneous setup utility for legality checking data sources. /// internal static class EncounterUtil { internal static ReadOnlySpan Get(string resource) => Util.GetBinaryResource($"encounter_{resource}.pkl"); internal static BinLinkerAccessor Get(string resource, string ident) => BinLinkerAccessor.Get(Get(resource), ident); internal static T? GetMinByLevel(ReadOnlySpan chain, IEnumerable possible) where T : class, IEncounterTemplate { // MinBy grading: prefer species-form match, select lowest min level encounter. // Minimum allocation :) T? result = null; int min = int.MaxValue; foreach (var enc in possible) { int m = int.MaxValue; foreach (var evo in chain) { bool specDiff = enc.Species != evo.Species || enc.Form != evo.Form; var val = (Convert.ToInt32(specDiff) << 16) | enc.LevelMin; if (val < m) m = val; } if (m >= min) continue; min = m; result = enc; } return result; } /// /// 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. public static string[] GetNamesForLanguage(ReadOnlySpan names, uint index) { var result = new string[names.Length]; for (int i = 0; i < result.Length; i++) { var arr = names[i]; result[i] = index < arr.Length ? arr[index] : string.Empty; } return result; } }