Update showdown form parsing

Closes #1437 (should have been handled in PKHeX.Core not winforms);
extracted the two sanitization methods and sprinkled in some c#7
This commit is contained in:
Kurt 2017-09-02 08:26:51 -07:00
parent 6589869b35
commit 229d752d7a
2 changed files with 68 additions and 59 deletions

View file

@ -55,7 +55,7 @@ namespace PKHeX.Core
// Seek for start of set // Seek for start of set
int start = Array.FindIndex(lines, line => line.Contains(" @ ")); int start = Array.FindIndex(lines, line => line.Contains(" @ "));
if (start != -1) // Has Item -- skip to start. if (start != -1) // Has Item -- skip to start.
lines = lines.Skip(start).Take(lines.Length - start).ToArray(); lines = lines.Skip(start).Take(lines.Length - start).ToArray();
else // Has no Item -- try parsing the first line anyway. else // Has no Item -- try parsing the first line anyway.
@ -91,9 +91,9 @@ namespace PKHeX.Core
{ {
case "Trait": case "Trait":
case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1].Trim()); break; } case "Ability": { Ability = Array.IndexOf(abilities, brokenline[1].Trim()); break; }
case "Level": { Level = Util.ToInt32(brokenline[1].Trim()); break; } case "Level": { if (int.TryParse(brokenline[1].Trim(), out int val)) Level = val; else InvalidLines.Add(line); break; }
case "Shiny": { Shiny = brokenline[1].Trim() == "Yes"; break; } case "Shiny": { Shiny = brokenline[1].Trim() == "Yes"; break; }
case "Happiness": { Friendship = Util.ToInt32(brokenline[1].Trim()); break; } case "Happiness": { if (int.TryParse(brokenline[1].Trim(), out int val)) Friendship = val; else InvalidLines.Add(line); break; }
case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; } case "Nature": { Nature = Array.IndexOf(natures, brokenline[1].Trim()); break; }
case "EV": case "EV":
case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; } case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; }
@ -142,24 +142,7 @@ namespace PKHeX.Core
EVs = EVsSpeedFirst; EVs = EVsSpeedFirst;
// Showdown Quirks // Showdown Quirks
switch (Species) Form = ConvertFormFromShowdown(Form, Species, Ability);
{
case 658: // Greninja
if (Ability == 210) Form = "Ash"; // Battle Bond
break;
case 666: // Vivillon
if (Form == "Pokeball") Form = "Poké Ball";
break;
case 718: // Zygarde
if (string.IsNullOrEmpty(Form)) Form = "50%";
else if (Form == "Complete") Form = "100%";
if (Ability == 211) Form += "-C"; // Power Construct
break;
case 774: // Minior
if (!string.IsNullOrWhiteSpace(Form) && Form != "Meteor")
Form = "C-" + Form;
break;
}
} }
public string Text => GetText(); public string Text => GetText();
@ -171,7 +154,7 @@ namespace PKHeX.Core
var result = new List<string>(); var result = new List<string>();
// First Line: Name, Nickname, Gender, Item // First Line: Name, Nickname, Gender, Item
string form = GetStringForm(Form); string form = ConvertFormToShowdown(Form, Species);
result.Add(GetStringFirstLine(form)); result.Add(GetStringFirstLine(form));
// IVs // IVs
@ -197,35 +180,6 @@ namespace PKHeX.Core
return string.Join(Environment.NewLine, result); return string.Join(Environment.NewLine, result);
} }
private string GetStringForm(string form)
{
if (string.IsNullOrWhiteSpace(form))
{
if (Species == 774) // Minior
form = "Meteor";
return form;
}
switch (Species)
{
case 658: // Greninja
form = form.Replace("Ash", "");
form = form.Replace("Active", "");
break;
case 718: // Zygarde
form = form.Replace("-C", "");
form = form.Replace("50%", "");
form = form.Replace("100%", "Complete");
break;
case 774: // Minior
if (form.StartsWith("M-"))
form = "Meteor";
form = form.Replace("C-", "");
break;
}
return form;
}
private string GetStringFirstLine(string form) private string GetStringFirstLine(string form)
{ {
string specForm = species[Species]; string specForm = species[Species];
@ -290,9 +244,8 @@ namespace PKHeX.Core
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "", Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "",
}; };
if (Set.Form == "F") Set.Gender = ""; if (Set.Form == "F")
else if (Set.Species == 676) Set.Form = ""; // Furfrou Set.Gender = "";
else if (Set.Species == 666 && Set.Form == "Poké Ball") Set.Form = "Pokeball"; // Vivillon
return Set.Text; return Set.Text;
} }
@ -395,6 +348,65 @@ namespace PKHeX.Core
InvalidLines.Add($"Unknown IV Type input: {ivlist[i * 2]}"); InvalidLines.Add($"Unknown IV Type input: {ivlist[i * 2]}");
} }
} }
private static string ConvertFormToShowdown(string form, int spec)
{
if (string.IsNullOrWhiteSpace(form))
{
if (spec == 774) // Minior
form = "Meteor";
return form;
}
switch (spec)
{
case 550 when form == "Blue":
return "Blue Striped";
case 666 when form == "Poké Ball":
return "Pokeball"; // Vivillon
case 676:
return ""; // Furfrou
case 658: // Greninja
return "";
case 718: // Zygarde
form = form.Replace("-C", "");
form = form.Replace("50%", "");
return form.Replace("100%", "Complete");
case 774: // Minior
if (form.StartsWith("M-"))
return "Meteor";
return form.Replace("C-", "");
default:
return form;
}
}
private static string ConvertFormFromShowdown(string form, int spec, int ability)
{
switch (spec)
{
case 550 when form == "Blue Striped": // Basculin
return "Blue";
case 658 when ability == 210: // Greninja
return "Ash"; // Battle Bond
case 666 when form == "Pokeball": // Vivillon
return "Poké Ball";
// Zygarde
case 718 when string.IsNullOrWhiteSpace(form):
return "50%";
case 718 when form == "Complete":
return "100%";
case 718 when ability == 211:
return "-C"; // Power Construct
// Minior
case 774 when !string.IsNullOrWhiteSpace(form) && form != "Meteor":
return "C-" + form;
default:
return form;
}
}
private static string[] SplitLineStats(string line) private static string[] SplitLineStats(string line)
{ {

View file

@ -1984,11 +1984,8 @@ namespace PKHeX.WinForms.Controls
string[] formStrings = PKX.GetFormList(Set.Species, string[] formStrings = PKX.GetFormList(Set.Species,
Util.GetTypesList("en"), Util.GetTypesList("en"),
Util.GetFormsList("en"), gendersymbols, pkm.Format); Util.GetFormsList("en"), gendersymbols, pkm.Format);
int form = 0; int form = Array.FindIndex(formStrings, z => z.Contains(Set.Form ?? ""));
for (int i = 0; i < formStrings.Length; i++) CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, Math.Max(0, form));
if (formStrings[i].Contains(Set.Form ?? ""))
{ form = i; break; }
CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, form);
// Set Ability and Moves // Set Ability and Moves
CB_Ability.SelectedIndex = Math.Max(0, Array.IndexOf(pkm.PersonalInfo.Abilities, Set.Ability)); CB_Ability.SelectedIndex = Math.Max(0, Array.IndexOf(pkm.PersonalInfo.Abilities, Set.Ability));