mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
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:
parent
6589869b35
commit
229d752d7a
2 changed files with 68 additions and 59 deletions
|
@ -55,7 +55,7 @@ namespace PKHeX.Core
|
|||
|
||||
// Seek for start of set
|
||||
int start = Array.FindIndex(lines, line => line.Contains(" @ "));
|
||||
|
||||
|
||||
if (start != -1) // Has Item -- skip to start.
|
||||
lines = lines.Skip(start).Take(lines.Length - start).ToArray();
|
||||
else // Has no Item -- try parsing the first line anyway.
|
||||
|
@ -91,9 +91,9 @@ namespace PKHeX.Core
|
|||
{
|
||||
case "Trait":
|
||||
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 "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 "EV":
|
||||
case "EVs": { ParseLineEVs(brokenline[1].Trim()); break; }
|
||||
|
@ -142,24 +142,7 @@ namespace PKHeX.Core
|
|||
EVs = EVsSpeedFirst;
|
||||
|
||||
// Showdown Quirks
|
||||
switch (Species)
|
||||
{
|
||||
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;
|
||||
}
|
||||
Form = ConvertFormFromShowdown(Form, Species, Ability);
|
||||
}
|
||||
|
||||
public string Text => GetText();
|
||||
|
@ -171,7 +154,7 @@ namespace PKHeX.Core
|
|||
var result = new List<string>();
|
||||
|
||||
// First Line: Name, Nickname, Gender, Item
|
||||
string form = GetStringForm(Form);
|
||||
string form = ConvertFormToShowdown(Form, Species);
|
||||
result.Add(GetStringFirstLine(form));
|
||||
|
||||
// IVs
|
||||
|
@ -197,35 +180,6 @@ namespace PKHeX.Core
|
|||
|
||||
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)
|
||||
{
|
||||
string specForm = species[Species];
|
||||
|
@ -290,9 +244,8 @@ namespace PKHeX.Core
|
|||
Form = pkm.AltForm > 0 && pkm.AltForm < Forms.Length ? Forms[pkm.AltForm] : "",
|
||||
};
|
||||
|
||||
if (Set.Form == "F") Set.Gender = "";
|
||||
else if (Set.Species == 676) Set.Form = ""; // Furfrou
|
||||
else if (Set.Species == 666 && Set.Form == "Poké Ball") Set.Form = "Pokeball"; // Vivillon
|
||||
if (Set.Form == "F")
|
||||
Set.Gender = "";
|
||||
|
||||
return Set.Text;
|
||||
}
|
||||
|
@ -395,6 +348,65 @@ namespace PKHeX.Core
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1984,11 +1984,8 @@ namespace PKHeX.WinForms.Controls
|
|||
string[] formStrings = PKX.GetFormList(Set.Species,
|
||||
Util.GetTypesList("en"),
|
||||
Util.GetFormsList("en"), gendersymbols, pkm.Format);
|
||||
int form = 0;
|
||||
for (int i = 0; i < formStrings.Length; i++)
|
||||
if (formStrings[i].Contains(Set.Form ?? ""))
|
||||
{ form = i; break; }
|
||||
CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, form);
|
||||
int form = Array.FindIndex(formStrings, z => z.Contains(Set.Form ?? ""));
|
||||
CB_Form.SelectedIndex = Math.Min(CB_Form.Items.Count - 1, Math.Max(0, form));
|
||||
|
||||
// Set Ability and Moves
|
||||
CB_Ability.SelectedIndex = Math.Max(0, Array.IndexOf(pkm.PersonalInfo.Abilities, Set.Ability));
|
||||
|
|
Loading…
Reference in a new issue