Skip to content

Commit

Permalink
Even more code tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Dec 17, 2024
1 parent 25aef8f commit 6bd1dc2
Show file tree
Hide file tree
Showing 36 changed files with 283 additions and 329 deletions.
6 changes: 2 additions & 4 deletions Pkmds.Web/Components/BoxComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -38,9 +37,8 @@ private void ReloadBox()
return;
}

BoxEdit = new BoxEdit(AppState.SaveFile);
BoxEdit = new(AppState.SaveFile);
BoxEdit.LoadBox(BoxNumber);
RefreshService.Refresh();
}
}

6 changes: 2 additions & 4 deletions Pkmds.Web/Components/BoxGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 1 addition & 2 deletions Pkmds.Web/Components/BoxSlotComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
42 changes: 19 additions & 23 deletions Pkmds.Web/Components/DateOnlyPicker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateOnly?> DateChanged { get; set; }
[Parameter] public EventCallback<DateOnly?> DateChanged { get; set; }

[Parameter, EditorRequired]
public string? Label { get; set; }
[Parameter, EditorRequired] public string? Label { get; set; }

[Parameter]
public Expression<Func<DateOnly?>>? For { get; set; }
[Parameter] public Expression<Func<DateOnly?>>? 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;

Expand All @@ -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);
}
}

Expand All @@ -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<DateTime?, string>).GetField("_fieldIdentifier", BindingFlags.Instance | BindingFlags.NonPublic);
var fieldIdentifierField =
typeof(MudFormComponent<DateTime?, string>).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));
Expand Down
30 changes: 10 additions & 20 deletions Pkmds.Web/Components/Dialogs/ConfirmActionDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> OnConfirm { get; set; }
[Parameter] public EventCallback<bool> OnConfirm { get; set; }

private void Confirm()
{
Expand Down
10 changes: 5 additions & 5 deletions Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
35 changes: 11 additions & 24 deletions Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,14 +13,8 @@ public void Dispose() =>
private void ExportAsShowdown() =>
DialogService.Show<ShowdownExportDialog>(
"Showdown Export",
new DialogParameters
{
{ nameof(ShowdownExportDialog.Pokemon), Pokemon }
},
new DialogOptions
{
CloseOnEscapeKey = true,
});
new() { { nameof(ShowdownExportDialog.Pokemon), Pokemon } },
new() { CloseOnEscapeKey = true, });

private void DeletePokemon()
{
Expand All @@ -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<bool>(this, OnDeleteConfirm) }
};

DialogService.Show<ConfirmActionDialog>(
"Confirm Action",
parameters,
new DialogOptions
{
CloseOnEscapeKey = true,
MaxWidth = MaxWidth.Small,
});
new() { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, });

void OnDeleteConfirm(bool confirmed)
{

if (!confirmed)
{
return;
Expand Down Expand Up @@ -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<bool>(this, OnPasteConfirm) }
};

DialogService.Show<ConfirmActionDialog>(
"Confirm Action",
parameters,
new DialogOptions
{
CloseOnEscapeKey = true,
MaxWidth = MaxWidth.Small,
});
new() { CloseOnEscapeKey = true, MaxWidth = MaxWidth.Small, });
}

void OnPasteConfirm(bool confirmed)
Expand Down
3 changes: 1 addition & 2 deletions Pkmds.Web/Components/EditForms/Tabs/CosmeticTab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions Pkmds.Web/Components/EditForms/Tabs/MetTab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// Currently loaded met location group that is populating Met and Egg location comboboxes
Expand Down Expand Up @@ -51,6 +50,7 @@ private void CheckMetLocationChange(GameVersion version, EntityContext context)
version = group = context.GetSingleGameVersion();
}
}

if (group != origintrack || context != originFormat)
{
currentLocationSearchVersion = version;
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -95,10 +97,12 @@ private void OriginGameChanged()
}

private Task<IEnumerable<ComboItem>> SearchMetLocations(string searchString, CancellationToken token) =>
Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion, currentLocationSearchContext));
Task.FromResult(AppService.SearchMetLocations(searchString, currentLocationSearchVersion,
currentLocationSearchContext));

private Task<IEnumerable<ComboItem>> 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
Expand Down Expand Up @@ -139,6 +143,7 @@ private void MetAsEggChanged(bool newValue)
{
Pokemon.IsEgg = false;
}

Pokemon.EggDay = Pokemon.EggMonth = Pokemon.EggYear = 0;
Pokemon.EggLocation = 0;
break;
Expand Down
7 changes: 5 additions & 2 deletions Pkmds.Web/Components/EditForms/Tabs/MovesTab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions Pkmds.Web/Components/EditForms/Tabs/OtMiscTab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,8 +34,6 @@ private void FillFromGame()
Pokemon.SetTrainerTID7(saveFile.TrainerTID7);
Pokemon.SetTrainerSID7(saveFile.TrainerSID7);
break;
default:
break;
}
}

Expand Down
Loading

0 comments on commit 6bd1dc2

Please sign in to comment.