Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes #102

Merged
merged 7 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- '**/*.yml'
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened] # Only run when PR is created or updated

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
replacements: '%%CACHE_VERSION%%=${{ github.run_id }}'

- name: Commit wwwroot to GitHub Pages
uses: JamesIves/[email protected].2
uses: JamesIves/[email protected].3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
Expand Down
28 changes: 21 additions & 7 deletions Pkmds.Web/Components/EditForms/PokemonEditForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ void OnDeleteConfirm(bool confirmed)
return;
}

if (AppState.SelectedPartySlotNumber is not null)
var selectedPokemonType = AppService.GetSelectedPokemonSlot(out var partySlot, out var boxNumber, out var boxSlot);
switch (selectedPokemonType)
{
AppService.DeletePokemon(AppState.SelectedPartySlotNumber.Value);
}
else if (AppState.SelectedBoxNumber is not null && AppState.SelectedBoxSlotNumber is not null)
{
AppService.DeletePokemon(AppState.SelectedBoxNumber.Value, AppState.SelectedBoxSlotNumber.Value);
case Services.AppService.SelectedPokemonType.Party:
AppService.DeletePokemon(partySlot);
break;
case Services.AppService.SelectedPokemonType.Box:
AppService.DeletePokemon(boxNumber, boxSlot);
break;
}
}
}
Expand Down Expand Up @@ -90,7 +92,7 @@ void ShowPasteConfirmation()
{ 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.ConfirmText), "Paste" },
{ nameof(ConfirmActionDialog.ConfirmIcon), Icons.Material.Filled.Delete },
{ nameof(ConfirmActionDialog.ConfirmIcon), Icons.Material.Filled.ContentPaste },
{ nameof(ConfirmActionDialog.ConfirmColor), Color.Default },
{ nameof(ConfirmActionDialog.CancelText), "Cancel" },
{ nameof(ConfirmActionDialog.CancelIcon), Icons.Material.Filled.Clear },
Expand Down Expand Up @@ -118,6 +120,18 @@ void PastePokemon()
{
Pokemon = AppState.CopiedPokemon.Clone();
AppService.SavePokemon(Pokemon);

var selectedPokemonType = AppService.GetSelectedPokemonSlot(out var partySlot, out var boxNumber, out var boxSlot);
switch (selectedPokemonType)
{
case Services.AppService.SelectedPokemonType.Party:
AppService.SetSelectedPartyPokemon(Pokemon, partySlot);
break;
case Services.AppService.SelectedPokemonType.Box:
AppService.SetSelectedBoxPokemon(Pokemon, boxNumber, boxSlot);
break;
}

Snackbar.Add("The copied Pokémon has been pasted.");
}
}
Expand Down
14 changes: 7 additions & 7 deletions Pkmds.Web/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
Edge="@Edge.Start"
OnClick="@DrawerToggle"/>
<MudText Typo="@Typo.h4"
class="d-none d-lg-flex">
Class="d-none d-lg-flex">
@Constants.AppTitle
</MudText>
<MudText Typo="@Typo.h6"
class="d-none d-md-flex d-lg-none">
Class="d-none d-md-flex d-lg-none">
@(AppService.IsDrawerOpen
? Constants.AppShortTitle
: Constants.AppTitle)
</MudText>
<MudText Typo="@Typo.inherit"
class="d-xs-flex d-md-none">
Class="d-xs-flex d-md-none">
@Constants.AppShortTitle
</MudText>
<MudSpacer/>
Expand All @@ -35,18 +35,18 @@
: "Light")"/>
<MudButton Class="d-none d-md-flex"
EndIcon="@Icons.Custom.Brands.GitHub"
Href="https://github.com/codemonkey85/PKMDS-Blazor"
Href="@GitHubRepoLink"
Target="_blank"
title="Source code on GitHub"
title="@GitHubTooltip"
Color="@Color.Inherit"
Variant="@Variant.Outlined">
Source code on GitHub
</MudButton>
<MudIconButton Class="d-md-none"
Icon="@Icons.Custom.Brands.GitHub"
Href="https://github.com/codemonkey85/PKMDS-Blazor"
Href="@GitHubRepoLink"
Target="_blank"
title="Source code on GitHub"
title="@GitHubTooltip"
Color="@Color.Inherit"
Variant="@Variant.Outlined"/>
</MudStack>
Expand Down
5 changes: 5 additions & 0 deletions Pkmds.Web/Components/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ public partial class MainLayout : IDisposable
private bool isDarkMode;
private MudThemeProvider? mudThemeProvider;

[StringSyntax(StringSyntaxAttribute.Uri)]
private const string GitHubRepoLink = "https://github.com/codemonkey85/PKMDS-Blazor";

private const string GitHubTooltip = "Source code on GitHub";

protected override void OnInitialized() => RefreshService.OnAppStateChanged += StateHasChanged;

public void Dispose() => RefreshService.OnAppStateChanged -= StateHasChanged;
Expand Down
2 changes: 2 additions & 0 deletions Pkmds.Web/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using System.Collections.Generic;
global using System.Collections.ObjectModel;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.Linq.Expressions;
global using System.Net;
Expand All @@ -19,3 +20,4 @@
global using Pkmds.Web.Components.Dialogs;
global using Pkmds.Web.Extensions;
global using Pkmds.Web.Services;
global using static Pkmds.Web.Services.AppService;
66 changes: 44 additions & 22 deletions Pkmds.Web/Services/AppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,29 @@ public void SavePokemon(PKM? pokemon)
return;
}

if (AppState.SelectedPartySlotNumber is not null)
var selectedPokemonType = GetSelectedPokemonSlot(out var partySlot, out var boxNumber, out var boxSlot);
switch (selectedPokemonType)
{
AppState.SaveFile.SetPartySlotAtIndex(pokemon, AppState.SelectedPartySlotNumber.Value);

if (AppState.SaveFile is SAV7b)
{
case SelectedPokemonType.Party:
AppState.SaveFile.SetPartySlotAtIndex(pokemon, partySlot);

if (AppState.SaveFile is SAV7b)
{
RefreshService.RefreshBoxAndPartyState();
}
else
{
RefreshService.RefreshPartyState();
}
break;
case SelectedPokemonType.Box:
AppState.SaveFile.SetBoxSlotAtIndex(pokemon, boxNumber, boxSlot);
RefreshService.RefreshBoxState();
break;
case SelectedPokemonType.None when AppState.SaveFile is SAV7b:
AppState.SaveFile.SetBoxSlotAtIndex(pokemon, boxSlot);
RefreshService.RefreshBoxAndPartyState();
}
else
{
RefreshService.RefreshPartyState();
}
}
else if (AppState.SelectedBoxNumber is not null && AppState.SelectedBoxSlotNumber is not null)
{
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)
{
AppState.SaveFile.SetBoxSlotAtIndex(pokemon, AppState.SelectedBoxSlotNumber.Value);
RefreshService.RefreshBoxAndPartyState();
break;
}
}

Expand Down Expand Up @@ -302,4 +301,27 @@ private void HandleNullOrEmptyPokemon()
EditFormPokemon.Version = saveFile.Version.GetSingleVersion();
}
}

public SelectedPokemonType GetSelectedPokemonSlot(out int partySlot, out int boxNumber, out int boxSlot)
{
const int defaultValue = -1;

partySlot = AppState.SelectedPartySlotNumber ?? defaultValue;
boxNumber = AppState.SelectedBoxNumber ?? defaultValue;
boxSlot = AppState.SelectedBoxSlotNumber ?? defaultValue;

return (partySlot, boxNumber, boxSlot) switch
{
(not defaultValue, defaultValue, defaultValue) => SelectedPokemonType.Party,
(defaultValue, not defaultValue, not defaultValue) => SelectedPokemonType.Box,
_ => SelectedPokemonType.None,
};
}

public enum SelectedPokemonType
{
None,
Party,
Box
}
}
4 changes: 3 additions & 1 deletion Pkmds.Web/Services/IAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion,

ComboItem GetMoveComboItem(int moveId);

public void SavePokemon(PKM? selectedPokemon);
void SavePokemon(PKM? selectedPokemon);

string GetCleanFileName(PKM pkm);

Expand All @@ -59,4 +59,6 @@ ComboItem GetMetLocationComboItem(ushort metLocationId, GameVersion gameVersion,
string ExportPartyAsShowdown();

string GetIdFormatString(bool isSid = false);

SelectedPokemonType GetSelectedPokemonSlot(out int partySlot, out int boxNumber, out int boxSlot);
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sdk": {
"allowPrerelease": false,
"rollForward": "latestMinor",
"version": "9.0.103"
"version": "9.0.200"
}
}