...
This commit is contained in:
@@ -83,7 +83,7 @@
|
||||
{
|
||||
var count = CountInDeck(card.Name);
|
||||
var maxed = count >= 3;
|
||||
<div class="browser-card @(count > 0 ? "in-deck" : "") @(maxed ? "maxed" : "")"
|
||||
<div @key="card.Name" class="browser-card @(count > 0 ? "in-deck" : "") @(maxed ? "maxed" : "")"
|
||||
@onclick="() => AddCard(card)"
|
||||
title="@(count > 0 ? $"{card.Name} ({count}/3)" : card.Name)">
|
||||
<div class="browser-card-img">
|
||||
@@ -314,7 +314,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
private int CountInDeck(string name) => deckCards.Count(c => c == name);
|
||||
private Dictionary<string, int> _deckCounts = new();
|
||||
|
||||
private void RebuildDeckCounts() =>
|
||||
_deckCounts = deckCards.GroupBy(n => n).ToDictionary(g => g.Key, g => g.Count());
|
||||
|
||||
private int CountInDeck(string name) =>
|
||||
_deckCounts.TryGetValue(name, out var c) ? c : 0;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
@@ -339,23 +345,27 @@
|
||||
deckNotes = deck.Notes ?? "";
|
||||
deckCards = new List<string>(deck.Cards);
|
||||
divers = new List<string>(deck.Divers);
|
||||
RebuildDeckCounts();
|
||||
}
|
||||
|
||||
private void AddCard(CardData card)
|
||||
{
|
||||
if (CountInDeck(card.Name) >= 3) return;
|
||||
deckCards.Add(card.Name);
|
||||
RebuildDeckCounts();
|
||||
}
|
||||
|
||||
private void RemoveCard(string name)
|
||||
{
|
||||
var idx = deckCards.LastIndexOf(name);
|
||||
if (idx >= 0) deckCards.RemoveAt(idx);
|
||||
RebuildDeckCounts();
|
||||
}
|
||||
|
||||
private void ClearDeck()
|
||||
{
|
||||
deckCards.Clear();
|
||||
RebuildDeckCounts();
|
||||
}
|
||||
|
||||
private void OpenDiverPicker(int slot)
|
||||
|
||||
Reference in New Issue
Block a user