Vibe deck builder WIP
This commit is contained in:
@@ -0,0 +1,345 @@
|
||||
@page "/cards"
|
||||
@using Shared.Services
|
||||
@inject HttpClient Http
|
||||
@inject AnalyticsService AnalyticsService
|
||||
|
||||
<PageTitle>Chrono CCG - Card Gallery</PageTitle>
|
||||
|
||||
<HeadContent>
|
||||
<meta name="description" content="Browse and filter all Chrono CCG cards. Explore agents, spells, and more."/>
|
||||
</HeadContent>
|
||||
|
||||
<div class="gallery-container">
|
||||
<div class="gallery-header">
|
||||
<h1>Card Gallery</h1>
|
||||
<p class="text-secondary">Browse all @allCards.Count cards</p>
|
||||
</div>
|
||||
|
||||
<div class="category-tabs">
|
||||
<button class="tab @(categoryFilter == "" ? "active" : "")" @onclick='@(() => SetCategory(""))'>
|
||||
<i class="bi bi-grid-3x3-gap-fill"></i> All
|
||||
</button>
|
||||
|
||||
<button class="tab agent @(categoryFilter == "Agent" ? "active" : "")" @onclick='@(() => SetCategory("Agent"))'>
|
||||
<i class="bi bi-person-fill"></i> Agents
|
||||
</button>
|
||||
<button class="tab agent @(categoryFilter == "Immortalized" ? "active" : "")"
|
||||
@onclick='@(() => SetCategory("Immortalized"))'>
|
||||
<i class="bi bi-person-fill"></i> Immortalized
|
||||
</button>
|
||||
|
||||
<div class="tab link-toggle @(agentLink ? "active" : "")" @onclick="ToggleAgentLink" title="Link Agents and Immortalized cards">
|
||||
<i class="bi bi-link-45deg"></i>
|
||||
<span>Linked</span>
|
||||
<span class="toggle-switch @(agentLink ? "on" : "off")"></span>
|
||||
</div>
|
||||
|
||||
<div class="category-divider"></div>
|
||||
|
||||
<button class="tab spell @(categoryFilter == "Spell" ? "active" : "")" @onclick='@(() => SetCategory("Spell"))'>
|
||||
<i class="bi bi-wand"></i> Spells
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="filter-bar">
|
||||
<div class="search-wrapper">
|
||||
<i class="bi bi-search search-icon"></i>
|
||||
<input @bind="search" @bind:event="oninput" class="form-control search-input"
|
||||
placeholder="Search cards by name or description..."/>
|
||||
@if (search.Length > 0)
|
||||
{
|
||||
<button class="search-clear" @onclick="ClearSearch"><i class="bi bi-x-lg"></i></button>
|
||||
}
|
||||
</div>
|
||||
<select @bind="factionFilter" class="form-select filter-select">
|
||||
<option value="">All Factions</option>
|
||||
@foreach (var f in factions)
|
||||
{
|
||||
<option value="@f">@f</option>
|
||||
}
|
||||
</select>
|
||||
<select @bind="costFilter" class="form-select filter-select">
|
||||
<option value="">All Costs</option>
|
||||
@for (var i = 0; i <= 13; i++)
|
||||
{
|
||||
<option value="@i">@i</option>
|
||||
}
|
||||
</select>
|
||||
<div class="sort-group d-flex gap-1">
|
||||
<select @bind="sortBy" class="form-select filter-select sort-select">
|
||||
<option value="Cost">Sort by Cost</option>
|
||||
<option value="Name">Sort by Name</option>
|
||||
<option value="Attack">Sort by Attack</option>
|
||||
<option value="Health">Sort by Health</option>
|
||||
<option value="Efficiency">Sort by Efficiency</option>
|
||||
</select>
|
||||
<button class="btn btn-outline-secondary sort-dir-btn" @onclick="() => sortDescending = !sortDescending"
|
||||
title="@(sortDescending ? "Descending" : "Ascending")">
|
||||
<i class="bi bi-sort-@(sortDescending ? "down" : "up")"></i>
|
||||
</button>
|
||||
</div>
|
||||
<button class="btn @(showDetailedView ? "btn-primary" : "btn-outline-primary") view-toggle-btn"
|
||||
@onclick="() => showDetailedView = !showDetailedView" title="Toggle Detailed View">
|
||||
<i class="bi bi-list-ul"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (HasActiveFilters)
|
||||
{
|
||||
<div class="active-filters">
|
||||
<span class="filter-label">Filters:</span>
|
||||
@if (categoryFilter != "")
|
||||
{
|
||||
<span class="filter-chip">
|
||||
<i class="bi bi-tag-fill"></i> @categoryFilter
|
||||
<button @onclick="ClearCategoryFilter"><i class="bi bi-x"></i></button>
|
||||
</span>
|
||||
}
|
||||
@if (factionFilter != "")
|
||||
{
|
||||
<span class="filter-chip">
|
||||
<i class="bi bi-flag-fill"></i> @factionFilter
|
||||
<button @onclick="ClearFactionFilter"><i class="bi bi-x"></i></button>
|
||||
</span>
|
||||
}
|
||||
@if (costFilter != "")
|
||||
{
|
||||
<span class="filter-chip">
|
||||
<i class="bi bi-lightning-fill"></i> Cost @costFilter
|
||||
<button @onclick="ClearCostFilter"><i class="bi bi-x"></i></button>
|
||||
</span>
|
||||
}
|
||||
<button class="clear-all" @onclick="ClearFilters">Clear all</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="result-count">
|
||||
<span>@filteredCards.Count() card@(filteredCards.Count() != 1 ? "s" : "") found</span>
|
||||
@if (HasActiveFilters || search != "")
|
||||
{
|
||||
<span class="text-muted">out of @allCards.Count total</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (filteredCards.Any())
|
||||
{
|
||||
<div class="card-grid @(showDetailedView ? "detailed-view" : "")">
|
||||
@{ var idx = 0; }
|
||||
@foreach (var card in filteredCards.Where(a => a.Category is "Agent" or "Spell" or "Immortalized"))
|
||||
{
|
||||
<div class="card-cell @(selectedCard == card ? "selected" : "")"
|
||||
style="--i: @idx"
|
||||
@onclick="() => SelectCard(card)">
|
||||
<div class="card-image-wrapper">
|
||||
<div class="card-shimmer"></div>
|
||||
<img src="@card.ImagePath" alt="@card.Name" loading="lazy"
|
||||
onerror="this.src='data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%22200%22 height=%22280%22><rect fill=%22%23222244%22 width=%22200%22 height=%22280%22/><text fill=%22%23686888%22 font-size=%2214%22 x=%22100%22 y=%22140%22 text-anchor=%22middle%22 dominant-baseline=%22middle%22>No Image</text></svg>'"/>
|
||||
@if (card.IsImmortalized)
|
||||
{
|
||||
<div class="card-immortalize-badge" title="Immortalizes"><i class="bi bi-star-fill"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (showDetailedView)
|
||||
{
|
||||
<div class="card-label">
|
||||
<div class="card-name">@card.Name</div>
|
||||
<div class="card-stats">
|
||||
@if (card.Attack.HasValue)
|
||||
{
|
||||
<span class="stat"><i class="bi bi-crosshair"></i> @card.Attack</span>
|
||||
}
|
||||
@if (card.Health.HasValue)
|
||||
{
|
||||
<span class="stat"><i class="bi bi-heart-fill"></i> @card.Health</span>
|
||||
}
|
||||
</div>
|
||||
<div class="card-description-preview">@card.Description</div>
|
||||
<div class="card-category-badge @card.Category?.ToLowerInvariant()">@card.Category</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
idx++;
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="empty-state">
|
||||
<i class="bi bi-search"></i>
|
||||
<p>No cards match your filters.</p>
|
||||
<button class="btn btn-outline-secondary" @onclick="ClearFilters">Reset Filters</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (selectedCard != null)
|
||||
{
|
||||
<CardDialog Card="selectedCard" OnClose="CloseDetail" OnNavigate="SelectCard"/>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<CardData> allCards = [];
|
||||
private IEnumerable<CardData> filteredCards => ApplyFilters();
|
||||
private string search = "";
|
||||
private string categoryFilter = "";
|
||||
private string immortalFilter = "";
|
||||
private bool agentLink = true;
|
||||
private string factionFilter = "";
|
||||
private string costFilter = "";
|
||||
private string sortBy = "Cost";
|
||||
private bool sortDescending;
|
||||
private bool showDetailedView;
|
||||
private CardData? selectedCard;
|
||||
private List<string> factions = [];
|
||||
|
||||
private bool HasActiveFilters => categoryFilter != "" || factionFilter != "" || costFilter != "" || immortalFilter != "";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
allCards = CardDatabase.Cards;
|
||||
factions = allCards
|
||||
.Select(c => c.Faction)
|
||||
.Where(f => f != null)
|
||||
.Distinct()
|
||||
.OrderBy(f => f)
|
||||
.ToList()!;
|
||||
}
|
||||
|
||||
private IEnumerable<CardData> ApplyFilters()
|
||||
{
|
||||
var primarySet = allCards.Where(c =>
|
||||
c.MatchesSearch(search) &&
|
||||
(categoryFilter == "" || c.Category == categoryFilter) &&
|
||||
(factionFilter == "" || c.Faction == factionFilter) &&
|
||||
(costFilter == "" || c.Cost?.ToString() == costFilter)
|
||||
);
|
||||
|
||||
var sortedPrimary = sortBy switch
|
||||
{
|
||||
"Cost" => sortDescending ? primarySet.OrderByDescending(c => c.Cost) : primarySet.OrderBy(c => c.Cost),
|
||||
"Efficiency" => sortDescending ? primarySet.OrderByDescending(c => c.StatEfficiency) : primarySet.OrderBy(c => c.StatEfficiency),
|
||||
"Attack" => sortDescending ? primarySet.OrderByDescending(c => c.Attack) : primarySet.OrderBy(c => c.Attack),
|
||||
"Health" => sortDescending ? primarySet.OrderByDescending(c => c.Health) : primarySet.OrderBy(c => c.Health),
|
||||
_ => sortDescending ? primarySet.OrderByDescending(c => c.Name) : primarySet.OrderBy(c => c.Name)
|
||||
};
|
||||
|
||||
if (!agentLink)
|
||||
{
|
||||
return sortedPrimary;
|
||||
}
|
||||
|
||||
var result = new List<CardData>();
|
||||
var seen = new HashSet<string>();
|
||||
foreach (var card in sortedPrimary)
|
||||
{
|
||||
if (seen.Contains(card.Name)) continue;
|
||||
|
||||
// Determine the "Chain Head" (the Agent)
|
||||
var head = card;
|
||||
if (card.Category == "Immortalized" && card.ImmortalizeFrom != null)
|
||||
{
|
||||
var source = allCards.FirstOrDefault(c => c.Name == card.ImmortalizeFrom);
|
||||
if (source != null) head = source;
|
||||
}
|
||||
|
||||
// Add the chain starting from head
|
||||
if (!seen.Contains(head.Name))
|
||||
{
|
||||
result.Add(head);
|
||||
seen.Add(head.Name);
|
||||
}
|
||||
|
||||
if (head.ImmortalizeTo != null)
|
||||
{
|
||||
foreach (var targetName in head.ImmortalizeTo)
|
||||
{
|
||||
if (seen.Contains(targetName)) continue;
|
||||
var linked = allCards.FirstOrDefault(c => c.Name == targetName);
|
||||
if (linked != null)
|
||||
{
|
||||
result.Add(linked);
|
||||
seen.Add(linked.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the original card is added if it was somehow not part of the head's chain
|
||||
if (!seen.Contains(card.Name))
|
||||
{
|
||||
result.Add(card);
|
||||
seen.Add(card.Name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetImmortal(string imm)
|
||||
{
|
||||
immortalFilter = immortalFilter == imm ? "" : imm;
|
||||
}
|
||||
|
||||
private void ClearImmortalFilter()
|
||||
{
|
||||
immortalFilter = "";
|
||||
}
|
||||
|
||||
private void SetCategory(string cat)
|
||||
{
|
||||
categoryFilter = categoryFilter == cat ? "" : cat;
|
||||
_ = AnalyticsService.TrackEvent("filter_category", new { category = categoryFilter });
|
||||
}
|
||||
|
||||
private void ClearCategoryFilter()
|
||||
{
|
||||
categoryFilter = "";
|
||||
_ = AnalyticsService.TrackEvent("filter_category", new { category = "All" });
|
||||
}
|
||||
|
||||
private void ClearFactionFilter()
|
||||
{
|
||||
factionFilter = "";
|
||||
}
|
||||
|
||||
private void ToggleAgentLink()
|
||||
{
|
||||
agentLink = !agentLink;
|
||||
OnToggleAgentLink();
|
||||
}
|
||||
|
||||
private void OnToggleAgentLink()
|
||||
{
|
||||
_ = AnalyticsService.TrackEvent("toggle_agent_link", new { enabled = agentLink });
|
||||
}
|
||||
|
||||
private void ClearCostFilter()
|
||||
{
|
||||
costFilter = "";
|
||||
}
|
||||
|
||||
private void ClearSearch()
|
||||
{
|
||||
search = "";
|
||||
}
|
||||
|
||||
private void SelectCard(CardData card)
|
||||
{
|
||||
selectedCard = card;
|
||||
_ = AnalyticsService.TrackEvent("select_item", new { item_name = card.Name, item_category = card.Category });
|
||||
}
|
||||
|
||||
private void CloseDetail()
|
||||
{
|
||||
selectedCard = null;
|
||||
}
|
||||
|
||||
private void ClearFilters()
|
||||
{
|
||||
search = "";
|
||||
categoryFilter = "";
|
||||
factionFilter = "";
|
||||
costFilter = "";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user