Skip to content

Commit

Permalink
Start implementing Showdown export #20
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Mar 17, 2024
1 parent 0080c7a commit 91e69cf
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<MudDialog>
<DialogContent>
@ShowdownExport
</DialogContent>
<DialogActions>
<MudButton OnClick="@Close"
Variant="@Variant.Filled">
Close
</MudButton>
</DialogActions>
</MudDialog>
14 changes: 14 additions & 0 deletions Pkmds.Web/Components/Dialogs/ShowdownExportDialog.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Pkmds.Web.Components.Dialogs;

public partial class ShowdownExportDialog
{
[Parameter]
public PKM? Pokemon { get; set; }

[CascadingParameter]
private MudDialogInstance? MudDialog { get; set; }

private string? ShowdownExport => Pokemon is not null ? AppService.ExportPokemonAsShowdown(Pokemon) : AppService.ExportPartyAsShowdown();

private void Close() => MudDialog?.Close();
}
7 changes: 7 additions & 0 deletions Pkmds.Web/Components/PartyGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
</MudItem>
}
</MudGrid>
<MudButton OnClick="@ExportAsShowdown"
ButtonType="@ButtonType.Button"
Variant="@Variant.Filled"
Class=""
Color="@Color.Primary">
Export as Showdown
</MudButton>
</div>
}
8 changes: 8 additions & 0 deletions Pkmds.Web/Components/PartyGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public void Dispose()
RefreshService.OnAppStateChanged -= StateHasChanged;
RefreshService.OnPartyStateChanged -= StateHasChanged;
}

private void ExportAsShowdown() =>
DialogService.Show<Dialogs.ShowdownExportDialog>(
"Showdown Export",
new DialogOptions
{
CloseOnEscapeKey = true,
});
}
27 changes: 27 additions & 0 deletions Pkmds.Web/Services/AppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,31 @@ public void SetSelectedPartyPokemon(PKM? pkm, int slotNumber)
public void DeletePokemon()
{
}

public string ExportPokemonAsShowdown(PKM? pkm) => pkm is null
? string.Empty
: ShowdownParsing.GetShowdownText(pkm);

public string ExportPartyAsShowdown()
{
if (AppState.SaveFile is not { HasParty: true, PartyCount: var partyCount } saveFile)
{
return string.Empty;
}

var sbShowdown = new StringBuilder();

for (var slot = 0; slot < partyCount; slot++)
{
var pkm = saveFile.GetPartySlotAtIndex(slot);
if (pkm is null)
{
continue;
}

sbShowdown.AppendLine(ShowdownParsing.GetShowdownText(pkm));
}

return sbShowdown.ToString();
}
}
4 changes: 4 additions & 0 deletions Pkmds.Web/Services/IAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public interface IAppService
void SetSelectedBoxPokemon(PKM? pkm, int boxNumber, int slotNumber);

void SetSelectedPartyPokemon(PKM? pkm, int slotNumber);

string ExportPokemonAsShowdown(PKM? pkm);

string ExportPartyAsShowdown();
}
2 changes: 1 addition & 1 deletion Pkmds.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pkmds.Web", "Pkmds.Web\Pkmds.Web.csproj", "{F457F3DE-E45B-48D2-AFC9-BF9DAD07DE90}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pkmds.Web", "Pkmds.Web\Pkmds.Web.csproj", "{F457F3DE-E45B-48D2-AFC9-BF9DAD07DE90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 91e69cf

Please sign in to comment.