Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/migrie/f/aot
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/modules/cmdpal/Exts/SamplePagesExtension/SelfImmolateCommand.cs
#	src/modules/cmdpal/extensionsdk/Microsoft.CmdPal.Extensions.Helpers/CommandResult.cs
#	src/modules/cmdpal/extensionsdk/Microsoft.CmdPal.Extensions.Helpers/InvokableCommand.cs
  • Loading branch information
zadjii-msft committed Feb 3, 2025
2 parents 6fa3f2a + edb6145 commit b3d9254
Show file tree
Hide file tree
Showing 46 changed files with 2,167 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.Extensions.Helpers;

namespace PokedexExtension;

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "This is sample code")]
public class Pokemon
{
public int Number { get; set; }
Expand All @@ -21,6 +20,8 @@ public class Pokemon

public string IconUrl => $"https://serebii.net/pokedex-sv/icon/new/{Number:D3}.png";

public string SerebiiUrl => $"https://serebii.net/pokedex-sv/{Number:D3}.shtml";

public Pokemon(int number, string name, List<string> types)
{
Number = number;
Expand All @@ -29,17 +30,42 @@ public Pokemon(int number, string name, List<string> types)
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")]
internal sealed partial class PokemonPage : NoOpCommand
internal sealed partial class OpenPokemonCommand : InvokableCommand
{
public OpenPokemonCommand()
{
Name = "Open";
}

public override ICommandResult Invoke(object sender)
{
if (sender is PokemonListItem item)
{
var pokemon = item.Pokemon;
Process.Start(new ProcessStartInfo(pokemon.SerebiiUrl) { UseShellExecute = true });
}

return CommandResult.KeepOpen();
}
}

internal sealed partial class PokemonListItem : ListItem
{
public PokemonPage(Pokemon pokemon)
private static readonly OpenPokemonCommand _command = new();

public Pokemon Pokemon { get; private set; }

public PokemonListItem(Pokemon p)
: base(_command)
{
Name = pokemon.Name;
Icon = new(pokemon.IconUrl);
Pokemon = p;
Title = Pokemon.Name;
Icon = new(Pokemon.IconUrl);
Subtitle = $"#{Pokemon.Number}";
Tags = Pokemon.Types.Select(t => new Tag() { Text = t, Background = PokedexExtensionPage.GetColorForType(t) }).ToArray();
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "This is sample code")]
internal sealed partial class PokedexExtensionPage : ListPage
{
private readonly List<Pokemon> _kanto =
Expand Down Expand Up @@ -448,14 +474,7 @@ public PokedexExtensionPage()

public override IListItem[] GetItems() => _kanto.AsEnumerable().Concat(_johto.AsEnumerable()).Concat(_hoenn.AsEnumerable()).Select(GetPokemonListItem).ToArray();

private static ListItem GetPokemonListItem(Pokemon pokemon)
{
return new ListItem(new PokemonPage(pokemon))
{
Subtitle = $"#{pokemon.Number}",
Tags = pokemon.Types.Select(t => new Tag() { Text = t, Background = GetColorForType(t) }).ToArray(),
};
}
private static ListItem GetPokemonListItem(Pokemon pokemon) => new PokemonListItem(pokemon);

// Dictionary mapping Pokémon types to their corresponding colors
private static readonly Dictionary<string, OptionalColor> TypeColors = new()
Expand Down
Loading

0 comments on commit b3d9254

Please sign in to comment.