diff --git a/PKHeX.Core/Editing/ShowdownSet.cs b/PKHeX.Core/Editing/ShowdownSet.cs index 31e6d179f..0b2123de1 100644 --- a/PKHeX.Core/Editing/ShowdownSet.cs +++ b/PKHeX.Core/Editing/ShowdownSet.cs @@ -13,52 +13,125 @@ public class ShowdownSet private static readonly string[] genders = {"M", "F", ""}; private static readonly string[] genderForms = {"", "F", ""}; private static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" }; + private static readonly string[] Splitters = {"\r\n", "\n"}; + private static readonly string[] LineSplit = {": "}; private static int MAX_SPECIES => PKX.Personal.MaxSpeciesID; private const string Language = "en"; private const int DefaultLanguageID = 2; private static readonly GameStrings DefaultStrings = GameInfo.GetStrings(Language); + /// + /// of the Set entity. + /// + public int Species { get; private set; } = -1; + + /// + /// of the Set entity it is specific to. + /// + public int Format { get; } = PKMConverter.Format; + + /// + /// of the Set entity. + /// + public string Nickname { get; set; } + + /// + /// name of the Set entity. + /// + public string Gender { get; private set; } + + /// + /// of the Set entity. + /// + public int HeldItem { get; private set; } + + /// + /// of the Set entity. + /// + public int Ability { get; private set; } = -1; + + /// + /// of the Set entity. + /// + public int Level { get; private set; } = 100; + + /// + /// of the Set entity. + /// + public bool Shiny { get; private set; } + + /// + /// of the Set entity. + /// + public int Friendship { get; private set; } = 255; + + /// + /// of the Set entity. + /// + public int Nature { get; set; } + + /// + /// name of the Set entity. + /// + public string Form { get; private set; } + + /// + /// of the Set entity. + /// + public int FormIndex { get; private set; } + + /// + /// of the Set entity. + /// + public int[] EVs { get; private set; } = {00, 00, 00, 00, 00, 00}; + + /// + /// of the Set entity. + /// + public int[] IVs { get; private set; } = {31, 31, 31, 31, 31, 31}; + + /// + /// of the Set entity. + /// + public int[] Moves { get; } = {0, 0, 0, 0}; + + /// + /// Any lines that failed to be parsed. + /// + public readonly List InvalidLines = new List(); + private GameStrings Strings { get; set; } = DefaultStrings; private int LanguageID { get; set; } = DefaultLanguageID; - // Default Set Data - public string Nickname { get; set; } - public int Species { get; private set; } = -1; - public int Format { get; private set; } = PKMConverter.Format; - public string Form { get; private set; } - public string Gender { get; private set; } - public int HeldItem { get; private set; } - public int Ability { get; private set; } = -1; - public int Level { get; private set; } = 100; - public bool Shiny { get; private set; } - public int Friendship { get; private set; } = 255; - public int Nature { get; set; } - public int FormIndex { get; private set; } - public int[] EVs { get; private set; } = {00, 00, 00, 00, 00, 00}; - public int[] IVs { get; private set; } = {31, 31, 31, 31, 31, 31}; - public int[] Moves { get; private set; } = {0, 0, 0, 0}; - public readonly List InvalidLines = new List(); - private int[] IVsSpeedFirst => new[] {IVs[0], IVs[1], IVs[2], IVs[5], IVs[3], IVs[4]}; private int[] IVsSpeedLast => new[] {IVs[0], IVs[1], IVs[2], IVs[4], IVs[5], IVs[3]}; private int[] EVsSpeedFirst => new[] {EVs[0], EVs[1], EVs[2], EVs[5], EVs[3], EVs[4]}; private int[] EVsSpeedLast => new[] {EVs[0], EVs[1], EVs[2], EVs[4], EVs[5], EVs[3]}; - // Parsing Utility + /// + /// Loads a new from the input string. If no string is provided, a blank set is returned. + /// + /// Single-line string which will be split before loading. public ShowdownSet(string input = null) { if (input == null) return; - string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); + string[] lines = input.Split(Splitters, StringSplitOptions.None); LoadLines(lines); } + + /// + /// Loads a new from the input string. If no string is provided, a blank set is returned. + /// + /// Enumerable list of lines. public ShowdownSet(IEnumerable lines) { if (lines == null) return; LoadLines(lines); } + private void LoadLines(IEnumerable lines) { lines = lines.Select(z => z.Replace("'", "’").Replace("–", "-").Trim()); // Sanitize apostrophes & dashes @@ -97,7 +170,7 @@ private void ParseLines(IEnumerable lines) continue; } - string[] brokenline = line.Split(new[] { ": " }, StringSplitOptions.None); + string[] brokenline = line.Split(LineSplit, StringSplitOptions.None); var piece1 = brokenline[0].Trim(); var piece2 = brokenline.Length == 1 ? string.Empty : brokenline[1].Trim(); if (!ParseEntry(piece1, piece2)) @@ -141,9 +214,23 @@ private bool ParseEntry(string first, string second) } } + /// + /// Gets the standard Text representation of the set details. + /// public string Text => GetText(); + + /// + /// Gets the localized Text representation of the set details. + /// + /// 2 character language code public string LocalizedText(string lang) => LocalizedText(GameInfo.Language(lang)); + + /// + /// Gets the localized Text representation of the set details. + /// + /// Language ID public string LocalizedText(int lang) => GetText(GameInfo.GetStrings(LanguageID = lang)); + private string GetText(GameStrings strings = null) { if (Species <= 0 || Species > MAX_SPECIES) @@ -232,6 +319,12 @@ public static string GetShowdownText(PKM pkm) return string.Empty; return new ShowdownSet(pkm).Text; } + + /// + /// Converts the data into an importable set format for Pokémon Showdown. + /// + /// PKM to convert to string + /// New ShowdownSet object representing the input public ShowdownSet(PKM pkm) { if (pkm.Species <= 0)