From 0cf9601fe2bbee27e2dc5a8ff4b392e3a94d38ab Mon Sep 17 00:00:00 2001 From: Kira Jiroux Date: Wed, 19 Feb 2025 15:13:45 -0500 Subject: [PATCH] Subskill and Nature information being collected; Pokemon are being rated; UI improvements to specialities/sleep types --- Portfolio.Application/DependencyInjection.cs | 4 + .../IPokemonNatureService.cs | 4 +- .../PokemonNatureService.cs | 15 +- .../PokemonService/IPokemonService.cs | 1 + .../Services/PokemonService/PokemonService.cs | 5 + .../IPokemonSubskillService.cs | 5 +- .../PokemonSubskillService.cs | 14 +- .../IPokemonNatureRepository.cs | 13 + .../IPokemonSubskillRepository.cs | 13 + .../Features/Pokemon/IPokemonRepository.cs | 1 + .../DependencyInjection.cs | 4 + .../Repositories/PokemonNatureRepository.cs | 24 ++ .../Repositories/PokemonRepository.cs | 6 + .../Repositories/PokemonSubskillRepository.cs | 24 ++ .../Components/Pages/PokemonCreate.razor | 3 +- .../Components/Pages/PokemonRate.razor | 378 +++++++++++++++++- .../Components/Pages/PokemonSleep.razor | 51 ++- .../Components/_Imports.razor | 4 + 18 files changed, 558 insertions(+), 11 deletions(-) create mode 100644 Portfolio.Domain/Features/Pokemon Natures/IPokemonNatureRepository.cs create mode 100644 Portfolio.Domain/Features/Pokemon Subskills/IPokemonSubskillRepository.cs create mode 100644 Portfolio.Infrastructure/Repositories/PokemonNatureRepository.cs create mode 100644 Portfolio.Infrastructure/Repositories/PokemonSubskillRepository.cs diff --git a/Portfolio.Application/DependencyInjection.cs b/Portfolio.Application/DependencyInjection.cs index 8de8a9d..373fb00 100644 --- a/Portfolio.Application/DependencyInjection.cs +++ b/Portfolio.Application/DependencyInjection.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.DependencyInjection; using Portfolio.Application.Services.Articles; +using Portfolio.Application.Services.PokemonNatureService; using Portfolio.Application.Services.PokemonService; +using Portfolio.Application.Services.PokemonSubskillService; using System; using System.Collections.Generic; using System.Linq; @@ -15,6 +17,8 @@ namespace Portfolio.Application { services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); diff --git a/Portfolio.Application/Services/PokemonNatureService/IPokemonNatureService.cs b/Portfolio.Application/Services/PokemonNatureService/IPokemonNatureService.cs index e40db94..b3564f7 100644 --- a/Portfolio.Application/Services/PokemonNatureService/IPokemonNatureService.cs +++ b/Portfolio.Application/Services/PokemonNatureService/IPokemonNatureService.cs @@ -1,4 +1,5 @@ -using System; +using Portfolio.Domain.Features.Pokemon_Natures; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,6 @@ namespace Portfolio.Application.Services.PokemonNatureService { public interface IPokemonNatureService { + Task> GetAllPokemonNaturesAsync(); } } diff --git a/Portfolio.Application/Services/PokemonNatureService/PokemonNatureService.cs b/Portfolio.Application/Services/PokemonNatureService/PokemonNatureService.cs index eb171bb..fe2fd7a 100644 --- a/Portfolio.Application/Services/PokemonNatureService/PokemonNatureService.cs +++ b/Portfolio.Application/Services/PokemonNatureService/PokemonNatureService.cs @@ -1,4 +1,6 @@ -using System; +using Portfolio.Domain.Features.Pokemon; +using Portfolio.Domain.Features.Pokemon_Natures; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +10,16 @@ namespace Portfolio.Application.Services.PokemonNatureService { public class PokemonNatureService : IPokemonNatureService { + private readonly IPokemonNatureRepository _pokemonNatureRepository; + + public PokemonNatureService(IPokemonNatureRepository pokemonNatureRepository) + { + _pokemonNatureRepository = pokemonNatureRepository; + } + + public async Task> GetAllPokemonNaturesAsync() + { + return await _pokemonNatureRepository.GetAllPokemonNaturesAsync(); + } } } diff --git a/Portfolio.Application/Services/PokemonService/IPokemonService.cs b/Portfolio.Application/Services/PokemonService/IPokemonService.cs index bd59cc2..9d0164f 100644 --- a/Portfolio.Application/Services/PokemonService/IPokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/IPokemonService.cs @@ -10,6 +10,7 @@ namespace Portfolio.Application.Services.PokemonService public interface IPokemonService { Task> GetAllPokemonAsync(); + Task GetPokemonByIdAsync(int id); Task AddPokemonAsync(Pokemon pokemon); Task DeletePokemonAsync(int pokemonId); } diff --git a/Portfolio.Application/Services/PokemonService/PokemonService.cs b/Portfolio.Application/Services/PokemonService/PokemonService.cs index 00443e7..fb4f7dd 100644 --- a/Portfolio.Application/Services/PokemonService/PokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/PokemonService.cs @@ -32,5 +32,10 @@ namespace Portfolio.Application.Services.PokemonService return await _pokemonRepository.GetAllPokemonsAsync(); } + + public async Task GetPokemonByIdAsync(int id) + { + return await _pokemonRepository.GetPokemonByIdAsync(id); + } } } diff --git a/Portfolio.Application/Services/PokemonSubskillService/IPokemonSubskillService.cs b/Portfolio.Application/Services/PokemonSubskillService/IPokemonSubskillService.cs index 3d5565f..b16b849 100644 --- a/Portfolio.Application/Services/PokemonSubskillService/IPokemonSubskillService.cs +++ b/Portfolio.Application/Services/PokemonSubskillService/IPokemonSubskillService.cs @@ -1,4 +1,5 @@ -using System; +using Portfolio.Domain.Features.Pokemon_Subskills; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,7 @@ namespace Portfolio.Application.Services.PokemonSubskillService { public interface IPokemonSubskillService { + Task> GetAllPokemonSubskillsAsync(); + } } diff --git a/Portfolio.Application/Services/PokemonSubskillService/PokemonSubskillService.cs b/Portfolio.Application/Services/PokemonSubskillService/PokemonSubskillService.cs index 745c241..16aea6e 100644 --- a/Portfolio.Application/Services/PokemonSubskillService/PokemonSubskillService.cs +++ b/Portfolio.Application/Services/PokemonSubskillService/PokemonSubskillService.cs @@ -1,4 +1,6 @@ -using System; +using Portfolio.Domain.Features.Pokemon; +using Portfolio.Domain.Features.Pokemon_Subskills; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +10,15 @@ namespace Portfolio.Application.Services.PokemonSubskillService { public class PokemonSubskillService : IPokemonSubskillService { + private readonly IPokemonSubskillRepository _pokemonSubskillRepository; + + public PokemonSubskillService(IPokemonSubskillRepository pokemonSubskillRepository) + { + _pokemonSubskillRepository = pokemonSubskillRepository; + } + public async Task> GetAllPokemonSubskillsAsync() + { + return await _pokemonSubskillRepository.GetAllPokemonSubskillsAsync(); + } } } diff --git a/Portfolio.Domain/Features/Pokemon Natures/IPokemonNatureRepository.cs b/Portfolio.Domain/Features/Pokemon Natures/IPokemonNatureRepository.cs new file mode 100644 index 0000000..662cf3e --- /dev/null +++ b/Portfolio.Domain/Features/Pokemon Natures/IPokemonNatureRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Portfolio.Domain.Features.Pokemon_Natures +{ + public interface IPokemonNatureRepository + { + Task> GetAllPokemonNaturesAsync(); + } +} diff --git a/Portfolio.Domain/Features/Pokemon Subskills/IPokemonSubskillRepository.cs b/Portfolio.Domain/Features/Pokemon Subskills/IPokemonSubskillRepository.cs new file mode 100644 index 0000000..0b87b21 --- /dev/null +++ b/Portfolio.Domain/Features/Pokemon Subskills/IPokemonSubskillRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Portfolio.Domain.Features.Pokemon_Subskills +{ + public interface IPokemonSubskillRepository + { + Task> GetAllPokemonSubskillsAsync(); + } +} diff --git a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs index 0539bc4..87a7dca 100644 --- a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs +++ b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs @@ -9,6 +9,7 @@ namespace Portfolio.Domain.Features.Pokemon public interface IPokemonRepository { Task> GetAllPokemonsAsync(); + Task GetPokemonByIdAsync(int id); Task AddPokemonAsync(Pokemon pokemon); Task DeletePokemonAsync(int pokemonId); diff --git a/Portfolio.Infrastructure/DependencyInjection.cs b/Portfolio.Infrastructure/DependencyInjection.cs index c109a9e..4bf1479 100644 --- a/Portfolio.Infrastructure/DependencyInjection.cs +++ b/Portfolio.Infrastructure/DependencyInjection.cs @@ -4,6 +4,8 @@ using Microsoft.Extensions.DependencyInjection; using Portfolio.Application.Services.Articles; using Portfolio.Application.Services.PokemonService; using Portfolio.Domain.Features.Pokemon; +using Portfolio.Domain.Features.Pokemon_Natures; +using Portfolio.Domain.Features.Pokemon_Subskills; using Portfolio.Infrastructure.Repositories; using System; using System.Collections.Generic; @@ -21,6 +23,8 @@ namespace Portfolio.Infrastructure options.UseSqlServer(configuration.GetConnectionString("DefaultConnection") )); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); return services; } diff --git a/Portfolio.Infrastructure/Repositories/PokemonNatureRepository.cs b/Portfolio.Infrastructure/Repositories/PokemonNatureRepository.cs new file mode 100644 index 0000000..d9977a1 --- /dev/null +++ b/Portfolio.Infrastructure/Repositories/PokemonNatureRepository.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Portfolio.Domain.Features.Pokemon_Natures; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Portfolio.Infrastructure.Repositories +{ + public class PokemonNatureRepository : IPokemonNatureRepository + { + private readonly ApplicationDbContext _context; + + public PokemonNatureRepository(ApplicationDbContext context) + { + _context = context; + } + public async Task> GetAllPokemonNaturesAsync() + { + return await _context.PokemonNatures.ToListAsync(); + } + } +} diff --git a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs index 3d34313..85c1a3e 100644 --- a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs +++ b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs @@ -21,6 +21,11 @@ namespace Portfolio.Infrastructure.Repositories { return await _context.Pokemons.ToListAsync(); } + public async Task GetPokemonByIdAsync(int id) + { + return await _context.Pokemons.FirstOrDefaultAsync(p => p.Id == id); + } + public async Task AddPokemonAsync(Pokemon pokemon) { _context.Pokemons.Add(pokemon); @@ -35,5 +40,6 @@ namespace Portfolio.Infrastructure.Repositories await _context.SaveChangesAsync(); } } + } } diff --git a/Portfolio.Infrastructure/Repositories/PokemonSubskillRepository.cs b/Portfolio.Infrastructure/Repositories/PokemonSubskillRepository.cs new file mode 100644 index 0000000..62f4255 --- /dev/null +++ b/Portfolio.Infrastructure/Repositories/PokemonSubskillRepository.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Portfolio.Domain.Features.Pokemon_Subskills; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Portfolio.Infrastructure.Repositories +{ + public class PokemonSubskillRepository : IPokemonSubskillRepository + { + private readonly ApplicationDbContext _context; + + public PokemonSubskillRepository(ApplicationDbContext context) + { + _context = context; + } + public async Task> GetAllPokemonSubskillsAsync() + { + return await _context.PokemonSubskills.ToListAsync(); + } + } +} diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor index e6309f2..e5f0561 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor @@ -9,10 +9,11 @@ Add New Pokémon +
-

Pokémon Sleep

+

Pokémon Sleep

diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor index 80dc875..b2ce1fd 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor @@ -1,7 +1,381 @@ -@page "/pokemonsleep/add-new-pokemon" +@page "/pokemonsleep/rate-pokemon" @inject IPokemonService PokemonService +@inject IPokemonNatureService PokemonNatureService +@inject IPokemonSubskillService PokemonSubskillService @inject NavigationManager Navigation @attribute [StreamRendering] -@rendermode InteractiveServer \ No newline at end of file +@rendermode InteractiveServer + + +Rate Pokémon + + + + +
+
+
+

Pokémon Sleep

+
+
+
+ + +@if (PokemonList == null || NatureList == null || SubskillList == null) +{ +

Loading...

+} +else +{ +
+ +
+
+
+

Pokémon Rater

+
+
+
+ + +
+
+
+ + +
+
+ + + @if (SelectedPokemon != null) + { +
+
+ + +
+ + + @if (SelectedPokemon.IsVariation) + { +
+
+ + + +
+
+ } + else + { +
+
+ + + +
+
+ } +
+
+ +
+ @if (SelectedPokemon.IsVariation) // If a Variant + { +

@SelectedPokemon.VariationName @SelectedPokemon.PokemonName

+ } + else // Otherwise, Base Case + { +

@SelectedPokemon.PokemonName

+ } +
+ + +
+

Pokédex #@SelectedPokemon.PokemonId

+
+ + +
+ + +
+
+

@SelectedPokemon.SleepType

+ +

@SelectedPokemon.Speciality

+ +
+ +
+
+ +
+ + + + +
+

Select Nature & Subskills

+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ + + +
+ +

Final Score: @FinalScore

+
+
+ } +
+
+} + + + + +@code { + + private List PokemonList; + private List NatureList; + private List SubskillList; + + private Dictionary isShiny = new Dictionary(); + + + private int _selectedPokemonId; + private int SelectedPokemonId + { + get => _selectedPokemonId; + set + { + _selectedPokemonId = value; + OnPokemonSelected(); + } + } + + private int SelectedNatureId; + private int subskillSelect1; + private int subskillSelect2; + private int subskillSelect3; + + private int[] SelectedSubskills = new int[3]; + + private Pokemon SelectedPokemon; + + private int FinalScore; + + private string PokemonImageUrl => SelectedPokemon != null + ? $"https://www.serebii.net/pokemonsleep/pokemon/{SelectedPokemon.Id}.png" + : string.Empty; + + protected override async Task OnInitializedAsync() + { + PokemonList = await PokemonService.GetAllPokemonAsync(); + NatureList = await PokemonNatureService.GetAllPokemonNaturesAsync(); + SubskillList = await PokemonSubskillService.GetAllPokemonSubskillsAsync(); + + if (PokemonList is not null) + { + + PokemonList.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); + + // Initialize dictionary with false (show base image first) + foreach (var pokemon in PokemonList) + { + isShiny[pokemon.Id] = false; + } + + } + + } + + private async void OnPokemonSelected() + { + if (SelectedPokemonId > 0) + { + SelectedPokemon = await PokemonService.GetPokemonByIdAsync(SelectedPokemonId); + StateHasChanged(); // Force UI to refresh + } + } + + private void ToggleImage(int Id) + { + if (isShiny.ContainsKey(Id)) + { + isShiny[Id] = !isShiny[Id]; + } + } + + private void CalculateScore() + { + if (SelectedPokemon == null || SelectedNatureId == 0 || subskillSelect1 == 0 || subskillSelect2 == 0 || subskillSelect3 == 0 ) + { + return; + } + + var nature = NatureList.FirstOrDefault(n => n.Id == SelectedNatureId); + var subskill1 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect1); + var subskill2 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect2); + var subskill3 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect3); + + if (nature == null || subskill1 == null || subskill2 == null || subskill3 == null) + { + return; + } + + FinalScore = SelectedPokemon.Speciality switch + { + "Berries" => nature.BerryRating + subskill1.BerryRank + subskill2.BerryRank + subskill3.BerryRank, + "Ingredients" => nature.IngredientRating + subskill1.IngredientRank + subskill2.IngredientRank + subskill3.IngredientRank, + "Skills" => nature.SkillRating + subskill1.SkillRank + subskill2.SkillRank + subskill3.SkillRank, + _ => 0 + }; + } +} \ No newline at end of file diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor index eefb177..834a2e3 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor @@ -54,6 +54,45 @@ transform: rotateY(180deg); } + .badge { + width: 100px; + height: 30px; + color: white; + padding: 4px 8px; + text-align: center; + vertical-align: middle; + border-radius: 30px; + } + .statText { + position: relative; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 13px; + } + + .dozing { + background-color: #fcdc5e; + } + .snoozing { + background-color: #4ce8ed; + } + + .slumbering { + background-color: #4588fb; + } + + .berries { + background-color: #24d86b; + } + + .ingredients { + background-color: #fdbe4d; + } + + .skills { + background-color: #47a0fc; + } @@ -71,7 +110,7 @@ Add New Pokémon - + Rate Pokémon @@ -90,7 +129,7 @@ } else { - +
@@ -175,10 +214,14 @@ else } - @pokemon.SleepType + +

@pokemon.SleepType

+ - @pokemon.Speciality + +

@pokemon.Speciality

+ diff --git a/Portfolio.WebUI.Server/Components/_Imports.razor b/Portfolio.WebUI.Server/Components/_Imports.razor index 5dda988..399609a 100644 --- a/Portfolio.WebUI.Server/Components/_Imports.razor +++ b/Portfolio.WebUI.Server/Components/_Imports.razor @@ -10,6 +10,10 @@ @using Portfolio.WebUI.Server.Components @using Portfolio.Domain.Features.Articles @using Portfolio.Domain.Features.Pokemon +@using Portfolio.Domain.Features.Pokemon_Natures +@using Portfolio.Domain.Features.Pokemon_Subskills @using Portfolio.Application.Services.Articles @using Portfolio.Application.Services.PokemonService +@using Portfolio.Application.Services.PokemonNatureService +@using Portfolio.Application.Services.PokemonSubskillService