From 5cfaf7eecde2ec1ac255d187e040bb87c6f68249 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 17 Aug 2022 23:50:14 -0700 Subject: [PATCH] Add overloads to get localized showdown sets --- .../Editing/Showdown/ShowdownParsing.cs | 26 ++++++++++++++++--- PKHeX.Core/Editing/Showdown/ShowdownSet.cs | 5 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/PKHeX.Core/Editing/Showdown/ShowdownParsing.cs b/PKHeX.Core/Editing/Showdown/ShowdownParsing.cs index ff4bdcb19..4d4592fb5 100644 --- a/PKHeX.Core/Editing/Showdown/ShowdownParsing.cs +++ b/PKHeX.Core/Editing/Showdown/ShowdownParsing.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using static PKHeX.Core.Species; namespace PKHeX.Core; @@ -154,8 +153,29 @@ public static string GetShowdownText(PKM pk) /// Fetches ShowdownSet lines from the input data. /// /// Pokémon data to summarize. + /// Localization setting /// Consumable list of lines. - public static IEnumerable GetShowdownSets(IEnumerable data) => data.Where(p => p.Species != 0).Select(GetShowdownText); + public static IEnumerable GetShowdownText(IEnumerable data, string lang = ShowdownSet.DefaultLanguage) + { + var sets = GetShowdownSets(data); + foreach (var set in sets) + yield return set.LocalizedText(lang); + } + + /// + /// Fetches ShowdownSet lines from the input data. + /// + /// Pokémon data to summarize. + /// Consumable list of lines. + public static IEnumerable GetShowdownSets(IEnumerable data) + { + foreach (var pk in data) + { + if (pk.Species == 0) + continue; + yield return new ShowdownSet(pk); + } + } /// /// Fetches ShowdownSet lines from the input data, and combines it into one string. @@ -163,7 +183,7 @@ public static string GetShowdownText(PKM pk) /// Pokémon data to summarize. /// Splitter between each set. /// Single string containing all lines. - public static string GetShowdownSets(IEnumerable data, string separator) => string.Join(separator, GetShowdownSets(data)); + public static string GetShowdownSets(IEnumerable data, string separator) => string.Join(separator, GetShowdownText(data)); /// /// Gets a localized string preview of the provided . diff --git a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs index a46e5c75d..f7563674f 100644 --- a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs +++ b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs @@ -17,7 +17,8 @@ public sealed class ShowdownSet : IBattleTemplate private static readonly char[] ParenJunk = { '(', ')', '[', ']' }; private static readonly ushort[] DashedSpecies = {782, 783, 784, 250, 032, 029}; // Kommo-o, Ho-Oh, Nidoran-M, Nidoran-F private const int MAX_SPECIES = (int)MAX_COUNT - 1; - private static readonly GameStrings DefaultStrings = GameInfo.GetStrings(GameLanguage.DefaultLanguage); + internal const string DefaultLanguage = GameLanguage.DefaultLanguage; + private static readonly GameStrings DefaultStrings = GameInfo.GetStrings(DefaultLanguage); /// public int Species { get; private set; } = -1; @@ -247,7 +248,7 @@ private bool ParseDynamax(string value) /// Gets the localized Text representation of the set details. /// /// 2 character language code - public string LocalizedText(string lang) => LocalizedText(GameLanguage.GetLanguageIndex(lang)); + public string LocalizedText(string lang = DefaultLanguage) => LocalizedText(GameLanguage.GetLanguageIndex(lang)); /// /// Gets the localized Text representation of the set details.