Extract out showdown set interface

This commit is contained in:
Kurt
2020-04-12 13:05:29 -07:00
parent a94c754c3f
commit 30d21e4532
6 changed files with 115 additions and 77 deletions

View File

@@ -9,14 +9,14 @@ namespace PKHeX.Core
public static class CommonEdits
{
/// <summary>
/// Setting which enables/disables automatic manipulation of <see cref="PKM.Markings"/> when importing from a <see cref="ShowdownSet"/>.
/// Setting which enables/disables automatic manipulation of <see cref="PKM.Markings"/> when importing from a <see cref="IBattleTemplate"/>.
/// </summary>
public static bool ShowdownSetIVMarkings { get; set; } = true;
/// <summary>
/// Setting which causes the <see cref="PKM.StatNature"/> to the <see cref="PKM.Nature"/> in Gen8+ formats.
/// </summary>
public static bool ShowdownSetBehaviorNature { get; set; } = false;
public static bool ShowdownSetBehaviorNature { get; set; }
/// <summary>
/// Sets the <see cref="PKM.Nickname"/> to the provided value.
@@ -185,11 +185,11 @@ public static void SetNature(this PKM pk, int nature)
}
/// <summary>
/// Copies <see cref="ShowdownSet"/> details to the <see cref="PKM"/>.
/// Copies <see cref="IBattleTemplate"/> details to the <see cref="PKM"/>.
/// </summary>
/// <param name="pk">Pokémon to modify.</param>
/// <param name="Set"><see cref="ShowdownSet"/> details to copy from.</param>
public static void ApplySetDetails(this PKM pk, ShowdownSet Set)
/// <param name="Set"><see cref="IBattleTemplate"/> details to copy from.</param>
public static void ApplySetDetails(this PKM pk, IBattleTemplate Set)
{
pk.Species = Math.Min(pk.MaxSpeciesID, Set.Species);
pk.SetMoves(Set.Moves, true);

View File

@@ -0,0 +1,85 @@
namespace PKHeX.Core
{
public interface IBattleTemplate : IGigantamax
{
/// <summary>
/// <see cref="PKM.Species"/> of the Set entity.
/// </summary>
int Species { get; }
/// <summary>
/// <see cref="PKM.Format"/> of the Set entity it is specific to.
/// </summary>
int Format { get; }
/// <summary>
/// <see cref="PKM.Nickname"/> of the Set entity.
/// </summary>
string Nickname { get; }
/// <summary>
/// <see cref="PKM.Gender"/> name of the Set entity.
/// </summary>
string Gender { get; }
/// <summary>
/// <see cref="PKM.HeldItem"/> of the Set entity.
/// </summary>
int HeldItem { get; }
/// <summary>
/// <see cref="PKM.Ability"/> of the Set entity.
/// </summary>
int Ability { get; }
/// <summary>
/// <see cref="PKM.CurrentLevel"/> of the Set entity.
/// </summary>
int Level { get; }
/// <summary>
/// <see cref="PKM.CurrentLevel"/> of the Set entity.
/// </summary>
bool Shiny { get; }
/// <summary>
/// <see cref="PKM.CurrentFriendship"/> of the Set entity.
/// </summary>
int Friendship { get; }
/// <summary>
/// <see cref="PKM.StatNature"/> of the Set entity.
/// </summary>
int Nature { get; }
/// <summary>
/// <see cref="PKM.AltForm"/> name of the Set entity, stored in PKHeX style (instead of Showdown's)
/// </summary>
string Form { get; }
/// <summary>
/// <see cref="PKM.AltForm"/> of the Set entity.
/// </summary>
int FormIndex { get; }
/// <summary>
/// <see cref="PKM.HPType"/> of the Set entity.
/// </summary>
int HiddenPowerType { get; }
/// <summary>
/// <see cref="PKM.EVs"/> of the Set entity.
/// </summary>
int[] EVs { get; }
/// <summary>
/// <see cref="PKM.IVs"/> of the Set entity.
/// </summary>
int[] IVs { get; }
/// <summary>
/// <see cref="PKM.Moves"/> of the Set entity.
/// </summary>
int[] Moves { get; }
}
}

View File

@@ -7,7 +7,7 @@ namespace PKHeX.Core
/// <summary>
/// Logic for exporting and importing <see cref="PKM"/> data in Pokémon Showdown's text format.
/// </summary>
public sealed class ShowdownSet : IGigantamax
public sealed class ShowdownSet : IBattleTemplate
{
private static readonly string[] genders = {"M", "F", ""};
private static readonly string[] genderForms = {"", "F", ""};
@@ -21,89 +21,55 @@ public sealed class ShowdownSet : IGigantamax
private const int MAX_SPECIES = (int)Core.Species.MAX_COUNT - 1;
private static readonly GameStrings DefaultStrings = GameInfo.GetStrings(GameLanguage.DefaultLanguage);
/// <summary>
/// <see cref="PKM.Species"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int Species { get; private set; } = -1;
/// <summary>
/// <see cref="PKM.Format"/> of the Set entity it is specific to.
/// </summary>
/// <inheritdoc/>
public int Format { get; private set; } = PKMConverter.Format;
/// <summary>
/// <see cref="PKM.Nickname"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public string Nickname { get; set; } = string.Empty;
/// <summary>
/// <see cref="PKM.Gender"/> name of the Set entity.
/// </summary>
/// <inheritdoc/>
public string Gender { get; private set; } = string.Empty;
/// <summary>
/// <see cref="PKM.HeldItem"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int HeldItem { get; private set; }
/// <summary>
/// <see cref="PKM.Ability"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int Ability { get; private set; } = -1;
/// <summary>
/// <see cref="PKM.CurrentLevel"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int Level { get; private set; } = 100;
/// <summary>
/// <see cref="PKM.CurrentLevel"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public bool Shiny { get; private set; }
/// <summary>
/// <see cref="PKM.CurrentFriendship"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int Friendship { get; private set; } = 255;
/// <summary>
/// <see cref="PKM.StatNature"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int Nature { get; set; } = -1;
/// <summary>
/// <see cref="PKM.AltForm"/> name of the Set entity, stored in PKHeX style (instead of Showdown's)
/// </summary>
/// <inheritdoc/>
public string Form { get; private set; } = string.Empty;
/// <summary>
/// <see cref="PKM.AltForm"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int FormIndex { get; private set; }
/// <summary>
/// <see cref="PKM.EVs"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int[] EVs { get; private set; } = {00, 00, 00, 00, 00, 00};
/// <summary>
/// <see cref="PKM.IVs"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int[] IVs { get; private set; } = {31, 31, 31, 31, 31, 31};
/// <summary>
/// <see cref="PKM.HPType"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int HiddenPowerType { get; set; } = -1;
/// <summary>
/// <see cref="PKM.Moves"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public int[] Moves { get; } = {0, 0, 0, 0};
/// <summary>
/// <see cref="IGigantamax.CanGigantamax"/> of the Set entity.
/// </summary>
/// <inheritdoc/>
public bool CanGigantamax { get; set; }
/// <summary>
@@ -118,29 +84,17 @@ public sealed class ShowdownSet : IGigantamax
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]};
/// <summary>
/// Loads a new blank <see cref="ShowdownSet"/>.
/// </summary>
public ShowdownSet() { }
/// <summary>
/// Loads a new <see cref="ShowdownSet"/> from the input string.
/// </summary>
/// <param name="input">Single-line string which will be split before loading.</param>
public ShowdownSet(string input)
{
var lines = input.Split(Splitters, StringSplitOptions.None);
LoadLines(lines);
}
public ShowdownSet(string input) : this(input.Split(Splitters, 0)) { }
/// <summary>
/// Loads a new <see cref="ShowdownSet"/> from the input string.
/// </summary>
/// <param name="lines">Enumerable list of lines.</param>
public ShowdownSet(IEnumerable<string> lines)
{
LoadLines(lines);
}
public ShowdownSet(IEnumerable<string> lines) => LoadLines(lines);
private void LoadLines(IEnumerable<string> lines)
{
@@ -164,7 +118,6 @@ private void LoadLines(IEnumerable<string> lines)
private void ParseLines(IEnumerable<string> lines)
{
// ReSharper disable once GenericEnumeratorNotDisposed
using var e = lines.GetEnumerator();
if (!e.MoveNext())
return;

View File

@@ -43,7 +43,7 @@ bool ivCanMatch(int spec, int enc)
return true;
}
public static EncounterCriteria GetCriteria(ShowdownSet s)
public static EncounterCriteria GetCriteria(IBattleTemplate s)
{
int gender = string.IsNullOrWhiteSpace(s.Gender) ? -1 : PKX.GetGenderFromString(s.Gender);
return new EncounterCriteria

View File

@@ -1844,9 +1844,9 @@ public void EnableDragDrop(DragEventHandler enter, DragEventHandler drop)
}
// ReSharper disable once FieldCanBeMadeReadOnly.Global
public Action<ShowdownSet> LoadShowdownSet;
public Action<IBattleTemplate> LoadShowdownSet;
private void LoadShowdownSetDefault(ShowdownSet Set)
private void LoadShowdownSetDefault(IBattleTemplate Set)
{
var pk = PreparePKM();
pk.ApplySetDetails(Set);

View File

@@ -494,12 +494,12 @@ private void ClickShowdownImportPKM(object sender, EventArgs e)
{ WinFormsUtil.Alert(MsgClipboardFailRead); return; }
// Get Simulator Data
ShowdownSet Set = new ShowdownSet(Clipboard.GetText());
var Set = new ShowdownSet(Clipboard.GetText());
if (Set.Species < 0)
{ WinFormsUtil.Alert(MsgSimulatorFailClipboard); return; }
if (Set.Nickname?.Length > C_SAV.SAV.NickLength)
if (Set.Nickname.Length > C_SAV.SAV.NickLength)
Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength);
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgSimulatorLoad, Set.Text))