-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual-display.js
More file actions
202 lines (178 loc) · 6.99 KB
/
visual-display.js
File metadata and controls
202 lines (178 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// visual-display.js - Visual display and rendering functions
// Functions that handle the visual presentation of decks and cards
/**
* Render the visual decklist with card images
* @param {Object} typeGroups - Cards grouped by type
* @param {Array} commanders - Commander cards (optional)
*/
function renderVisualDecklist(typeGroups, commanders = []) {
const container = document.getElementById('visualDecklist');
container.innerHTML = '';
// Preload all unique card images for the decklist
const allCardNames = [];
Object.values(typeGroups).forEach(cards => {
cards.forEach(card => {
const cardName = card.Name || card.name;
if (cardName && !allCardNames.includes(cardName)) {
allCardNames.push(cardName);
}
});
});
preloadCardImages(allCardNames);
Object.entries(typeGroups).forEach(([type, cards]) => {
// Skip empty groups and "Other" if it only contains lands
if (cards.length === 0) return;
if (type === "Other") {
// Filter out lands from "Other"
const nonLandCards = cards.filter(card => {
const typeLine = (card.Type || card.type || card.type_line || "").toLowerCase();
return !typeLine.includes("land");
});
if (nonLandCards.length === 0) return; // Don't show "Other" if only lands
cards = nonLandCards;
}
// Count duplicates by card name
const cardCounts = {};
cards.forEach(card => {
const cardName = card.Name || card.name;
cardCounts[cardName] = (cardCounts[cardName] || 0) + 1;
});
// Only unique cards for display
const uniqueCards = Object.keys(cardCounts).map(cardName =>
cards.find(card => (card.Name || card.name) === cardName)
);
const stackDiv = document.createElement('div');
stackDiv.className = 'mb-6';
const title = document.createElement('h3');
title.textContent = type;
title.style.color = '#facc15';
stackDiv.appendChild(title);
// Creature: two rows, others: one row
let cardsPerRow = 8;
if (type === "Creature") {
cardsPerRow = Math.ceil(uniqueCards.length / 2);
}
for (let row = 0; row < (type === "Creature" ? 2 : 1); row++) {
const cardStack = createCardStack(uniqueCards, cardCounts, row, cardsPerRow);
stackDiv.appendChild(cardStack);
}
container.appendChild(stackDiv);
});
}
/**
* Create a card stack for visual display
* @param {Array} uniqueCards - Unique cards to display
* @param {Object} cardCounts - Count of each card
* @param {number} row - Current row number
* @param {number} cardsPerRow - Cards per row
* @returns {HTMLElement} Card stack element
*/
function createCardStack(uniqueCards, cardCounts, row, cardsPerRow) {
const cardStack = document.createElement('div');
cardStack.style.display = 'flex';
cardStack.style.flexDirection = 'row';
cardStack.style.position = 'relative';
cardStack.style.height = '156px';
cardStack.style.gap = '0';
const startIdx = row * cardsPerRow;
const endIdx = Math.min(startIdx + cardsPerRow, uniqueCards.length);
for (let idx = startIdx; idx < endIdx; idx++) {
const card = uniqueCards[idx];
const cardName = card.Name || card.name;
const count = cardCounts[cardName];
const cardWrapper = createCardWrapper(cardName, count, idx, cardsPerRow);
cardStack.appendChild(cardWrapper);
}
return cardStack;
}
/**
* Create a card wrapper with image and count badge
* @param {string} cardName - Name of the card
* @param {number} count - Number of copies
* @param {number} idx - Index in the row
* @param {number} cardsPerRow - Cards per row
* @returns {HTMLElement} Card wrapper element
*/
function createCardWrapper(cardName, count, idx, cardsPerRow) {
const cardWrapper = document.createElement('div');
cardWrapper.style.position = 'relative';
cardWrapper.style.display = 'inline-block';
cardWrapper.style.marginLeft = idx % cardsPerRow === 0 ? '0' : '-32px'; // overlap by 32px
const cardImg = createCardImage(cardName, {
width: '122px',
height: '170px',
className: 'decklist-card-thumb'
});
cardImg.style.border = '2px solid #222';
cardWrapper.appendChild(cardImg);
// Add count badge if more than 1
if (count > 1) {
const badge = createCountBadge(count);
cardWrapper.appendChild(badge);
}
return cardWrapper;
}
/**
* Create a count badge for cards with multiple copies
* @param {number} count - Number of copies
* @returns {HTMLElement} Count badge element
*/
function createCountBadge(count) {
const badge = document.createElement('span');
badge.textContent = `x${count}`;
badge.style.position = 'absolute';
badge.style.bottom = '4px';
badge.style.left = '6px';
badge.style.background = '#1a1a2e';
badge.style.color = '#facc15';
badge.style.fontFamily = "'Press Start 2P', cursive";
badge.style.fontSize = '0.85rem';
badge.style.padding = '2px 6px';
badge.style.borderRadius = '6px';
badge.style.border = '1px solid #222';
badge.style.pointerEvents = 'none';
return badge;
}
/**
* Update deck display with new deck information
* @param {Object} deckResult - Deck result object
* @param {Object} globals - Global variables needed
*/
function updateDeckDisplay(deckResult, globals) {
const { decklistOutput, chosenPack1Display, chosenPack2Display, chosenCubeCodeDisplay, packSelections, cubeSelect } = globals;
decklistOutput.value = deckResult.decklistText;
chosenPack1Display.textContent = packSelections.pack1;
chosenPack2Display.textContent = packSelections.pack2;
chosenCubeCodeDisplay.textContent = cubeSelect.name;
renderVisualDecklist(deckResult.typeGroups, deckResult.commanders);
}
/**
* Finalize deck generation and show final UI
* @param {Array} deck - Final deck cards
* @param {Array} commanders - Commander cards
*/
function finalizeDeckGeneration(deck, commanders = []) {
const copyDecklistBtn = document.getElementById('copyDecklistBtn');
// Don't manipulate visibility here - let smoothTransition handle it
// cubeSelectionStep.classList.add('hidden');
// packSelectionStep.classList.add('hidden');
// decklistStep.classList.remove('hidden');
copyDecklistBtn.disabled = false;
showMessage('DECKLIST READY!', 'success');
toggleLoading(false);
runBullyMeterAnalysis(deck, commanders);
}
/**
* Run bully meter analysis on the deck
* @param {Array} deck - Deck cards
* @param {Array} commanders - Commander cards
*/
function runBullyMeterAnalysis(deck, commanders = []) {
const bullyMeter = initializeBullyMeter();
if (bullyMeter) {
setTimeout(() => {
const powerScore = bullyMeter.analyzeDeck(deck, commanders);
console.log(`Deck Power Level: ${Math.round(powerScore)}%`);
}, 1000);
}
}