From 6bd1dc285f86e4ad42107b03f1b9a99c24ff93b7 Mon Sep 17 00:00:00 2001 From: Michael Bond Date: Tue, 17 Dec 2024 18:15:38 -0500 Subject: [PATCH] Even more code tweaks --- Pkmds.Web/Components/BoxComponent.razor.cs | 6 +- Pkmds.Web/Components/BoxGrid.razor.cs | 6 +- Pkmds.Web/Components/BoxSlotComponent.cs | 3 +- Pkmds.Web/Components/DateOnlyPicker.razor.cs | 42 ++++----- .../Dialogs/ConfirmActionDialog.razor.cs | 30 +++---- .../Dialogs/ShowdownExportDialog.razor.cs | 10 +-- .../EditForms/PokemonEditForm.razor.cs | 35 +++----- .../EditForms/Tabs/CosmeticTab.razor.cs | 3 +- .../Components/EditForms/Tabs/MetTab.razor.cs | 17 ++-- .../EditForms/Tabs/MovesTab.razor.cs | 7 +- .../EditForms/Tabs/OtMiscTab.razor.cs | 5 +- .../EditForms/Tabs/PokerusComponent.razor.cs | 47 +++++----- .../EditForms/Tabs/StatsTab.razor.cs | 10 +-- .../GenderDisplayComponent.razor.cs | 21 ++--- .../Components/Layout/MainLayout.razor.cs | 60 +++---------- .../Components/LetsGoBoxComponent.razor.cs | 3 +- .../Components/MainTabPages/BagTab.razor.cs | 19 ++-- .../MainTabPages/MysteryGiftDatabaseTab.razor | 10 +-- .../MysteryGiftDatabaseTab.razor.cs | 39 ++++---- .../MainTabPages/RecordsTab.razor.cs | 2 +- .../MainTabPages/TrainerInfoTab.razor.cs | 32 ++++--- .../Components/MarkingComponent.razor.cs | 6 +- .../Components/MarkingsContainer.razor.cs | 3 +- Pkmds.Web/Components/Pages/Home.razor.cs | 5 +- Pkmds.Web/Components/PartyGrid.razor.cs | 5 +- .../Components/SaveFileComponent.razor.cs | 1 - Pkmds.Web/Components/SaveFileNameDisplay.cs | 4 +- Pkmds.Web/Extensions/MoveExtension.cs | 8 -- Pkmds.Web/Program.cs | 4 +- Pkmds.Web/Services/AppService.cs | 89 ++++++++++--------- Pkmds.Web/Services/BlazorAesProvider.cs | 3 +- Pkmds.Web/Services/IAppService.cs | 8 +- Pkmds.Web/Services/IRefreshService.cs | 1 + Pkmds.Web/Services/JsService.cs | 4 +- Pkmds.Web/Services/RefreshService.cs | 2 +- Pkmds.Web/SpriteHelper.cs | 62 +++++++------ 36 files changed, 283 insertions(+), 329 deletions(-) delete mode 100644 Pkmds.Web/Extensions/MoveExtension.cs diff --git a/Pkmds.Web/Components/BoxComponent.razor.cs b/Pkmds.Web/Components/BoxComponent.razor.cs index 8d4e46ad..14a4d7e5 100644 --- a/Pkmds.Web/Components/BoxComponent.razor.cs +++ b/Pkmds.Web/Components/BoxComponent.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components; public partial class BoxComponent : IDisposable { - [Parameter] - public int BoxNumber { get; set; } + [Parameter] public int BoxNumber { get; set; } private BoxEdit? BoxEdit { get; set; } @@ -38,9 +37,8 @@ private void ReloadBox() return; } - BoxEdit = new BoxEdit(AppState.SaveFile); + BoxEdit = new(AppState.SaveFile); BoxEdit.LoadBox(BoxNumber); RefreshService.Refresh(); } } - diff --git a/Pkmds.Web/Components/BoxGrid.razor.cs b/Pkmds.Web/Components/BoxGrid.razor.cs index 092dd6e7..ffc55603 100644 --- a/Pkmds.Web/Components/BoxGrid.razor.cs +++ b/Pkmds.Web/Components/BoxGrid.razor.cs @@ -2,11 +2,9 @@ namespace Pkmds.Web.Components; public partial class BoxGrid : IDisposable { - [Parameter, EditorRequired] - public BoxEdit? BoxEdit { get; set; } + [Parameter, EditorRequired] public BoxEdit? BoxEdit { get; set; } - [Parameter, EditorRequired] - public int BoxNumber { get; set; } + [Parameter, EditorRequired] public int BoxNumber { get; set; } private string BoxGridClass => AppState.SaveFile?.BoxSlotCount == 20 ? "box-grid-20" : "box-grid-30"; diff --git a/Pkmds.Web/Components/BoxSlotComponent.cs b/Pkmds.Web/Components/BoxSlotComponent.cs index b46d67b7..91b3c819 100644 --- a/Pkmds.Web/Components/BoxSlotComponent.cs +++ b/Pkmds.Web/Components/BoxSlotComponent.cs @@ -2,6 +2,5 @@ namespace Pkmds.Web.Components; public class BoxSlotComponent : PokemonSlotComponent { - [Parameter, EditorRequired] - public int BoxNumber { get; set; } + [Parameter, EditorRequired] public int BoxNumber { get; set; } } diff --git a/Pkmds.Web/Components/DateOnlyPicker.razor.cs b/Pkmds.Web/Components/DateOnlyPicker.razor.cs index 5b5d7edc..6416d33b 100644 --- a/Pkmds.Web/Components/DateOnlyPicker.razor.cs +++ b/Pkmds.Web/Components/DateOnlyPicker.razor.cs @@ -2,32 +2,23 @@ namespace Pkmds.Web.Components; public partial class DateOnlyPicker { - [CascadingParameter] - public EditContext? EditContext { get; set; } + [CascadingParameter] public EditContext? EditContext { get; set; } - [Parameter, EditorRequired] - public DateOnly? Date { get; set; } + [Parameter, EditorRequired] public DateOnly? Date { get; set; } - [Parameter] - public EventCallback DateChanged { get; set; } + [Parameter] public EventCallback DateChanged { get; set; } - [Parameter, EditorRequired] - public string? Label { get; set; } + [Parameter, EditorRequired] public string? Label { get; set; } - [Parameter] - public Expression>? For { get; set; } + [Parameter] public Expression>? For { get; set; } - [Parameter] - public bool ReadOnly { get; set; } + [Parameter] public bool ReadOnly { get; set; } - [Parameter] - public string? HelperText { get; set; } + [Parameter] public string? HelperText { get; set; } - [Parameter] - public Variant Variant { get; set; } = Variant.Outlined; + [Parameter] public Variant Variant { get; set; } = Variant.Outlined; - [Parameter] - public Color Color { get; set; } = Color.Default; + [Parameter] public Color Color { get; set; } = Color.Default; private MudDatePicker? datePickerRef; @@ -36,11 +27,13 @@ private DateTime? DateBindTarget get => Date?.ToDateTime(TimeOnly.MinValue); set { - if (value is not null) + if (value is null) { - Date = DateOnly.FromDateTime((DateTime)value); - DateChanged.InvokeAsync(Date); + return; } + + Date = DateOnly.FromDateTime((DateTime)value); + DateChanged.InvokeAsync(Date); } } @@ -53,11 +46,14 @@ protected override void OnAfterRender(bool firstRender) if (EditContext is null) { - throw new Exception("Using 'For' without an 'EditContext' is not supported. Are you missing an 'EditForm'?"); + throw new( + "Using 'For' without an 'EditContext' is not supported. Are you missing an 'EditForm'?"); } // Get the private field _fieldidentifier by reflection. - var fieldIdentifierField = typeof(MudFormComponent).GetField("_fieldIdentifier", BindingFlags.Instance | BindingFlags.NonPublic); + var fieldIdentifierField = + typeof(MudFormComponent).GetField("_fieldIdentifier", + BindingFlags.Instance | BindingFlags.NonPublic); // Set the field identifier with our DateOnly? expression, avoiding the type issue between DateOnly vs DateTime fieldIdentifierField?.SetValue(datePickerRef, FieldIdentifier.Create(For)); diff --git a/Pkmds.Web/Components/Dialogs/ConfirmActionDialog.razor.cs b/Pkmds.Web/Components/Dialogs/ConfirmActionDialog.razor.cs index c53f342b..cc0abf34 100644 --- a/Pkmds.Web/Components/Dialogs/ConfirmActionDialog.razor.cs +++ b/Pkmds.Web/Components/Dialogs/ConfirmActionDialog.razor.cs @@ -2,35 +2,25 @@ namespace Pkmds.Web.Components.Dialogs; public partial class ConfirmActionDialog { - [CascadingParameter] - private MudDialogInstance? MudDialog { get; set; } + [CascadingParameter] private MudDialogInstance? MudDialog { get; set; } - [Parameter] - public string Title { get; set; } = "Confirm Action"; + [Parameter] public string Title { get; set; } = "Confirm Action"; - [Parameter] - public string Message { get; set; } = "Are you sure you want to perform this action?"; + [Parameter] public string Message { get; set; } = "Are you sure you want to perform this action?"; - [Parameter] - public string ConfirmText { get; set; } = "Confirm"; + [Parameter] public string ConfirmText { get; set; } = "Confirm"; - [Parameter] - public string ConfirmIcon { get; set; } = Icons.Material.Filled.Check; + [Parameter] public string ConfirmIcon { get; set; } = Icons.Material.Filled.Check; - [Parameter] - public Color ConfirmColor { get; set; } = Color.Primary; + [Parameter] public Color ConfirmColor { get; set; } = Color.Primary; - [Parameter] - public string CancelText { get; set; } = "Cancel"; + [Parameter] public string CancelText { get; set; } = "Cancel"; - [Parameter] - public string CancelIcon { get; set; } = Icons.Material.Filled.Clear; + [Parameter] public string CancelIcon { get; set; } = Icons.Material.Filled.Clear; - [Parameter] - public Color CancelColor { get; set; } = Color.Secondary; + [Parameter] public Color CancelColor { get; set; } = Color.Secondary; - [Parameter] - public EventCallback OnConfirm { get; set; } + [Parameter] public EventCallback OnConfirm { get; set; } private void Confirm() { diff --git a/Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs b/Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs index a26d2b1d..3ab6420f 100644 --- a/Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs +++ b/Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs @@ -2,13 +2,13 @@ namespace Pkmds.Web.Components.Dialogs; public partial class ShowdownExportDialog { - [Parameter] - public PKM? Pokemon { get; set; } + [Parameter] public PKM? Pokemon { get; set; } - [CascadingParameter] - private MudDialogInstance? MudDialog { get; set; } + [CascadingParameter] private MudDialogInstance? MudDialog { get; set; } - private string ShowdownExport => Pokemon is not null ? AppService.ExportPokemonAsShowdown(Pokemon) : AppService.ExportPartyAsShowdown(); + private string ShowdownExport => Pokemon is not null + ? AppService.ExportPokemonAsShowdown(Pokemon) + : AppService.ExportPartyAsShowdown(); private void Close() => MudDialog?.Close(); } diff --git a/Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs b/Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs index d41a2ea7..c0e6ea24 100644 --- a/Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs +++ b/Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms; public partial class PokemonEditForm : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; @@ -14,14 +13,8 @@ public void Dispose() => private void ExportAsShowdown() => DialogService.Show( "Showdown Export", - new DialogParameters - { - { nameof(ShowdownExportDialog.Pokemon), Pokemon } - }, - new DialogOptions - { - CloseOnEscapeKey = true, - }); + new() { { nameof(ShowdownExportDialog.Pokemon), Pokemon } }, + new() { CloseOnEscapeKey = true, }); private void DeletePokemon() { @@ -34,22 +27,17 @@ private void DeletePokemon() { nameof(ConfirmActionDialog.ConfirmColor), Color.Default }, { nameof(ConfirmActionDialog.CancelText), "Cancel" }, { nameof(ConfirmActionDialog.CancelIcon), Icons.Material.Filled.Clear }, - { nameof(ConfirmActionDialog.CancelColor), Color.Error}, + { nameof(ConfirmActionDialog.CancelColor), Color.Error }, { nameof(ConfirmActionDialog.OnConfirm), EventCallback.Factory.Create(this, OnDeleteConfirm) } }; DialogService.Show( "Confirm Action", parameters, - new DialogOptions - { - CloseOnEscapeKey = true, - MaxWidth = MaxWidth.Small, - }); + new() { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, }); void OnDeleteConfirm(bool confirmed) { - if (!confirmed) { return; @@ -99,24 +87,23 @@ void ShowPasteConfirmation() var parameters = new DialogParameters { { nameof(ConfirmActionDialog.Title), "Paste Pokémon" }, - { nameof(ConfirmActionDialog.Message), "Are you sure you want to paste the copied Pokémon? The Pokémon in the selected slot will be replaced." }, + { + nameof(ConfirmActionDialog.Message), + "Are you sure you want to paste the copied Pokémon? The Pokémon in the selected slot will be replaced." + }, { nameof(ConfirmActionDialog.ConfirmText), "Paste" }, { nameof(ConfirmActionDialog.ConfirmIcon), Icons.Material.Filled.Delete }, { nameof(ConfirmActionDialog.ConfirmColor), Color.Default }, { nameof(ConfirmActionDialog.CancelText), "Cancel" }, { nameof(ConfirmActionDialog.CancelIcon), Icons.Material.Filled.Clear }, - { nameof(ConfirmActionDialog.CancelColor), Color.Primary}, + { nameof(ConfirmActionDialog.CancelColor), Color.Primary }, { nameof(ConfirmActionDialog.OnConfirm), EventCallback.Factory.Create(this, OnPasteConfirm) } }; DialogService.Show( "Confirm Action", parameters, - new DialogOptions - { - CloseOnEscapeKey = true, - MaxWidth = MaxWidth.Small, - }); + new() { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, }); } void OnPasteConfirm(bool confirmed) diff --git a/Pkmds.Web/Components/EditForms/Tabs/CosmeticTab.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/CosmeticTab.razor.cs index aeacdcff..fbe1f8ee 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/CosmeticTab.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/CosmeticTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class CosmeticTab : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; diff --git a/Pkmds.Web/Components/EditForms/Tabs/MetTab.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/MetTab.razor.cs index cbdc5601..48257b2f 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/MetTab.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/MetTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class MetTab : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } /// /// Currently loaded met location group that is populating Met and Egg location comboboxes @@ -51,6 +50,7 @@ private void CheckMetLocationChange(GameVersion version, EntityContext context) version = group = context.GetSingleGameVersion(); } } + if (group != origintrack || context != originFormat) { currentLocationSearchVersion = version; @@ -70,7 +70,8 @@ private ComboItem GetMetLocation() CheckMetLocationChange(pkm.Version, pkm.Context); - return AppService.GetMetLocationComboItem(Pokemon.MetLocation, currentLocationSearchVersion, currentLocationSearchContext); + return AppService.GetMetLocationComboItem(Pokemon.MetLocation, currentLocationSearchVersion, + currentLocationSearchContext); } private ComboItem GetEggMetLocation() @@ -81,7 +82,8 @@ private ComboItem GetEggMetLocation() } CheckMetLocationChange(pkm.Version, pkm.Context); - return AppService.GetMetLocationComboItem(Pokemon.EggLocation, currentLocationSearchVersion, currentLocationSearchContext, true); + return AppService.GetMetLocationComboItem(Pokemon.EggLocation, currentLocationSearchVersion, + currentLocationSearchContext, true); } private void OriginGameChanged() @@ -95,10 +97,12 @@ private void OriginGameChanged() } private Task> SearchMetLocations(string searchString, CancellationToken token) => - Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion, currentLocationSearchContext)); + Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion, + currentLocationSearchContext)); private Task> SearchEggMetLocations(string searchString, CancellationToken token) => - Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion, currentLocationSearchContext, isEggLocation: true)); + Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion, + currentLocationSearchContext, isEggLocation: true)); private MetTimeOfDay GetMetTimeOfDay => Pokemon is not (PK2 and ICaughtData2 c2) ? MetTimeOfDay.None @@ -139,6 +143,7 @@ private void MetAsEggChanged(bool newValue) { Pokemon.IsEgg = false; } + Pokemon.EggDay = Pokemon.EggMonth = Pokemon.EggYear = 0; Pokemon.EggLocation = 0; break; diff --git a/Pkmds.Web/Components/EditForms/Tabs/MovesTab.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/MovesTab.razor.cs index cd3dd6ed..3761f637 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/MovesTab.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/MovesTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class MovesTab : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; @@ -26,9 +25,11 @@ private void SetPokemonMove(int moveIndex, ComboItem moveComboItem) RefreshService.Refresh(); } + // ReSharper disable once InconsistentNaming private int GetPokemonPP(int moveIndex) => Pokemon?.GetPP()[moveIndex] ?? 0; + // ReSharper disable once InconsistentNaming private void SetPokemonPP(int moveIndex, int pp) { if (Pokemon is null) @@ -41,9 +42,11 @@ private void SetPokemonPP(int moveIndex, int pp) RefreshService.Refresh(); } + // ReSharper disable once InconsistentNaming private int GetPokemonPPUps(int moveIndex) => Pokemon?.GetPPUps()[moveIndex] ?? 0; + // ReSharper disable once InconsistentNaming private void SetPokemonPPUps(int moveIndex, int ppUps) { if (Pokemon is null) diff --git a/Pkmds.Web/Components/EditForms/Tabs/OtMiscTab.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/OtMiscTab.razor.cs index e6915b77..8697f3c4 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/OtMiscTab.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/OtMiscTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class OtMiscTab : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; @@ -35,8 +34,6 @@ private void FillFromGame() Pokemon.SetTrainerTID7(saveFile.TrainerTID7); Pokemon.SetTrainerSID7(saveFile.TrainerSID7); break; - default: - break; } } diff --git a/Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor.cs index ae372863..fb13b397 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class PokerusComponent { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } private List PokerusDays { get; set; } = []; @@ -29,28 +28,28 @@ private void SetPokerusInfected(bool infected) Pokemon.IsPokerusInfected = infected; - if (!infected && Pokemon.IsPokerusCured) - { - Pokemon.IsPokerusCured = false; - return; - } - - if (infected) - { - if (Pokemon.PokerusStrain == 0) - { - Pokemon.PokerusStrain = 1; - } - - if (Pokemon.PokerusDays == 0) - { - Pokemon.PokerusDays = 1; - } - } - - if (!infected) - { - Pokemon.PokerusStrain = Pokemon.PokerusDays = 0; + switch (infected) + { + case false when Pokemon.IsPokerusCured: + Pokemon.IsPokerusCured = false; + return; + case true: + { + if (Pokemon.PokerusStrain == 0) + { + Pokemon.PokerusStrain = 1; + } + + if (Pokemon.PokerusDays == 0) + { + Pokemon.PokerusDays = 1; + } + + break; + } + case false: + Pokemon.PokerusStrain = Pokemon.PokerusDays = 0; + break; } } diff --git a/Pkmds.Web/Components/EditForms/Tabs/StatsTab.razor.cs b/Pkmds.Web/Components/EditForms/Tabs/StatsTab.razor.cs index d796c3ae..1e827a8d 100644 --- a/Pkmds.Web/Components/EditForms/Tabs/StatsTab.razor.cs +++ b/Pkmds.Web/Components/EditForms/Tabs/StatsTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.EditForms.Tabs; public partial class StatsTab : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; @@ -11,9 +10,8 @@ protected override void OnInitialized() => public void Dispose() => RefreshService.OnAppStateChanged -= StateHasChanged; - public static string GetCharacteristic(PKM? pokemon) => - pokemon?.Characteristic is int characteristicIndex && - characteristicIndex > -1 && + private static string GetCharacteristic(PKM? pokemon) => + pokemon?.Characteristic is { } characteristicIndex and > -1 && GameInfo.Strings.characteristics is { Length: > 0 } characteristics && characteristicIndex < characteristics.Length ? characteristics[characteristicIndex] @@ -64,7 +62,7 @@ private void OnStatNatureSet(Nature statNature) private string GetStatClass(Stats stat) { - if (Pokemon is not INature) + if (Pokemon is null) { return string.Empty; } diff --git a/Pkmds.Web/Components/GenderDisplayComponent.razor.cs b/Pkmds.Web/Components/GenderDisplayComponent.razor.cs index ea4d51df..cc01de73 100644 --- a/Pkmds.Web/Components/GenderDisplayComponent.razor.cs +++ b/Pkmds.Web/Components/GenderDisplayComponent.razor.cs @@ -1,17 +1,14 @@ namespace Pkmds.Web.Components; + public partial class GenderDisplayComponent { - [Parameter] - public Gender Gender { get; set; } + [Parameter] public Gender Gender { get; set; } - [Parameter] - public EventCallback OnChange { get; set; } + [Parameter] public EventCallback OnChange { get; set; } - [Parameter] - public bool Disabled { get; set; } + [Parameter] public bool Disabled { get; set; } - [Parameter] - public bool IncludeGenderless { get; set; } + [Parameter] public bool IncludeGenderless { get; set; } private static string GetGenderIcon(Gender gender) => gender switch { @@ -28,10 +25,10 @@ public partial class GenderDisplayComponent _ => string.Empty, }; - public RenderFragment GenderDisplayIcon(Gender gender) => !Disabled && OnChange.HasDelegate - ? GenderButton(gender, IncludeGenderless) - : GenderIconOnly(gender); + private RenderFragment GenderDisplayIcon(Gender gender) => !Disabled && OnChange.HasDelegate + ? GenderButton(gender, IncludeGenderless) + : GenderIconOnly(gender); - public static RenderFragment GenderDisplayAscii(Gender gender) => + private static RenderFragment GenderDisplayAscii(Gender gender) => GenderText(gender.ToString(), GetGenderColor(gender)); } diff --git a/Pkmds.Web/Components/Layout/MainLayout.razor.cs b/Pkmds.Web/Components/Layout/MainLayout.razor.cs index b499aa30..b244c605 100644 --- a/Pkmds.Web/Components/Layout/MainLayout.razor.cs +++ b/Pkmds.Web/Components/Layout/MainLayout.razor.cs @@ -36,18 +36,11 @@ private async Task ShowLoadSaveFileDialog() { const string message = "Choose a save file"; - var dialogParameters = new DialogParameters - { - { nameof(FileUploadDialog.Message), message } - }; + var dialogParameters = new DialogParameters { { nameof(FileUploadDialog.Message), message } }; var dialog = await DialogService.ShowAsync("Load Save File", parameters: dialogParameters, - options: new DialogOptions - { - CloseOnEscapeKey = true, - BackdropClick = false, - }); + options: new() { CloseOnEscapeKey = true, BackdropClick = false, }); var result = await dialog.Result; if (result is { Data: IBrowserFile selectedFile }) @@ -80,7 +73,8 @@ private async Task LoadSaveFile(IBrowserFile selectedFile) if (AppState.SaveFile is null) { - const string message = "The selected save file is invalid. If this save file came from a ROM hack, it is not supported. Otherwise, try saving in-game and re-exporting / re-uploading the save file."; + const string message = + "The selected save file is invalid. If this save file came from a ROM hack, it is not supported. Otherwise, try saving in-game and re-exporting / re-uploading the save file."; await DialogService.ShowMessageBox("Error", message); return; } @@ -119,25 +113,17 @@ private async Task ShowLoadPokemonFileDialog() const string title = "Load Pokémon File"; const string message = "Choose a Pokémon file"; - var dialogParameters = new DialogParameters - { - { nameof(FileUploadDialog.Message), message } - }; + var dialogParameters = new DialogParameters { { nameof(FileUploadDialog.Message), message } }; var dialog = await DialogService.ShowAsync( title, parameters: dialogParameters, - options: new DialogOptions - { - CloseOnEscapeKey = true, - BackdropClick = false, - }); + options: new() { CloseOnEscapeKey = true, BackdropClick = false, }); var result = await dialog.Result; if (result is { Data: IBrowserFile selectedFile }) { - var browserLoadPokemonFile = selectedFile; - await LoadPokemonFile(browserLoadPokemonFile, title); + await LoadPokemonFile(selectedFile, title); } } @@ -146,25 +132,17 @@ private async Task ShowLoadMysteryGiftFileDialog() const string title = "Load Mystery Gift file"; const string message = "Choose a Mystery Gift file"; - var dialogParameters = new DialogParameters - { - { nameof(FileUploadDialog.Message), message } - }; + var dialogParameters = new DialogParameters { { nameof(FileUploadDialog.Message), message } }; var dialog = await DialogService.ShowAsync( title, parameters: dialogParameters, - options: new DialogOptions - { - CloseOnEscapeKey = true, - BackdropClick = false, - }); + options: new() { CloseOnEscapeKey = true, BackdropClick = false, }); var result = await dialog.Result; if (result is { Data: IBrowserFile selectedFile }) { - var browserLoadPokemonFile = selectedFile; - await LoadMysteryGiftFile(browserLoadPokemonFile, title); + await LoadMysteryGiftFile(selectedFile, title); } } @@ -175,12 +153,6 @@ private async Task LoadPokemonFile(IBrowserFile browserLoadPokemonFile, string t return; } - if (browserLoadPokemonFile is null) - { - await DialogService.ShowMessageBox("No file selected", "Please select a file to load."); - return; - } - AppState.ShowProgressIndicator = true; try @@ -248,12 +220,6 @@ private async Task LoadMysteryGiftFile(IBrowserFile browserLoadMysteryGiftFile, return; } - if (browserLoadMysteryGiftFile is null) - { - await DialogService.ShowMessageBox("No file selected", "Please select a file to load."); - return; - } - AppState.ShowProgressIndicator = true; try @@ -263,7 +229,8 @@ private async Task LoadMysteryGiftFile(IBrowserFile browserLoadMysteryGiftFile, await fileStream.CopyToAsync(memoryStream); var data = memoryStream.ToArray(); - if (!FileUtil.TryGetMysteryGift(data, out var mysteryGift, Path.GetExtension(browserLoadMysteryGiftFile.Name))) + if (!FileUtil.TryGetMysteryGift(data, out var mysteryGift, + Path.GetExtension(browserLoadMysteryGiftFile.Name))) { await DialogService.ShowMessageBox("Error", "The file is not a supported Mystery Gift file."); return; @@ -350,7 +317,8 @@ private async Task WriteFile(byte[] data, string fileName, string fileTypeExtens try { // Ensure that the FilePicker API is invoked correctly within a user gesture context - await JSRuntime.InvokeVoidAsync("showFilePickerAndWrite", fileName, data, fileTypeExtension, fileTypeDescription); + await JSRuntime.InvokeVoidAsync("showFilePickerAndWrite", fileName, data, fileTypeExtension, + fileTypeDescription); } catch (JSException ex) { diff --git a/Pkmds.Web/Components/LetsGoBoxComponent.razor.cs b/Pkmds.Web/Components/LetsGoBoxComponent.razor.cs index 6dfc7857..d322fb5b 100644 --- a/Pkmds.Web/Components/LetsGoBoxComponent.razor.cs +++ b/Pkmds.Web/Components/LetsGoBoxComponent.razor.cs @@ -2,6 +2,7 @@ namespace Pkmds.Web.Components; public partial class LetsGoBoxComponent : IDisposable { + // ReSharper disable once UnusedAutoPropertyAccessor.Global public BoxEdit? BoxEdit { get; set; } protected override void OnInitialized() @@ -33,7 +34,7 @@ private void ReloadBox() return; } - BoxEdit = new BoxEdit(AppState.SaveFile); + BoxEdit = new(AppState.SaveFile); RefreshService.Refresh(); } } diff --git a/Pkmds.Web/Components/MainTabPages/BagTab.razor.cs b/Pkmds.Web/Components/MainTabPages/BagTab.razor.cs index b9639c38..bf03c1f2 100644 --- a/Pkmds.Web/Components/MainTabPages/BagTab.razor.cs +++ b/Pkmds.Web/Components/MainTabPages/BagTab.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components.MainTabPages; public partial class BagTab { - [Parameter, EditorRequired] - public IReadOnlyList? Inventory { get; set; } + [Parameter, EditorRequired] public IReadOnlyList? Inventory { get; set; } private MudTabs? PouchTabs { get; set; } @@ -104,16 +103,23 @@ private void DeleteItem(CellContext context, InventoryPouch pouch private string[] GetStringsForPouch(ReadOnlySpan items, bool sort = true) { - string[] res = new string[items.Length + 1]; - for (int i = 0; i < res.Length - 1; i++) + var res = new string[items.Length + 1]; + for (var i = 0; i < res.Length - 1; i++) + { res[i] = ItemList[items[i]]; + } + res[items.Length] = ItemList[0]; if (sort) + { Array.Sort(res); + } + return res; } - private void SortByName(InventoryPouch pouch) => pouch.SortByName(ItemList, reverse: IsSortedByName = !IsSortedByName); + private void SortByName(InventoryPouch pouch) => + pouch.SortByName(ItemList, reverse: IsSortedByName = !IsSortedByName); private void SortByCount(InventoryPouch pouch) => pouch.SortByCount(reverse: IsSortedByCount = !IsSortedByCount); @@ -125,6 +131,7 @@ private Task> SearchItemNames(InventoryPouch pouch, strin return Task.FromResult(ItemList .Select((name, index) => new ComboItem(name, index)) - .Where(x => itemsToSearch.Contains(x.Text) && x.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase))); + .Where(x => itemsToSearch.Contains(x.Text) && + x.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase))); } } diff --git a/Pkmds.Web/Components/MainTabPages/MysteryGiftDatabaseTab.razor b/Pkmds.Web/Components/MainTabPages/MysteryGiftDatabaseTab.razor index dd9acb6b..c26dbb26 100644 --- a/Pkmds.Web/Components/MainTabPages/MysteryGiftDatabaseTab.razor +++ b/Pkmds.Web/Components/MainTabPages/MysteryGiftDatabaseTab.razor @@ -1,17 +1,17 @@ @inherits BasePkmdsComponent -@if (AppState is { SaveFile: not null } && MysteryGiftsList.Count > 0) +@if (AppState is { SaveFile: not null } && mysteryGiftsList.Count > 0) { - - @foreach (var pageSize in PagesSizes) + @foreach (var pageSize in pagesSizes) { @pageSize @@ -22,7 +22,7 @@
- @foreach (var mysteryGift in PaginatedItems) + @foreach (var mysteryGift in paginatedItems) { MysteryGiftsList = []; + private List mysteryGiftsList = []; - private List PaginatedItems = []; - private int CurrentPage = 1; - private int PageSize = 20; // Number of items per page - private readonly int[] PagesSizes = [10, 20, 50, 100]; + private List paginatedItems = []; + private int currentPage = 1; + private int pageSize = 20; // Number of items per page + private readonly int[] pagesSizes = [10, 20, 50, 100]; - private int TotalPages => (int)Math.Ceiling((double)MysteryGiftsList.Count / PageSize); + private int TotalPages => (int)Math.Ceiling((double)mysteryGiftsList.Count / pageSize); protected override void OnInitialized() { @@ -43,28 +42,29 @@ private void LoadData() }; } - MysteryGiftsList = [.. encounterDatabase]; + mysteryGiftsList = [.. encounterDatabase]; - foreach (var mysteryGift in MysteryGiftsList) + foreach (var mysteryGift in mysteryGiftsList) { mysteryGift.GiftUsed = false; } UpdatePaginatedItems(); - static Func IsPresent(TTable pt) where TTable : IPersonalTable => z => pt.IsPresentInGame(z.Species, z.Form); + static Func IsPresent(TTable pt) where TTable : IPersonalTable => + z => pt.IsPresentInGame(z.Species, z.Form); } - private void UpdatePaginatedItems() => PaginatedItems = MysteryGiftsList - .Skip((CurrentPage - 1) * PageSize) - .Take(PageSize) - .ToList(); + private void UpdatePaginatedItems() => paginatedItems = mysteryGiftsList + .Skip((currentPage - 1) * pageSize) + .Take(pageSize) + .ToList(); private void GoToPage() => UpdatePaginatedItems(); private void OnPageSizeChange() { - CurrentPage = 1; // Reset to the first page + currentPage = 1; // Reset to the first page UpdatePaginatedItems(); } @@ -92,12 +92,12 @@ private async Task OnClickCopy(MysteryGift gift) saveFile.AdaptPKM(pokemon); AppState.CopiedPokemon = pokemon.Clone(); - Snackbar.Add("The selected Pokémon has been copied."); + Snackbar.Add("The selected Pokémon has been copied."); } private static string RenderListAsHtml(IReadOnlyList items, string tag = "p") { - if (items == null || items.Count == 0) + if (items.Count == 0) { return string.Empty; } @@ -107,6 +107,7 @@ private static string RenderListAsHtml(IReadOnlyList items, string tag = { builder.AppendFormat("<{0}>{1}", tag, WebUtility.HtmlEncode(item)); } + return builder.ToString(); } } diff --git a/Pkmds.Web/Components/MainTabPages/RecordsTab.razor.cs b/Pkmds.Web/Components/MainTabPages/RecordsTab.razor.cs index 56bcfc98..cd2949c5 100644 --- a/Pkmds.Web/Components/MainTabPages/RecordsTab.razor.cs +++ b/Pkmds.Web/Components/MainTabPages/RecordsTab.razor.cs @@ -39,7 +39,7 @@ private void LoadRecords() return; } - Records = new Record3(SaveFile); + Records = new(SaveFile); RecordComboItems = Record3.GetItems(SaveFile); GetRecord(); } diff --git a/Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor.cs b/Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor.cs index b1d25327..be097291 100644 --- a/Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor.cs +++ b/Pkmds.Web/Components/MainTabPages/TrainerInfoTab.razor.cs @@ -174,7 +174,7 @@ private static void SetTrainerCardPokemon(SAV3FRLG sav, int index, ComboItem spe break; default: return (null, null); - }; + } return (date, time.TimeOfDay); } @@ -192,20 +192,24 @@ private void UpdateGameStarted() switch (saveFile) { case SAV4 sav: - sav.SecondsToStart = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToStart = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV5 sav: - sav.SecondsToStart = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToStart = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV6 sav: - sav.SecondsToStart = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToStart = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV7 sav: - sav.SecondsToStart = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToStart = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; default: return; - }; + } } private (DateTime? Date, TimeSpan? Time) GetHallOfFame() @@ -234,7 +238,7 @@ private void UpdateGameStarted() break; default: return (null, null); - }; + } return (date, time.TimeOfDay); } @@ -252,20 +256,24 @@ private void UpdateHallOfFame() switch (saveFile) { case SAV4 sav: - sav.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToFame = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV5 sav: - sav.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToFame = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV6 sav: - sav.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToFame = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; case SAV7 sav: - sav.SecondsToFame = (uint)DateUtil.GetSecondsFrom2000(date, new DateTime(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); + sav.SecondsToFame = + (uint)DateUtil.GetSecondsFrom2000(date, new(2000, 1, 1, time.Hours, time.Minutes, time.Seconds)); break; default: return; - }; + } } private ComboItem GetGen1RivalStarter(SAV1 sav1) diff --git a/Pkmds.Web/Components/MarkingComponent.razor.cs b/Pkmds.Web/Components/MarkingComponent.razor.cs index 50fb2fcf..83617349 100644 --- a/Pkmds.Web/Components/MarkingComponent.razor.cs +++ b/Pkmds.Web/Components/MarkingComponent.razor.cs @@ -4,11 +4,9 @@ namespace Pkmds.Web.Components; public partial class MarkingComponent { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } - [Parameter, EditorRequired] - public Markings Shape { get; set; } + [Parameter, EditorRequired] public Markings Shape { get; set; } private string DisplayString => Shape switch { diff --git a/Pkmds.Web/Components/MarkingsContainer.razor.cs b/Pkmds.Web/Components/MarkingsContainer.razor.cs index 72ce4e37..d65116b2 100644 --- a/Pkmds.Web/Components/MarkingsContainer.razor.cs +++ b/Pkmds.Web/Components/MarkingsContainer.razor.cs @@ -2,8 +2,7 @@ namespace Pkmds.Web.Components; public partial class MarkingsContainer : IDisposable { - [Parameter, EditorRequired] - public PKM? Pokemon { get; set; } + [Parameter, EditorRequired] public PKM? Pokemon { get; set; } private string ContainerClass => $"markings-container{(Pokemon is { Generation: 3 } ? " gen-3" : string.Empty)}"; diff --git a/Pkmds.Web/Components/Pages/Home.razor.cs b/Pkmds.Web/Components/Pages/Home.razor.cs index ad0eec0b..e20f7bc8 100644 --- a/Pkmds.Web/Components/Pages/Home.razor.cs +++ b/Pkmds.Web/Components/Pages/Home.razor.cs @@ -1,8 +1,9 @@ namespace Pkmds.Web.Components.Pages; +// ReSharper disable once UnusedType.Global public partial class Home : IDisposable { - private bool IsUpdateAvailable { get; set; } = false; + private bool IsUpdateAvailable { get; set; } protected override void OnInitialized() { @@ -16,7 +17,7 @@ public void Dispose() RefreshService.OnUpdateAvailable -= ShowUpdateMessage; } - public void ShowUpdateMessage() + private void ShowUpdateMessage() { // Display the alert when an update is available IsUpdateAvailable = true; diff --git a/Pkmds.Web/Components/PartyGrid.razor.cs b/Pkmds.Web/Components/PartyGrid.razor.cs index c9cc2bbd..74b5ea2f 100644 --- a/Pkmds.Web/Components/PartyGrid.razor.cs +++ b/Pkmds.Web/Components/PartyGrid.razor.cs @@ -24,8 +24,5 @@ public void Dispose() private void ExportAsShowdown() => DialogService.Show( "Showdown Export", - new DialogOptions - { - CloseOnEscapeKey = true - }); + new DialogOptions { CloseOnEscapeKey = true }); } diff --git a/Pkmds.Web/Components/SaveFileComponent.razor.cs b/Pkmds.Web/Components/SaveFileComponent.razor.cs index a51a3151..dd1253fd 100644 --- a/Pkmds.Web/Components/SaveFileComponent.razor.cs +++ b/Pkmds.Web/Components/SaveFileComponent.razor.cs @@ -5,5 +5,4 @@ public partial class SaveFileComponent : IDisposable protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged; public void Dispose() => RefreshService.OnAppStateChanged -= StateHasChanged; - } diff --git a/Pkmds.Web/Components/SaveFileNameDisplay.cs b/Pkmds.Web/Components/SaveFileNameDisplay.cs index 54458e56..0ce54161 100644 --- a/Pkmds.Web/Components/SaveFileNameDisplay.cs +++ b/Pkmds.Web/Components/SaveFileNameDisplay.cs @@ -21,7 +21,9 @@ public static string SaveFileNameDisplayString(IAppState appState, IAppService a if (saveFile.Context is not EntityContext.Gen1) { - var genderDisplay = saveFile.Gender == (byte)Gender.Male ? Constants.MaleGenderUnicode : Constants.FemaleGenderUnicode; + var genderDisplay = saveFile.Gender == (byte)Gender.Male + ? Constants.MaleGenderUnicode + : Constants.FemaleGenderUnicode; sbTitle.Append($"{genderDisplay} "); } diff --git a/Pkmds.Web/Extensions/MoveExtension.cs b/Pkmds.Web/Extensions/MoveExtension.cs deleted file mode 100644 index d7bebe34..00000000 --- a/Pkmds.Web/Extensions/MoveExtension.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Pkmds.Web.Extensions; - -public static class MoveExtension -{ - public static bool IsValidMove(this Move move) => move is > Move.None and < Move.MAX_COUNT; - - public static bool IsValidMove(this ushort move) => IsValidMove((Move)move); -} diff --git a/Pkmds.Web/Program.cs b/Pkmds.Web/Program.cs index 986c15b9..223e39e8 100644 --- a/Pkmds.Web/Program.cs +++ b/Pkmds.Web/Program.cs @@ -5,14 +5,14 @@ builder.RootComponents.Add("head::after"); services - .AddMudServices(config => + .AddMudServices(config => { config.SnackbarConfiguration.PreventDuplicates = false; config.SnackbarConfiguration.ClearAfterNavigation = true; }); services - .AddSingleton(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }) + .AddSingleton(_ => new HttpClient { BaseAddress = new(builder.HostEnvironment.BaseAddress) }) .AddFileSystemAccessService() .AddSingleton() .AddSingleton() diff --git a/Pkmds.Web/Services/AppService.cs b/Pkmds.Web/Services/AppService.cs index af93cfd2..9b535588 100644 --- a/Pkmds.Web/Services/AppService.cs +++ b/Pkmds.Web/Services/AppService.cs @@ -47,38 +47,41 @@ public void ClearSelection() public string GetPokemonSpeciesName(ushort speciesId) => GetSpeciesComboItem(speciesId).Text; - public IEnumerable SearchPokemonNames(string searchString) => AppState.SaveFile is null || searchString is not { Length: > 0 } - ? [] - : GameInfo.FilteredSources.Species - .DistinctBy(species => species.Value) - .Where(species => species.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) - .OrderBy(species => species.Text); + public IEnumerable SearchPokemonNames(string searchString) => + AppState.SaveFile is null || searchString is not { Length: > 0 } + ? [] + : GameInfo.FilteredSources.Species + .DistinctBy(species => species.Value) + .Where(species => species.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + .OrderBy(species => species.Text); public ComboItem GetSpeciesComboItem(ushort speciesId) => GameInfo.FilteredSources.Species .DistinctBy(species => species.Value) - .FirstOrDefault(species => species.Value == speciesId) ?? default!; + .FirstOrDefault(species => species.Value == speciesId) ?? null!; - public IEnumerable SearchItemNames(string searchString) => AppState.SaveFile is null || searchString is not { Length: > 0 } - ? [] - : GameInfo.FilteredSources.Items - .DistinctBy(item => item.Value) - .Where(item => item.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) - .OrderBy(item => item.Text); + public IEnumerable SearchItemNames(string searchString) => + AppState.SaveFile is null || searchString is not { Length: > 0 } + ? [] + : GameInfo.FilteredSources.Items + .DistinctBy(item => item.Value) + .Where(item => item.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + .OrderBy(item => item.Text); public ComboItem GetItemComboItem(int itemId) => GameInfo.FilteredSources.Items .DistinctBy(item => item.Value) - .FirstOrDefault(item => item.Value == itemId) ?? default!; + .FirstOrDefault(item => item.Value == itemId) ?? null!; public ComboItem GetAbilityComboItem(int abilityId) => GameInfo.FilteredSources.Abilities .DistinctBy(ability => ability.Value) - .FirstOrDefault(ability => ability.Value == abilityId) ?? default!; + .FirstOrDefault(ability => ability.Value == abilityId) ?? null!; - public IEnumerable SearchAbilityNames(string searchString) => AppState.SaveFile is null || searchString is not { Length: > 0 } - ? [] - : GameInfo.FilteredSources.Abilities - .DistinctBy(ability => ability.Value) - .Where(ability => ability.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) - .OrderBy(ability => ability.Text); + public IEnumerable SearchAbilityNames(string searchString) => + AppState.SaveFile is null || searchString is not { Length: > 0 } + ? [] + : GameInfo.FilteredSources.Abilities + .DistinctBy(ability => ability.Value) + .Where(ability => ability.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + .OrderBy(ability => ability.Text); public string GetStatModifierString(Nature nature) { @@ -100,29 +103,33 @@ public void LoadPokemonStats(PKM? pokemon) pokemon.SetStats(stats); } - public IEnumerable SearchMetLocations(string searchString, GameVersion gameVersion, EntityContext entityContext, bool isEggLocation = false) => AppState.SaveFile is null || searchString is not { Length: > 0 } - ? [] - : GameInfo.GetLocationList(gameVersion, entityContext, isEggLocation) - .DistinctBy(l => l.Value) - .Where(metLocation => metLocation.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) - .OrderBy(metLocation => metLocation.Text); - - public ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion, EntityContext entityContext, bool isEggLocation = false) => AppState.SaveFile is null - ? default! + public IEnumerable SearchMetLocations(string searchString, GameVersion gameVersion, + EntityContext entityContext, bool isEggLocation = false) => + AppState.SaveFile is null || searchString is not { Length: > 0 } + ? [] + : GameInfo.GetLocationList(gameVersion, entityContext, isEggLocation) + .DistinctBy(l => l.Value) + .Where(metLocation => metLocation.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + .OrderBy(metLocation => metLocation.Text); + + public ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion, EntityContext entityContext, + bool isEggLocation = false) => AppState.SaveFile is null + ? null! : GameInfo.GetLocationList(gameVersion, entityContext, isEggLocation) .DistinctBy(l => l.Value) - .FirstOrDefault(metLocation => metLocation.Value == metLocationId) ?? default!; + .FirstOrDefault(metLocation => metLocation.Value == metLocationId) ?? null!; - public IEnumerable SearchMoves(string searchString) => AppState.SaveFile is null || searchString is not { Length: > 0 } - ? [] - : GameInfo.FilteredSources.Moves - .DistinctBy(move => move.Value) - .Where(move => move.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) - .OrderBy(move => move.Text); + public IEnumerable SearchMoves(string searchString) => + AppState.SaveFile is null || searchString is not { Length: > 0 } + ? [] + : GameInfo.FilteredSources.Moves + .DistinctBy(move => move.Value) + .Where(move => move.Text.Contains(searchString, StringComparison.OrdinalIgnoreCase)) + .OrderBy(move => move.Text); public ComboItem GetMoveComboItem(int moveId) => GameInfo.FilteredSources.Moves .DistinctBy(move => move.Value) - .FirstOrDefault(metLocation => metLocation.Value == moveId) ?? default!; + .FirstOrDefault(metLocation => metLocation.Value == moveId) ?? null!; public void SavePokemon(PKM? pokemon) { @@ -146,10 +153,12 @@ public void SavePokemon(PKM? pokemon) } else if (AppState.SelectedBoxNumber is not null && AppState.SelectedBoxSlotNumber is not null) { - AppState.SaveFile.SetBoxSlotAtIndex(pokemon, AppState.SelectedBoxNumber.Value, AppState.SelectedBoxSlotNumber.Value); + AppState.SaveFile.SetBoxSlotAtIndex(pokemon, AppState.SelectedBoxNumber.Value, + AppState.SelectedBoxSlotNumber.Value); RefreshService.RefreshBoxState(); } - else if (AppState.SelectedBoxNumber is null && AppState.SelectedBoxSlotNumber is not null && AppState.SaveFile is SAV7b) + else if (AppState.SelectedBoxNumber is null && AppState.SelectedBoxSlotNumber is not null && + AppState.SaveFile is SAV7b) { AppState.SaveFile.SetBoxSlotAtIndex(pokemon, AppState.SelectedBoxSlotNumber.Value); RefreshService.RefreshBoxAndPartyState(); diff --git a/Pkmds.Web/Services/BlazorAesProvider.cs b/Pkmds.Web/Services/BlazorAesProvider.cs index dbcfb543..13953f93 100644 --- a/Pkmds.Web/Services/BlazorAesProvider.cs +++ b/Pkmds.Web/Services/BlazorAesProvider.cs @@ -8,7 +8,7 @@ public IAesCryptographyProvider.IAes Create(byte[] key, CipherMode mode, Padding #pragma warning disable CS9113 // Parameter is unread. private class CryptoJsAes(JsService jsService, byte[] key, CipherMode mode, PaddingMode padding, byte[]? iv = null) #pragma warning restore CS9113 // Parameter is unread. - : IAesCryptographyProvider.IAes, IDisposable + : IAesCryptographyProvider.IAes { public void EncryptEcb(ReadOnlySpan plaintext, Span destination) => jsService.EncryptAes(plaintext, destination, key, CipherMode.ECB); @@ -25,4 +25,3 @@ public void DecryptCbc(ReadOnlySpan ciphertext, Span destination) => public void Dispose() { } } } - diff --git a/Pkmds.Web/Services/IAppService.cs b/Pkmds.Web/Services/IAppService.cs index 126c739a..941d47a4 100644 --- a/Pkmds.Web/Services/IAppService.cs +++ b/Pkmds.Web/Services/IAppService.cs @@ -2,8 +2,6 @@ public interface IAppService { - string[] NatureStatShortNames { get; } - PKM? EditFormPokemon { get; set; } bool IsDrawerOpen { get; set; } @@ -34,9 +32,11 @@ public interface IAppService IEnumerable SearchAbilityNames(string searchString); - IEnumerable SearchMetLocations(string searchString, GameVersion gameVersion, EntityContext entityContext, bool isEggLocation = false); + IEnumerable SearchMetLocations(string searchString, GameVersion gameVersion, EntityContext entityContext, + bool isEggLocation = false); - ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion, EntityContext entityContext, bool isEggLocation = false); + ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion, EntityContext entityContext, + bool isEggLocation = false); IEnumerable SearchMoves(string searchString); diff --git a/Pkmds.Web/Services/IRefreshService.cs b/Pkmds.Web/Services/IRefreshService.cs index 43dbd164..e27f9c79 100644 --- a/Pkmds.Web/Services/IRefreshService.cs +++ b/Pkmds.Web/Services/IRefreshService.cs @@ -18,5 +18,6 @@ public interface IRefreshService void RefreshBoxAndPartyState(); + // ReSharper disable once UnusedMember.Global void ShowUpdateMessage(); } diff --git a/Pkmds.Web/Services/JsService.cs b/Pkmds.Web/Services/JsService.cs index a40942be..81e2ddf0 100644 --- a/Pkmds.Web/Services/JsService.cs +++ b/Pkmds.Web/Services/JsService.cs @@ -3,8 +3,8 @@ public class JsService(IJSRuntime js) { private IJSInProcessRuntime SyncJs => js as IJSInProcessRuntime ?? - throw new NotSupportedException( - "Requested an in process javascript interop, but none was found"); + throw new NotSupportedException( + "Requested an in process javascript interop, but none was found"); public void EncryptAes(ReadOnlySpan origin, Span destination, ReadOnlySpan key, CipherMode mode) { diff --git a/Pkmds.Web/Services/RefreshService.cs b/Pkmds.Web/Services/RefreshService.cs index a7e22800..abd49850 100644 --- a/Pkmds.Web/Services/RefreshService.cs +++ b/Pkmds.Web/Services/RefreshService.cs @@ -2,7 +2,7 @@ public class RefreshService : IRefreshService { - public static RefreshService? Instance { get; private set; } + private static RefreshService? Instance { get; set; } public event Action? OnAppStateChanged; public event Action? OnBoxStateChanged; diff --git a/Pkmds.Web/SpriteHelper.cs b/Pkmds.Web/SpriteHelper.cs index 5184bdb0..9e9f97d9 100644 --- a/Pkmds.Web/SpriteHelper.cs +++ b/Pkmds.Web/SpriteHelper.cs @@ -10,39 +10,44 @@ public static class SpriteHelper public const string PokemonFallbackImageFileName = $"{SpritesRoot}a/a_unknown.png"; public static string GetMysteryGiftSpriteFileName(MysteryGift gift) => gift.IsItem - ? GetItemSpriteFilename(gift.ItemID, gift.Context) - : GetPokemonSpriteFilename(gift.Species, gift.Context, gift.IsEgg, gift.Form, 0, gift.Gender); + ? GetItemSpriteFilename(gift.ItemID, gift.Context) + : GetPokemonSpriteFilename(gift.Species, gift.Context, gift.IsEgg, gift.Form, 0, gift.Gender); public static string GetPokemonSpriteFilename(PKM? pokemon) => pokemon is null - ? PokemonFallbackImageFileName - : GetPokemonSpriteFilename(pokemon.Species, pokemon.Context, pokemon.IsEgg, pokemon.Form, pokemon.GetFormArgument(0), pokemon.Gender); + ? PokemonFallbackImageFileName + : GetPokemonSpriteFilename(pokemon.Species, pokemon.Context, pokemon.IsEgg, pokemon.Form, + pokemon.GetFormArgument(0), pokemon.Gender); - public static string GetPokemonSpriteFilename(ushort species, EntityContext context, bool isEgg, byte form, uint? formArg1, byte gender) => + private static string GetPokemonSpriteFilename(ushort species, EntityContext context, bool isEgg, byte form, + uint? formArg1, byte gender) => new StringBuilder($"{SpritesRoot}a/a_") - .Append((species, context, isEgg, form, formArg1, gender) switch - { - { context: EntityContext.Gen7b } and ({ species: (ushort)Species.Pikachu, form: PikachuStarterForm } - or { species: (ushort)Species.Eevee, form: EeveeStarterForm }) => $"{species}-{form}p", - { species: (ushort)Species.Manaphy, isEgg: true } => "490-e", - { isEgg: true } => "egg", - { species: (ushort)Species.Frillish or (ushort)Species.Jellicent, gender: (byte)Gender.Female } => $"{species}f", - { species: (ushort)Species.Alcremie } => $"{species}-{form}-{formArg1}", - _ when form > 0 && FormInfo.HasTotemForm(species) && FormInfo.IsTotemForm(species, form) => $"{species}-{FormInfo.GetTotemBaseForm(species, form)}", - { form: > 0 } => species switch + .Append((species, context, isEgg, form, formArg1, gender) switch { - (ushort)Species.Rockruff => species.ToString(), - (ushort)Species.Sinistea or (ushort)Species.Polteageist => species.ToString(), - (ushort)Species.Scatterbug or (ushort)Species.Spewpa => species.ToString(), - (ushort)Species.Urshifu => species.ToString(), - (ushort)Species.Dudunsparce => species.ToString(), - _ => $"{species}-{form}", - }, - { species: > (ushort)Species.None and < (ushort)Species.MAX_COUNT } => - species.ToString(), - _ => "unknown", - }) - .Append(".png") - .ToString(); + { context: EntityContext.Gen7b } and ({ species: (ushort)Species.Pikachu, form: PikachuStarterForm } + or { species: (ushort)Species.Eevee, form: EeveeStarterForm }) => $"{species}-{form}p", + { species: (ushort)Species.Manaphy, isEgg: true } => "490-e", + { isEgg: true } => "egg", + { + species: (ushort)Species.Frillish or (ushort)Species.Jellicent, gender: (byte)Gender.Female + } => $"{species}f", + { species: (ushort)Species.Alcremie } => $"{species}-{form}-{formArg1}", + (_, _, _, > 0, _, _) when FormInfo.HasTotemForm(species) && FormInfo.IsTotemForm(species, form) => + $"{species}-{FormInfo.GetTotemBaseForm(species, form)}", + { form: > 0 } => species switch + { + (ushort)Species.Rockruff => species.ToString(), + (ushort)Species.Sinistea or (ushort)Species.Polteageist => species.ToString(), + (ushort)Species.Scatterbug or (ushort)Species.Spewpa => species.ToString(), + (ushort)Species.Urshifu => species.ToString(), + (ushort)Species.Dudunsparce => species.ToString(), + _ => $"{species}-{form}", + }, + { species: > (ushort)Species.None and < (ushort)Species.MAX_COUNT } => + species.ToString(), + _ => "unknown", + }) + .Append(".png") + .ToString(); public static string GetBallSpriteFilename(int ball) => $"{SpritesRoot}b/_ball{ball}.png"; @@ -96,6 +101,7 @@ public static string GetBagPouchSpriteFileName(InventoryType type) => }; // TODO: Implement + // ReSharper disable once UnusedParameter.Global public static string GetMoveCategorySpriteFileName(int categoryId) => string.Empty;