mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Minor clean
This commit is contained in:
parent
e25b2037e2
commit
ea85d5e6b0
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using static PKHeX.Core.LearnMethod;
|
||||
|
||||
namespace PKHeX.Core;
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ public static class StringConverter1
|
|||
public const char Terminator = '\0';
|
||||
public const char TradeOT = '*';
|
||||
|
||||
public static bool GetIsJapanese(ReadOnlySpan<char> str) => AllJapanese(str);
|
||||
|
||||
private static bool AllJapanese(ReadOnlySpan<char> str)
|
||||
/// <summary>
|
||||
/// Quick check if the input string is entirely Japanese characters.
|
||||
/// </summary>
|
||||
public static bool GetIsJapanese(ReadOnlySpan<char> str)
|
||||
{
|
||||
foreach (var x in str)
|
||||
{
|
||||
|
|
@ -202,6 +203,7 @@ private static bool TryGetUserFriendlyRemap(in ReadOnlySpan<char> dict, char c,
|
|||
|
||||
#region Gen 1 Character Tables
|
||||
|
||||
// Share all to Gen2's tables.
|
||||
internal const char NUL = Terminator;
|
||||
internal const char TOT = TradeOT;
|
||||
internal const char LPK = '{'; // Pk
|
||||
|
|
@ -210,9 +212,9 @@ private static bool TryGetUserFriendlyRemap(in ReadOnlySpan<char> dict, char c,
|
|||
internal const char LPO = '@'; // Po
|
||||
internal const char LKE = '#'; // Ke
|
||||
internal const char LEA = '%'; // é for Box/Mail
|
||||
public const char DOT = '․'; // . for MR.MIME (U+2024, not U+002E)
|
||||
internal const char DOT = '․'; // . for MR.MIME (U+2024, not U+002E)
|
||||
internal const char SPF = ' '; // Full-width space (U+3000)
|
||||
public const char SPH = ' '; // Half-width space
|
||||
internal const char SPH = ' '; // Half-width space
|
||||
|
||||
public static ReadOnlySpan<char> TableEN =>
|
||||
[
|
||||
|
|
|
|||
|
|
@ -18,18 +18,7 @@ public static class StringConverter2
|
|||
public const char TradeOT = StringConverter1.TradeOT;
|
||||
public const char LineBreak = '⏎'; // Mail
|
||||
|
||||
public static bool GetIsJapanese(ReadOnlySpan<char> str) => AllJapanese(str);
|
||||
|
||||
private static bool AllJapanese(ReadOnlySpan<char> str)
|
||||
{
|
||||
foreach (var x in str)
|
||||
{
|
||||
if (!IsJapanese(x))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
static bool IsJapanese(char c) => c is >= '\u3000' and <= '\u30FC';
|
||||
}
|
||||
public static bool GetIsJapanese(ReadOnlySpan<char> str) => StringConverter1.GetIsJapanese(str);
|
||||
|
||||
public static bool GetIsEnglish(ReadOnlySpan<char> str) => !GetIsJapanese(str);
|
||||
public static bool GetIsJapanese(ReadOnlySpan<byte> raw) => AllCharsInTable(raw, TableJP);
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ public static int LoadStringUnicodeBR(ReadOnlySpan<byte> data, Span<char> result
|
|||
return ctr;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetStringUnicode(ReadOnlySpan{char}, Span{byte}, int, StringConverterOption))"/>
|
||||
/// <inheritdoc cref="SetStringUnicode(ReadOnlySpan{char}, Span{byte}, int, StringConverterOption)"/>
|
||||
public static int SetStringUnicodeBR(ReadOnlySpan<char> value, Span<byte> destBuffer, int maxLength = -1, StringConverterOption option = StringConverterOption.ClearZero)
|
||||
{
|
||||
if (maxLength < 0)
|
||||
|
|
|
|||
|
|
@ -121,14 +121,7 @@ private void LoadBlankSaveFile(GameVersion version)
|
|||
if (!version.IsValidSavedVersion())
|
||||
version = Latest.Version;
|
||||
var current = C_SAV?.SAV;
|
||||
var lang = BlankSaveFile.GetSafeLanguage(current);
|
||||
var tr = BlankSaveFile.GetSafeTrainerName(current, lang);
|
||||
var sav = BlankSaveFile.Get(version, tr, lang);
|
||||
if (sav.Version == GameVersion.Invalid) // will fail to load
|
||||
{
|
||||
version = Latest.Version;
|
||||
sav = BlankSaveFile.Get(version, tr, lang);
|
||||
}
|
||||
var sav = BlankSaveFile.Get(version, current);
|
||||
OpenSAV(sav, string.Empty);
|
||||
C_SAV!.SAV.State.Edited = false; // Prevents form close warning from showing until changes are made
|
||||
}
|
||||
|
|
@ -425,7 +418,7 @@ private void MainMenuFolder(object sender, EventArgs e)
|
|||
}
|
||||
|
||||
// Misc Options
|
||||
private void ClickShowdownImportPKM(object sender, EventArgs e)
|
||||
private void ClickShowdownImportPKM(object? sender, EventArgs e)
|
||||
{
|
||||
if (!Clipboard.ContainsText())
|
||||
{ WinFormsUtil.Alert(MsgClipboardFailRead); return; }
|
||||
|
|
@ -1146,42 +1139,49 @@ private void Main_DragDrop(object? sender, DragEventArgs? e)
|
|||
// ReSharper disable once AsyncVoidMethod
|
||||
private async void Dragout_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button != MouseButtons.Left)
|
||||
return;
|
||||
|
||||
if (ModifierKeys is Keys.Alt or Keys.Shift)
|
||||
{
|
||||
ClickQR(sender, e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PKME_Tabs.EditsComplete)
|
||||
return;
|
||||
|
||||
// Gather data
|
||||
var pk = PreparePKM();
|
||||
var encrypt = ModifierKeys == Keys.Control;
|
||||
var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData;
|
||||
|
||||
// Create Temp File to Drag
|
||||
var newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
||||
try
|
||||
{
|
||||
await File.WriteAllBytesAsync(newfile, data).ConfigureAwait(true);
|
||||
if (e.Button != MouseButtons.Left)
|
||||
return;
|
||||
|
||||
var pb = (PictureBox)sender;
|
||||
if (pb.Image is Bitmap img)
|
||||
C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon());
|
||||
if (ModifierKeys is Keys.Alt or Keys.Shift)
|
||||
{
|
||||
ClickQR(sender, e);
|
||||
return;
|
||||
}
|
||||
|
||||
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
|
||||
if (!PKME_Tabs.EditsComplete)
|
||||
return;
|
||||
|
||||
// Gather data
|
||||
var pk = PreparePKM();
|
||||
var encrypt = ModifierKeys == Keys.Control;
|
||||
var data = encrypt ? pk.EncryptedPartyData : pk.DecryptedPartyData;
|
||||
|
||||
// Create Temp File to Drag
|
||||
var newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
||||
try
|
||||
{
|
||||
await File.WriteAllBytesAsync(newfile, data).ConfigureAwait(true);
|
||||
|
||||
var pb = (PictureBox)sender;
|
||||
if (pb.Image is Bitmap img)
|
||||
C_SAV.M.Drag.Info.Cursor = Cursor = new Cursor(img.GetHicon());
|
||||
|
||||
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy);
|
||||
}
|
||||
// Tons of things can happen with drag & drop; don't try to handle things, just indicate failure.
|
||||
catch (Exception x)
|
||||
{ WinFormsUtil.Error("Drag && Drop Error", x); }
|
||||
finally
|
||||
{
|
||||
C_SAV.M.Drag.ResetCursor(this);
|
||||
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
// Tons of things can happen with drag & drop; don't try to handle things, just indicate failure.
|
||||
catch (Exception x)
|
||||
{ WinFormsUtil.Error("Drag && Drop Error", x); }
|
||||
finally
|
||||
catch
|
||||
{
|
||||
C_SAV.M.Drag.ResetCursor(this);
|
||||
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -613,26 +613,33 @@ static ushort GetU16(ListControl cb)
|
|||
// ReSharper disable once AsyncVoidMethod
|
||||
private async void B_Search_Click(object sender, EventArgs e)
|
||||
{
|
||||
B_Search.Enabled = false;
|
||||
var search = SearchDatabase();
|
||||
|
||||
bool legalSearch = Menu_SearchLegal.Checked ^ Menu_SearchIllegal.Checked;
|
||||
bool wordFilter = ParseSettings.Settings.WordFilter.CheckWordFilter;
|
||||
if (wordFilter && legalSearch && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBSearchLegalityWordfilter) == DialogResult.No)
|
||||
ParseSettings.Settings.WordFilter.CheckWordFilter = false;
|
||||
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
|
||||
ParseSettings.Settings.WordFilter.CheckWordFilter = wordFilter;
|
||||
|
||||
if (results.Count == 0)
|
||||
try
|
||||
{
|
||||
if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked && !Menu_SearchBackups.Checked)
|
||||
WinFormsUtil.Alert(MsgDBSearchFail, MsgDBSearchNone);
|
||||
else
|
||||
WinFormsUtil.Alert(MsgDBSearchNone);
|
||||
B_Search.Enabled = false;
|
||||
var search = SearchDatabase();
|
||||
|
||||
bool legalSearch = Menu_SearchLegal.Checked ^ Menu_SearchIllegal.Checked;
|
||||
bool wordFilter = ParseSettings.Settings.WordFilter.CheckWordFilter;
|
||||
if (wordFilter && legalSearch && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgDBSearchLegalityWordfilter) == DialogResult.No)
|
||||
ParseSettings.Settings.WordFilter.CheckWordFilter = false;
|
||||
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
|
||||
ParseSettings.Settings.WordFilter.CheckWordFilter = wordFilter;
|
||||
|
||||
if (results.Count == 0)
|
||||
{
|
||||
if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked && !Menu_SearchBackups.Checked)
|
||||
WinFormsUtil.Alert(MsgDBSearchFail, MsgDBSearchNone);
|
||||
else
|
||||
WinFormsUtil.Alert(MsgDBSearchNone);
|
||||
}
|
||||
SetResults(results); // updates Count Label as well.
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Search.Enabled = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
SetResults(results); // updates Count Label as well.
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Search.Enabled = true;
|
||||
}
|
||||
|
||||
private void UpdateScroll(object sender, ScrollEventArgs e)
|
||||
|
|
|
|||
|
|
@ -412,31 +412,38 @@ static ushort GetU16(ListControl cb)
|
|||
// ReSharper disable once AsyncVoidMethod
|
||||
private async void B_Search_Click(object sender, EventArgs e)
|
||||
{
|
||||
B_Search.Enabled = false;
|
||||
EncounterMovesetGenerator.PriorityList = GetTypes();
|
||||
|
||||
var token = TokenSource.Token;
|
||||
var search = SearchDatabase(token);
|
||||
if (token.IsCancellationRequested)
|
||||
try
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
}
|
||||
B_Search.Enabled = false;
|
||||
EncounterMovesetGenerator.PriorityList = GetTypes();
|
||||
|
||||
var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true);
|
||||
if (token.IsCancellationRequested)
|
||||
var token = TokenSource.Token;
|
||||
var search = SearchDatabase(token);
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
var results = await Task.Run(() => search.ToList(), token).ConfigureAwait(true);
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.Count == 0)
|
||||
WinFormsUtil.Alert(MsgDBSearchNone);
|
||||
|
||||
SetResults(results); // updates Count Label as well.
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Search.Enabled = true;
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
}
|
||||
catch
|
||||
{
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
return;
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
if (results.Count == 0)
|
||||
WinFormsUtil.Alert(MsgDBSearchNone);
|
||||
|
||||
SetResults(results); // updates Count Label as well.
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Search.Enabled = true;
|
||||
EncounterMovesetGenerator.ResetFilters();
|
||||
}
|
||||
|
||||
private void UpdateScroll(object sender, ScrollEventArgs e)
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ public partial class SAV_BattlePass : Form
|
|||
private readonly string[] Skin = WinFormsTranslator.GetEnumTranslation<SkinColorBR>(Main.CurrentLanguage);
|
||||
private readonly string[] PictureTypes = WinFormsTranslator.GetEnumTranslation<PictureTypeBR>(Main.CurrentLanguage);
|
||||
private readonly string[] PassDesigns = GameLanguage.GetStrings("pass_design", Main.CurrentLanguage);
|
||||
private readonly string[] TrainerTitles1 = GameLanguage.GetStrings($"trainer_title", Main.CurrentLanguage);
|
||||
private readonly string[] TrainerTitles2 = GameLanguage.GetStrings($"trainer_title_npc", Main.CurrentLanguage);
|
||||
private readonly string[] TrainerTitles1 = GameLanguage.GetStrings("trainer_title", Main.CurrentLanguage);
|
||||
private readonly string[] TrainerTitles2 = GameLanguage.GetStrings("trainer_title_npc", Main.CurrentLanguage);
|
||||
|
||||
private readonly IReadOnlyList<ComboItem> Languages = GameInfo.LanguageDataSource(3);
|
||||
private readonly IReadOnlyList<ComboItem> EmptyCBList = [new ComboItem(string.Empty, 0)];
|
||||
private const string NPC = "NPC";
|
||||
private string None => CharacterStyles[0];
|
||||
|
||||
private bool loading = true;
|
||||
private bool loading;
|
||||
|
||||
public SAV_BattlePass(SAV4BR sav, IPKMView view, int index = 0)
|
||||
{
|
||||
|
|
@ -323,7 +323,7 @@ private void LoadBattlePassList()
|
|||
string type = WinFormsTranslator.TranslateEnum(SAV.BattlePasses.GetPassType(i), Main.CurrentLanguage);
|
||||
BattlePass pass = GetBattlePassReference(i);
|
||||
string name = pass.Name;
|
||||
if ((!pass.Rental && !pass.Issued) || string.IsNullOrWhiteSpace(name))
|
||||
if (pass is { Rental: false, Issued: false } || string.IsNullOrWhiteSpace(name))
|
||||
name = None;
|
||||
LB_Passes.Items.Add($"{i + 1:00} {type}/{name}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -470,40 +470,47 @@ private void ImportQRToView(string url)
|
|||
// ReSharper disable once AsyncVoidMethod
|
||||
private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e)
|
||||
{
|
||||
if (sender is null)
|
||||
return;
|
||||
switch (ModifierKeys)
|
||||
{
|
||||
case Keys.Control: ClickView(sender, e); return;
|
||||
case Keys.Shift: ClickSet(sender, e); return;
|
||||
case Keys.Alt: ClickDelete(sender, e); return;
|
||||
}
|
||||
var pb = sender as PictureBox;
|
||||
if (pb?.Image is null)
|
||||
return;
|
||||
|
||||
if (e.Button != MouseButtons.Left || e.Clicks != 1)
|
||||
return;
|
||||
|
||||
int index = pba.IndexOf(pb);
|
||||
var gift = Album[index];
|
||||
if (gift.IsEmpty)
|
||||
return;
|
||||
|
||||
// Create Temp File to Drag
|
||||
wc_slot = index;
|
||||
Cursor.Current = Cursors.Hand;
|
||||
string newfile = Path.Combine(Path.GetTempPath(), PathUtil.CleanFileName(gift.FileName));
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(newfile, gift.Write());
|
||||
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy | DragDropEffects.Move);
|
||||
if (sender is null)
|
||||
return;
|
||||
switch (ModifierKeys)
|
||||
{
|
||||
case Keys.Control: ClickView(sender, e); return;
|
||||
case Keys.Shift: ClickSet(sender, e); return;
|
||||
case Keys.Alt: ClickDelete(sender, e); return;
|
||||
}
|
||||
var pb = sender as PictureBox;
|
||||
if (pb?.Image is null)
|
||||
return;
|
||||
|
||||
if (e.Button != MouseButtons.Left || e.Clicks != 1)
|
||||
return;
|
||||
|
||||
int index = pba.IndexOf(pb);
|
||||
var gift = Album[index];
|
||||
if (gift.IsEmpty)
|
||||
return;
|
||||
|
||||
// Create Temp File to Drag
|
||||
wc_slot = index;
|
||||
Cursor.Current = Cursors.Hand;
|
||||
string newfile = Path.Combine(Path.GetTempPath(), PathUtil.CleanFileName(gift.FileName));
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(newfile, gift.Write());
|
||||
DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Copy | DragDropEffects.Move);
|
||||
}
|
||||
// Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message.
|
||||
catch (Exception x)
|
||||
{ WinFormsUtil.Error("Drag & Drop Error", x); }
|
||||
wc_slot = -1;
|
||||
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
// Sometimes the drag-drop is canceled or ends up at a bad location. Don't bother recovering from an exception; just display a safe error message.
|
||||
catch (Exception x)
|
||||
{ WinFormsUtil.Error("Drag & Drop Error", x); }
|
||||
wc_slot = -1;
|
||||
await DeleteAsync(newfile, 20_000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task DeleteAsync(string path, int delay)
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ private static IEnumerable<object> GetTranslatableControls(Control f)
|
|||
if (z is ListControl or TextBoxBase or LinkLabel or NumericUpDown or ContainerControl)
|
||||
break; // undesirable to modify, ignore
|
||||
|
||||
if (z is DataGridView dgv && dgv.ColumnHeadersVisible)
|
||||
if (z is DataGridView { ColumnHeadersVisible: true } dgv)
|
||||
{
|
||||
foreach (DataGridViewColumn col in dgv.Columns)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ namespace PKHeX.Core.Tests;
|
|||
public static class LocalizationTests
|
||||
{
|
||||
[Fact]
|
||||
public static void EncounterDisplay() => EncounterDisplayLocalization.Cache.GetAll();
|
||||
public static void EncounterDisplay() => _ = EncounterDisplayLocalization.Cache.GetAll();
|
||||
|
||||
[Fact]
|
||||
public static void MoveSource() => MoveSourceLocalization.Cache.GetAll();
|
||||
public static void MoveSource() => _ = MoveSourceLocalization.Cache.GetAll();
|
||||
|
||||
[Fact]
|
||||
public static void LegalityCheck() => LegalityCheckLocalization.Cache.GetAll();
|
||||
public static void LegalityCheck() => _ = LegalityCheckLocalization.Cache.GetAll();
|
||||
|
||||
[Fact]
|
||||
public static void General() => GeneralLocalization.Cache.GetAll();
|
||||
public static void General() => _ = GeneralLocalization.Cache.GetAll();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,8 +134,6 @@ private static void VerifyAll(string folder, string subFolder, bool isValid, boo
|
|||
ParseSettings.Settings.Tradeback.AllowGen1Tradeback = dn.Contains("1 Tradeback");
|
||||
var pk = EntityFormat.GetFromBytes(data, prefer);
|
||||
pk.Should().NotBeNull($"the PKM '{new FileInfo(file).Name}' should have been loaded");
|
||||
if (pk is null)
|
||||
continue;
|
||||
var legality = new LegalityAnalysis(pk);
|
||||
if (legality.Valid == isValid)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user