Misc updates

relocate program language enum
test that test case is proper
move getcompatible & gettemplate to core
remove catch rate changing for pk1 (catchrate editor now used instead)
This commit is contained in:
Kurt 2019-02-15 00:50:23 -08:00
parent 3b8974665e
commit 858760fa28
9 changed files with 142 additions and 105 deletions

View file

@ -231,47 +231,4 @@ namespace PKHeX.Core
return Strings.GetLocationList(version, pkmFormat, egg); return Strings.GetLocationList(version, pkmFormat, egg);
} }
} }
public enum ProgramLanguage
{
/// <summary>
/// Japanese
/// </summary>
,
/// <summary>
/// English
/// </summary>
English,
/// <summary>
/// French
/// </summary>
Français,
/// <summary>
/// Italian
/// </summary>
Italiano,
/// <summary>
/// German
/// </summary>
Deutsch,
/// <summary>
/// Spanish
/// </summary>
Español,
/// <summary>
/// Korean
/// </summary>
,
/// <summary>
/// Chinese
/// </summary>
,
}
} }

View file

@ -327,10 +327,12 @@ namespace PKHeX.Core
public MemoryStrings Memories { get; private set; } public MemoryStrings Memories { get; private set; }
// ignores Poke/Great/Ultra
private static readonly int[] ball_nums = { 007, 576, 013, 492, 497, 014, 495, 493, 496, 494, 011, 498, 008, 006, 012, 015, 009, 005, 499, 010, 001, 016, 851 };
private static readonly int[] ball_vals = { 007, 025, 013, 017, 022, 014, 020, 018, 021, 019, 011, 023, 008, 006, 012, 015, 009, 005, 024, 010, 001, 016, 026 };
private void InitializeDataSources() private void InitializeDataSources()
{ {
int[] ball_nums = { 007, 576, 013, 492, 497, 014, 495, 493, 496, 494, 011, 498, 008, 006, 012, 015, 009, 005, 499, 010, 001, 016, 851 };
int[] ball_vals = { 007, 025, 013, 017, 022, 014, 020, 018, 021, 019, 011, 023, 008, 006, 012, 015, 009, 005, 024, 010, 001, 016, 026 };
BallDataSource = Util.GetVariedCBListBall(itemlist, ball_nums, ball_vals); BallDataSource = Util.GetVariedCBListBall(itemlist, ball_nums, ball_vals);
SpeciesDataSource = Util.GetCBList(specieslist); SpeciesDataSource = Util.GetCBList(specieslist);
NatureDataSource = Util.GetCBList(natures); NatureDataSource = Util.GetCBList(natures);
@ -437,50 +439,57 @@ namespace PKHeX.Core
ItemDataSource = Util.GetCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int)i)).ToArray()); ItemDataSource = Util.GetCBList(items, (allowed == null || HaX ? Enumerable.Range(0, MaxItemID) : allowed.Select(i => (int)i)).ToArray());
} }
public IReadOnlyList<ComboItem> GetLocationList(GameVersion Version, int SaveFormat, bool egg) /// <summary>
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
/// </summary>
/// <param name="version">Origin version</param>
/// <param name="currentGen">Current savefile generation</param>
/// <param name="egg">True if an egg location list, false if a regular met location list</param>
/// <returns>Met location list</returns>
public IReadOnlyList<ComboItem> GetLocationList(GameVersion version, int currentGen, bool egg = false)
{ {
if (SaveFormat == 2) if (currentGen == 2)
return MetGen2; return MetGen2;
if (egg && Version < GameVersion.W && SaveFormat >= 5) if (egg && version < GameVersion.W && currentGen >= 5)
return MetGen4; return MetGen4;
switch (Version) switch (version)
{ {
case GameVersion.CXD: case GameVersion.CXD:
if (SaveFormat == 3) if (currentGen == 3)
return MetGen3CXD; return MetGen3CXD;
break; break;
case GameVersion.R: case GameVersion.R:
case GameVersion.S: case GameVersion.S:
if (SaveFormat == 3) if (currentGen == 3)
return MetGen3.OrderByDescending(loc => loc.Value <= 87).ToList(); // Ferry return MetGen3.OrderByDescending(loc => loc.Value <= 87).ToList(); // Ferry
break; break;
case GameVersion.E: case GameVersion.E:
if (SaveFormat == 3) if (currentGen == 3)
return MetGen3.OrderByDescending(loc => loc.Value <= 87 || (loc.Value >= 196 && loc.Value <= 212)).ToList(); // Trainer Hill return MetGen3.OrderByDescending(loc => loc.Value <= 87 || (loc.Value >= 196 && loc.Value <= 212)).ToList(); // Trainer Hill
break; break;
case GameVersion.FR: case GameVersion.FR:
case GameVersion.LG: case GameVersion.LG:
if (SaveFormat == 3) if (currentGen == 3)
return MetGen3.OrderByDescending(loc => loc.Value > 87 && loc.Value < 197).ToList(); // Celadon Dept. return MetGen3.OrderByDescending(loc => loc.Value > 87 && loc.Value < 197).ToList(); // Celadon Dept.
break; break;
case GameVersion.D: case GameVersion.D:
case GameVersion.P: case GameVersion.P:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg)) if (currentGen == 4 || (currentGen >= 5 && egg))
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 111)).ToList(); // Battle Park return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 111)).ToList(); // Battle Park
break; break;
case GameVersion.Pt: case GameVersion.Pt:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg)) if (currentGen == 4 || (currentGen >= 5 && egg))
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 125)).ToList(); // Rock Peak Ruins return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value <= 125)).ToList(); // Rock Peak Ruins
break; break;
case GameVersion.HG: case GameVersion.HG:
case GameVersion.SS: case GameVersion.SS:
if (SaveFormat == 4 || (SaveFormat >= 5 && egg)) if (currentGen == 4 || (currentGen >= 5 && egg))
return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value > 125 && loc.Value < 234)).ToList(); // Celadon Dept. return MetGen4.Take(4).Concat(MetGen4.Skip(4).OrderByDescending(loc => loc.Value > 125 && loc.Value < 234)).ToList(); // Celadon Dept.
break; break;
@ -523,22 +532,32 @@ namespace PKHeX.Core
return MetGen7GG.Take(3).Concat(MetGen7GG.Skip(3).OrderByDescending(loc => loc.Value <= 54)).ToList(); // Pokémon League return MetGen7GG.Take(3).Concat(MetGen7GG.Skip(3).OrderByDescending(loc => loc.Value <= 54)).ToList(); // Pokémon League
} }
// Currently on a future game, return corresponding list for generation return GetLocationListModified(version, currentGen);
if (Version <= GameVersion.CXD && SaveFormat == 4) }
/// <summary>
/// Fetches a Met Location list for a <see cref="version"/> that has been transferred away from and overwritten.
/// </summary>
/// <param name="version">Origin version</param>
/// <param name="currentGen">Current savefile generation</param>
/// <returns>Met location list</returns>
private IReadOnlyList<ComboItem> GetLocationListModified(GameVersion version, int currentGen)
{
if (version <= GameVersion.CXD && currentGen == 4)
{ {
return MetGen4.Where(loc => loc.Value == Legal.Transfer3) // Pal Park to front return MetGen4.Where(loc => loc.Value == Legal.Transfer3) // Pal Park to front
.Concat(MetGen4.Take(4)) .Concat(MetGen4.Take(4))
.Concat(MetGen4.Skip(4).Where(loc => loc.Value != Legal.Transfer3)).ToList(); .Concat(MetGen4.Skip(4).Where(loc => loc.Value != Legal.Transfer3)).ToList();
} }
if (Version < GameVersion.X && SaveFormat >= 5) // PokéTransfer to front if (version < GameVersion.X && currentGen >= 5) // PokéTransfer to front
{ {
return MetGen5.Where(loc => loc.Value == Legal.Transfer4) return MetGen5.Where(loc => loc.Value == Legal.Transfer4)
.Concat(MetGen5.Take(3)) .Concat(MetGen5.Take(3))
.Concat(MetGen5.Skip(3).Where(loc => loc.Value != Legal.Transfer4)).ToList(); .Concat(MetGen5.Skip(3).Where(loc => loc.Value != Legal.Transfer4)).ToList();
} }
return MetGen6; return Array.Empty<ComboItem>();
} }
public static IReadOnlyList<ComboItem> LanguageDataSource(int gen) public static IReadOnlyList<ComboItem> LanguageDataSource(int gen)

View file

@ -29,7 +29,7 @@ namespace PKHeX.Core
{ {
if (!sav.Exportable) // Blank save file if (!sav.Exportable) // Blank save file
{ {
sav.FileFolder = sav.FilePath = null; sav.FileFolder = sav.FilePath = string.Empty;
sav.FileName = "Blank Save File"; sav.FileName = "Blank Save File";
return; return;
} }
@ -154,5 +154,48 @@ namespace PKHeX.Core
yield return pk; yield return pk;
} }
} }
/// <summary>
/// Gets a compatible <see cref="PKM"/> for editing with a new <see cref="SaveFile"/>.
/// </summary>
/// <param name="sav">SaveFile to receive the compatible <see cref="pk"/></param>
/// <param name="pk">Current Pokémon being edited</param>
/// <returns>Current Pokémon, assuming conversion is possible. If conversion is not possible, a blank <see cref="PKM"/> will be obtained from the <see cref="sav"/>.</returns>
public static PKM GetCompatiblePKM(this SaveFile sav, PKM pk = null)
{
if (pk == null)
return sav.BlankPKM;
if (pk.Format < 3 && sav.Generation < 7)
{
// gen1-2 compatibility check
if (pk.Japanese != sav.Japanese)
return sav.BlankPKM;
if (sav is SAV2 s2 && s2.Korean != pk.Korean)
return sav.BlankPKM;
}
return PKMConverter.ConvertToType(pk, sav.PKMType, out _) ?? sav.BlankPKM;
}
/// <summary>
/// Gets a blank file for the save file. If the template path exists, a template load will be attempted.
/// </summary>
/// <param name="sav">Save File to fetch a template for</param>
/// <param name="templatePath">Path to look for a template in</param>
/// <returns>Template if it exists, or a blank <see cref="PKM"/> from the <see cref="sav"/></returns>
public static PKM LoadTemplate(this SaveFile sav, string templatePath = null)
{
var blank = sav.BlankPKM;
if (!Directory.Exists(templatePath))
return blank;
var di = new DirectoryInfo(templatePath);
string path = Path.Combine(templatePath, $"{di.Name}.{blank.Extension}");
if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length))
return blank;
var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format);
return PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path) ?? blank; // no sneaky plz; reuse string
}
} }
} }

View file

@ -37,7 +37,7 @@ namespace PKHeX.WinForms
private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names) private PictureBox GetBallView(Ball b, ICollection<Ball> legal, IReadOnlyList<ComboItem> names)
{ {
var img = SpriteUtil.GetBallSprite((int) b); var img = SpriteUtil.GetBallSprite((int)b);
var pb = new PictureBox var pb = new PictureBox
{ {
Size = img.Size, Size = img.Size,
@ -45,7 +45,7 @@ namespace PKHeX.WinForms
BackgroundImage = legal.Contains(b) ? Resources.slotSet : Resources.slotDel, BackgroundImage = legal.Contains(b) ? Resources.slotSet : Resources.slotDel,
BackgroundImageLayout = ImageLayout.Tile BackgroundImageLayout = ImageLayout.Tile
}; };
pb.MouseEnter += (_, __) => Text = names.First(z => z.Value == (int) b).Text; pb.MouseEnter += (_, __) => Text = names.First(z => z.Value == (int)b).Text;
pb.Click += (_, __) => SelectBall(b); pb.Click += (_, __) => SelectBall(b);
return pb; return pb;
} }

View file

@ -1205,8 +1205,6 @@ namespace PKHeX.WinForms.Controls
case Keys.Control: RequestShowdownImport?.Invoke(sender, e); return; case Keys.Control: RequestShowdownImport?.Invoke(sender, e); return;
case Keys.Alt: RequestShowdownExport?.Invoke(sender, e); return; case Keys.Alt: RequestShowdownExport?.Invoke(sender, e); return;
default: default:
if (pkm is PK1 pk1)
pk1.Catch_Rate = pk1.PersonalInfo.CatchRate;
return; return;
} }
} }
@ -1466,11 +1464,8 @@ namespace PKHeX.WinForms.Controls
FieldsLoaded = true; FieldsLoaded = true;
} }
private void ValidateComboBox(object sender) private void ValidateComboBox(ComboBox cb)
{ {
if (!(sender is ComboBox cb))
return;
if (cb.Text.Length == 0 && cb.Items.Count > 0) if (cb.Text.Length == 0 && cb.Items.Count > 0)
cb.SelectedIndex = 0; cb.SelectedIndex = 0;
else if (cb.SelectedValue == null) else if (cb.SelectedValue == null)
@ -1481,10 +1476,10 @@ namespace PKHeX.WinForms.Controls
private void ValidateComboBox(object sender, CancelEventArgs e) private void ValidateComboBox(object sender, CancelEventArgs e)
{ {
if (!(sender is ComboBox)) if (!(sender is ComboBox cb))
return; return;
ValidateComboBox(sender); ValidateComboBox(cb);
UpdateSprite(); UpdateSprite();
} }
@ -1522,7 +1517,7 @@ namespace PKHeX.WinForms.Controls
if (!FieldsLoaded) if (!FieldsLoaded)
return; return;
ValidateComboBox(sender); ValidateComboBox((ComboBox)sender);
if (Moves.Contains(sender)) // Move if (Moves.Contains(sender)) // Move
UpdatePP(sender, e); UpdatePP(sender, e);
@ -1565,10 +1560,10 @@ namespace PKHeX.WinForms.Controls
private void ValidateLocation(object sender, EventArgs e) private void ValidateLocation(object sender, EventArgs e)
{ {
ValidateComboBox(sender);
if (!FieldsLoaded) if (!FieldsLoaded)
return; return;
ValidateComboBox((ComboBox)sender);
pkm.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation); pkm.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation);
pkm.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation); pkm.Egg_Location = WinFormsUtil.GetIndex(CB_EggLocation);
UpdateLegality(); UpdateLegality();
@ -1596,7 +1591,7 @@ namespace PKHeX.WinForms.Controls
/// <param name="pk">Pokémon data to edit</param> /// <param name="pk">Pokémon data to edit</param>
public bool ToggleInterface(SaveFile sav, PKM pk) public bool ToggleInterface(SaveFile sav, PKM pk)
{ {
pkm = GetCompatiblePKM(sav, pk); pkm = sav.GetCompatiblePKM(pk);
ToggleInterface(pkm); ToggleInterface(pkm);
return FinalizeInterface(sav); return FinalizeInterface(sav);
} }
@ -1820,12 +1815,5 @@ namespace PKHeX.WinForms.Controls
var abils = pkm.PersonalInfo.Abilities; var abils = pkm.PersonalInfo.Abilities;
return GameInfo.GetAbilityList(abils, pkm.Format); return GameInfo.GetAbilityList(abils, pkm.Format);
} }
private static PKM GetCompatiblePKM(SaveFile sav, PKM current)
{
if (current.Format < 3 || current.GetType() != sav.PKMType)
return sav.BlankPKM;
return current;
}
} }
} }

View file

@ -708,22 +708,6 @@ namespace PKHeX.WinForms
} }
} }
private static PKM LoadTemplate(SaveFile sav)
{
var blank = sav.BlankPKM;
if (!Directory.Exists(TemplatePath))
return blank;
var di = new DirectoryInfo(TemplatePath);
string path = Path.Combine(TemplatePath, $"{di.Name}.{blank.Extension}");
if (!File.Exists(path) || !PKX.IsPKM(new FileInfo(path).Length))
return blank;
var pk = PKMConverter.GetPKMfromBytes(File.ReadAllBytes(path), prefer: blank.Format);
return PKMConverter.ConvertToType(pk, sav.BlankPKM.GetType(), out path) ?? blank; // no sneaky plz; reuse string
}
private bool OpenSAV(SaveFile sav, string path) private bool OpenSAV(SaveFile sav, string path)
{ {
if (sav == null || sav.Version == GameVersion.Invalid) if (sav == null || sav.Version == GameVersion.Invalid)
@ -762,7 +746,7 @@ namespace PKHeX.WinForms
bool WindowToggleRequired = C_SAV.SAV?.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack bool WindowToggleRequired = C_SAV.SAV?.Generation < 3 && sav.Generation >= 3; // version combobox refresh hack
C_SAV.SAV = sav; C_SAV.SAV = sav;
var pk = LoadTemplate(sav); var pk = sav.LoadTemplate(TemplatePath);
var isBlank = pk.Data.SequenceEqual(sav.BlankPKM.Data); var isBlank = pk.Data.SequenceEqual(sav.BlankPKM.Data);
bool init = PKME_Tabs.pkm == null; bool init = PKME_Tabs.pkm == null;
PKME_Tabs.CurrentPKM = pk; PKME_Tabs.CurrentPKM = pk;
@ -1135,8 +1119,9 @@ namespace PKHeX.WinForms
try try
{ {
File.WriteAllBytes(newfile, dragdata); File.WriteAllBytes(newfile, dragdata);
PictureBox pb = (PictureBox)sender;
C_SAV.M.DragInfo.Source.PKM = pkx; C_SAV.M.DragInfo.Source.PKM = pkx;
var pb = (PictureBox)sender;
if (pb.Image != null) if (pb.Image != null)
C_SAV.M.DragInfo.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon()); C_SAV.M.DragInfo.Cursor = Cursor = new Cursor(((Bitmap)pb.Image).GetHicon());
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);

View file

@ -0,0 +1,45 @@
namespace PKHeX.WinForms
{
public enum ProgramLanguage
{
/// <summary>
/// Japanese
/// </summary>
,
/// <summary>
/// English
/// </summary>
English,
/// <summary>
/// French
/// </summary>
Français,
/// <summary>
/// Italian
/// </summary>
Italiano,
/// <summary>
/// German
/// </summary>
Deutsch,
/// <summary>
/// Spanish
/// </summary>
Español,
/// <summary>
/// Korean
/// </summary>
,
/// <summary>
/// Chinese
/// </summary>
,
}
}

View file

@ -267,6 +267,7 @@
<DependentUpon>PKMEditor.cs</DependentUpon> <DependentUpon>PKMEditor.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="MainWindow\PluginLoader.cs" /> <Compile Include="MainWindow\PluginLoader.cs" />
<Compile Include="MainWindow\ProgramLanguage.cs" />
<Compile Include="Misc\About.cs"> <Compile Include="Misc\About.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View file

@ -49,8 +49,7 @@ namespace PKHeX.Tests.Legality
var data = File.ReadAllBytes(file); var data = File.ReadAllBytes(file);
var format = PKX.GetPKMFormatFromExtension(file[file.Length - 1], -1); var format = PKX.GetPKMFormatFromExtension(file[file.Length - 1], -1);
if (format > 10) format.Should().BeLessOrEqualTo(PKX.Generation, "filename is expected to have a valid extension");
format = 6;
var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format); var pkm = PKMConverter.GetPKMfromBytes(data, prefer: format);
pkm.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded"); pkm.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded");