Initial commit from your app
This commit is contained in:
89
src/utils/deckValidation.ts
Normal file
89
src/utils/deckValidation.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
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 {
|
||||
console.log("deck in validator", deck);
|
||||
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) => {
|
||||
if (count > rules.maxCopies) {
|
||||
errors.push(`${cardName} has too many copies (max ${rules.maxCopies})`);
|
||||
}
|
||||
});
|
||||
|
||||
// Check commander requirement
|
||||
if (rules.requiresCommander) {
|
||||
const hasCommander = deck.cards.some(({ card }) =>
|
||||
card.type_line?.toLowerCase().includes('legendary creature')
|
||||
);
|
||||
if (!hasCommander) {
|
||||
errors.push('Deck must have a legendary creature as commander');
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isValid: errors.length === 0,
|
||||
errors,
|
||||
};
|
||||
}
|
||||
32
src/utils/theme.ts
Normal file
32
src/utils/theme.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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'
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user