feat: Enhance card metadata handling, implement persistent Scryfall caching, and update pack generation logic for new booster structure.
Some checks failed
Build and Deploy / build (push) Failing after 55s
Some checks failed
Build and Deploy / build (push) Failing after 55s
This commit is contained in:
@@ -111,7 +111,8 @@ export const CubeManager: React.FC<CubeManagerProps> = ({ packs, setPacks, onGoT
|
||||
// --- Effects ---
|
||||
useEffect(() => {
|
||||
if (rawScryfallData) {
|
||||
const result = generatorService.processCards(rawScryfallData, filters);
|
||||
// Use local images: true
|
||||
const result = generatorService.processCards(rawScryfallData, filters, true);
|
||||
setProcessedData(result);
|
||||
}
|
||||
}, [filters, rawScryfallData]);
|
||||
@@ -189,6 +190,20 @@ export const CubeManager: React.FC<CubeManagerProps> = ({ packs, setPacks, onGoT
|
||||
}
|
||||
|
||||
setRawScryfallData(expandedCards);
|
||||
|
||||
// Cache to server
|
||||
if (expandedCards.length > 0) {
|
||||
setProgress('Loading...');
|
||||
// Deduplicate for shipping to server
|
||||
const uniqueCards = Array.from(new Map(expandedCards.map(c => [c.id, c])).values());
|
||||
|
||||
await fetch('/api/cards/cache', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ cards: uniqueCards }) // Send full metadata
|
||||
});
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
setProgress('');
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ export const LobbyManager: React.FC<LobbyManagerProps> = ({ generatedPacks }) =>
|
||||
|
||||
// Transform packs to use local URLs
|
||||
// Note: For multiplayer, clients need to access this URL.
|
||||
const baseUrl = `${window.location.protocol}//${window.location.host}/cards`;
|
||||
const baseUrl = `${window.location.protocol}//${window.location.host}/cards/images`;
|
||||
|
||||
const updatedPacks = generatedPacks.map(pack => ({
|
||||
...pack,
|
||||
|
||||
@@ -79,7 +79,7 @@ export interface PackGenerationSettings {
|
||||
|
||||
export class PackGeneratorService {
|
||||
|
||||
processCards(cards: ScryfallCard[], filters: { ignoreBasicLands: boolean, ignoreCommander: boolean, ignoreTokens: boolean }): { pools: ProcessedPools, sets: SetsMap } {
|
||||
processCards(cards: ScryfallCard[], filters: { ignoreBasicLands: boolean, ignoreCommander: boolean, ignoreTokens: boolean }, useLocalImages: boolean = false): { pools: ProcessedPools, sets: SetsMap } {
|
||||
const pools: ProcessedPools = { commons: [], uncommons: [], rares: [], mythics: [], lands: [], tokens: [] };
|
||||
const setsMap: SetsMap = {};
|
||||
|
||||
@@ -104,7 +104,9 @@ export class PackGeneratorService {
|
||||
typeLine: typeLine,
|
||||
layout: layout,
|
||||
colors: cardData.colors || [],
|
||||
image: cardData.image_uris?.normal || cardData.card_faces?.[0]?.image_uris?.normal || '',
|
||||
image: useLocalImages
|
||||
? `${window.location.origin}/cards/images/${cardData.id}.jpg`
|
||||
: (cardData.image_uris?.normal || cardData.card_faces?.[0]?.image_uris?.normal || ''),
|
||||
set: cardData.set_name,
|
||||
setCode: cardData.set,
|
||||
setType: setType,
|
||||
|
||||
Reference in New Issue
Block a user