add chunk to get cards collection from scryfall
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
import { Deck } from '../types';
|
||||
|
||||
interface DeckValidation {
|
||||
isValid: boolean;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
const FORMAT_RULES = {
|
||||
standard: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
modern: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
commander: {
|
||||
minCards: 100,
|
||||
maxCards: 100,
|
||||
maxCopies: 1,
|
||||
requiresCommander: true,
|
||||
},
|
||||
legacy: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
vintage: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
pauper: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
};
|
||||
|
||||
export function validateDeck(deck: Deck): DeckValidation {
|
||||
const rules = FORMAT_RULES[deck.format as keyof typeof FORMAT_RULES];
|
||||
const errors: string[] = [];
|
||||
|
||||
// Count total cards
|
||||
const totalCards = deck.cards.reduce((acc, curr) => acc + curr.quantity, 0);
|
||||
|
||||
// Check minimum cards
|
||||
if (totalCards < rules.minCards) {
|
||||
errors.push(`Deck must contain at least ${rules.minCards} cards`);
|
||||
}
|
||||
|
||||
// Check maximum cards
|
||||
if (rules.maxCards && totalCards > rules.maxCards) {
|
||||
errors.push(`Deck must not contain more than ${rules.maxCards} cards`);
|
||||
}
|
||||
|
||||
// Check card copies
|
||||
const cardCounts = new Map<string, number>();
|
||||
for (const element of deck.cards) {
|
||||
const {card, quantity} = element;
|
||||
//console.log("card", card);
|
||||
const currentCount = cardCounts.get(card.id) || 0;
|
||||
cardCounts.set(card.id, currentCount + quantity);
|
||||
}
|
||||
|
||||
cardCounts.forEach((count, cardName) => {
|
||||
const card = deck.cards.find(c => c.card.id === cardName)?.card;
|
||||
const isBasicLand = card?.name === 'Plains' || card?.name === 'Island' || card?.name === 'Swamp' || card?.name === 'Mountain' || card?.name === 'Forest';
|
||||
|
||||
if (!isBasicLand && count > rules.maxCopies) {
|
||||
errors.push(`${cardName} has too many copies (max ${rules.maxCopies})`);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
};
|
||||
import { Deck } from '../types';
|
||||
|
||||
interface DeckValidation {
|
||||
isValid: boolean;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
const FORMAT_RULES = {
|
||||
standard: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
modern: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
commander: {
|
||||
minCards: 100,
|
||||
maxCards: 100,
|
||||
maxCopies: 1,
|
||||
requiresCommander: true,
|
||||
},
|
||||
legacy: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
vintage: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
pauper: {
|
||||
minCards: 60,
|
||||
maxCards: undefined,
|
||||
maxCopies: 4,
|
||||
},
|
||||
};
|
||||
|
||||
export function validateDeck(deck: Deck): DeckValidation {
|
||||
const rules = FORMAT_RULES[deck.format as keyof typeof FORMAT_RULES];
|
||||
const errors: string[] = [];
|
||||
|
||||
// Count total cards
|
||||
const totalCards = deck.cards.reduce((acc, curr) => acc + curr.quantity, 0);
|
||||
|
||||
// Check minimum cards
|
||||
if (totalCards < rules.minCards) {
|
||||
errors.push(`Deck must contain at least ${rules.minCards} cards`);
|
||||
}
|
||||
|
||||
// Check maximum cards
|
||||
if (rules.maxCards && totalCards > rules.maxCards) {
|
||||
errors.push(`Deck must not contain more than ${rules.maxCards} cards`);
|
||||
}
|
||||
|
||||
// Check card copies
|
||||
const cardCounts = new Map<string, number>();
|
||||
for (const element of deck.cards) {
|
||||
const {card, quantity} = element;
|
||||
//console.log("card", card);
|
||||
const currentCount = cardCounts.get(card.id) || 0;
|
||||
cardCounts.set(card.id, currentCount + quantity);
|
||||
}
|
||||
|
||||
cardCounts.forEach((count, cardName) => {
|
||||
const card = deck.cards.find(c => c.card.id === cardName)?.card;
|
||||
const isBasicLand = card?.name === 'Plains' || card?.name === 'Island' || card?.name === 'Swamp' || card?.name === 'Mountain' || card?.name === 'Forest';
|
||||
|
||||
if (!isBasicLand && count > rules.maxCopies) {
|
||||
errors.push(`${cardName} has too many copies (max ${rules.maxCopies})`);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
export const themeColors = {
|
||||
red: {
|
||||
primary: '#ef4444',
|
||||
secondary: '#b91c1c',
|
||||
hover: '#dc2626'
|
||||
},
|
||||
green: {
|
||||
primary: '#22c55e',
|
||||
secondary: '#15803d',
|
||||
hover: '#16a34a'
|
||||
},
|
||||
blue: {
|
||||
primary: '#3b82f6',
|
||||
secondary: '#1d4ed8',
|
||||
hover: '#2563eb'
|
||||
},
|
||||
yellow: {
|
||||
primary: '#eab308',
|
||||
secondary: '#a16207',
|
||||
hover: '#ca8a04'
|
||||
},
|
||||
grey: {
|
||||
primary: '#6b7280',
|
||||
secondary: '#374151',
|
||||
hover: '#4b5563'
|
||||
},
|
||||
purple: {
|
||||
primary: '#a855f7',
|
||||
secondary: '#7e22ce',
|
||||
hover: '#9333ea'
|
||||
},
|
||||
white: {
|
||||
primary: '#f8fafc',
|
||||
secondary: '#e2e8f0',
|
||||
hover: '#f1f5f9',
|
||||
},
|
||||
black: {
|
||||
primary: '#0f172a',
|
||||
secondary: '#1e293b',
|
||||
hover: '#1e293b',
|
||||
}
|
||||
export const themeColors = {
|
||||
red: {
|
||||
primary: '#ef4444',
|
||||
secondary: '#b91c1c',
|
||||
hover: '#dc2626'
|
||||
},
|
||||
green: {
|
||||
primary: '#22c55e',
|
||||
secondary: '#15803d',
|
||||
hover: '#16a34a'
|
||||
},
|
||||
blue: {
|
||||
primary: '#3b82f6',
|
||||
secondary: '#1d4ed8',
|
||||
hover: '#2563eb'
|
||||
},
|
||||
yellow: {
|
||||
primary: '#eab308',
|
||||
secondary: '#a16207',
|
||||
hover: '#ca8a04'
|
||||
},
|
||||
grey: {
|
||||
primary: '#6b7280',
|
||||
secondary: '#374151',
|
||||
hover: '#4b5563'
|
||||
},
|
||||
purple: {
|
||||
primary: '#a855f7',
|
||||
secondary: '#7e22ce',
|
||||
hover: '#9333ea'
|
||||
},
|
||||
white: {
|
||||
primary: '#f8fafc',
|
||||
secondary: '#e2e8f0',
|
||||
hover: '#f1f5f9',
|
||||
},
|
||||
black: {
|
||||
primary: '#0f172a',
|
||||
secondary: '#1e293b',
|
||||
hover: '#1e293b',
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user